[High] [Bug] Spells from enchanted equipment bypass mana cost / never fire during spire combat #345

Closed
opened 2026-06-10 09:55:12 +02:00 by Anexim · 2 comments
Owner

Bug: Spells from enchanted weapons do not cost mana while climbing the spire

Description

There are actually two interrelated bugs affecting spells from enchanted equipment during spire climbing:


Bug A: Equipment spell enchantments never fire during combat (no damage, no mana cost)

Root cause: equipmentSpellStates in combatStore.ts is initialized as [] (empty array) and is never populated from the player's actual equipped gear before or during the combat tick.

Code path:

  1. combatStore.ts line 68: equipmentSpellStates: [] — starts empty
  2. gameStore.ts line ~291: The combat tick result writes equipmentSpellStates: cr.equipmentSpellStates back, but cr.equipmentSpellStates is just a copy of the empty input array
  3. combat-actions.ts line 130: const updatedEquipmentSpellStates = [...state.equipmentSpellStates]; — spreads the empty array
  4. combat-actions.ts lines 198-250: The equipment spell loop iterates over this empty array → never executes

The utility function getActiveEquipmentSpells() in combat-utils.ts (lines 335-360) correctly scans equipped instances for effect.type === 'spell' enchantments, but it is only used by the DPS calculation (getTotalDPS) and is never called during the combat tick setup. It is never wired into equipmentSpellStates.

Result: Casters, staves, and other equipment with spell-type enchantments (e.g., spell_manaBolt, spell_fireball) produce zero combat damage. Since they never fire, they also never deduct mana — but not because of a bypass, rather because the system is completely disconnected.


Bug B: Weapon enchantment spells (fireBlade, frostBlade, lightningBlade, voidBlade) have mana costs defined but never consume mana

Root cause: Weapon enchantments like fireBlade are defined in constants/spells-modules/enchantment-spells.ts with costs (e.g., rawCost(1) for fireBlade). They have isWeaponEnchant: true. However, they are not processed through the equipment spell state system (Bug A makes this irrelevant). Instead, they are processed through calcMeleeDamage() in combat-utils.ts (lines 298-333), which:

  • Only checks for effect.type === 'special' enchantments (not effect.type === 'spell')
  • Applies an elemental bonus to melee damage only
  • Never calls canAffordSpellCost or deductSpellCost — melee attacks are free

Code path:

  1. combat-actions.ts lines 218-260: Melee sword attack loop
  2. Calls calcMeleeDamage() which applies elemental bonus from weapon enchantments
  3. No mana check, no mana deduction — the melee loop has no canAffordSpellCost guard

Result: If a player enchants a sword with fireBlade (which has a defined cost of rawCost(1)), the fire damage bonus is applied to melee attacks for free. The cost field on the SpellDef is never consulted for weapon-enchant spells during melee processing.


Severity Assessment

Bug Severity Impact
A — Equipment spell enchantments never fire High Entire enchantment category (spell-type) is non-functional. Players enchanting casters/staves see no benefit in combat. This is a core system that has never worked.
B — Weapon enchant costs ignored Medium Melee weapon enchants deal elemental bonus damage for free. Less impactful since melee is already a separate damage type, but still a balance issue.

Files Involved

File Role
src/lib/game/stores/combatStore.ts (line 68) equipmentSpellStates: [] — never populated
src/lib/game/stores/combat-actions.ts (lines 130, 198-250) Equipment spell loop — iterates empty array
src/lib/game/stores/combat-actions.ts (lines 218-260) Melee loop — no mana cost check
src/lib/game/stores/gameStore.ts (~line 270-295) Combat tick setup — does not populate equipmentSpellStates from equipped gear
src/lib/game/utils/combat-utils.ts (lines 335-360) getActiveEquipmentSpells() — correct logic, only used for DPS calc
src/lib/game/utils/combat-utils.ts (lines 298-333) calcMeleeDamage() — no mana deduction
src/lib/game/constants/spells-modules/enchantment-spells.ts Defines weapon enchant spell costs that are never used

Reproduction Steps

  1. Enchant a caster/staff with a spell-type enchantment (e.g., spell_manaBolt or spell_fireball)
  2. Equip it and enter the spire
  3. Observe: no equipment spell damage is dealt
  4. Observe: mana is not consumed by equipment spell casts

