Enhance /kit all

- "all" is now in proposed completions
- `/kit all` gives all imaginable items, it's not limited to assets
  anymore
This commit is contained in:
juliancoffee 2024-01-13 18:45:32 +02:00
parent aba8ec7558
commit b8e6840bf6
3 changed files with 33 additions and 20 deletions

View File

@ -1,6 +1,6 @@
ItemDef( ItemDef(
name: "Admin's Black Hole", name: "Admin's Black Hole",
description: "It just works.", description: "They say it will fit anything.",
kind: Armor( kind: Armor(
( (
kind: Bag, kind: Bag,
@ -9,5 +9,5 @@ ItemDef(
), ),
quality: Debug, quality: Debug,
tags: [], tags: [],
slots: 900, slots: 2500,
) )

View File

@ -242,13 +242,16 @@ lazy_static! {
}; };
pub static ref KITS: Vec<String> = { pub static ref KITS: Vec<String> = {
if let Ok(kits) = KitManifest::load_and_combine(KIT_MANIFEST_PATH) { let mut kits = if let Ok(kits) = KitManifest::load_and_combine(KIT_MANIFEST_PATH) {
let mut kits = kits.read().0.keys().cloned().collect::<Vec<String>>(); let mut kits = kits.read().0.keys().cloned().collect::<Vec<String>>();
kits.sort(); kits.sort();
kits kits
} else { } else {
Vec::new() Vec::new()
} };
kits.push("all".to_owned());
kits
}; };
static ref PRESETS: HashMap<String, Vec<(Skill, u8)>> = { static ref PRESETS: HashMap<String, Vec<(Skill, u8)>> = {

View File

@ -21,14 +21,14 @@ use common::{
assets, assets,
calendar::Calendar, calendar::Calendar,
cmd::{ cmd::{
AreaKind, EntityTarget, KitSpec, ServerChatCommand, BUFF_PACK, BUFF_PARSER, ITEM_SPECS, AreaKind, EntityTarget, KitSpec, ServerChatCommand, BUFF_PACK, BUFF_PARSER,
KIT_MANIFEST_PATH, PRESET_MANIFEST_PATH, KIT_MANIFEST_PATH, PRESET_MANIFEST_PATH,
}, },
comp::{ comp::{
self, self,
buff::{Buff, BuffData, BuffKind, BuffSource, MiscBuffData}, buff::{Buff, BuffData, BuffKind, BuffSource, MiscBuffData},
inventory::{ inventory::{
item::{tool::AbilityMap, MaterialStatManifest, Quality}, item::{all_items_expect, tool::AbilityMap, MaterialStatManifest, Quality},
slot::Slot, slot::Slot,
}, },
invite::InviteKind, invite::InviteKind,
@ -2434,6 +2434,15 @@ fn handle_kill_npcs(
Ok(()) Ok(())
} }
enum KitEntry {
Spec(KitSpec),
Item(Item),
}
impl From<KitSpec> for KitEntry {
fn from(spec: KitSpec) -> Self { Self::Spec(spec) }
}
fn handle_kit( fn handle_kit(
server: &mut Server, server: &mut Server,
client: EcsEntity, client: EcsEntity,
@ -2453,13 +2462,13 @@ fn handle_kit(
match name.as_str() { match name.as_str() {
"all" => { "all" => {
// TODO: we will probably want to handle modular items here too // This can't fail, we have tests
let items = &ITEM_SPECS; let items = all_items_expect();
let total = items.len();
let res = push_kit( let res = push_kit(
items items.into_iter().map(|item| (KitEntry::Item(item), 1)),
.iter() total,
.map(|item_id| (KitSpec::Item(item_id.to_string()), 1)),
items.len(),
server, server,
target, target,
); );
@ -2480,7 +2489,7 @@ fn handle_kit(
let res = push_kit( let res = push_kit(
kit.iter() kit.iter()
.map(|(item_id, quantity)| (item_id.clone(), *quantity)), .map(|(item_id, quantity)| (item_id.clone().into(), *quantity)),
kit.len(), kit.len(),
server, server,
target, target,
@ -2495,7 +2504,7 @@ fn handle_kit(
fn push_kit<I>(kit: I, count: usize, server: &mut Server, target: EcsEntity) -> CmdResult<()> fn push_kit<I>(kit: I, count: usize, server: &mut Server, target: EcsEntity) -> CmdResult<()>
where where
I: Iterator<Item = (KitSpec, u32)>, I: Iterator<Item = (KitEntry, u32)>,
{ {
if let (Some(mut target_inventory), mut target_inv_update) = ( if let (Some(mut target_inventory), mut target_inv_update) = (
server server
@ -2529,19 +2538,20 @@ where
} }
fn push_item( fn push_item(
item_id: KitSpec, item_id: KitEntry,
quantity: u32, quantity: u32,
server: &Server, server: &Server,
push: &mut dyn FnMut(Item) -> Result<(), Item>, push: &mut dyn FnMut(Item) -> Result<(), Item>,
) -> CmdResult<()> { ) -> CmdResult<()> {
let items = match &item_id { let items = match item_id {
KitSpec::Item(item_id) => vec![ KitEntry::Spec(KitSpec::Item(item_id)) => vec![
Item::new_from_asset(item_id).map_err(|_| format!("Unknown item: {:#?}", item_id))?, Item::new_from_asset(&item_id).map_err(|_| format!("Unknown item: {:#?}", item_id))?,
], ],
KitSpec::ModularWeapon { tool, material } => { KitEntry::Spec(KitSpec::ModularWeapon { tool, material }) => {
comp::item::modular::generate_weapons(*tool, *material, None) comp::item::modular::generate_weapons(tool, material, None)
.map_err(|err| format!("{:#?}", err))? .map_err(|err| format!("{:#?}", err))?
}, },
KitEntry::Item(item) => vec![item],
}; };
let mut res = Ok(()); let mut res = Ok(());