mirror of
				https://github.com/pagefaultgames/pokerogue.git
				synced 2025-10-31 16:35:52 +01:00 
			
		
		
		
	* Rename `Abilities` to `AbilityId` * Rename `abilities.ts` to `ability-id.ts` * Rename `Moves` to `MoveId` * Rename `moves.ts` to `move-id.ts` * Rename `Species` to `SpeciesId` * Rename `species.ts` to `species-id.ts` * Rename `Biome` to `BiomeId` * Rename `biome.ts` to `biome-id.ts` * Replace `Abilities` with `AbilityId` in comments * Replace `Biome` with `BiomeId` in comments * Replace `Moves` with `MoveId` in comments * Replace `Species` with `SpeciesId` in comments
		
			
				
	
	
		
			265 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			265 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { BiomeId } from "#enums/biome-id";
 | |
| import { MysteryEncounterType } from "#app/enums/mystery-encounter-type";
 | |
| import { SpeciesId } from "#enums/species-id";
 | |
| import GameManager from "#test/testUtils/gameManager";
 | |
| import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
 | |
| import * as EncounterPhaseUtils from "#app/data/mystery-encounters/utils/encounter-phase-utils";
 | |
| import { runMysteryEncounterToEnd } from "#test/mystery-encounter/encounter-test-utils";
 | |
| import type BattleScene from "#app/battle-scene";
 | |
| import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode";
 | |
