* 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,
LevelUp,
Item,
Healing { by: Uid },
Healing { by: Option<Uid> },
Unknown,
}

View File

@ -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) },
},
});
}

View File

@ -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) => {

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(uid) = state.ecs().read_storage::<Uid>().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::<UidAllocator>()
.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 },
});
}
}
}