#ifndef CREATURELIB_ATTACKTURNCHOICE_HPP #define CREATURELIB_ATTACKTURNCHOICE_HPP #include "../Models/Battle.hpp" #include "../Models/CreatureIndex.hpp" #include "../Models/LearnedAttack.hpp" #include "../ScriptHandling/ScriptCategory.hpp" #include "BaseTurnChoice.hpp" namespace CreatureLib::Battling { class AttackTurnChoice : public BaseTurnChoice { LearnedAttack* _attack; CreatureIndex _target; Script* _attackScript = nullptr; bool _scriptIsTaken = false; 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: AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target) : BaseTurnChoice(user), _attack(attack), _target(target) { AssertNotNull(attack) ResolveScript(); } AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target, Script* script) noexcept : BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {} ~AttackTurnChoice() { if (!_scriptIsTaken) { delete _attackScript; } } inline LearnedAttack* GetAttack() const noexcept { return _attack; } TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; } int8_t GetPriority() const { // HOOK: Change priority return _attack->GetAttack()->GetPriority(); } void MarkScriptAsTaken() { _scriptIsTaken = true; } const CreatureIndex& GetTarget() const noexcept { return _target; } Script* GetAttackScript() const noexcept { return _attackScript; } size_t ScriptCount() const override { return 1 + GetUser()->ScriptCount(); } protected: void GetActiveScripts(ArbUt::List& scripts) override { scripts.Append(ScriptWrapper::FromScript(&_attackScript)); GetUser()->GetActiveScripts(scripts); } }; } #endif // CREATURELIB_ATTACKTURNCHOICE_HPP