From c09f070241b047a2932d10682c358081c946a151 Mon Sep 17 00:00:00 2001 From: N A Date: Sun, 29 May 2022 23:53:00 +0000 Subject: [PATCH] Change animal species to have only one inventory slot --- common/src/comp/inventory/mod.rs | 23 +++++++++++-- common/src/comp/inventory/test.rs | 32 +++++++++---------- common/src/states/basic_summon.rs | 2 +- server/src/character_creator.rs | 2 +- server/src/cmd.rs | 4 +-- server/src/events/player.rs | 2 +- server/src/events/trade.rs | 4 +-- server/src/persistence/character.rs | 2 +- .../src/persistence/character/conversions.rs | 2 +- server/src/state_ext.rs | 4 +-- server/src/sys/terrain.rs | 2 +- .../audio/sfx/event_mapper/combat/tests.rs | 10 +++--- voxygen/src/menu/char_selection/ui/mod.rs | 2 +- 13 files changed, 55 insertions(+), 36 deletions(-) diff --git a/common/src/comp/inventory/mod.rs b/common/src/comp/inventory/mod.rs index 37c4e33070..e5cdaa2988 100644 --- a/common/src/comp/inventory/mod.rs +++ b/common/src/comp/inventory/mod.rs @@ -8,6 +8,7 @@ use vek::Vec3; use crate::{ comp::{ + body::Body, inventory::{ item::{tool::AbilityMap, ItemDef, ItemKind, MaterialStatManifest, TagExampleInfo}, loadout::Loadout, @@ -80,9 +81,19 @@ impl InventorySortOrder { /// that contains items etc) must first ensure items are unloaded from the item. /// This is handled in `inventory\slot.rs` impl Inventory { - pub fn new_empty() -> Inventory { Self::new_with_loadout(LoadoutBuilder::empty().build()) } + pub fn with_empty() -> Inventory { + Self::with_loadout_humanoid(LoadoutBuilder::empty().build()) + } - pub fn new_with_loadout(loadout: Loadout) -> Inventory { + pub fn with_loadout(loadout: Loadout, body: Body) -> Inventory { + if let Body::Humanoid(_) = body { + Self::with_loadout_humanoid(loadout) + } else { + Self::with_loadout_animal(loadout) + } + } + + pub fn with_loadout_humanoid(loadout: Loadout) -> Inventory { Inventory { next_sort_order: InventorySortOrder::Name, loadout, @@ -90,6 +101,14 @@ impl Inventory { } } + pub fn with_loadout_animal(loadout: Loadout) -> Inventory { + Inventory { + next_sort_order: InventorySortOrder::Name, + loadout, + slots: vec![None; 1], + } + } + /// Total number of slots in in the inventory. pub fn capacity(&self) -> usize { self.slots().count() } diff --git a/common/src/comp/inventory/test.rs b/common/src/comp/inventory/test.rs index e65d9748ec..c7d7e65b1e 100644 --- a/common/src/comp/inventory/test.rs +++ b/common/src/comp/inventory/test.rs @@ -124,7 +124,7 @@ fn push_all_unique_empty() { fn free_slots_minus_equipped_item_items_only_present_in_equipped_bag_slots() { let msm = &MaterialStatManifest::load().read(); let ability_map = &AbilityMap::load().read(); - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let bag = get_test_bag(18); let bag1_slot = EquipSlot::Armor(ArmorSlot::Bag1); @@ -144,7 +144,7 @@ fn free_slots_minus_equipped_item_items_only_present_in_equipped_bag_slots() { fn free_slots_minus_equipped_item() { let msm = &MaterialStatManifest::load().read(); let ability_map = &AbilityMap::load().read(); - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let bag = get_test_bag(18); let bag1_slot = EquipSlot::Armor(ArmorSlot::Bag1); @@ -166,7 +166,7 @@ fn free_slots_minus_equipped_item() { #[test] fn get_slot_range_for_equip_slot() { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let bag = get_test_bag(18); let bag1_slot = EquipSlot::Armor(ArmorSlot::Bag1); inv.loadout.swap(bag1_slot, Some(bag)); @@ -196,7 +196,7 @@ fn can_swap_equipped_bag_into_empty_inv_slot( inv_slot_id: InvSlotId, expected_result: bool, ) { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); inv.replace_loadout_item(EquipSlot::Armor(ArmorSlot::Bag1), Some(get_test_bag(18))); @@ -209,7 +209,7 @@ fn can_swap_equipped_bag_into_empty_inv_slot( #[test] fn can_swap_equipped_bag_into_only_empty_slot_provided_by_itself_should_return_true() { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); inv.replace_loadout_item(EquipSlot::Armor(ArmorSlot::Bag1), Some(get_test_bag(18))); @@ -224,7 +224,7 @@ fn can_swap_equipped_bag_into_only_empty_slot_provided_by_itself_should_return_t fn unequip_items_both_hands() { let msm = &MaterialStatManifest::load().read(); let ability_map = &AbilityMap::load().read(); - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let sword = Item::new_from_asset_expect("common.items.weapons.sword.starter"); @@ -267,7 +267,7 @@ fn equip_replace_already_equipped_item() { "common.items.armor.misc.foot.sandals", )); - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); inv.push(boots.duplicate(ability_map, msm)).unwrap(); inv.replace_loadout_item( EquipSlot::Armor(ArmorSlot::Feet), @@ -294,7 +294,7 @@ fn equip_replace_already_equipped_item() { /// after equipping it (because the equipped bag is larger) #[test] fn equip_equipping_smaller_bag_from_last_slot_of_big_bag() { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); const LARGE_BAG_ID: &str = "common.items.testing.test_bag_18_slot"; let small_bag = get_test_bag(9); @@ -322,7 +322,7 @@ fn equip_equipping_smaller_bag_from_last_slot_of_big_bag() { #[test] fn unequip_unequipping_bag_into_its_own_slot_with_no_other_free_slots_returns_one_item() { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let bag = get_test_bag(9); assert!( @@ -350,7 +350,7 @@ fn unequip_unequipping_bag_into_its_own_slot_with_no_other_free_slots_returns_on fn equip_one_bag_equipped_equip_second_bag() { let msm = &MaterialStatManifest::load().read(); let ability_map = &AbilityMap::load().read(); - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let bag = get_test_bag(9); assert!( @@ -371,7 +371,7 @@ fn equip_one_bag_equipped_equip_second_bag() { #[test] fn free_after_swap_equipped_item_has_more_slots() { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let bag = get_test_bag(18); assert!( @@ -394,7 +394,7 @@ fn free_after_swap_equipped_item_has_more_slots() { #[test] fn free_after_swap_equipped_item_has_less_slots() { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let bag = get_test_bag(9); assert!( @@ -417,7 +417,7 @@ fn free_after_swap_equipped_item_has_less_slots() { #[test] fn free_after_swap_equipped_item_with_slots_swapped_with_empty_inv_slot() { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let bag = get_test_bag(9); assert!( @@ -437,7 +437,7 @@ fn free_after_swap_equipped_item_with_slots_swapped_with_empty_inv_slot() { #[test] fn free_after_swap_inv_item_with_slots_swapped_with_empty_equip_slot() { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); inv.push(get_test_bag(9)).unwrap(); @@ -452,7 +452,7 @@ fn free_after_swap_inv_item_with_slots_swapped_with_empty_equip_slot() { #[test] fn free_after_swap_inv_item_without_slots_swapped_with_empty_equip_slot() { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let boots = Item::new_from_asset_expect("common.items.testing.test_boots"); inv.push(boots).unwrap(); @@ -471,7 +471,7 @@ fn free_after_swap_inv_item_without_slots_swapped_with_empty_equip_slot() { // provide slots. #[test] fn backpack_crash() { - let mut inv = Inventory::new_empty(); + let mut inv = Inventory::with_empty(); let backpack = Item::new_from_asset_expect("common.items.armor.misc.back.backpack"); inv.loadout diff --git a/common/src/states/basic_summon.rs b/common/src/states/basic_summon.rs index 317e4b183f..ba77b32bd7 100644 --- a/common/src/states/basic_summon.rs +++ b/common/src/states/basic_summon.rs @@ -179,7 +179,7 @@ impl CharacterBehavior for Data { skill_set, health, poise: comp::Poise::new(body), - inventory: comp::Inventory::new_with_loadout(loadout), + inventory: comp::Inventory::with_loadout(loadout, body), body, agent: Some( comp::Agent::from_body(&body) diff --git a/server/src/character_creator.rs b/server/src/character_creator.rs index e1cfbf0541..96c3d5cbc2 100644 --- a/server/src/character_creator.rs +++ b/server/src/character_creator.rs @@ -50,7 +50,7 @@ pub fn create_character( .active_mainhand(character_mainhand.map(|x| Item::new_from_asset_expect(&x))) .active_offhand(character_offhand.map(|x| Item::new_from_asset_expect(&x))) .build(); - let mut inventory = Inventory::new_with_loadout(loadout); + let mut inventory = Inventory::with_loadout_humanoid(loadout); let stats = Stats::new(character_alias.to_string()); let skill_set = SkillSet::default(); // Default items for new characters diff --git a/server/src/cmd.rs b/server/src/cmd.rs index eba2cc0870..f631b728f6 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1201,7 +1201,7 @@ fn handle_spawn( let body = body(); let loadout = LoadoutBuilder::from_default(&body).build(); - let inventory = Inventory::new_with_loadout(loadout); + let inventory = Inventory::with_loadout(loadout, body); let mut entity_base = server .state @@ -1293,7 +1293,7 @@ fn handle_spawn_training_dummy( skill_set, Some(health), poise, - Inventory::new_empty(), + Inventory::with_empty(), body, ) .with(comp::Vel(vel)) diff --git a/server/src/events/player.rs b/server/src/events/player.rs index 5fdc6616ae..0f63e53625 100644 --- a/server/src/events/player.rs +++ b/server/src/events/player.rs @@ -447,7 +447,7 @@ pub fn handle_possess(server: &mut Server, possessor_uid: Uid, possessee_uid: Ui let mut inventory = inventories .entry(possessee) .expect("Nobody has &mut World, so there's no way to delete an entity.") - .or_insert(Inventory::new_empty()); + .or_insert(Inventory::with_empty()); let debug_item = comp::Item::new_from_asset_expect("common.items.debug.admin_stick"); if let item::ItemKind::Tool(_) = &*debug_item.kind() { diff --git a/server/src/events/trade.rs b/server/src/events/trade.rs index e2bad21292..aa239aad24 100644 --- a/server/src/events/trade.rs +++ b/server/src/events/trade.rs @@ -428,12 +428,12 @@ mod tests { let player: EcsEntity = mockworld .create_entity() - .with(Inventory::new_empty()) + .with(Inventory::with_empty()) .build(); let merchant: EcsEntity = mockworld .create_entity() - .with(Inventory::new_empty()) + .with(Inventory::with_empty()) .build(); { diff --git a/server/src/persistence/character.rs b/server/src/persistence/character.rs index 943dabff96..5d79df0d5e 100644 --- a/server/src/persistence/character.rs +++ b/server/src/persistence/character.rs @@ -339,7 +339,7 @@ pub fn load_character_list(player_uuid_: &str, connection: &Connection) -> Chara Ok(CharacterItem { character: char, body: char_body, - inventory: Inventory::new_with_loadout(loadout), + inventory: Inventory::with_loadout_humanoid(loadout), }) }) .collect() diff --git a/server/src/persistence/character/conversions.rs b/server/src/persistence/character/conversions.rs index 21cdd22b82..23b6da224d 100644 --- a/server/src/persistence/character/conversions.rs +++ b/server/src/persistence/character/conversions.rs @@ -349,7 +349,7 @@ pub fn convert_inventory_from_database_items( // inventory at the correct position. // let loadout = convert_loadout_from_database_items(loadout_container_id, loadout_items)?; - let mut inventory = Inventory::new_with_loadout(loadout); + let mut inventory = Inventory::with_loadout_humanoid(loadout); let mut item_indices = HashMap::new(); // In order to items with components to properly load, it is important that this diff --git a/server/src/state_ext.rs b/server/src/state_ext.rs index ef99603136..602b05855a 100644 --- a/server/src/state_ext.rs +++ b/server/src/state_ext.rs @@ -306,7 +306,7 @@ impl StateExt for State { .with(body) .with(comp::Scale(comp::ship::AIRSHIP_SCALE)) .with(comp::Controller::default()) - .with(comp::inventory::Inventory::new_empty()) + .with(comp::inventory::Inventory::with_empty()) .with(comp::CharacterState::default()) // TODO: some of these are required in order for the character_behavior system to // recognize a possesed airship; that system should be refactored to use `.maybe()` @@ -597,7 +597,7 @@ impl StateExt for State { comp::SkillSet::default(), Some(comp::Health::new(body, DEFAULT_PET_HEALTH_LEVEL)), Poise::new(body), - Inventory::new_empty(), + Inventory::with_empty(), body, ) .with(comp::Scale(1.0)) diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 967c20c2e5..7dda1c5a52 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -389,7 +389,7 @@ impl NpcData { loadout_builder = loadout_builder.with_creator(make_loadout, economy.as_ref()); } let loadout = loadout_builder.build(); - let mut inventory = comp::inventory::Inventory::new_with_loadout(loadout); + let mut inventory = comp::inventory::Inventory::with_loadout(loadout, body); for (num, mut item) in items { if let Err(e) = item.set_amount(num) { tracing::warn!( diff --git a/voxygen/src/audio/sfx/event_mapper/combat/tests.rs b/voxygen/src/audio/sfx/event_mapper/combat/tests.rs index f4b4e89e38..b3b0b0eac8 100644 --- a/voxygen/src/audio/sfx/event_mapper/combat/tests.rs +++ b/voxygen/src/audio/sfx/event_mapper/combat/tests.rs @@ -17,7 +17,7 @@ fn maps_wield_while_equipping() { "common.items.weapons.axe.starter_axe", ))) .build(); - let inventory = Inventory::new_with_loadout(loadout); + let inventory = Inventory::with_loadout_humanoid(loadout); let result = CombatEventMapper::map_event( &CharacterState::Equipping(states::equipping::Data { @@ -45,7 +45,7 @@ fn maps_unwield() { "common.items.weapons.bow.starter", ))) .build(); - let inventory = Inventory::new_with_loadout(loadout); + let inventory = Inventory::with_loadout_humanoid(loadout); let result = CombatEventMapper::map_event( &CharacterState::default(), @@ -67,7 +67,7 @@ fn maps_basic_melee() { "common.items.weapons.axe.starter_axe", ))) .build(); - let inventory = Inventory::new_with_loadout(loadout); + let inventory = Inventory::with_loadout_humanoid(loadout); let result = CombatEventMapper::map_event( &CharacterState::BasicMelee(states::basic_melee::Data { @@ -118,7 +118,7 @@ fn matches_ability_stage() { "common.items.weapons.sword.starter", ))) .build(); - let inventory = Inventory::new_with_loadout(loadout); + let inventory = Inventory::with_loadout_humanoid(loadout); let result = CombatEventMapper::map_event( &CharacterState::ComboMelee(states::combo_melee::Data { @@ -180,7 +180,7 @@ fn ignores_different_ability_stage() { "common.items.weapons.axe.starter_axe", ))) .build(); - let inventory = Inventory::new_with_loadout(loadout); + let inventory = Inventory::with_loadout_humanoid(loadout); let result = CombatEventMapper::map_event( &CharacterState::ComboMelee(states::combo_melee::Data { diff --git a/voxygen/src/menu/char_selection/ui/mod.rs b/voxygen/src/menu/char_selection/ui/mod.rs index aa3d948f07..5108630834 100644 --- a/voxygen/src/menu/char_selection/ui/mod.rs +++ b/voxygen/src/menu/char_selection/ui/mod.rs @@ -202,7 +202,7 @@ impl Mode { .active_offhand(offhand.map(Item::new_from_asset_expect)) .build(); - let inventory = Box::new(Inventory::new_with_loadout(loadout)); + let inventory = Box::new(Inventory::with_loadout_humanoid(loadout)); Self::CreateOrEdit { name,