2022-03-17 20:13:31 +13:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2023-04-07 11:21:12 -07:00
|
|
|
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.
|
|
|
|
|
|
2025-06-25 09:13:03 -04:00
|
|
|
public abstract partial class SharedHandsSystem
|
2022-03-17 20:13:31 +13:00
|
|
|
{
|
2023-04-07 11:21:12 -07: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;
|
|
|
|
|
|
2025-06-25 09:13:03 -04:00
|
|
|
if (!IsHolding((uid, handsComp), entity, out var hand))
|
2022-03-17 20:13:31 +13:00
|
|
|
return false;
|
|
|
|
|
|
2025-06-25 09:13:03 -04:00
|
|
|
SetActiveHand((uid, handsComp), hand);
|
2022-03-17 20:13:31 +13:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 11:21:12 -07:00
|
|
|
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;
|
|
|
|
|
|
2025-06-25 09:13:03 -04:00
|
|
|
foreach (var hand in handsComp.Hands.Keys)
|
2022-03-17 20:13:31 +13:00
|
|
|
{
|
2025-06-25 09:13:03 -04: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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 11:21:12 -07:00
|
|
|
public bool TrySelectEmptyHand(EntityUid uid, HandsComponent? handsComp = null) => TrySelect(uid, null, handsComp);
|
2022-03-17 20:13:31 +13:00
|
|
|
}
|