[High] [Bug] Attunement system: conversion rate uses linear 1+level×0.5 instead of exponential 1.5^(level-1) #331

Closed
opened 2026-06-08 16:02:46 +02:00 by Anexim · 2 comments
Owner

Spec: docs/specs/attunements/attunement-system-spec.md

Discrepancies found:

Conversion rate level scaling — wrong formula [HIGH]

  • Spec §4.3: scaledValue = baseValue × 1.5^(level-1) (exponential)
  • Code (conversion-rates.ts:107-115): Uses 1 + (level × 0.5) (linear)
  • Impact: At level 10, spec expects ~19.2× multiplier but code gives 6× — a 3× difference that fundamentally changes game balance
  • Fix: Change conversion rate level scaling to use Math.pow(1.5, level - 1) to match spec

getAttunementLevelMultiplier() — dead code with wrong formula [LOW]

  • File: src/lib/game/attunements.ts:113-114
  • Function exists but is never called anywhere in the codebase
  • Also uses wrong formula (1 + level × 0.5 instead of 1.5^(level-1))
  • Fix: Either remove dead code or fix formula and wire it to conversion rate calculation

Level-up logging missing [LOW]

  • Spec §4.2: addAttunementXP should log "Attunement leveled up!" on each level-up
  • Code (attunementStore.ts:43-55): Level-up loop increments level but never logs anything
  • Fix: Add log message on level-up

Puzzle room progression — time-based vs %/tick-based [MEDIUM]

  • Spec §8: "1.5–2% per tick base, with attunement bonus of 2.5–3% per relevant attunement level"
  • Code: Implements time-based progression (puzzleRequired in hours, progress accumulated as hours per tick). Attunements reduce the total hours needed rather than increasing progress speed.
  • Fix: Reconcile — either update spec to describe time-based system, or implement %/tick system in code

getAttunementConversionRate() — no level scaling, unused in production [MEDIUM]

  • File: src/lib/game/attunements.ts:105-110
  • Returns base conversion rate with no level scaling applied
  • Only used in tests, not in actual tick pipeline
  • Fix: Apply level scaling in this function or remove it
**Spec:** `docs/specs/attunements/attunement-system-spec.md` **Discrepancies found:** ### Conversion rate level scaling — wrong formula [HIGH] - **Spec §4.3:** `scaledValue = baseValue × 1.5^(level-1)` (exponential) - **Code (`conversion-rates.ts:107-115`):** Uses `1 + (level × 0.5)` (linear) - **Impact:** At level 10, spec expects ~19.2× multiplier but code gives 6× — a 3× difference that fundamentally changes game balance - **Fix:** Change conversion rate level scaling to use `Math.pow(1.5, level - 1)` to match spec ### `getAttunementLevelMultiplier()` — dead code with wrong formula [LOW] - **File:** `src/lib/game/attunements.ts:113-114` - Function exists but is **never called** anywhere in the codebase - Also uses wrong formula (`1 + level × 0.5` instead of `1.5^(level-1)`) - **Fix:** Either remove dead code or fix formula and wire it to conversion rate calculation ### Level-up logging missing [LOW] - **Spec §4.2:** `addAttunementXP` should log "Attunement leveled up!" on each level-up - **Code (`attunementStore.ts:43-55`):** Level-up loop increments level but **never logs anything** - **Fix:** Add log message on level-up ### Puzzle room progression — time-based vs %/tick-based [MEDIUM] - **Spec §8:** "1.5–2% per tick base, with attunement bonus of 2.5–3% per relevant attunement level" - **Code:** Implements time-based progression (`puzzleRequired` in hours, progress accumulated as `hours` per tick). Attunements reduce the total hours needed rather than increasing progress speed. - **Fix:** Reconcile — either update spec to describe time-based system, or implement %/tick system in code ### `getAttunementConversionRate()` — no level scaling, unused in production [MEDIUM] - **File:** `src/lib/game/attunements.ts:105-110` - Returns base conversion rate with **no level scaling applied** - Only used in tests, not in actual tick pipeline - **Fix:** Apply level scaling in this function or remove it
Anexim added the ai:todo label 2026-06-08 16:02:46 +02:00
n8n-gitea was assigned by Anexim 2026-06-08 16:02:46 +02:00
Anexim added ai:in-progress and removed ai:todo labels 2026-06-08 22:00:33 +02:00
Author
Owner

Starting investigation of issue #331. Will read the spec and relevant code files to understand all 5 discrepancies before implementing fixes.

Starting investigation of issue #331. Will read the spec and relevant code files to understand all 5 discrepancies before implementing fixes.
Anexim added ai:done and removed ai:in-progress labels 2026-06-08 22:09:26 +02:00
Author
Owner

Fix complete. All 5 discrepancies from the spec audit have been resolved:

  1. [HIGH] Conversion rate level scaling — Changed from linear (1 + level × 0.5) to exponential (1.5^(level-1)) in conversion-rates.ts. At level 10, this changes the multiplier from 6× to ~19.2×, matching spec §4.3.

  2. [LOW] getAttunementLevelMultiplier formula — Fixed from 1 + level × 0.5 to Math.pow(1.5, level - 1) in data/attunements.ts. Function was dead code (never called) but now has the correct formula for future use.

  3. [LOW] Level-up logging — Added addActivityLog('attunement', ...) call in attunementStore.ts when addAttunementXP triggers a level-up, matching spec §4.2.

  4. [MEDIUM] Puzzle room progression — Updated spec §8 to describe the time-based system that the code actually implements (base hours by floor range, attunement level reduces total time needed, up to 90% max reduction).

  5. [MEDIUM] getAttunementConversionRate — Clarified JSDoc: function intentionally returns flat base rate (no level scaling). Level scaling is applied separately in computeConversionRates() via attunementMult.

All 1086 tests pass (59 test files), including 17 new regression tests in attunement-conversion-fix.test.ts.

Fix complete. All 5 discrepancies from the spec audit have been resolved: 1. **[HIGH] Conversion rate level scaling** — Changed from linear (`1 + level × 0.5`) to exponential (`1.5^(level-1)`) in `conversion-rates.ts`. At level 10, this changes the multiplier from 6× to ~19.2×, matching spec §4.3. 2. **[LOW] `getAttunementLevelMultiplier` formula** — Fixed from `1 + level × 0.5` to `Math.pow(1.5, level - 1)` in `data/attunements.ts`. Function was dead code (never called) but now has the correct formula for future use. 3. **[LOW] Level-up logging** — Added `addActivityLog('attunement', ...)` call in `attunementStore.ts` when `addAttunementXP` triggers a level-up, matching spec §4.2. 4. **[MEDIUM] Puzzle room progression** — Updated spec §8 to describe the time-based system that the code actually implements (base hours by floor range, attunement level reduces total time needed, up to 90% max reduction). 5. **[MEDIUM] `getAttunementConversionRate`** — Clarified JSDoc: function intentionally returns flat base rate (no level scaling). Level scaling is applied separately in `computeConversionRates()` via `attunementMult`. All 1086 tests pass (59 test files), including 17 new regression tests in `attunement-conversion-fix.test.ts`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#331