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"; import { onlineGroupAiPartySize, useOnlineGroupStore } from "../app/onlineGroupStore"; /** 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 onlineActivity = useOnlineGroupStore((state) => state.activeActivity); 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(); const requestedPartySize = gameMode === "manastorm" ? manastormPartySize : 5; const aiPartySize = onlineActivity && onlineActivity.type === (gameMode === "manastorm" ? "manastorm" : "dungeon") ? onlineGroupAiPartySize(onlineActivity.partySize) : requestedPartySize; party.initializeParty( character.id, combat.level, combat.health, playerRole, aiPartySize, character.categoryId ?? "wow", ); usePartyStore.getState().syncEquipment(combat.equipment, combat.inventory); resetPartyRuntimeClock(); }, [character?.id, gameMode, manastormPartySize, onlineActivity?.id, playerRole]); useEffect(() => { const party = usePartyStore.getState(); const combat = useCombatStore.getState(); party.syncLevel(level); usePartyStore.getState().syncEquipment(combat.equipment, combat.inventory); }, [level]); useEffect(() => { if (mountedResetRevision.current === resetRevision) return; mountedResetRevision.current = resetRevision; const combat = useCombatStore.getState(); usePartyStore.getState().resetCombat(combat.level, combat.health); usePartyStore.getState().syncEquipment(combat.equipment, combat.inventory); resetPartyRuntimeClock(); }, [resetRevision]); useEffect(() => useCombatStore.subscribe((state, previous) => { if (state.selectedTargetId && state.selectedTargetId !== previous.selectedTargetId) { usePartyStore.getState().clearSelection(); } }), []); return null; }