diff --git a/src/components/game/crafting/EquipmentCrafter.tsx b/src/components/game/crafting/EquipmentCrafter.tsx index 4b547f0..ab6f154 100644 --- a/src/components/game/crafting/EquipmentCrafter.tsx +++ b/src/components/game/crafting/EquipmentCrafter.tsx @@ -11,16 +11,16 @@ import { CRAFTING_RECIPES, canCraftRecipe } from '@/lib/game/data/crafting-recip import { LOOT_DROPS, RARITY_COLORS } from '@/lib/game/data/loot-drops'; import type { EquipmentInstance, AppliedEnchantment, LootInventory, EquipmentCraftingProgress } from '@/lib/game/types'; import { fmt } from '@/lib/game/stores'; -import { useGameStore } from '@/lib/game/stores'; +import { useGameStore, useCraftingStore } from '@/lib/game/stores'; export function EquipmentCrafter() { - const lootInventory = useGameStore((s) => s.lootInventory); + const lootInventory = useCraftingStore((s) => s.lootInventory); const equipmentCraftingProgress = useGameStore((s) => s.equipmentCraftingProgress); const rawMana = useGameStore((s) => s.rawMana); const currentAction = useGameStore((s) => s.currentAction); const startCraftingEquipment = useGameStore((s) => s.startCraftingEquipment); const cancelEquipmentCrafting = useGameStore((s) => s.cancelEquipmentCrafting); - const deleteMaterial = useGameStore((s) => s.deleteMaterial); + const deleteMaterial = useCraftingStore((s) => s.deleteMaterial); return (
diff --git a/src/components/game/debug/GameStateDebug.tsx b/src/components/game/debug/GameStateDebug.tsx index 266248a..80fd341 100644 --- a/src/components/game/debug/GameStateDebug.tsx +++ b/src/components/game/debug/GameStateDebug.tsx @@ -10,7 +10,7 @@ import { RotateCcw, AlertTriangle, Zap, Clock, Settings, Eye, } from 'lucide-react'; import { useDebug } from '@/lib/game/debug-context'; -import { useGameStore, useManaStore } from '@/lib/game/stores'; +import { useGameStore, useManaStore, useUIStore, useCombatStore } from '@/lib/game/stores'; import { computeMaxMana } from '@/lib/game/stores'; export function GameStateDebug() { @@ -24,14 +24,14 @@ export function GameStateDebug() { const gatherMana = useGameStore((s) => s.gatherMana); const day = useGameStore((s) => s.day); const hour = useGameStore((s) => s.hour); - const paused = useGameStore((s) => s.paused); - const togglePause = useGameStore((s) => s.togglePause); + const paused = useUIStore((s) => s.paused); + const togglePause = useUIStore((s) => s.togglePause); // Get actions from stores const resetGame = useGameStore((s) => s.resetGame); - const setTime = useGameStore((s) => s.debugSetTime); - const setFloor = useGameStore((s) => s.debugSetFloor); - const resetHP = useGameStore((s) => s.resetFloorHP); + const setTime = useCombatStore((s) => s.debugSetTime); + const setFloor = useCombatStore((s) => s.debugSetFloor); + const resetHP = useCombatStore((s) => s.resetFloorHP); const handleReset = () => { if (confirmReset) { diff --git a/src/components/game/debug/PactDebug.tsx b/src/components/game/debug/PactDebug.tsx index 1d3f71a..4d0be03 100644 --- a/src/components/game/debug/PactDebug.tsx +++ b/src/components/game/debug/PactDebug.tsx @@ -3,25 +3,29 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Bug } from 'lucide-react'; -import { useGameStore } from '@/lib/game/stores'; +import { usePrestigeStore, useManaStore, useUIStore } from '@/lib/game/stores'; import { GUARDIANS, ELEMENTS } from '@/lib/game/constants'; export function PactDebug() { - // Get state from the main game store where pacts are stored - const store = useGameStore(); - const signedPacts = useGameStore((s) => s.signedPacts); - const signedPactDetails = useGameStore((s) => s.signedPactDetails); - const elements = useGameStore((s) => s.elements); - const prestigeUpgrades = useGameStore((s) => s.prestigeUpgrades); + // Get state from modular stores + const signedPacts = usePrestigeStore((s) => s.signedPacts); + const signedPactDetails = usePrestigeStore((s) => s.signedPactDetails); + const elements = useManaStore((s) => s.elements); + const prestigeUpgrades = usePrestigeStore((s) => s.prestigeUpgrades); + + // Get actions + const addSignedPact = usePrestigeStore((s) => s.addSignedPact); + const removePact = usePrestigeStore((s) => s.removePact); + const debugSetSignedPacts = usePrestigeStore((s) => s.debugSetSignedPacts); + const debugSetPactDetails = usePrestigeStore((s) => s.debugSetPactDetails); + const unlockElement = useManaStore((s) => s.unlockElement); + + // Get log function from uiStore + const addLog = useUIStore((s) => s.addLog); // Get all guardian floors const guardianFloors = Object.keys(GUARDIANS).map(Number).sort((a, b) => a - b); - // Helper to add log messages - const addLog = (message: string) => { - store.log.unshift(message); - }; - // Force sign a pact with a guardian (bypass costs and time) const forcePact = (floor: number) => { const guardian = GUARDIANS[floor]; @@ -41,7 +45,7 @@ export function PactDebug() { } // Force sign the pact - const newSignedPacts = [...signedPacts, floor]; + addSignedPact(floor); // Add pact details const newSignedPactDetails = { @@ -49,74 +53,59 @@ export function PactDebug() { [floor]: { floor, guardianId: guardian.element, - signedAt: { day: store.day, hour: store.hour }, + signedAt: { day: useGameStore.getState().day, hour: useGameStore.getState().hour }, skillLevels: {} as Record, }, }; + debugSetPactDetails(newSignedPactDetails); // Unlock mana types - let newElements = { ...elements }; for (const elemId of guardian.unlocksMana) { - if (newElements[elemId]) { - newElements = { - ...newElements, - [elemId]: { ...newElements[elemId], unlocked: true }, - }; + if (!elements[elemId]?.unlocked) { + unlockElement(elemId, 500); } } // Check for compound element unlocks + const currentElements = useManaStore.getState().elements; const unlockedSet = new Set( - Object.entries(newElements) + Object.entries(currentElements) .filter(([, e]) => e.unlocked) .map(([id]) => id) ); for (const [elemId, elemDef] of Object.entries(ELEMENTS)) { - if (elemDef.recipe && !newElements[elemId]?.unlocked) { + if (elemDef.recipe && !currentElements[elemId]?.unlocked) { const canUnlock = elemDef.recipe.every((comp: string) => unlockedSet.has(comp)); if (canUnlock) { - newElements = { - ...newElements, - [elemId]: { ...newElements[elemId], unlocked: true }, - }; + unlockElement(elemId, 500); addLog(`🔮 ${elemDef.name} mana unlocked through component synergy!`); } } } addLog(`📜 DEBUG: Pact with ${guardian.name} force-signed! ${guardian.unlocksMana.map(e => ELEMENTS[e]?.name || e).join(', ')} mana unlocked!`); - - // Update store - store.setState({ - signedPacts: newSignedPacts, - signedPactDetails: newSignedPactDetails, - elements: newElements, - }); }; // Remove a pact - const removePact = (floor: number) => { + const removePactHandler = (floor: number) => { const guardian = GUARDIANS[floor]; - const newSignedPacts = signedPacts.filter(f => f !== floor); + + removePact(floor); + + // Remove pact details const newSignedPactDetails = { ...signedPactDetails }; delete newSignedPactDetails[floor]; + debugSetPactDetails(newSignedPactDetails); addLog(`📜 DEBUG: Removed pact with ${guardian?.name || 'Unknown'}!`); - - store.setState({ - signedPacts: newSignedPacts, - signedPactDetails: newSignedPactDetails, - }); }; // Clear all pacts const clearAllPacts = () => { addLog(`📜 DEBUG: Cleared all pacts!`); - store.setState({ - signedPacts: [], - signedPactDetails: {}, - }); + debugSetSignedPacts([]); + debugSetPactDetails({}); }; return ( @@ -162,7 +151,7 @@ export function PactDebug() { diff --git a/src/components/game/tabs/SkillsTab.tsx b/src/components/game/tabs/SkillsTab.tsx index 902c780..8a91a6f 100755 --- a/src/components/game/tabs/SkillsTab.tsx +++ b/src/components/game/tabs/SkillsTab.tsx @@ -19,7 +19,7 @@ import { } from '@/lib/game/skill-evolution'; import { getUnifiedEffects } from '@/lib/game/effects'; import { getAvailableSkillCategories } from '@/lib/game/data/attunements'; -import { fmt, fmtDec } from '@/lib/game/stores'; +import { fmt, fmtDec, useAttunementStore } from '@/lib/game/stores'; import type { SkillUpgradeChoice } from '@/lib/game/types'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; @@ -166,7 +166,7 @@ export function SkillsTab() { }; // Get available skill categories based on attunements - const attunements = useGameStore((s) => s.attunements); + const attunements = useAttunementStore((s) => s.attunements); const availableCategories = getAvailableSkillCategories(attunements || {}); return ( diff --git a/src/lib/game/stores/combatStore.ts b/src/lib/game/stores/combatStore.ts index 7e1a040..31004e9 100755 --- a/src/lib/game/stores/combatStore.ts +++ b/src/lib/game/stores/combatStore.ts @@ -7,6 +7,7 @@ import { SPELLS_DEF, GUARDIANS, HOURS_PER_TICK } from '../constants'; import type { GameAction, SpellState } from '../types'; import { getFloorMaxHP, getFloorElement, calcDamage, canAffordSpellCost, deductSpellCost } from '../utils'; import { usePrestigeStore } from './prestigeStore'; +import { useGameStore } from './gameStore'; export interface CombatState { // Floor state @@ -56,6 +57,11 @@ export interface CombatState { // Reset resetCombat: (startFloor: number, spellsToKeep?: string[]) => void; + + // Debug helpers + debugSetFloor: (floor: number) => void; + resetFloorHP: () => void; + debugSetTime: (day: number, hour: number) => void; } export const useCombatStore = create()( @@ -244,6 +250,25 @@ export const useCombatStore = create()( spells: startSpells, }); }, + + // Debug helpers + debugSetFloor: (floor: number) => { + set({ + currentFloor: floor, + floorHP: getFloorMaxHP(floor), + floorMaxHP: getFloorMaxHP(floor), + }); + }, + + resetFloorHP: () => { + set((state) => ({ + floorHP: state.floorMaxHP, + })); + }, + + debugSetTime: (day: number, hour: number) => { + useGameStore.setState({ day, hour }); + }, }), { name: 'mana-loop-combat', diff --git a/src/lib/game/stores/craftingStore.ts b/src/lib/game/stores/craftingStore.ts index dc5b80d..eeabf96 100644 --- a/src/lib/game/stores/craftingStore.ts +++ b/src/lib/game/stores/craftingStore.ts @@ -37,6 +37,11 @@ export interface CraftingState { equipmentInstances: Record; // Equipped instances (slot -> instanceId or null) equippedInstances: Record; + // Loot inventory + lootInventory: { + materials: Record; + blueprints: string[]; + }; } export interface CraftingActions { @@ -68,6 +73,10 @@ export interface CraftingActions { // Enchantment preparation actions startPreparing: (equipmentInstanceId: string) => boolean; cancelPreparation: () => void; + + // Loot inventory actions + deleteMaterial: (materialId: string, amount: number) => void; + deleteEquipmentInstance: (instanceId: string) => void; } export type CraftingStore = CraftingState & CraftingActions; @@ -85,6 +94,10 @@ export const useCraftingStore = create()( unlockedEffects: [], equipmentInstances: {}, equippedInstances: {}, + lootInventory: { + materials: {}, + blueprints: [], + }, // Actions setDesignProgress: (progress) => set({ designProgress: progress }), @@ -221,6 +234,47 @@ export const useCraftingStore = create()( PreparationActions.cancelPreparation(set); useGameStore.setState({ currentAction: 'meditate' }); }, + + // Loot inventory actions + deleteMaterial: (materialId: string, amount: number) => { + set((state) => { + const newMaterials = { ...state.lootInventory.materials }; + const currentAmount = newMaterials[materialId] || 0; + const newAmount = Math.max(0, currentAmount - amount); + + if (newAmount <= 0) { + delete newMaterials[materialId]; + } else { + newMaterials[materialId] = newAmount; + } + + return { + lootInventory: { + ...state.lootInventory, + materials: newMaterials, + }, + }; + }); + }, + + deleteEquipmentInstance: (instanceId: string) => { + set((state) => { + let newEquipped = { ...state.equippedInstances }; + for (const [slot, id] of Object.entries(newEquipped)) { + if (id === instanceId) { + newEquipped[slot as any] = null; + } + } + + const newInstances = { ...state.equipmentInstances }; + delete newInstances[instanceId]; + + return { + equippedInstances: newEquipped, + equipmentInstances: newInstances, + }; + }); + }, }), { name: 'mana-loop-crafting', @@ -234,6 +288,7 @@ export const useCraftingStore = create()( unlockedEffects: state.unlockedEffects, equipmentInstances: state.equipmentInstances, equippedInstances: state.equippedInstances, + lootInventory: state.lootInventory, }), } ) diff --git a/src/lib/game/stores/prestigeStore.ts b/src/lib/game/stores/prestigeStore.ts index 7480338..6144bb3 100755 --- a/src/lib/game/stores/prestigeStore.ts +++ b/src/lib/game/stores/prestigeStore.ts @@ -26,6 +26,12 @@ export interface PrestigeState { // Guardian pacts defeatedGuardians: number[]; signedPacts: number[]; + signedPactDetails: Record; + }>; pactRitualFloor: number | null; pactRitualProgress: number; @@ -73,6 +79,12 @@ const initialState = { memories: [] as Memory[], defeatedGuardians: [] as number[], signedPacts: [] as number[], + signedPactDetails: {} as Record; + }>, pactRitualFloor: null as number | null, pactRitualProgress: 0, }; @@ -249,6 +261,19 @@ export const usePrestigeStore = create()( resetPrestige: () => { set(initialState); }, + + // Debug helpers + debugSetSignedPacts: (pacts: number[]) => { + set({ signedPacts: pacts }); + }, + debugSetPactDetails: (details: Record; + }>) => { + set({ signedPactDetails: details }); + }, }), { name: 'mana-loop-prestige',