fix: fabricator recipes now use correct elemental mana type
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m37s

- fabricator-recipes.ts: add optional manaType param to canCraftRecipe for clarity
- FabricatorSubTab.tsx: read elemental mana from store based on recipe manaType instead of always using rawMana
- craftingStore.ts: add startFabricatorCrafting action that deducts correct mana type
- craftingStore.types.ts: add startFabricatorCrafting to CraftingActions interface
- crafting-fabricator.ts: new helper file to keep craftingStore.ts under 400 lines

Fixes #155
This commit is contained in:
2026-05-27 11:06:24 +02:00
parent 707a1eef31
commit 64b472572b
8 changed files with 198 additions and 27 deletions
+32 -16
View File
@@ -16,6 +16,12 @@ import { equipItem as equipItemAction, unequipItem as unequipItemAction } from '
import { ErrorCode } from '../utils/result';
import { createSafeStorage } from '../utils/safe-persist';
import { createInitialEquipmentInstances } from './crafting-initial-state';
import {
getFabricatorRecipe,
deductFabricatorMana,
deductMaterials,
makeFabricatorProgress,
} from '../crafting-fabricator';
export const useCraftingStore = create<CraftingStore>()(
persist(
@@ -235,29 +241,39 @@ export const useCraftingStore = create<CraftingStore>()(
},
cancelEquipmentCrafting: () => {
const state = get();
const progress = state.equipmentCraftingProgress;
const progress = get().equipmentCraftingProgress;
if (!progress) return;
// Get cancel result (mana refund)
const cancelResult = CraftingEquipment.cancelEquipmentCrafting(
progress.blueprintId,
progress.manaSpent
);
// Update crafting store state
const cancelResult = CraftingEquipment.cancelEquipmentCrafting(progress.blueprintId, progress.manaSpent);
set({ equipmentCraftingProgress: null });
// Refund mana to mana store
useManaStore.setState((s) => ({ rawMana: s.rawMana + cancelResult.manaRefund }));
// Update combat store (reset action)
useCombatStore.setState({ currentAction: 'meditate' });
// Add log message to UI store
useUIStore.getState().addLog(cancelResult.logMessage);
},
// Fabricator crafting — uses elemental mana instead of raw mana
startFabricatorCrafting: (recipeId: string) => {
const state = get();
const currentAction = useCombatStore.getState().currentAction;
if (currentAction !== 'meditate') return false;
const recipe = getFabricatorRecipe(recipeId);
if (!recipe) return false;
const rawMana = useManaStore.getState().rawMana;
const elements = useManaStore.getState().elements;
const deducted = deductFabricatorMana(recipe, rawMana, elements);
if (!deducted) return false;
const newMaterials = deductMaterials(recipe, state.lootInventory.materials);
const progress = makeFabricatorProgress(recipeId, recipe.equipmentTypeId, recipe.craftTime, recipe.manaCost);
useManaStore.setState({ rawMana: deducted.rawMana, elements: deducted.elements });
set((s) => ({ lootInventory: { ...s.lootInventory, materials: newMaterials }, equipmentCraftingProgress: progress }));
useCombatStore.setState({ currentAction: 'craft' });
return true;
},
// Enchantment selection actions
setSelectedEquipmentType: (type) => {
set((s) => ({ enchantmentSelection: { ...s.enchantmentSelection, selectedEquipmentType: type }}));
@@ -61,6 +61,7 @@ export interface CraftingActions {
equipItem: (instanceId: string, slot: EquipmentSlot) => boolean;
unequipItem: (slot: EquipmentSlot) => void;
startCraftingEquipment: (blueprintId: string) => boolean;
startFabricatorCrafting: (recipeId: string) => boolean;
cancelEquipmentCrafting: () => void;
setSelectedEquipmentType: (type: string | null) => void;
setSelectedEffects: (effects: DesignEffect[]) => void;