diff --git a/CHANGELOG.md b/CHANGELOG.md index 621684c177..3c7e0f489d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Ability to wield 2 × 1h weapons and shields (Note: 1h weapons & shields are not currently avaliable, see [!1095](https://gitlab.com/veloren/veloren/-/merge_requests/1095) for more info) - Zoomable Map - M2 attack for hammer +- Spawnable training dummies ### Changed diff --git a/client/src/cmd.rs b/client/src/cmd.rs index 0e07f0365a..7c5502ba8b 100644 --- a/client/src/cmd.rs +++ b/client/src/cmd.rs @@ -32,6 +32,11 @@ impl TabComplete for ArgumentSpec { .filter(|string| string.starts_with(part)) .map(|c| c.to_string()) .collect(), + ArgumentSpec::Boolean(_, part, _) => vec!["true", "false"] + .iter() + .filter(|string| string.starts_with(part)) + .map(|c| c.to_string()) + .collect(), } } } diff --git a/common/src/cmd.rs b/common/src/cmd.rs index 16fab4703b..812af83795 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -40,6 +40,7 @@ pub enum ChatCommand { Build, Debug, DebugColumn, + Dummy, Explosion, Faction, GiveExp, @@ -81,6 +82,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[ ChatCommand::Build, ChatCommand::Debug, ChatCommand::DebugColumn, + ChatCommand::Dummy, ChatCommand::Explosion, ChatCommand::Faction, ChatCommand::GiveExp, @@ -191,6 +193,7 @@ impl ChatCommand { "Prints some debug information about a column", NoAdmin, ), + ChatCommand::Dummy => cmd(vec![], "Spawns a training dummy", NoAdmin), ChatCommand::Explosion => cmd( vec![Float("radius", 5.0, Required)], "Explodes the ground around you", @@ -321,6 +324,7 @@ impl ChatCommand { Enum("alignment", ALIGNMENTS.clone(), Required), Enum("entity", ENTITIES.clone(), Required), Integer("amount", 1, Optional), + Boolean("ai", "true".to_string(), Optional), ], "Spawn a test entity", Admin, @@ -370,6 +374,7 @@ impl ChatCommand { ChatCommand::Build => "build", ChatCommand::Debug => "debug", ChatCommand::DebugColumn => "debug_column", + ChatCommand::Dummy => "dummy", ChatCommand::Explosion => "explosion", ChatCommand::Faction => "faction", ChatCommand::GiveExp => "give_exp", @@ -433,6 +438,7 @@ impl ChatCommand { ArgumentSpec::Message(_) => "{/.*/}", ArgumentSpec::SubCommand => "{} {/.*/}", ArgumentSpec::Enum(_, _, _) => "{}", + ArgumentSpec::Boolean(_, _, _) => "{}", }) .collect::>() .join(" ") @@ -514,6 +520,11 @@ pub enum ArgumentSpec { /// * Predefined string completions /// * whether it's optional Enum(&'static str, Vec, Requirement), + /// The argument is likely a boolean. The associated values are + /// * label + /// * suggested tab-completion + /// * whether it's optional + Boolean(&'static str, String, Requirement), } impl ArgumentSpec { @@ -569,6 +580,13 @@ impl ArgumentSpec { format! {"[{}]", label} } }, + ArgumentSpec::Boolean(label, _, req) => { + if &Requirement::Required == req { + format!("<{}>", label) + } else { + format!("[{}]", label) + } + }, } } } diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 03259a291b..ebfac3b3b1 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -66,6 +66,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler { ChatCommand::Build => handle_build, ChatCommand::Debug => handle_debug, ChatCommand::DebugColumn => handle_debug_column, + ChatCommand::Dummy => handle_spawn_training_dummy, ChatCommand::Explosion => handle_explosion, ChatCommand::Faction => handle_faction, ChatCommand::GiveExp => handle_give_exp, @@ -497,8 +498,15 @@ fn handle_spawn( args: String, action: &ChatCommand, ) { - match scan_fmt_some!(&args, &action.arg_fmt(), String, npc::NpcBody, String) { - (Some(opt_align), Some(npc::NpcBody(id, mut body)), opt_amount) => { + match scan_fmt_some!( + &args, + &action.arg_fmt(), + String, + npc::NpcBody, + String, + String + ) { + (Some(opt_align), Some(npc::NpcBody(id, mut body)), opt_amount, opt_ai) => { if let Some(alignment) = parse_alignment(target, &opt_align) { let amount = opt_amount .and_then(|a| a.parse().ok()) @@ -506,6 +514,8 @@ fn handle_spawn( .unwrap_or(1) .min(10); + let ai = opt_ai.unwrap_or("true".to_string()); + match server.state.read_component_cloned::(target) { Some(pos) => { let agent = @@ -524,7 +534,7 @@ fn handle_spawn( let body = body(); - let new_entity = server + let mut entity_base = server .state .create_npc( pos, @@ -534,9 +544,13 @@ fn handle_spawn( ) .with(comp::Vel(vel)) .with(comp::MountState::Unmounted) - .with(agent.clone()) - .with(alignment) - .build(); + .with(alignment); + + if ai == "true".to_string() { + entity_base = entity_base.with(agent.clone()); + } + + let new_entity = entity_base.build(); if let Some(uid) = server.state.ecs().uid_from_entity(new_entity) { server.notify_client( @@ -568,6 +582,47 @@ fn handle_spawn( } } +fn handle_spawn_training_dummy( + server: &mut Server, + client: EcsEntity, + target: EcsEntity, + _args: String, + _action: &ChatCommand, +) { + match server.state.read_component_cloned::(target) { + Some(pos) => { + let vel = Vec3::new( + rand::thread_rng().gen_range(-2.0, 3.0), + rand::thread_rng().gen_range(-2.0, 3.0), + 10.0, + ); + + let body = comp::Body::Object(comp::object::Body::Scarecrow); + + server + .state + .create_npc( + pos, + comp::Stats::new("Training Dummy".to_string(), body), + comp::Loadout::default(), + body, + ) + .with(comp::Vel(vel)) + .with(comp::MountState::Unmounted) + .build(); + + server.notify_client( + client, + ChatType::CommandInfo.server_msg(format!("Spawned a training dummy")), + ); + }, + None => server.notify_client( + client, + ChatType::CommandError.server_msg("You have no position!"), + ), + } +} + fn handle_players( server: &mut Server, client: EcsEntity,