[Critical] [Bug] Golem combat wipes all mana when no enemies are alive #352

Closed
opened 2026-06-10 19:22:08 +02:00 by Anexim · 2 comments
Owner

Severity: Critical
File: src/lib/game/stores/golem-combat-actions.ts (lines 242-243, 310-317) and src/lib/game/stores/golem-combat-helpers.ts (lines 148-192)

Description:
processGolemAttacks initializes rawMana = 0 and elements = {} as local accumulators. When no golems attack, or all enemies are dead, these zero/empty values are returned. The caller in combat-actions.ts (lines 316-317) then overwrites the game's actual mana state with these zeros:

rawMana = golemResult.rawMana;  // Overwrites with 0!
elements = golemResult.elements;  // Overwrites with {}!

Similarly, processBasicAttack in golem-combat-helpers.ts initializes rawMana = 0 and elements = {} and returns them when no targets exist.

Impact: Complete mana wipe (all elements and raw mana set to zero) whenever golems process their attack phase but find no living enemies. This is a soft-lock at minimum — the player loses all mana progress.

Reproduction:

  1. Have golems active in combat
  2. Kill all enemies in a room
  3. On the next golem attack tick, all mana is wiped to 0
**Severity:** Critical **File:** `src/lib/game/stores/golem-combat-actions.ts` (lines 242-243, 310-317) and `src/lib/game/stores/golem-combat-helpers.ts` (lines 148-192) **Description:** `processGolemAttacks` initializes `rawMana = 0` and `elements = {}` as local accumulators. When no golems attack, or all enemies are dead, these zero/empty values are returned. The caller in `combat-actions.ts` (lines 316-317) then overwrites the game's actual mana state with these zeros: ```typescript rawMana = golemResult.rawMana; // Overwrites with 0! elements = golemResult.elements; // Overwrites with {}! ``` Similarly, `processBasicAttack` in `golem-combat-helpers.ts` initializes `rawMana = 0` and `elements = {}` and returns them when no targets exist. **Impact:** Complete mana wipe (all elements and raw mana set to zero) whenever golems process their attack phase but find no living enemies. This is a soft-lock at minimum — the player loses all mana progress. **Reproduction:** 1. Have golems active in combat 2. Kill all enemies in a room 3. On the next golem attack tick, all mana is wiped to 0
Anexim added the ai:todo label 2026-06-10 19:22:08 +02:00
n8n-gitea was assigned by Anexim 2026-06-10 19:22:08 +02:00
Anexim added ai:review and removed ai:todo labels 2026-06-10 20:41:38 +02:00
Author
Owner

Fix applied. processGolemAttacks initialized rawMana = 0 and elements = {} as local accumulators. When no enemies were alive, processBasicAttack never called onDamageDealt, so these zero/empty values were returned. The caller in combat-actions.ts then overwrote the game's actual mana state with these zeros.

Root cause: Local accumulators initialized to zero instead of current mana values.

Fix:

  1. processGolemAttacks now accepts currentRawMana and currentElements as parameters and initializes from them
  2. processBasicAttack now accepts and uses currentRawMana/currentElements instead of 0/{}
  3. processGolemAttacksFromStore passes through the current mana values
  4. combat-actions.ts caller passes rawMana and elements to the golem attack pipeline
  5. Updated test file to pass the two new parameters

All 1141 tests pass.

**Fix applied.** `processGolemAttacks` initialized `rawMana = 0` and `elements = {}` as local accumulators. When no enemies were alive, `processBasicAttack` never called `onDamageDealt`, so these zero/empty values were returned. The caller in `combat-actions.ts` then overwrote the game's actual mana state with these zeros. **Root cause:** Local accumulators initialized to zero instead of current mana values. **Fix:** 1. `processGolemAttacks` now accepts `currentRawMana` and `currentElements` as parameters and initializes from them 2. `processBasicAttack` now accepts and uses `currentRawMana`/`currentElements` instead of `0`/`{}` 3. `processGolemAttacksFromStore` passes through the current mana values 4. `combat-actions.ts` caller passes `rawMana` and `elements` to the golem attack pipeline 5. Updated test file to pass the two new parameters All 1141 tests pass.
Anexim added ai:done and removed ai:review labels 2026-06-11 12:37:53 +02:00
Author
Owner

Review complete — fix verified.

The golem combat mana wipe is fixed. processGolemAttacks, processGolemAttacksFromStore, and processBasicAttack all now accept and initialize from currentRawMana/currentElements instead of 0/{}. When no enemies are alive, the original mana values pass through unchanged instead of being zeroed out.

The data flow is unbroken: combat-actions.tsprocessGolemAttacksFromStoreprocessGolemAttacksprocessBasicAttack, with current mana threaded through every level.

  • Regression test bug-352-golem-mana-wipe.test.ts: 7/7 tests pass
  • Full suite: 68 files, 1158 tests — all green

No remaining issues.

**Review complete — fix verified.** The golem combat mana wipe is fixed. `processGolemAttacks`, `processGolemAttacksFromStore`, and `processBasicAttack` all now accept and initialize from `currentRawMana`/`currentElements` instead of `0`/`{}`. When no enemies are alive, the original mana values pass through unchanged instead of being zeroed out. The data flow is unbroken: `combat-actions.ts` → `processGolemAttacksFromStore` → `processGolemAttacks` → `processBasicAttack`, with current mana threaded through every level. - Regression test `bug-352-golem-mana-wipe.test.ts`: 7/7 tests pass - Full suite: 68 files, 1158 tests — all green No remaining issues.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#352