pokerogue/test/moves/disable.test.ts
Bertie690 5efdb0dc0b
[Refactor] Fix issues with "last move selected" vs "used" (#5810)
* Added `MoveUseType` and refactored MEP

* Fixed Wimp out tests & ME code

finally i think all the booleans are gone
i hope

* Added version migration for last resort and co.

buh gumbug

* Fixed various bugs and added tests for previous bugfixes

* Reverted a couple doc changes

* WIP

* Update pokemon-species.ts

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

* Update pokemon-phase.ts

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

* Fixed remaining tests (I think)

* Reverted rollout test changes

* Fixed command phase bug causing metronome test timeout

* Revert early_bird.test.ts

* Fix biome.jsonc

* Made `MoveUseType` start at 1

As per @DayKev's request

* Fixed a thing

* Fixed bolt beak condition to be marginally less jank

* Applied some review suggestions

* Reverted move phase operations

* Added helper functions complete with markdown tables

* Fixed things

* Update battler-tags.ts

* Fixed random issues

* Fixed code

* Fixed comment

* Fixed import issues

* Fix disable.test.ts conflicts

* Update instruct.test.ts

* Update `biome.jsonc`

* Renamed `MoveUseType` to `MoveUseMode`; applied review comments

* Fixed space

* Fixed phasemanager bugs

* Fixed instruct test to not bork

* Fixed gorilla tactics bug

* Battler Tags doc fixes

* Fixed formatting and suttff

* Minor comment updates and remove unused imports in `move.ts`

* Re-add `public`, remove unnecessary default value in `battler-tags.ts`

* Restore `{}` in `turn-start-phase.ts`

Fixes `lint/correctness/noSwitchDeclarations`

* Remove extra space in TSDoc in `move-phase.ts`

* Use `game.field` instead of `game.scene` in `instruct.test.ts`

Also `game.toEndOfTurn()` instead of
`game.phaseInterceptor.to("BerryPhase")`

* Use `game.field` instead of `game.scene` in `metronome.test.ts`

* Use `toEndOfTurn()` instead of `to("BerryPhase")` in `powder.test.ts`

* Convert `MoveUseMode` enum to `const` object

* Update move-phase.ts

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

* Add `enumValueToKey` utility function

* Apply Biome

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-06-15 10:52:44 -07:00

180 lines
6.6 KiB
TypeScript

import { BattlerIndex } from "#enums/battler-index";
import { MoveResult } from "#enums/move-result";
import { AbilityId } from "#enums/ability-id";
import { MoveUseMode } from "#enums/move-use-mode";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id";
import { Stat } from "#enums/stat";
import GameManager from "#test/testUtils/gameManager";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { RandomMoveAttr } from "#app/data/moves/move";
describe("Moves - Disable", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(async () => {
game = new GameManager(phaserGame);
game.override
.battleStyle("single")
.ability(AbilityId.BALL_FETCH)
.enemyAbility(AbilityId.BALL_FETCH)
.moveset([MoveId.DISABLE, MoveId.SPLASH])
.enemyMoveset(MoveId.SPLASH)
.enemySpecies(SpeciesId.SHUCKLE);
});
it("should restrict the last move used", async () => {
await game.classicMode.startBattle([SpeciesId.PIKACHU]);
const enemyMon = game.field.getEnemyPokemon();
game.move.select(MoveId.SPLASH);
await game.move.forceEnemyMove(MoveId.GROWL);
await game.toNextTurn();
game.move.select(MoveId.DISABLE);
await game.move.forceEnemyMove(MoveId.SPLASH);
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.toNextTurn();
expect(enemyMon.getLastXMoves(-1)).toHaveLength(2);
expect(enemyMon.isMoveRestricted(MoveId.SPLASH)).toBe(true);
expect(enemyMon.isMoveRestricted(MoveId.GROWL)).toBe(false);
});
it("should fail if enemy has no move history", async () => {
await game.classicMode.startBattle([SpeciesId.PIKACHU]);
const playerMon = game.field.getPlayerPokemon();
const enemyMon = game.field.getEnemyPokemon();
game.move.select(MoveId.DISABLE);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.toNextTurn();
expect(playerMon.getLastXMoves()[0]).toMatchObject({
move: MoveId.DISABLE,
result: MoveResult.FAIL,
});
expect(enemyMon.isMoveRestricted(MoveId.SPLASH)).toBe(false);
});
it("causes STRUGGLE if all usable moves are disabled", async () => {
await game.classicMode.startBattle([SpeciesId.PIKACHU]);
const enemyMon = game.field.getEnemyPokemon();
game.move.select(MoveId.DISABLE);
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.toNextTurn();
game.move.select(MoveId.SPLASH);
await game.toNextTurn();
const enemyHistory = enemyMon.getLastXMoves(-1);
expect(enemyHistory).toHaveLength(2);
expect(enemyHistory.map(m => m.move)).toEqual([MoveId.STRUGGLE, MoveId.SPLASH]);
});
it("should fail if it would otherwise disable struggle", async () => {
await game.classicMode.startBattle([SpeciesId.PIKACHU]);
const playerMon = game.field.getPlayerPokemon();
const enemyMon = game.field.getEnemyPokemon();
game.move.select(MoveId.DISABLE);
await game.move.forceEnemyMove(MoveId.STRUGGLE);
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.toNextTurn();
expect(playerMon.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
expect(enemyMon.getLastXMoves()[0].move).toBe(MoveId.STRUGGLE);
expect(enemyMon.isMoveRestricted(MoveId.STRUGGLE)).toBe(false);
});
it("should interrupt target's move if used first", async () => {
await game.classicMode.startBattle([SpeciesId.PIKACHU]);
const enemyMon = game.field.getEnemyPokemon();
// add splash to enemy move history
enemyMon.pushMoveHistory({
move: MoveId.SPLASH,
targets: [BattlerIndex.ENEMY],
useMode: MoveUseMode.NORMAL,
});
game.move.select(MoveId.DISABLE);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.toNextTurn();
const enemyHistory = enemyMon.getLastXMoves(-1);
expect(enemyHistory).toHaveLength(2);
expect(enemyHistory[0].result).toBe(MoveResult.FAIL);
});
it.each([
{ name: "Nature Power", moveId: MoveId.NATURE_POWER },
{ name: "Mirror Move", moveId: MoveId.MIRROR_MOVE },
{ name: "Copycat", moveId: MoveId.COPYCAT },
{ name: "Metronome", moveId: MoveId.METRONOME },
])("should ignore virtual moves called by $name", async ({ moveId }) => {
vi.spyOn(RandomMoveAttr.prototype, "getMoveOverride").mockReturnValue(MoveId.ABSORB);
await game.classicMode.startBattle([SpeciesId.PIKACHU]);
const playerMon = game.scene.getPlayerPokemon()!;
playerMon.pushMoveHistory({ move: MoveId.SPLASH, targets: [BattlerIndex.ENEMY], useMode: MoveUseMode.NORMAL });
game.scene.currentBattle.lastMove = MoveId.SPLASH;
game.move.select(MoveId.DISABLE);
await game.move.forceEnemyMove(moveId);
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.toNextTurn();
const enemyMon = game.scene.getEnemyPokemon()!;
expect(enemyMon.isMoveRestricted(moveId), `calling move ${MoveId[moveId]} was not disabled`).toBe(true);
expect(enemyMon.getLastXMoves(-1)).toHaveLength(2);
const calledMove = enemyMon.getLastXMoves()[0].move;
expect(
enemyMon.isMoveRestricted(calledMove),
`called move ${MoveId[calledMove]} (from ${MoveId[moveId]}) was incorrectly disabled`,
).toBe(false);
});
it("should ignore dancer copied moves, even if also in moveset", async () => {
game.override
.enemyAbility(AbilityId.DANCER)
.moveset([MoveId.DISABLE, MoveId.SWORDS_DANCE])
.enemyMoveset([MoveId.SPLASH, MoveId.SWORDS_DANCE]);
await game.classicMode.startBattle([SpeciesId.PIKACHU]);
game.move.select(MoveId.SWORDS_DANCE);
await game.move.selectEnemyMove(MoveId.SPLASH);
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.toNextTurn();
game.move.select(MoveId.DISABLE);
await game.move.selectEnemyMove(MoveId.SWORDS_DANCE);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.toNextTurn();
// Dancer-induced Swords Dance was ignored in favor of splash,
// leaving the subsequent _normal_ swords dance free to work as normal
const shuckle = game.field.getEnemyPokemon();
expect.soft(shuckle.isMoveRestricted(MoveId.SPLASH)).toBe(true);
expect.soft(shuckle.isMoveRestricted(MoveId.SWORDS_DANCE)).toBe(false);
expect(shuckle.getLastXMoves()[0]).toMatchObject({ move: MoveId.SWORDS_DANCE, result: MoveResult.SUCCESS });
expect(shuckle.getStatStage(Stat.ATK)).toBe(4);
});
});