🐛 Disciplines don't accumulate XP or drain mana when active #119

Closed
opened 2026-05-22 13:20:54 +02:00 by Anexim · 2 comments
Owner

Bug

When a discipline is activated, it does not accumulate XP or drain mana over time.

Investigation

The discipline tick processing logic in src/lib/game/stores/discipline-slice.ts (processTick method) appears correct on paper — it iterates over activeIds, checks mana availability, drains mana, and increments XP. However, there are several potential issues:

  1. activate() early-returns if id is already in activeIds: The guard if (s.activeIds.includes(id)) return s; prevents re-activation of a discipline that was auto-paused by processTick (when mana runs out). The discipline stays in activeIds with paused: true, so activate() no-ops. This means once a discipline is auto-paused due to insufficient mana, the user cannot re-activate it.

  2. The processTick method may not be called correctly from the tick pipeline: Need to verify that stores/tick-pipeline.ts correctly calls processTick on the discipline store and passes the current mana state.

  3. Mana drain calculation: calculateManaDrain(def.drainBase, disc.xp, def.difficultyFactor) — if drainBase is 0 or very low for some disciplines, the drain may be imperceptible.

Files Involved

  • src/lib/game/stores/discipline-slice.ts (activate, deactivate, processTick)
  • src/lib/game/stores/tick-pipeline.ts (tick orchestration)
  • src/lib/game/utils/discipline-math.ts (calculateManaDrain)
  • src/components/game/tabs/DisciplinesTab.tsx (UI)

Suggested Fix

  1. Fix activate() to check !s.disciplines[id]?.paused instead of just activeIds.includes(id), so auto-paused disciplines can be re-activated.
  2. Verify the tick pipeline correctly invokes discipline processing.
  3. Add logging to processTick to confirm it's being called and disciplines are being processed each tick.
## Bug When a discipline is activated, it does not accumulate XP or drain mana over time. ## Investigation The discipline tick processing logic in `src/lib/game/stores/discipline-slice.ts` (`processTick` method) appears correct on paper — it iterates over `activeIds`, checks mana availability, drains mana, and increments XP. However, there are several potential issues: 1. **`activate()` early-returns if id is already in `activeIds`**: The guard `if (s.activeIds.includes(id)) return s;` prevents re-activation of a discipline that was auto-paused by `processTick` (when mana runs out). The discipline stays in `activeIds` with `paused: true`, so `activate()` no-ops. This means once a discipline is auto-paused due to insufficient mana, the user cannot re-activate it. 2. **The `processTick` method may not be called correctly from the tick pipeline**: Need to verify that `stores/tick-pipeline.ts` correctly calls `processTick` on the discipline store and passes the current mana state. 3. **Mana drain calculation**: `calculateManaDrain(def.drainBase, disc.xp, def.difficultyFactor)` — if `drainBase` is 0 or very low for some disciplines, the drain may be imperceptible. ## Files Involved - `src/lib/game/stores/discipline-slice.ts` (activate, deactivate, processTick) - `src/lib/game/stores/tick-pipeline.ts` (tick orchestration) - `src/lib/game/utils/discipline-math.ts` (calculateManaDrain) - `src/components/game/tabs/DisciplinesTab.tsx` (UI) ## Suggested Fix 1. Fix `activate()` to check `!s.disciplines[id]?.paused` instead of just `activeIds.includes(id)`, so auto-paused disciplines can be re-activated. 2. Verify the tick pipeline correctly invokes discipline processing. 3. Add logging to `processTick` to confirm it's being called and disciplines are being processed each tick.
Anexim added the ai:todo label 2026-05-22 13:20:54 +02:00
n8n-gitea was assigned by Anexim 2026-05-22 13:20:54 +02:00
Author
Owner

Fixed. Changes made:
discipline-slice.tsactivate() now checks if the discipline is already in activeIds but paused. If so, it un-pauses it (sets paused: false) instead of returning early. This allows re-activation of disciplines that were auto-paused by processTick when mana ran out.

Previously: if (s.activeIds.includes(id)) return s; — this blocked re-activation of auto-paused disciplines because they remained in activeIds.

Now: If the discipline is in activeIds and paused, it gets un-paused. If it's already active and not paused, it returns early (no-op).

✅ Fixed. Changes made: **discipline-slice.ts** — `activate()` now checks if the discipline is already in `activeIds` but paused. If so, it un-pauses it (sets `paused: false`) instead of returning early. This allows re-activation of disciplines that were auto-paused by `processTick` when mana ran out. Previously: `if (s.activeIds.includes(id)) return s;` — this blocked re-activation of auto-paused disciplines because they remained in `activeIds`. Now: If the discipline is in `activeIds` and paused, it gets un-paused. If it's already active and not paused, it returns early (no-op).
Author
Owner

Fixed discipline XP accumulation - activate() now properly handles auto-paused disciplines

✅ Fixed discipline XP accumulation - activate() now properly handles auto-paused disciplines
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#119