From 051a96479858e8dd8d5695c0f7f39fff47568d86 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 8 Oct 2019 18:50:26 +0200 Subject: [PATCH] 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()