From 43f75f2f545145e941a5101eaa5c9a393f3e7781 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 5 Jul 2020 15:06:01 +0100 Subject: [PATCH] Removed bomb timeout --- CHANGELOG.md | 2 +- common/src/comp/misc.rs | 6 +----- common/src/comp/phys.rs | 9 +++++++++ common/src/sys/phys.rs | 6 +----- common/src/sys/stats.rs | 14 +++----------- server/src/events/inventory_manip.rs | 17 ++++++----------- server/src/sys/object.rs | 11 ++++------- voxygen/src/hud/overhead.rs | 5 +---- world/src/site/settlement/mod.rs | 5 +++-- 9 files changed, 29 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59e3321783..de98e44886 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added new animals - Better pathfinding - Bombs -- Training dummies +- Training dummy items ### Changed diff --git a/common/src/comp/misc.rs b/common/src/comp/misc.rs index 22951df4b8..5135ec67d7 100644 --- a/common/src/comp/misc.rs +++ b/common/src/comp/misc.rs @@ -1,14 +1,10 @@ use crate::sync::Uid; use specs::Component; use specs_idvs::IDVStorage; -use std::time::Duration; #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum Object { - Bomb { - timeout: Duration, - owner: Option, - }, + Bomb { owner: Option }, } impl Component for Object { diff --git a/common/src/comp/phys.rs b/common/src/comp/phys.rs index 01fe96dc46..61ceaaaf90 100644 --- a/common/src/comp/phys.rs +++ b/common/src/comp/phys.rs @@ -78,6 +78,15 @@ pub struct PhysicsState { pub in_fluid: bool, } +impl PhysicsState { + pub fn on_surface(&self) -> Option> { + self.on_ground + .then_some(-Vec3::unit_z()) + .or_else(|| self.on_ceiling.then_some(Vec3::unit_z())) + .or(self.on_wall) + } +} + impl Component for PhysicsState { type Storage = FlaggedStorage>; } diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index b5a1236d6e..d57ef92df1 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -96,11 +96,7 @@ impl<'a> System<'a> for Sys { { let mut physics_state = physics_states.get(entity).cloned().unwrap_or_default(); - if sticky.is_some() - && (physics_state.on_ground - || physics_state.on_ceiling - || physics_state.on_wall.is_some()) - { + if sticky.is_some() && physics_state.on_surface().is_some() { vel.0 = Vec3::zero(); continue; } diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index 28045e8313..2335c64fce 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -34,12 +34,7 @@ impl<'a> System<'a> for Sys { stats.set_event_emission(true); // Update stats - for (entity, mut stats) in ( - &entities, - &mut stats.restrict_mut(), - ) - .join() - { + for (entity, mut stats) in (&entities, &mut stats.restrict_mut()).join() { let (set_dead, level_up) = { let stat = stats.get_unchecked(); ( @@ -74,11 +69,8 @@ impl<'a> System<'a> for Sys { } // Update energies - for (character_state, mut energy) in ( - &character_states, - &mut energies.restrict_mut(), - ) - .join() + for (character_state, mut energy) in + (&character_states, &mut energies.restrict_mut()).join() { match character_state { // Accelerate recharging energy. diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index 4254e196f4..0d6c37839d 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -11,7 +11,6 @@ use common::{ }; use rand::Rng; use specs::{join::Join, world::WorldExt, Builder, Entity as EcsEntity, WriteStorage}; -use std::time::Duration; use tracing::{debug, error}; use vek::Vec3; @@ -177,7 +176,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv .get(entity) .copied() .unwrap_or_default(), - kind.clone(), + *kind, )); } Some(comp::InventoryUpdateEvent::Used) @@ -363,17 +362,13 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv match kind { item::Throwable::Bomb => { - new_entity = new_entity.with(comp::Object::Bomb { - timeout: Duration::from_secs_f32(1.0), - owner: uid, - }); + new_entity = new_entity.with(comp::Object::Bomb { owner: uid }); }, item::Throwable::TrainingDummy => { - new_entity = new_entity - .with(comp::Stats::new( - "Training Dummy".to_string(), - comp::object::Body::TrainingDummy.into(), - )); + new_entity = new_entity.with(comp::Stats::new( + "Training Dummy".to_string(), + comp::object::Body::TrainingDummy.into(), + )); }, }; diff --git a/server/src/sys/object.rs b/server/src/sys/object.rs index 3becae6218..be986f8e6e 100644 --- a/server/src/sys/object.rs +++ b/server/src/sys/object.rs @@ -4,7 +4,6 @@ use common::{ state::DeltaTime, }; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; -use std::time::Duration; /// This system is responsible for handling misc object behaviours pub struct Sys; @@ -21,19 +20,17 @@ impl<'a> System<'a> for Sys { fn run( &mut self, - (entities, dt, server_bus, positions, physics_states, mut objects): Self::SystemData, + (entities, _dt, server_bus, positions, physics_states, mut objects): Self::SystemData, ) { let mut server_emitter = server_bus.emitter(); // Objects - for (entity, pos, _physics, object) in + for (entity, pos, physics, object) in (&entities, &positions, &physics_states, &mut objects).join() { match object { - Object::Bomb { owner, timeout } => { - if let Some(t) = timeout.checked_sub(Duration::from_secs_f32(dt.0)) { - *timeout = t; - } else { + Object::Bomb { owner } => { + if physics.on_surface().is_some() { server_emitter.emit(ServerEvent::Destroy { entity, cause: HealthSource::Suicide, diff --git a/voxygen/src/hud/overhead.rs b/voxygen/src/hud/overhead.rs index da74395dd2..ad551d7281 100644 --- a/voxygen/src/hud/overhead.rs +++ b/voxygen/src/hud/overhead.rs @@ -330,10 +330,7 @@ impl<'a> Widget for Overhead<'a> { let energy_factor = energy.current() as f64 / energy.maximum() as f64; Rectangle::fill_with( - [ - 72.0 * energy_factor * BARSIZE, - MANA_BAR_HEIGHT, - ], + [72.0 * energy_factor * BARSIZE, MANA_BAR_HEIGHT], MANA_COLOR, ) .x_y( diff --git a/world/src/site/settlement/mod.rs b/world/src/site/settlement/mod.rs index 546f81215b..7571df7aab 100644 --- a/world/src/site/settlement/mod.rs +++ b/world/src/site/settlement/mod.rs @@ -10,7 +10,7 @@ use crate::{ use common::{ assets, astar::Astar, - comp::{self, bird_medium, humanoid, quadruped_small, object}, + comp::{self, bird_medium, humanoid, object, quadruped_small}, generation::{ChunkSupplement, EntityInfo}, path::Path, spiral::Spiral2d, @@ -789,7 +789,8 @@ impl Settlement { && RandomField::new(self.seed).chance(Vec3::from(wpos2d), 1.0 / (50.0 * 50.0)) { let is_human: bool; - let is_dummy = RandomField::new(self.seed + 1).chance(Vec3::from(wpos2d), 1.0 / 15.0); + let is_dummy = + RandomField::new(self.seed + 1).chance(Vec3::from(wpos2d), 1.0 / 15.0); let entity = EntityInfo::at(entity_wpos) .with_body(match rng.gen_range(0, 4) { _ if is_dummy => {