mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Now allows weapons to be swapped between the mainhand and offhand slot. (Probably hacky?)
This commit is contained in:
parent
6b153bcf47
commit
23cc3d671b
@ -167,24 +167,84 @@ impl Loadout {
|
||||
return;
|
||||
}
|
||||
|
||||
enum MainhandHand {
|
||||
MainhandA,
|
||||
MainhandB,
|
||||
}
|
||||
|
||||
let hands_swapping = match (equip_slot_a, equip_slot_b) {
|
||||
(EquipSlot::ActiveMainhand, EquipSlot::ActiveOffhand) => Some(MainhandHand::MainhandA),
|
||||
(EquipSlot::ActiveOffhand, EquipSlot::ActiveMainhand) => Some(MainhandHand::MainhandB),
|
||||
(EquipSlot::InactiveMainhand, EquipSlot::InactiveOffhand) => {
|
||||
Some(MainhandHand::MainhandA)
|
||||
},
|
||||
(EquipSlot::InactiveOffhand, EquipSlot::InactiveMainhand) => {
|
||||
Some(MainhandHand::MainhandB)
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let item_a = self.swap(equip_slot_a, None);
|
||||
let item_b = self.swap(equip_slot_b, None);
|
||||
|
||||
// Check if items can go in the other slots
|
||||
if item_a
|
||||
.as_ref()
|
||||
.map_or(true, |i| self.slot_can_hold(equip_slot_b, &i.kind()))
|
||||
&& item_b
|
||||
.as_ref()
|
||||
.map_or(true, |i| self.slot_can_hold(equip_slot_a, &i.kind()))
|
||||
{
|
||||
// Swap
|
||||
self.swap(equip_slot_b, item_a).unwrap_none();
|
||||
self.swap(equip_slot_a, item_b).unwrap_none();
|
||||
if let Some(hands_swapping) = hands_swapping {
|
||||
match hands_swapping {
|
||||
MainhandHand::MainhandA => {
|
||||
if item_b
|
||||
.as_ref()
|
||||
.map_or(true, |i| self.slot_can_hold(equip_slot_a, &i.kind()))
|
||||
&& item_a
|
||||
.as_ref()
|
||||
.map_or(true, |i| equip_slot_b.can_hold(&i.kind()))
|
||||
{
|
||||
// Checks that item b (from offhand) can go into equip slot a (mainhand
|
||||
// slot) and that item a (from mainhand) is a valid item to insert into
|
||||
// equip slot b (offhand slot) Swap
|
||||
self.swap(equip_slot_a, item_b).unwrap_none();
|
||||
self.swap(equip_slot_b, item_a).unwrap_none();
|
||||
} else {
|
||||
// Otherwise put the items back
|
||||
self.swap(equip_slot_a, item_a).unwrap_none();
|
||||
self.swap(equip_slot_b, item_b).unwrap_none();
|
||||
}
|
||||
},
|
||||
MainhandHand::MainhandB => {
|
||||
if item_a
|
||||
.as_ref()
|
||||
.map_or(true, |i| self.slot_can_hold(equip_slot_b, &i.kind()))
|
||||
&& item_b
|
||||
.as_ref()
|
||||
.map_or(true, |i| equip_slot_b.can_hold(&i.kind()))
|
||||
{
|
||||
// Checks that item a (from offhand) can go into equip slot b (mainhand
|
||||
// slot) and that item b (from mainhand) is a valid item to insert into
|
||||
// equip slot a (offhand slot) Swap
|
||||
self.swap(equip_slot_b, item_a).unwrap_none();
|
||||
self.swap(equip_slot_a, item_b).unwrap_none();
|
||||
} else {
|
||||
// Otherwise put the items back
|
||||
self.swap(equip_slot_a, item_a).unwrap_none();
|
||||
self.swap(equip_slot_b, item_b).unwrap_none();
|
||||
}
|
||||
},
|
||||
}
|
||||
} else {
|
||||
// Otherwise put the items back
|
||||
self.swap(equip_slot_a, item_a).unwrap_none();
|
||||
self.swap(equip_slot_b, item_b).unwrap_none();
|
||||
// Check if items can go in the other slots
|
||||
if item_a
|
||||
.as_ref()
|
||||
.map_or(true, |i| self.slot_can_hold(equip_slot_b, &i.kind()))
|
||||
&& item_b
|
||||
.as_ref()
|
||||
.map_or(true, |i| self.slot_can_hold(equip_slot_a, &i.kind()))
|
||||
{
|
||||
// Swap
|
||||
self.swap(equip_slot_b, item_a).unwrap_none();
|
||||
self.swap(equip_slot_a, item_b).unwrap_none();
|
||||
} else {
|
||||
// Otherwise put the items back
|
||||
self.swap(equip_slot_a, item_a).unwrap_none();
|
||||
self.swap(equip_slot_b, item_b).unwrap_none();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ use std::{cmp::Ordering, convert::TryFrom};
|
||||
|
||||
use crate::comp::{
|
||||
inventory::{
|
||||
item::{armor, armor::ArmorKind, ItemKind},
|
||||
item::{armor, armor::ArmorKind, tool, ItemKind},
|
||||
loadout::LoadoutSlotId,
|
||||
},
|
||||
item,
|
||||
@ -123,9 +123,9 @@ impl EquipSlot {
|
||||
match (self, item_kind) {
|
||||
(Self::Armor(slot), ItemKind::Armor(armor::Armor { kind, .. })) => slot.can_hold(kind),
|
||||
(Self::ActiveMainhand, ItemKind::Tool(_)) => true,
|
||||
(Self::ActiveOffhand, ItemKind::Tool(_)) => true,
|
||||
(Self::ActiveOffhand, ItemKind::Tool(tool)) => matches!(tool.hands, tool::Hands::One),
|
||||
(Self::InactiveMainhand, ItemKind::Tool(_)) => true,
|
||||
(Self::InactiveOffhand, ItemKind::Tool(_)) => true,
|
||||
(Self::InactiveOffhand, ItemKind::Tool(tool)) => matches!(tool.hands, tool::Hands::One),
|
||||
(Self::Lantern, ItemKind::Lantern(_)) => true,
|
||||
(Self::Glider, ItemKind::Glider(_)) => true,
|
||||
_ => false,
|
||||
|
Loading…
Reference in New Issue
Block a user