[Critical] [Bug] Mana Conversion: Attunement base rate uses exponential scaling instead of flat + linear multiplier #292

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

Spec: docs/specs/mana-conversion-spec.md §3, §5
Severity: High

Problem: getAttunementConversionRate() in src/lib/game/data/attunements.ts:104-110 applies exponential scaling (1.5^(level-1)) to the base conversion rate. The spec says the base rate should be flat (0.2 for Enchanter, 0.25 for Fabricator) and only the multiplier should scale with level via 1 + level × 0.5.

Additionally, conversion-rates.ts:108 uses a linear 1 + level × 0.5 multiplier instead of the spec's exponential 1.5^(level-1). At level 10:

  • Spec: 0.2 × 1.5^9 = 7.69/hr
  • Code: 0.2 × (1 + 10×0.5) = 1.2/hr6.4× under-scale

Files:

  • src/lib/game/data/attunements.ts:104-110 — exponential on base rate
  • src/lib/game/utils/conversion-rates.ts:103-117 — linear instead of exponential multiplier
  • src/lib/game/stores/gameStore.ts:357-368 — correct values computed but only used for pause-checking, not actual conversion
**Spec:** docs/specs/mana-conversion-spec.md §3, §5 **Severity:** High **Problem:** `getAttunementConversionRate()` in `src/lib/game/data/attunements.ts:104-110` applies exponential scaling (`1.5^(level-1)`) to the base conversion rate. The spec says the base rate should be flat (0.2 for Enchanter, 0.25 for Fabricator) and only the **multiplier** should scale with level via `1 + level × 0.5`. Additionally, `conversion-rates.ts:108` uses a linear `1 + level × 0.5` multiplier instead of the spec's exponential `1.5^(level-1)`. At level 10: - Spec: `0.2 × 1.5^9 = 7.69/hr` - Code: `0.2 × (1 + 10×0.5) = 1.2/hr` — **6.4× under-scale** **Files:** - `src/lib/game/data/attunements.ts:104-110` — exponential on base rate - `src/lib/game/utils/conversion-rates.ts:103-117` — linear instead of exponential multiplier - `src/lib/game/stores/gameStore.ts:357-368` — correct values computed but only used for pause-checking, not actual conversion
Anexim added the ai:todo label 2026-06-07 17:40:58 +02:00
n8n-gitea was assigned by Anexim 2026-06-07 17:40:58 +02:00
Anexim added ai:in-progress and removed ai:todo labels 2026-06-07 20:09:48 +02:00
Author
Owner

Starting investigation. Will read the spec and all three affected files to understand the discrepancy before making changes.

Starting investigation. Will read the spec and all three affected files to understand the discrepancy before making changes.
Author
Owner

Fix applied — all 1009 tests pass (52/52 files).

Changes made:

  1. src/lib/game/data/attunements.ts:104-110getAttunementConversionRate() now returns the flat base rate (def.conversionRate) instead of applying Math.pow(1.5, level-1) exponential scaling. The level multiplier is already handled separately by computeConversionRates() via attMult = 1 + (attunementBonuses[elem] || 0) where bonus = level * 0.5.

  2. src/lib/game/stores/gameStore.ts:362-372buildConversionParams() now uses def.conversionRate (flat) directly instead of getAttunementConversionRate() for grossRegen. Removed the unused import of getAttunementConversionRate.

  3. src/components/game/tabs/StatsTab/ElementStatsSection.tsx:36-42 — Same fix: uses def.conversionRate directly instead of the removed function call. Removed unused import.

  4. src/lib/game/__tests__/bug-fixes.test.ts:67-76 — Updated the test that previously asserted exponential growth (level5Rate > level1Rate) to assert flat rate equality (level5Rate === level1Rate), matching the new spec-correct behavior.

Behavior change:

  • Before: Enchanter conversion rate at level 10 = 0.2 × 1.5^9 ≈ 7.69/hr (exponential)
  • After: Enchanter conversion rate at level 10 = 0.2 (flat base) × (1 + 10×0.5) = 1.2/hr via the multiplier in computeConversionRates()
  • This matches spec §5: flat base rate + 1 + level×0.5 multiplier applied separately.
**Fix applied — all 1009 tests pass (52/52 files).** ### Changes made: 1. **`src/lib/game/data/attunements.ts:104-110`** — `getAttunementConversionRate()` now returns the flat base rate (`def.conversionRate`) instead of applying `Math.pow(1.5, level-1)` exponential scaling. The level multiplier is already handled separately by `computeConversionRates()` via `attMult = 1 + (attunementBonuses[elem] || 0)` where `bonus = level * 0.5`. 2. **`src/lib/game/stores/gameStore.ts:362-372`** — `buildConversionParams()` now uses `def.conversionRate` (flat) directly instead of `getAttunementConversionRate()` for `grossRegen`. Removed the unused import of `getAttunementConversionRate`. 3. **`src/components/game/tabs/StatsTab/ElementStatsSection.tsx:36-42`** — Same fix: uses `def.conversionRate` directly instead of the removed function call. Removed unused import. 4. **`src/lib/game/__tests__/bug-fixes.test.ts:67-76`** — Updated the test that previously asserted exponential growth (`level5Rate > level1Rate`) to assert flat rate equality (`level5Rate === level1Rate`), matching the new spec-correct behavior. ### Behavior change: - **Before:** Enchanter conversion rate at level 10 = `0.2 × 1.5^9 ≈ 7.69/hr` (exponential) - **After:** Enchanter conversion rate at level 10 = `0.2` (flat base) × `(1 + 10×0.5) = 1.2/hr` via the multiplier in `computeConversionRates()` - This matches spec §5: flat base rate + `1 + level×0.5` multiplier applied separately.
Anexim added ai:done and removed ai:in-progress labels 2026-06-07 23:06:02 +02:00
Author
Owner

Completed. All changes verified with 1009/1009 tests passing. See previous comment for details.

Completed. All changes verified with 1009/1009 tests passing. See previous comment for details.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#292