MUnique/OpenMU

Prevent equipping weapons and shields when not enough hands are free

Closed this issue · 3 comments

Describe the bug
Two handed weapons can be equipped, even if a shield is already equipped.

To Reproduce
Steps to reproduce the behavior:

  1. Enter the game with a wizard character which has a Chaos Lightning Staff and a Skull Shield.
  2. Equip the shield
  3. Equip the staff
  4. See that both are equipped, even if the staff requires both hands to wear it.

Expected behavior
The staff should not be able to be equipped.
Also, if you equip the staff first, the shield should not be able to be equipped.

Additional context
We can determine if a weapon requires two hands based on the width of the item. Every weapon which needs two hands is at least 2 fields wide.
The behavior is wrongly implemented here, as it only considers to prevent equipping, when the item to equip is a weapon which can be equipped on both hands (one-handed swords), and there is already an two-handed item equipped on the left hand:

if (itemDefinition.ItemSlot.ItemSlots.Contains(RightHandSlot)
&& itemDefinition.ItemSlot.ItemSlots.Contains(LeftHandSlot)
&& toSlot == RightHandSlot
&& storage.GetItem(LeftHandSlot)?.Definition!.Width >= 2)
{
return Movement.None;
}

This logic needs to consider more cases, probably even preventing to equip a shield when an elf already equipped a bow or crossbow.
For elfs there is an exception for arrows and bolts - they occupy a slot, but not use any hand. However, when arrows or bolts are equipped it makes to sense to allow shields.

Thank you for the excellent summary.

After discovering the staff-shield situation, I did some tests. It appears that the client already prevents most invalid combinations, with shields being the primary exceptions.

I've opened Issue #393 to address these shield cases.

Yea, however, we should also make sure that the server prevents invalid things - we don't want to trust the client :)

Indeed. It seems plausible to expand the group checks to include more invalid cases. Just gotta list all of them.