2024-07-25 14:19:56 -07:00
|
|
|
import { Weather, WeatherType } from "#app/data/weather";
|
2024-07-25 15:01:59 -07:00
|
|
|
import { Abilities } from "#app/enums/abilities.js";
|
2024-07-25 14:19:56 -07:00
|
|
|
import { Biome } from "#app/enums/biome";
|
2024-07-25 15:11:05 -07:00
|
|
|
import { Moves } from "#app/enums/moves.js";
|
2024-07-25 14:53:34 -07:00
|
|
|
import { Species } from "#app/enums/species.js";
|
2024-07-25 14:19:56 -07:00
|
|
|
import * as GameMode from "#app/game-mode";
|
|
|
|
import { GameModes, getGameMode } from "#app/game-mode";
|
|
|
|
import Overrides from "#app/overrides";
|
|
|
|
import GameManager from "#test/utils/gameManager";
|
|
|
|
import { vi } from "vitest";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to handle overrides in tests
|
|
|
|
*/
|
|
|
|
export class OverridesHelper {
|
|
|
|
private readonly game: GameManager;
|
|
|
|
|
|
|
|
constructor(game: GameManager) {
|
|
|
|
this.game = game;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the starting biome
|
|
|
|
* @warning Any event listeners that are attached to [NewArenaEvent](events\battle-scene.ts) may need to be handled down the line
|
|
|
|
* @param biome the biome to set
|
|
|
|
*/
|
|
|
|
startingBiome(biome: Biome): this {
|
|
|
|
this.game.scene.newArena(biome);
|
|
|
|
this.log(`Starting biome set to ${Biome[biome]} (=${biome})!`);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the starting wave (index)
|
|
|
|
* @param wave the wave (index) to set. Classic: `1`-`200`
|
2024-07-25 14:36:46 -07:00
|
|
|
* @returns this
|
2024-07-25 14:19:56 -07:00
|
|
|
*/
|
|
|
|
startingWave(wave: number): this {
|
|
|
|
vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(wave);
|
|
|
|
this.log(`Starting wave set to ${wave}!`);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override each wave to have or not have standard trainer battles
|
2024-07-25 14:36:46 -07:00
|
|
|
* @returns this
|
|
|
|
* @param disable true
|
2024-07-25 14:19:56 -07:00
|
|
|
*/
|
|
|
|
disableTrainerWaves(disable: boolean): this {
|
|
|
|
const realFn = getGameMode;
|
|
|
|
vi.spyOn(GameMode, "getGameMode").mockImplementation((gameMode: GameModes) => {
|
|
|
|
const mode = realFn(gameMode);
|
|
|
|
mode.hasTrainers = !disable;
|
|
|
|
return mode;
|
|
|
|
});
|
|
|
|
this.log(`Standard trainer waves are ${disable ? "disabled" : "enabled"}!`);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-07-25 15:01:59 -07:00
|
|
|
* Override the {@linkcode WeatherType | weather (type)}
|
|
|
|
* @param type {@linkcode WeatherType | weather type} to set
|
2024-07-25 14:36:46 -07:00
|
|
|
* @returns this
|
2024-07-25 14:19:56 -07:00
|
|
|
*/
|
|
|
|
weather(type: WeatherType): this {
|
|
|
|
vi.spyOn(Overrides, "WEATHER_OVERRIDE", "get").mockReturnValue(type);
|
|
|
|
this.log(`Weather set to ${Weather[type]} (=${type})!`);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the seed
|
|
|
|
* @param seed the seed to set
|
2024-07-25 14:36:46 -07:00
|
|
|
* @returns this
|
2024-07-25 14:19:56 -07:00
|
|
|
*/
|
|
|
|
seed(seed: string): this {
|
|
|
|
vi.spyOn(this.game.scene, "resetSeed").mockImplementation(() => {
|
|
|
|
this.game.scene.waveSeed = seed;
|
|
|
|
Phaser.Math.RND.sow([seed]);
|
|
|
|
this.game.scene.rngCounter = 0;
|
|
|
|
});
|
|
|
|
this.game.scene.resetSeed();
|
|
|
|
this.log(`Seed set to "${seed}"!`);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2024-07-25 14:36:46 -07:00
|
|
|
/**
|
|
|
|
* Override the battle type (single or double)
|
|
|
|
* @param battleType battle type to set
|
|
|
|
* @returns this
|
|
|
|
*/
|
|
|
|
battleType(battleType: "single" | "double"): this {
|
|
|
|
vi.spyOn(Overrides, "BATTLE_TYPE_OVERRIDE", "get").mockReturnValue(battleType);
|
|
|
|
this.log(`Battle type set to ${battleType} only!`);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2024-07-25 14:53:34 -07:00
|
|
|
/**
|
2024-07-25 15:01:59 -07:00
|
|
|
* Override the enemy (pokemon) {@linkcode Species | species}
|
|
|
|
* @param species the (pokemon) {@linkcode Species | species} to set
|
2024-07-25 14:53:34 -07:00
|
|
|
* @returns this
|
|
|
|
*/
|
2024-07-25 14:57:37 -07:00
|
|
|
enemySpecies(species: Species | number): this {
|
2024-07-25 14:53:34 -07:00
|
|
|
vi.spyOn(Overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(species);
|
|
|
|
this.log(`Enemy Pokemon species set to ${Species[species]} (=${species})!`);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2024-07-25 15:01:59 -07:00
|
|
|
/**
|
|
|
|
* Override the enemy (pokemon) {@linkcode Abilities | ability}
|
|
|
|
* @param ability the (pokemon) {@linkcode Abilities | ability} to set
|
|
|
|
* @returns this
|
|
|
|
*/
|
|
|
|
enemyAbility(ability: Abilities): this {
|
|
|
|
vi.spyOn(Overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(ability);
|
2024-07-25 15:11:05 -07:00
|
|
|
this.log(`Enemy Pokemon ability set to ${Abilities[ability]} (=${ability})!`);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the enemy (pokemon) {@linkcode Moves | moves}set
|
|
|
|
* @param moveset the {@linkcode Moves | moves}set to set
|
|
|
|
* @returns this
|
|
|
|
*/
|
|
|
|
enemyMoveset(moveset: Moves[]): this {
|
|
|
|
vi.spyOn(Overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue(moveset);
|
|
|
|
const movesetStr = moveset.map((moveId) => Moves[moveId]).join(", ");
|
|
|
|
this.log(`Enemy Pokemon moveset set to ${movesetStr} (=[${moveset.join(", ")}])!`);
|
2024-07-25 15:01:59 -07:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2024-07-25 14:19:56 -07:00
|
|
|
private log(...params: any[]) {
|
|
|
|
console.log("Overrides:", ...params);
|
|
|
|
}
|
|
|
|
}
|