Skip to content

Commit

Permalink
Fix Pursuit not getting Choice-locked on switch-out (#4801)
Browse files Browse the repository at this point in the history
* Fix Pursuit not getting Choice-locked on switch-out

* use label
  • Loading branch information
DizzyEggg authored Jun 14, 2024
1 parent c7224d9 commit 2716ec5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
4 changes: 3 additions & 1 deletion data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -5739,6 +5739,7 @@ BattleScript_DoSwitchOut::

BattleScript_PursuitDmgOnSwitchOut::
pause B_WAIT_TIME_SHORT
orword gHitMarker, HITMARKER_OBEYS
attackstring
ppreduce
critcalc
Expand All @@ -5756,11 +5757,12 @@ BattleScript_PursuitDmgOnSwitchOut::
resultmessage
waitmessage B_WAIT_TIME_LONG
tryfaintmon BS_TARGET
moveendfromto MOVEEND_ABILITIES, MOVEEND_CHOICE_MOVE
moveendfromto MOVEEND_ABILITIES, MOVEEND_ATTACKER_INVISIBLE @ MOVEEND_CHOICE_MOVE has to be included
jumpiffainted BS_TARGET, FALSE, BattleScript_PursuitDmgOnSwitchOutRet
setbyte sGIVEEXP_STATE, 0
getexp BS_TARGET
BattleScript_PursuitDmgOnSwitchOutRet:
bicword gHitMarker, HITMARKER_OBEYS
return

BattleScript_Pausex20::
Expand Down
47 changes: 25 additions & 22 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -5419,7 +5419,6 @@ static void Cmd_moveend(void)
bool32 effect = FALSE;
u32 moveType = 0;
u32 holdEffectAtk = 0;
u16 *choicedMoveAtk = NULL;
u32 endMode, endState;
u32 originallyUsedMove;

Expand All @@ -5432,7 +5431,6 @@ static void Cmd_moveend(void)
endState = cmd->endState;

holdEffectAtk = GetBattlerHoldEffect(gBattlerAttacker, TRUE);
choicedMoveAtk = &gBattleStruct->choicedMove[gBattlerAttacker];
GET_MOVE_TYPE(gCurrentMove, moveType);

do
Expand Down Expand Up @@ -5642,29 +5640,34 @@ static void Cmd_moveend(void)
gBattleScripting.moveendState++;
break;
case MOVEEND_CHOICE_MOVE: // update choice band move
if (gHitMarker & HITMARKER_OBEYS
&& (HOLD_EFFECT_CHOICE(holdEffectAtk) || GetBattlerAbility(gBattlerAttacker) == ABILITY_GORILLA_TACTICS)
&& gChosenMove != MOVE_STRUGGLE
&& (*choicedMoveAtk == MOVE_NONE || *choicedMoveAtk == MOVE_UNAVAILABLE))
{
if ((gMovesInfo[gChosenMove].effect == EFFECT_BATON_PASS
|| gMovesInfo[gChosenMove].effect == EFFECT_HEALING_WISH)
&& !(gMoveResultFlags & MOVE_RESULT_FAILED))
u16 *choicedMoveAtk = &gBattleStruct->choicedMove[gBattlerAttacker];
if (gHitMarker & HITMARKER_OBEYS
&& (HOLD_EFFECT_CHOICE(holdEffectAtk) || GetBattlerAbility(gBattlerAttacker) == ABILITY_GORILLA_TACTICS)
&& gChosenMove != MOVE_STRUGGLE
&& (*choicedMoveAtk == MOVE_NONE || *choicedMoveAtk == MOVE_UNAVAILABLE))
{
gBattleScripting.moveendState++;
break;
if ((gMovesInfo[gChosenMove].effect == EFFECT_BATON_PASS
|| gMovesInfo[gChosenMove].effect == EFFECT_HEALING_WISH)
&& !(gMoveResultFlags & MOVE_RESULT_FAILED))
{
gBattleScripting.moveendState++;
break;
}
*choicedMoveAtk = gChosenMove;
}
*choicedMoveAtk = gChosenMove;
}
for (i = 0; i < MAX_MON_MOVES; i++)
{
if (gBattleMons[gBattlerAttacker].moves[i] == *choicedMoveAtk)
break;
for (i = 0; i < MAX_MON_MOVES; i++)
{
if (gBattleMons[gBattlerAttacker].moves[i] == *choicedMoveAtk)
break;
}
if (i == MAX_MON_MOVES)
{
*choicedMoveAtk = MOVE_NONE;
}
gBattleScripting.moveendState++;
break;
}
if (i == MAX_MON_MOVES)
*choicedMoveAtk = MOVE_NONE;
gBattleScripting.moveendState++;
break;
case MOVEEND_CHANGED_ITEMS: // changed held items
for (i = 0; i < gBattlersCount; i++)
{
Expand Down Expand Up @@ -13504,7 +13507,7 @@ static void Cmd_jumpifnopursuitswitchdmg(void)
gActionsByTurnOrder[i] = B_ACTION_TRY_FINISH;
}

gCurrentMove = gChosenMoveByBattler[gBattlerTarget];
gCurrentMove = gChosenMove = gChosenMoveByBattler[gBattlerTarget];
gCurrMovePos = gChosenMovePos = *(gBattleStruct->chosenMovePositions + gBattlerTarget);
gBattlescriptCurrInstr = cmd->nextInstr;
gBattleScripting.animTurn = 1;
Expand Down
21 changes: 21 additions & 0 deletions test/battle/move_effect/pursuit.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,25 @@ SINGLE_BATTLE_TEST("Pursuited mon correctly switches out after it got hit and ac
}
}

// Checked so that Pursuit has only 1 PP and it forces the player to use Struggle.
SINGLE_BATTLE_TEST("Pursuit becomes a locked move after being used on switch-out while holding a Choice Item")
{
GIVEN {
ASSUME(gItemsInfo[ITEM_CHOICE_BAND].holdEffect == HOLD_EFFECT_CHOICE_BAND);
PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_CHOICE_BAND); MovesWithPP({MOVE_PURSUIT, 1}, {MOVE_CELEBRATE, 10}, {MOVE_WATER_GUN, 10}, {MOVE_TACKLE, 10}); }
OPPONENT(SPECIES_WYNAUT);
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { SWITCH(opponent, 1); MOVE(player, MOVE_PURSUIT); }
TURN { FORCED_MOVE(player); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_PURSUIT, player);
HP_BAR(opponent);
MESSAGE("2 sent out Wobbuffet!");

MESSAGE("Wobbuffet used Struggle!");
ANIMATION(ANIM_TYPE_MOVE, MOVE_STRUGGLE, player);
}
}

TO_DO_BATTLE_TEST("Baton Pass doesn't cause Pursuit to increase its power or priority");

0 comments on commit 2716ec5

Please sign in to comment.