Files
tbd-station-14/Content.Server/AI/Operators/Inventory/InteractWithEntityOperator.cs
Vera Aguilera Puerto a5b57c8e10 Inline Transform
2021-12-03 14:20:34 +01:00

49 lines
1.7 KiB
C#

using Content.Server.CombatMode;
using Content.Server.Interaction;
using Content.Shared.Interaction.Helpers;
using Robust.Shared.GameObjects;
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>
public class InteractWithEntityOperator : AiOperator
{
private readonly IEntity _owner;
private readonly IEntity _useTarget;
public InteractWithEntityOperator(IEntity owner, IEntity useTarget)
{
_owner = owner;
_useTarget = useTarget;
}
public override Outcome Execute(float frameTime)
{
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(_useTarget.Uid).GridID != IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(_owner.Uid).GridID)
{
return Outcome.Failed;
}
if (!_owner.InRangeUnobstructed(_useTarget, popup: true))
{
return Outcome.Failed;
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(_owner.Uid, out CombatModeComponent? combatModeComponent))
{
combatModeComponent.IsInCombatMode = false;
}
// Click on da thing
var interactionSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<InteractionSystem>();
interactionSystem.AiUseInteraction(_owner, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(_useTarget.Uid).Coordinates, _useTarget.Uid);
return Outcome.Success;
}
}
}