Rework tp command - "/sudo player /tp" is short for "/sudo player /tp sudoer"

This commit is contained in:
CapsizeGlimmer 2020-05-09 21:17:03 -04:00
parent 9d118b55a0
commit 3f76d1d702
3 changed files with 48 additions and 36 deletions

View File

@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Cultists clothing - Cultists clothing
- You can start the game by pressing "enter" from the character selection menu - You can start the game by pressing "enter" from the character selection menu
- Added server-side character saving - Added server-side character saving
- Added tab completion in chat for player names and chat commands
### Changed ### Changed
@ -87,6 +88,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Rewrote the humanoid skeleton to be more ideal for attack animations - Rewrote the humanoid skeleton to be more ideal for attack animations
- Arrows can no longer hurt their owners - Arrows can no longer hurt their owners
- Increased overall character scale - Increased overall character scale
- `/sudo player /tp` is short for `/sudo player /tp me`
- The `/object` command can create any object in comp::object::Body
- The `/help` command takes an optional argument. `/help /sudo` will show you information about only the sudo command.
### Removed ### Removed

View File

@ -60,7 +60,7 @@ lazy_static! {
pub static ref ASSETS: RwLock<HashMap<String, Arc<dyn Any + 'static + Sync + Send>>> = pub static ref ASSETS: RwLock<HashMap<String, Arc<dyn Any + 'static + Sync + Send>>> =
RwLock::new(HashMap::new()); RwLock::new(HashMap::new());
/// List of item specifiers. Used for tab completing /// List of item specifiers. Useful for tab completing
pub static ref ITEM_SPECS: Vec<String> = { pub static ref ITEM_SPECS: Vec<String> = {
let base = ASSETS_PATH.join("common").join("items"); let base = ASSETS_PATH.join("common").join("items");
let mut items = vec![]; let mut items = vec![];

View File

@ -86,7 +86,9 @@ fn handle_give_item(
args: String, args: String,
action: &ChatCommand, action: &ChatCommand,
) { ) {
if let (Some(item_name), give_amount_opt) = scan_fmt_some!(&args, &action.arg_fmt(), String, u32) { if let (Some(item_name), give_amount_opt) =
scan_fmt_some!(&args, &action.arg_fmt(), String, u32)
{
let give_amount = give_amount_opt.unwrap_or(1); let give_amount = give_amount_opt.unwrap_or(1);
if let Ok(item) = assets::load_cloned(&item_name) { if let Ok(item) = assets::load_cloned(&item_name) {
let mut item: Item = item; let mut item: Item = item;
@ -145,7 +147,10 @@ fn handle_give_item(
); );
} }
} else { } else {
server.notify_client(client, ServerMsg::private(String::from(action.help_string()))); server.notify_client(
client,
ServerMsg::private(String::from(action.help_string())),
);
} }
} }
@ -356,44 +361,47 @@ fn handle_tp(
args: String, args: String,
action: &ChatCommand, action: &ChatCommand,
) { ) {
if let Ok(alias) = scan_fmt!(&args, &action.arg_fmt(), String) { let opt_player = if let Some(alias) = scan_fmt_some!(&args, &action.arg_fmt(), String) {
let ecs = server.state.ecs(); let ecs = server.state.ecs();
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::Player>()) (&ecs.entities(), &ecs.read_storage::<comp::Player>())
.join() .join()
.find(|(_, player)| player.alias == alias) .find(|(_, player)| player.alias == alias)
.map(|(entity, _)| entity); .map(|(entity, _)| entity)
match server.state.read_component_cloned::<comp::Pos>(target) { } else {
Some(_pos) => match opt_player { if client != target {
Some(player) => match server.state.read_component_cloned::<comp::Pos>(player) { Some(client)
Some(pos) => {
server.state.write_component(target, pos);
server.state.write_component(target, comp::ForceUpdate);
},
None => server.notify_client(
client,
ServerMsg::private(format!("Unable to teleport to player '{}'!", alias)),
),
},
None => {
server.notify_client(
client,
ServerMsg::private(format!("Player '{}' not found!", alias)),
);
server.notify_client(
client,
ServerMsg::private(String::from(action.help_string())),
);
},
},
None => {
server.notify_client(client, ServerMsg::private(format!("You have no position!")));
},
}
} else { } else {
server.notify_client(
client,
ServerMsg::private("You must specify a player name".to_string()),
);
server.notify_client( server.notify_client(
client, client,
ServerMsg::private(String::from(action.help_string())), ServerMsg::private(String::from(action.help_string())),
); );
return;
}
};
if let Some(_pos) = server.state.read_component_cloned::<comp::Pos>(target) {
if let Some(player) = opt_player {
if let Some(pos) = server.state.read_component_cloned::<comp::Pos>(player) {
server.state.write_component(target, pos);
server.state.write_component(target, comp::ForceUpdate);
} else {
server.notify_client(
client,
ServerMsg::private(format!("Unable to teleport to player!")),
);
}
} else {
server.notify_client(client, ServerMsg::private(format!("Player not found!")));
server.notify_client(
client,
ServerMsg::private(String::from(action.help_string())),
);
}
} else {
server.notify_client(client, ServerMsg::private(format!("You have no position!")));
} }
} }