feat(combat): support a damage multiplier in calculateDamage

This commit is contained in:
Bastian Wagner
2026-08-20 21:06:54 +02:00
parent 96d04d8ba3
commit eed247d318
2 changed files with 15 additions and 2 deletions

View File

@@ -14,4 +14,13 @@ describe('calculateDamage', () => {
// raw = 9; 9 * 60 / (60 + 5) = 8.307... -> rounds to 8 // raw = 9; 9 * 60 / (60 + 5) = 8.307... -> rounds to 8
expect(calculateDamage({ attack: 9 }, 5)).toBe(8); expect(calculateDamage({ attack: 9 }, 5)).toBe(8);
}); });
it('applies a damage multiplier before the minimum-1 floor', () => {
// raw = 27; mitigated = 20.25; *1.6 = 32.4 -> rounds to 32
expect(calculateDamage({ attack: 12, weaponDamage: 15 }, 20, 1.6)).toBe(32);
});
it('still floors at 1 damage even with a small multiplier', () => {
expect(calculateDamage({ attack: 1, weaponDamage: 0 }, 100_000, 0.5)).toBe(1);
});
}); });

View File

@@ -5,9 +5,13 @@ export interface DamageAttacker {
const ARMOR_MITIGATION_CONSTANT = 60; const ARMOR_MITIGATION_CONSTANT = 60;
export function calculateDamage(attacker: DamageAttacker, targetArmor: number): number { export function calculateDamage(
attacker: DamageAttacker,
targetArmor: number,
multiplier = 1,
): number {
const rawDamage = attacker.attack + (attacker.weaponDamage ?? 0); const rawDamage = attacker.attack + (attacker.weaponDamage ?? 0);
const mitigatedDamage = const mitigatedDamage =
(rawDamage * ARMOR_MITIGATION_CONSTANT) / (ARMOR_MITIGATION_CONSTANT + targetArmor); (rawDamage * ARMOR_MITIGATION_CONSTANT) / (ARMOR_MITIGATION_CONSTANT + targetArmor);
return Math.max(1, Math.round(mitigatedDamage)); return Math.max(1, Math.round(mitigatedDamage * multiplier));
} }