fix: lootInventory, prestige, golemancy, attunementStore export, debug components
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m21s

This commit is contained in:
Refactoring Agent
2026-05-05 15:00:22 +02:00
parent f0532c1673
commit ed616738fd
10 changed files with 171 additions and 68 deletions
@@ -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 (
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
+6 -6
View File
@@ -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) {
+34 -45
View File
@@ -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<string, number>,
},
};
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() {
<Button
size="sm"
variant="destructive"
onClick={() => removePact(floor)}
onClick={() => removePactHandler(floor)}
className="text-xs"
>
Remove
+2 -2
View File
@@ -9,10 +9,10 @@ import {
} from 'lucide-react';
import { GOLEMS_DEF, getGolemSlots, isGolemUnlocked, getGolemDamage, getGolemAttackSpeed, getGolemFloorDuration } from '@/lib/game/data/golems';
import { ELEMENTS } from '@/lib/game/constants';
import { useGameStore, useManaStore, useSkillStore, useCombatStore } from '@/lib/game/stores';
import { useGameStore, useManaStore, useSkillStore, useCombatStore, useAttunementStore } from '@/lib/game/stores';
export function GolemancyTab() {
const attunements = useGameStore((s) => s.attunements);
const attunements = useAttunementStore((s) => s.attunements);
const elements = useManaStore((s) => s.elements);
const skills = useSkillStore((s) => s.skills);
const golemancy = useGameStore((s) => s.golemancy);
+5 -5
View File
@@ -1,14 +1,14 @@
'use client';
import { useGameStore, useCraftingStore } from '@/lib/game/stores';
import { useCraftingStore, useManaStore } from '@/lib/game/stores';
import { LootInventoryDisplay } from '@/components/game/LootInventory';
export function LootTab() {
const lootInventory = useGameStore((s) => s.lootInventory);
const elements = useGameStore((s) => s.elements);
const lootInventory = useCraftingStore((s) => s.lootInventory);
const elements = useManaStore((s) => s.elements);
const equipmentInstances = useCraftingStore((s) => s.equipmentInstances);
const deleteMaterial = useGameStore((s) => s.deleteMaterial);
const deleteEquipmentInstance = useGameStore((s) => s.deleteEquipmentInstance);
const deleteMaterial = useCraftingStore((s) => s.deleteMaterial);
const deleteEquipmentInstance = useCraftingStore((s) => s.deleteEquipmentInstance);
return (
<div className="space-y-4">
+14 -5
View File
@@ -3,7 +3,7 @@
'use client';
import { useState } from 'react';
import { useGameStore, usePrestigeStore, useSkillStore, useManaStore } from '@/lib/game/stores';
import { usePrestigeStore, useSkillStore, useManaStore, useCraftingStore } from '@/lib/game/stores';
import { useGameLoop } from '@/lib/game/stores/gameHooks';
import { getUnifiedEffects } from '@/lib/game/effects';
import {
@@ -21,19 +21,28 @@ import { fmt } from '@/lib/game/stores';
export function PrestigeTab() {
const [selectedManaType, setSelectedManaType] = useState<string>('');
const store = useGameStore();
useGameLoop();
const skills = useSkillStore((s) => s.skills);
const prestigeUpgrades = usePrestigeStore((s) => s.prestigeUpgrades);
const rawMana = useManaStore((s) => s.rawMana);
const elements = useManaStore((s) => s.elements);
const skillUpgrades = useSkillStore((s) => s.skillUpgrades);
const skillTiers = useSkillStore((s) => s.skillTiers);
const equipmentInstances = useCraftingStore((s) => s.equipmentInstances);
const equippedInstances = useCraftingStore((s) => s.equippedInstances);
const doPrestige = usePrestigeStore((s) => s.doPrestige);
const upgradeEffects = getUnifiedEffects(store);
const upgradeEffects = getUnifiedEffects({
skillUpgrades,
skillTiers,
equipmentInstances,
equippedInstances,
});
// Get unlocked elements for mana type selector
const unlockedElements = Object.entries(ELEMENTS)
.filter(([id]) => store.elements[id]?.unlocked)
.filter(([id]) => elements[id]?.unlocked)
.map(([id, elem]) => ({
id,
name: elem.name,
@@ -66,7 +75,7 @@ export function PrestigeTab() {
<Button
size="sm"
disabled={!canAfford || level >= def.maxLevel}
onClick={() => store.doPrestige(id)}
onClick={() => doPrestige(id)}
>
{level >= def.maxLevel ? 'Maxed' : `Upgrade (${fmt(def.cost)})`}
</Button>
+2 -2
View File
@@ -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 (
+25
View File
@@ -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<CombatState>()(
@@ -244,6 +250,25 @@ export const useCombatStore = create<CombatState>()(
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',
+55
View File
@@ -37,6 +37,11 @@ export interface CraftingState {
equipmentInstances: Record<string, EquipmentInstance>;
// Equipped instances (slot -> instanceId or null)
equippedInstances: Record<string, string | null>;
// Loot inventory
lootInventory: {
materials: Record<string, number>;
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<CraftingStore>()(
unlockedEffects: [],
equipmentInstances: {},
equippedInstances: {},
lootInventory: {
materials: {},
blueprints: [],
},
// Actions
setDesignProgress: (progress) => set({ designProgress: progress }),
@@ -221,6 +234,47 @@ export const useCraftingStore = create<CraftingStore>()(
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<CraftingStore>()(
unlockedEffects: state.unlockedEffects,
equipmentInstances: state.equipmentInstances,
equippedInstances: state.equippedInstances,
lootInventory: state.lootInventory,
}),
}
)
+25
View File
@@ -26,6 +26,12 @@ export interface PrestigeState {
// Guardian pacts
defeatedGuardians: number[];
signedPacts: number[];
signedPactDetails: Record<number, {
floor: number;
guardianId: string;
signedAt: { day: number; hour: number };
skillLevels: Record<string, number>;
}>;
pactRitualFloor: number | null;
pactRitualProgress: number;
@@ -73,6 +79,12 @@ const initialState = {
memories: [] as Memory[],
defeatedGuardians: [] as number[],
signedPacts: [] as number[],
signedPactDetails: {} as Record<number, {
floor: number;
guardianId: string;
signedAt: { day: number; hour: number };
skillLevels: Record<string, number>;
}>,
pactRitualFloor: null as number | null,
pactRitualProgress: 0,
};
@@ -249,6 +261,19 @@ export const usePrestigeStore = create<PrestigeState>()(
resetPrestige: () => {
set(initialState);
},
// Debug helpers
debugSetSignedPacts: (pacts: number[]) => {
set({ signedPacts: pacts });
},
debugSetPactDetails: (details: Record<number, {
floor: number;
guardianId: string;
signedAt: { day: number; hour: number };
skillLevels: Record<string, number>;
}>) => {
set({ signedPactDetails: details });
},
}),
{
name: 'mana-loop-prestige',