From be71aea20b17df5614dbbd911981fb6a0a82ba74 Mon Sep 17 00:00:00 2001 From: yashaslokesh Date: Tue, 27 Aug 2019 22:33:14 +0000 Subject: [PATCH] Changed exp type from f64 to u32 and altered exp calculations and function signatures to adhere to the new types Signed-off-by: Yashas Lokesh --- common/src/comp/stats.rs | 24 ++++++++++++------------ common/src/sys/stats.rs | 4 ++-- server/src/lib.rs | 5 +++-- voxygen/src/hud/character_window.rs | 8 ++++---- voxygen/src/hud/skillbar.rs | 8 ++++---- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index e0a69b9117..f147247cbd 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -35,8 +35,8 @@ pub struct Energy { #[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub struct Exp { - current: f64, - maximum: f64, + current: u32, + maximum: u32, } #[derive(Clone, Copy, Debug, Serialize, Deserialize)] @@ -97,29 +97,29 @@ impl Energy { } impl Exp { - pub fn current(&self) -> f64 { + pub fn current(&self) -> u32 { self.current } - pub fn maximum(&self) -> f64 { + pub fn maximum(&self) -> u32 { self.maximum } - pub fn set_current(&mut self, current: f64) { + pub fn set_current(&mut self, current: u32) { self.current = current; } // TODO: Uncomment when needed - // pub fn set_maximum(&mut self, maximum: f64) { + // pub fn set_maximum(&mut self, maximum: u32) { // self.maximum = maximum; // } - pub fn change_by(&mut self, current: f64) { - self.current = self.current + current; + pub fn change_by(&mut self, current: i64) { + self.current = ((self.current as i64) + current) as u32; } - pub fn change_maximum_by(&mut self, maximum: f64) { - self.maximum = self.maximum + maximum; + pub fn change_maximum_by(&mut self, maximum: i64) { + self.maximum = ((self.maximum as i64) + maximum) as u32; } } @@ -171,8 +171,8 @@ impl Stats { }, level: Level { amount: 1 }, exp: Exp { - current: 0.0, - maximum: 50.0, + current: 0, + maximum: 50, }, energy: Energy { current: 200, diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index 3aeb11746d..a943335970 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -40,8 +40,8 @@ impl<'a> System<'a> for Sys { } if stat.exp.current() >= stat.exp.maximum() { - stat.exp.change_by(-stat.exp.maximum()); - stat.exp.change_maximum_by(25.0); + stat.exp.change_by(-(stat.exp.maximum() as i64)); + stat.exp.change_maximum_by(25); stat.level.change_by(1); stat.health.set_maximum(stat.health.maximum() + 10); stat.health diff --git a/server/src/lib.rs b/server/src/lib.rs index 2c4eaf6ef2..606b143923 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -315,8 +315,9 @@ impl Server { if let Some(attacker_stats) = stats.get_mut(attacker) { // 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 * 10.0, + (entity_stats.health.maximum() as f64 / 10.0 + + entity_stats.level.level() as f64 * 10.0) + as i64, ); } }); diff --git a/voxygen/src/hud/character_window.rs b/voxygen/src/hud/character_window.rs index 25c92c8410..575ce3bc49 100644 --- a/voxygen/src/hud/character_window.rs +++ b/voxygen/src/hud/character_window.rs @@ -113,8 +113,8 @@ 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.current() / self.stats.exp.maximum(); - let xp_treshold = format!("{}/{}", self.stats.exp.current(), self.stats.exp.maximum()); + let exp_percentage = (self.stats.exp.current() as f64) / (self.stats.exp.maximum() as f64); + let exp_treshold = format!("{}/{}", self.stats.exp.current(), self.stats.exp.maximum()); let level = (self.stats.level.level()).to_string(); // Frame @@ -354,7 +354,7 @@ impl<'a> Widget for CharacterWindow<'a> { .set(state.charwindow_exp_rectangle, ui); // Exp-Bar Progress - Rectangle::fill_with([170.0 * (xp_percentage), 6.0], XP_COLOR) // 0.8 = Experience percentage + Rectangle::fill_with([170.0 * (exp_percentage), 6.0], XP_COLOR) // 0.8 = Experience percentage .mid_left_with_margin_on(state.charwindow_tab1_expbar, 1.0) .set(state.charwindow_exp_progress_rectangle, ui); @@ -365,7 +365,7 @@ impl<'a> Widget for CharacterWindow<'a> { .set(state.charwindow_tab1_expbar, ui); // Exp-Text - Text::new(&xp_treshold) + Text::new(&exp_treshold) .mid_top_with_margin_on(state.charwindow_tab1_expbar, 10.0) .font_id(self.fonts.opensans) .font_size(15) diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index b947de8c6d..88906fe71a 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -116,7 +116,7 @@ impl<'a> Skillbar<'a> { pub struct State { ids: Ids, - last_xp_value: f64, + last_xp_value: u32, last_level: u32, last_update_xp: Instant, last_update_level: Instant, @@ -131,7 +131,7 @@ impl<'a> Widget for Skillbar<'a> { State { ids: Ids::new(id_gen), - last_xp_value: 0.0, + last_xp_value: 0, last_level: 1, last_update_xp: Instant::now(), last_update_level: Instant::now(), @@ -148,7 +148,7 @@ impl<'a> Widget for Skillbar<'a> { let level = (self.stats.level.level()).to_string(); let next_level = (self.stats.level.level() + 1).to_string(); - let exp_percentage = self.stats.exp.current() / self.stats.exp.maximum(); + let exp_percentage = (self.stats.exp.current() as f64) / (self.stats.exp.maximum() as f64); let hp_percentage = self.stats.health.current() as f64 / self.stats.health.maximum() as f64 * 100.0; @@ -281,7 +281,7 @@ impl<'a> Widget for Skillbar<'a> { } let seconds_xp = state.last_update_xp.elapsed().as_secs_f32(); - let fade_xp = if current_xp == 0.0 { + let fade_xp = if current_xp == 0 { 0.0 } else if seconds_xp < FADE_IN_XP { seconds_xp / FADE_IN_XP