From c4c97e0d3655bd9d153e2d9688aa469454331610 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Thu, 25 Mar 2021 18:32:38 +0000 Subject: [PATCH] Added arguments for different kits --- common/src/cmd.rs | 6 ++- server/src/cmd.rs | 125 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 100 insertions(+), 31 deletions(-) diff --git a/common/src/cmd.rs b/common/src/cmd.rs index e37329e3c1..2a3c85d79b 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -327,7 +327,11 @@ impl ChatCommand { ), ChatCommand::Kill => cmd(vec![], "Kill yourself", NoAdmin), ChatCommand::KillNpcs => cmd(vec![], "Kill the NPCs", Admin), - ChatCommand::Kit => cmd(vec![], "Place all combat testing items into your pack.", Admin), + ChatCommand::Kit => cmd( + vec![Integer("kit_number", 3, Required)], + "Place all combat testing items into your pack.", + Admin, + ), ChatCommand::Lantern => cmd( vec![ Float("strength", 5.0, Required), diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 8916bd2b6a..e26c466d36 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1248,39 +1248,104 @@ fn handle_kill_npcs( fn handle_kit( server: &mut Server, - _client: EcsEntity, + client: EcsEntity, target: EcsEntity, - _args: String, - _action: &ChatCommand, + args: String, + action: &ChatCommand, ) { - let item_list = [ - comp::Item::new_from_asset_expect("common.items.armor.cultist.chest"), - comp::Item::new_from_asset_expect("common.items.armor.cultist.pants"), - comp::Item::new_from_asset_expect("common.items.armor.cultist.hand"), - comp::Item::new_from_asset_expect("common.items.armor.cultist.foot"), - comp::Item::new_from_asset_expect("common.items.armor.cultist.shoulder"), - comp::Item::new_from_asset_expect("common.items.armor.cultist.belt"), - comp::Item::new_from_asset_expect("common.items.weapons.hammer.cultist_purp_2h-0"), - comp::Item::new_from_asset_expect("common.items.weapons.staff.cultist_staff"), - comp::Item::new_from_asset_expect("common.items.weapons.sword.cultist"), - comp::Item::new_from_asset_expect("common.items.weapons.bow.velorite"), - comp::Item::new_from_asset_expect("common.items.weapons.axe.malachite_axe-0") + let kit_number = scan_fmt!(&args, &action.arg_fmt(), u32); + if kit_number == Ok(1) { + let item_list = [ + comp::Item::new_from_asset_expect("common.items.armor.cultist.chest"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.pants"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.hand"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.foot"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.shoulder"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.belt"), + comp::Item::new_from_asset_expect("common.items.weapons.hammer.cultist_purp_2h-0"), + comp::Item::new_from_asset_expect("common.items.weapons.staff.cultist_staff"), + comp::Item::new_from_asset_expect("common.items.weapons.sword.cultist"), + comp::Item::new_from_asset_expect("common.items.weapons.bow.velorite"), + comp::Item::new_from_asset_expect("common.items.weapons.axe.malachite_axe-0"), ]; - for item in &item_list { - server - .state() - .ecs() - .write_storage::() - .get_mut(target) - .map(|mut inv| inv.push(item.clone())); - let _ = server - .state - .ecs() - .write_storage::() - .insert( - target, - comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Debug), - ); + for item in &item_list { + server + .state() + .ecs() + .write_storage::() + .get_mut(target) + .map(|mut inv| inv.push(item.clone())); + let _ = server + .state + .ecs() + .write_storage::() + .insert( + target, + comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Debug), + ); + } + } else if kit_number == Ok(2) { + let item_list = [ + comp::Item::new_from_asset_expect("common.items.armor.cultist.chest"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.pants"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.hand"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.foot"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.shoulder"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.belt"), + comp::Item::new_from_asset_expect("common.items.weapons.hammer.cultist_purp_2h-0"), + comp::Item::new_from_asset_expect("common.items.weapons.staff.cultist_staff"), + comp::Item::new_from_asset_expect("common.items.weapons.sword.cultist"), + comp::Item::new_from_asset_expect("common.items.weapons.bow.velorite"), + ]; + for item in &item_list { + server + .state() + .ecs() + .write_storage::() + .get_mut(target) + .map(|mut inv| inv.push(item.clone())); + let _ = server + .state + .ecs() + .write_storage::() + .insert( + target, + comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Debug), + ); + } + } else if kit_number == Ok(3) { + let item_list = [ + comp::Item::new_from_asset_expect("common.items.armor.cultist.chest"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.pants"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.hand"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.foot"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.shoulder"), + comp::Item::new_from_asset_expect("common.items.armor.cultist.belt"), + comp::Item::new_from_asset_expect("common.items.weapons.hammer.cultist_purp_2h-0"), + comp::Item::new_from_asset_expect("common.items.weapons.staff.cultist_staff"), + comp::Item::new_from_asset_expect("common.items.weapons.sword.cultist"), + ]; + for item in &item_list { + server + .state() + .ecs() + .write_storage::() + .get_mut(target) + .map(|mut inv| inv.push(item.clone())); + let _ = server + .state + .ecs() + .write_storage::() + .insert( + target, + comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Debug), + ); + } + } else { + server.notify_client( + client, + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), + ); } }