diff --git a/common/src/comp/inventory/loadout.rs b/common/src/comp/inventory/loadout.rs index b0ebde4170..b519959588 100644 --- a/common/src/comp/inventory/loadout.rs +++ b/common/src/comp/inventory/loadout.rs @@ -260,7 +260,7 @@ impl Loadout { pub(super) fn inv_slots_mut(&mut self) -> impl Iterator { self.slots.iter_mut() .filter_map(|x| x.slot.as_mut().map(|item| item.slots_mut())) // Discard loadout items that have no slots of their own - .flat_map(|loadout_slots| loadout_slots.iter_mut()) //Collapse iter of Vec to iter of InvSlot + .flat_map(|loadout_slots| loadout_slots.iter_mut()) //Collapse iter of Vec to iter of InvSlot } /// Gets the range of loadout-provided inventory slot indexes that are @@ -328,26 +328,47 @@ impl Loadout { equip_slot: EquipSlot, item_kind: Option<&ItemKind>, ) -> bool { - let weapon_compare_slots = match equip_slot { - EquipSlot::ActiveMainhand | EquipSlot::ActiveOffhand => { - Some((EquipSlot::ActiveMainhand, EquipSlot::ActiveOffhand)) - }, - EquipSlot::InactiveMainhand | EquipSlot::InactiveOffhand => { - Some((EquipSlot::InactiveMainhand, EquipSlot::InactiveOffhand)) - }, - _ => None, - }; + // let weapon_compare_slots = match equip_slot { + // EquipSlot::ActiveMainhand | EquipSlot::ActiveOffhand => { + // Some((EquipSlot::ActiveMainhand, EquipSlot::ActiveOffhand)) + // }, + // EquipSlot::InactiveMainhand | EquipSlot::InactiveOffhand => { + // Some((EquipSlot::InactiveMainhand, EquipSlot::InactiveOffhand)) + // }, + // _ => None, + // }; + if !(match equip_slot { + EquipSlot::ActiveMainhand => Loadout::is_valid_weapon_pair( + item_kind, + self.equipped(EquipSlot::ActiveOffhand).map(|x| &x.kind), + ), + EquipSlot::ActiveOffhand => Loadout::is_valid_weapon_pair( + self.equipped(EquipSlot::ActiveMainhand).map(|x| &x.kind), + item_kind, + ), + EquipSlot::InactiveMainhand => Loadout::is_valid_weapon_pair( + item_kind, + self.equipped(EquipSlot::InactiveOffhand).map(|x| &x.kind), + ), + EquipSlot::InactiveOffhand => Loadout::is_valid_weapon_pair( + self.equipped(EquipSlot::InactiveMainhand).map(|x| &x.kind), + item_kind, + ), + _ => true, + }) { + return false; + } // Disallow equipping incompatible weapon pairs (i.e a two-handed weapon and a // one-handed weapon) - if let Some(weapon_compare_slots) = weapon_compare_slots { - if !Loadout::is_valid_weapon_pair( - self.equipped(weapon_compare_slots.0).map(|x| &x.kind), - self.equipped(weapon_compare_slots.1).map(|x| &x.kind), - ) { - return false; - } - } + // if let Some(weapon_compare_slots) = weapon_compare_slots { + // if !Loadout::is_valid_weapon_pair( + // self.equipped(weapon_compare_slots.0).map(|x| &x.kind), + // self.equipped(weapon_compare_slots.1).map(|x| &x.kind), + // ) { + // return false; + // } + // } item_kind.map_or(true, |item_kind| equip_slot.can_hold(item_kind)) } @@ -369,6 +390,10 @@ impl Loadout { .map_or(true, |i| self.slot_can_hold(equip_slot, Some(i.kind()))) }; + // If every weapon is currently in a valid slot, after this change they will + // still be in a valid slot. This is because active mainhand and + // inactive mainhand, and active offhand and inactive offhand have the same + // requirements on what can be equipped. if valid_slot(EquipSlot::ActiveMainhand) && valid_slot(EquipSlot::ActiveOffhand) && valid_slot(EquipSlot::InactiveMainhand) @@ -380,14 +405,22 @@ impl Loadout { let inactive_mainhand = self.swap(EquipSlot::InactiveMainhand, None); let inactive_offhand = self.swap(EquipSlot::InactiveOffhand, None); // Equip weapons into new slots - self.swap(EquipSlot::ActiveMainhand, inactive_mainhand) - .unwrap_none(); - self.swap(EquipSlot::ActiveOffhand, inactive_offhand) - .unwrap_none(); - self.swap(EquipSlot::InactiveMainhand, active_mainhand) - .unwrap_none(); - self.swap(EquipSlot::InactiveOffhand, active_offhand) - .unwrap_none(); + assert!( + self.swap(EquipSlot::ActiveMainhand, inactive_mainhand) + .is_none() + ); + assert!( + self.swap(EquipSlot::ActiveOffhand, inactive_offhand) + .is_none() + ); + assert!( + self.swap(EquipSlot::InactiveMainhand, active_mainhand) + .is_none() + ); + assert!( + self.swap(EquipSlot::InactiveOffhand, active_offhand) + .is_none() + ); } } } diff --git a/common/src/comp/inventory/mod.rs b/common/src/comp/inventory/mod.rs index 0fed36145a..ff0bfb11f4 100644 --- a/common/src/comp/inventory/mod.rs +++ b/common/src/comp/inventory/mod.rs @@ -577,7 +577,7 @@ impl Inventory { + i32::try_from(slots_from_inv).expect("Inventory item with more than i32::MAX slots") - i32::try_from(self.populated_slots()) .expect("Inventory item with more than i32::MAX used slots") - + inv_slot_for_equipped // If there is no item already in the equip slot we gain 1 slot + + inv_slot_for_equipped // If there is no item already in the equip slot we gain 1 slot } /// Handles picking up an item, unloading any items inside the item being @@ -640,7 +640,7 @@ impl Inventory { .expect("Equipped item with more than i32::MAX slots") - i32::try_from(self.populated_slots()) .expect("Inventory item with more than i32::MAX used slots") - - inv_slot_for_unequipped // If there is an item being unequipped we lose 1 slot + - inv_slot_for_unequipped // If there is an item being unequipped we lose 1 slot } /// Swaps items from two slots, regardless of if either is inventory or @@ -684,7 +684,7 @@ impl Inventory { - i32::try_from(self.populated_slots()) .expect("inventory with more than i32::MAX used slots") - inv_slot_for_equipped // +1 inventory slot required if an item was unequipped - + inv_slot_for_inv_item // -1 inventory slot required if an item was equipped + + inv_slot_for_inv_item // -1 inventory slot required if an item was equipped } /// Swap item in an inventory slot with one in a loadout slot. @@ -730,9 +730,11 @@ impl Inventory { && self.loadout.equipped(EquipSlot::ActiveOffhand).is_some() { let offhand = self.loadout.swap(EquipSlot::ActiveOffhand, None); - self.loadout - .swap(EquipSlot::ActiveMainhand, offhand) - .unwrap_none(); + assert!( + self.loadout + .swap(EquipSlot::ActiveMainhand, offhand) + .is_none() + ); } }, EquipSlot::InactiveMainhand => { @@ -740,9 +742,11 @@ impl Inventory { && self.loadout.equipped(EquipSlot::InactiveOffhand).is_some() { let offhand = self.loadout.swap(EquipSlot::InactiveOffhand, None); - self.loadout - .swap(EquipSlot::InactiveMainhand, offhand) - .unwrap_none(); + assert!( + self.loadout + .swap(EquipSlot::InactiveMainhand, offhand) + .is_none() + ); } }, _ => {}, diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 880fc594e1..c7eff5efe7 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -452,7 +452,7 @@ pub fn attempt_wield(data: &JoinData, update: &mut StateUpdate) { .map(|(item, tool)| tool.equip_time(data.msm, item.components())) }; - // Calcualtes time required to equip weapons, if weapon in mainhand and offhand, + // Calculates time required to equip weapons, if weapon in mainhand and offhand, // uses maximum duration let mainhand_equip_time = equip_time(EquipSlot::ActiveMainhand); let offhand_equip_time = equip_time(EquipSlot::ActiveOffhand); diff --git a/voxygen/src/hud/bag.rs b/voxygen/src/hud/bag.rs index 844797a42a..e6f69b6b00 100644 --- a/voxygen/src/hud/bag.rs +++ b/voxygen/src/hud/bag.rs @@ -1004,10 +1004,10 @@ impl<'a> Widget for Bag<'a> { } // Ring let ring1_item = inventory - .equipped(EquipSlot::InactiveOffhand) + .equipped(EquipSlot::Armor(ArmorSlot::Ring1)) .map(|item| item.to_owned()); let slot = slot_maker - .fabricate(EquipSlot::InactiveOffhand, [45.0; 2]) + .fabricate(EquipSlot::Armor(ArmorSlot::Ring1), [45.0; 2]) .bottom_left_with_margins_on(state.ids.hands_slot, -55.0, 0.0) .with_icon(self.imgs.ring_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN)) .filled_slot(filled_slot); @@ -1026,10 +1026,10 @@ impl<'a> Widget for Bag<'a> { } // Ring 2 let ring2_item = inventory - .equipped(EquipSlot::InactiveMainhand) + .equipped(EquipSlot::Armor(ArmorSlot::Ring2)) .map(|item| item.to_owned()); let slot = slot_maker - .fabricate(EquipSlot::InactiveMainhand, [45.0; 2]) + .fabricate(EquipSlot::Armor(ArmorSlot::Ring2), [45.0; 2]) .bottom_right_with_margins_on(state.ids.shoulders_slot, -55.0, 0.0) .with_icon(self.imgs.ring_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN)) .filled_slot(filled_slot);