fix: emergency exit cutoff off by 1 on odd max hp (#4040)
* fix: emergency exit cutoff off by 1 on odd max hp * squash!: newline at end of file --------- Co-authored-by: sbird <sbird@no.tld>
This commit is contained in:
parent
d125da7797
commit
73a1fa30e9
2 changed files with 27 additions and 5 deletions
|
@ -4211,11 +4211,14 @@ static uq4_12_t GetSupremeOverlordModifier(u32 battler)
|
|||
return modifier;
|
||||
}
|
||||
|
||||
static bool32 HadMoreThanHalfHpNowHasLess(u32 battler)
|
||||
static inline bool32 HadMoreThanHalfHpNowHasLess(u32 battler)
|
||||
{
|
||||
u32 cutoff = gBattleMons[battler].maxHP / 2;
|
||||
if (gBattleMons[battler].maxHP % 2 == 1)
|
||||
cutoff++;
|
||||
// Had more than half of hp before, now has less
|
||||
return (gBattleStruct->hpBefore[battler] >= gBattleMons[battler].maxHP / 2
|
||||
&& gBattleMons[battler].hp < gBattleMons[battler].maxHP / 2);
|
||||
return (gBattleStruct->hpBefore[battler] >= cutoff
|
||||
&& gBattleMons[battler].hp < cutoff);
|
||||
}
|
||||
|
||||
u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 moveArg)
|
||||
|
@ -5271,8 +5274,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
|
|||
&& TARGET_TURN_DAMAGED
|
||||
&& IsBattlerAlive(battler)
|
||||
// Had more than half of hp before, now has less
|
||||
&& gBattleStruct->hpBefore[battler] > gBattleMons[battler].maxHP / 2
|
||||
&& gBattleMons[battler].hp < gBattleMons[battler].maxHP / 2
|
||||
&& HadMoreThanHalfHpNowHasLess(battler)
|
||||
&& (gMultiHitCounter == 0 || gMultiHitCounter == 1)
|
||||
&& !(TestSheerForceFlag(gBattlerAttacker, gCurrentMove))
|
||||
&& (CanBattlerSwitch(battler) || !(gBattleTypeFlags & BATTLE_TYPE_TRAINER))
|
||||
|
|
20
test/battle/ability/emergency_exit.c
Normal file
20
test/battle/ability/emergency_exit.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "global.h"
|
||||
#include "test/battle.h"
|
||||
|
||||
SINGLE_BATTLE_TEST("Emergency Exit switches out when taking 50% max-hp damage")
|
||||
{
|
||||
GIVEN {
|
||||
PLAYER(SPECIES_WOBBUFFET) { Attack(1314); }; // will deal exactly 132 damage, putting GOLISOPOD just under half hp
|
||||
OPPONENT(SPECIES_GOLISOPOD) { Ability(ABILITY_EMERGENCY_EXIT); MaxHP(263); HP(263); };
|
||||
OPPONENT(SPECIES_WOBBUFFET);
|
||||
} WHEN {
|
||||
TURN {
|
||||
MOVE(player, MOVE_POUND);
|
||||
SEND_OUT(opponent, 1);
|
||||
}
|
||||
} SCENE {
|
||||
ANIMATION(ANIM_TYPE_MOVE, MOVE_POUND, player);
|
||||
HP_BAR(opponent);
|
||||
ABILITY_POPUP(opponent, ABILITY_EMERGENCY_EXIT);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue