diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index 7d0a3a48bd..771a8d5b1c 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -57,11 +57,11 @@ impl Health { } impl Exp { - pub fn get_current(&self) -> f64 { + pub fn current(&self) -> f64 { self.current } - pub fn get_maximum(&self) -> f64 { + pub fn maximum(&self) -> f64 { self.maximum } @@ -74,7 +74,7 @@ impl Exp { // self.maximum = maximum; // } - pub fn change_current_by(&mut self, current: f64) { + pub fn change_by(&mut self, current: f64) { self.current = self.current + current; } @@ -89,7 +89,7 @@ impl Level { // self.amount = level; // } - pub fn get_level(&self) -> u32 { + pub fn level(&self) -> u32 { self.amount } diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index d25480bd45..270ddf7860 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -35,6 +35,15 @@ impl<'a> System<'a> for Sys { if let Some(change) = &mut stat.health.last_change { change.1 += f64::from(dt.0); } + + if stat.exp.current() >= stat.exp.maximum() { + stat.exp.change_by(-stat.exp.maximum()); + stat.exp.change_maximum_by(25.0); + stat.level.change_by(1); + stat.health.set_maximum(stat.health.maximum() + 10); + stat.health + .set_to(stat.health.maximum(), HealthSource::LevelUp) + } } } } diff --git a/server/src/lib.rs b/server/src/lib.rs index f21ae9c614..6de1516188 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -878,34 +878,18 @@ impl Server { } // Give EXP to the client - if let Some(_enemy) = ecs.read_storage::().get(entity) { - if let comp::HealthSource::Attack { by } = dying.cause { - ecs.entity_from_uid(by.into()).and_then(|attacker| { - let mut stats = ecs.write_storage::(); - let attacker_stats = stats.get_mut(attacker).unwrap(); + if let comp::HealthSource::Attack { by } = dying.cause { + ecs.entity_from_uid(by.into()).map(|attacker| { + let mut stats = ecs.write_storage::(); + let entity_stats = stats.get(entity).unwrap().clone(); + let attacker_stats = stats.get_mut(attacker).unwrap(); - // TODO: Discuss whether we should give EXP by Player Killing or not. - // TODO: Don't make this a single value and make it depend on - // slayed entity's level - attacker_stats.exp.change_current_by(1.0); - - if attacker_stats.exp.get_current() >= attacker_stats.exp.get_maximum() - { - 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() - }); - } + // TODO: Discuss whether we should give EXP by Player Killing or not. + attacker_stats.exp.change_by( + entity_stats.health.maximum() as f64 / 10.0 + * entity_stats.level.level() as f64, + ); + }); } entity diff --git a/voxygen/src/hud/character_window.rs b/voxygen/src/hud/character_window.rs index 9ce1bb2afd..63e0fa2390 100644 --- a/voxygen/src/hud/character_window.rs +++ b/voxygen/src/hud/character_window.rs @@ -107,13 +107,9 @@ impl<'a> Widget for CharacterWindow<'a> { fn update(self, args: widget::UpdateArgs) -> Self::Event { let widget::UpdateArgs { id, state, ui, .. } = args; - let xp_percentage = self.stats.exp.get_current() / self.stats.exp.get_maximum(); - let xp_treshold = format!( - "{}/{}", - self.stats.exp.get_current(), - self.stats.exp.get_maximum() - ); - let level = (self.stats.level.get_level()).to_string(); + let xp_percentage = self.stats.exp.current() / self.stats.exp.maximum(); + let xp_treshold = format!("{}/{}", self.stats.exp.current(), self.stats.exp.maximum()); + let level = (self.stats.level.level()).to_string(); // Frame Image::new(self.imgs.window_3) diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 5e4469d5c5..a2bcd4eef0 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -72,10 +72,10 @@ impl<'a> Widget for Skillbar<'a> { fn update(self, args: widget::UpdateArgs) -> Self::Event { let widget::UpdateArgs { state, ui, .. } = args; - let level = (self.stats.level.get_level()).to_string(); - let next_level = (self.stats.level.get_level() + 1).to_string(); + let level = (self.stats.level.level()).to_string(); + let next_level = (self.stats.level.level() + 1).to_string(); - let exp_percentage = self.stats.exp.get_current() / self.stats.exp.get_maximum(); + let exp_percentage = self.stats.exp.current() / self.stats.exp.maximum(); let hp_percentage = self.stats.health.current() as f64 / self.stats.health.maximum() as f64; let mana_percentage = 1.0;