[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
This commit is contained in:
allen925 2024-08-02 19:30:50 -07:00 committed by GitHub
parent e1812466a8
commit 3055d4500f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 76 additions and 0 deletions

View File

@ -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);
});

View File

@ -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);
}
}