From 0e794fe2fc2cc586e72ee10da8c64d25bd119f7c Mon Sep 17 00:00:00 2001 From: Adrian T <68144167+torranx@users.noreply.github.com> Date: Thu, 13 Jun 2024 23:37:15 +0800 Subject: [PATCH] [Bug] Fix Berserk and Anger Shell from crashing the game when pokemon is forced to switch out (#1699) * fix PostDefendHpGatedStatChangeAbAttr crashing the game * remove new line * refactor condition * refactor condition --- src/data/ability.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 82d72e9ac52..0365e740672 100755 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -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; }