Allow non player entites to be removed again

This commit is contained in:
timokoesters 2019-08-23 22:50:35 +02:00 committed by jshipsey
parent b5f649eb15
commit e674424974

View File

@ -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::<comp::Stats>();
// Give EXP to the client
let mut stats = ecs.write_storage::<comp::Stats>();
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);
}
}
}