fix: melee attacks now apply enemy defenses (armor/barrier/dodge)
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m17s

Bug: Melee sword attacks passed null as the enemy to applyEnemyDefenses,
causing all enemy defenses (armor, barrier, dodge) to be bypassed.
Spell damage and DoT effects correctly went through defenses.

Fix: In combat-actions.ts melee loop, get the current target enemy
from currentRoom.enemies (lowest HP, matching focus-fire targeting)
and pass it to applyEnemyDefenses instead of null.

Added 7 regression tests in melee-defense-bypass.test.ts to verify:
- Melee damage is reduced by armor
- Melee damage is reduced by barrier
- Unarmored enemies take more damage than armored ones
- Full damage dealt when no defenses
- Focus-fire targeting (lowest HP enemy)
- Graceful handling of empty enemy list
- Comparison proving defense application

All 948 tests pass (49 test files).
This commit is contained in:
2026-06-06 17:33:31 +02:00
parent 4b7aa82953
commit 325949cc5f
5 changed files with 431 additions and 13 deletions
+7 -1
View File
@@ -270,7 +270,13 @@ export function processCombatTick(
let meleeSafetyCounter = 0;
while (meleeProgress >= 1 && meleeSafetyCounter < 100) {
const meleeDamage = calcMeleeDamage(swordInstance as EquipmentInstance, swordType, floorElems[0]);
const finalMeleeDamage = applyEnemyDefenses(meleeDamage, null, 'combat', (msg) => logMessages.push(msg));
// Get the current target enemy (lowest HP, matching focus-fire targeting in applyDamageToRoom)
const currentRoomState = get().currentRoom;
const livingEnemies = currentRoomState.enemies.filter(e => e.hp > 0);
const targetEnemy = livingEnemies.length > 0
? livingEnemies.reduce((lowest, e) => e.hp < lowest.hp ? e : lowest)
: null;
const finalMeleeDamage = applyEnemyDefenses(meleeDamage, targetEnemy, currentRoomState.roomType, (msg) => logMessages.push(msg));
if (!Number.isFinite(finalMeleeDamage)) break;
// Apply melee damage per-enemy (spec §3.2, focus-fire)