CreatureLib/src/Battling/TurnChoices/AttackTurnChoice.hpp

67 lines
2.5 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) {
if (_attack->GetAttack()->HasSecondaryEffect()) {
auto library = battle->GetLibrary();
auto effect = _attack->GetAttack()->GetSecondaryEffect();
_attackScript = library->LoadScript(ScriptCategory::Attack, effect->GetEffectName());
if (_attackScript != nullptr) {
_attackScript->OnInitialize(effect->GetParameters());
}
}
}
}
public:
2019-12-05 08:53:48 +00:00
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target)
: BaseTurnChoice(user), _attack(attack), _target(target) {
2020-03-22 12:42:26 +00:00
AssertNotNull(attack)
ResolveScript();
}
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target, Script* script) noexcept
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {}
inline LearnedAttack* GetAttack() const noexcept { return _attack; }
TurnChoiceKind GetKind() const noexcept 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
const CreatureIndex& GetTarget() const noexcept { return _target; }
Script* GetAttackScript() const noexcept { return _attackScript; }
size_t ScriptCount() const override { return 1 + GetUser()->ScriptCount(); }
2019-11-24 10:06:51 +00:00
protected:
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
2020-04-23 21:23:58 +00:00
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
GetUser()->GetActiveScripts(scripts);
}
};
}
#endif // CREATURELIB_ATTACKTURNCHOICE_HPP