From b8011420e64f80e29c9509d1fbb428a6da7c9f06 Mon Sep 17 00:00:00 2001 From: Condorra Date: Sat, 22 Jun 2024 22:37:16 +1000 Subject: [PATCH] Allow inspecting things for sale in shops. --- .../user_commands/help/registered.yaml | 7 ++- .../src/message_handler/user_commands/look.rs | 50 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/blastmud_game/src/message_handler/user_commands/help/registered.yaml b/blastmud_game/src/message_handler/user_commands/help/registered.yaml index f7a4581..19a32ab 100644 --- a/blastmud_game/src/message_handler/user_commands/help/registered.yaml +++ b/blastmud_game/src/message_handler/user_commands/help/registered.yaml @@ -49,7 +49,12 @@ northwest: *movement up: *movement down: *movement in: *movement -look: &look Try look, l, examine or ex to look at the current room. Follow it with the name of an exit to look at an adjacent room. Or name an object or player in the room to look at that. +look: &look >- + Try look, l, examine or ex to look at the current room. + Follow it with the name of an exit to look at an adjacent room. + Or name an object or player in the room to look at that. + You can also use look at thing for sale while in a shop to inspect the wares before + you buy. l: *look ex: *look read: *look diff --git a/blastmud_game/src/message_handler/user_commands/look.rs b/blastmud_game/src/message_handler/user_commands/look.rs index 8a79bb1..8355f32 100644 --- a/blastmud_game/src/message_handler/user_commands/look.rs +++ b/blastmud_game/src/message_handler/user_commands/look.rs @@ -20,7 +20,7 @@ use crate::{ static_content::{ dynzone, possession_type::{possession_data, recipe_craft_by_recipe}, - room::{self, Direction}, + room::{self, room_map_by_code, Direction}, species::species_info_map, }, }; @@ -706,6 +706,38 @@ pub async fn direction_to_item( Ok(trans.find_item_by_type_code("room", &new_room.code).await?) } +async fn describe_store_item( + ctx: &VerbContext<'_>, + player_item: &Item, + location_type: &str, + location_code: &str, + item: &str, +) -> UResult<()> { + if location_type != "room" { + user_error("Nothing is for sale here.".to_owned())?; + } + let room = room_map_by_code() + .get(location_code) + .ok_or_else(|| UserError("Couldn't find your room to look.".to_owned()))?; + if room.stock_list.is_empty() { + user_error("Nothing is for sale here.".to_owned())? + } + let (poss_type, _poss_data) = room + .stock_list + .iter() + .filter(|rs| rs.can_buy) + .filter_map(|rs| match possession_data().get(&rs.possession_type) { + Some(pd) => Some((rs.possession_type.clone(), pd)), + None => None, + }) + .find(|(_, pd)| { + pd.display.starts_with(item) || pd.aliases.iter().any(|a| a.starts_with(item)) + }) + .ok_or_else(|| UserError("Couldn't find anything like that for sale.".to_owned()))?; + let tmp_item: Item = poss_type.clone().into(); + describe_normal_item(&player_item, ctx, &tmp_item).await +} + pub struct Verb; #[async_trait] impl UserVerb for Verb { @@ -722,6 +754,9 @@ impl UserVerb for Verb { if rem_trim.starts_with("in ") { rem_trim = rem_trim[3..].trim_start().to_owned(); } + if rem_trim.starts_with("at ") { + rem_trim = rem_trim[3..].trim_start().to_owned(); + } let use_location = if player_item.death_data.is_some() { "room/repro_xv_respawn" } else { @@ -730,6 +765,18 @@ impl UserVerb for Verb { let (heretype, herecode) = use_location .split_once("/") .unwrap_or(("room", "repro_xv_chargen")); + + if rem_trim.ends_with(" for sale") { + return Ok(describe_store_item( + ctx, + &player_item, + heretype, + herecode, + rem_trim[0..(rem_trim.len() - 9)].trim_end(), + ) + .await?); + } + let item: Arc = if rem_trim == "" { ctx.trans .find_item_by_type_code(heretype, herecode) @@ -838,5 +885,6 @@ impl UserVerb for Verb { Ok(()) } } + static VERB_INT: Verb = Verb; pub static VERB: UserVerbRef = &VERB_INT as UserVerbRef;