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