SharedHandsSystem.AI.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Diagnostics.CodeAnalysis;
  2. using Content.Shared.Hands.Components;
  3. namespace Content.Shared.Hands.EntitySystems;
  4. // These functions are mostly unused except for some AI operator stuff
  5. // Nothing stops them from being used in general. If they ever get used elsewhere, then this file probably needs to be renamed.
  6. public abstract partial class SharedHandsSystem : EntitySystem
  7. {
  8. public bool TrySelect(EntityUid uid, EntityUid? entity, HandsComponent? handsComp = null)
  9. {
  10. if (!Resolve(uid, ref handsComp, false))
  11. return false;
  12. if (!IsHolding(uid, entity, out var hand, handsComp))
  13. return false;
  14. SetActiveHand(uid, hand, handsComp);
  15. return true;
  16. }
  17. public bool TrySelect<TComponent>(EntityUid uid, [NotNullWhen(true)] out TComponent? component, HandsComponent? handsComp = null) where TComponent : Component
  18. {
  19. component = null;
  20. if (!Resolve(uid, ref handsComp, false))
  21. return false;
  22. foreach (var hand in handsComp.Hands.Values)
  23. {
  24. if (TryComp(hand.HeldEntity, out component))
  25. return true;
  26. }
  27. return false;
  28. }
  29. public bool TrySelectEmptyHand(EntityUid uid, HandsComponent? handsComp = null) => TrySelect(uid, null, handsComp);
  30. }