Merge branch '183_add_killnpcs_command' into 'master'

/killnpcs command, closes #183

Closes #183

See merge request veloren/veloren!329
This commit is contained in:
Forest Anderson 2019-07-17 17:34:36 +00:00
commit b8993f568f

View File

@ -118,6 +118,12 @@ lazy_static! {
"/build : Toggles build mode on and off",
handle_build,
),
ChatCommand::new(
"killnpcs",
"{}",
"/killnpcs : Kill the NPCs",
handle_killnpcs,
),
];
}
@ -407,3 +413,20 @@ fn kind_to_body(kind: NpcKind) -> comp::Body {
NpcKind::Wolf => comp::Body::QuadrupedMedium(comp::quadruped_medium::Body::random()),
}
}
fn handle_killnpcs(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
let ecs = server.state.ecs();
let mut stats = ecs.write_storage::<comp::Stats>();
let players = ecs.read_storage::<comp::Player>();
let mut count = 0;
for (stats, ()) in (&mut stats, !&players).join() {
count += 1;
stats.health.set_to(0, comp::HealthSource::Command);
}
let text = if count > 0 {
format!("Destroyed {} NPCs.", count)
} else {
"No NPCs on server.".to_string()
};
server.clients.notify(entity, ServerMsg::Chat(text));
}