]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix wielding two-handed items with only one hand (#40966)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Fri, 24 Oct 2025 07:25:42 +0000 (09:25 +0200)
committerGitHub <noreply@github.com>
Fri, 24 Oct 2025 07:25:42 +0000 (07:25 +0000)
* fix

* review

Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs
Content.Shared/Wieldable/SharedWieldableSystem.cs

index 8431e27658bc81fb1304a37fbaccc17feb5a5fc1..2060ee892fde3617bc8dc69ed34e6d800e4b9b24 100644 (file)
@@ -419,6 +419,9 @@ public abstract partial class SharedHandsSystem
         return GetHeldItem(ent, handId) == null;
     }
 
+    /// <summary>
+    /// Counts the number of hands on this entity.
+    /// </summary>
     public int GetHandCount(Entity<HandsComponent?> ent)
     {
         if (!Resolve(ent, ref ent.Comp, false))
@@ -427,6 +430,9 @@ public abstract partial class SharedHandsSystem
         return ent.Comp.Hands.Count;
     }
 
+    /// <summary>
+    /// Counts the number of hands that are empty.
+    /// </summary>
     public int CountFreeHands(Entity<HandsComponent?> ent)
     {
         if (!Resolve(ent, ref ent.Comp, false))
@@ -442,11 +448,19 @@ public abstract partial class SharedHandsSystem
         return free;
     }
 
-    public int CountFreeableHands(Entity<HandsComponent> hands)
+    /// <summary>
+    /// 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.
+    /// </summary>
+    /// <param name="except">The hand this entity is in will be ignored when counting.</param>
+    public int CountFreeableHands(Entity<HandsComponent> 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++;
         }
index 3b9b8dd8e711bb35ed512fe322a8b51aacbbd8d4..49db4ff86cf2c294e32a43e292b8dddd9c744645 100644 (file)
@@ -259,7 +259,7 @@ public abstract class SharedWieldableSystem : EntitySystem
             return false;
         }
 
-        if (_hands.CountFreeableHands((user, hands)) < component.FreeHandsRequired)
+        if (_hands.CountFreeableHands((user, hands), except: uid) < component.FreeHandsRequired)
         {
             if (!quiet)
             {