Fix wielding two-handed items with only one hand (#40966)

* fix

* review
This commit is contained in:
slarticodefast 2025-10-24 09:25:42 +02:00 committed by Vanessa
parent b3fd980ae5
commit 355cf08d43
2 changed files with 16 additions and 2 deletions

View File

@ -420,6 +420,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))
@ -428,6 +431,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))
@ -443,11 +449,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++;
}

View 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)
{