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;
|
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_a = self.swap(equip_slot_a, None);
|
||||||
let item_b = self.swap(equip_slot_b, None);
|
let item_b = self.swap(equip_slot_b, None);
|
||||||
|
|
||||||
// Check if items can go in the other slots
|
if let Some(hands_swapping) = hands_swapping {
|
||||||
if item_a
|
match hands_swapping {
|
||||||
.as_ref()
|
MainhandHand::MainhandA => {
|
||||||
.map_or(true, |i| self.slot_can_hold(equip_slot_b, &i.kind()))
|
if item_b
|
||||||
&& item_b
|
.as_ref()
|
||||||
.as_ref()
|
.map_or(true, |i| self.slot_can_hold(equip_slot_a, &i.kind()))
|
||||||
.map_or(true, |i| self.slot_can_hold(equip_slot_a, &i.kind()))
|
&& item_a
|
||||||
{
|
.as_ref()
|
||||||
// Swap
|
.map_or(true, |i| equip_slot_b.can_hold(&i.kind()))
|
||||||
self.swap(equip_slot_b, item_a).unwrap_none();
|
{
|
||||||
self.swap(equip_slot_a, item_b).unwrap_none();
|
// 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 {
|
} else {
|
||||||
// Otherwise put the items back
|
// Check if items can go in the other slots
|
||||||
self.swap(equip_slot_a, item_a).unwrap_none();
|
if item_a
|
||||||
self.swap(equip_slot_b, item_b).unwrap_none();
|
.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::{
|
use crate::comp::{
|
||||||
inventory::{
|
inventory::{
|
||||||
item::{armor, armor::ArmorKind, ItemKind},
|
item::{armor, armor::ArmorKind, tool, ItemKind},
|
||||||
loadout::LoadoutSlotId,
|
loadout::LoadoutSlotId,
|
||||||
},
|
},
|
||||||
item,
|
item,
|
||||||
@ -123,9 +123,9 @@ impl EquipSlot {
|
|||||||
match (self, item_kind) {
|
match (self, item_kind) {
|
||||||
(Self::Armor(slot), ItemKind::Armor(armor::Armor { kind, .. })) => slot.can_hold(kind),
|
(Self::Armor(slot), ItemKind::Armor(armor::Armor { kind, .. })) => slot.can_hold(kind),
|
||||||
(Self::ActiveMainhand, ItemKind::Tool(_)) => true,
|
(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::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::Lantern, ItemKind::Lantern(_)) => true,
|
||||||
(Self::Glider, ItemKind::Glider(_)) => true,
|
(Self::Glider, ItemKind::Glider(_)) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
Loading…
Reference in New Issue
Block a user