use crate::static_content::room::room_map_by_code; use super::{ get_player_item_or_fail, user_error, UResult, UserError, UserVerb, UserVerbRef, VerbContext, }; use async_trait::async_trait; pub struct Verb; #[async_trait] impl UserVerb for Verb { async fn handle( self: &Self, ctx: &mut VerbContext, _verb: &str, _remaining: &str, ) -> UResult<()> { let player_item = get_player_item_or_fail(ctx).await?; let (loc_type, loc_code) = player_item .location .split_once("/") .ok_or_else(|| UserError("Your location is invalid".to_owned()))?; if loc_type != "room" { user_error("You can't find anything to scan here.".to_owned())?; } let room = room_map_by_code() .get(&loc_code) .ok_or_else(|| UserError("Your location no longer exists!".to_owned()))?; let allowed_scan = room .scan_code .as_ref() .ok_or_else(|| UserError("You can't find anything to scan here.".to_owned()))?; let user = ctx .user_dat .as_mut() .ok_or(UserError("Please log in first".to_owned()))?; if !user.scan_codes.contains(&allowed_scan) { user.scan_codes.push(allowed_scan.clone()); ctx.trans.save_user_model(&user).await?; } ctx.trans .queue_for_session( &ctx.session, Some("Your wristpad beeps indicating a successful scan.\n"), ) .await?; Ok(()) } } static VERB_INT: Verb = Verb; pub static VERB: UserVerbRef = &VERB_INT as UserVerbRef;