2020-08-22 20:03:24 +10:00
|
|
|
#nullable enable
|
2020-07-25 15:11:16 +02:00
|
|
|
using Content.Server.GameObjects.Components.GUI;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Server.GameObjects.Components.Items.Storage;
|
2020-07-06 14:27:03 -07:00
|
|
|
using Content.Server.GameObjects.EntitySystems.Click;
|
2020-08-30 11:37:06 +02:00
|
|
|
using Content.Shared.Utility;
|
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
|
|
|
|
|
{
|
|
|
|
|
public class PickupEntityOperator : AiOperator
|
|
|
|
|
{
|
|
|
|
|
// Input variables
|
|
|
|
|
private readonly IEntity _owner;
|
|
|
|
|
private readonly IEntity _target;
|
|
|
|
|
|
|
|
|
|
public PickupEntityOperator(IEntity owner, IEntity target)
|
|
|
|
|
{
|
|
|
|
|
_owner = owner;
|
|
|
|
|
_target = target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Outcome Execute(float frameTime)
|
|
|
|
|
{
|
2020-08-22 20:03:24 +10:00
|
|
|
if (_target.Deleted ||
|
2020-06-18 22:52:44 +10:00
|
|
|
!_target.HasComponent<ItemComponent>() ||
|
2020-11-13 20:25:04 +13:00
|
|
|
_target.IsInContainer() ||
|
2020-08-30 11:37:06 +02:00
|
|
|
!_owner.InRangeUnobstructed(_target, popup: true))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-22 12:24:59 +02:00
|
|
|
if (!_owner.TryGetComponent(out HandsComponent? handsComponent))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var emptyHands = false;
|
|
|
|
|
|
|
|
|
|
foreach (var hand in handsComponent.ActivePriorityEnumerable())
|
|
|
|
|
{
|
2020-07-25 15:11:16 +02:00
|
|
|
if (handsComponent.GetItem(hand) == null)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2020-07-25 15:11:16 +02:00
|
|
|
if (handsComponent.ActiveHand != hand)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2020-07-25 15:11:16 +02:00
|
|
|
handsComponent.ActiveHand = hand;
|
2020-06-18 22:52:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emptyHands = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!emptyHands)
|
|
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var interactionSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<InteractionSystem>();
|
|
|
|
|
interactionSystem.Interaction(_owner, _target);
|
|
|
|
|
return Outcome.Success;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|