Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ public bool HandIsEmpty(Entity<HandsComponent?> ent, string handId)
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))
Expand All @@ -427,6 +430,9 @@ public int GetHandCount(Entity<HandsComponent?> ent)
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))
Expand All @@ -442,6 +448,10 @@ public int CountFreeHands(Entity<HandsComponent?> ent)
return free;
}

/// <summary>
/// Counts the number of hands that can are empty or can be emptied by dropping an item.
/// Unremoveable items will cause a hand to not be freeable.
/// </summary>
public int CountFreeableHands(Entity<HandsComponent> hands)
{
var freeable = 0;
Expand All @@ -453,4 +463,23 @@ public int CountFreeableHands(Entity<HandsComponent> hands)

return freeable;
}

/// <summary>
/// Counts the number of hands that can are empty or can be emptied by dropping an item, ignoring the hand the <paramref name="except"/> entity is in.
/// Unremoveable items will cause a hand to not be freeable.
/// </summary>
public int CountFreeableHandsExcept(Entity<HandsComponent> hands, EntityUid except)
{
var freeable = 0;
foreach (var name in hands.Comp.Hands.Keys)
{
if (GetHeldItem(hands.AsNullable(), name) == except)
continue;

if (HandIsEmpty(hands.AsNullable(), name) || CanDropHeld(hands, name))
freeable++;
}

return freeable;
}
}
2 changes: 1 addition & 1 deletion Content.Shared/Wieldable/SharedWieldableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public bool CanWield(EntityUid uid, WieldableComponent component, EntityUid user
return false;
}

if (_hands.CountFreeableHands((user, hands)) < component.FreeHandsRequired)
if (_hands.CountFreeableHandsExcept((user, hands), uid) < component.FreeHandsRequired)
{
if (!quiet)
{
Expand Down
Loading