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

@ -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
assert!(
self.swap(EquipSlot::ActiveMainhand, inactive_mainhand) self.swap(EquipSlot::ActiveMainhand, inactive_mainhand)
.unwrap_none(); .is_none()
);
assert!(
self.swap(EquipSlot::ActiveOffhand, inactive_offhand) self.swap(EquipSlot::ActiveOffhand, inactive_offhand)
.unwrap_none(); .is_none()
);
assert!(
self.swap(EquipSlot::InactiveMainhand, active_mainhand) self.swap(EquipSlot::InactiveMainhand, active_mainhand)
.unwrap_none(); .is_none()
);
assert!(
self.swap(EquipSlot::InactiveOffhand, active_offhand) self.swap(EquipSlot::InactiveOffhand, active_offhand)
.unwrap_none(); .is_none()
);
} }
} }
} }

View File

@ -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);
assert!(
self.loadout self.loadout
.swap(EquipSlot::ActiveMainhand, offhand) .swap(EquipSlot::ActiveMainhand, offhand)
.unwrap_none(); .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);
assert!(
self.loadout self.loadout
.swap(EquipSlot::InactiveMainhand, offhand) .swap(EquipSlot::InactiveMainhand, offhand)
.unwrap_none(); .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);