Files
healer-man/src/game/DungeonEncounterEffectBridge.test.ts
T
2026-09-09 11:21:33 -04:00

68 lines
2.5 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { applyDungeonEncounterEffect } from "./DungeonEncounterEffectBridge";
import { clearPartyRuntimeRegistry, getPartyRuntimePosition, updatePartyRuntimePosition } from "./partyRuntimeRegistry";
import { usePartyStore } from "./partyStore";
import { useGameStore } from "./store";
import { useCombatStore } from "./combatStore";
import {
clearMobRuntimeRegistry,
getMobRuntimePosition,
registerMobRuntime,
} from "./mobRuntimeRegistry";
import { DUNGEON_REGISTRY } from "./dungeonRegistry";
afterEach(() => {
clearPartyRuntimeRegistry();
clearMobRuntimeRegistry();
usePartyStore.setState({ members: [] });
});
describe("dungeon encounter effects", () => {
it("teleports the player and every current party runtime actor", () => {
usePartyStore.getState().initializeParty("encounter-effect-test", 1, 10);
const allyId = usePartyStore.getState().members[0].id;
updatePartyRuntimePosition(allyId, 0, 0, 0);
applyDungeonEncounterEffect({
dungeonId: useGameStore.getState().activeDungeonId,
encounterId: "test:transition",
effect: {
kind: "party-teleport",
actionId: "cross-threshold",
destination: [12, 3, -8],
},
}, 100);
expect(useGameStore.getState().playerPosition).toEqual([12, 3, -8]);
expect(getPartyRuntimePosition(allyId)).toEqual([12, 3, -8]);
});
it("removes every combat and spatial actor owned by a deactivated spawn group", () => {
const dungeon = DUNGEON_REGISTRY["wailing-caverns"];
const group = dungeon.encounterSpawnGroups?.find(
(candidate) => candidate.id === "naralex-ravagers",
);
expect(group).toBeDefined();
for (const spawn of group!.spawns) {
useCombatStore.getState().registerMob(spawn.id, { name: spawn.id, maxHealth: 100 });
registerMobRuntime(spawn.id, spawn.position);
}
useCombatStore.getState().registerMob("unrelated", { name: "Unrelated", maxHealth: 100 });
applyDungeonEncounterEffect({
dungeonId: dungeon.id,
encounterId: "wailing-caverns:naralex",
effect: {
kind: "despawn-group",
actionId: "cleanup-ravagers",
spawnGroupId: group!.id,
},
}, 100);
for (const spawn of group!.spawns) {
expect(useCombatStore.getState().mobs[spawn.id]).toBeUndefined();
expect(getMobRuntimePosition(spawn.id)).toBeNull();
}
expect(useCombatStore.getState().mobs.unrelated).toBeDefined();
useCombatStore.getState().removeMob("unrelated");
});
});