fix all tests for MEs and cleanup

This commit is contained in:
ImperialSympathizer 2024-09-11 18:00:15 -04:00
parent 899a5a5c4a
commit 983c3f0040
10 changed files with 68 additions and 35 deletions

View File

@ -1100,10 +1100,12 @@ export const trainerTypeDialogue: TrainerTypeDialogue = {
"dialogue:stat_trainer_buck.encounter.2" "dialogue:stat_trainer_buck.encounter.2"
], ],
victory: [ victory: [
"dialogue:stat_trainer_buck.victory.1" "dialogue:stat_trainer_buck.victory.1",
"dialogue:stat_trainer_buck.victory.2"
], ],
defeat: [ defeat: [
"dialogue:stat_trainer_buck.defeat.1" "dialogue:stat_trainer_buck.defeat.1",
"dialogue:stat_trainer_buck.defeat.2"
] ]
} }
], ],
@ -1114,10 +1116,12 @@ export const trainerTypeDialogue: TrainerTypeDialogue = {
"dialogue:stat_trainer_cheryl.encounter.2" "dialogue:stat_trainer_cheryl.encounter.2"
], ],
victory: [ victory: [
"dialogue:stat_trainer_cheryl.victory.1" "dialogue:stat_trainer_cheryl.victory.1",
"dialogue:stat_trainer_cheryl.victory.2"
], ],
defeat: [ defeat: [
"dialogue:stat_trainer_cheryl.defeat.1" "dialogue:stat_trainer_cheryl.defeat.1",
"dialogue:stat_trainer_cheryl.defeat.2"
] ]
} }
], ],
@ -1128,10 +1132,12 @@ export const trainerTypeDialogue: TrainerTypeDialogue = {
"dialogue:stat_trainer_marley.encounter.2" "dialogue:stat_trainer_marley.encounter.2"
], ],
victory: [ victory: [
"dialogue:stat_trainer_marley.victory.1" "dialogue:stat_trainer_marley.victory.1",
"dialogue:stat_trainer_marley.victory.2"
], ],
defeat: [ defeat: [
"dialogue:stat_trainer_marley.defeat.1" "dialogue:stat_trainer_marley.defeat.1",
"dialogue:stat_trainer_marley.defeat.2"
] ]
} }
], ],
@ -1142,10 +1148,12 @@ export const trainerTypeDialogue: TrainerTypeDialogue = {
"dialogue:stat_trainer_mira.encounter.2" "dialogue:stat_trainer_mira.encounter.2"
], ],
victory: [ victory: [
"dialogue:stat_trainer_mira.victory.1" "dialogue:stat_trainer_mira.victory.1",
"dialogue:stat_trainer_mira.victory.2"
], ],
defeat: [ defeat: [
"dialogue:stat_trainer_mira.defeat.1" "dialogue:stat_trainer_mira.defeat.1",
"dialogue:stat_trainer_mira.defeat.2"
] ]
} }
], ],
@ -1156,10 +1164,12 @@ export const trainerTypeDialogue: TrainerTypeDialogue = {
"dialogue:stat_trainer_riley.encounter.2" "dialogue:stat_trainer_riley.encounter.2"
], ],
victory: [ victory: [
"dialogue:stat_trainer_riley.victory.1" "dialogue:stat_trainer_riley.victory.1",
"dialogue:stat_trainer_riley.victory.2"
], ],
defeat: [ defeat: [
"dialogue:stat_trainer_riley.defeat.1" "dialogue:stat_trainer_riley.defeat.1",
"dialogue:stat_trainer_riley.defeat.2"
] ]
} }
], ],

View File

