Ensure Attack script is deleted when not taken by ExecutingAttack.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
20be2815ce
commit
a7069a5960
|
@ -63,6 +63,7 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
|||
ArbUt::List<Creature*> targets = {target};
|
||||
|
||||
auto attack = ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
||||
choice->MarkScriptAsTaken();
|
||||
bool prevented = false;
|
||||
HOOK_LOCAL(PreventAttack, attack, &attack, &prevented);
|
||||
if (prevented) {
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace CreatureLib::Battling {
|
|||
LearnedAttack* _attack;
|
||||
CreatureIndex _target;
|
||||
Script* _attackScript = nullptr;
|
||||
bool _scriptIsTaken = false;
|
||||
|
||||
void ResolveScript() {
|
||||
if (_attackScript != nullptr)
|
||||
|
@ -41,6 +42,12 @@ namespace CreatureLib::Battling {
|
|||
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; }
|
||||
|
@ -50,6 +57,8 @@ namespace CreatureLib::Battling {
|
|||
return _attack->GetAttack()->GetPriority();
|
||||
}
|
||||
|
||||
void MarkScriptAsTaken() { _scriptIsTaken = true; }
|
||||
|
||||
const CreatureIndex& GetTarget() const noexcept { return _target; }
|
||||
|
||||
Script* GetAttackScript() const noexcept { return _attackScript; }
|
||||
|
|
Loading…
Reference in New Issue