CreatureLib/src/Battling/TurnChoices/AttackTurnChoice.hpp

59 lines
2.0 KiB
C++
Raw Normal View History

#ifndef CREATURELIB_ATTACKTURNCHOICE_HPP
#define CREATURELIB_ATTACKTURNCHOICE_HPP
#include "../Models/Battle.hpp"
2019-12-05 08:53:48 +00:00
#include "../Models/CreatureIndex.hpp"
#include "../Models/LearnedAttack.hpp"
#include "../ScriptHandling/ScriptCategory.hpp"
#include "BaseTurnChoice.hpp"
namespace CreatureLib::Battling {
class AttackTurnChoice : public BaseTurnChoice {
LearnedAttack* _attack;
2019-12-05 08:53:48 +00:00
CreatureIndex _target;
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:
2019-12-05 08:53:48 +00:00
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& 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; }
TurnChoiceKind GetKind() const override { return TurnChoiceKind ::Attack; }
2019-10-31 11:31:31 +00:00
int8_t GetPriority() const {
// HOOK: Change priority
2019-10-31 11:31:31 +00:00
return _attack->GetAttack()->GetPriority();
}
2019-11-02 12:57:43 +00:00
2019-12-05 08:53:48 +00:00
const CreatureIndex& GetTarget() const { return _target; }
2020-03-11 11:22:13 +00:00
Script* GetAttackScript() const { return _attackScript; }
2019-11-24 10:06:51 +00:00
protected:
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override {
scripts.emplace_back(&_attackScript);
GetUser()->GetActiveScripts(scripts);
}
};
}
#endif // CREATURELIB_ATTACKTURNCHOICE_HPP