2024-11-08 14:44:34 -08:00
|
|
|
import { Status } from "#app/data/status-effect";
|
2024-11-14 14:40:01 -05:00
|
|
|
import { Abilities } from "#enums/abilities";
|
|
|
|
import { GameModes, getGameMode } from "#app/game-mode";
|
2024-08-22 06:49:33 -07:00
|
|
|
import { BattleEndPhase } from "#app/phases/battle-end-phase";
|
|
|
|
import { TurnInitPhase } from "#app/phases/turn-init-phase";
|
2024-08-02 19:30:50 -07:00
|
|
|
import { Moves } from "#enums/moves";
|
|
|
|
import { Species } from "#enums/species";
|
2024-11-08 14:44:34 -08:00
|
|
|
import { StatusEffect } from "#enums/status-effect";
|
2025-02-22 22:52:07 -06:00
|
|
|
import GameManager from "#test/testUtils/gameManager";
|
2024-08-02 19:30:50 -07:00
|
|
|
import Phaser from "phaser";
|
2024-11-14 14:40:01 -05:00
|
|
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
2024-08-02 19:30:50 -07:00
|
|
|
|
2024-08-11 21:54:42 -07:00
|
|
|
describe("Double Battles", () => {
|
2024-11-14 14:40:01 -05:00
|
|
|
const DOUBLE_CHANCE = 8; // Normal chance of double battle is 1/8
|
|
|
|
|
2024-08-02 19:30:50 -07:00
|
|
|
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)
|
2024-08-22 06:49:33 -07:00
|
|
|
it("3v2 edge case: player summons 2 pokemon on the next battle after being fainted and revived", async () => {
|
2024-09-09 09:55:11 -07:00
|
|
|
game.override.battleType("double").enemyMoveset(Moves.SPLASH).moveset(Moves.SPLASH);
|
2024-08-02 19:30:50 -07:00
|
|
|
await game.startBattle([
|
|
|
|
Species.BULBASAUR,
|
|
|
|
Species.CHARIZARD,
|
|
|
|
Species.SQUIRTLE,
|
|
|
|
]);
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.SPLASH);
|
|
|
|
game.move.select(Moves.SPLASH, 1);
|
2024-08-02 19:30:50 -07:00
|
|
|
|
|
|
|
for (const pokemon of game.scene.getPlayerField()) {
|
|
|
|
pokemon.hp = 0;
|
|
|
|
pokemon.status = new Status(StatusEffect.FAINT);
|
|
|
|
expect(pokemon.isFainted()).toBe(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
await game.doKillOpponents();
|
|
|
|
|
|
|
|
await game.phaseInterceptor.to(BattleEndPhase);
|
|
|
|
game.doSelectModifier();
|
|
|
|
|
2024-11-03 18:53:52 -08:00
|
|
|
const charizard = game.scene.getPlayerParty().findIndex(p => p.species.speciesId === Species.CHARIZARD);
|
2024-08-02 19:30:50 -07:00
|
|
|
game.doRevivePokemon(charizard);
|
|
|
|
|
|
|
|
await game.phaseInterceptor.to(TurnInitPhase);
|
|
|
|
expect(game.scene.getPlayerField().filter(p => !p.isFainted())).toHaveLength(2);
|
|
|
|
}, 20000);
|
2024-11-14 14:40:01 -05:00
|
|
|
|
|
|
|
it("randomly chooses between single and double battles if there is no battle type override", async () => {
|
|
|
|
let rngSweepProgress = 0; // Will simulate RNG rolls by slowly increasing from 0 to 1
|
|
|
|
let doubleCount = 0;
|
|
|
|
let singleCount = 0;
|
|
|
|
|
|
|
|
vi.spyOn(Phaser.Math.RND, "realInRange").mockImplementation((min: number, max: number) => {
|
|
|
|
return rngSweepProgress * (max - min) + min;
|
|
|
|
});
|
|
|
|
|
|
|
|
game.override.enemyMoveset(Moves.SPLASH)
|
|
|
|
.moveset(Moves.SPLASH)
|
|
|
|
.enemyAbility(Abilities.BALL_FETCH)
|
|
|
|
.ability(Abilities.BALL_FETCH);
|
|
|
|
|
|
|
|
// Play through endless, waves 1 to 9, counting number of double battles from waves 2 to 9
|
|
|
|
await game.classicMode.startBattle([ Species.BULBASAUR ]);
|
|
|
|
game.scene.gameMode = getGameMode(GameModes.ENDLESS);
|
|
|
|
|
|
|
|
for (let i = 0; i < DOUBLE_CHANCE; i++) {
|
|
|
|
rngSweepProgress = (i + 0.5) / DOUBLE_CHANCE;
|
|
|
|
|
|
|
|
game.move.select(Moves.SPLASH);
|
|
|
|
await game.doKillOpponents();
|
|
|
|
await game.toNextWave();
|
|
|
|
|
|
|
|
if (game.scene.getEnemyParty().length === 1) {
|
|
|
|
singleCount++;
|
|
|
|
} else if (game.scene.getEnemyParty().length === 2) {
|
|
|
|
doubleCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(doubleCount).toBe(1);
|
|
|
|
expect(singleCount).toBe(DOUBLE_CHANCE - 1);
|
|
|
|
});
|
2024-08-02 19:30:50 -07:00
|
|
|
});
|