diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs index 8431e27658bc8..2060ee892fde3 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs @@ -419,6 +419,9 @@ public bool HandIsEmpty(Entity ent, string handId) return GetHeldItem(ent, handId) == null; } + /// + /// Counts the number of hands on this entity. + /// public int GetHandCount(Entity ent) { if (!Resolve(ent, ref ent.Comp, false)) @@ -427,6 +430,9 @@ public int GetHandCount(Entity ent) return ent.Comp.Hands.Count; } + /// + /// Counts the number of hands that are empty. + /// public int CountFreeHands(Entity ent) { if (!Resolve(ent, ref ent.Comp, false)) @@ -442,11 +448,19 @@ public int CountFreeHands(Entity ent) return free; } - public int CountFreeableHands(Entity hands) + /// + /// Counts the number of hands that are empty or can be emptied by dropping an item. + /// Unremoveable items will cause a hand to not be freeable. + /// + /// The hand this entity is in will be ignored when counting. + public int CountFreeableHands(Entity hands, EntityUid? except = null) { var freeable = 0; foreach (var name in hands.Comp.Hands.Keys) { + if (except != null && GetHeldItem(hands.AsNullable(), name) == except) + continue; + if (HandIsEmpty(hands.AsNullable(), name) || CanDropHeld(hands, name)) freeable++; } diff --git a/Content.Shared/Wieldable/SharedWieldableSystem.cs b/Content.Shared/Wieldable/SharedWieldableSystem.cs index 3b9b8dd8e711b..49db4ff86cf2c 100644 --- a/Content.Shared/Wieldable/SharedWieldableSystem.cs +++ b/Content.Shared/Wieldable/SharedWieldableSystem.cs @@ -259,7 +259,7 @@ public bool CanWield(EntityUid uid, WieldableComponent component, EntityUid user return false; } - if (_hands.CountFreeableHands((user, hands)) < component.FreeHandsRequired) + if (_hands.CountFreeableHands((user, hands), except: uid) < component.FreeHandsRequired) { if (!quiet) {