[Critical] [Bug] All 22 mana types auto-unlocked on first tick via conversion system #377

Closed
opened 2026-06-12 12:05:43 +02:00 by Anexim · 1 comment
Owner

Bug Summary

All 22 mana types (including exotic elements like Crystal, Stellar, Void, Soul, Time, Plasma) are unlocked from the very first tick, bypassing the intended guardian pact unlock progression.

Expected Behavior

Only Transference should be unlocked at game start (BASE_UNLOCKED_ELEMENTS = ['transference']). All other mana types should be unlocked through:

  • Guardian pacts (defeating guardians on floors 10-240)
  • Manual unlock via raw mana cost

Root Cause

Two lines in src/lib/game/stores/gameStore.ts unconditionally auto-unlock any element that has a non-zero net conversion rate:

  • Line 211: if (!elements[elem].unlocked) elements[elem] = { ...elements[elem], unlocked: true };
  • Line 324: Same pattern in the recovery room boosting code

These lines reside inside loops iterating over conversionResult.rates (all 22 elements). On the first tick, the Enchanter attunement (active at level 1) provides conversion rate bonuses for transference-containing elements (soul, plasma, time), causing them to get non-zero rates and be auto-unlocked. This creates a cascade that unlocks all 22 elements within the first few ticks.

Severity

Critical — Completely breaks the core progression loop. The guardian pact system (the intended unlock mechanism) is bypassed entirely.

Fix Direction

Remove the auto-unlock lines at gameStore.ts:211 and :324. The conversion system should only apply mana deltas to elements that are already unlocked. If elements[elem].unlocked is false, skip that element.

Files Involved

File Lines Role
src/lib/game/stores/gameStore.ts 211, 324 BUG — auto-unlock in conversion loop
src/lib/game/constants/elements.ts 115 Correctly defines BASE_UNLOCKED_ELEMENTS = ['transference']
src/lib/game/stores/manaStore.ts 207-217 Correctly initializes elements using BASE_UNLOCKED_ELEMENTS
## Bug Summary All 22 mana types (including exotic elements like Crystal, Stellar, Void, Soul, Time, Plasma) are unlocked from the very first tick, bypassing the intended guardian pact unlock progression. ## Expected Behavior Only Transference should be unlocked at game start (`BASE_UNLOCKED_ELEMENTS = ['transference']`). All other mana types should be unlocked through: - Guardian pacts (defeating guardians on floors 10-240) - Manual unlock via raw mana cost ## Root Cause Two lines in `src/lib/game/stores/gameStore.ts` unconditionally auto-unlock any element that has a non-zero net conversion rate: - **Line 211**: `if (!elements[elem].unlocked) elements[elem] = { ...elements[elem], unlocked: true };` - **Line 324**: Same pattern in the recovery room boosting code These lines reside inside loops iterating over `conversionResult.rates` (all 22 elements). On the first tick, the Enchanter attunement (active at level 1) provides conversion rate bonuses for transference-containing elements (soul, plasma, time), causing them to get non-zero rates and be auto-unlocked. This creates a cascade that unlocks all 22 elements within the first few ticks. ## Severity **Critical** — Completely breaks the core progression loop. The guardian pact system (the intended unlock mechanism) is bypassed entirely. ## Fix Direction Remove the auto-unlock lines at gameStore.ts:211 and :324. The conversion system should only apply mana deltas to elements that are already unlocked. If `elements[elem].unlocked` is false, skip that element. ## Files Involved | File | Lines | Role | |------|-------|------| | `src/lib/game/stores/gameStore.ts` | 211, 324 | **BUG** — auto-unlock in conversion loop | | `src/lib/game/constants/elements.ts` | 115 | Correctly defines `BASE_UNLOCKED_ELEMENTS = ['transference']` | | `src/lib/game/stores/manaStore.ts` | 207-217 | Correctly initializes elements using `BASE_UNLOCKED_ELEMENTS` |
Anexim added the ai:todo label 2026-06-12 12:05:43 +02:00
n8n-gitea was assigned by Anexim 2026-06-12 12:05:43 +02:00
Anexim added ai:in-progress and removed ai:todo labels 2026-06-12 12:12:05 +02:00
Anexim added ai:done and removed ai:in-progress labels 2026-06-12 12:15:20 +02:00
Author
Owner

Fix Applied

Root cause: Two lines in gameStore.ts unconditionally auto-unlocked any element with a non-zero conversion rate:

  • Line 211: In the element regen loop (// Apply net element regen to pools)
  • Line 324: In the recovery room boost loop

On the first tick, the Enchanter attunement (active at level 1) provides conversion rate bonuses for transference-containing elements (soul, plasma, time), causing them to get non-zero rates and be auto-unlocked. This cascaded to unlock all 22 elements within the first few ticks.

Fix: Replaced both if (!elements[elem].unlocked) elements[elem] = { ...elements[elem], unlocked: true }; lines with a guard that skips locked elements entirely:

  • if (entry.paused || !elements[elem] || !elements[elem].unlocked) continue;

Regression test: Added bug-377-mana-auto-unlock.test.ts with 4 tests:

  1. Only transference is unlocked at game start
  2. Running one tick does not unlock any new elements
  3. Running multiple ticks does not unlock exotic elements
  4. Conversion rates for locked elements do not cause unlock after many ticks

Verification: All 73 test files (1186 tests) pass. The regression test was confirmed to FAIL on the unfixed code and PASS on the fixed code.

Files changed:

  • src/lib/game/stores/gameStore.ts — removed 2 auto-unlock lines, added unlocked guards
  • src/lib/game/__tests__/bug-377-mana-auto-unlock.test.ts — new regression test
## Fix Applied **Root cause:** Two lines in `gameStore.ts` unconditionally auto-unlocked any element with a non-zero conversion rate: - Line 211: In the element regen loop (`// Apply net element regen to pools`) - Line 324: In the recovery room boost loop On the first tick, the Enchanter attunement (active at level 1) provides conversion rate bonuses for transference-containing elements (soul, plasma, time), causing them to get non-zero rates and be auto-unlocked. This cascaded to unlock all 22 elements within the first few ticks. **Fix:** Replaced both `if (!elements[elem].unlocked) elements[elem] = { ...elements[elem], unlocked: true };` lines with a guard that skips locked elements entirely: - `if (entry.paused || !elements[elem] || !elements[elem].unlocked) continue;` **Regression test:** Added `bug-377-mana-auto-unlock.test.ts` with 4 tests: 1. Only transference is unlocked at game start ✅ 2. Running one tick does not unlock any new elements ✅ 3. Running multiple ticks does not unlock exotic elements ✅ 4. Conversion rates for locked elements do not cause unlock after many ticks ✅ **Verification:** All 73 test files (1186 tests) pass. The regression test was confirmed to FAIL on the unfixed code and PASS on the fixed code. **Files changed:** - `src/lib/game/stores/gameStore.ts` — removed 2 auto-unlock lines, added unlocked guards - `src/lib/game/__tests__/bug-377-mana-auto-unlock.test.ts` — new regression test
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#377