From 6c75ad6ef8f7b2805028b39a62036822773035d4 Mon Sep 17 00:00:00 2001 From: socksonme Date: Sat, 29 Jan 2022 21:03:04 +0200 Subject: [PATCH] Code quality changes and comments --- common/src/combat.rs | 4 +--- common/src/comp/health.rs | 8 ++++---- common/systems/src/shockwave.rs | 1 - server/src/events/entity_manipulation.rs | 3 ++- voxygen/src/audio/sfx/mod.rs | 1 + voxygen/src/hud/mod.rs | 12 ++++++------ 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/common/src/combat.rs b/common/src/combat.rs index 4ad47760b1..bed6ab1f87 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -212,8 +212,6 @@ impl Attack { let is_crit = thread_rng().gen::() < self.crit_chance; let mut is_applied = false; let mut accumulated_damage = 0.0; - // TODO: Issue with shotgun ability - // TODO: Add instance number to AttackDamage? for damage in self .damages .iter() @@ -636,6 +634,7 @@ pub struct AttackDamage { damage: Damage, target: Option, effects: Vec, + /// A random ID, used to group up attacks instance: u64, } @@ -741,7 +740,6 @@ impl From> for DamageContributor { #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] pub enum DamageSource { - // Could be used to separate DOTs? Buff(BuffKind), Melee, Projectile, diff --git a/common/src/comp/health.rs b/common/src/comp/health.rs index 898f26daef..61e898f855 100644 --- a/common/src/comp/health.rs +++ b/common/src/comp/health.rs @@ -29,10 +29,10 @@ pub struct HealthChange { /// couldn't have been a crit) pub crit: Option, pub crit_mult: f32, - /// A random instance ID given to every health change - /// Note: Two or more changes could have the same instance number, if they - /// came from the same attack (for example - the extra damage caused by - /// slashing weapons) + /// A random ID, used to group up health changes + // Note: Two or more changes could have the same instance number, if they + // came from the same attack (for example - the extra damage caused by + // slashing weapons) pub instance: u64, } diff --git a/common/systems/src/shockwave.rs b/common/systems/src/shockwave.rs index cec9eab99a..f0ad8268b3 100644 --- a/common/systems/src/shockwave.rs +++ b/common/systems/src/shockwave.rs @@ -128,7 +128,6 @@ impl<'a> System<'a> for Sys { // Might make this more nuanced if shockwaves are used for non damage effects let group = shockwave_owner.and_then(|e| read_data.groups.get(e)); - // TODO: Join counter later? // Go through all other effectable entities for (target, uid_b, pos_b, health_b, body_b, physics_state_b) in ( &read_data.entities, diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index c1837d5d73..f1dcba1818 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -82,6 +82,8 @@ pub fn handle_health_change(server: &Server, entity: EcsEntity, change: HealthCh ecs.read_storage::().get(entity), ecs.read_storage::().get(entity), ) { + // If the absolute health change amount was greater than the health epsilon, + // push a new Damage outcome if changed { outcomes.push(Outcome::Damage { pos: pos.0, @@ -863,7 +865,6 @@ pub fn handle_explosion(server: &Server, pos: Vec3, explosion: Explosion, o } }, RadiusEffect::Attack(attack) => { - // TODO: Join counter later? let energies = &ecs.read_storage::(); let combos = &ecs.read_storage::(); let inventories = &ecs.read_storage::(); diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index f2133d8272..c1fef7b9ef 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -515,6 +515,7 @@ impl SfxMgr { ); }, Outcome::Damage { pos, info, .. } => { + // Don't emit sound effects from positive damage (healing) if info.amount < Health::HEALTH_EPSILON { let sfx_trigger_item = triggers.get_key_value(&SfxEvent::Damage); audio.emit_sfx(sfx_trigger_item, *pos, Some(1.5), false); diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index fdbc5bfa3a..51dbd2fa6c 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -4686,18 +4686,17 @@ impl Hud { let last_floater = if info.amount < Health::HEALTH_EPSILON { floater_list.floaters.iter_mut().rev().find(|f| { f.info.amount < Health::HEALTH_EPSILON - && info.crit.map_or(f.info.crit.unwrap_or(false), |_| { - !f.info.crit.unwrap_or(false) - }) + && info.crit.unwrap_or(false) + == f.info.crit.unwrap_or(false) }) } else { floater_list.floaters.iter_mut().rev().find(|f| { f.info.amount > Health::HEALTH_EPSILON - && info.crit.map_or(f.info.crit.unwrap_or(false), |_| { - !f.info.crit.unwrap_or(false) - }) + && info.crit.unwrap_or(false) + == f.info.crit.unwrap_or(false) }) }; + dbg!(&last_floater); match last_floater { Some(f) @@ -4711,6 +4710,7 @@ impl Hud { f.info.crit = Some(f.info.crit.unwrap_or(false) || info.crit.unwrap_or(false)); }, _ => { + dbg!(&info.amount); floater_list.floaters.push(HpFloater { timer: 0.0, info: *info,