pokerogue/test/abilities/anger-point.test.ts
Sirz Benjie 115d63d0c5
[Bug] Fix anger point procing on every hit if first hit in multi hit was a crit
https://github.com/pagefaultgames/pokerogue/pull/6067

* Fix anger point always procing on multi-hit

when first strike was a crit

* Fix comment spacing

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* Rename PostDefendCritStatStageChangeAbAttr

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-07-07 18:38:18 -07:00

79 lines
2.9 KiB
TypeScript

import { PostReceiveCritStatStageChangeAbAttr } from "#app/data/abilities/ability";
import { AbilityId } from "#enums/ability-id";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id";
import { Stat } from "#enums/stat";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Ability - Anger Point", () => {
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
.ability(AbilityId.BALL_FETCH)
.battleStyle("single")
.criticalHits(false)
.enemySpecies(SpeciesId.MAGIKARP)
.enemyAbility(AbilityId.BALL_FETCH)
.enemyMoveset(MoveId.SPLASH)
.enemyLevel(100);
});
it("should set the user's attack stage to +6 when hit by a critical hit", async () => {
game.override.enemyAbility(AbilityId.ANGER_POINT).moveset(MoveId.FALSE_SWIPE);
await game.classicMode.startBattle([SpeciesId.MAGIKARP]);
const enemy = game.scene.getEnemyPokemon()!;
// minimize the enemy's attack stage to ensure it is always set to +6
enemy.setStatStage(Stat.ATK, -6);
vi.spyOn(enemy, "getCriticalHitResult").mockReturnValueOnce(true);
game.move.select(MoveId.FALSE_SWIPE);
await game.phaseInterceptor.to("BerryPhase");
expect(enemy.getStatStage(Stat.ATK)).toBe(6);
});
it("should only proc once when a multi-hit move crits on the first hit", async () => {
game.override
.moveset(MoveId.BULLET_SEED)
.enemyLevel(50)
.enemyAbility(AbilityId.ANGER_POINT)
.ability(AbilityId.SKILL_LINK);
await game.classicMode.startBattle([SpeciesId.FEEBAS]);
const enemy = game.scene.getEnemyPokemon()!;
vi.spyOn(enemy, "getCriticalHitResult").mockReturnValueOnce(true);
const angerPointSpy = vi.spyOn(PostReceiveCritStatStageChangeAbAttr.prototype, "apply");
game.move.select(MoveId.BULLET_SEED);
await game.phaseInterceptor.to("BerryPhase");
expect(angerPointSpy).toHaveBeenCalledTimes(1);
});
it("should set a contrary user's attack stage to -6 when hit by a critical hit", async () => {
game.override
.enemyAbility(AbilityId.ANGER_POINT)
.enemyPassiveAbility(AbilityId.CONTRARY)
.enemyHasPassiveAbility(true)
.moveset(MoveId.FALSE_SWIPE);
await game.classicMode.startBattle([SpeciesId.MAGIKARP]);
const enemy = game.scene.getEnemyPokemon()!;
vi.spyOn(enemy, "getCriticalHitResult").mockReturnValueOnce(true);
enemy.setStatStage(Stat.ATK, 6);
game.move.select(MoveId.FALSE_SWIPE);
await game.phaseInterceptor.to("BerryPhase");
expect(enemy.getStatStage(Stat.ATK)).toBe(-6);
});
});