// Temporary hit points are a buffer: damage comes off them first, and only // what is left over reaches real HP. Takes the character's HP and temp HP as // they are and the HP a damage/heal asked for (which may be below zero), and // returns what both should become. Healing never touches temp HP. function absorbDamage(currentHp, tempHp, requestedHp) { const damage = currentHp - requestedHp; if (damage <= 0 || tempHp <= 0) return { currentHp: requestedHp, tempHp }; const absorbed = Math.min(tempHp, damage); return { currentHp: requestedHp + absorbed, tempHp: tempHp - absorbed }; } module.exports = { absorbDamage };