From a9086b27a0d890aa7c4985cec18aa14a27bfb56a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 8 Sep 2020 22:14:17 +0200 Subject: [PATCH] Do not make healing items deal damage --- common/src/comp/stats.rs | 1 + common/src/sys/combat.rs | 11 ++++++++++- server/src/events/entity_manipulation.rs | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index 2c8faf0e4b..6c61c2577b 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -25,6 +25,7 @@ pub enum HealthSource { Command, LevelUp, Item, + Healing { by: Uid }, Unknown, } diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index e8d83e9847..0081cb6276 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -129,7 +129,7 @@ impl<'a> System<'a> for Sys { damage.modify_damage(block, loadout); } - if damage.healthchange != 0.0 { + if damage.healthchange < 0.0 { server_emitter.emit(ServerEvent::Damage { uid: *uid_b, change: HealthChange { @@ -137,7 +137,16 @@ impl<'a> System<'a> for Sys { cause: HealthSource::Attack { by: *uid }, }, }); + } else if damage.healthchange > 0.0 { + server_emitter.emit(ServerEvent::Damage { + uid: *uid_b, + change: HealthChange { + amount: damage.healthchange as i32, + cause: HealthSource::Healing { by: *uid }, + }, + }); } + if attack.knockback != 0.0 { local_emitter.emit(LocalEvent::ApplyForce { entity: b, diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 18245f77bb..44479d8704 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::Attack { by } | HealthSource::Healing { 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)