Skip to content

Commit

Permalink
[Bug] Fix Berserk and Anger Shell from crashing the game when pokemon…
Browse files Browse the repository at this point in the history
… is forced to switch out (pagefaultgames#1699)

* fix PostDefendHpGatedStatChangeAbAttr crashing the game

* remove new line

* refactor condition

* refactor condition
  • Loading branch information
torranx authored Jun 13, 2024
1 parent e6c24dc commit 0e794fe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/data/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,9 @@ export class PostDefendHpGatedStatChangeAbAttr extends PostDefendAbAttr {
applyPostDefend(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: Move, hitResult: HitResult, args: any[]): boolean {
const hpGateFlat: integer = Math.ceil(pokemon.getMaxHp() * this.hpGate);
const lastAttackReceived = pokemon.turnData.attacksReceived[pokemon.turnData.attacksReceived.length - 1];
if (this.condition(pokemon, attacker, move) && (pokemon.hp <= hpGateFlat && (pokemon.hp + lastAttackReceived.damage) > hpGateFlat)) {
const damageReceived = lastAttackReceived?.damage || 0;

if (this.condition(pokemon, attacker, move) && (pokemon.hp <= hpGateFlat && (pokemon.hp + damageReceived) > hpGateFlat)) {
pokemon.scene.unshiftPhase(new StatChangePhase(pokemon.scene, (this.selfTarget ? pokemon : attacker).getBattlerIndex(), true, this.stats, this.levels));
return true;
}
Expand Down

0 comments on commit 0e794fe

Please sign in to comment.