For weapon enchants:

  1. Enchant a sword with fireBlade/fire/frost/lightning/void blade
  2. Equip it and enter the spire
  3. Observe: elemental bonus damage is applied to melee attacks
  4. Observe: mana is never consumed despite defined costs

Related Code Observations

  • The weaponMana/weaponManaMax/weaponManaRegen/weaponManaType fields exist on EquipmentInstance (in types/equipment.ts) and in crafting-initial-state.ts, suggesting a "weapon mana pool" was planned for weapon enchant costs but was never implemented.
  • A secondary issue: gameStore.ts line ~281 passes attackSpeedMult: 1 (hardcoded) to processCombatTick, ignoring the computed attackSpeedMultiplier from computeAllEffects(). This affects casting speed but is separate from the mana cost bug.
## Bug: Spells from enchanted weapons do not cost mana while climbing the spire ### Description There are actually **two interrelated bugs** affecting spells from enchanted equipment during spire climbing: --- ### Bug A: Equipment spell enchantments never fire during combat (no damage, no mana cost) **Root cause:** `equipmentSpellStates` in `combatStore.ts` is initialized as `[]` (empty array) and is **never populated from the player's actual equipped gear** before or during the combat tick. **Code path:** 1. `combatStore.ts` line 68: `equipmentSpellStates: []` — starts empty 2. `gameStore.ts` line ~291: The combat tick result writes `equipmentSpellStates: cr.equipmentSpellStates` back, but `cr.equipmentSpellStates` is just a copy of the empty input array 3. `combat-actions.ts` line 130: `const updatedEquipmentSpellStates = [...state.equipmentSpellStates];` — spreads the empty array 4. `combat-actions.ts` lines 198-250: The equipment spell loop iterates over this empty array → **never executes** The utility function `getActiveEquipmentSpells()` in `combat-utils.ts` (lines 335-360) correctly scans equipped instances for `effect.type === 'spell'` enchantments, but it is **only used by the DPS calculation** (`getTotalDPS`) and is **never called during the combat tick setup**. It is never wired into `equipmentSpellStates`. **Result:** Casters, staves, and other equipment with spell-type enchantments (e.g., `spell_manaBolt`, `spell_fireball`) produce zero combat damage. Since they never fire, they also never deduct mana — but not because of a bypass, rather because the system is completely disconnected. --- ### Bug B: Weapon enchantment spells (fireBlade, frostBlade, lightningBlade, voidBlade) have mana costs defined but never consume mana **Root cause:** Weapon enchantments like `fireBlade` are defined in `constants/spells-modules/enchantment-spells.ts` with costs (e.g., `rawCost(1)` for fireBlade). They have `isWeaponEnchant: true`. However, they are **not processed through the equipment spell state system** (Bug A makes this irrelevant). Instead, they are processed through `calcMeleeDamage()` in `combat-utils.ts` (lines 298-333), which: - Only checks for `effect.type === 'special'` enchantments (not `effect.type === 'spell'`) - Applies an elemental bonus to **melee damage only** - **Never calls `canAffordSpellCost` or `deductSpellCost`** — melee attacks are free **Code path:** 1. `combat-actions.ts` lines 218-260: Melee sword attack loop 2. Calls `calcMeleeDamage()` which applies elemental bonus from weapon enchantments 3. **No mana check, no mana deduction** — the melee loop has no `canAffordSpellCost` guard **Result:** If a player enchants a sword with fireBlade (which has a defined cost of `rawCost(1)`), the fire damage bonus is applied to melee attacks for free. The `cost` field on the `SpellDef` is never consulted for weapon-enchant spells during melee processing. --- ### Severity Assessment | Bug | Severity | Impact | |-----|----------|--------| | A — Equipment spell enchantments never fire | **High** | Entire enchantment category (spell-type) is non-functional. Players enchanting casters/staves see no benefit in combat. This is a core system that has never worked. | | B — Weapon enchant costs ignored | **Medium** | Melee weapon enchants deal elemental bonus damage for free. Less impactful since melee is already a separate damage type, but still a balance issue. | --- ### Files Involved | File | Role | |------|------| | `src/lib/game/stores/combatStore.ts` (line 68) | `equipmentSpellStates: []` — never populated | | `src/lib/game/stores/combat-actions.ts` (lines 130, 198-250) | Equipment spell loop — iterates empty array | | `src/lib/game/stores/combat-actions.ts` (lines 218-260) | Melee loop — no mana cost check | | `src/lib/game/stores/gameStore.ts` (~line 270-295) | Combat tick setup — does not populate equipmentSpellStates from equipped gear | | `src/lib/game/utils/combat-utils.ts` (lines 335-360) | `getActiveEquipmentSpells()` — correct logic, only used for DPS calc | | `src/lib/game/utils/combat-utils.ts` (lines 298-333) | `calcMeleeDamage()` — no mana deduction | | `src/lib/game/constants/spells-modules/enchantment-spells.ts` | Defines weapon enchant spell costs that are never used | --- ### Reproduction Steps 1. Enchant a caster/staff with a spell-type enchantment (e.g., `spell_manaBolt` or `spell_fireball`) 2. Equip it and enter the spire 3. Observe: no equipment spell damage is dealt 4. Observe: mana is not consumed by equipment spell casts **For weapon enchants:** 1. Enchant a sword with fireBlade/fire/frost/lightning/void blade 2. Equip it and enter the spire 3. Observe: elemental bonus damage is applied to melee attacks 4. Observe: mana is never consumed despite defined costs --- ### Related Code Observations - The `weaponMana`/`weaponManaMax`/`weaponManaRegen`/`weaponManaType` fields exist on `EquipmentInstance` (in `types/equipment.ts`) and in `crafting-initial-state.ts`, suggesting a "weapon mana pool" was planned for weapon enchant costs but was never implemented. - A secondary issue: `gameStore.ts` line ~281 passes `attackSpeedMult: 1` (hardcoded) to `processCombatTick`, ignoring the computed `attackSpeedMultiplier` from `computeAllEffects()`. This affects casting speed but is separate from the mana cost bug.
Anexim added the ai:todo label 2026-06-10 09:55:12 +02:00
n8n-gitea was assigned by Anexim 2026-06-10 09:55:12 +02:00
Anexim added ai:in-progress and removed ai:todo labels 2026-06-10 12:06:23 +02:00
Author
Owner

