From 4b1789ab1e8e9f2ca2d9b7743f0f7eaf4bc53da1 Mon Sep 17 00:00:00 2001 From: Pawkkie <61265402+Pawkkie@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:16:48 -0400 Subject: [PATCH] Fix Wonder Guard potential double switching (#6737) --- src/battle_ai_switch_items.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 3a936a18f5..a6d25ad5b1 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -411,7 +411,7 @@ static bool32 ShouldSwitchIfAllMovesBad(u32 battler) return FALSE; } -static bool32 FindMonThatHitsWonderGuard(u32 battler) +static bool32 ShouldSwitchIfWonderGuard(u32 battler) { u32 opposingBattler = GetOppositeBattler(battler); u32 i, move; @@ -434,7 +434,12 @@ static bool32 FindMonThatHitsWonderGuard(u32 battler) } if (RandomPercentage(RNG_AI_SWITCH_WONDER_GUARD, GetSwitchChance(SHOULD_SWITCH_WONDER_GUARD))) - return FindMonWithMoveOfEffectiveness(battler, opposingBattler, UQ_4_12(2.0)); + { + if (AI_DATA->mostSuitableMonId[battler] == PARTY_SIZE) // No good candidate mons, find any one that can deal damage + return FindMonWithMoveOfEffectiveness(battler, opposingBattler, UQ_4_12(2.0)); + else // Good candidate mon, send that in + return SetSwitchinAndSwitch(battler, PARTY_SIZE); + } return FALSE; } @@ -1145,7 +1150,7 @@ bool32 ShouldSwitch(u32 battler) // FindMon functions can prompt a switch to specific party members that override GetMostSuitableMonToSwitchInto // The rest can prompt a switch to party member returned by GetMostSuitableMonToSwitchInto - if (FindMonThatHitsWonderGuard(battler)) + if (ShouldSwitchIfWonderGuard(battler)) return TRUE; if ((AI_THINKING_STRUCT->aiFlags[GetThinkingBattler(battler)] & AI_FLAG_SMART_SWITCHING) && (CanMonSurviveHazardSwitchin(battler) == FALSE)) return FALSE;