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};
|
ArbUt::List<Creature*> targets = {target};
|
||||||
|
|
||||||
auto attack = ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
auto attack = ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
||||||
|
choice->MarkScriptAsTaken();
|
||||||
bool prevented = false;
|
bool prevented = false;
|
||||||
HOOK_LOCAL(PreventAttack, attack, &attack, &prevented);
|
HOOK_LOCAL(PreventAttack, attack, &attack, &prevented);
|
||||||
if (prevented) {
|
if (prevented) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace CreatureLib::Battling {
|
||||||
LearnedAttack* _attack;
|
LearnedAttack* _attack;
|
||||||
CreatureIndex _target;
|
CreatureIndex _target;
|
||||||
Script* _attackScript = nullptr;
|
Script* _attackScript = nullptr;
|
||||||
|
bool _scriptIsTaken = false;
|
||||||
|
|
||||||
void ResolveScript() {
|
void ResolveScript() {
|
||||||
if (_attackScript != nullptr)
|
if (_attackScript != nullptr)
|
||||||
|
@ -41,6 +42,12 @@ namespace CreatureLib::Battling {
|
||||||
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target, Script* script) noexcept
|
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target, Script* script) noexcept
|
||||||
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {}
|
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {}
|
||||||
|
|
||||||
|
~AttackTurnChoice() {
|
||||||
|
if (!_scriptIsTaken) {
|
||||||
|
delete _attackScript;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline LearnedAttack* GetAttack() const noexcept { return _attack; }
|
inline LearnedAttack* GetAttack() const noexcept { return _attack; }
|
||||||
|
|
||||||
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
|
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
|
||||||
|
@ -50,6 +57,8 @@ namespace CreatureLib::Battling {
|
||||||
return _attack->GetAttack()->GetPriority();
|
return _attack->GetAttack()->GetPriority();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MarkScriptAsTaken() { _scriptIsTaken = true; }
|
||||||
|
|
||||||
const CreatureIndex& GetTarget() const noexcept { return _target; }
|
const CreatureIndex& GetTarget() const noexcept { return _target; }
|
||||||
|
|
||||||
Script* GetAttackScript() const noexcept { return _attackScript; }
|
Script* GetAttackScript() const noexcept { return _attackScript; }
|
||||||
|
|
Loading…
Reference in New Issue