Support for attack when other attacks can't be used in MiscLibrary.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
7435a2a678
commit
5672f2d2a7
|
@ -6,7 +6,13 @@ export MiscLibrary* CreatureLib_MiscLibrary_Construct() { return new MiscLibrary
|
||||||
|
|
||||||
export void CreatureLib_MiscLibrary_Destruct(const MiscLibrary* p) { delete p; }
|
export void CreatureLib_MiscLibrary_Destruct(const MiscLibrary* p) { delete p; }
|
||||||
|
|
||||||
export void CreatureLib_MiscLibrary_IsCritical(MiscLibrary* p, ExecutingAttack* attack, Creature* target, uint8_t hit) {
|
export bool CreatureLib_MiscLibrary_IsCritical(MiscLibrary* p, ExecutingAttack* attack, Creature* target, uint8_t hit) {
|
||||||
p->IsCritical(attack, target, hit);
|
return p->IsCritical(attack, target, hit);
|
||||||
|
};
|
||||||
|
export bool CreatureLib_MiscLibrary_CanFlee(MiscLibrary* p, FleeTurnChoice* switchChoice) {
|
||||||
|
return p->CanFlee(switchChoice);
|
||||||
|
};
|
||||||
|
export BaseTurnChoice* CreatureLib_MiscLibrary_ReplacementAttack(MiscLibrary* p, Creature* user, uint8_t sideTarget,
|
||||||
|
uint8_t creatureTarget) {
|
||||||
|
return p->ReplacementAttack(user, CreatureIndex(sideTarget, creatureTarget));
|
||||||
};
|
};
|
||||||
export void CreatureLib_MiscLibrary_CanFlee(MiscLibrary* p, FleeTurnChoice* switchChoice) { p->CanFlee(switchChoice); };
|
|
|
@ -1,9 +1,38 @@
|
||||||
#include "MiscLibrary.hpp"
|
#include "MiscLibrary.hpp"
|
||||||
#include "../Models/Battle.hpp"
|
#include "../Models/Battle.hpp"
|
||||||
|
#include "../TurnChoices/AttackTurnChoice.hpp"
|
||||||
|
|
||||||
bool CreatureLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack,
|
bool CreatureLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
CreatureLib::Battling::Creature* target, uint8_t hit) const {
|
CreatureLib::Battling::Creature* target, uint8_t hit) const {
|
||||||
auto rand = target->GetBattle()->GetRandom();
|
auto rand = target->GetBattle()->GetRandom();
|
||||||
return rand->Get(10) <= 0;
|
return rand->Get(10) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CreatureLib::Battling::LearnedAttack* _replacementAttack = nullptr;
|
||||||
|
static CreatureLib::Library::AttackData* _replacementAttackData = nullptr;
|
||||||
|
|
||||||
|
static CreatureLib::Library::AttackData* GetReplacementAttackData() {
|
||||||
|
if (_replacementAttackData == nullptr) {
|
||||||
|
_replacementAttackData =
|
||||||
|
new CreatureLib::Library::AttackData("replacement"_cnc, 0, CreatureLib::Library::AttackCategory::Physical,
|
||||||
|
30, 255, 255, CreatureLib::Library::AttackTarget::Any, 0, {});
|
||||||
|
}
|
||||||
|
return _replacementAttackData;
|
||||||
|
}
|
||||||
|
|
||||||
|
static CreatureLib::Battling::LearnedAttack* GetReplacementAttack() {
|
||||||
|
if (_replacementAttack == nullptr) {
|
||||||
|
_replacementAttack = new CreatureLib::Battling::LearnedAttack(
|
||||||
|
GetReplacementAttackData(), CreatureLib::Battling::AttackLearnMethod::Unknown);
|
||||||
|
}
|
||||||
|
return _replacementAttack;
|
||||||
|
}
|
||||||
|
|
||||||
bool CreatureLib::Battling::MiscLibrary::CanFlee(FleeTurnChoice* switchChoice) const { return true; }
|
bool CreatureLib::Battling::MiscLibrary::CanFlee(FleeTurnChoice* switchChoice) const { return true; }
|
||||||
|
CreatureLib::Battling::BaseTurnChoice*
|
||||||
|
CreatureLib::Battling::MiscLibrary::ReplacementAttack(Creature* user, CreatureIndex target) const {
|
||||||
|
auto sideTarget = 0;
|
||||||
|
if (user->GetBattleSide()->GetSideIndex() == 0)
|
||||||
|
sideTarget = 1;
|
||||||
|
return new AttackTurnChoice(user, GetReplacementAttack(), target);
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef CREATURELIB_MISCLIBRARY_HPP
|
#ifndef CREATURELIB_MISCLIBRARY_HPP
|
||||||
#define CREATURELIB_MISCLIBRARY_HPP
|
#define CREATURELIB_MISCLIBRARY_HPP
|
||||||
|
|
||||||
|
#include "../Models/CreatureIndex.hpp"
|
||||||
#include "../Models/ExecutingAttack.hpp"
|
#include "../Models/ExecutingAttack.hpp"
|
||||||
#include "../TurnChoices/FleeTurnChoice.hpp"
|
#include "../TurnChoices/FleeTurnChoice.hpp"
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ namespace CreatureLib::Battling {
|
||||||
virtual ~MiscLibrary() = default;
|
virtual ~MiscLibrary() = default;
|
||||||
virtual bool IsCritical(ExecutingAttack* attack, Creature* target, uint8_t hit) const;
|
virtual bool IsCritical(ExecutingAttack* attack, Creature* target, uint8_t hit) const;
|
||||||
virtual bool CanFlee(FleeTurnChoice* switchChoice) const;
|
virtual bool CanFlee(FleeTurnChoice* switchChoice) const;
|
||||||
|
virtual BaseTurnChoice* ReplacementAttack(Creature* user, CreatureIndex target) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#ifndef CREATURELIB_ATTACKTURNCHOICE_HPP
|
#ifndef CREATURELIB_ATTACKTURNCHOICE_HPP
|
||||||
#define CREATURELIB_ATTACKTURNCHOICE_HPP
|
#define CREATURELIB_ATTACKTURNCHOICE_HPP
|
||||||
|
|
||||||
|
#include "../Models/Battle.hpp"
|
||||||
#include "../Models/CreatureIndex.hpp"
|
#include "../Models/CreatureIndex.hpp"
|
||||||
#include "../Models/LearnedAttack.hpp"
|
#include "../Models/LearnedAttack.hpp"
|
||||||
|
#include "../ScriptHandling/ScriptCategory.hpp"
|
||||||
#include "BaseTurnChoice.hpp"
|
#include "BaseTurnChoice.hpp"
|
||||||
|
|
||||||
namespace CreatureLib::Battling {
|
namespace CreatureLib::Battling {
|
||||||
|
@ -11,9 +13,26 @@ namespace CreatureLib::Battling {
|
||||||
CreatureIndex _target;
|
CreatureIndex _target;
|
||||||
Script* _attackScript = nullptr;
|
Script* _attackScript = nullptr;
|
||||||
|
|
||||||
|
void ResolveScript() {
|
||||||
|
if (_attackScript != nullptr)
|
||||||
|
return;
|
||||||
|
auto user = GetUser();
|
||||||
|
if (user == nullptr)
|
||||||
|
return;
|
||||||
|
auto battle = user->GetBattle();
|
||||||
|
if (battle != nullptr) {
|
||||||
|
auto library = battle->GetLibrary();
|
||||||
|
_attackScript = library->LoadScript(ScriptCategory::Attack, _attack->GetAttack()->GetName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target)
|
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target)
|
||||||
: BaseTurnChoice(user), _attack(attack), _target(target) {}
|
: BaseTurnChoice(user), _attack(attack), _target(target) {
|
||||||
|
ResolveScript();
|
||||||
|
}
|
||||||
|
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target, Script* script)
|
||||||
|
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {}
|
||||||
|
|
||||||
inline LearnedAttack* GetAttack() const { return _attack; }
|
inline LearnedAttack* GetAttack() const { return _attack; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue