From 1563b8e581b75016c776deaba6d640d398097d7d Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:46:22 -0700 Subject: [PATCH] [Test] Add test for rollout move (#3114) * add test for rollout move Co-authored-by: Zach Day * fix tests still using `SINGLE_BATTLE_OVERRIDE` --------- Co-authored-by: Zach Day --- src/test/moves/rollout.test.ts | 82 ++++++++++++++++++++++++++++++++ src/test/moves/spit_up.test.ts | 2 +- src/test/moves/stockpile.test.ts | 2 +- src/test/moves/swallow.test.ts | 2 +- src/test/utils/testUtils.ts | 5 ++ 5 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 src/test/moves/rollout.test.ts diff --git a/src/test/moves/rollout.test.ts b/src/test/moves/rollout.test.ts new file mode 100644 index 00000000000..6d8828455e4 --- /dev/null +++ b/src/test/moves/rollout.test.ts @@ -0,0 +1,82 @@ +import { allMoves } from "#app/data/move.js"; +import Overrides from "#app/overrides"; +import { CommandPhase } from "#app/phases"; +import GameManager from "#app/test/utils/gameManager"; +import { getMovePosition } from "#app/test/utils/gameManagerUtils"; +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { SPLASH_ONLY } from "../utils/testUtils"; + +describe("Moves - Rollout", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + vi.spyOn(Overrides, "NEVER_CRIT_OVERRIDE", "get").mockReturnValue(true); + vi.spyOn(Overrides, "BATTLE_TYPE_OVERRIDE", "get").mockReturnValue("single"); + vi.spyOn(Overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.RATTATA); + vi.spyOn(Overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.NONE); + vi.spyOn(Overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.BIDOOF); + vi.spyOn(Overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.NONE); + vi.spyOn(Overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(100); + vi.spyOn(Overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(100); + vi.spyOn(Overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue(SPLASH_ONLY); + }); + + it("should double it's dmg on sequential uses but reset after 5", async () => { + vi.spyOn(Overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.ROLLOUT]); + vi.spyOn(allMoves[Moves.ROLLOUT], "accuracy", "get").mockReturnValue(100); //always hit + + const variance = 5; + const turns = 6; + const dmgHistory: number[] = []; + + await game.startBattle(); + + const playerPkm = game.scene.getParty()[0]; + vi.spyOn(playerPkm, "stats", "get").mockReturnValue([500000, 1, 1, 1, 1, 1]); // HP, ATK, DEF, SPATK, SPDEF, SPD + + const enemyPkm = game.scene.getEnemyParty()[0]; + vi.spyOn(enemyPkm, "stats", "get").mockReturnValue([500000, 1, 1, 1, 1, 1]); // HP, ATK, DEF, SPATK, SPDEF, SPD + vi.spyOn(enemyPkm, "getHeldItems").mockReturnValue([]); //no berries + + enemyPkm.hp = enemyPkm.getMaxHp(); + let previousHp = enemyPkm.hp; + + for (let i = 0; i < turns; i++) { + game.doAttack(getMovePosition(game.scene, 0, Moves.ROLLOUT)); + await game.phaseInterceptor.to(CommandPhase); + + dmgHistory.push(previousHp - enemyPkm.hp); + previousHp = enemyPkm.hp; + } + + const [turn1Dmg, turn2Dmg, turn3Dmg, turn4Dmg, turn5Dmg, turn6Dmg] = dmgHistory; + + expect(turn2Dmg).toBeGreaterThanOrEqual(turn1Dmg * 2 - variance); + expect(turn2Dmg).toBeLessThanOrEqual(turn1Dmg * 2 + variance); + expect(turn3Dmg).toBeGreaterThanOrEqual(turn2Dmg * 2 - variance); + expect(turn3Dmg).toBeLessThanOrEqual(turn2Dmg * 2 + variance); + expect(turn4Dmg).toBeGreaterThanOrEqual(turn3Dmg * 2 - variance); + expect(turn4Dmg).toBeLessThanOrEqual(turn3Dmg * 2 + variance); + expect(turn5Dmg).toBeGreaterThanOrEqual(turn4Dmg * 2 - variance); + expect(turn5Dmg).toBeLessThanOrEqual(turn4Dmg * 2 + variance); + // reset + expect(turn6Dmg).toBeGreaterThanOrEqual(turn1Dmg - variance); + expect(turn6Dmg).toBeLessThanOrEqual(turn1Dmg + variance); + }); +}); diff --git a/src/test/moves/spit_up.test.ts b/src/test/moves/spit_up.test.ts index 6b24275f3e3..f136d8f1e2b 100644 --- a/src/test/moves/spit_up.test.ts +++ b/src/test/moves/spit_up.test.ts @@ -27,7 +27,7 @@ describe("Moves - Spit Up", () => { beforeEach(() => { game = new GameManager(phaserGame); - vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); + vi.spyOn(overrides, "BATTLE_TYPE_OVERRIDE", "get").mockReturnValue("single"); vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.RATTATA); vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH]); diff --git a/src/test/moves/stockpile.test.ts b/src/test/moves/stockpile.test.ts index 4f9688e6dd9..1a23017c6b3 100644 --- a/src/test/moves/stockpile.test.ts +++ b/src/test/moves/stockpile.test.ts @@ -27,7 +27,7 @@ describe("Moves - Stockpile", () => { beforeEach(() => { game = new GameManager(phaserGame); - vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); + vi.spyOn(overrides, "BATTLE_TYPE_OVERRIDE", "get").mockReturnValue("single"); vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.RATTATA); vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH]); diff --git a/src/test/moves/swallow.test.ts b/src/test/moves/swallow.test.ts index 2d1ab55879a..0dd4237c232 100644 --- a/src/test/moves/swallow.test.ts +++ b/src/test/moves/swallow.test.ts @@ -26,7 +26,7 @@ describe("Moves - Swallow", () => { beforeEach(() => { game = new GameManager(phaserGame); - vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); + vi.spyOn(overrides, "BATTLE_TYPE_OVERRIDE", "get").mockReturnValue("single"); vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.RATTATA); vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH]); diff --git a/src/test/utils/testUtils.ts b/src/test/utils/testUtils.ts index b922fc9c61c..0a9be16a4b5 100644 --- a/src/test/utils/testUtils.ts +++ b/src/test/utils/testUtils.ts @@ -1,6 +1,10 @@ +import { Moves } from "#app/enums/moves.js"; import i18next, { type ParseKeys } from "i18next"; import { vi } from "vitest"; +/** Ready to use array of Moves.SPLASH x4 */ +export const SPLASH_ONLY = [Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH]; + /** * Sets up the i18next mock. * Includes a i18next.t mocked implementation only returning the raw key (`(key) => key`) @@ -21,3 +25,4 @@ export function mockI18next() { export function arrayOfRange(start: integer, end: integer) { return Array.from({ length: end - start }, (_v, k) => k + start); } +