implement /home to return to home town

This commit is contained in:
Christof Petig 2020-11-04 00:53:46 +01:00
parent 9e905b297a
commit ac92c8a6af
2 changed files with 29 additions and 1 deletions

View File

@ -51,6 +51,7 @@ pub enum ChatCommand {
Group,
Health,
Help,
Home,
JoinFaction,
Jump,
Kick,
@ -98,6 +99,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
ChatCommand::Group,
ChatCommand::Health,
ChatCommand::Help,
ChatCommand::Home,
ChatCommand::JoinFaction,
ChatCommand::Jump,
ChatCommand::Kick,
@ -267,6 +269,7 @@ impl ChatCommand {
"Display information about commands",
NoAdmin,
),
ChatCommand::Home => cmd(vec![], "Return to the home town", NoAdmin),
ChatCommand::JoinFaction => ChatCommandData::new(
vec![Any("faction", Optional)],
"Join/leave the specified faction",
@ -427,6 +430,7 @@ impl ChatCommand {
ChatCommand::Health => "health",
ChatCommand::JoinFaction => "join_faction",
ChatCommand::Help => "help",
ChatCommand::Home => "home",
ChatCommand::Jump => "jump",
ChatCommand::Kick => "kick",
ChatCommand::Kill => "kill",

View File

@ -4,7 +4,7 @@
use crate::{
settings::{BanRecord, EditableSetting},
Server, StateExt,
Server, SpawnPoint, StateExt,
};
use chrono::{NaiveTime, Timelike};
use common::{
@ -82,6 +82,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
ChatCommand::Group => handle_group,
ChatCommand::Health => handle_health,
ChatCommand::Help => handle_help,
ChatCommand::Home => handle_home,
ChatCommand::JoinFaction => handle_join_faction,
ChatCommand::Jump => handle_jump,
ChatCommand::Kick => handle_kick,
@ -359,6 +360,29 @@ fn handle_goto(
}
}
fn handle_home(
server: &mut Server,
client: EcsEntity,
target: EcsEntity,
_args: String,
_action: &ChatCommand,
) {
if server
.state
.read_component_copied::<comp::Pos>(target)
.is_some()
{
let home_pos = server.state.ecs().read_resource::<SpawnPoint>().0;
server.state.write_component(target, comp::Pos(home_pos));
server.state.write_component(target, comp::ForceUpdate);
} else {
server.notify_client(
client,
ChatType::CommandError.server_msg("You have no position."),
);
}
}
fn handle_kill(
server: &mut Server,
client: EcsEntity,