Make ExecutingAttack a local variable while being used, to ensure it's always cleaned up.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -62,9 +62,9 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
||||
auto target = choice->GetUser()->GetBattle()->GetCreature(choice->GetTarget());
|
||||
ArbUt::List<Creature*> targets = {target};
|
||||
|
||||
auto attack = new ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
||||
auto attack = ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
||||
bool prevented = false;
|
||||
HOOK(PreventAttack, attack, attack, &prevented);
|
||||
HOOK_LOCAL(PreventAttack, attack, &attack, &prevented);
|
||||
if (prevented) {
|
||||
return;
|
||||
}
|
||||
@@ -77,25 +77,22 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
||||
|
||||
// HOOK: check if attack fails
|
||||
bool fail = false;
|
||||
HOOK(FailAttack, attack, attack, &fail);
|
||||
HOOK_LOCAL(FailAttack, attack, &attack, &fail);
|
||||
if (fail) {
|
||||
// TODO: Fail handling.
|
||||
return;
|
||||
}
|
||||
|
||||
bool stopBeforeAttack = false;
|
||||
HOOK(StopBeforeAttack, attack, attack, &stopBeforeAttack);
|
||||
HOOK_LOCAL(StopBeforeAttack, attack, &attack, &stopBeforeAttack);
|
||||
if (stopBeforeAttack) {
|
||||
return;
|
||||
}
|
||||
HOOK(OnBeforeAttack, attack, attack);
|
||||
HOOK_LOCAL(OnBeforeAttack, attack, &attack);
|
||||
|
||||
for (auto& t : attack->GetTargets()) {
|
||||
HandleAttackForTarget(attack, t);
|
||||
for (auto& t : attack.GetTargets()) {
|
||||
HandleAttackForTarget(&attack, t);
|
||||
}
|
||||
|
||||
// TODO: We currently delete this, but we probably want to store this in a log, so scripts can look it up.
|
||||
delete attack;
|
||||
}
|
||||
|
||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target) {
|
||||
|
||||
Reference in New Issue
Block a user