finish lost-at-sea-encounter.test.ts (for now)

This commit is contained in:
Felix Staud 2024-07-16 21:27:35 -07:00
parent b26cffc49e
commit 04da4516b4
3 changed files with 84 additions and 31 deletions

View File

@ -1,6 +1,6 @@
import { Button } from "#app/enums/buttons"; import { Button } from "#app/enums/buttons";
import { MessagePhase } from "#app/phases"; import { MessagePhase } from "#app/phases";
import { MysteryEncounterOptionSelectedPhase, MysteryEncounterPhase, MysteryEncounterRewardsPhase } from "#app/phases/mystery-encounter-phase"; import { MysteryEncounterPhase, MysteryEncounterRewardsPhase } from "#app/phases/mystery-encounter-phase";
import MysteryEncounterUiHandler from "#app/ui/mystery-encounter-ui-handler"; import MysteryEncounterUiHandler from "#app/ui/mystery-encounter-ui-handler";
import { Mode } from "#app/ui/ui"; import { Mode } from "#app/ui/ui";
import GameManager from "../utils/gameManager"; import GameManager from "../utils/gameManager";
@ -50,7 +50,5 @@ export async function runSelectMysteryEncounterOption(game: GameManager, optionN
const uiHandler = game.scene.ui.getHandler<MysteryEncounterUiHandler>(); const uiHandler = game.scene.ui.getHandler<MysteryEncounterUiHandler>();
uiHandler.processInput(Button.ACTION); uiHandler.processInput(Button.ACTION);
}); });
await game.phaseInterceptor.run(MysteryEncounterOptionSelectedPhase);
await game.phaseInterceptor.to(MysteryEncounterRewardsPhase); await game.phaseInterceptor.to(MysteryEncounterRewardsPhase);
} }

View File

