diff --git a/src/battle_main.c b/src/battle_main.c index a324ec91737..cfd630a1f6b 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3230,6 +3230,13 @@ void SwitchInClearSetData(u32 battler) gBattleStruct->boosterEnergyActivates &= ~(1u << battler); gBattleStruct->canPickupItem &= ~(1u << battler); + if (gBattleStruct->pursuitTarget & (1u << battler)) + { + gBattleStruct->pursuitTarget = 0; + gBattleStruct->pursuitSwitchByMove = FALSE; + gBattleStruct->pursuitStoredSwitch = 0; + } + for (i = 0; i < ARRAY_COUNT(gSideTimers); i++) { // Switched into sticky web user slot, so reset stored battler ID @@ -3360,9 +3367,13 @@ const u8* FaintClearSetData(u32 battler) gBattleStruct->lastTakenMoveFrom[battler][1] = 0; gBattleStruct->lastTakenMoveFrom[battler][2] = 0; gBattleStruct->lastTakenMoveFrom[battler][3] = 0; - gBattleStruct->pursuitTarget = 0; - gBattleStruct->pursuitSwitchByMove = FALSE; - gBattleStruct->pursuitStoredSwitch = 0; + + if (gBattleStruct->pursuitTarget & (1u << battler)) + { + gBattleStruct->pursuitTarget = 0; + gBattleStruct->pursuitSwitchByMove = FALSE; + gBattleStruct->pursuitStoredSwitch = 0; + } gBattleStruct->palaceFlags &= ~(1u << battler); gBattleStruct->boosterEnergyActivates &= ~(1u << battler); diff --git a/test/battle/move_effect/pursuit.c b/test/battle/move_effect/pursuit.c index 5dfa3f8e333..a20b1ed1d12 100644 --- a/test/battle/move_effect/pursuit.c +++ b/test/battle/move_effect/pursuit.c @@ -610,4 +610,67 @@ SINGLE_BATTLE_TEST("Pursuit attacks a switching foe and switchin is correctly st } } +SINGLE_BATTLE_TEST("Pursuit doesn't cause mon with Emergency Exit to switch twice") +{ + GIVEN { + PLAYER(SPECIES_GOLISOPOD) { HP(101); MaxHP(200); Ability(ABILITY_EMERGENCY_EXIT); } + PLAYER(SPECIES_WOBBUFFET); + PLAYER(SPECIES_VOLTORB); + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { SWITCH(player, 1); MOVE(opponent, MOVE_PURSUIT); SEND_OUT(player, 2); } + } SCENE { + SWITCH_OUT_MESSAGE("Golisopod"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_PURSUIT, opponent); + ABILITY_POPUP(player, ABILITY_EMERGENCY_EXIT); + SEND_IN_MESSAGE("Voltorb"); + } THEN { + EXPECT_EQ(player->species, SPECIES_VOLTORB); + } +} + +SINGLE_BATTLE_TEST("Pursuit user gets forced out by Red Card and target still switches out") +{ + GIVEN { + ASSUME(gItemsInfo[ITEM_RED_CARD].holdEffect == HOLD_EFFECT_RED_CARD); + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + PLAYER(SPECIES_VOLTORB); + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_VOLTORB); + } WHEN { + TURN { SWITCH(player, 1); MOVE(opponent, MOVE_PURSUIT); } + } SCENE { + SWITCH_OUT_MESSAGE("Wobbuffet"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_PURSUIT, opponent); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("The opposing Voltorb was dragged out!"); + SEND_IN_MESSAGE("Voltorb"); + } THEN { + EXPECT_EQ(player->species, SPECIES_VOLTORB); + EXPECT_EQ(opponent->species, SPECIES_VOLTORB); + } +} + +SINGLE_BATTLE_TEST("Pursuit user faints to Life Orb and target still switches out") +{ + GIVEN { + ASSUME(gItemsInfo[ITEM_LIFE_ORB].holdEffect == HOLD_EFFECT_LIFE_ORB); + PLAYER(SPECIES_WOBBUFFET); + PLAYER(SPECIES_VOLTORB); + OPPONENT(SPECIES_WOBBUFFET) { Item(ITEM_LIFE_ORB); HP(1); } + OPPONENT(SPECIES_VOLTORB); + } WHEN { + TURN { SWITCH(player, 1); MOVE(opponent, MOVE_PURSUIT); SEND_OUT(opponent, 1); } + } SCENE { + SWITCH_OUT_MESSAGE("Wobbuffet"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_PURSUIT, opponent); + HP_BAR(opponent); + MESSAGE("The opposing Wobbuffet fainted!"); + SEND_IN_MESSAGE("Voltorb"); + } THEN { + EXPECT_EQ(player->species, SPECIES_VOLTORB); + EXPECT_EQ(opponent->species, SPECIES_VOLTORB); + } +} + TO_DO_BATTLE_TEST("Baton Pass doesn't cause Pursuit to increase its power or priority");