Starting work on Issue #345. Two bugs: (A) equipmentSpellStates never populated from equipped gear, (B) weapon enchant spells bypass mana cost in melee. Reading gameStore.ts combat tick setup to understand the wiring.

Starting work on Issue #345. Two bugs: (A) equipmentSpellStates never populated from equipped gear, (B) weapon enchant spells bypass mana cost in melee. Reading gameStore.ts combat tick setup to understand the wiring.
Anexim added ai:done and removed ai:in-progress labels 2026-06-10 12:43:39 +02:00
Author
Owner

Fixed Issue #345 (both bugs):

Bug A - Equipment spell enchantments never fire:

  • Added getActiveEquipmentSpells() call in gameStore.ts combat tick setup to populate equipmentSpellStates from equipped gear before processCombatTick runs
  • Equipment with spell-type enchantments (e.g., spell_manaBolt on casters/staves) now properly fire during combat

Bug B - Weapon enchant spells bypass mana cost:

  • Extracted deductWeaponEnchantCosts() helper in combat-damage.ts
  • Melee loop in combat-actions.ts now deducts mana for weapon enchant spells (fireBlade, frostBlade, lightningBlade, voidBlade) per hit

All 1141 tests pass (65 test files), no regressions.

✅ Fixed Issue #345 (both bugs): **Bug A - Equipment spell enchantments never fire:** - Added `getActiveEquipmentSpells()` call in `gameStore.ts` combat tick setup to populate `equipmentSpellStates` from equipped gear before `processCombatTick` runs - Equipment with `spell`-type enchantments (e.g., spell_manaBolt on casters/staves) now properly fire during combat **Bug B - Weapon enchant spells bypass mana cost:** - Extracted `deductWeaponEnchantCosts()` helper in `combat-damage.ts` - Melee loop in `combat-actions.ts` now deducts mana for weapon enchant spells (fireBlade, frostBlade, lightningBlade, voidBlade) per hit All 1141 tests pass (65 test files), no regressions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#345