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

52 lines
1.9 KiB
Rust

use super::{VerbContext, UserVerb, UserVerbRef, UResult, user_error,
get_player_item_or_fail, search_item_for_user};
use async_trait::async_trait;
use ansi::ansi;
use crate::{
services::{
combat::start_attack,
},
db::ItemSearchParams,
};
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.is_dead {
user_error("It doesn't really seem fair, but you realise you won't be able to attack anyone while you're dead!".to_string())?;
}
let attack_whom = search_item_for_user(ctx, &ItemSearchParams {
include_loc_contents: true,
..ItemSearchParams::base(&player_item, remaining)
}).await?;
match attack_whom.item_type.as_str() {
"npc" => {}
"player" => {},
_ => user_error("Only characters (players / NPCs) can be attacked".to_string())?
}
if attack_whom.item_code == player_item.item_code && attack_whom.item_type == player_item.item_type {
user_error("That's you, silly!".to_string())?
}
if attack_whom.is_challenge_attack_only {
// Add challenge check here.
user_error(ansi!("<blue>Your wristpad vibrates and blocks you from doing that.<reset> You get a feeling that while the empire might be gone, the system to stop subjects with working wristpads from fighting each unless they have an accepted challenge is very much functional. [Try <bold>help challenge<reset>]").to_string())?
}
if attack_whom.is_dead {
user_error("There's no point attacking the dead!".to_string())?
}
start_attack(&ctx.trans, &player_item, &attack_whom).await
}
}
static VERB_INT: Verb = Verb;
pub static VERB: UserVerbRef = &VERB_INT as UserVerbRef;