mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Swapping weapon sets is now functional. (Though very hacky?)
This commit is contained in:
parent
23cc3d671b
commit
19926a2322
@ -423,6 +423,36 @@ impl Loadout {
|
||||
_ => equip_slot.can_hold(item_kind),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn swap_equipped_weapons(&mut self) {
|
||||
// Checks if a given slot can hold an item right now, defaults to true if
|
||||
// nothing is equipped in slot
|
||||
let valid_slot = |equip_slot| {
|
||||
self.equipped(equip_slot)
|
||||
.map_or(true, |i| self.slot_can_hold(equip_slot, i.kind()))
|
||||
};
|
||||
|
||||
if valid_slot(EquipSlot::ActiveMainhand)
|
||||
&& valid_slot(EquipSlot::ActiveOffhand)
|
||||
&& valid_slot(EquipSlot::InactiveMainhand)
|
||||
&& valid_slot(EquipSlot::InactiveOffhand)
|
||||
{
|
||||
// Get weapons from each slot
|
||||
let active_mainhand = self.swap(EquipSlot::ActiveMainhand, None);
|
||||
let active_offhand = self.swap(EquipSlot::ActiveOffhand, None);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -778,6 +778,8 @@ impl Inventory {
|
||||
pub fn equipped_items_of_kind(&self, item_kind: ItemKind) -> impl Iterator<Item = &Item> {
|
||||
self.loadout.equipped_items_of_kind(item_kind)
|
||||
}
|
||||
|
||||
pub fn swap_equipped_weapons(&mut self) { self.loadout.swap_equipped_weapons() }
|
||||
}
|
||||
|
||||
impl Component for Inventory {
|
||||
|
@ -5,14 +5,9 @@ use specs::{
|
||||
|
||||
use common::{
|
||||
comp::{
|
||||
self,
|
||||
inventory::{
|
||||
item::MaterialStatManifest,
|
||||
slot::{EquipSlot, Slot},
|
||||
},
|
||||
Beam, Body, CharacterState, Combo, Controller, Density, Energy, Health, Inventory, Mass,
|
||||
Melee, Mounting, Ori, PhysicsState, Poise, PoiseState, Pos, SkillSet, StateUpdate, Stats,
|
||||
Vel,
|
||||
self, inventory::item::MaterialStatManifest, Beam, Body, CharacterState, Combo, Controller,
|
||||
Density, Energy, Health, Inventory, Mass, Melee, Mounting, Ori, PhysicsState, Poise,
|
||||
PoiseState, Pos, SkillSet, StateUpdate, Stats, Vel,
|
||||
},
|
||||
event::{EventBus, LocalEvent, ServerEvent},
|
||||
outcome::Outcome,
|
||||
@ -48,26 +43,7 @@ fn incorporate_update(join: &mut JoinStruct, mut state_update: StateUpdate) {
|
||||
if state_update.swap_equipped_weapons {
|
||||
let mut inventory = join.inventory.get_mut_unchecked();
|
||||
let inventory = &mut *inventory;
|
||||
assert!(
|
||||
inventory
|
||||
.swap(
|
||||
Slot::Equip(EquipSlot::ActiveMainhand),
|
||||
Slot::Equip(EquipSlot::InactiveMainhand),
|
||||
)
|
||||
.first()
|
||||
.is_none(),
|
||||
"Swapping active and inactive mainhand never results in leftover items",
|
||||
);
|
||||
assert!(
|
||||
inventory
|
||||
.swap(
|
||||
Slot::Equip(EquipSlot::ActiveOffhand),
|
||||
Slot::Equip(EquipSlot::InactiveOffhand),
|
||||
)
|
||||
.first()
|
||||
.is_none(),
|
||||
"Swapping active and inactive offhand never results in leftover items",
|
||||
);
|
||||
inventory.swap_equipped_weapons();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user