Release Healer Man 0.1.21
This commit is contained in:
1 parent
699fc858c9
commit
f6f2375145
210 files changed
+976039
-6247
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import { useEffect } from "react";
|
||||
import { useShellStore } from "../app/shellStore";
|
||||
import {
|
||||
dispatchDungeonEncounterSignal,
|
||||
registerDungeonEncounterEffectHandler,
|
||||
} from "./dungeonEncounterRuntime";
|
||||
import { LOOT_CATALOG, rollBossLoot } from "./lootCatalog";
|
||||
import { updatePartyRuntimePosition } from "./partyRuntimeRegistry";
|
||||
import { usePartyStore } from "./partyStore";
|
||||
import { useCombatStore } from "./combatStore";
|
||||
import { useGameStore } from "./store";
|
||||
import type { DungeonEncounterEffectEnvelope } from "./dungeonEncounterTypes";
|
||||
import { publishOnlinePartyTeleport } from "./onlineSessionRuntime";
|
||||
|
||||
function grantEncounterLoot(lootTableId: string, now: number): boolean {
|
||||
const table = LOOT_CATALOG.bosses.find((candidate) => candidate.lootTableId === lootTableId);
|
||||
if (!table) return false;
|
||||
const combat = useCombatStore.getState();
|
||||
const drops = rollBossLoot(table.bossKey, combat.level, { now });
|
||||
if (!drops.length) return false;
|
||||
const inventory = [...combat.inventory, ...drops];
|
||||
useCombatStore.setState({ inventory });
|
||||
useShellStore.getState().saveActiveInventory(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Applies platform effects emitted by the renderer-neutral encounter reducer. */
|
||||
export function DungeonEncounterEffectBridge() {
|
||||
useEffect(() => registerDungeonEncounterEffectHandler((envelope) => {
|
||||
applyDungeonEncounterEffect(envelope, Date.now());
|
||||
}), []);
|
||||
return null;
|
||||
}
|
||||
|
||||
export function applyDungeonEncounterEffect(
|
||||
{ effect }: DungeonEncounterEffectEnvelope,
|
||||
now = Date.now(),
|
||||
): void {
|
||||
if (effect.kind === "signal") {
|
||||
dispatchDungeonEncounterSignal(effect.signalId, now);
|
||||
return;
|
||||
}
|
||||
if (effect.kind === "party-teleport") {
|
||||
const game = useGameStore.getState();
|
||||
game.relocatePlayer({ footPosition: effect.destination, yaw: game.cameraYaw }, true);
|
||||
for (const member of usePartyStore.getState().members) {
|
||||
updatePartyRuntimePosition(member.id, ...effect.destination);
|
||||
}
|
||||
publishOnlinePartyTeleport(effect.destination, effect.actionId, now);
|
||||
return;
|
||||
}
|
||||
if (effect.kind === "loot-grant" && !grantEncounterLoot(effect.lootTableId, now)) {
|
||||
useShellStore.getState().setNotice(`Loot table ${effect.lootTableId} is not packaged for this encounter.`);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user