Fixed comments and some functionality.

This commit is contained in:
Sam 2021-05-16 21:35:17 -05:00
parent 951b006e1c
commit daafde048f
4 changed files with 77 additions and 40 deletions

View File

@ -260,7 +260,7 @@ impl Loadout {
pub(super) fn inv_slots_mut(&mut self) -> impl Iterator<Item = &mut InvSlot> { pub(super) fn inv_slots_mut(&mut self) -> impl Iterator<Item = &mut InvSlot> {
self.slots.iter_mut() 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 .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<InvSlot> to iter of InvSlot .flat_map(|loadout_slots| loadout_slots.iter_mut()) //Collapse iter of Vec<InvSlot> to iter of InvSlot
} }
/// Gets the range of loadout-provided inventory slot indexes that are /// Gets the range of loadout-provided inventory slot indexes that are
@ -328,26 +328,47 @@ impl Loadout {
equip_slot: EquipSlot, equip_slot: EquipSlot,
item_kind: Option<&ItemKind>, item_kind: Option<&ItemKind>,
) -> bool { ) -> bool {
let weapon_compare_slots = match equip_slot { // let weapon_compare_slots = match equip_slot {
EquipSlot::ActiveMainhand | EquipSlot::ActiveOffhand => { // EquipSlot::ActiveMainhand | EquipSlot::ActiveOffhand => {
Some((EquipSlot::ActiveMainhand, EquipSlot::ActiveOffhand)) // Some((EquipSlot::ActiveMainhand, EquipSlot::ActiveOffhand))
}, // },
EquipSlot::InactiveMainhand | EquipSlot::InactiveOffhand => { // EquipSlot::InactiveMainhand | EquipSlot::InactiveOffhand => {
Some((EquipSlot::InactiveMainhand, EquipSlot::InactiveOffhand)) // Some((EquipSlot::InactiveMainhand, EquipSlot::InactiveOffhand))
}, // },
_ => None, // _ => 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 // Disallow equipping incompatible weapon pairs (i.e a two-handed weapon and a
// one-handed weapon) // one-handed weapon)
if let Some(weapon_compare_slots) = weapon_compare_slots { // if let Some(weapon_compare_slots) = weapon_compare_slots {
if !Loadout::is_valid_weapon_pair( // if !Loadout::is_valid_weapon_pair(
self.equipped(weapon_compare_slots.0).map(|x| &x.kind), // self.equipped(weapon_compare_slots.0).map(|x| &x.kind),
self.equipped(weapon_compare_slots.1).map(|x| &x.kind), // self.equipped(weapon_compare_slots.1).map(|x| &x.kind),
) { // ) {
return false; // return false;
} // }
} // }
item_kind.map_or(true, |item_kind| equip_slot.can_hold(item_kind)) 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()))) .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) if valid_slot(EquipSlot::ActiveMainhand)
&& valid_slot(EquipSlot::ActiveOffhand) && valid_slot(EquipSlot::ActiveOffhand)
&& valid_slot(EquipSlot::InactiveMainhand) && valid_slot(EquipSlot::InactiveMainhand)
@ -380,14 +405,22 @@ impl Loadout {
let inactive_mainhand = self.swap(EquipSlot::InactiveMainhand, None); let inactive_mainhand = self.swap(EquipSlot::InactiveMainhand, None);
let inactive_offhand = self.swap(EquipSlot::InactiveOffhand, None); let inactive_offhand = self.swap(EquipSlot::InactiveOffhand, None);
// Equip weapons into new slots // Equip weapons into new slots
self.swap(EquipSlot::ActiveMainhand, inactive_mainhand) assert!(
.unwrap_none(); self.swap(EquipSlot::ActiveMainhand, inactive_mainhand)
self.swap(EquipSlot::ActiveOffhand, inactive_offhand) .is_none()
.unwrap_none(); );
self.swap(EquipSlot::InactiveMainhand, active_mainhand) assert!(
.unwrap_none(); self.swap(EquipSlot::ActiveOffhand, inactive_offhand)
self.swap(EquipSlot::InactiveOffhand, active_offhand) .is_none()
.unwrap_none(); );
assert!(
self.swap(EquipSlot::InactiveMainhand, active_mainhand)
.is_none()
);
assert!(
self.swap(EquipSlot::InactiveOffhand, active_offhand)
.is_none()
);
} }
} }
} }

