mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Get EXP for killing NPCs and Players, properly show EXP bar
This commit is contained in:
parent
b1aace0110
commit
5c84508015
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2769,6 +2769,7 @@ dependencies = [
|
||||
name = "veloren-server"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -56,37 +56,35 @@ impl Exp {
|
||||
}
|
||||
|
||||
pub fn set_current(&mut self, current: f64) {
|
||||
if self.current < self.maximum {
|
||||
self.current = current;
|
||||
}
|
||||
self.current = current;
|
||||
}
|
||||
|
||||
pub fn set_maximum(&mut self, maximum: f64) {
|
||||
self.maximum = maximum;
|
||||
}
|
||||
// TODO: Uncomment when needed
|
||||
// pub fn set_maximum(&mut self, maximum: f64) {
|
||||
// self.maximum = maximum;
|
||||
// }
|
||||
|
||||
pub fn change_current_by(&mut self, current: f64) {
|
||||
if self.current < self.maximum {
|
||||
self.current + current;
|
||||
}
|
||||
self.current = self.current + current;
|
||||
}
|
||||
|
||||
pub fn change_maximum_by(&mut self, maximum: f64) {
|
||||
self.maximum + maximum;
|
||||
self.maximum = self.maximum + maximum;
|
||||
}
|
||||
}
|
||||
|
||||
impl Level {
|
||||
pub fn set_level(&mut self, level: u32) {
|
||||
self.amount = level;
|
||||
}
|
||||
// TODO: Uncomment when needed
|
||||
// pub fn set_level(&mut self, level: u32) {
|
||||
// self.amount = level;
|
||||
// }
|
||||
|
||||
pub fn get_level(&self) -> u32 {
|
||||
self.amount
|
||||
}
|
||||
|
||||
pub fn change_by(&mut self, level: u32) {
|
||||
self.amount + level;
|
||||
self.amount = self.amount + level;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -710,7 +710,7 @@ impl Server {
|
||||
self.clients
|
||||
.notify_registered(ServerMsg::EcsSync(self.state.ecs_mut().next_sync_package()));
|
||||
|
||||
// Sync deaths.
|
||||
// Handle deaths.
|
||||
let ecs = &self.state.ecs();
|
||||
let clients = &mut self.clients;
|
||||
let todo_kill = (&ecs.entities(), &ecs.read_storage::<comp::Dying>())
|
||||
@ -737,6 +737,30 @@ impl Server {
|
||||
clients.notify_registered(ServerMsg::chat(msg));
|
||||
}
|
||||
|
||||
// Give EXP to the client
|
||||
if let Some(_enemy) = ecs.read_storage::<comp::Body>().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::<comp::Stats>();
|
||||
let attacker_stats = stats.get_mut(attacker).unwrap();
|
||||
|
||||
// TODO: Discuss whether we should give EXP by Player Killing or not.
|
||||
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);
|
||||
} else {
|
||||
// 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);
|
||||
};
|
||||
|
||||
ecs.read_storage::<comp::Player>().get(attacker).cloned()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
entity
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
@ -72,10 +72,9 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
let widget::UpdateArgs { state, ui, .. } = args;
|
||||
|
||||
let level = (self.stats.level.get_level()).to_string();
|
||||
let next_level = self.stats.level.get_level() + 1;
|
||||
// TODO: We need a max xp value
|
||||
let xp_percentage = self.stats.exp.get_current();
|
||||
let max_xp = self.stats.exp.get_maximum();
|
||||
let next_level = (self.stats.level.get_level() + 1).to_string();
|
||||
|
||||
let exp_percentage = self.stats.exp.get_current() / self.stats.exp.get_maximum();
|
||||
|
||||
let hp_percentage =
|
||||
self.stats.health.get_current() as f64 / self.stats.health.get_maximum() as f64;
|
||||
@ -94,7 +93,7 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
.mid_bottom_of(ui.window)
|
||||
.set(state.ids.xp_bar, ui);
|
||||
|
||||
Rectangle::fill_with([406.0 * (xp_percentage), 5.0], XP_COLOR) // "W=406*[Exp. %]"
|
||||
Rectangle::fill_with([406.0 * (exp_percentage), 5.0], XP_COLOR) // "W=406*[Exp. %]"
|
||||
.top_left_with_margins_on(state.ids.xp_bar, 5.0, 21.0)
|
||||
.set(state.ids.xp_bar_progress, ui);
|
||||
|
||||
@ -173,7 +172,7 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.level_text, ui);
|
||||
|
||||
Text::new(&next_level.to_string())
|
||||
Text::new(&next_level)
|
||||
.right_from(state.ids.xp_bar, -15.0)
|
||||
.font_size(10)
|
||||
.color(TEXT_COLOR)
|
||||
|
Loading…
Reference in New Issue
Block a user