Allow checking score and status.

This commit is contained in:
Condorra 2023-02-26 22:34:26 +11:00
parent 369b07474a
commit caa3d84081
4 changed files with 136 additions and 0 deletions

View File

@ -31,6 +31,8 @@ pub mod parsing;
mod quit;
mod register;
pub mod say;
mod score;
mod status;
pub mod use_cmd;
mod whisper;
mod who;
@ -136,6 +138,13 @@ static REGISTERED_COMMANDS: UserVerbRegistry = phf_map! {
"\'" => say::VERB,
"say" => say::VERB,
"sc" => score::VERB,
"score" => score::VERB,
"st" => status::VERB,
"stat" => status::VERB,
"status" => status::VERB,
"use" => use_cmd::VERB,
"-" => whisper::VERB,

View File

@ -0,0 +1,58 @@
use super::{VerbContext, UserVerb, UserVerbRef, UResult,
user_error, get_player_item_or_fail};
use crate::{
models::item::{StatType, SkillType}
};
use async_trait::async_trait;
use ansi::ansi;
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 user = match ctx.user_dat {
None => user_error("Log in first".to_owned())?,
Some(user) => user
};
let mut msg = String::new();
msg.push_str(&format!(ansi!("<bgblue><white><bold>| {:11} | {:5} | {:5} |<reset>\n"),
"Stat", "Raw", "Total"
));
for st in StatType::values().iter() {
msg.push_str(&format!(ansi!("| <bold>{:11}<reset> | {:5.2} | {:5.2} |\n"),
st.display(),
user.raw_stats.get(st).unwrap_or(&0.0),
player_item.total_stats.get(st).unwrap_or(&0.0)
));
}
msg.push_str("\n");
msg.push_str(&format!(ansi!("<bgblue><white><bold>| {:11} | {:5} | {:5} |<reset>\n"),
"Skill", "Raw", "Total"
));
for st in SkillType::values().iter() {
msg.push_str(&format!(ansi!("| <bold>{:11}<reset> | {:5.2} | {:5.2} |\n"),
st.display(),
user.raw_skills.get(st).unwrap_or(&0.0),
player_item.total_skills.get(st).unwrap_or(&0.0)
));
}
msg.push_str("\n");
msg.push_str(&format!(ansi!("Experience: <bold>{}<reset> total, \
change of {} this re-roll, \
{} spent since re-roll.\n"),
player_item.total_xp,
user.experience.xp_change_for_this_reroll,
user.experience.spent_xp
));
ctx.trans.queue_for_session(ctx.session, Some(&msg)).await?;
Ok(())
}
}
static VERB_INT: Verb = Verb;
pub static VERB: UserVerbRef = &VERB_INT as UserVerbRef;

View File

@ -0,0 +1,58 @@
use super::{VerbContext, UserVerb, UserVerbRef, UResult,
user_error, get_player_item_or_fail};
use crate::{
services::combat::max_health,
};
use async_trait::async_trait;
use ansi::ansi;
fn bar_n_of_m(mut actual: u64, max: u64) -> String {
if actual > max {
actual = max;
}
let mut r = String::new();
for _i in 0..actual {
r += "|";
}
for _i in actual..max {
r += " ";
}
r
}
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 user = match ctx.user_dat {
None => user_error("Log in first".to_owned())?,
Some(user) => user
};
let mut msg = String::new();
let maxh = max_health(&player_item);
msg.push_str(&format!(ansi!("<bold>Health [<green>{}<reset><bold>] [ {}/{} ]<reset>\n"),
bar_n_of_m(player_item.health, maxh),
player_item.health, maxh
));
msg.push_str(&format!(ansi!("<bold>Credits <green>${}<reset>\n"), user.credits));
ctx.trans.queue_for_session(ctx.session, Some(&msg)).await?;
Ok(())
}
}
static VERB_INT: Verb = Verb;
pub static VERB: UserVerbRef = &VERB_INT as UserVerbRef;
#[cfg(test)]
mod test {
#[test]
fn bar_n_of_m_works() {
assert_eq!(super::bar_n_of_m(4,7), "|||| ");
assert_eq!(super::bar_n_of_m(8,7), "|||||||");
assert_eq!(super::bar_n_of_m(8,8), "||||||||");
assert_eq!(super::bar_n_of_m(0,5), " ");
}
}

View File

@ -165,6 +165,17 @@ impl StatType {
Cool
)
}
pub fn display(&self) -> &'static str {
use StatType::*;
match self {
Brains => "brains",
Senses => "senses",
Brawn => "brawn",
Reflexes => "reflexes",
Endurance => "endurance",
Cool => "cool"
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]