From 57c6160b725f9a5bb7efcf99c6e70e9726f3f47c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 9 Sep 2020 21:26:59 +0200 Subject: [PATCH] * Set the KillType to Other for HealthSource::Healing * Extend logic to projectiles and explosions --- common/src/comp/stats.rs | 2 +- common/src/sys/combat.rs | 2 +- common/src/sys/projectile.rs | 28 +++++++++++++++++------- server/src/events/entity_manipulation.rs | 19 +++++++++++----- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index 6c61c2577b..a45f3cfaff 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -25,7 +25,7 @@ pub enum HealthSource { Command, LevelUp, Item, - Healing { by: Uid }, + Healing { by: Option }, Unknown, } diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index 0081cb6276..2495fc8062 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -142,7 +142,7 @@ impl<'a> System<'a> for Sys { uid: *uid_b, change: HealthChange { amount: damage.healthchange as i32, - cause: HealthSource::Healing { by: *uid }, + cause: HealthSource::Healing { by: Some(*uid) }, }, }); } diff --git a/common/src/sys/projectile.rs b/common/src/sys/projectile.rs index 3d70aa18fc..342ee6050d 100644 --- a/common/src/sys/projectile.rs +++ b/common/src/sys/projectile.rs @@ -82,15 +82,27 @@ impl<'a> System<'a> for Sys { } if other != owner_uid { - server_emitter.emit(ServerEvent::Damage { - uid: other, - change: HealthChange { - amount: damage.healthchange as i32, - cause: HealthSource::Projectile { - owner: Some(owner_uid), + if damage.healthchange < 0.0 { + server_emitter.emit(ServerEvent::Damage { + uid: other, + change: HealthChange { + amount: damage.healthchange as i32, + cause: HealthSource::Projectile { + owner: Some(owner_uid), + }, }, - }, - }); + }); + } else if damage.healthchange > 0.0 { + server_emitter.emit(ServerEvent::Damage { + uid: other, + change: HealthChange { + amount: damage.healthchange as i32, + cause: HealthSource::Healing { + by: Some(owner_uid), + }, + }, + }); + } } }, projectile::Effect::Knockback(knockback) => { diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 44479d8704..297c535f75 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -60,7 +60,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc if let Some(_player) = state.ecs().read_storage::().get(entity) { if let Some(uid) = state.ecs().read_storage::().get(entity) { let kill_source = match cause { - HealthSource::Attack { by } | HealthSource::Healing { by } => { + HealthSource::Attack { by } => { // Get attacker entity if let Some(char_entity) = state.ecs().entity_from_uid(by.into()) { // Check if attacker is another player or entity with stats (npc) @@ -135,6 +135,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc | HealthSource::Command | HealthSource::LevelUp | HealthSource::Item + | HealthSource::Healing { by: _ } | HealthSource::Unknown => KillSource::Other, }; state.notify_registered_clients( @@ -450,7 +451,6 @@ pub fn handle_explosion( power, reagent, }); - let owner_entity = owner.and_then(|uid| { ecs.read_resource::() .retrieve_entity_internal(uid.into()) @@ -493,10 +493,17 @@ pub fn handle_explosion( damage.modify_damage(block, loadout); } - stats_b.health.change_by(HealthChange { - amount: damage.healthchange as i32, - cause: HealthSource::Explosion { owner }, - }); + if damage.healthchange < 0.0 { + stats_b.health.change_by(HealthChange { + amount: damage.healthchange as i32, + cause: HealthSource::Explosion { owner }, + }); + } else if damage.healthchange > 0.0 { + stats_b.health.change_by(HealthChange { + amount: damage.healthchange as i32, + cause: HealthSource::Healing { by: owner }, + }); + } } }