Give xp depending on max hp and lvl of entity killed

This commit is contained in:
timokoesters
2019-08-03 21:30:01 +02:00
parent eaee0f263d
commit 7365dbe9e6
5 changed files with 30 additions and 41 deletions

View File

@ -57,11 +57,11 @@ impl Health {
} }
impl Exp { impl Exp {
pub fn get_current(&self) -> f64 { pub fn current(&self) -> f64 {
self.current self.current
} }
pub fn get_maximum(&self) -> f64 { pub fn maximum(&self) -> f64 {
self.maximum self.maximum
} }
@ -74,7 +74,7 @@ impl Exp {
// self.maximum = maximum; // 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; self.current = self.current + current;
} }
@ -89,7 +89,7 @@ impl Level {
// self.amount = level; // self.amount = level;
// } // }
pub fn get_level(&self) -> u32 { pub fn level(&self) -> u32 {
self.amount self.amount
} }

View File

@ -35,6 +35,15 @@ impl<'a> System<'a> for Sys {
if let Some(change) = &mut stat.health.last_change { if let Some(change) = &mut stat.health.last_change {
change.1 += f64::from(dt.0); 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)
}
} }
} }
} }

View File

@ -878,34 +878,18 @@ impl Server {
} }
// Give EXP to the client // Give EXP to the client
if let Some(_enemy) = ecs.read_storage::<comp::Body>().get(entity) { if let comp::HealthSource::Attack { by } = dying.cause {
if let comp::HealthSource::Attack { by } = dying.cause { ecs.entity_from_uid(by.into()).map(|attacker| {
ecs.entity_from_uid(by.into()).and_then(|attacker| { let mut stats = ecs.write_storage::<comp::Stats>();
let mut stats = ecs.write_storage::<comp::Stats>(); let entity_stats = stats.get(entity).unwrap().clone();
let attacker_stats = stats.get_mut(attacker).unwrap(); let attacker_stats = stats.get_mut(attacker).unwrap();
// TODO: Discuss whether we should give EXP by Player Killing or not. // 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 attacker_stats.exp.change_by(
// slayed entity's level entity_stats.health.maximum() as f64 / 10.0
attacker_stats.exp.change_current_by(1.0); * entity_stats.level.level() as f64,
);
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::<comp::Player>().get(attacker).cloned()
});
}
} }
entity entity

View File

@ -107,13 +107,9 @@ 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.get_current() / self.stats.exp.get_maximum(); let xp_percentage = self.stats.exp.current() / self.stats.exp.maximum();
let xp_treshold = format!( let xp_treshold = format!("{}/{}", self.stats.exp.current(), self.stats.exp.maximum());
"{}/{}", let level = (self.stats.level.level()).to_string();
self.stats.exp.get_current(),
self.stats.exp.get_maximum()
);
let level = (self.stats.level.get_level()).to_string();
// Frame // Frame
Image::new(self.imgs.window_3) Image::new(self.imgs.window_3)

View File

@ -72,10 +72,10 @@ impl<'a> Widget for Skillbar<'a> {
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event { fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { state, ui, .. } = args; let widget::UpdateArgs { state, ui, .. } = args;
let level = (self.stats.level.get_level()).to_string(); let level = (self.stats.level.level()).to_string();
let next_level = (self.stats.level.get_level() + 1).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 hp_percentage = self.stats.health.current() as f64 / self.stats.health.maximum() as f64;
let mana_percentage = 1.0; let mana_percentage = 1.0;