[High] [Bug] Pact System: Raw mana cost never deducted when starting pact ritual #306

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

Spec: docs/specs/attunements/invoker/systems/pact-system-spec.md §2.2 step 7
Severity: High

Problem: src/lib/game/stores/prestigeStore.ts:97-108startPactRitual() validates rawMana < guardian.pactCost but never deducts the cost. The spec explicitly says "Deduct guardian.pactCost raw mana" and the cancellation rule says "not refunded on cancellation," implying it should have been deducted upfront.

File: src/lib/game/stores/prestigeStore.ts:97-108

**Spec:** docs/specs/attunements/invoker/systems/pact-system-spec.md §2.2 step 7 **Severity:** High **Problem:** `src/lib/game/stores/prestigeStore.ts:97-108` — `startPactRitual()` validates `rawMana < guardian.pactCost` but **never deducts the cost**. The spec explicitly says "Deduct guardian.pactCost raw mana" and the cancellation rule says "not refunded on cancellation," implying it should have been deducted upfront. **File:** `src/lib/game/stores/prestigeStore.ts:97-108`
Anexim added the ai:todo label 2026-06-07 17:42:19 +02:00
n8n-gitea was assigned by Anexim 2026-06-07 17:42:19 +02:00
Anexim added ai:in-progress and removed ai:todo labels 2026-06-08 11:13:18 +02:00
Author
Owner

Starting investigation of Issue #306: Pact System raw mana cost never deducted when starting pact ritual.

Starting investigation of Issue #306: Pact System raw mana cost never deducted when starting pact ritual.
Author
Owner

Bug confirmed. In startPactRitual() (prestigeStore.ts:97-108), the function validates rawMana < guardian.pactCost but never deducts the cost. Per spec §2.2 step 7: "Deduct guardian.pactCost raw mana". The spec §2.5 also confirms the cost should NOT be refunded on cancellation, implying it must be deducted upfront at start.

Root cause: The startPactRitual function only sets pactRitualFloor and pactRitualProgress, but never calls any mana deduction method.

Fix plan: After all validations pass and before set(), deduct guardian.pactCost from raw mana using useManaStore.getState().spendMana() or equivalent. Need to check the mana store API first.

**Bug confirmed.** In `startPactRitual()` (prestigeStore.ts:97-108), the function validates `rawMana < guardian.pactCost` but never deducts the cost. Per spec §2.2 step 7: "Deduct guardian.pactCost raw mana". The spec §2.5 also confirms the cost should NOT be refunded on cancellation, implying it must be deducted upfront at start. **Root cause:** The `startPactRitual` function only sets `pactRitualFloor` and `pactRitualProgress`, but never calls any mana deduction method. **Fix plan:** After all validations pass and before `set()`, deduct `guardian.pactCost` from raw mana using `useManaStore.getState().spendMana()` or equivalent. Need to check the mana store API first.
Anexim added ai:done and removed ai:in-progress labels 2026-06-08 11:21:30 +02:00
Author
Owner

Fix complete. Added useManaStore.getState().spendRawMana(guardian.pactCost) call in startPactRitual() after all validations pass, before setting ritual state. This implements spec §2.2 step 7: "Deduct guardian.pactCost raw mana".

Changes:

  • src/lib/game/stores/prestigeStore.ts — Added mana deduction after validation guards in startPactRitual()
  • src/lib/game/__tests__/store-actions-combat-prestige.test.ts — Added 2 regression tests:
    1. "should deduct raw mana cost when starting ritual" — verifies mana is deducted on successful ritual start
    2. "should NOT deduct raw mana when ritual fails" — verifies mana is NOT deducted when validation fails
    • Also fixed existing test "should start ritual when conditions met" to set mana store state (previously passed only because deduction was missing)

Verification: All 54 test files (1043 tests) pass.

**Fix complete.** Added `useManaStore.getState().spendRawMana(guardian.pactCost)` call in `startPactRitual()` after all validations pass, before setting ritual state. This implements spec §2.2 step 7: "Deduct guardian.pactCost raw mana". **Changes:** - `src/lib/game/stores/prestigeStore.ts` — Added mana deduction after validation guards in `startPactRitual()` - `src/lib/game/__tests__/store-actions-combat-prestige.test.ts` — Added 2 regression tests: 1. "should deduct raw mana cost when starting ritual" — verifies mana is deducted on successful ritual start 2. "should NOT deduct raw mana when ritual fails" — verifies mana is NOT deducted when validation fails - Also fixed existing test "should start ritual when conditions met" to set mana store state (previously passed only because deduction was missing) **Verification:** All 54 test files (1043 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#306