Files

43 lines
1.4 KiB
C#
Raw Permalink Normal View History

2022-03-17 20:13:31 +13:00
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Hands.Components;
2022-03-17 20:13:31 +13:00
namespace Content.Shared.Hands.EntitySystems;
// These functions are mostly unused except for some AI operator stuff
// Nothing stops them from being used in general. If they ever get used elsewhere, then this file probably needs to be renamed.
public abstract partial class SharedHandsSystem
2022-03-17 20:13:31 +13:00
{
public bool TrySelect(EntityUid uid, EntityUid? entity, HandsComponent? handsComp = null)
2022-03-17 20:13:31 +13:00
{
if (!Resolve(uid, ref handsComp, false))
return false;
if (!IsHolding((uid, handsComp), entity, out var hand))
2022-03-17 20:13:31 +13:00
return false;
SetActiveHand((uid, handsComp), hand);
2022-03-17 20:13:31 +13:00
return true;
}
public bool TrySelect<TComponent>(EntityUid uid, [NotNullWhen(true)] out TComponent? component, HandsComponent? handsComp = null) where TComponent : Component
2022-03-17 20:13:31 +13:00
{
component = null;
if (!Resolve(uid, ref handsComp, false))
return false;
foreach (var hand in handsComp.Hands.Keys)
2022-03-17 20:13:31 +13:00
{
if (!TryGetHeldItem((uid, handsComp), hand, out var held))
continue;
if (TryComp(held, out component))
2022-03-17 20:13:31 +13:00
return true;
}
return false;
}
public bool TrySelectEmptyHand(EntityUid uid, HandsComponent? handsComp = null) => TrySelect(uid, null, handsComp);
2022-03-17 20:13:31 +13:00
}