Show wielded and worn in inventory.
This commit is contained in:
parent
228c5fbb9b
commit
862d7e3824
@ -1,14 +1,8 @@
|
||||
use super::{
|
||||
VerbContext, UserVerb, UserVerbRef, UResult,
|
||||
get_player_item_or_fail,
|
||||
};
|
||||
use super::{get_player_item_or_fail, UResult, UserVerb, UserVerbRef, VerbContext};
|
||||
use crate::{
|
||||
language::weight,
|
||||
static_content::possession_type::{
|
||||
possession_data,
|
||||
PossessionType
|
||||
},
|
||||
models::item::Item,
|
||||
models::item::{Item, LocationActionType},
|
||||
static_content::possession_type::{possession_data, PossessionType},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use itertools::Itertools;
|
||||
@ -17,19 +11,33 @@ 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<()> {
|
||||
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?;
|
||||
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 inv = ctx
|
||||
.trans
|
||||
.find_items_by_location(&format!(
|
||||
"{}/{}",
|
||||
&player_item.item_type, &player_item.item_code
|
||||
))
|
||||
.await?;
|
||||
let all_groups: Vec<Vec<&Arc<Item>>> = inv
|
||||
.iter()
|
||||
.group_by(|i| i.display_for_sentence(true, 1, false))
|
||||
.group_by(|i| (i.display_for_sentence(true, 1, false), &i.action_type))
|
||||
.into_iter()
|
||||
.map(|(_, g)|g.collect::<Vec<&Arc<Item>>>())
|
||||
.map(|(_, g)| g.collect::<Vec<&Arc<Item>>>())
|
||||
.collect::<Vec<Vec<&Arc<Item>>>>();
|
||||
let mut response = String::new();
|
||||
for items in all_groups {
|
||||
@ -38,19 +46,33 @@ impl UserVerb for Verb {
|
||||
continue;
|
||||
}
|
||||
if let Some(posdat) = possession_data().get(
|
||||
&item.possession_type.as_ref().unwrap_or(&PossessionType::AntennaWhip)) {
|
||||
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)));
|
||||
&item
|
||||
.possession_type
|
||||
.as_ref()
|
||||
.unwrap_or(&PossessionType::AntennaWhip),
|
||||
) {
|
||||
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)",
|
||||
_ => "",
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
if response == "" {
|
||||
response.push_str("You aren't carrying anything.\n");
|
||||
}
|
||||
ctx.trans.queue_for_session(ctx.session, Some(&response)).await?;
|
||||
ctx.trans
|
||||
.queue_for_session(ctx.session, Some(&response))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user