mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add a health bonus for level ups, fix pets
This commit is contained in:
parent
6f73d27431
commit
ec550620ad
@ -8,6 +8,7 @@ pub enum HealthSource {
|
|||||||
Suicide,
|
Suicide,
|
||||||
Revive,
|
Revive,
|
||||||
Command,
|
Command,
|
||||||
|
LevelUp,
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,10 +31,10 @@ pub struct Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Health {
|
impl Health {
|
||||||
pub fn get_current(&self) -> u32 {
|
pub fn current(&self) -> u32 {
|
||||||
self.current
|
self.current
|
||||||
}
|
}
|
||||||
pub fn get_maximum(&self) -> u32 {
|
pub fn maximum(&self) -> u32 {
|
||||||
self.maximum
|
self.maximum
|
||||||
}
|
}
|
||||||
pub fn set_to(&mut self, amount: u32, cause: HealthSource) {
|
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.current = ((self.current as i32 + amount).max(0) as u32).min(self.maximum);
|
||||||
self.last_change = Some((amount, 0.0, cause));
|
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 {
|
impl Exp {
|
||||||
@ -105,7 +110,7 @@ impl Stats {
|
|||||||
}
|
}
|
||||||
pub fn revive(&mut self) {
|
pub fn revive(&mut self) {
|
||||||
self.health
|
self.health
|
||||||
.set_to(self.health.get_maximum(), HealthSource::Revive);
|
.set_to(self.health.maximum(), HealthSource::Revive);
|
||||||
self.is_dead = false;
|
self.is_dead = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
Vec2::from(pos.0 - tgt_pos).normalized()
|
Vec2::from(pos.0 - tgt_pos).normalized()
|
||||||
} else {
|
} else {
|
||||||
Vec2::zero()
|
Vec2::zero()
|
||||||
} * -10.0;
|
};
|
||||||
}
|
}
|
||||||
_ => controller.move_dir = Vec2::zero(),
|
_ => controller.move_dir = Vec2::zero(),
|
||||||
}
|
}
|
||||||
|
@ -839,6 +839,13 @@ impl Server {
|
|||||||
attacker_stats.exp.change_maximum_by(25.0);
|
attacker_stats.exp.change_maximum_by(25.0);
|
||||||
attacker_stats.exp.set_current(0.0);
|
attacker_stats.exp.set_current(0.0);
|
||||||
attacker_stats.level.change_by(1);
|
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()
|
ecs.read_storage::<comp::Player>().get(attacker).cloned()
|
||||||
|
@ -429,7 +429,7 @@ impl Hud {
|
|||||||
.filter(|(entity, _, stats)| {
|
.filter(|(entity, _, stats)| {
|
||||||
*entity != me
|
*entity != me
|
||||||
&& !stats.is_dead
|
&& !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)
|
// Don't process health bars outside the vd (visibility further limited by ui backend)
|
||||||
.filter(|(_, pos, _)| {
|
.filter(|(_, pos, _)| {
|
||||||
@ -457,9 +457,7 @@ impl Hud {
|
|||||||
// % HP Filling
|
// % HP Filling
|
||||||
Rectangle::fill_with(
|
Rectangle::fill_with(
|
||||||
[
|
[
|
||||||
120.0
|
120.0 * (stats.health.current() as f64 / stats.health.maximum() as f64),
|
||||||
* (stats.health.get_current() as f64
|
|
||||||
/ stats.health.get_maximum() as f64),
|
|
||||||
8.0,
|
8.0,
|
||||||
],
|
],
|
||||||
HP_COLOR,
|
HP_COLOR,
|
||||||
|
@ -77,8 +77,7 @@ impl<'a> Widget for Skillbar<'a> {
|
|||||||
|
|
||||||
let exp_percentage = self.stats.exp.get_current() / self.stats.exp.get_maximum();
|
let exp_percentage = self.stats.exp.get_current() / self.stats.exp.get_maximum();
|
||||||
|
|
||||||
let hp_percentage =
|
let hp_percentage = self.stats.health.current() as f64 / self.stats.health.maximum() as f64;
|
||||||
self.stats.health.get_current() as f64 / self.stats.health.get_maximum() as f64;
|
|
||||||
let mana_percentage = 1.0;
|
let mana_percentage = 1.0;
|
||||||
|
|
||||||
// TODO: Only show while aiming with a bow or when casting a spell.
|
// TODO: Only show while aiming with a bow or when casting a spell.
|
||||||
|
Loading…
Reference in New Issue
Block a user