2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.CombatMode;
|
|
|
|
|
using Content.Server.Interaction;
|
|
|
|
|
using Content.Server.Weapon.Melee.Components;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-06-18 22:52:44 +10:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
2020-06-25 01:43:58 +10:00
|
|
|
namespace Content.Server.AI.Operators.Combat.Melee
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2020-06-25 01:43:58 +10:00
|
|
|
public sealed class UnarmedCombatOperator : AiOperator
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2021-12-08 17:04:21 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
|
|
2020-11-21 14:02:00 +01:00
|
|
|
private readonly float _burstTime;
|
2020-06-18 22:52:44 +10:00
|
|
|
private float _elapsedTime;
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
private readonly EntityUid _owner;
|
|
|
|
|
private readonly EntityUid _target;
|
2021-03-16 15:50:20 +01:00
|
|
|
private UnarmedCombatComponent? _unarmedCombat;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public UnarmedCombatOperator(EntityUid owner, EntityUid target, float burstTime = 1.0f)
|
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;
|
|
|
|
|
_target = target;
|
|
|
|
|
_burstTime = burstTime;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 01:24:03 +11:00
|
|
|
public override bool Startup()
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2021-01-11 01:24:03 +11:00
|
|
|
if (!base.Startup())
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
|
2021-12-08 17:04:21 +01:00
|
|
|
if (!_entMan.TryGetComponent(_owner, out CombatModeComponent? combatModeComponent))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!combatModeComponent.IsInCombatMode)
|
|
|
|
|
{
|
|
|
|
|
combatModeComponent.IsInCombatMode = true;
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
|
2021-12-08 17:04:21 +01:00
|
|
|
if (_entMan.TryGetComponent(_owner, out UnarmedCombatComponent? unarmedCombatComponent))
|
2020-06-25 01:43:58 +10:00
|
|
|
{
|
|
|
|
|
_unarmedCombat = unarmedCombatComponent;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-06-18 22:52:44 +10:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 01:24:03 +11:00
|
|
|
public override bool Shutdown(Outcome outcome)
|
2020-06-25 01:43:58 +10:00
|
|
|
{
|
2021-01-11 01:24:03 +11:00
|
|
|
if (!base.Shutdown(outcome))
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-12-08 17:04:21 +01:00
|
|
|
if (_entMan.TryGetComponent(_owner, out CombatModeComponent? combatModeComponent))
|
2020-06-25 01:43:58 +10:00
|
|
|
{
|
|
|
|
|
combatModeComponent.IsInCombatMode = false;
|
|
|
|
|
}
|
2021-01-11 01:24:03 +11:00
|
|
|
|
|
|
|
|
return true;
|
2020-06-25 01:43:58 +10:00
|
|
|
}
|
|
|
|
|
|
2020-06-18 22:52:44 +10:00
|
|
|
public override Outcome Execute(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
if (_burstTime <= _elapsedTime)
|
|
|
|
|
{
|
|
|
|
|
return Outcome.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
if (_unarmedCombat?.Deleted ?? true)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:04:21 +01:00
|
|
|
if ((_entMan.GetComponent<TransformComponent>(_target).Coordinates.Position - _entMan.GetComponent<TransformComponent>(_owner).Coordinates.Position).Length >
|
2020-06-25 01:43:58 +10:00
|
|
|
_unarmedCombat.Range)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var interactionSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<InteractionSystem>();
|
2021-12-08 17:04:21 +01:00
|
|
|
interactionSystem.AiUseInteraction(_owner, _entMan.GetComponent<TransformComponent>(_target).Coordinates, _target);
|
2020-06-18 22:52:44 +10:00
|
|
|
_elapsedTime += frameTime;
|
|
|
|
|
return Outcome.Continuing;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|