mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Updates based on code review #183
This commit is contained in:
parent
2bf2e7f958
commit
42861541cf
@ -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,26 @@ 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 npclist=Vec::new();
|
||||
{
|
||||
// get the npc list, scope read access to prevent
|
||||
// 'Already borrowed: InvalidBorrow' error when setting health stat
|
||||
let entities = ecs.entities();
|
||||
let stats = ecs.read_storage::<comp::Stats>();
|
||||
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 mut text = npc.1.clone();
|
||||
text += " is no more.";
|
||||
server.clients.notify(entity, ServerMsg::Chat(text));
|
||||
ecs.write_storage::<comp::Stats>()
|
||||
.get_mut(npc.0)
|
||||
.map(|s| s.health.set_to(0, comp::HealthSource::Command));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user