/** Four-roll hit pattern: high hit, low agility, high damage, low defence. */ const DAMAGING_PATTERN = Object.freeze([0.99, 0, 0.99, 0]); /** * Deterministic Math.random for integration tests: melee hits land with damage. * Matches {@link shared/combat/rolls.js} — damage equals the damage skill roll only. */ export function installDamagingCombatRng () { const random = Math.random; let i = 0; Math.random = () => DAMAGING_PATTERN[i++ % DAMAGING_PATTERN.length]; return () => { Math.random = random; }; } export function withDamagingCombatRng (fn) { const restore = installDamagingCombatRng(); try { fn(); } finally { restore(); } } /** Miss (agility wins) but attacker rolled non-zero damage for dodge XP. */ export function installMissDodgeRng (attackerDamageSkill = 1) { const damageSample = attackerDamageSkill <= 1 ? 0.51 : 0.99; const pattern = Object.freeze([0, 0.99, damageSample]); let i = 0; const random = Math.random; Math.random = () => pattern[i++ % pattern.length]; return () => { Math.random = random; }; } /** Block after a hit contest; damage roll is non-zero for Defence XP. */ export function installBlockRng (attackerDamageSkill = 1) { const damageSample = attackerDamageSkill <= 1 ? 0.51 : 0.99; const pattern = Object.freeze([0.99, 0, damageSample, 0.99]); let i = 0; const random = Math.random; Math.random = () => pattern[i++ % pattern.length]; return () => { Math.random = random; }; }