2024-10-04 13:08:31 +08:00
|
|
|
import { afterEach, beforeAll, beforeEach, expect, describe, it, vi } from "vitest";
|
2024-09-13 22:05:58 -04:00
|
|
|
import GameManager from "#app/test/utils/gameManager";
|
|
|
|
import Phaser from "phaser";
|
2024-10-04 13:08:31 +08:00
|
|
|
import { Species } from "#enums/species";
|
2024-09-13 22:05:58 -04:00
|
|
|
import { MysteryEncounterOptionSelectedPhase, MysteryEncounterPhase } from "#app/phases/mystery-encounter-phases";
|
2024-10-04 13:08:31 +08:00
|
|
|
import { Mode } from "#app/ui/ui";
|
|
|
|
import { Button } from "#enums/buttons";
|
2024-09-13 22:05:58 -04:00
|
|
|
import MysteryEncounterUiHandler from "#app/ui/mystery-encounter-ui-handler";
|
2024-10-04 13:08:31 +08:00
|
|
|
import { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
2024-09-13 22:05:58 -04:00
|
|
|
import MessageUiHandler from "#app/ui/message-ui-handler";
|
|
|
|
import { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
|
2024-10-09 13:01:49 -07:00
|
|
|
import i18next from "i18next";
|
2024-09-13 22:05:58 -04:00
|
|
|
|
|
|
|
describe("Mystery Encounter Phases", () => {
|
|
|
|
let phaserGame: Phaser.Game;
|
|
|
|
let game: GameManager;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
phaserGame = new Phaser.Game({
|
|
|
|
type: Phaser.HEADLESS,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
game.phaseInterceptor.restoreOg();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
game = new GameManager(phaserGame);
|
|
|
|
game.override.startingWave(11);
|
|
|
|
game.override.mysteryEncounterChance(100);
|
|
|
|
// Seed guarantees wild encounter to be replaced by ME
|
|
|
|
game.override.seed("test");
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("MysteryEncounterPhase", () => {
|
|
|
|
it("Runs to MysteryEncounterPhase", async() => {
|
2024-10-04 13:08:31 +08:00
|
|
|
await game.runToMysteryEncounter(MysteryEncounterType.MYSTERIOUS_CHALLENGERS, [ Species.CHARIZARD, Species.VOLCARONA ]);
|
2024-09-13 22:05:58 -04:00
|
|
|
|
|
|
|
await game.phaseInterceptor.to(MysteryEncounterPhase, false);
|
|
|
|
expect(game.scene.getCurrentPhase()?.constructor.name).toBe(MysteryEncounterPhase.name);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Runs MysteryEncounterPhase", async() => {
|
2024-10-04 13:08:31 +08:00
|
|
|
await game.runToMysteryEncounter(MysteryEncounterType.MYSTERIOUS_CHALLENGERS, [ Species.CHARIZARD, Species.VOLCARONA ]);
|
2024-09-13 22:05:58 -04:00
|
|
|
|
|
|
|
game.onNextPrompt("MysteryEncounterPhase", Mode.MYSTERY_ENCOUNTER, () => {
|
|
|
|
// End phase early for test
|
|
|
|
game.phaseInterceptor.superEndPhase();
|
|
|
|
});
|
|
|
|
await game.phaseInterceptor.run(MysteryEncounterPhase);
|
|
|
|
|
|
|
|
expect(game.scene.mysteryEncounterSaveData.encounteredEvents.length).toBeGreaterThan(0);
|
|
|
|
expect(game.scene.mysteryEncounterSaveData.encounteredEvents[0].type).toEqual(MysteryEncounterType.MYSTERIOUS_CHALLENGERS);
|
|
|
|
expect(game.scene.mysteryEncounterSaveData.encounteredEvents[0].tier).toEqual(MysteryEncounterTier.GREAT);
|
|
|
|
expect(game.scene.ui.getMode()).toBe(Mode.MYSTERY_ENCOUNTER);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Selects an option for MysteryEncounterPhase", async() => {
|
2024-10-01 13:55:16 -07:00
|
|
|
const { ui } = game.scene;
|
|
|
|
vi.spyOn(ui, "showDialogue");
|
|
|
|
vi.spyOn(ui, "showText");
|
2024-10-04 13:08:31 +08:00
|
|
|
await game.runToMysteryEncounter(MysteryEncounterType.MYSTERIOUS_CHALLENGERS, [ Species.CHARIZARD, Species.VOLCARONA ]);
|
2024-09-13 22:05:58 -04:00
|
|
|
|
|
|
|
game.onNextPrompt("MysteryEncounterPhase", Mode.MESSAGE, () => {
|
|
|
|
const handler = game.scene.ui.getHandler() as MessageUiHandler;
|
|
|
|
handler.processInput(Button.ACTION);
|
|
|
|
});
|
|
|
|
|
|
|
|
await game.phaseInterceptor.run(MysteryEncounterPhase);
|
|
|
|
|
|
|
|
// Select option 1 for encounter
|
|
|
|
const handler = game.scene.ui.getHandler() as MysteryEncounterUiHandler;
|
|
|
|
handler.unblockInput();
|
|
|
|
handler.processInput(Button.ACTION);
|
|
|
|
|
|
|
|
// Waitfor required so that option select messages and preOptionPhase logic are handled
|
|
|
|
await vi.waitFor(() => expect(game.scene.getCurrentPhase()?.constructor.name).toBe(MysteryEncounterOptionSelectedPhase.name));
|
2024-10-01 13:55:16 -07:00
|
|
|
expect(ui.getMode()).toBe(Mode.MESSAGE);
|
|
|
|
expect(ui.showDialogue).toHaveBeenCalledTimes(1);
|
|
|
|
expect(ui.showText).toHaveBeenCalledTimes(2);
|
2024-10-09 13:01:49 -07:00
|
|
|
expect(ui.showDialogue).toHaveBeenCalledWith(i18next.t("battle:mysteryEncounterAppeared"), "???", null, expect.any(Function));
|
|
|
|
expect(ui.showText).toHaveBeenCalledWith(i18next.t("mysteryEncounters/mysteriousChallengers:intro"), null, expect.any(Function), 750, true);
|
|
|
|
expect(ui.showText).toHaveBeenCalledWith(i18next.t("mysteryEncounters/mysteriousChallengers:option.selected"), null, expect.any(Function), 300, true);
|
2024-09-13 22:05:58 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("MysteryEncounterOptionSelectedPhase", () => {
|
|
|
|
it("runs phase", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles onOptionSelect execution", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("hides intro visuals", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not hide intro visuals if option disabled", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("MysteryEncounterBattlePhase", () => {
|
|
|
|
it("runs phase", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles TRAINER_BATTLE variant", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles BOSS_BATTLE variant", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles WILD_BATTLE variant", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles double battle", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("MysteryEncounterRewardsPhase", () => {
|
|
|
|
it("runs phase", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles doEncounterRewards", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles heal phase if enabled", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("PostMysteryEncounterPhase", () => {
|
|
|
|
it("runs phase", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles onPostOptionSelect execution", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("runs to next EncounterPhase", () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|