From 7fd1404354a8bf5c56627dacffde72df0deb7b11 Mon Sep 17 00:00:00 2001 From: moostoet <70690976+moostoet@users.noreply.github.com> Date: Mon, 17 Nov 2025 18:03:41 +0100 Subject: [PATCH] Fix Magic Coat reflecting hazard moves incorrectly when used by a partner (#8272) --- src/battle_script_commands.c | 21 +++++++++++++++++++- test/battle/move_effect/magic_coat.c | 29 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 4c2ac13178..e100d3a9ca 100755 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1167,7 +1167,26 @@ static void Cmd_attackcanceler(void) } u32 isBounceable = MoveCanBeBouncedBack(gCurrentMove); - if (gProtectStructs[gBattlerTarget].bounceMove + bool32 bounceActive = (gProtectStructs[gBattlerTarget].bounceMove && IsBattlerAlive(gBattlerTarget)); + + if (!bounceActive + && !gBattleStruct->bouncedMoveIsUsed + && isBounceable + && GetBattlerMoveTargetType(gBattlerAttacker, gCurrentMove) == MOVE_TARGET_OPPONENTS_FIELD) + { + u32 partner = BATTLE_PARTNER(gBattlerTarget); + + if (partner < gBattlersCount + && GetBattlerSide(partner) == GetBattlerSide(gBattlerTarget) + && gProtectStructs[partner].bounceMove + && IsBattlerAlive(partner)) + { + gBattlerTarget = partner; + bounceActive = TRUE; + } + } + + if (bounceActive && isBounceable && !gBattleStruct->bouncedMoveIsUsed) { diff --git a/test/battle/move_effect/magic_coat.c b/test/battle/move_effect/magic_coat.c index 50ed79e194..ca7b78883e 100644 --- a/test/battle/move_effect/magic_coat.c +++ b/test/battle/move_effect/magic_coat.c @@ -32,3 +32,32 @@ SINGLE_BATTLE_TEST("Magic Coat prints the correct message when bouncing back a m STATUS_ICON(opponent, sleep: TRUE); } } + +DOUBLE_BATTLE_TEST("Magic Coat reflects hazards regardless of the user's position") +{ + struct BattlePokemon *coatUser = NULL; + PARAMETRIZE { coatUser = playerLeft; } + PARAMETRIZE { coatUser = playerRight; } + ASSUME(GetMoveEffect(MOVE_SPIKES) == EFFECT_SPIKES); + ASSUME(GetMoveEffect(MOVE_STEALTH_ROCK) == EFFECT_STEALTH_ROCK); + + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + PLAYER(SPECIES_WYNAUT); + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(coatUser, MOVE_MAGIC_COAT); MOVE(opponentRight, MOVE_STEALTH_ROCK); MOVE(opponentLeft, MOVE_SPIKES); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_MAGIC_COAT, coatUser); + NONE_OF { + ANIMATION(ANIM_TYPE_MOVE, MOVE_STEALTH_ROCK, opponentRight); + ANIMATION(ANIM_TYPE_MOVE, MOVE_SPIKES, opponentLeft); + } + } THEN { + EXPECT(!IsHazardOnSide(B_SIDE_PLAYER, HAZARDS_STEALTH_ROCK)); + EXPECT(!IsHazardOnSide(B_SIDE_PLAYER, HAZARDS_SPIKES)); + EXPECT(IsHazardOnSide(B_SIDE_OPPONENT, HAZARDS_STEALTH_ROCK)); + EXPECT(IsHazardOnSide(B_SIDE_OPPONENT, HAZARDS_SPIKES)); + } +}