tp_npc command

This commit is contained in:
IsseW 2022-08-12 17:57:55 +02:00 committed by Joshua Barretto
parent 587996abb7
commit ac0e62df8e
3 changed files with 31 additions and 0 deletions

View File

@ -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",

View File

@ -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<String>,
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::<RtSim>().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,

View File

@ -179,6 +179,10 @@ impl RtSim {
pub fn get_chunk_resources(&self, key: Vec2<i32>) -> EnumMap<ChunkResource, f32> {
self.state.data().nature.get_chunk_resources(key)
}
pub fn state(&self) -> &RtState {
&self.state
}
}
struct ChunkStates(pub Grid<Option<LoadedChunkState>>);