mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
fix: server side fall damage
This avoids flickering health
This commit is contained in:
parent
b20cf6c62b
commit
051a964798
@ -15,10 +15,6 @@ pub enum LocalEvent {
|
||||
entity: EcsEntity,
|
||||
vel: Vec3<f32>,
|
||||
},
|
||||
LandOnGround {
|
||||
entity: EcsEntity,
|
||||
vel: Vec3<f32>,
|
||||
},
|
||||
}
|
||||
|
||||
pub enum ServerEvent {
|
||||
@ -41,6 +37,10 @@ pub enum ServerEvent {
|
||||
dir: Vec3<f32>,
|
||||
projectile: comp::Projectile,
|
||||
},
|
||||
LandOnGround {
|
||||
entity: EcsEntity,
|
||||
vel: Vec3<f32>,
|
||||
},
|
||||
Mount(EcsEntity, EcsEntity),
|
||||
Unmount(EcsEntity),
|
||||
}
|
||||
|
@ -406,17 +406,6 @@ impl State {
|
||||
let mut velocities = self.ecs.write_storage::<comp::Vel>();
|
||||
let mut controllers = self.ecs.write_storage::<comp::Controller>();
|
||||
match event {
|
||||
LocalEvent::LandOnGround { entity, vel } => {
|
||||
if vel.z <= -20.0 {
|
||||
if let Some(stats) = self.ecs.write_storage::<comp::Stats>().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;
|
||||
|
@ -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<LocalEvent>>,
|
||||
Read<'a, EventBus<ServerEvent>>,
|
||||
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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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::<comp::Stats>()
|
||||
.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()
|
||||
|
Loading…
Reference in New Issue
Block a user