[Medium] [Bug] Item Fabrication: Material cancellation refund uses wrong formula #317

Closed
opened 2026-06-07 17:43:57 +02:00 by Anexim · 3 comments
Owner

Spec: docs/specs/attunements/fabricator/systems/item-fabrication-spec.md §6.3
Severity: Wrong formula

Problem: The spec says material refund should be a flat 50% regardless of progress. The code in src/lib/game/stores/pipelines/equipment-crafting.ts:89-94,107-113 uses remainingFraction for materials:

const refundAmount = Math.floor(amount * remainingFraction);

This means:

  • Cancel at start (progress ≈ 0): ~100% refund (spec says 50%)
  • Cancel at 50%: ~50% refund (coincidentally matches)
  • Cancel near end: ~0% refund (spec says 50%)

File: src/lib/game/stores/pipelines/equipment-crafting.ts:89-94,107-113

**Spec:** docs/specs/attunements/fabricator/systems/item-fabrication-spec.md §6.3 **Severity:** Wrong formula **Problem:** The spec says material refund should be a flat 50% regardless of progress. The code in `src/lib/game/stores/pipelines/equipment-crafting.ts:89-94,107-113` uses `remainingFraction` for materials: ``` const refundAmount = Math.floor(amount * remainingFraction); ``` This means: - Cancel at start (progress ≈ 0): ~100% refund (spec says 50%) - Cancel at 50%: ~50% refund (coincidentally matches) - Cancel near end: ~0% refund (spec says 50%) **File:** `src/lib/game/stores/pipelines/equipment-crafting.ts:89-94,107-113`
Anexim added the ai:todo label 2026-06-07 17:43:57 +02:00
n8n-gitea was assigned by Anexim 2026-06-07 17:43:57 +02:00
Anexim added ai:in-progress and removed ai:todo labels 2026-06-08 13:11:04 +02:00
Author
Owner

Starting investigation. Reading spec §6.3 and the buggy file equipment-crafting.ts.

Starting investigation. Reading spec §6.3 and the buggy file equipment-crafting.ts.
Author
Owner

Root cause confirmed.

Spec §6.3 states:

  • Mana refund: refundRate = remainingFraction + (1 - remainingFraction) × 0.5 (blended rate)
  • Material refund: floor(materialsSpent × 0.5) (flat 50%)

Both the fabricator branch (line 89-94) and standard equipment branch (line 107-113) incorrectly use remainingFraction for material refunds instead of flat 0.5.

Fixing both branches to use 0.5 for material refunds.

**Root cause confirmed.** Spec §6.3 states: - Mana refund: `refundRate = remainingFraction + (1 - remainingFraction) × 0.5` (blended rate) - Material refund: `floor(materialsSpent × 0.5)` (flat 50%) Both the fabricator branch (line 89-94) and standard equipment branch (line 107-113) incorrectly use `remainingFraction` for material refunds instead of flat `0.5`. Fixing both branches to use `0.5` for material refunds.
Anexim added ai:done and removed ai:in-progress labels 2026-06-08 13:14:35 +02:00
Author
Owner

Fixed. Changed material refund in both branches of cancelEquipmentCrafting() in equipment-crafting.ts:

  • Fabricator branch (line ~89): Math.floor(reducedAmount * remainingFraction)Math.floor(reducedAmount * 0.5)
  • Standard equipment branch (line ~107): Math.floor(amount * remainingFraction)Math.floor(amount * 0.5)

Also cleaned up the now-unnecessary remainingFraction variable and its associated lines in the standard equipment branch. The mana refund formula (refundRate = remainingFraction + (1 - remainingFraction) * 0.5) was already correct and left unchanged.

All 1060 tests pass. Pre-commit hooks pass.

**Fixed.** Changed material refund in both branches of `cancelEquipmentCrafting()` in `equipment-crafting.ts`: - **Fabricator branch** (line ~89): `Math.floor(reducedAmount * remainingFraction)` → `Math.floor(reducedAmount * 0.5)` - **Standard equipment branch** (line ~107): `Math.floor(amount * remainingFraction)` → `Math.floor(amount * 0.5)` Also cleaned up the now-unnecessary `remainingFraction` variable and its associated lines in the standard equipment branch. The mana refund formula (`refundRate = remainingFraction + (1 - remainingFraction) * 0.5`) was already correct and left unchanged. All 1060 tests pass. Pre-commit hooks pass.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#317