From ce3921c345746442fe5c0a6eb384a5b6f8c6ab33 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 8 Oct 2019 18:12:08 +0200 Subject: [PATCH 1/6] fix: fix level and health distribution --- common/src/comp/stats.rs | 20 +++++++++++++------- common/src/sys/stats.rs | 2 +- server/src/lib.rs | 16 ++++++---------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index bc1a9de487..09ebc940a1 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -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) -> 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 { diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index 6a6ebc8bf7..d1f503d456 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -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) } diff --git a/server/src/lib.rs b/server/src/lib.rs index 82809edb3f..b78915c31e 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -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::() < 0.8 { @@ -581,10 +576,11 @@ impl Server { ); body = comp::Body::Humanoid(comp::humanoid::Body::random()); } - stats = stats.with_max_health(500 + rand::random::() % 400); + stats.level.set_level(rand::thread_rng().gen_range(10, 50)); scale = 2.5 + rand::random::(); } + stats.update_max_hp(); self.create_npc(comp::Pos(npc.pos), stats, body) .with(comp::Agent::enemy()) .with(comp::Scale(scale)) From 462bb50879cf113deb7aebcdcd2e1c30801c175e Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 8 Oct 2019 18:15:18 +0200 Subject: [PATCH 2/6] fix: spawnpoint nearer to the floor We can change this back when we have a proper spawn location system or random seeds. --- server/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/lib.rs b/server/src/lib.rs index b78915c31e..56c669c1ad 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -104,7 +104,7 @@ impl Server { let mut state = State::default(); state .ecs_mut() - .add_resource(SpawnPoint(Vec3::new(16_384.0, 16_384.0, 512.0))); + .add_resource(SpawnPoint(Vec3::new(16_384.0, 16_384.0, 190.0))); state .ecs_mut() .add_resource(EventBus::::default()); From 7d0efbcfd0546d7208589afee224d718a34972ba Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 8 Oct 2019 18:38:20 +0200 Subject: [PATCH 3/6] fix: set minimum speed for fall damage and balance it --- common/src/state.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/common/src/state.rs b/common/src/state.rs index cab489eb5b..956d7dfbaa 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -407,10 +407,13 @@ impl State { let mut controllers = self.ecs.write_storage::(); match event { LocalEvent::LandOnGround { entity, vel } => { - if let Some(stats) = self.ecs.write_storage::().get_mut(entity) { - let falldmg = (vel.z / 1.5 + 10.0) as i32; - if falldmg < 0 { - stats.health.change_by(falldmg, comp::HealthSource::World); + if vel.z <= -20.0 { + if let Some(stats) = self.ecs.write_storage::().get_mut(entity) + { + let falldmg = (vel.z / 5.0) as i32; + if falldmg < 0 { + stats.health.change_by(falldmg, comp::HealthSource::World); + } } } } From 8680648ac6afa055b6fe291a00143b56ca0ff3b6 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 8 Oct 2019 18:50:26 +0200 Subject: [PATCH 4/6] fix: server side fall damage This avoids flickering health --- common/src/event.rs | 8 ++++---- common/src/state.rs | 11 ----------- common/src/sys/phys.rs | 6 +++--- server/src/lib.rs | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/common/src/event.rs b/common/src/event.rs index 623a546057..e86bc8ab93 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -15,10 +15,6 @@ pub enum LocalEvent { entity: EcsEntity, vel: Vec3, }, - LandOnGround { - entity: EcsEntity, - vel: Vec3, - }, } pub enum ServerEvent { @@ -41,6 +37,10 @@ pub enum ServerEvent { dir: Vec3, projectile: comp::Projectile, }, + LandOnGround { + entity: EcsEntity, + vel: Vec3, + }, Mount(EcsEntity, EcsEntity), Unmount(EcsEntity), } diff --git a/common/src/state.rs b/common/src/state.rs index 956d7dfbaa..bab2f8ade6 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -406,17 +406,6 @@ impl State { let mut velocities = self.ecs.write_storage::(); let mut controllers = self.ecs.write_storage::(); match event { - LocalEvent::LandOnGround { entity, vel } => { - if vel.z <= -20.0 { - if let Some(stats) = self.ecs.write_storage::().get_mut(entity) - { - let falldmg = (vel.z / 5.0) as i32; - if falldmg < 0 { - stats.health.change_by(falldmg, comp::HealthSource::World); - } - } - } - } LocalEvent::Jump(entity) => { if let Some(vel) = velocities.get_mut(entity) { vel.0.z = HUMANOID_JUMP_ACCEL; diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 6fc9b8a29f..0d5f656ffa 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -1,7 +1,7 @@ use { crate::{ comp::{Body, Mass, Mounting, Ori, PhysicsState, Pos, Scale, Sticky, Vel}, - event::{EventBus, LocalEvent}, + event::{EventBus, ServerEvent}, state::DeltaTime, terrain::{Block, TerrainGrid}, vol::ReadVol, @@ -45,7 +45,7 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Uid>, ReadExpect<'a, TerrainGrid>, Read<'a, DeltaTime>, - Read<'a, EventBus>, + Read<'a, EventBus>, ReadStorage<'a, Scale>, ReadStorage<'a, Sticky>, ReadStorage<'a, Mass>, @@ -245,7 +245,7 @@ impl<'a> System<'a> for Sys { on_ground = true; if !was_on_ground { - event_emitter.emit(LocalEvent::LandOnGround { entity, vel: vel.0 }); + event_emitter.emit(ServerEvent::LandOnGround { entity, vel: vel.0 }); } } diff --git a/server/src/lib.rs b/server/src/lib.rs index 56c669c1ad..7153beb21a 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -399,6 +399,22 @@ impl Server { .insert(entity, comp::ForceUpdate); } } + + ServerEvent::LandOnGround { entity, vel } => { + if vel.z <= -25.0 { + if let Some(stats) = state + .ecs_mut() + .write_storage::() + .get_mut(entity) + { + let falldmg = (vel.z / 5.0) as i32; + if falldmg < 0 { + stats.health.change_by(falldmg, comp::HealthSource::World); + } + } + } + } + ServerEvent::Mount(mounter, mountee) => { if state .ecs() From e33af5e29a23afad0b4691f297662e73d578aa8c Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 8 Oct 2019 20:36:46 +0200 Subject: [PATCH 5/6] fix: tweek hp --- common/src/comp/stats.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index 09ebc940a1..c5c7e29f1d 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -169,7 +169,7 @@ impl Stats { // TODO: Delete this once stat points will be a thing pub fn update_max_hp(&mut self) { - self.health.set_maximum(22 * self.level.amount); + self.health.set_maximum(42 * self.level.amount); } } From 54d71848d2a7bcd83eb183a7a21ad395d24597e3 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 8 Oct 2019 21:19:16 +0200 Subject: [PATCH 6/6] fix: blocking now ends in wielded This makes blocking more viable because while blocking you can wait for the enemy to attack and then quickly exit the block and attack yourself. --- common/src/sys/controller.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/sys/controller.rs b/common/src/sys/controller.rs index be4c2b8b46..ff05dadde9 100644 --- a/common/src/sys/controller.rs +++ b/common/src/sys/controller.rs @@ -177,13 +177,15 @@ impl<'a> System<'a> for Sys { // Block if controller.secondary && (character.movement == Stand || character.movement == Run) - && (character.action == Idle || character.action.is_wield()) + && character.action.is_wield() { character.action = Block { time_left: Duration::from_secs(5), }; } else if !controller.secondary && character.action.is_block() { - character.action = Idle; + character.action = Wield { + time_left: Duration::default(), + }; } } Some(Item::Debug(item::Debug::Boost)) => {