From add77325a4b260a7adc57dede5df6e4b1be2be27 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 12 Jun 2020 16:48:49 +0200 Subject: [PATCH] Several additional checks to ensure battle does not finish turn when ended. --- src/Battling/Flow/TurnHandler.cpp | 11 +++++++++-- src/Battling/Models/Battle.cpp | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index da777e2..9c8541b 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -20,12 +20,15 @@ void TurnHandler::RunTurn(ArbUt::BorrowedPtr queue) { } void TurnHandler::ExecuteChoice(ArbUt::BorrowedPtr choice) { - AssertNotNull(choice); + AssertNotNull(choice) auto choiceKind = choice->GetKind(); if (choiceKind == TurnChoiceKind::Pass) { return; } auto user = choice->GetUser(); + AssertNotNull(user) + if (user->GetBattle()->HasEnded()) + return; // If the user is fainted, we don't want to execute its choice. if (user->IsFainted()) { return; @@ -100,6 +103,8 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo auto user = attack->GetUser(); AssertNotNull(user) AssertNotNull(target) + if (user->GetBattle()->HasEnded()) + return; auto targetSource = target; auto userSource = attack; @@ -130,6 +135,8 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo auto& dmgLibrary = library->GetDamageLibrary(); auto hitIterator = attack->GetTargetIteratorBegin(target.GetRaw()); for (uint8_t hitIndex = 0; hitIndex < numberOfHits; hitIndex++) { + if (user->GetBattle()->HasEnded()) + return; if (user->IsFainted()) { break; } @@ -170,7 +177,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo if (damage > 0) { target->Damage(damage, DamageSource::AttackDamage); - if (attackData->HasSecondaryEffect()) { + if (attackData->HasSecondaryEffect() && !user->IsFainted()) { bool preventSecondary = false; HOOK(PreventSecondaryEffects, targetSource, attack, target.GetRaw(), hitIndex, &preventSecondary); if (!preventSecondary) { diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index e0e8076..73c37bc 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -101,6 +101,9 @@ bool Battle::CanSlotBeFilled(uint8_t side, uint8_t index) const { } void Battle::ValidateBattleState() { + if (_hasEnded) { + return; + } bool survivingSideExists = false; uint8_t winningSide = 255; for (uint8_t i = 0; i < _sides.Count(); i++) {