2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Hands.Components;
|
|
|
|
|
using Content.Server.Interaction;
|
2022-03-17 20:13:31 +13:00
|
|
|
using Content.Shared.Hands.EntitySystems;
|
2022-02-17 15:40:03 +13:00
|
|
|
using Content.Shared.Interaction;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Interaction.Helpers;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Item;
|
2020-06-18 22:52:44 +10:00
|
|
|
using Robust.Shared.Containers;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-06-18 22:52:44 +10:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.AI.Operators.Inventory
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class PickupEntityOperator : AiOperator
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
// Input variables
|
2021-12-05 18:09:01 +01:00
|
|
|
private readonly EntityUid _owner;
|
|
|
|
|
private readonly EntityUid _target;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public PickupEntityOperator(EntityUid owner, EntityUid target)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
_owner = owner;
|
|
|
|
|
_target = target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Outcome Execute(float frameTime)
|
|
|
|
|
{
|
2021-12-08 17:04:21 +01:00
|
|
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
2022-03-17 20:13:31 +13:00
|
|
|
var sysMan = IoCManager.Resolve<IEntitySystemManager>();
|
|
|
|
|
var interactionSystem = sysMan.GetEntitySystem<InteractionSystem>();
|
|
|
|
|
var handsSys = sysMan.GetEntitySystem<SharedHandsSystem>();
|
2021-12-08 17:04:21 +01:00
|
|
|
|
|
|
|
|
if (entMan.Deleted(_target)
|
2021-12-30 22:56:10 +01:00
|
|
|
|| !entMan.HasComponent<SharedItemComponent>(_target)
|
2021-12-08 17:04:21 +01:00
|
|
|
|| _target.IsInContainer()
|
2022-03-17 20:13:31 +13:00
|
|
|
|| !interactionSystem.InRangeUnobstructed(_owner, _target, popup: true))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 20:13:31 +13:00
|
|
|
// select empty hand
|
|
|
|
|
if (!handsSys.TrySelectEmptyHand(_owner))
|
2020-06-18 22:52:44 +10:00
|
|
|
return Outcome.Failed;
|
2022-03-17 20:13:31 +13:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
interactionSystem.InteractHand(_owner, _target);
|
2020-06-18 22:52:44 +10:00
|
|
|
return Outcome.Success;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|