Files
healer-man/src/game/PartyBridge.tsx
T
2026-08-14 15:56:39 -04:00

55 lines
2.0 KiB
TypeScript

import { useEffect, useRef } from "react";
import { useShellStore } from "../app/shellStore";
import { useCombatStore } from "./combatStore";
import { resetPartyRuntimeClock } from "./partyRuntime";
import { usePartyStore } from "./partyStore";
import { useGameStore } from "./store";
import { useManastormStore } from "./manastormStore";
/** Owns party lifecycle; the combat interval itself remains in CombatBridge. */
export function PartyBridge() {
const character = useShellStore((state) => state.activeCharacter);
const playerRole = useShellStore((state) => state.activeDungeonRole);
const gameMode = useGameStore((state) => state.gameMode);
const manastormPartySize = useManastormStore((state) => state.partySize);
const level = useCombatStore((state) => state.level);
const resetRevision = useGameStore((state) => state.resetRevision);
const mountedResetRevision = useRef(resetRevision);
useEffect(() => {
if (!character) return;
const combat = useCombatStore.getState();
const party = usePartyStore.getState();
party.initializeParty(
character.id,
combat.level,
combat.health,
playerRole,
gameMode === "manastorm" ? manastormPartySize : 5,
character.categoryId ?? "wow",
);
usePartyStore.getState().syncEquipment(combat.equipment, combat.inventory);
resetPartyRuntimeClock();
}, [character?.id, gameMode, manastormPartySize, playerRole]);
useEffect(() => {
usePartyStore.getState().syncLevel(level);
}, [level]);
useEffect(() => {
if (mountedResetRevision.current === resetRevision) return;
mountedResetRevision.current = resetRevision;
const combat = useCombatStore.getState();
usePartyStore.getState().resetCombat(combat.level, combat.health);
resetPartyRuntimeClock();
}, [resetRevision]);
useEffect(() => useCombatStore.subscribe((state, previous) => {
if (state.selectedTargetId && state.selectedTargetId !== previous.selectedTargetId) {
usePartyStore.getState().clearSelection();
}
}), []);
return null;
}