[High] [Bug] Enemy defenses (armor/barrier/dodge) partially bypassed for melee attacks #285
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: Bug / Incomplete feature
Priority: High
Investigation findings:
The
applyEnemyDefensesfunction incombat-tick.tsis fully implemented with the correct dodge → barrier → armor pipeline per spec §5.2. However, there is a critical gap:applyEnemyDefensescorrectlyapplyEnemyDefensescorrectlyenemy: null, which causes the defense function to short-circuit and return damage unchangedprocessGolemAttacks, needs separate investigationRoot cause: In
combat-actions.ts, the melee attack loop callsonDamageDealt(damage)which eventually callsapplyEnemyDefenses(dmg, null, ...)— passingnullas the enemy. TheapplyEnemyDefensesfunction checksif (!enemy) return dmgat the top, skipping all defense calculations.Fix needed: Pass the actual target enemy to
applyEnemyDefensesfor melee attacks, just like spells do.Files:
src/lib/game/stores/combat-actions.ts— melee attack loopsrc/lib/game/stores/pipelines/combat-tick.ts—applyEnemyDefensesfunctionStarting work on the melee defense bypass bug. Root cause is clear: in combat-actions.ts, the melee attack loop passes
nullas the enemy toapplyEnemyDefenses, causing it to short-circuit. Will investigate the exact code path and fix it.Fix Complete: Melee attacks now apply enemy defenses
Root Cause
In
combat-actions.ts, the melee sword attack loop calledapplyEnemyDefenses(meleeDamage, null, 'combat', ...)— passingnullas the enemy. TheapplyEnemyDefensesfunction incombat-tick.tschecksif (!enemy) return dmg;at the top, so all enemy defenses (armor, barrier, dodge) were completely bypassed for melee attacks.Spell damage and DoT effects correctly went through defenses via the
onDamageDealtcallback which used the properdefCtx.enemy.Fix Applied
File:
src/lib/game/stores/combat-actions.ts(melee loop, ~line 267)Changed the melee loop to:
get().currentRoomto get the current room stateapplyDamageToRoom)applyEnemyDefensesinstead ofnullRegression Tests Added
File:
src/lib/game/__tests__/melee-defense-bypass.test.ts(390 lines, 7 tests)Tests verify:
Verification
325949c)