From 3055d4500fc7dad886190eadcc9f400823d90a38 Mon Sep 17 00:00:00 2001 From: allen925 <62000482+allen925@users.noreply.github.com> Date: Fri, 2 Aug 2024 19:30:50 -0700 Subject: [PATCH] [Test] added revive function in gameManager & a double-battle test (#3298) * added revive function in gamaManager & a double-battle test * extended timeout of double battle test referencing to battle test * less code, deleted unused param, clearer description of test * add back dbond to move in test * more straight forward testing * reverse back override * polish double battle test a bit --- src/test/battle/double_battle.test.ts | 64 +++++++++++++++++++++++++++ src/test/utils/gameManager.ts | 12 +++++ 2 files changed, 76 insertions(+) create mode 100644 src/test/battle/double_battle.test.ts diff --git a/src/test/battle/double_battle.test.ts b/src/test/battle/double_battle.test.ts new file mode 100644 index 00000000000..e2d8dee562c --- /dev/null +++ b/src/test/battle/double_battle.test.ts @@ -0,0 +1,64 @@ +import { + BattleEndPhase, + TurnInitPhase, +} from "#app/phases"; +import GameManager from "#app/test/utils/gameManager"; +import { getMovePosition, } from "#app/test/utils/gameManagerUtils"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; +import { SPLASH_ONLY } from "../utils/testUtils"; +import { Status, StatusEffect } from "#app/data/status-effect.js"; + +describe("Test Battle Phase", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + }); + + // double-battle player's pokemon both fainted in same round, then revive one, and next double battle summons two player's pokemon successfully. + // (There were bugs that either only summon one when can summon two, player stuck in switchPhase etc) + it("3v2 edge case: player summons 2 pokemon on the next battle after being fainted and revived", async() => { + game.override.battleType("double").enemyMoveset(SPLASH_ONLY).moveset(SPLASH_ONLY); + await game.startBattle([ + Species.BULBASAUR, + Species.CHARIZARD, + Species.SQUIRTLE, + ]); + + game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH)); + game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH)); + + for (const pokemon of game.scene.getPlayerField()) { + expect(pokemon).toBeDefined(); + + pokemon.hp = 0; + pokemon.status = new Status(StatusEffect.FAINT); + expect(pokemon.isFainted()).toBe(true); + } + + await game.doKillOpponents(); + + await game.phaseInterceptor.to(BattleEndPhase); + game.doSelectModifier(); + + const charizard = game.scene.getParty().findIndex(p => p.species.speciesId === Species.CHARIZARD); + game.doRevivePokemon(charizard); + + await game.phaseInterceptor.to(TurnInitPhase); + expect(game.scene.getPlayerField().filter(p => !p.isFainted())).toHaveLength(2); + }, 20000); +}); diff --git a/src/test/utils/gameManager.ts b/src/test/utils/gameManager.ts index d491e007940..1938d57dfd1 100644 --- a/src/test/utils/gameManager.ts +++ b/src/test/utils/gameManager.ts @@ -35,6 +35,7 @@ import { Button } from "#enums/buttons"; import { BattlerIndex } from "#app/battle.js"; import TargetSelectUiHandler from "#app/ui/target-select-ui-handler.js"; import { OverridesHelper } from "./overridesHelper"; +import { ModifierTypeOption, modifierTypes } from "#app/modifier/modifier-type.js"; /** * Class to manage the game state and transitions between phases. @@ -328,4 +329,15 @@ export default class GameManager { (this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.POKEMON, pokemonIndex, false); }); } + + /** + * Revive pokemon, currently player's only. + * @param pokemonIndex the index of the pokemon in your party to revive + */ + doRevivePokemon(pokemonIndex: number) { + const party = this.scene.getParty(); + const candidate = new ModifierTypeOption(modifierTypes.MAX_REVIVE(), 0); + const modifier = candidate.type.newModifier(party[pokemonIndex]); + this.scene.addModifier(modifier, false); + } }