Skip to content

Commit

Permalink
Fixes Eject Items causing wrong pokemon to take damage from entry haz…
Browse files Browse the repository at this point in the history
…ards (rh-hideout#4465)

* Fix hazards damaging the wrong pokemon using eject items

* Added Stealth Rock test as requested

* Added Stealth Rock double battle test
  • Loading branch information
PhallenTree authored and Pawkkie committed May 17, 2024
1 parent dce52f7 commit 6b4ae9b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
15 changes: 15 additions & 0 deletions data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -7195,6 +7195,21 @@ BattleScript_DmgHazardsOnTargetFainted::
moveendall
goto BattleScript_HandleFaintedMon

BattleScript_DmgHazardsOnBattlerScripting::
orword gHitMarker, HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_PASSIVE_DAMAGE
healthbarupdate BS_SCRIPTING
datahpupdate BS_SCRIPTING
call BattleScript_PrintHurtByDmgHazards
tryfaintmon BS_SCRIPTING
tryfaintmon_spikes BS_SCRIPTING, BattleScript_DmgHazardsOnBattlerScriptingFainted
return

BattleScript_DmgHazardsOnBattlerScriptingFainted::
setbyte sGIVEEXP_STATE, 0
getexp BS_SCRIPTING
moveendall
goto BattleScript_HandleFaintedMon

BattleScript_DmgHazardsOnFaintedBattler::
orword gHitMarker, HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_PASSIVE_DAMAGE
healthbarupdate BS_FAINTED
Expand Down
1 change: 1 addition & 0 deletions include/battle_scripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ extern const u8 BattleScript_EncoredNoMore[];
extern const u8 BattleScript_DestinyBondTakesLife[];
extern const u8 BattleScript_DmgHazardsOnAttacker[];
extern const u8 BattleScript_DmgHazardsOnTarget[];
extern const u8 BattleScript_DmgHazardsOnBattlerScripting[];
extern const u8 BattleScript_DmgHazardsOnFaintedBattler[];
extern const u8 BattleScript_PerishSongTakesLife[];
extern const u8 BattleScript_PerishSongCountGoesDown[];
Expand Down
2 changes: 2 additions & 0 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -6937,6 +6937,8 @@ static void SetDmgHazardsBattlescript(u8 battler, u8 multistringId)
gBattlescriptCurrInstr = BattleScript_DmgHazardsOnTarget;
else if (gBattlescriptCurrInstr[1] == BS_ATTACKER)
gBattlescriptCurrInstr = BattleScript_DmgHazardsOnAttacker;
else if (gBattlescriptCurrInstr[1] == BS_SCRIPTING)
gBattlescriptCurrInstr = BattleScript_DmgHazardsOnBattlerScripting;
else
gBattlescriptCurrInstr = BattleScript_DmgHazardsOnFaintedBattler;
}
Expand Down
43 changes: 43 additions & 0 deletions test/battle/move_effect/stealth_rock.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,46 @@ SINGLE_BATTLE_TEST("Stealth Rock damage on switch in based on typing")
HP_BAR(opponent, damage: maxHP / divisor);
}
}

SINGLE_BATTLE_TEST("Stealth Rock damages the correct pokemon when Eject Button is triggered")
{
GIVEN {
PLAYER(SPECIES_METAPOD) { Item(ITEM_EJECT_BUTTON); }
PLAYER(SPECIES_METAPOD);
OPPONENT(SPECIES_JOLTEON);
} WHEN {
TURN { MOVE(opponent, MOVE_STEALTH_ROCK); MOVE(player, MOVE_HARDEN); }
TURN { MOVE(opponent, MOVE_QUICK_ATTACK); MOVE(player, MOVE_HARDEN); SEND_OUT(player, 1); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_STEALTH_ROCK, opponent);
ANIMATION(ANIM_TYPE_MOVE, MOVE_HARDEN, player);
ANIMATION(ANIM_TYPE_MOVE, MOVE_QUICK_ATTACK, opponent);
NOT ANIMATION(ANIM_TYPE_MOVE, MOVE_HARDEN, player);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
MESSAGE("Go! Metapod!");
HP_BAR(player);
} THEN {
EXPECT_EQ(opponent->hp, opponent->maxHP);
}
}

DOUBLE_BATTLE_TEST("Stealth Rock damages the correct pokemon when Eject Button is triggered in double battle")
{
GIVEN {
PLAYER(SPECIES_METAPOD) { Item(ITEM_EJECT_BUTTON); }
PLAYER(SPECIES_METAPOD) { Item(ITEM_EJECT_BUTTON); }
PLAYER(SPECIES_METAPOD);
OPPONENT(SPECIES_JOLTEON);
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(opponentLeft, MOVE_STEALTH_ROCK); MOVE(opponentRight, MOVE_TACKLE, target: playerLeft); SEND_OUT(playerLeft, 2); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_STEALTH_ROCK, opponentLeft);
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponentRight);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, playerLeft);
MESSAGE("Go! Metapod!");
HP_BAR(playerLeft);
} THEN {
EXPECT_EQ(opponentLeft->hp, opponentLeft->maxHP);
}
}

0 comments on commit 6b4ae9b

Please sign in to comment.