mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'timo-kill-xp' into 'master'
Give xp depending on max hp and lvl of entity killed See merge request veloren/veloren!400
This commit is contained in:
commit
c9f1a793db
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -878,32 +878,17 @@ impl Server {
|
||||
}
|
||||
|
||||
// Give EXP to the client
|
||||
if let Some(_enemy) = ecs.read_storage::<comp::Body>().get(entity) {
|
||||
let mut stats = ecs.write_storage::<comp::Stats>();
|
||||
if let Some(entity_stats) = stats.get(entity).cloned() {
|
||||
if let comp::HealthSource::Attack { by } = dying.cause {
|
||||
ecs.entity_from_uid(by.into()).and_then(|attacker| {
|
||||
let mut stats = ecs.write_storage::<comp::Stats>();
|
||||
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.entity_from_uid(by.into()).map(|attacker| {
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
ecs.read_storage::<comp::Player>().get(attacker).cloned()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -107,13 +107,9 @@ impl<'a> Widget for CharacterWindow<'a> {
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> 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)
|
||||
|
@ -72,10 +72,10 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user