[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
This commit is contained in:
NightKev 2025-01-20 09:12:58 -08:00 committed by GitHub
parent d495c48716
commit d85aedbdfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 46 additions and 5 deletions

View File

@ -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,

View File

@ -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);
});
});
});

View File

@ -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;
}