diff --git a/common/src/cmd.rs b/common/src/cmd.rs index eb304014a0..f074cc6a3e 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -310,6 +310,7 @@ pub enum ServerChatCommand { Tell, Time, Tp, + TpNpc, Unban, Version, Waypoint, @@ -679,6 +680,11 @@ impl ServerChatCommand { "Teleport to another player", Some(Moderator), ), + ServerChatCommand::TpNpc => cmd( + vec![Integer("npc index", 0, Required)], + "Teleport to a npc", + Some(Moderator), + ), ServerChatCommand::Unban => cmd( vec![PlayerName(Required)], "Remove the ban for the given username", @@ -801,6 +807,7 @@ impl ServerChatCommand { ServerChatCommand::Tell => "tell", ServerChatCommand::Time => "time", ServerChatCommand::Tp => "tp", + ServerChatCommand::TpNpc => "tp_npc", ServerChatCommand::Unban => "unban", ServerChatCommand::Version => "version", ServerChatCommand::Waypoint => "waypoint", diff --git a/server/src/cmd.rs b/server/src/cmd.rs index ff72e6c8c8..8132fae612 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -184,6 +184,7 @@ fn do_command( ServerChatCommand::Tell => handle_tell, ServerChatCommand::Time => handle_time, ServerChatCommand::Tp => handle_tp, + ServerChatCommand::TpNpc => handle_tp_npc, ServerChatCommand::Unban => handle_unban, ServerChatCommand::Version => handle_version, ServerChatCommand::Waypoint => handle_waypoint, @@ -1182,6 +1183,25 @@ fn handle_tp( }) } +fn handle_tp_npc( + server: &mut Server, + _client: EcsEntity, + target: EcsEntity, + args: Vec, + action: &ServerChatCommand, +) -> CmdResult<()> { + use crate::rtsim2::RtSim; + let pos = if let Some(id) = parse_cmd_args!(args, u32) { + // TODO: Take some other identifier than an integer to this command. + server.state.ecs().read_resource::().state().data().npcs.values().nth(id as usize).ok_or(action.help_string())?.wpos + } else { + return Err(action.help_string()); + }; + position_mut(server, target, "target", |target_pos| { + target_pos.0 = pos; + }) +} + fn handle_spawn( server: &mut Server, client: EcsEntity, diff --git a/server/src/rtsim2/mod.rs b/server/src/rtsim2/mod.rs index a0f6cf6d33..748b99b054 100644 --- a/server/src/rtsim2/mod.rs +++ b/server/src/rtsim2/mod.rs @@ -179,6 +179,10 @@ impl RtSim { pub fn get_chunk_resources(&self, key: Vec2) -> EnumMap { self.state.data().nature.get_chunk_resources(key) } + + pub fn state(&self) -> &RtState { + &self.state + } } struct ChunkStates(pub Grid>);