38 lines
2.3 KiB
TypeScript
38 lines
2.3 KiB
TypeScript
import { useShellStore } from "./shellStore";
|
|
import { specializationById } from "../game/specializationCatalog";
|
|
import { defaultPartyRoleForClass, type PartyRole } from "../game/partyRoles";
|
|
import { createBossTestingRoom, type TestableBoss } from "../game/bossTesting";
|
|
import { clearBossTestingDungeons, registerBossTestingDungeon, requireDungeonDefinition } from "../game/dungeonRegistry";
|
|
import { activateDungeonSession } from "../game/dungeonSession";
|
|
import { dungeonContentIsUsable, initializeContentSystem, installContentPack } from "../content/contentManager";
|
|
|
|
let preparationQueue: Promise<void> = Promise.resolve();
|
|
|
|
export async function prepareBossTesting(boss: TestableBoss): Promise<void> {
|
|
if (dungeonContentIsUsable(boss.dungeonId)) return;
|
|
const preparation = preparationQueue.then(async () => {
|
|
await initializeContentSystem();
|
|
if (!dungeonContentIsUsable(boss.dungeonId)) await installContentPack(`dungeon:${boss.dungeonId}`);
|
|
if (!dungeonContentIsUsable(boss.dungeonId)) throw new Error("The boss assets could not be verified. Please retry the download.");
|
|
});
|
|
preparationQueue = preparation.catch(() => undefined);
|
|
await preparation;
|
|
}
|
|
|
|
export function enterBossTesting(boss: TestableBoss, requestedRole?: PartyRole): boolean {
|
|
const shell = useShellStore.getState();
|
|
const character = shell.characters.find((entry) => entry.id === shell.selectedCharacterId);
|
|
if (!shell.session || !character) throw new Error("Select a character first.");
|
|
const specialization = specializationById(character.specializationId);
|
|
if (character.categoryId !== "rom" && !specialization) throw new Error("Choose a specialization in the Class Hall first.");
|
|
const { definition, session } = createBossTestingRoom(requireDungeonDefinition(boss.dungeonId), boss);
|
|
registerBossTestingDungeon(definition, boss.dungeonId);
|
|
if (!activateDungeonSession(definition.id, undefined, { gmTestMode: true, bossTest: session })) {
|
|
clearBossTestingDungeons();
|
|
throw new Error("The boss testing room could not be started. Check the downloaded assets and retry.");
|
|
}
|
|
useShellStore.setState({ phase: "game", activeCharacter: character, activeDungeonId: definition.id,
|
|
activeDungeonRole: specialization?.role ?? requestedRole ?? defaultPartyRoleForClass(character.classId), notice: "" });
|
|
return true;
|
|
}
|