@ -28,7 +28,9 @@ describe("Lost at Sea - Mystery Encounter", () => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override.mysteryEncounterChance(100); game.override.mysteryEncounterChance(100);
game.override.startingBiome(Biome.SEA); game.override.startingBiome(Biome.SEA);
vi.spyOn(MysteryEncounters, "allMysteryEncounters", "get").mockReturnValue({ [MysteryEncounterType.LOST_AT_SEA]: LostAtSeaEncounter }); vi.spyOn(MysteryEncounters, "allMysteryEncounters", "get").mockReturnValue({
[MysteryEncounterType.LOST_AT_SEA]: LostAtSeaEncounter,
});
}); });
afterEach(() => { afterEach(() => {
@ -47,14 +49,16 @@ describe("Lost at Sea - Mystery Encounter", () => {
expect(LostAtSeaEncounter.options.length).toBe(3); expect(LostAtSeaEncounter.options.length).toBe(3);
}); });
it("should not run outside of sea biome", async () => {
// TODO: a little tricky
});
it("should not run below wave 11", async () => { it("should not run below wave 11", async () => {
game.override.startingWave(10); game.override.startingWave(10);
await game.runToMysteryEncounter(); await game.runToMysteryEncounter();
const { currentBattle } = game.scene; expect(game.scene.currentBattle.mysteryEncounter).toBeUndefined();
expect(currentBattle).toBeDefined();
expect(currentBattle.mysteryEncounter).toBeUndefined();
}); });
it("should not run above wave 179", async () => { it("should not run above wave 179", async () => {
@ -62,9 +66,7 @@ describe("Lost at Sea - Mystery Encounter", () => {
await game.runToMysteryEncounter(); await game.runToMysteryEncounter();
const { currentBattle } = game.scene; expect(game.scene.currentBattle.mysteryEncounter).toBeUndefined();
expect(currentBattle).toBeDefined();
expect(currentBattle.mysteryEncounter).toBeUndefined();
}); });
it("should set the correct dialog tokens during initialization", () => { it("should set the correct dialog tokens during initialization", () => {
@ -99,6 +101,37 @@ describe("Lost at Sea - Mystery Encounter", () => {
], ],
}); });
}); });
it("should award exp to surfable PKM (Blastoise)", async () => {
const laprasBaseExp = 187;
const wave = 33;
game.override.startingWave(wave);
await workaround_reInitSceneWithOverrides(game);
await game.runToMysteryEncounter(defaultParty);
const party = game.scene.getParty();
const blastoise = party.find((pkm) => pkm.species.speciesId === Species.PIDGEOT);
const expBefore = blastoise.exp;
await runSelectMysteryEncounterOption(game, 2);
expect(blastoise.exp).toBe(expBefore + laprasBaseExp * wave);
});
it("should leave encounter without battle", async () => {
game.override.startingWave(33);
const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle");
await workaround_reInitSceneWithOverrides(game);
await game.runToMysteryEncounter(defaultParty);
await runSelectMysteryEncounterOption(game, 1);
expect(leaveEncounterWithoutBattleSpy).toBeCalled();
});
it("should be disabled if no surfable PKM is in party", async () => {
// TODO
});
}); });
describe("Option 2 - Fly", () => { describe("Option 2 - Fly", () => {
@ -120,22 +153,35 @@ describe("Lost at Sea - Mystery Encounter", () => {
}); });
}); });
it("should award exp to surfable pokemone (Blastoise)", async () => { it("should award exp to flyable PKM (Pidgeot)", async () => {
game.override.startingWave(33); const laprasBaseExp = 187;
const setEncounterExpSpy = vi.spyOn(EncounterPhaseUtils, "setEncounterExp"); const wave = 33;
game.override.startingWave(wave);
workaround_reInitSceneWithOverrides(game); await workaround_reInitSceneWithOverrides(game);
await game.runToMysteryEncounter(defaultParty); await game.runToMysteryEncounter(defaultParty);
let blastoise = game.scene.getParty().find((pkm) => pkm.species.speciesId === Species.BLASTOISE); const party = game.scene.getParty();
console.log("BLASTOISE EXP BEFORE: ", blastoise.exp); const pidgeot = party.find((pkm) => pkm.species.speciesId === Species.PIDGEOT);
const expBefore = pidgeot.exp;
await runSelectMysteryEncounterOption(game, 2); await runSelectMysteryEncounterOption(game, 2);
blastoise = game.scene.getParty().find((pkm) => pkm.species.speciesId === Species.BLASTOISE); expect(pidgeot.exp).toBe(expBefore + laprasBaseExp * wave);
console.log("BLASTOISE EXP AFTER: ", blastoise.exp); });
expect(blastoise.exp).toBe(128); it("should leave encounter without battle", async () => {
expect(setEncounterExpSpy).toHaveBeenCalledWith(expect.anything(), 128, expect.anything(), true); game.override.startingWave(33);
const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle");
await workaround_reInitSceneWithOverrides(game);
await game.runToMysteryEncounter(defaultParty);
await runSelectMysteryEncounterOption(game, 2);
expect(leaveEncounterWithoutBattleSpy).toBeCalled();
});
it("should be disabled if no flyable PKM is in party", async () => {
// TODO
}); });
}); });
@ -156,20 +202,25 @@ describe("Lost at Sea - Mystery Encounter", () => {
}); });
}); });
it("should damage all party pokemon by 25%", async () => { it("should damage all (allowed in battle) party PKM by 25%", async () => {
game.override.startingWave(33); game.override.startingWave(33);
workaround_reInitSceneWithOverrides(game); await workaround_reInitSceneWithOverrides(game);
await game.runToMysteryEncounter(defaultParty); await game.runToMysteryEncounter(defaultParty);
const party = game.scene.getParty();
const abra = party.find((pkm) => pkm.species.speciesId === Species.ABRA);
vi.spyOn(abra, "isAllowedInBattle").mockReturnValue(false);
await runSelectMysteryEncounterOption(game, 3); await runSelectMysteryEncounterOption(game, 3);
game.scene const allowedPkm = party.filter((pkm) => pkm.isAllowedInBattle());
.getParty() const notAllowedPkm = party.filter((pkm) => !pkm.isAllowedInBattle());
.forEach((pkm) => allowedPkm.forEach((pkm) =>
expect(pkm.hp, `${pkm.name} should have receivd 25% damage: ${pkm.hp} / ${pkm.getMaxHp()} HP`).toBe( expect(pkm.hp, `${pkm.name} should have receivd 25% damage: ${pkm.hp} / ${pkm.getMaxHp()} HP`).toBe(pkm.getMaxHp() - Math.floor(pkm.getMaxHp() * 0.25))
pkm.getMaxHp() - Math.floor(pkm.getMaxHp() * 0.25)
)
); );
notAllowedPkm.forEach((pkm) => expect(pkm.hp, `${pkm.name} should be full hp: ${pkm.hp} / ${pkm.getMaxHp()} HP`).toBe(pkm.getMaxHp()));
}); });
it("should leave encounter without battle", async () => { it("should leave encounter without battle", async () => {

View File

@ -8,6 +8,7 @@ import {
EncounterPhase, EncounterPhase,
EnemyCommandPhase, EnemyCommandPhase,
FaintPhase, FaintPhase,
LearnMovePhase,
LoginPhase, LoginPhase,
MessagePhase, MessagePhase,
MoveEffectPhase, MoveEffectPhase,
@ -41,6 +42,7 @@ import {
MysteryEncounterBattlePhase, MysteryEncounterBattlePhase,
MysteryEncounterOptionSelectedPhase, MysteryEncounterOptionSelectedPhase,
MysteryEncounterPhase, MysteryEncounterPhase,
MysteryEncounterRewardsPhase,
PostMysteryEncounterPhase PostMysteryEncounterPhase
} from "#app/phases/mystery-encounter-phase"; } from "#app/phases/mystery-encounter-phase";
@ -100,11 +102,13 @@ export default class PhaseInterceptor {
[MysteryEncounterPhase, this.startPhase], [MysteryEncounterPhase, this.startPhase],
[MysteryEncounterOptionSelectedPhase, this.startPhase], [MysteryEncounterOptionSelectedPhase, this.startPhase],
[MysteryEncounterBattlePhase, this.startPhase], [MysteryEncounterBattlePhase, this.startPhase],
[PostMysteryEncounterPhase, this.startPhase] [MysteryEncounterRewardsPhase, this.startPhase],
[PostMysteryEncounterPhase, this.startPhase],
[LearnMovePhase, this.startPhase]
]; ];
private endBySetMode = [ private endBySetMode = [
TitlePhase, SelectGenderPhase, CommandPhase, SelectModifierPhase TitlePhase, SelectGenderPhase, CommandPhase, SelectModifierPhase, PostMysteryEncounterPhase
]; ];
/** /**