From 9b547e0870355a08e957de4a95eed78dd062efe2 Mon Sep 17 00:00:00 2001 From: xsn34kzx Date: Thu, 11 Jul 2024 02:29:40 -0400 Subject: [PATCH] [Test] Add Unit Tests for Dynamax Cannon --- src/test/moves/dynamax_cannon.test.ts | 243 ++++++++++++++++++++++++++ src/test/moves/dynamax_cannon_test.ts | 66 ------- 2 files changed, 243 insertions(+), 66 deletions(-) create mode 100644 src/test/moves/dynamax_cannon.test.ts delete mode 100644 src/test/moves/dynamax_cannon_test.ts diff --git a/src/test/moves/dynamax_cannon.test.ts b/src/test/moves/dynamax_cannon.test.ts new file mode 100644 index 000000000000..cdd19ec8212f --- /dev/null +++ b/src/test/moves/dynamax_cannon.test.ts @@ -0,0 +1,243 @@ +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import Phaser from "phaser"; +import GameManager from "#app/test/utils/gameManager"; +import * as overrides from "#app/overrides"; +import { Species } from "#enums/species"; +import { MoveEffectPhase } from "#app/phases"; +import { Moves } from "#enums/moves"; +import { getMovePosition } from "#app/test/utils/gameManagerUtils"; +import { Stat } from "#app/data/pokemon-stat"; +import { applyMoveAttrs, VariablePowerAttr } from "#app/data/move"; +import * as Utils from "#app/utils"; + +describe("Moves - Dynamax Cannon", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + const moveToUse = Moves.DYNAMAX_CANNON; + + // Note that, for Waves 1-10, the level cap is 10 + vi.spyOn(overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(1); + vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); + vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.MAGIKARP); + vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(200); + vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([ moveToUse ]); + vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([ Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH ]); + vi.spyOn(overrides, "NEVER_CRIT_OVERRIDE", "get").mockReturnValue(true); + }); + + it("DYNAMAX CANNON against enemy below level cap", async() => { + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(1); + const moveToUse = Moves.DYNAMAX_CANNON; + await game.startBattle([ + Species.ETERNATUS, + ]); + + game.doAttack(getMovePosition(game.scene, 0, moveToUse)); + + await game.phaseInterceptor.to(MoveEffectPhase, false); + + // Check initial base power of Dynamax Cannon + const phase = game.scene.getCurrentPhase() as MoveEffectPhase; + const move = phase.move.getMove(); + expect(move.id).toBe(moveToUse); + expect(move.power).toBe(100); + + // Check base power of Dynamax Cannon in context + const power = new Utils.IntegerHolder(move.power); + applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), phase.getTarget(), move, power); + expect(power.value).toBe(100); + }, 20000); + + it("DYNAMAX CANNON against enemy at level cap", async() => { + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(10); + const moveToUse = Moves.DYNAMAX_CANNON; + await game.startBattle([ + Species.ETERNATUS, + ]); + + game.doAttack(getMovePosition(game.scene, 0, moveToUse)); + + await game.phaseInterceptor.to(MoveEffectPhase, false); + + // Check initial base power of Dynamax Cannon + const phase = game.scene.getCurrentPhase() as MoveEffectPhase; + const move = phase.move.getMove(); + expect(move.id).toBe(moveToUse); + expect(move.power).toBe(100); + + // Check base power of Dynamax Cannon in context + const power = new Utils.IntegerHolder(move.power); + applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), phase.getTarget(), move, power); + expect(power.value).toBe(100); + }, 20000); + + it("DYNAMAX CANNON against enemy at 1% above level cap", async() => { + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(101); + const moveToUse = Moves.DYNAMAX_CANNON; + await game.startBattle([ + Species.ETERNATUS, + ]); + + game.doAttack(getMovePosition(game.scene, 0, moveToUse)); + + await game.phaseInterceptor.to(MoveEffectPhase, false); + + // Check initial base power of Dynamax Cannon + const phase = game.scene.getCurrentPhase() as MoveEffectPhase; + const move = phase.move.getMove(); + expect(move.id).toBe(moveToUse); + expect(move.power).toBe(100); + + const target = phase.getTarget(); + // Force level cap to be 100; that is, level cap is no longer 10 + target.scene.getMaxExpLevel = vi.fn().mockReturnValue(100); + + // Check base power of Dynamax Cannon in context + const power = new Utils.IntegerHolder(move.power); + applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), target, move, power); + expect(power.value).toBe(120); + }, 20000); + + it("DYNAMAX CANNON against enemy at 2% above level cap", async() => { + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(102); + const moveToUse = Moves.DYNAMAX_CANNON; + await game.startBattle([ + Species.ETERNATUS, + ]); + + game.doAttack(getMovePosition(game.scene, 0, moveToUse)); + + await game.phaseInterceptor.to(MoveEffectPhase, false); + + // Check initial base power of Dynamax Cannon + const phase = game.scene.getCurrentPhase() as MoveEffectPhase; + const move = phase.move.getMove(); + expect(move.id).toBe(moveToUse); + expect(move.power).toBe(100); + + const target = phase.getTarget(); + target.scene.getMaxExpLevel = vi.fn().mockReturnValue(100); + + // Check base power of Dynamax Cannon in context + const power = new Utils.IntegerHolder(move.power); + applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), target, move, power); + expect(power.value).toBe(140); + }, 20000); + + it("DYNAMAX CANNON against enemy at 3% above level cap", async() => { + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(103); + const moveToUse = Moves.DYNAMAX_CANNON; + await game.startBattle([ + Species.ETERNATUS, + ]); + + game.doAttack(getMovePosition(game.scene, 0, moveToUse)); + + await game.phaseInterceptor.to(MoveEffectPhase, false); + + // Check initial base power of Dynamax Cannon + const phase = game.scene.getCurrentPhase() as MoveEffectPhase; + const move = phase.move.getMove(); + expect(move.id).toBe(moveToUse); + expect(move.power).toBe(100); + + const target = phase.getTarget(); + target.scene.getMaxExpLevel = vi.fn().mockReturnValue(100); + + // Check base power of Dynamax Cannon in context + const power = new Utils.IntegerHolder(move.power); + applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), target, move, power); + expect(power.value).toBe(160); + }, 20000); + + it("DYNAMAX CANNON against enemy at 4% above level cap", async() => { + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(104); + const moveToUse = Moves.DYNAMAX_CANNON; + await game.startBattle([ + Species.ETERNATUS, + ]); + + game.doAttack(getMovePosition(game.scene, 0, moveToUse)); + + await game.phaseInterceptor.to(MoveEffectPhase, false); + + // Check initial base power of Dynamax Cannon + const phase = game.scene.getCurrentPhase() as MoveEffectPhase; + const move = phase.move.getMove(); + expect(move.id).toBe(moveToUse); + expect(move.power).toBe(100); + + const target = phase.getTarget(); + target.scene.getMaxExpLevel = vi.fn().mockReturnValue(100); + + // Check base power of Dynamax Cannon in context + const power = new Utils.IntegerHolder(move.power); + applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), target, move, power); + expect(power.value).toBe(180); + }, 20000); + + it("DYNAMAX CANNON against enemy at 5% above level cap", async() => { + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(105); + const moveToUse = Moves.DYNAMAX_CANNON; + await game.startBattle([ + Species.ETERNATUS, + ]); + + game.doAttack(getMovePosition(game.scene, 0, moveToUse)); + + await game.phaseInterceptor.to(MoveEffectPhase, false); + + // Check initial base power of Dynamax Cannon + const phase = game.scene.getCurrentPhase() as MoveEffectPhase; + const move = phase.move.getMove(); + expect(move.id).toBe(moveToUse); + expect(move.power).toBe(100); + + const target = phase.getTarget(); + target.scene.getMaxExpLevel = vi.fn().mockReturnValue(100); + + // Check base power of Dynamax Cannon in context + const power = new Utils.IntegerHolder(move.power); + applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), target, move, power); + expect(power.value).toBe(200); + }, 20000); + + it("DYNAMAX CANNON against enemy way above level cap", async() => { + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(999); + const moveToUse = Moves.DYNAMAX_CANNON; + await game.startBattle([ + Species.ETERNATUS, + ]); + + // Force enemy to go last + game.scene.getEnemyParty()[0].stats[Stat.SPD] = 1; + + game.doAttack(getMovePosition(game.scene, 0, moveToUse)); + + await game.phaseInterceptor.to(MoveEffectPhase, false); + + // Check initial base power of Dynamax Cannon + const phase = game.scene.getCurrentPhase() as MoveEffectPhase; + const move = phase.move.getMove(); + expect(move.id).toBe(moveToUse); + expect(move.power).toBe(100); + + // Check base power of Dynamax Cannon in context + const power = new Utils.IntegerHolder(move.power); + applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), phase.getTarget(), move, power); + expect(power.value).toBe(200); + }, 20000); +}); diff --git a/src/test/moves/dynamax_cannon_test.ts b/src/test/moves/dynamax_cannon_test.ts deleted file mode 100644 index de93557ed986..000000000000 --- a/src/test/moves/dynamax_cannon_test.ts +++ /dev/null @@ -1,66 +0,0 @@ -import {afterEach, beforeAll, beforeEach, describe, expect, it, vi} from "vitest"; -import Phaser from "phaser"; -import GameManager from "#app/test/utils/gameManager"; -import * as overrides from "#app/overrides"; -import { - CommandPhase, - EnemyCommandPhase, TurnEndPhase, -} from "#app/phases"; -import {Mode} from "#app/ui/ui"; -import {getMovePosition} from "#app/test/utils/gameManagerUtils"; -import {Command} from "#app/ui/command-ui-handler"; -import {Stat} from "#app/data/pokemon-stat"; -import { Moves } from "#enums/moves"; -import { Species } from "#enums/species"; - - -describe("Moves - Dynamax Cannon", () => { - let phaserGame: Phaser.Game; - let game: GameManager; - - beforeAll(() => { - phaserGame = new Phaser.Game({ - type: Phaser.HEADLESS, - }); - }); - - afterEach(() => { - game.phaseInterceptor.restoreOg(); - }); - - beforeEach(() => { - game = new GameManager(phaserGame); - const moveToUse = Moves.DYNAMAX_CANNON; - vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); - vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.MAGIKARP); - vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(1); - vi.spyOn(overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(200); - vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]); - vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.GROWTH,Moves.GROWTH,Moves.GROWTH,Moves.GROWTH]); - vi.spyOn(overrides, "NEVER_CRIT_OVERRIDE", "get").mockReturnValue(true); - }); - - it("DYNAMAX CANNON against enemy at level cap", async() => { - const moveToUse = Moves.DYNAMAX_CANNON; - await game.startBattle([ - Species.MIGHTYENA, - ]); - game.scene.getParty()[0].level = 200; - game.scene.currentBattle.enemyParty[0].stats[Stat.SPDEF] = 50; - game.scene.getParty()[0].stats[Stat.SPATK] = 50; - - const hpOpponent = game.scene.currentBattle.enemyParty[0].hp; - - game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { - game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex()); - }); - game.onNextPrompt("CommandPhase", Mode.FIGHT, () => { - const movePosition = getMovePosition(game.scene, 0, moveToUse); - (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); - }); - await game.phaseInterceptor.runFrom(EnemyCommandPhase).to(TurnEndPhase); - const hpLost = hpOpponent - game.scene.currentBattle.enemyParty[0].hp; - expect(hpLost).toBeGreaterThan(0); - expect(hpLost).toBe(10); // Meaning BP was 100BP? This number was "4" for Tackle - }, 20000); -});