View File

@ -577,7 +577,7 @@ impl Inventory {
+ i32::try_from(slots_from_inv).expect("Inventory item with more than i32::MAX slots") + i32::try_from(slots_from_inv).expect("Inventory item with more than i32::MAX slots")
- i32::try_from(self.populated_slots()) - i32::try_from(self.populated_slots())
.expect("Inventory item with more than i32::MAX used 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 /// 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") .expect("Equipped item with more than i32::MAX slots")
- i32::try_from(self.populated_slots()) - i32::try_from(self.populated_slots())
.expect("Inventory item with more than i32::MAX used 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 /// Swaps items from two slots, regardless of if either is inventory or
@ -684,7 +684,7 @@ impl Inventory {
- i32::try_from(self.populated_slots()) - i32::try_from(self.populated_slots())
.expect("inventory with more than i32::MAX used 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_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. /// 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() && self.loadout.equipped(EquipSlot::ActiveOffhand).is_some()
{ {
let offhand = self.loadout.swap(EquipSlot::ActiveOffhand, None); let offhand = self.loadout.swap(EquipSlot::ActiveOffhand, None);
self.loadout assert!(
.swap(EquipSlot::ActiveMainhand, offhand) self.loadout
.unwrap_none(); .swap(EquipSlot::ActiveMainhand, offhand)
.is_none()
);
} }
}, },
EquipSlot::InactiveMainhand => { EquipSlot::InactiveMainhand => {
@ -740,9 +742,11 @@ impl Inventory {
&& self.loadout.equipped(EquipSlot::InactiveOffhand).is_some() && self.loadout.equipped(EquipSlot::InactiveOffhand).is_some()
{ {
let offhand = self.loadout.swap(EquipSlot::InactiveOffhand, None); let offhand = self.loadout.swap(EquipSlot::InactiveOffhand, None);
self.loadout assert!(
.swap(EquipSlot::InactiveMainhand, offhand) self.loadout
.unwrap_none(); .swap(EquipSlot::InactiveMainhand, offhand)
.is_none()
);
} }
}, },
_ => {}, _ => {},

View File

@ -452,7 +452,7 @@ pub fn attempt_wield(data: &JoinData, update: &mut StateUpdate) {
.map(|(item, tool)| tool.equip_time(data.msm, item.components())) .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 // uses maximum duration
let mainhand_equip_time = equip_time(EquipSlot::ActiveMainhand); let mainhand_equip_time = equip_time(EquipSlot::ActiveMainhand);
let offhand_equip_time = equip_time(EquipSlot::ActiveOffhand); let offhand_equip_time = equip_time(EquipSlot::ActiveOffhand);

View File

@ -1004,10 +1004,10 @@ impl<'a> Widget for Bag<'a> {
} }
// Ring // Ring
let ring1_item = inventory let ring1_item = inventory
.equipped(EquipSlot::InactiveOffhand) .equipped(EquipSlot::Armor(ArmorSlot::Ring1))
.map(|item| item.to_owned()); .map(|item| item.to_owned());
let slot = slot_maker 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) .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)) .with_icon(self.imgs.ring_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
@ -1026,10 +1026,10 @@ impl<'a> Widget for Bag<'a> {
} }
// Ring 2 // Ring 2
let ring2_item = inventory let ring2_item = inventory
.equipped(EquipSlot::InactiveMainhand) .equipped(EquipSlot::Armor(ArmorSlot::Ring2))
.map(|item| item.to_owned()); .map(|item| item.to_owned());
let slot = slot_maker 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) .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)) .with_icon(self.imgs.ring_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);