diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index 771a8d5b1c..a6c5d189fc 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -6,6 +6,7 @@ use specs_idvs::IDVStorage; pub enum HealthSource { Attack { by: Uid }, // TODO: Implement weapon Suicide, + World, Revive, Command, LevelUp, diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 8d6a072ab6..de3045b0a6 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -1,4 +1,5 @@ use crate::{ + comp::HealthSource, comp::{ ActionState, Body, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Scale, Stats, Vel, Wielding, @@ -41,6 +42,7 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, Pos>, WriteStorage<'a, Vel>, WriteStorage<'a, Ori>, + WriteStorage<'a, Stats>, ); fn run( @@ -56,10 +58,11 @@ impl<'a> System<'a> for Sys { mut positions, mut velocities, mut orientations, + mut stats, ): Self::SystemData, ) { // Apply movement inputs - for (entity, a, scale, _, mut pos, mut vel, mut ori) in ( + for (entity, a, scale, b, mut pos, mut vel, mut ori, mut stat) in ( &entities, &action_states, scales.maybe(), @@ -67,6 +70,7 @@ impl<'a> System<'a> for Sys { &mut positions, &mut velocities, &mut orientations, + &mut stats, ) .join() { @@ -206,6 +210,11 @@ impl<'a> System<'a> for Sys { // When the resolution direction is pointing upwards, we must be on the ground if resolve_dir.z > 0.0 && vel.0.z <= 0.0 { + // Check for fall damage + let falldmg = (vel.0.z / 1.5 + 6.0) as i32; + if falldmg < 0 { + stat.health.change_by(falldmg, HealthSource::World); + } on_ground = true; } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 5251416430..95ca203571 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -82,6 +82,7 @@ widget_ids! { fps_counter, ping, coordinates, + velocity, loaded_distance, // Game Version @@ -127,6 +128,7 @@ pub struct DebugInfo { pub tps: f64, pub ping_ms: f64, pub coordinates: Option, + pub velocity: Option, } pub enum Event { @@ -498,7 +500,7 @@ impl Hud { .font_id(self.fonts.opensans) .font_size(14) .set(self.ids.ping, ui_widgets); - // Players position + // Player's position let coordinates_text = match debug_info.coordinates { Some(coordinates) => format!("Coordinates: {:.1}", coordinates.0), None => "Player has no Pos component".to_owned(), @@ -509,13 +511,24 @@ impl Hud { .font_id(self.fonts.opensans) .font_size(14) .set(self.ids.coordinates, ui_widgets); + // Player's velocity + let velocity_text = match debug_info.velocity { + Some(velocity) => format!("Velocity: {:.1}", velocity.0), + None => "Player has no Vel component".to_owned(), + }; + Text::new(&velocity_text) + .color(TEXT_COLOR) + .down_from(self.ids.coordinates, 5.0) + .font_id(self.fonts.opensans) + .font_size(14) + .set(self.ids.velocity, ui_widgets); // Loaded distance Text::new(&format!( "View distance: {} chunks", client.loaded_distance().unwrap_or(0) )) .color(TEXT_COLOR) - .down_from(self.ids.coordinates, 5.0) + .down_from(self.ids.velocity, 5.0) .font_id(self.fonts.opensans) .font_size(14) .set(self.ids.loaded_distance, ui_widgets); diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index f593086784..36cd3d995f 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -7,7 +7,9 @@ use crate::{ Direction, Error, GlobalState, PlayState, PlayStateResult, }; use client::{self, Client}; -use common::{clock::Clock, comp, comp::Pos, msg::ClientState, terrain::Block, vol::ReadVol}; +use common::{ + clock::Clock, comp, comp::Pos, comp::Vel, msg::ClientState, terrain::Block, vol::ReadVol, +}; use log::error; use specs::Join; use std::{cell::RefCell, rc::Rc, time::Duration}; @@ -287,6 +289,14 @@ impl PlayState for SessionState { .read_storage::() .get(self.client.borrow().entity()) .cloned(), + velocity: self + .client + .borrow() + .state() + .ecs() + .read_storage::() + .get(self.client.borrow().entity()) + .cloned(), }, &self.scene.camera(), );