mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Incorporated changes from Imbris
This commit is contained in:
parent
6d8eea5085
commit
bfa42dd33b
@ -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()));
|
|
||||||
}
|
}
|
||||||
}
|
let text = if count > 0 {
|
||||||
for npc in &npclist {
|
format!("Destroyed {} NPCs.", count)
|
||||||
ecs.write_storage::<comp::Stats>()
|
|
||||||
.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()
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user