From 3aa6e28a623d6cb883e1c9516fa5ac48dae516b9 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 15 May 2022 11:31:39 +0200 Subject: [PATCH] Fixes battle not ending on capture of last pokemon --- src/Battling/Pokemon/Pokemon.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Battling/Pokemon/Pokemon.cpp b/src/Battling/Pokemon/Pokemon.cpp index 7c1034d..112e82f 100644 --- a/src/Battling/Pokemon/Pokemon.cpp +++ b/src/Battling/Pokemon/Pokemon.cpp @@ -91,8 +91,15 @@ void PkmnLib::Battling::Pokemon::AttemptCapture(PkmnLib::Library::Item* catchIte if (result.WasCaught) { // By marking the pokemon as caught, it becomes no longer usable for switch in. _wasCaught = true; - // As the pokemon is caught now, we replace it with an empty space. - _battleData.Side.GetValue()->SetCreature(nullptr, _battleData.Index.GetCreatureIndex()); + + if (_battleData.Battle.HasValue() && _battleData.Side.HasValue()) { + auto sideIndex = _battleData.Side.GetValue()->GetCreatureIndex(this); + if (!_battleData.Battle.GetValue()->CanSlotBeFilled(_battleData.Side.GetValue()->GetSideIndex(), + sideIndex)) { + _battleData.Side.GetValue()->MarkSlotAsUnfillable(this); + } + _battleData.Battle.GetValue()->ValidateBattleState(); + } } } void PkmnLib::Battling::Pokemon::ClearBattleData() noexcept {