[High] [Bug] Crystal conversion sand cost halved due to duplicate key in recipe #359

Closed
opened 2026-06-10 19:26:25 +02:00 by Anexim · 2 comments
Owner

Severity: High
File: src/lib/game/data/conversion-costs.ts (line 107)

Description:
The crystal conversion recipe is defined as:

crystal: exoticElementCost('crystal', ['sand', 'sand', 'light'])

When Object.fromEntries(components.map(c => [c, computeComponentCost(3)])) is called, the duplicate sand key means the second entry overwrites the first. The resulting component cost for sand is 40 instead of the intended 80.

Impact: Exploit — crystal conversion costs only 40 sand per unit instead of the intended 80, making crystal mana cheaper to produce than designed. This breaks the game's mana economy balance.

Fix needed: Change the recipe to ['sand', 'light'] with a higher per-unit cost, or change the cost computation to properly handle duplicate components by summing them.

**Severity:** High **File:** `src/lib/game/data/conversion-costs.ts` (line 107) **Description:** The crystal conversion recipe is defined as: ``` crystal: exoticElementCost('crystal', ['sand', 'sand', 'light']) ``` When `Object.fromEntries(components.map(c => [c, computeComponentCost(3)]))` is called, the duplicate `sand` key means the second entry overwrites the first. The resulting component cost for sand is `40` instead of the intended `80`. **Impact:** Exploit — crystal conversion costs only 40 sand per unit instead of the intended 80, making crystal mana cheaper to produce than designed. This breaks the game's mana economy balance. **Fix needed:** Change the recipe to `['sand', 'light']` with a higher per-unit cost, or change the cost computation to properly handle duplicate components by summing them.
Anexim added the ai:todo label 2026-06-10 19:26:25 +02:00
n8n-gitea was assigned by Anexim 2026-06-10 19:26:25 +02:00
Anexim added ai:in-progress and removed ai:todo labels 2026-06-10 21:51:40 +02:00
Author
Owner

Starting work on fixing the Crystal conversion duplicate key bug. Investigating conversion-costs.ts for the duplicate key issue.

Starting work on fixing the Crystal conversion duplicate key bug. Investigating conversion-costs.ts for the duplicate key issue.
Anexim added ai:done and removed ai:in-progress labels 2026-06-10 22:56:17 +02:00
Author
Owner

Fixed. Changed compositeElementCost, exoticElementCost, and timeElementCost to use a manual loop that sums costs for duplicate component keys instead of Object.fromEntries which silently overwrites duplicates. Crystal now correctly costs 80 sand (40×2) + 40 light. All 1157 tests pass.

Fixed. Changed compositeElementCost, exoticElementCost, and timeElementCost to use a manual loop that sums costs for duplicate component keys instead of Object.fromEntries which silently overwrites duplicates. Crystal now correctly costs 80 sand (40×2) + 40 light. All 1157 tests pass.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#359