* Set the KillType to Other for HealthSource::Healing

* Extend logic to projectiles and explosions
This commit is contained in:
Matthew Martin 2020-09-09 21:26:59 +02:00
parent a9086b27a0
commit 57c6160b72
4 changed files with 35 additions and 16 deletions

View File

@ -25,7 +25,7 @@ pub enum HealthSource {
Command, Command,
LevelUp, LevelUp,
Item, Item,
Healing { by: Uid }, Healing { by: Option<Uid> },
Unknown, Unknown,
} }

View File

@ -142,7 +142,7 @@ impl<'a> System<'a> for Sys {
uid: *uid_b, uid: *uid_b,
change: HealthChange { change: HealthChange {
amount: damage.healthchange as i32, amount: damage.healthchange as i32,
cause: HealthSource::Healing { by: *uid }, cause: HealthSource::Healing { by: Some(*uid) },
}, },
}); });
} }

View File

@ -82,15 +82,27 @@ impl<'a> System<'a> for Sys {
} }
if other != owner_uid { if other != owner_uid {
server_emitter.emit(ServerEvent::Damage { if damage.healthchange < 0.0 {
uid: other, server_emitter.emit(ServerEvent::Damage {
change: HealthChange { uid: other,
amount: damage.healthchange as i32, change: HealthChange {
cause: HealthSource::Projectile { amount: damage.healthchange as i32,
owner: Some(owner_uid), 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) => { projectile::Effect::Knockback(knockback) => {

View File

@ -60,7 +60,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc
if let Some(_player) = state.ecs().read_storage::<Player>().get(entity) { if let Some(_player) = state.ecs().read_storage::<Player>().get(entity) {
if let Some(uid) = state.ecs().read_storage::<Uid>().get(entity) { if let Some(uid) = state.ecs().read_storage::<Uid>().get(entity) {
let kill_source = match cause { let kill_source = match cause {
HealthSource::Attack { by } | HealthSource::Healing { by } => { HealthSource::Attack { by } => {
// Get attacker entity // Get attacker entity
if let Some(char_entity) = state.ecs().entity_from_uid(by.into()) { if let Some(char_entity) = state.ecs().entity_from_uid(by.into()) {
// Check if attacker is another player or entity with stats (npc) // 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::Command
| HealthSource::LevelUp | HealthSource::LevelUp
| HealthSource::Item | HealthSource::Item
| HealthSource::Healing { by: _ }
| HealthSource::Unknown => KillSource::Other, | HealthSource::Unknown => KillSource::Other,
}; };
state.notify_registered_clients( state.notify_registered_clients(
@ -450,7 +451,6 @@ pub fn handle_explosion(
power, power,
reagent, reagent,
}); });
let owner_entity = owner.and_then(|uid| { let owner_entity = owner.and_then(|uid| {
ecs.read_resource::<UidAllocator>() ecs.read_resource::<UidAllocator>()
.retrieve_entity_internal(uid.into()) .retrieve_entity_internal(uid.into())
@ -493,10 +493,17 @@ pub fn handle_explosion(
damage.modify_damage(block, loadout); damage.modify_damage(block, loadout);
} }
stats_b.health.change_by(HealthChange { if damage.healthchange < 0.0 {
amount: damage.healthchange as i32, stats_b.health.change_by(HealthChange {
cause: HealthSource::Explosion { owner }, 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 },
});
}
} }
} }