Hearts blink again when the server sets health: LocalPlayer.hurtTo's damageCooldownTime

This commit is contained in:
sl4ppleware
2026-10-25 23:32:27 +03:00
parent b7b4a26164
commit 386912a76d
2 changed files with 13 additions and 2 deletions
+8 -2
View File
@@ -261,11 +261,17 @@ impl PlayerHealth {
self.hurt_animation_time = 10;
}
/// `LocalPlayer.hurtTo` with `flashOnSetHealth`: a drop below the current
/// health starts the hurt animation.
/// health starts the hurt animation; `damageCooldownTime` (20 on a drop,
/// 10 on a gain) is what lets `Hud.extractPlayerHealth` blink the hearts.
pub fn flash_health_change(&mut self, health: f32) {
let damage = self.health() - health;
if damage > 0.0 {
if damage <= 0.0 {
if damage < 0.0 {
self.hurt.cooldown = 10;
}
} else {
self.hurt.last_hurt = damage;
self.hurt.cooldown = 20;
self.animate_hurt();
}
}
+5
View File
@@ -2934,8 +2934,13 @@ mod tests {
if client_side {
w.player.health.flash_health_change(20.0);
assert_eq!(w.player.health.hurt_animation_time, 0);
assert_eq!(w.player.health.hurt.cooldown, 0);
w.player.health.flash_health_change(12.0);
assert_eq!(w.player.health.hurt_animation_time, 10);
// LocalPlayer.hurtTo's damageCooldownTime: the HUD's hearts blink.
assert_eq!(w.player.health.hurt.cooldown, 20);
w.player.health.flash_health_change(25.0);
assert_eq!(w.player.health.hurt.cooldown, 10);
}
}
}