From 5dd2bde1d6dace6662be58959d0757010e4fccf4 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Fri, 13 Sep 2024 10:22:21 +0200 Subject: [PATCH] Fixes Defog used by the wrong side when there is a Substitue and Screen --- src/battle_script_commands.c | 7 ++++++- test/battle/move_effect/defog.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 76c39377a179..bfb7eec56d11 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -8637,6 +8637,10 @@ static void RemoveAllTerrains(void) BattleScriptPushCursor(); \ gBattlescriptCurrInstr = battlescript; \ } \ + else \ + { \ + gBattlerAttacker = saveBattler; \ + } \ return TRUE; \ } \ } @@ -8651,9 +8655,9 @@ static bool32 TryDefogClear(u32 battlerAtk, bool32 clear) struct SideTimer *sideTimer = &gSideTimers[i]; u32 *sideStatuses = &gSideStatuses[i]; - gBattlerAttacker = i; // For correct battle string. Ally's / Foe's if (GetBattlerSide(battlerAtk) != i) { + gBattlerAttacker = i; // For correct battle string. Ally's / Foe's DEFOG_CLEAR(SIDE_STATUS_REFLECT, reflectTimer, BattleScript_SideStatusWoreOffReturn, MOVE_REFLECT); DEFOG_CLEAR(SIDE_STATUS_LIGHTSCREEN, lightscreenTimer, BattleScript_SideStatusWoreOffReturn, MOVE_LIGHT_SCREEN); DEFOG_CLEAR(SIDE_STATUS_MIST, mistTimer, BattleScript_SideStatusWoreOffReturn, MOVE_MIST); @@ -8662,6 +8666,7 @@ static bool32 TryDefogClear(u32 battlerAtk, bool32 clear) } if (B_DEFOG_EFFECT_CLEARING >= GEN_6) { + gBattlerAttacker = i; // For correct battle string. Ally's / Foe's DEFOG_CLEAR(SIDE_STATUS_SPIKES, spikesAmount, BattleScript_SpikesDefog, 0); DEFOG_CLEAR(SIDE_STATUS_STEALTH_ROCK, stealthRockAmount, BattleScript_StealthRockDefog, 0); DEFOG_CLEAR(SIDE_STATUS_TOXIC_SPIKES, toxicSpikesAmount, BattleScript_ToxicSpikesDefog, 0); diff --git a/test/battle/move_effect/defog.c b/test/battle/move_effect/defog.c index 80d500d2ee20..ab6d647a9768 100644 --- a/test/battle/move_effect/defog.c +++ b/test/battle/move_effect/defog.c @@ -383,3 +383,21 @@ DOUBLE_BATTLE_TEST("Defog lowers evasiveness by 1 and removes everything it can" } } } + +SINGLE_BATTLE_TEST("Defog is used on the correct side if opposing mon is behind a substitute with Screen up") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_LIGHT_SCREEN); } + TURN { MOVE(opponent, MOVE_SUBSTITUTE); MOVE(player, MOVE_DEFOG); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_LIGHT_SCREEN, opponent); + ANIMATION(ANIM_TYPE_MOVE, MOVE_SUBSTITUTE, opponent); + MESSAGE("Wobbuffet used Defog!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_DEFOG, player); + MESSAGE("Foe Wobbuffet's evasiveness fell!"); + MESSAGE("Foe's Light Screen wore off!"); + } +}