blastmud/blastmud_game/src/message_handler/user_commands/stop.rs

61 lines
2.2 KiB
Rust

use super::{
get_player_item_or_fail, movement::reverse_climb, user_error, UResult, 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?;
if player_item.death_data.is_some() {
user_error("You're dead. If you wanted to just stop being dead, I'm afraid it doesn't work like that (although you can try going up to resurrect into a new body). If you wanted to stop doing whatever you were doing when you died, then the good news is that your death already put a stop to it.".to_owned())?;
}
let mut player_item_mut = (*player_item).clone();
let mut queue_head = player_item_mut.queue.pop_front();
if player_item.active_combat.is_some() {
// Otherwise, we assume they wanted to stop escaping etc...
if queue_head.is_none() {
user_error("You can't just stop fighting - either fight to the death or try moving to another room.".to_owned())?;
}
}
let mut msg = String::new();
if let Some(_active_climb) = player_item_mut.active_climb.as_mut() {
if let Some(ref mut queue_head_v) = queue_head {
msg.push_str(&reverse_climb(&mut player_item_mut, &ctx.trans, queue_head_v).await?);
}
}
let qlen = player_item_mut.queue.len();
if qlen > 0 {
msg.push_str(&format!(
"You cancel your plans to take {} action{}.\n",
qlen,
if qlen > 1 { "s" } else { "" },
));
} else if msg == "" {
user_error("You weren't doing anything that could be stopped.".to_owned())?;
}
player_item_mut.queue = queue_head.clone().into_iter().collect();
ctx.trans.save_item_model(&player_item_mut).await?;
ctx.trans
.queue_for_session(&ctx.session, Some(&msg))
.await?;
Ok(())
}
}
static VERB_INT: Verb = Verb;
pub static VERB: UserVerbRef = &VERB_INT as UserVerbRef;