2023-01-15 17:30:23 +11:00
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 ;
2023-01-20 23:08:40 +11:00
use crate ::{
2023-01-22 22:43:44 +11:00
services ::{
combat ::start_attack ,
2023-01-22 01:16:00 +11:00
} ,
2023-01-15 23:16:02 +11:00
2023-01-22 22:43:44 +11:00
db ::ItemSearchParams ,
} ;
2023-01-15 17:30:23 +11:00
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 ? ;
2023-01-27 00:36:49 +11:00
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 ( ) ) ? ;
}
2023-01-15 17:30:23 +11:00
let attack_whom = search_item_for_user ( ctx , & ItemSearchParams {
include_loc_contents : true ,
2023-02-20 22:27:43 +11:00
limit : 1 ,
2023-01-15 17:30:23 +11:00
.. ItemSearchParams ::base ( & player_item , remaining )
} ) . await ? ;
match attack_whom . item_type . as_str ( ) {
" npc " = > { }
" player " = > { } ,
2023-01-22 22:43:44 +11:00
_ = > user_error ( " Only characters (players / NPCs) can be attacked " . to_string ( ) ) ?
2023-01-15 17:30:23 +11:00
}
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.
2023-01-22 01:16:00 +11:00
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 ( ) ) ?
2023-01-15 17:30:23 +11:00
}
2023-01-22 22:43:44 +11:00
if attack_whom . is_dead {
user_error ( " There's no point attacking the dead! " . to_string ( ) ) ?
}
2023-01-15 17:30:23 +11:00
start_attack ( & ctx . trans , & player_item , & attack_whom ) . await
}
}
static VERB_INT : Verb = Verb ;
pub static VERB : UserVerbRef = & VERB_INT as UserVerbRef ;