Incorporated changes from Imbris

This commit is contained in:
tommy 2019-07-14 16:35:22 -04:00
parent 6d8eea5085
commit bfa42dd33b

View File

@ -416,24 +416,15 @@ fn kind_to_body(kind: NpcKind) -> comp::Body {
fn handle_killnpcs(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) { fn handle_killnpcs(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
let ecs = server.state.ecs(); let ecs = server.state.ecs();
let mut npclist = Vec::new(); let mut stats = ecs.write_storage::<comp::Stats>();
{ let players = ecs.write_storage::<comp::Player>();
// Get the npc list, scope read access to prevent let mut count = 0;
// 'Already borrowed: InvalidBorrow' error when setting health stat for (npc, ()) in (&mut stats, !&players).join() {
let entities = ecs.entities(); count += 1;
let stats = ecs.read_storage::<comp::Stats>(); npc.health.set_to(0, comp::HealthSource::Command);
let players = ecs.read_storage::<comp::Player>();
for (npc, stat, ()) in (&entities, &stats, !&players).join() {
npclist.push((npc, stat.name.clone()));
}
} }
for npc in &npclist { let text = if count > 0 {
ecs.write_storage::<comp::Stats>() format!("Destroyed {} NPCs.", count)
.get_mut(npc.0)
.map(|s| s.health.set_to(0, comp::HealthSource::Command));
}
let text = if npclist.len() > 0 {
format!("Destroyed {} NPCs.", npclist.len())
} else { } else {
"No NPCs on server.".to_string() "No NPCs on server.".to_string()
}; };