2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.CombatMode;
|
|
|
|
|
using Content.Server.Interaction;
|
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-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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A Generic interacter; if you need to check stuff then make your own
|
|
|
|
|
/// </summary>
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class InteractWithEntityOperator : AiOperator
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2021-12-08 17:04:21 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
private readonly EntityUid _owner;
|
|
|
|
|
private readonly EntityUid _useTarget;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public InteractWithEntityOperator(EntityUid owner, EntityUid useTarget)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2021-12-08 17:04:21 +01:00
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
2020-06-18 22:52:44 +10:00
|
|
|
_owner = owner;
|
|
|
|
|
_useTarget = useTarget;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Outcome Execute(float frameTime)
|
|
|
|
|
{
|
2021-12-08 17:04:21 +01:00
|
|
|
var targetTransform = _entMan.GetComponent<TransformComponent>(_useTarget);
|
|
|
|
|
|
|
|
|
|
if (targetTransform.GridID != _entMan.GetComponent<TransformComponent>(_owner).GridID)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 15:40:03 +13:00
|
|
|
var interactionSystem = EntitySystem.Get<InteractionSystem>();
|
|
|
|
|
|
|
|
|
|
if (!interactionSystem.InRangeUnobstructed(_owner, _useTarget, popup: true))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:04:21 +01:00
|
|
|
if (_entMan.TryGetComponent(_owner, out CombatModeComponent? combatModeComponent))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
combatModeComponent.IsInCombatMode = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Click on da thing
|
2021-12-08 17:04:21 +01:00
|
|
|
interactionSystem.AiUseInteraction(_owner, targetTransform.Coordinates, _useTarget);
|
2020-06-18 22:52:44 +10:00
|
|
|
|
|
|
|
|
return Outcome.Success;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|