diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index d271cb5..ff469f0 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -89,6 +89,7 @@ void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr HOOK(ChangeAttack, choice, choice.GetRaw(), &attackName); if (attackName != choice->GetAttack()->GetAttack()->GetName()) { attackData = battle.GetValue()->GetLibrary()->GetAttackLibrary()->Get(attackName); + choice->ChangeAttackScript(attackData); } auto targetType = attackData->GetTarget(); diff --git a/src/Battling/TurnChoices/AttackTurnChoice.hpp b/src/Battling/TurnChoices/AttackTurnChoice.hpp index d6f1ea7..cafd30d 100644 --- a/src/Battling/TurnChoices/AttackTurnChoice.hpp +++ b/src/Battling/TurnChoices/AttackTurnChoice.hpp @@ -15,15 +15,15 @@ namespace CreatureLib::Battling { std::unique_ptr _attackScript = nullptr; int8_t _priority = 0; - void ResolveScript() { + void ResolveScript(ArbUt::BorrowedPtr attack) { if (_attackScript != nullptr) return; auto user = GetUser(); auto battle = user->GetBattle(); if (battle.HasValue()) { - if (_attack->GetAttack()->HasSecondaryEffect()) { + if (attack->HasSecondaryEffect()) { auto library = battle.GetValue()->GetLibrary(); - auto& effect = _attack->GetAttack()->GetSecondaryEffect(); + auto& effect = attack->GetSecondaryEffect(); _attackScript = std::unique_ptr( library->LoadScript(ScriptCategory::Attack, effect->GetEffectName())); if (_attackScript != nullptr) { @@ -37,7 +37,7 @@ namespace CreatureLib::Battling { AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr& attack, const CreatureIndex& target) : BaseTurnChoice(user), _attack(attack), _target(target) { EnsureNotNull(user) - ResolveScript(); + ResolveScript(attack->GetAttack()); _priority = _attack->GetAttack()->GetPriority(); } AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr& attack, const CreatureIndex& target, @@ -50,6 +50,12 @@ namespace CreatureLib::Battling { inline const ArbUt::BorrowedPtr& GetAttack() const noexcept { return _attack; } + void ChangeAttackScript(ArbUt::BorrowedPtr attack) { + _attackScript = nullptr; + ResolveScript(attack); + ResetActiveScripts(); + } + TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; } inline int8_t GetPriority() const noexcept { return _priority; }