diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index 2c8faf0e4b..a45f3cfaff 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: Option }, Unknown, } diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index e8d83e9847..2495fc8062 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: Some(*uid) }, + }, + }); } + if attack.knockback != 0.0 { local_emitter.emit(LocalEvent::ApplyForce { entity: b, 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 18245f77bb..297c535f75 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -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 }, + }); + } } }