Better health accessors methods

This commit is contained in:
Joshua Barretto 2019-08-02 20:49:48 +01:00
parent 5e4f383952
commit 23cfe50455
2 changed files with 8 additions and 7 deletions

View File

@ -50,10 +50,6 @@ impl Health {
self.last_change = Some((amount, 0.0, cause));
}
pub fn set_current(&mut self, amount: u32) {
self.current = amount.min(self.maximum);
}
pub fn set_maximum(&mut self, amount: u32) {
self.maximum = amount;
self.current = self.current.min(self.maximum);
@ -140,6 +136,12 @@ impl Stats {
is_dead: false,
}
}
pub fn with_max_health(mut self, amount: u32) -> Self {
self.health.maximum = amount;
self.health.current = amount;
self
}
}
impl Component for Stats {

View File

@ -275,9 +275,8 @@ impl Server {
let mut scale = 1.0;
if npc.boss {
stats.health.set_maximum(400);
stats.health.set_current(400);
scale = 2.5;
stats = stats.with_max_health(300 + rand::random::<u32>() % 400);
scale = 1.8 + rand::random::<f32>().fract();
body = comp::Body::Humanoid(comp::humanoid::Body::random());
}