Merge branch 'qutrin/last-minute-health' into 'master'

Add a health bonus for level ups, fix pets

See merge request veloren/veloren!387
This commit is contained in:
Timo Koesters 2019-08-01 17:08:06 +00:00
commit b1ca4fa13d
5 changed files with 19 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -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(),
}

View File

@ -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::<comp::Player>().get(attacker).cloned()

View File

@ -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,

View File

@ -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.