@ -61,7 +61,7 @@ export class GameMode implements GameModeConfig {
} }
this.battleConfig = battleConfig || {}; this.battleConfig = battleConfig || {};
this.minMysteryEncounterWave = this.minMysteryEncounterWave ?? 0; this.minMysteryEncounterWave = this.minMysteryEncounterWave ?? 0;
this.maxMysteryEncounterWave = this.maxMysteryEncounterWave ?? Number.MAX_SAFE_INTEGER; this.maxMysteryEncounterWave = this.maxMysteryEncounterWave ?? 100000;
} }
/** /**

View File

@ -173,6 +173,7 @@ describe("Dancing Lessons - Mystery Encounter", () => {
const phaseSpy = vi.spyOn(scene, "unshiftPhase"); const phaseSpy = vi.spyOn(scene, "unshiftPhase");
await game.runToMysteryEncounter(MysteryEncounterType.DANCING_LESSONS, defaultParty); await game.runToMysteryEncounter(MysteryEncounterType.DANCING_LESSONS, defaultParty);
scene.getParty()[0].moveset = [];
await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1 }); await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1 });
const movePhases = phaseSpy.mock.calls.filter(p => p[0] instanceof LearnMovePhase).map(p => p[0]); const movePhases = phaseSpy.mock.calls.filter(p => p[0] instanceof LearnMovePhase).map(p => p[0]);
@ -184,6 +185,7 @@ describe("Dancing Lessons - Mystery Encounter", () => {
const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle"); const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle");
await game.runToMysteryEncounter(MysteryEncounterType.DANCING_LESSONS, defaultParty); await game.runToMysteryEncounter(MysteryEncounterType.DANCING_LESSONS, defaultParty);
scene.getParty()[0].moveset = [];
await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1 }); await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1 });
expect(leaveEncounterWithoutBattleSpy).toBeCalled(); expect(leaveEncounterWithoutBattleSpy).toBeCalled();

View File

@ -186,7 +186,7 @@ describe("Teleporting Hijinks - Mystery Encounter", () => {
expect([Biome.SPACE, Biome.ISLAND, Biome.LABORATORY, Biome.FAIRY_CAVE]).toContain(scene.arena.biomeType); expect([Biome.SPACE, Biome.ISLAND, Biome.LABORATORY, Biome.FAIRY_CAVE]).toContain(scene.arena.biomeType);
}); });
it("should start a battle against an enraged boss", async () => { it("should start a battle against an enraged boss", { retry: 5 }, async () => {
await game.runToMysteryEncounter(MysteryEncounterType.TELEPORTING_HIJINKS, defaultParty); await game.runToMysteryEncounter(MysteryEncounterType.TELEPORTING_HIJINKS, defaultParty);
await runMysteryEncounterToEnd(game, 1, undefined, true); await runMysteryEncounterToEnd(game, 1, undefined, true);
const enemyField = scene.getEnemyField(); const enemyField = scene.getEnemyField();

View File

@ -21,6 +21,9 @@ import { getPokemonSpecies } from "#app/data/pokemon-species";
import { BerryType } from "#enums/berry-type"; import { BerryType } from "#enums/berry-type";
import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase";
import { Stat } from "#enums/stat"; import { Stat } from "#enums/stat";
import { BerryModifier } from "#app/modifier/modifier";
import { generateModifierType } from "#app/data/mystery-encounters/utils/encounter-phase-utils";
import { modifierTypes } from "#app/modifier/modifier-type";
const namespace = "mysteryEncounter:uncommonBreed"; const namespace = "mysteryEncounter:uncommonBreed";
const defaultParty = [Species.LAPRAS, Species.GENGAR, Species.ABRA]; const defaultParty = [Species.LAPRAS, Species.GENGAR, Species.ABRA];
@ -164,8 +167,11 @@ describe("Uncommon Breed - Mystery Encounter", () => {
}); });
it("should NOT be selectable if the player doesn't have enough berries", async () => { it("should NOT be selectable if the player doesn't have enough berries", async () => {
game.override.startingHeldItems([]);
await game.runToMysteryEncounter(MysteryEncounterType.UNCOMMON_BREED, defaultParty); await game.runToMysteryEncounter(MysteryEncounterType.UNCOMMON_BREED, defaultParty);
// Clear out any pesky mods that slipped through test spin-up
scene.modifiers.forEach(mod => {
scene.removeModifier(mod);
});
await game.phaseInterceptor.to(MysteryEncounterPhase, false); await game.phaseInterceptor.to(MysteryEncounterPhase, false);
const encounterPhase = scene.getCurrentPhase(); const encounterPhase = scene.getCurrentPhase();
@ -184,11 +190,21 @@ describe("Uncommon Breed - Mystery Encounter", () => {
}); });
it("Should skip fight when player meets requirements", async () => { it("Should skip fight when player meets requirements", async () => {
game.override.startingHeldItems([{name: "BERRY", count: 2, type: BerryType.SITRUS}, {name: "BERRY", count: 3, type: BerryType.GANLON}]);
const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle"); const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle");
await game.runToMysteryEncounter(MysteryEncounterType.UNCOMMON_BREED, defaultParty); await game.runToMysteryEncounter(MysteryEncounterType.UNCOMMON_BREED, defaultParty);
// Berries on party lead
const sitrus = generateModifierType(scene, modifierTypes.BERRY, [BerryType.SITRUS])!;
const sitrusMod = sitrus.newModifier(scene.getParty()[0]) as BerryModifier;
sitrusMod.stackCount = 2;
await scene.addModifier(sitrusMod, true, false, false, true);
const ganlon = generateModifierType(scene, modifierTypes.BERRY, [BerryType.GANLON])!;
const ganlonMod = ganlon.newModifier(scene.getParty()[0]) as BerryModifier;
ganlonMod.stackCount = 3;
await scene.addModifier(ganlonMod, true, false, false, true);
await scene.updateModifiers(true);
await runMysteryEncounterToEnd(game, 2); await runMysteryEncounterToEnd(game, 2);
expect(leaveEncounterWithoutBattleSpy).toBeCalled(); expect(leaveEncounterWithoutBattleSpy).toBeCalled();

View File

@ -227,7 +227,7 @@ export default class GameWrapper {
}; };
this.scene.make = new MockGameObjectCreator(mockTextureManager); this.scene.make = new MockGameObjectCreator(mockTextureManager);
this.scene.time = new MockClock(this.scene); this.scene.time = new MockClock(this.scene);
this.scene.remove = vi.fn(); this.scene.remove = vi.fn(); // TODO: this should be stubbed differently
} }
} }

View File

@ -7,7 +7,6 @@ import MockSprite from "#test/utils/mocks/mocksContainer/mockSprite";
import MockText from "#test/utils/mocks/mocksContainer/mockText"; import MockText from "#test/utils/mocks/mocksContainer/mockText";
import MockTexture from "#test/utils/mocks/mocksContainer/mockTexture"; import MockTexture from "#test/utils/mocks/mocksContainer/mockTexture";
import { MockGameObject } from "./mockGameObject"; import { MockGameObject } from "./mockGameObject";
import { vi } from "vitest";
import { MockVideoGameObject } from "./mockVideoGameObject"; import { MockVideoGameObject } from "./mockVideoGameObject";
/** /**
@ -36,7 +35,7 @@ export default class MockTextureManager {
text: this.text.bind(this), text: this.text.bind(this),
bitmapText: this.text.bind(this), bitmapText: this.text.bind(this),
displayList: this.displayList, displayList: this.displayList,
video: vi.fn(() => new MockVideoGameObject()), video: () => new MockVideoGameObject(),
}; };
} }

View File

@ -1,5 +1,4 @@
import MockTextureManager from "#test/utils/mocks/mockTextureManager"; import MockTextureManager from "#test/utils/mocks/mockTextureManager";
import { vi } from "vitest";
import { MockGameObject } from "../mockGameObject"; import { MockGameObject } from "../mockGameObject";
export default class MockContainer implements MockGameObject { export default class MockContainer implements MockGameObject {
@ -36,7 +35,9 @@ export default class MockContainer implements MockGameObject {
// same as remove or destroy // same as remove or destroy
} }
removeBetween = vi.fn((startIndex, endIndex, destroyChild) => {}); removeBetween(startIndex, endIndex, destroyChild) {
// Removes multiple children across an index range
}
addedToScene() { addedToScene() {
// This callback is invoked when this Game Object is added to a Scene. // This callback is invoked when this Game Object is added to a Scene.
@ -154,7 +155,9 @@ export default class MockContainer implements MockGameObject {
// Sends this Game Object to the back of its parent's display list. // Sends this Game Object to the back of its parent's display list.
} }
moveTo = vi.fn((obj) => {}); moveTo(obj) {
// Moves this Game Object to the given index in the list.
}
moveAbove(obj) { moveAbove(obj) {
// Moves this Game Object to be above the given Game Object in the display list. // Moves this Game Object to be above the given Game Object in the display list.
@ -164,9 +167,9 @@ export default class MockContainer implements MockGameObject {
// Moves this Game Object to be below the given Game Object in the display list. // Moves this Game Object to be below the given Game Object in the display list.
} }
setName = (name: string) => { setName(name: string) {
this.name = name; this.name = name;
}; }
bringToTop(obj) { bringToTop(obj) {
// Brings this Game Object to the top of its parents display list. // Brings this Game Object to the top of its parents display list.
@ -210,9 +213,9 @@ export default class MockContainer implements MockGameObject {
return this.list; return this.list;
} }
getByName = vi.fn((key: string) => { getByName(key: string) {
return this.list.find(v => v.name === key) ?? new MockContainer(this.textureManager, 0, 0); return this.list.find(v => v.name === key) ?? new MockContainer(this.textureManager, 0, 0);
}); }
disableInteractive = () => null; disableInteractive = () => null;
} }

View File

@ -79,19 +79,19 @@ export default class MockText implements MockGameObject {
return result; return result;
} }
showText = vi.fn((text: string, delay?: integer | null, callback?: Function | null, callbackDelay?: integer | null, prompt?: boolean | null, promptDelay?: integer | null) => { showText(text: string, delay?: integer | null, callback?: Function | null, callbackDelay?: integer | null, prompt?: boolean | null, promptDelay?: integer | null) {
this.scene.messageWrapper.showText(text, delay, callback, callbackDelay, prompt, promptDelay); this.scene.messageWrapper.showText(text, delay, callback, callbackDelay, prompt, promptDelay);
if (callback) { if (callback) {
callback(); callback();
} }
}); }
showDialogue = vi.fn((keyOrText: string, name: string | undefined, delay: integer | null = 0, callback: Function, callbackDelay?: integer, promptDelay?: integer) => { showDialogue(keyOrText: string, name: string | undefined, delay: integer | null = 0, callback: Function, callbackDelay?: integer, promptDelay?: integer) {
this.scene.messageWrapper.showDialogue(keyOrText, name, delay, callback, callbackDelay, promptDelay); this.scene.messageWrapper.showDialogue(keyOrText, name, delay, callback, callbackDelay, promptDelay);
if (callback) { if (callback) {
callback(); callback();
} }
}); }
setScale(scale) { setScale(scale) {
// return this.phaserText.setScale(scale); // return this.phaserText.setScale(scale);
@ -200,9 +200,9 @@ export default class MockText implements MockGameObject {
}; };
} }
setColor = (color: string) => { setColor(color: string) {
this.color = color; this.color = color;
}; }
setInteractive = () => null; setInteractive = () => null;
@ -230,9 +230,9 @@ export default class MockText implements MockGameObject {
// return this.phaserText.setAlpha(alpha); // return this.phaserText.setAlpha(alpha);
} }
setName = (name: string) => { setName(name: string) {
this.name = name; this.name = name;
}; }
setAlign(align) { setAlign(align) {
// return this.phaserText.setAlign(align); // return this.phaserText.setAlign(align);
@ -256,9 +256,13 @@ export default class MockText implements MockGameObject {
}; };
} }
disableInteractive = vi.fn(); disableInteractive() {
// Disables interaction with this Game Object.
}
clearTint = vi.fn(); clearTint() {
// Clears tint on this Game Object.
}
add(obj) { add(obj) {
// Adds a child to this Game Object. // Adds a child to this Game Object.

View File

@ -126,7 +126,6 @@ export default class PhaseInterceptor {
[MysteryEncounterBattlePhase, this.startPhase], [MysteryEncounterBattlePhase, this.startPhase],
[MysteryEncounterRewardsPhase, this.startPhase], [MysteryEncounterRewardsPhase, this.startPhase],
[PostMysteryEncounterPhase, this.startPhase], [PostMysteryEncounterPhase, this.startPhase],
[LearnMovePhase, this.startPhase],
[ModifierRewardPhase, this.startPhase], [ModifierRewardPhase, this.startPhase],
[PartyExpPhase, this.startPhase] [PartyExpPhase, this.startPhase]
]; ];