fix: fix level and health distribution

This commit is contained in:
timokoesters 2019-10-08 18:12:08 +02:00
parent 05cecf5ee2
commit 4e87f125a2
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
3 changed files with 20 additions and 18 deletions

View File

@ -168,19 +168,18 @@ impl Stats {
}
// TODO: Delete this once stat points will be a thing
pub fn update_hp_bonus(&mut self, level: u32) {
self.health
.set_maximum(self.health.maximum() + (10 * level) / 2);
pub fn update_max_hp(&mut self) {
self.health.set_maximum(22 * self.level.amount);
}
}
impl Stats {
pub fn new(name: String, main: Option<comp::Item>) -> Self {
Self {
let mut stats = Self {
name,
health: Health {
current: 100,
maximum: 100,
current: 0,
maximum: 0,
last_change: None,
},
level: Level { amount: 1 },
@ -198,7 +197,14 @@ impl Stats {
alt: None,
},
is_dead: false,
}
};
stats.update_max_hp();
stats
.health
.set_to(stats.health.maximum(), HealthSource::Revive);
stats
}
pub fn with_max_health(mut self, amount: u32) -> Self {

View File

@ -45,7 +45,7 @@ impl<'a> System<'a> for Sys {
stat.exp.change_maximum_by(25);
stat.level.change_by(1);
}
stat.update_hp_bonus(stat.level.level());
stat.update_max_hp();
stat.health
.set_to(stat.health.maximum(), HealthSource::LevelUp)
}

View File

@ -357,11 +357,9 @@ impl Server {
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)
as i64,
);
attacker_stats
.exp
.change_by((entity_stats.level.level() * 10) as i64);
}
});
}
@ -565,10 +563,7 @@ impl Server {
let mut scale = 1.0;
// TODO: Remove this and implement scaling or level depending on stuff like species instead
stats.level.set_level(rand::thread_rng().gen_range(1, 20));
if stats.level.level() > 1 {
stats.update_hp_bonus(stats.level.level());
}
stats.level.set_level(rand::thread_rng().gen_range(1, 3));
if npc.boss {
if rand::random::<f32>() < 0.8 {
@ -581,10 +576,11 @@ impl Server {
);
body = comp::Body::Humanoid(comp::humanoid::Body::random());
}
stats = stats.with_max_health(500 + rand::random::<u32>() % 400);
stats.level.set_level(rand::thread_rng().gen_range(10, 50));
scale = 2.5 + rand::random::<f32>();
}
stats.update_max_hp();
self.create_npc(comp::Pos(npc.pos), stats, body)
.with(comp::Agent::enemy())
.with(comp::Scale(scale))