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"; import { useDungeonSimulationStore } from "./dungeonSimulationStore"; /** 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 simulationMode = useDungeonSimulationStore((state) => state.sessionMode); const simulationSeed = useDungeonSimulationStore((state) => state.seed); 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; if (simulationMode === "play") { party.initializeParty( character.id, combat.level, combat.health, playerRole, aiPartySize, character.categoryId ?? "wow", ); } else { party.initializeSpectatorParty(simulationSeed, combat.level, character.categoryId ?? "wow"); } usePartyStore.getState().syncEquipment(combat.equipment, combat.inventory); combat.synchronizeActors(); combat.applyDefaultPartyBuffs(); combat.applyPrecombatPreparation(); resetPartyRuntimeClock(); }, [character?.id, gameMode, manastormPartySize, onlineActivity?.id, playerRole, simulationMode, simulationSeed]); useEffect(() => { const party = usePartyStore.getState(); const combat = useCombatStore.getState(); party.syncLevel(level); usePartyStore.getState().syncEquipment(combat.equipment, combat.inventory); combat.synchronizeActors(); combat.applyDefaultPartyBuffs(); combat.applyPrecombatPreparation(); }, [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); combat.synchronizeActors(); combat.applyDefaultPartyBuffs(); combat.applyPrecombatPreparation(); resetPartyRuntimeClock(); }, [resetRevision]); useEffect(() => useCombatStore.subscribe((state, previous) => { if (state.selectedTargetId && state.selectedTargetId !== previous.selectedTargetId) { usePartyStore.getState().clearSelection(); } }), []); return null; }