import { BattlerIndex } from "#enums/battler-index"; import { RandomMoveAttr } from "#app/data/moves/move"; import { Stat } from "#app/enums/stat"; import { MoveResult } from "#enums/move-result"; import { AbilityId } from "#enums/ability-id"; import { MoveId } from "#enums/move-id"; import { SpeciesId } from "#enums/species-id"; import GameManager from "#test/testUtils/gameManager"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; describe("Moves - Copycat", () => { 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([MoveId.COPYCAT, MoveId.SPIKY_SHIELD, MoveId.SWORDS_DANCE, MoveId.SPLASH]) .ability(AbilityId.BALL_FETCH) .battleStyle("single") .criticalHits(false) .enemySpecies(SpeciesId.MAGIKARP) .enemyAbility(AbilityId.BALL_FETCH) .enemyMoveset(MoveId.SPLASH); }); it("should copy the last move successfully executed", async () => { await game.classicMode.startBattle([SpeciesId.FEEBAS]); game.move.select(MoveId.SWORDS_DANCE); await game.move.forceEnemyMove(MoveId.SPLASH); await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]); await game.toNextTurn(); game.move.select(MoveId.COPYCAT); // Last successful move should be Swords Dance await game.move.forceEnemyMove(MoveId.SUCKER_PUNCH); await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]); await game.toNextTurn(); const player = game.field.getPlayerPokemon(); expect(player.getStatStage(Stat.ATK)).toBe(4); expect(player.getLastXMoves()[0].move).toBe(MoveId.SWORDS_DANCE); }); it("should fail if no prior moves have been made", async () => { await game.classicMode.startBattle([SpeciesId.FEEBAS]); game.move.select(MoveId.COPYCAT); await game.move.forceEnemyMove(MoveId.SPLASH); await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.toNextTurn(); expect(game.field.getPlayerPokemon().getLastXMoves()[0].result).toBe(MoveResult.FAIL); }); it("should fail if the last move used is not a valid Copycat move", async () => { await game.classicMode.startBattle([SpeciesId.FEEBAS]); game.move.use(MoveId.COPYCAT); await game.move.forceEnemyMove(MoveId.PROTECT); await game.toNextTurn(); expect(game.field.getPlayerPokemon().getLastXMoves()[0].result).toBe(MoveResult.FAIL); }); it("should copy the called move when the last move successfully calls another", async () => { vi.spyOn(RandomMoveAttr.prototype, "getMove").mockReturnValue(MoveId.SWORDS_DANCE); await game.classicMode.startBattle([SpeciesId.FEEBAS]); game.move.use(MoveId.METRONOME); await game.move.forceEnemyMove(MoveId.COPYCAT); await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]); // Player moves first, so enemy can copy Swords Dance await game.toNextTurn(); expect(game.field.getEnemyPokemon().getStatStage(Stat.ATK)).toBe(2); }); it("should apply move secondary effects", async () => { game.override.enemyMoveset(MoveId.ACID_SPRAY); // Secondary effect lowers SpDef by 2 stages await game.classicMode.startBattle([SpeciesId.FEEBAS]); game.move.use(MoveId.COPYCAT); await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]); await game.toNextTurn(); expect(game.field.getEnemyPokemon().getStatStage(Stat.SPDEF)).toBe(-2); }); });