diff --git a/server/src/lib.rs b/server/src/lib.rs index 0be77d38d9..52c7fc7cd4 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -243,6 +243,8 @@ impl Server { let state = &mut self.state; let clients = &mut self.clients; + let mut todo_remove = None; + match event { ServerEvent::Explosion { pos, radius } => { const RAYS: usize = 500; @@ -306,23 +308,21 @@ impl Server { clients.notify_registered(ServerMsg::kill(msg)); } - { - // Give EXP to the client - let mut stats = ecs.write_storage::(); + // Give EXP to the client + let mut stats = ecs.write_storage::(); - if let Some(entity_stats) = stats.get(entity).cloned() { - if let comp::HealthSource::Attack { by } = cause { - ecs.entity_from_uid(by.into()).map(|attacker| { - if let Some(attacker_stats) = stats.get_mut(attacker) { - // TODO: Discuss whether we should give EXP by Player Killing or not. - attacker_stats.exp.change_by( - (entity_stats.health.maximum() as f64 / 10.0 - + entity_stats.level.level() as f64 * 10.0) - as i64, - ); - } - }); - } + if let Some(entity_stats) = stats.get(entity).cloned() { + if let comp::HealthSource::Attack { by } = cause { + ecs.entity_from_uid(by.into()).map(|attacker| { + if let Some(attacker_stats) = stats.get_mut(attacker) { + // TODO: Discuss whether we should give EXP by Player Killing or not. + attacker_stats.exp.change_by( + (entity_stats.health.maximum() as f64 / 10.0 + + entity_stats.level.level() as f64 * 10.0) + as i64, + ); + } + }); } } @@ -331,7 +331,7 @@ impl Server { let _ = ecs.write_storage().insert(entity, comp::ForceUpdate); client.force_state(ClientState::Dead); } else { - let _ = state.ecs_mut().delete_entity_synced(entity); + todo_remove = Some(entity.clone()); } } @@ -356,6 +356,10 @@ impl Server { } } } + + if let Some(entity) = todo_remove { + let _ = state.ecs_mut().delete_entity_synced(entity); + } } }