fix: apply Crafting Efficiency cost reduction to all fabrication paths
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m18s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m18s
- Add getCraftingCostReduction() and applyCostReduction() helpers in crafting-fabricator.ts - Apply cost reduction in deductMaterials() and checkFabricatorCosts() - Apply cost reduction in startFabricatorCrafting() and cancelEquipmentCrafting() pipeline - Update canCraftRecipe() in fabricator-recipes.ts to accept costReduction param - Update FabricatorSubTab and MaterialRecipeCard UIs to display discounted costs - Spec formula: actualCost = ceil(baseCost × (1 - craftingCostReduction / 100)) Fixes #316
This commit is contained in:
@@ -10,6 +10,8 @@ import {
|
||||
deductMaterials,
|
||||
makeFabricatorProgress,
|
||||
refundFabricatorMana,
|
||||
getCraftingCostReduction,
|
||||
applyCostReduction,
|
||||
} from '../../crafting-fabricator';
|
||||
import { useManaStore } from '../manaStore';
|
||||
import { useCombatStore } from '../combatStore';
|
||||
@@ -72,11 +74,13 @@ export function cancelEquipmentCrafting(get: GetFn, set: SetFn): void {
|
||||
const refunded = refundFabricatorMana(recipe, manaRefund, rawMana, elements);
|
||||
useManaStore.setState({ rawMana: refunded.rawMana, elements: refunded.elements });
|
||||
|
||||
// Refund materials
|
||||
// Refund materials — use reduced amounts (what player actually paid)
|
||||
const reduction = getCraftingCostReduction();
|
||||
const currentMaterials = get().lootInventory.materials;
|
||||
const refundedMaterials = { ...currentMaterials };
|
||||
for (const [matId, amount] of Object.entries(recipe.materials)) {
|
||||
const refundAmount = Math.floor(amount * remainingFraction);
|
||||
for (const [matId, rawAmount] of Object.entries(recipe.materials)) {
|
||||
const reducedAmount = applyCostReduction(rawAmount, reduction);
|
||||
const refundAmount = Math.floor(reducedAmount * remainingFraction);
|
||||
if (refundAmount > 0) {
|
||||
refundedMaterials[matId] = (refundedMaterials[matId] || 0) + refundAmount;
|
||||
}
|
||||
@@ -132,6 +136,7 @@ export function startFabricatorCrafting(recipeId: string, get: GetFn, set: SetFn
|
||||
const deducted = deductFabricatorMana(recipe, rawMana, elements);
|
||||
if (!deducted) return false;
|
||||
|
||||
// deductMaterials already applies cost reduction internally via getCraftingCostReduction()
|
||||
const newMaterials = deductMaterials(recipe, state.lootInventory.materials);
|
||||
const progress = makeFabricatorProgress(recipeId, recipe.equipmentTypeId, recipe.craftTime, recipe.manaCost);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user