From 0f244bf84bb0a90b5926ebcff449efa3a3f9d4b2 Mon Sep 17 00:00:00 2001 From: jiminycrick Date: Wed, 16 Dec 2020 16:14:14 -0800 Subject: [PATCH] Made stunned state invulnerable to poise damage Fixing silly error for comp creation --- common/src/comp/poise.rs | 1 - common/src/states/behavior.rs | 4 ++-- common/sys/src/character_behavior.rs | 2 +- common/sys/src/stats.rs | 11 ++++++++--- server/src/events/entity_manipulation.rs | 10 +++++++--- server/src/state_ext.rs | 17 +++++++++++++---- server/src/sys/sentinel.rs | 6 ++++++ 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/common/src/comp/poise.rs b/common/src/comp/poise.rs index 7d9962e317..8e5e05c8a5 100644 --- a/common/src/comp/poise.rs +++ b/common/src/comp/poise.rs @@ -173,7 +173,6 @@ impl Poise { } pub fn change_by(&mut self, change: PoiseChange, impulse: Vec3) { - println!("Poise change: {:?}", change); self.current = ((self.current as i32 + change.amount).max(0) as u32).min(self.maximum); self.knockback = impulse; self.last_change = (0.0, PoiseChange { diff --git a/common/src/states/behavior.rs b/common/src/states/behavior.rs index 0ee227e3fe..775b494b3b 100644 --- a/common/src/states/behavior.rs +++ b/common/src/states/behavior.rs @@ -51,7 +51,7 @@ pub struct JoinData<'a> { pub controller: &'a Controller, pub inputs: &'a ControllerInputs, pub health: &'a Health, - pub poise: Option<&'a Poise>, + pub poise: &'a Poise, pub energy: &'a Energy, pub inventory: &'a Inventory, pub body: &'a Body, @@ -81,7 +81,7 @@ pub type JoinTuple<'a> = ( RestrictedMut<'a, Inventory>, &'a mut Controller, &'a Health, - Option<&'a Poise>, + &'a Poise, &'a Body, &'a PhysicsState, Option<&'a Attacking>, diff --git a/common/sys/src/character_behavior.rs b/common/sys/src/character_behavior.rs index c86b0a45e9..b5c17d1fac 100644 --- a/common/sys/src/character_behavior.rs +++ b/common/sys/src/character_behavior.rs @@ -120,7 +120,7 @@ impl<'a> System<'a> for Sys { &mut inventories.restrict_mut(), &mut controllers, &healths, - poises.maybe(), + &poises, &bodies, &physics_states, attacking_storage.maybe(), diff --git a/common/sys/src/stats.rs b/common/sys/src/stats.rs index e72dd5ccb1..68ede0ae91 100644 --- a/common/sys/src/stats.rs +++ b/common/sys/src/stats.rs @@ -190,7 +190,6 @@ impl<'a> System<'a> for Sys { entity, impulse: 5.0 * poise.knockback(), }); - //handle_knockback(server, entity, 5.0 * knockback_dir); }, PoiseState::Dazed => { poise.reset(); @@ -203,7 +202,10 @@ impl<'a> System<'a> for Sys { stage_section: common::states::utils::StageSection::Buildup, was_wielded, }); - //handle_knockback(server, entity, 10.0 * knockback_dir); + server_event_emitter.emit(ServerEvent::Knockback { + entity, + impulse: 10.0 * poise.knockback(), + }); }, PoiseState::KnockedDown => { poise.reset(); @@ -216,7 +218,10 @@ impl<'a> System<'a> for Sys { stage_section: common::states::utils::StageSection::Buildup, was_wielded, }); - //handle_knockback(server, entity, 10.0 * knockback_dir); + server_event_emitter.emit(ServerEvent::Knockback { + entity, + impulse: 10.0 * poise.knockback(), + }); }, } } diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 6f14849597..a3be99aaf4 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -12,7 +12,7 @@ use common::{ combat, comp::{ self, aura, buff, - chat::{KillSource, KillType}, + chat::{KillSource, KillType}, CharacterState, object, Alignment, Body, Energy, EnergyChange, Group, Health, HealthChange, HealthSource, Inventory, Item, Player, Poise, PoiseChange, PoiseSource, Pos, Stats, }, @@ -41,8 +41,12 @@ pub fn handle_poise( knockback_dir: Vec3, ) { let ecs = &server.state.ecs(); - if let Some(poise) = ecs.write_storage::().get_mut(entity) { - poise.change_by(change, knockback_dir); + if let Some(character_state) = ecs.read_storage::().get(entity) { + if !character_state.is_stunned() { + if let Some(poise) = ecs.write_storage::().get_mut(entity) { + poise.change_by(change, knockback_dir); + } + } } } diff --git a/server/src/state_ext.rs b/server/src/state_ext.rs index f5de034ca6..7b1b047e4f 100644 --- a/server/src/state_ext.rs +++ b/server/src/state_ext.rs @@ -99,10 +99,19 @@ impl StateExt for State { Effect::PoiseChange(poise_damage) => { let loadouts = self.ecs().read_storage::(); let change = poise_damage.modify_poise_damage(loadouts.get(entity)); - self.ecs() - .write_storage::() - .get_mut(entity) - .map(|poise| poise.change_by(change, Vec3::zero())); + // Check to make sure the entity is not already stunned + if let Some(character_state) = self + .ecs() + .read_storage::() + .get(entity) + { + if !character_state.is_stunned() { + self.ecs() + .write_storage::() + .get_mut(entity) + .map(|poise| poise.change_by(change, Vec3::zero())); + } + } }, Effect::Buff(buff) => { self.ecs() diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index 9bfe4b6451..01ffd0b25d 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -108,6 +108,10 @@ impl<'a> TrackedComps<'a> { .get(entity) .cloned() .map(|c| comps.push(c.into())); + self.poise + .get(entity) + .cloned() + .map(|c| comps.push(c.into())); self.can_build .get(entity) .cloned() @@ -214,6 +218,7 @@ impl<'a> ReadTrackers<'a> { .with_component(&comps.uid, &*self.auras, &comps.auras, filter) .with_component(&comps.uid, &*self.energy, &comps.energy, filter) .with_component(&comps.uid, &*self.health, &comps.health, filter) + .with_component(&comps.uid, &*self.poise, &comps.poise, filter) .with_component(&comps.uid, &*self.can_build, &comps.can_build, filter) .with_component( &comps.uid, @@ -282,6 +287,7 @@ fn record_changes(comps: &TrackedComps, trackers: &mut WriteTrackers) { trackers.auras.record_changes(&comps.auras); trackers.energy.record_changes(&comps.energy); trackers.health.record_changes(&comps.health); + trackers.poise.record_changes(&comps.poise); trackers.can_build.record_changes(&comps.can_build); trackers.light_emitter.record_changes(&comps.light_emitter); trackers.item.record_changes(&comps.item);