| import { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
 | |
| import * as MysteryEncounters from "#app/data/mystery-encounters/mystery-encounters";
 | |
| import { FieldTripEncounter } from "#app/data/mystery-encounters/encounters/field-trip-encounter";
 | |
| import { MoveId } from "#enums/move-id";
 | |
| import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
 | |
| import { UiMode } from "#enums/ui-mode";
 | |
| import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
 | |
| import i18next from "i18next";
 | |
| 
 | |
| const namespace = "mysteryEncounters/fieldTrip";
 | |
| const defaultParty = [SpeciesId.LAPRAS, SpeciesId.GENGAR, SpeciesId.ABRA];
 | |
| const defaultBiome = BiomeId.CAVE;
 | |
| const defaultWave = 45;
 | |
| 
 | |
| describe("Field Trip - Mystery Encounter", () => {
 | |
|   let phaserGame: Phaser.Game;
 | |
|   let game: GameManager;
 | |
|   let scene: BattleScene;
 | |
| 
 | |
|   beforeAll(() => {
 | |
|     phaserGame = new Phaser.Game({ type: Phaser.HEADLESS });
 | |
|   });
 | |
| 
 | |
|   beforeEach(async () => {
 | |
|     game = new GameManager(phaserGame);
 | |
|     scene = game.scene;
 | |
|     game.override.mysteryEncounterChance(100);
 | |
|     game.override.startingWave(defaultWave);
 | |
|     game.override.startingBiome(defaultBiome);
 | |
|     game.override.disableTrainerWaves();
 | |
|     game.override.moveset([MoveId.TACKLE, MoveId.UPROAR, MoveId.SWORDS_DANCE]);
 | |
| 
 | |
|     vi.spyOn(MysteryEncounters, "mysteryEncountersByBiome", "get").mockReturnValue(
 | |
|       new Map<BiomeId, MysteryEncounterType[]>([[BiomeId.CAVE, [MysteryEncounterType.FIELD_TRIP]]]),
 | |
|     );
 | |
|   });
 | |
| 
 | |
|   afterEach(() => {
 | |
|     game.phaseInterceptor.restoreOg();
 | |
|     vi.clearAllMocks();
 | |
|     vi.resetAllMocks();
 | |
|   });
 | |
| 
 | |
|   it("should have the correct properties", async () => {
 | |
|     await game.runToMysteryEncounter(MysteryEncounterType.FIELD_TRIP, defaultParty);
 | |
| 
 | |
|     expect(FieldTripEncounter.encounterType).toBe(MysteryEncounterType.FIELD_TRIP);
 | |
|     expect(FieldTripEncounter.encounterTier).toBe(MysteryEncounterTier.COMMON);
 | |
|     expect(FieldTripEncounter.dialogue).toBeDefined();
 | |
|     expect(FieldTripEncounter.dialogue.intro).toStrictEqual([
 | |
|       {
 | |
|         text: `${namespace}:intro`,
 | |
|       },
 | |
|       {
 | |
|         speaker: `${namespace}:speaker`,
 | |
|         text: `${namespace}:intro_dialogue`,
 | |
|       },
 | |
|     ]);
 | |
|     expect(FieldTripEncounter.dialogue.encounterOptionsDialogue?.title).toBe(`${namespace}:title`);
 | |
|     expect(FieldTripEncounter.dialogue.encounterOptionsDialogue?.description).toBe(`${namespace}:description`);
 | |
|     expect(FieldTripEncounter.dialogue.encounterOptionsDialogue?.query).toBe(`${namespace}:query`);
 | |
|     expect(FieldTripEncounter.options.length).toBe(3);
 | |
|   });
 | |
| 
 | |
|   describe("Option 1 - Show off a physical move", () => {
 | |
|     it("should have the correct properties", () => {
 | |
|       const option = FieldTripEncounter.options[0];
 | |
|       expect(option.optionMode).toBe(MysteryEncounterOptionMode.DEFAULT);
 | |
|       expect(option.dialogue).toBeDefined();
 | |
|       expect(option.dialogue).toStrictEqual({
 | |
|         buttonLabel: `${namespace}:option.1.label`,
 | |
|         buttonTooltip: `${namespace}:option.1.tooltip`,
 | |
|         secondOptionPrompt: `${namespace}:second_option_prompt`,
 | |
|       });
 | |
|     });
 | |
| 
 | |
|     it("Should give no reward on incorrect option", async () => {
 | |
|       await game.runToMysteryEncounter(MysteryEncounterType.FIELD_TRIP, defaultParty);
 | |
|       await runMysteryEncounterToEnd(game, 1, { pokemonNo: 1, optionNo: 2 });
 | |
|       await game.phaseInterceptor.to(SelectModifierPhase);
 | |
| 
 | |
|       expect(scene.ui.getMode()).to.equal(UiMode.MODIFIER_SELECT);
 | |
|       const modifierSelectHandler = scene.ui.handlers.find(
 | |
|         h => h instanceof ModifierSelectUiHandler,
 | |
|       ) as ModifierSelectUiHandler;
 | |
|       expect(modifierSelectHandler.options.length).toEqual(0);
 | |
|     });
 | |
| 
 | |
|     it("Should give proper rewards on correct Physical move option", async () => {
 | |
|       await game.runToMysteryEncounter(MysteryEncounterType.FIELD_TRIP, defaultParty);
 | |
|       await runMysteryEncounterToEnd(game, 1, { pokemonNo: 1, optionNo: 1 });
 | |
|       await game.phaseInterceptor.to(SelectModifierPhase);
 | |
| 
 | |
|       expect(scene.ui.getMode()).to.equal(UiMode.MODIFIER_SELECT);
 | |
|       const modifierSelectHandler = scene.ui.handlers.find(
 | |
|         h => h instanceof ModifierSelectUiHandler,
 | |
|       ) as ModifierSelectUiHandler;
 | |
|       expect(modifierSelectHandler.options.length).toEqual(5);
 | |
|       expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:TempStatStageBoosterItem.x_attack"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:TempStatStageBoosterItem.x_defense"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:TempStatStageBoosterItem.x_speed"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:ModifierType.DIRE_HIT.name"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:ModifierType.RARER_CANDY.name"),
 | |
|       );
 | |
|     });
 | |
| 
 | |
|     it("should leave encounter without battle", async () => {
 | |
|       const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle");
 | |
| 
 | |
|       await game.runToMysteryEncounter(MysteryEncounterType.FIELD_TRIP, defaultParty);
 | |
|       await runMysteryEncounterToEnd(game, 1, { pokemonNo: 1, optionNo: 1 });
 | |
| 
 | |
|       expect(leaveEncounterWithoutBattleSpy).toBeCalled();
 | |
|     });
 | |
|   });
 | |
| 
 | |
|   describe("Option 2 - Give Food", () => {
 | |
|     it("should have the correct properties", () => {
 | |
|       const option = FieldTripEncounter.options[1];
 | |
|       expect(option.optionMode).toBe(MysteryEncounterOptionMode.DEFAULT);
 | |
|       expect(option.dialogue).toBeDefined();
 | |
|       expect(option.dialogue).toStrictEqual({
 | |
|         buttonLabel: `${namespace}:option.2.label`,
 | |
|         buttonTooltip: `${namespace}:option.2.tooltip`,
 | |
|         secondOptionPrompt: `${namespace}:second_option_prompt`,
 | |
|       });
 | |
|     });
 | |
| 
 | |
|     it("Should give no reward on incorrect option", async () => {
 | |
|       await game.runToMysteryEncounter(MysteryEncounterType.FIELD_TRIP, defaultParty);
 | |
|       await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1, optionNo: 1 });
 | |
|       await game.phaseInterceptor.to(SelectModifierPhase);
 | |
| 
 | |
|       expect(scene.ui.getMode()).to.equal(UiMode.MODIFIER_SELECT);
 | |
|       const modifierSelectHandler = scene.ui.handlers.find(
 | |
|         h => h instanceof ModifierSelectUiHandler,
 | |
|       ) as ModifierSelectUiHandler;
 | |
|       expect(modifierSelectHandler.options.length).toEqual(0);
 | |
|     });
 | |
| 
 | |
|     it("Should give proper rewards on correct Special move option", async () => {
 | |
|       await game.runToMysteryEncounter(MysteryEncounterType.FIELD_TRIP, defaultParty);
 | |
|       await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1, optionNo: 2 });
 | |
|       await game.phaseInterceptor.to(SelectModifierPhase);
 | |
| 
 | |
|       expect(scene.ui.getMode()).to.equal(UiMode.MODIFIER_SELECT);
 | |
|       const modifierSelectHandler = scene.ui.handlers.find(
 | |
|         h => h instanceof ModifierSelectUiHandler,
 | |
|       ) as ModifierSelectUiHandler;
 | |
|       expect(modifierSelectHandler.options.length).toEqual(5);
 | |
|       expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:TempStatStageBoosterItem.x_sp_atk"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:TempStatStageBoosterItem.x_sp_def"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:TempStatStageBoosterItem.x_speed"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:ModifierType.DIRE_HIT.name"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:ModifierType.RARER_CANDY.name"),
 | |
|       );
 | |
|     });
 | |
