mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
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 <yashas.lokesh@gmail.com>
This commit is contained in:
committed by
Joshua Barretto
parent
1bd3f0ab28
commit
be71aea20b
@ -35,8 +35,8 @@ pub struct Energy {
|
|||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||||
pub struct Exp {
|
pub struct Exp {
|
||||||
current: f64,
|
current: u32,
|
||||||
maximum: f64,
|
maximum: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||||
@ -97,29 +97,29 @@ impl Energy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Exp {
|
impl Exp {
|
||||||
pub fn current(&self) -> f64 {
|
pub fn current(&self) -> u32 {
|
||||||
self.current
|
self.current
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maximum(&self) -> f64 {
|
pub fn maximum(&self) -> u32 {
|
||||||
self.maximum
|
self.maximum
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_current(&mut self, current: f64) {
|
pub fn set_current(&mut self, current: u32) {
|
||||||
self.current = current;
|
self.current = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Uncomment when needed
|
// TODO: Uncomment when needed
|
||||||
// pub fn set_maximum(&mut self, maximum: f64) {
|
// pub fn set_maximum(&mut self, maximum: u32) {
|
||||||
// self.maximum = maximum;
|
// self.maximum = maximum;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pub fn change_by(&mut self, current: f64) {
|
pub fn change_by(&mut self, current: i64) {
|
||||||
self.current = self.current + current;
|
self.current = ((self.current as i64) + current) as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn change_maximum_by(&mut self, maximum: f64) {
|
pub fn change_maximum_by(&mut self, maximum: i64) {
|
||||||
self.maximum = self.maximum + maximum;
|
self.maximum = ((self.maximum as i64) + maximum) as u32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,8 +171,8 @@ impl Stats {
|
|||||||
},
|
},
|
||||||
level: Level { amount: 1 },
|
level: Level { amount: 1 },
|
||||||
exp: Exp {
|
exp: Exp {
|
||||||
current: 0.0,
|
current: 0,
|
||||||
maximum: 50.0,
|
maximum: 50,
|
||||||
},
|
},
|
||||||
energy: Energy {
|
energy: Energy {
|
||||||
current: 200,
|
current: 200,
|
||||||
|
@ -40,8 +40,8 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if stat.exp.current() >= stat.exp.maximum() {
|
if stat.exp.current() >= stat.exp.maximum() {
|
||||||
stat.exp.change_by(-stat.exp.maximum());
|
stat.exp.change_by(-(stat.exp.maximum() as i64));
|
||||||
stat.exp.change_maximum_by(25.0);
|
stat.exp.change_maximum_by(25);
|
||||||
stat.level.change_by(1);
|
stat.level.change_by(1);
|
||||||
stat.health.set_maximum(stat.health.maximum() + 10);
|
stat.health.set_maximum(stat.health.maximum() + 10);
|
||||||
stat.health
|
stat.health
|
||||||
|
@ -315,8 +315,9 @@ impl Server {
|
|||||||
if let Some(attacker_stats) = stats.get_mut(attacker) {
|
if let Some(attacker_stats) = stats.get_mut(attacker) {
|
||||||
// TODO: Discuss whether we should give EXP by Player Killing or not.
|
// TODO: Discuss whether we should give EXP by Player Killing or not.
|
||||||
attacker_stats.exp.change_by(
|
attacker_stats.exp.change_by(
|
||||||
entity_stats.health.maximum() as f64 / 10.0
|
(entity_stats.health.maximum() as f64 / 10.0
|
||||||
+ entity_stats.level.level() as f64 * 10.0,
|
+ entity_stats.level.level() as f64 * 10.0)
|
||||||
|
as i64,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -113,8 +113,8 @@ impl<'a> Widget for CharacterWindow<'a> {
|
|||||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||||
let widget::UpdateArgs { id, state, ui, .. } = args;
|
let widget::UpdateArgs { id, state, ui, .. } = args;
|
||||||
|
|
||||||
let xp_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 xp_treshold = format!("{}/{}", self.stats.exp.current(), self.stats.exp.maximum());
|
let exp_treshold = format!("{}/{}", self.stats.exp.current(), self.stats.exp.maximum());
|
||||||
let level = (self.stats.level.level()).to_string();
|
let level = (self.stats.level.level()).to_string();
|
||||||
|
|
||||||
// Frame
|
// Frame
|
||||||
@ -354,7 +354,7 @@ impl<'a> Widget for CharacterWindow<'a> {
|
|||||||
.set(state.charwindow_exp_rectangle, ui);
|
.set(state.charwindow_exp_rectangle, ui);
|
||||||
|
|
||||||
// Exp-Bar Progress
|
// 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)
|
.mid_left_with_margin_on(state.charwindow_tab1_expbar, 1.0)
|
||||||
.set(state.charwindow_exp_progress_rectangle, ui);
|
.set(state.charwindow_exp_progress_rectangle, ui);
|
||||||
|
|
||||||
@ -365,7 +365,7 @@ impl<'a> Widget for CharacterWindow<'a> {
|
|||||||
.set(state.charwindow_tab1_expbar, ui);
|
.set(state.charwindow_tab1_expbar, ui);
|
||||||
|
|
||||||
// Exp-Text
|
// Exp-Text
|
||||||
Text::new(&xp_treshold)
|
Text::new(&exp_treshold)
|
||||||
.mid_top_with_margin_on(state.charwindow_tab1_expbar, 10.0)
|
.mid_top_with_margin_on(state.charwindow_tab1_expbar, 10.0)
|
||||||
.font_id(self.fonts.opensans)
|
.font_id(self.fonts.opensans)
|
||||||
.font_size(15)
|
.font_size(15)
|
||||||
|
@ -116,7 +116,7 @@ impl<'a> Skillbar<'a> {
|
|||||||
pub struct State {
|
pub struct State {
|
||||||
ids: Ids,
|
ids: Ids,
|
||||||
|
|
||||||
last_xp_value: f64,
|
last_xp_value: u32,
|
||||||
last_level: u32,
|
last_level: u32,
|
||||||
last_update_xp: Instant,
|
last_update_xp: Instant,
|
||||||
last_update_level: Instant,
|
last_update_level: Instant,
|
||||||
@ -131,7 +131,7 @@ impl<'a> Widget for Skillbar<'a> {
|
|||||||
State {
|
State {
|
||||||
ids: Ids::new(id_gen),
|
ids: Ids::new(id_gen),
|
||||||
|
|
||||||
last_xp_value: 0.0,
|
last_xp_value: 0,
|
||||||
last_level: 1,
|
last_level: 1,
|
||||||
last_update_xp: Instant::now(),
|
last_update_xp: Instant::now(),
|
||||||
last_update_level: 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 level = (self.stats.level.level()).to_string();
|
||||||
let next_level = (self.stats.level.level() + 1).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 =
|
let hp_percentage =
|
||||||
self.stats.health.current() as f64 / self.stats.health.maximum() as f64 * 100.0;
|
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 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
|
0.0
|
||||||
} else if seconds_xp < FADE_IN_XP {
|
} else if seconds_xp < FADE_IN_XP {
|
||||||
seconds_xp / FADE_IN_XP
|
seconds_xp / FADE_IN_XP
|
||||||
|
Reference in New Issue
Block a user