Fixed crash from changes in explosion code.

This commit is contained in:
Sam 2020-11-04 21:48:59 -06:00
parent a0af315930
commit f69f494524

View File

@ -615,12 +615,7 @@ pub fn handle_explosion(
} }
}, },
RadiusEffect::Entity(target, mut effect) => { RadiusEffect::Entity(target, mut effect) => {
for (entity_b, pos_b, health_b) in ( for (entity_b, pos_b) in (&ecs.entities(), &ecs.read_storage::<comp::Pos>()).join()
&ecs.entities(),
&ecs.read_storage::<comp::Pos>(),
&ecs.read_storage::<comp::Health>(),
)
.join()
{ {
// See if entities are in the same group // See if entities are in the same group
let mut same_group = owner_entity let mut same_group = owner_entity
@ -646,17 +641,25 @@ pub fn handle_explosion(
let distance_squared = pos.distance_squared(pos_b.0); let distance_squared = pos.distance_squared(pos_b.0);
let strength = 1.0 - distance_squared / explosion.radius.powi(2); let strength = 1.0 - distance_squared / explosion.radius.powi(2);
if strength > 0.0 && !health_b.is_dead { if strength > 0.0 {
effect.modify_strength(strength); let is_alive = ecs
server.state().apply_effect(entity_b, effect, owner); .read_storage::<comp::Health>()
// Apply energy change .get(entity_b)
if let Some(owner) = owner_entity { .map_or(false, |h| !h.is_dead);
if let Some(energy) = ecs.write_storage::<comp::Energy>().get_mut(owner)
{ if is_alive {
energy.change_by(EnergyChange { effect.modify_strength(strength);
amount: explosion.energy_regen as i32, server.state().apply_effect(entity_b, effect, owner);
source: comp::EnergySource::HitEnemy, // Apply energy change
}); if let Some(owner) = owner_entity {
if let Some(energy) =
ecs.write_storage::<comp::Energy>().get_mut(owner)
{
energy.change_by(EnergyChange {
amount: explosion.energy_regen as i32,
source: comp::EnergySource::HitEnemy,
});
}
} }
} }
} }