| 
 | |
|     it("should leave encounter without battle", async () => {
 | |
|       const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle");
 | |
| 
 | |
|       await game.runToMysteryEncounter(MysteryEncounterType.FIELD_TRIP, defaultParty);
 | |
|       await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1, optionNo: 2 });
 | |
| 
 | |
|       expect(leaveEncounterWithoutBattleSpy).toBeCalled();
 | |
|     });
 | |
|   });
 | |
| 
 | |
|   describe("Option 3 - Give Item", () => {
 | |
|     it("should have the correct properties", () => {
 | |
|       const option = FieldTripEncounter.options[2];
 | |
|       expect(option.optionMode).toBe(MysteryEncounterOptionMode.DEFAULT);
 | |
|       expect(option.dialogue).toBeDefined();
 | |
|       expect(option.dialogue).toStrictEqual({
 | |
|         buttonLabel: `${namespace}:option.3.label`,
 | |
|         buttonTooltip: `${namespace}:option.3.tooltip`,
 | |
|         secondOptionPrompt: `${namespace}:second_option_prompt`,
 | |
|       });
 | |
|     });
 | |
| 
 | |
|     it("Should give no reward on incorrect option", async () => {
 | |
|       await game.runToMysteryEncounter(MysteryEncounterType.FIELD_TRIP, defaultParty);
 | |
|       await runMysteryEncounterToEnd(game, 3, { pokemonNo: 1, optionNo: 1 });
 | |
|       await game.phaseInterceptor.to(SelectModifierPhase);
 | |
| 
 | |
|       expect(scene.ui.getMode()).to.equal(UiMode.MODIFIER_SELECT);
 | |
|       const modifierSelectHandler = scene.ui.handlers.find(
 | |
|         h => h instanceof ModifierSelectUiHandler,
 | |
|       ) as ModifierSelectUiHandler;
 | |
|       expect(modifierSelectHandler.options.length).toEqual(0);
 | |
|     });
 | |
| 
 | |
|     it("Should give proper rewards on correct Special move option", async () => {
 | |
|       vi.spyOn(i18next, "t");
 | |
|       await game.runToMysteryEncounter(MysteryEncounterType.FIELD_TRIP, defaultParty);
 | |
|       await runMysteryEncounterToEnd(game, 3, { pokemonNo: 1, optionNo: 3 });
 | |
|       await game.phaseInterceptor.to(SelectModifierPhase);
 | |
| 
 | |
|       expect(scene.ui.getMode()).to.equal(UiMode.MODIFIER_SELECT);
 | |
|       const modifierSelectHandler = scene.ui.handlers.find(
 | |
|         h => h instanceof ModifierSelectUiHandler,
 | |
|       ) as ModifierSelectUiHandler;
 | |
|       expect(modifierSelectHandler.options.length).toEqual(5);
 | |
|       expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:TempStatStageBoosterItem.x_accuracy"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:TempStatStageBoosterItem.x_speed"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:ModifierType.AddPokeballModifierType.name", {
 | |
|           modifierCount: 5,
 | |
|           pokeballName: i18next.t("pokeball:greatBall"),
 | |
|         }),
 | |
|       );
 | |
|       expect(i18next.t).toHaveBeenCalledWith(
 | |
|         "modifierType:ModifierType.AddPokeballModifierType.name",
 | |
|         expect.objectContaining({ modifierCount: 5 }),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:ModifierType.IV_SCANNER.name"),
 | |
|       );
 | |
|       expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe(
 | |
|         i18next.t("modifierType:ModifierType.RARER_CANDY.name"),
 | |
|       );
 | |
|     });
 | |
| 
 | |
|     it("should leave encounter without battle", async () => {
 | |
|       const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle");
 | |
| 
 | |
|       await game.runToMysteryEncounter(MysteryEncounterType.FIELD_TRIP, defaultParty);
 | |
|       await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1, optionNo: 3 });
 | |
| 
 | |
|       expect(leaveEncounterWithoutBattleSpy).toBeCalled();
 | |
|     });
 | |
|   });
 | |
| });
 |