Merge branch 'master' into 'master'

Added ForceUpdate component upon teleport-related commands

See merge request veloren/veloren!41

Former-commit-id: 7597499a7949620a20558a855ddb85a7ccea58d2
This commit is contained in:
Joshua Barretto 2019-04-17 13:02:16 +00:00
commit 786dc16092

View File

@ -55,32 +55,28 @@ lazy_static! {
ChatCommand::new( ChatCommand::new(
"jump", "jump",
"{d} {d} {d}", "{d} {d} {d}",
"jump: offset your current position by a vector\n "/jump <dx> <dy> <dz> : Offset your current position",
Usage: /jump [x] [y] [z]",
handle_jump handle_jump
), ),
ChatCommand::new( ChatCommand::new(
"goto", "goto",
"{d} {d} {d}", "{d} {d} {d}",
"goto: teleport to a given position\n "/goto <x> <y> <z> : Teleport to a position",
Usage: /goto [x] [y] [z]",
handle_goto handle_goto
), ),
ChatCommand::new( ChatCommand::new(
"alias", "alias",
"{}", "{}",
"alias: change your player name (cannot contain spaces)\n "/alias <name> : Change your alias",
Usage: /alias [name]",
handle_alias handle_alias
), ),
ChatCommand::new( ChatCommand::new(
"tp", "tp",
"{}", "{}",
"tp: teleport to a named player\n "/tp <alias>: Teleport to another player",
Usage: /tp [name]",
handle_tp handle_tp
), ),
ChatCommand::new("help", "", "help: display this message", handle_help) ChatCommand::new("help", "", "/help: Display this message", handle_help)
]; ];
} }
@ -92,9 +88,10 @@ fn handle_jump(server: &mut Server, entity: EcsEntity, args: String, action: &Ch
.state .state
.read_component_cloned::<comp::phys::Pos>(entity) .read_component_cloned::<comp::phys::Pos>(entity)
{ {
Some(current_pos) => server Some(current_pos) => {
.state server.state.write_component(entity, comp::phys::Pos(current_pos.0 + Vec3::new(x, y, z)));
.write_component(entity, comp::phys::Pos(current_pos.0 + Vec3::new(x, y, z))), server.state.write_component(entity, comp::phys::ForceUpdate);
},
None => server.clients.notify( None => server.clients.notify(
entity, entity,
ServerMsg::Chat(String::from("Command 'jump' invalid in current state")), ServerMsg::Chat(String::from("Command 'jump' invalid in current state")),
@ -110,9 +107,10 @@ fn handle_jump(server: &mut Server, entity: EcsEntity, args: String, action: &Ch
fn handle_goto(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) { fn handle_goto(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
let (opt_x, opt_y, opt_z) = scan_fmt!(&args, action.arg_fmt, f32, f32, f32); let (opt_x, opt_y, opt_z) = scan_fmt!(&args, action.arg_fmt, f32, f32, f32);
match (opt_x, opt_y, opt_z) { match (opt_x, opt_y, opt_z) {
(Some(x), Some(y), Some(z)) => server (Some(x), Some(y), Some(z)) => {
.state server.state.write_component(entity, comp::phys::Pos(Vec3::new(x, y, z)));
.write_component(entity, comp::phys::Pos(Vec3::new(x, y, z))), server.state.write_component(entity, comp::phys::ForceUpdate);
},
_ => server _ => server
.clients .clients
.notify(entity, ServerMsg::Chat(String::from(action.help_string))), .notify(entity, ServerMsg::Chat(String::from(action.help_string))),
@ -145,13 +143,15 @@ fn handle_tp(server: &mut Server, entity: EcsEntity, args: String, action: &Chat
.state .state
.read_component_cloned::<comp::phys::Pos>(player) .read_component_cloned::<comp::phys::Pos>(player)
{ {
Some(pos) => server.state.write_component(entity, pos), Some(pos) => {
server.state.write_component(entity, pos);
server.state.write_component(entity, comp::phys::ForceUpdate);
},
None => server.clients.notify( None => server.clients.notify(
entity, entity,
ServerMsg::Chat(format!("Unable to teleport to player '{}'", alias)), ServerMsg::Chat(format!("Unable to teleport to player '{}'", alias)),
), ),
}, },
None => { None => {
server.clients.notify( server.clients.notify(
entity, entity,
@ -175,4 +175,4 @@ fn handle_help(server: &mut Server, entity: EcsEntity, _args: String, _action: &
.clients .clients
.notify(entity, ServerMsg::Chat(String::from(cmd.help_string))); .notify(entity, ServerMsg::Chat(String::from(cmd.help_string)));
} }
} }