Give drop the same enhancements as get, + write help

This commit is contained in:
Condorra 2023-02-22 21:36:57 +11:00
parent ea5b5ef70d
commit ed3dcdcb64
2 changed files with 37 additions and 7 deletions

View File

@ -6,7 +6,8 @@ use super::{
ItemSearchParams, ItemSearchParams,
user_error, user_error,
get_player_item_or_fail, get_player_item_or_fail,
search_item_for_user, search_items_for_user,
parsing::parse_count,
}; };
use crate::{ use crate::{
static_content::possession_type::possession_data, static_content::possession_type::possession_data,
@ -72,6 +73,7 @@ impl QueueCommandHandler for QueueHandler {
QueueCommand::Drop { possession_id } => possession_id, QueueCommand::Drop { possession_id } => possession_id,
_ => user_error("Unexpected command".to_owned())? _ => user_error("Unexpected command".to_owned())?
}; };
let item = match ctx.trans.find_item_by_type_code("possession", &item_id).await? { let item = match ctx.trans.find_item_by_type_code("possession", &item_id).await? {
None => user_error("Item not found".to_owned())?, None => user_error("Item not found".to_owned())?,
Some(it) => it Some(it) => it
@ -113,19 +115,34 @@ impl QueueCommandHandler for QueueHandler {
pub struct Verb; pub struct Verb;
#[async_trait] #[async_trait]
impl UserVerb for Verb { impl UserVerb for Verb {
async fn handle(self: &Self, ctx: &mut VerbContext, _verb: &str, remaining: &str) -> UResult<()> { async fn handle(self: &Self, ctx: &mut VerbContext, _verb: &str, mut remaining: &str) -> UResult<()> {
let player_item = get_player_item_or_fail(ctx).await?; let player_item = get_player_item_or_fail(ctx).await?;
let target = search_item_for_user(ctx, &ItemSearchParams {
let mut get_limit = Some(1);
if remaining == "all" || remaining.starts_with("all ") {
remaining = remaining[3..].trim();
get_limit = None;
} else if let (Some(n), remaining2) = parse_count(remaining) {
get_limit = Some(n);
remaining = remaining2;
}
let targets = search_items_for_user(ctx, &ItemSearchParams {
include_contents: true, include_contents: true,
item_type_only: Some("possession"),
limit: get_limit.unwrap_or(100),
..ItemSearchParams::base(&player_item, &remaining) ..ItemSearchParams::base(&player_item, &remaining)
}).await?; }).await?;
if player_item.is_dead { if player_item.is_dead {
user_error("You try to drop it, but your ghostly hands slip through it uselessly".to_owned())?; user_error("You try to drop it, but your ghostly hands slip through it uselessly".to_owned())?;
} }
if target.item_type != "possession" {
user_error("You can't drop that!".to_owned())?; for target in targets {
if target.item_type != "possession" {
user_error("You can't drop that!".to_owned())?;
}
queue_command(ctx, &QueueCommand::Drop { possession_id: target.item_code.clone() }).await?;
} }
queue_command(ctx, &QueueCommand::Drop { possession_id: target.item_code.clone() }).await?;
Ok(()) Ok(())
} }
} }

View File

@ -37,6 +37,7 @@ static REGISTERED_HELP_PAGES: phf::Map<&'static str, &'static str> = phf_map! {
Topics of interest:\n\ Topics of interest:\n\
\t<bold>newbie<reset>\tLearn the absolute basics.\n\ \t<bold>newbie<reset>\tLearn the absolute basics.\n\
\t<bold>movement<reset>\tCommands for moving around.\n\ \t<bold>movement<reset>\tCommands for moving around.\n\
\t<bold>possessions<reset>\tCommands for dealing with possessions / weapons.\n\
\t<bold>talk<reset>\tFind out how to talk in the game.\n\ \t<bold>talk<reset>\tFind out how to talk in the game.\n\
\t<bold>combat<reset>\tLearn how to fight.\n\ \t<bold>combat<reset>\tLearn how to fight.\n\
\t<bold>information<reset>\tLearn how to find out about the world and your character."), \t<bold>information<reset>\tLearn how to find out about the world and your character."),
@ -102,7 +103,19 @@ static REGISTERED_HELP_PAGES: phf::Map<&'static str, &'static str> = phf_map! {
"talk" => "talk" =>
ansi!("Use:\n\ ansi!("Use:\n\
\t<bold>'<reset>message to send message to the room.\n\ \t<bold>'<reset>message to send message to the room.\n\
\t<bold>-<reset>user message to whisper to someone.") \t<bold>-<reset>user message to whisper to someone."),
"possessions" =>
ansi!("Use:\n\
\t<bold>get<reset> item to pick something up from the ground.\n\
\t<bold>drop<reset> item to drop something from your inventory.\n\
\t<bold>inv<reset> to see what you are holding.\n\
\t<bold>buy<reset> item to buy something from the shop you are in.\n\
\t<bold>list<reset> to see the price list for the stop.\n\
\t<bold>wield<reset> to hold a weapon in your inventory for use when you attack.\n\
Hint: get and drop support an item name, but you can also prefix it \
with a number - e.g. <bold>get 2 whip<reset>. Instead of a number, you can \
use <bold>all<reset>. You can also omit the item name to match any \
possession, e.g. <bold>drop all<reset> will drop everything you have.")
}; };
static EXPLICIT_HELP_PAGES: phf::Map<&'static str, &'static str> = phf_map! { static EXPLICIT_HELP_PAGES: phf::Map<&'static str, &'static str> = phf_map! {