From d85aedbdfc87a59840f0cdad2f781761d212197a Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Mon, 20 Jan 2025 09:12:58 -0800 Subject: [PATCH] [Bug] Prevent pokemon with 0 HP from being statused (#5137) * [Bug] Prevent pokemon with 0 HP from being statused * Update test * Move check to `trySetStatus()` and update test --- src/field/pokemon.ts | 3 ++ ...s-effect.test.ts => status_effect.test.ts} | 38 +++++++++++++++++++ src/utils.ts | 10 ++--- 3 files changed, 46 insertions(+), 5 deletions(-) rename src/test/data/{status-effect.test.ts => status_effect.test.ts} (92%) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index a833facd2f8..a4b8603cbb0 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -3606,6 +3606,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (!this.canSetStatus(effect, asPhase, false, sourcePokemon)) { return false; } + if (this.isFainted() && effect !== StatusEffect.FAINT) { + return false; + } /** * If this Pokemon falls asleep or freezes in the middle of a multi-hit attack, diff --git a/src/test/data/status-effect.test.ts b/src/test/data/status_effect.test.ts similarity index 92% rename from src/test/data/status-effect.test.ts rename to src/test/data/status_effect.test.ts index 4831e8de5de..7948549b8e8 100644 --- a/src/test/data/status-effect.test.ts +++ b/src/test/data/status_effect.test.ts @@ -400,4 +400,42 @@ describe("Status Effects", () => { expect(player.getLastXMoves(1)[0].result).toBe(MoveResult.SUCCESS); }); }); + + describe("Behavior", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + game.override + .moveset([ Moves.SPLASH ]) + .ability(Abilities.BALL_FETCH) + .battleType("single") + .disableCrits() + .enemySpecies(Species.MAGIKARP) + .enemyAbility(Abilities.BALL_FETCH) + .enemyMoveset(Moves.NUZZLE) + .enemyLevel(2000); + }); + + it("should not inflict a 0 HP mon with a status", async () => { + await game.classicMode.startBattle([ Species.FEEBAS, Species.MILOTIC ]); + + const player = game.scene.getPlayerPokemon()!; + player.hp = 0; + + expect(player.trySetStatus(StatusEffect.BURN)).toBe(false); + expect(player.status?.effect).not.toBe(StatusEffect.BURN); + }); + }); }); diff --git a/src/utils.ts b/src/utils.ts index be0aec84ecd..2235fb69633 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -349,14 +349,14 @@ export class IntegerHolder extends NumberHolder { } } -/** @deprecated Use {@linkcode NumberHolder}*/ -export class FixedInt extends IntegerHolder { - constructor(value: integer) { - super(value); +export class FixedInt { + public readonly value: number; + + constructor(value: number) { + this.value = value; } } -/** @deprecated */ export function fixedInt(value: integer): integer { return new FixedInt(value) as unknown as integer; }