From ec550620ad8c5790d4a6276b7a132486dc2fad7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Korg=C3=B3l?= Date: Thu, 1 Aug 2019 14:48:09 +0200 Subject: [PATCH] Add a health bonus for level ups, fix pets --- common/src/comp/stats.rs | 11 ++++++++--- common/src/sys/agent.rs | 2 +- server/src/lib.rs | 7 +++++++ voxygen/src/hud/mod.rs | 6 ++---- voxygen/src/hud/skillbar.rs | 3 +-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index ac81196e84..12d13b7e58 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -8,6 +8,7 @@ pub enum HealthSource { Suicide, Revive, Command, + LevelUp, Unknown, } @@ -30,10 +31,10 @@ pub struct Level { } impl Health { - pub fn get_current(&self) -> u32 { + pub fn current(&self) -> u32 { self.current } - pub fn get_maximum(&self) -> u32 { + pub fn maximum(&self) -> u32 { self.maximum } pub fn set_to(&mut self, amount: u32, cause: HealthSource) { @@ -45,6 +46,10 @@ impl Health { self.current = ((self.current as i32 + amount).max(0) as u32).min(self.maximum); self.last_change = Some((amount, 0.0, cause)); } + pub fn set_maximum(&mut self, amount: u32) { + self.maximum = amount; + self.current = self.current.min(self.maximum); + } } impl Exp { @@ -105,7 +110,7 @@ impl Stats { } pub fn revive(&mut self) { self.health - .set_to(self.health.get_maximum(), HealthSource::Revive); + .set_to(self.health.maximum(), HealthSource::Revive); self.is_dead = false; } } diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index 4606245608..ba1d97c126 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -46,7 +46,7 @@ impl<'a> System<'a> for Sys { Vec2::from(pos.0 - tgt_pos).normalized() } else { Vec2::zero() - } * -10.0; + }; } _ => controller.move_dir = Vec2::zero(), } diff --git a/server/src/lib.rs b/server/src/lib.rs index 346099ea9f..50b0d0b437 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -839,6 +839,13 @@ impl Server { attacker_stats.exp.change_maximum_by(25.0); attacker_stats.exp.set_current(0.0); attacker_stats.level.change_by(1); + attacker_stats + .health + .set_maximum(attacker_stats.health.maximum() + 10); + attacker_stats.health.set_to( + attacker_stats.health.maximum(), + comp::HealthSource::LevelUp, + ) } ecs.read_storage::().get(attacker).cloned() diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 1a52b1192e..8796ffeb2d 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -429,7 +429,7 @@ impl Hud { .filter(|(entity, _, stats)| { *entity != me && !stats.is_dead - && stats.health.get_current() != stats.health.get_maximum() + && stats.health.current() != stats.health.maximum() }) // Don't process health bars outside the vd (visibility further limited by ui backend) .filter(|(_, pos, _)| { @@ -457,9 +457,7 @@ impl Hud { // % HP Filling Rectangle::fill_with( [ - 120.0 - * (stats.health.get_current() as f64 - / stats.health.get_maximum() as f64), + 120.0 * (stats.health.current() as f64 / stats.health.maximum() as f64), 8.0, ], HP_COLOR, diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 6c76b787a1..5e4469d5c5 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -77,8 +77,7 @@ impl<'a> Widget for Skillbar<'a> { let exp_percentage = self.stats.exp.get_current() / self.stats.exp.get_maximum(); - let hp_percentage = - self.stats.health.get_current() as f64 / self.stats.health.get_maximum() as f64; + let hp_percentage = self.stats.health.current() as f64 / self.stats.health.maximum() as f64; let mana_percentage = 1.0; // TODO: Only show while aiming with a bow or when casting a spell.