fix: material cancellation refund uses flat 50% per spec §6.3
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m20s

This commit is contained in:
2026-06-08 13:13:57 +02:00
parent 5b124ea845
commit 0894ee8c55
3 changed files with 6 additions and 9 deletions
@@ -74,13 +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 — use reduced amounts (what player actually paid)
// Refund materials — flat 50% per spec §6.3
const reduction = getCraftingCostReduction();
const currentMaterials = get().lootInventory.materials;
const refundedMaterials = { ...currentMaterials };
for (const [matId, rawAmount] of Object.entries(recipe.materials)) {
const reducedAmount = applyCostReduction(rawAmount, reduction);
const refundAmount = Math.floor(reducedAmount * remainingFraction);
const refundAmount = Math.floor(reducedAmount * 0.5);
if (refundAmount > 0) {
refundedMaterials[matId] = (refundedMaterials[matId] || 0) + refundAmount;
}
@@ -98,16 +98,13 @@ export function cancelEquipmentCrafting(get: GetFn, set: SetFn): void {
progress.progress,
progress.required,
);
// Refund materials proportionally to remaining progress
// Refund materials — flat 50% per spec §6.3
const recipe = CraftingEquipment.getRecipe(progress.blueprintId);
if (recipe) {
const remainingFraction = progress.required > 0
? Math.max(0, (progress.required - progress.progress) / progress.required)
: 1;
const currentMaterials = get().lootInventory.materials;
const refundedMaterials = { ...currentMaterials };
for (const [matId, amount] of Object.entries(recipe.materials)) {
const refundAmount = Math.floor(amount * remainingFraction);
const refundAmount = Math.floor(amount * 0.5);
if (refundAmount > 0) {
refundedMaterials[matId] = (refundedMaterials[matId] || 0) + refundAmount;
}