forked from phenom/healer-man
72 lines
2.7 KiB
TypeScript
72 lines
2.7 KiB
TypeScript
import { touchCharacter } from "./accountRepository";
|
|
import { useShellStore } from "./shellStore";
|
|
import { activateDungeonSession } from "../game/dungeonSession";
|
|
import { dungeonRouteDefinition } from "../game/dungeonRoutes";
|
|
import { useDungeonSimulationStore } from "../game/dungeonSimulationStore";
|
|
import type { DungeonReplayV1, DungeonSimulationMode } from "../game/dungeonSimulationTypes";
|
|
import { defaultPartyRoleForClass } from "../game/partyRoles";
|
|
import { useGameStore } from "../game/store";
|
|
|
|
function gmCharacter() {
|
|
const shell = useShellStore.getState();
|
|
if (shell.session?.kind !== "account" || !shell.session.accessToken || !shell.session.roles?.includes("gm")) {
|
|
shell.setNotice("Game Master access is required.");
|
|
return null;
|
|
}
|
|
const character = shell.selectedCharacterId
|
|
? touchCharacter(shell.session.ownerId, shell.selectedCharacterId)
|
|
?? shell.characters.find((candidate) => candidate.id === shell.selectedCharacterId)
|
|
: null;
|
|
if (!character) shell.setNotice("Select a character before launching a simulation.");
|
|
return character;
|
|
}
|
|
|
|
export function enterDungeonSimulation(
|
|
dungeonId: string,
|
|
mode: DungeonSimulationMode,
|
|
seed: string,
|
|
): boolean {
|
|
const character = gmCharacter();
|
|
const route = dungeonRouteDefinition(dungeonId);
|
|
if (!character || !route || !seed.trim()) return false;
|
|
if (!activateDungeonSession(dungeonId, undefined, {
|
|
gmTestMode: true,
|
|
dungeonSimulation: true,
|
|
})) {
|
|
useShellStore.getState().setNotice("The dungeon package is unavailable on this client.");
|
|
return false;
|
|
}
|
|
useDungeonSimulationStore.getState().startLive({ dungeonId, route, mode, seed: seed.trim() });
|
|
useGameStore.getState().setCompanionOpen(false);
|
|
useShellStore.setState({
|
|
phase: "game",
|
|
activeCharacter: character,
|
|
activeDungeonId: dungeonId,
|
|
activeDungeonRole: defaultPartyRoleForClass(character.classId),
|
|
notice: "",
|
|
});
|
|
return true;
|
|
}
|
|
|
|
export function enterDungeonSimulationReplay(replay: DungeonReplayV1): boolean {
|
|
const character = gmCharacter();
|
|
if (!character || !dungeonRouteDefinition(replay.dungeonId, replay.routeId)) return false;
|
|
if (!activateDungeonSession(replay.dungeonId, undefined, {
|
|
gmTestMode: true,
|
|
dungeonSimulation: true,
|
|
})) {
|
|
useShellStore.getState().setNotice("The replay dungeon package is unavailable on this client.");
|
|
return false;
|
|
}
|
|
useDungeonSimulationStore.getState().startReplay(replay);
|
|
useGameStore.getState().setCompanionOpen(false);
|
|
useShellStore.setState({
|
|
phase: "game",
|
|
activeCharacter: character,
|
|
activeDungeonId: replay.dungeonId,
|
|
activeDungeonRole: defaultPartyRoleForClass(character.classId),
|
|
notice: "",
|
|
});
|
|
return true;
|
|
}
|