Hearts blink again when the server sets health: LocalPlayer.hurtTo's damageCooldownTime
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user