Make enemies spawn with different levels

This commit is contained in:
Piotr Korgól 2019-10-04 18:07:26 +02:00
parent 152efaee3b
commit 9e10c8b700
2 changed files with 15 additions and 4 deletions

View File

@ -12,6 +12,7 @@ pub enum HealthSource {
Command,
LevelUp,
Item,
Creation,
Unknown,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
@ -133,10 +134,9 @@ impl Exp {
}
impl Level {
// TODO: Uncomment when needed
// pub fn set_level(&mut self, level: u32) {
// self.amount = level;
// }
pub fn set_level(&mut self, level: u32) {
self.amount = level;
}
pub fn level(&self) -> u32 {
self.amount
@ -167,6 +167,11 @@ impl Stats {
.set_to(self.health.maximum(), HealthSource::Revive);
self.is_dead = false;
}
// TODO: Delet this once stat points will be a thing
pub fn level_hp_bonus(&mut self, level: u32) {
self.health.set_maximum((10 * level) / 2);
}
}
impl Stats {

View File

@ -560,6 +560,12 @@ 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.level_hp_bonus(stats.level.level());
}
if npc.boss {
if rand::random::<f32>() < 0.8 {
stats = comp::Stats::new(