feat: add material crafting recipes to Fabricator
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 4m25s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 4m25s
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
import type { EquipmentCraftingProgress } from './types';
|
||||
import type { FabricatorRecipe } from './data/fabricator-recipes';
|
||||
import { FABRICATOR_RECIPES } from './data/fabricator-recipes';
|
||||
import { useManaStore } from './stores/manaStore';
|
||||
import { useCombatStore } from './stores/combatStore';
|
||||
import { useUIStore } from './stores/uiStore';
|
||||
|
||||
// ─── Lookup ───────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -139,3 +142,37 @@ export function makeFabricatorProgress(
|
||||
manaSpent: manaCost,
|
||||
};
|
||||
}
|
||||
|
||||
// ─── Material Crafting ──────────────────────────────────────────────────────
|
||||
|
||||
export interface CraftMaterialResult {
|
||||
success: boolean;
|
||||
newMaterials: Record<string, number>;
|
||||
newRawMana: number;
|
||||
newElements: Record<string, { current: number; max: number; unlocked: boolean }>;
|
||||
logMessage: string;
|
||||
}
|
||||
|
||||
export function executeMaterialCraft(
|
||||
recipe: FabricatorRecipe,
|
||||
materials: Record<string, number>,
|
||||
): CraftMaterialResult | null {
|
||||
if (recipe.recipeType !== 'material' || !recipe.resultMaterial || !recipe.resultAmount) return null;
|
||||
|
||||
const rawMana = useManaStore.getState().rawMana;
|
||||
const elements = useManaStore.getState().elements;
|
||||
|
||||
const deducted = deductFabricatorMana(recipe, rawMana, elements);
|
||||
if (!deducted) return null;
|
||||
|
||||
const newMaterials = deductMaterials(recipe, materials);
|
||||
newMaterials[recipe.resultMaterial] = (newMaterials[recipe.resultMaterial] || 0) + recipe.resultAmount;
|
||||
|
||||
return {
|
||||
success: true,
|
||||
newMaterials,
|
||||
newRawMana: deducted.rawMana,
|
||||
newElements: deducted.elements,
|
||||
logMessage: `✨ Crafted ${recipe.resultAmount}x ${recipe.name}!`,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user