Merge branch 'qutrin/command-stuff' into 'master'

Add /health command

See merge request veloren/veloren!283
This commit is contained in:
Joshua Barretto 2019-07-01 20:07:31 +00:00
commit 0f38fba897
2 changed files with 33 additions and 1 deletions

View File

@ -6,6 +6,7 @@ pub enum HealthSource {
Attack { by: Uid }, // TODO: Implement weapon
Suicide,
Revive,
Command,
Unknown,
}

View File

@ -119,7 +119,13 @@ lazy_static! {
handle_empty,
),
ChatCommand::new(
"help", "", "/help: Display this message", handle_help)
"help", "", "/help: Display this message", handle_help),
ChatCommand::new(
"health",
"{}",
"/health : Set your current health",
handle_health,
)
];
}
@ -205,6 +211,31 @@ fn handle_time(server: &mut Server, entity: EcsEntity, args: String, action: &Ch
};
}
fn handle_health(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
let opt_hp = scan_fmt!(&args, action.arg_fmt, u32);
match server
.state
.ecs_mut()
.write_storage::<comp::Stats>()
.get_mut(entity)
{
Some(stats) => match opt_hp {
Some(hp) => stats.health.set_to(hp, comp::HealthSource::Command),
None => {
server.clients.notify(
entity,
ServerMsg::Chat(String::from("You must specify health amount!")),
);
}
},
None => server.clients.notify(
entity,
ServerMsg::Chat(String::from("You have no position.")),
),
}
}
fn handle_alias(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
let opt_alias = scan_fmt!(&args, action.arg_fmt, String);
match opt_alias {