use super::{get_player_item_or_fail, UResult, UserVerb, UserVerbRef, VerbContext}; use crate::{ language::weight, models::item::{Item, LocationActionType}, static_content::possession_type::{possession_data, PossessionType}, }; use async_trait::async_trait; use itertools::Itertools; use std::sync::Arc; 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?; if player_item.death_data.is_some() { ctx.trans .queue_for_session( ctx.session, Some("The dead don't really have an inventory.\n"), ) .await?; } let inv = ctx .trans .find_items_by_location(&format!( "{}/{}", &player_item.item_type, &player_item.item_code )) .await?; let all_groups: Vec>> = inv .iter() .group_by(|i| (i.display_for_sentence(true, 1, false), &i.action_type)) .into_iter() .map(|(_, g)| g.collect::>>()) .collect::>>>(); let mut response = String::new(); let mut total: u64 = 0; for items in all_groups { let item = items[0]; if item.item_type != "possession" { continue; } if let Some(posdat) = possession_data().get( &item .possession_type .as_ref() .unwrap_or(&PossessionType::AntennaWhip), ) { total += items.len() as u64 * posdat.weight; response.push_str(&format!( "{} [{}]{}\n", item.display_for_sentence( !ctx.session_dat.less_explicit_mode, items.len(), true ), weight(items.len() as u64 * posdat.weight), match item.action_type { LocationActionType::Worn => " (worn)", LocationActionType::Wielded => " (wielded)", _ => "", } )); } } response.push_str(&format!( "Total weight: {} ({} max)\n", weight(total), weight(player_item.max_carry()) )); if response == "" { response.push_str("You aren't carrying anything.\n"); } ctx.trans .queue_for_session(ctx.session, Some(&response)) .await?; Ok(()) } } static VERB_INT: Verb = Verb; pub static VERB: UserVerbRef = &VERB_INT as UserVerbRef;