Files
tbd-station-14/Content.Server/AI/Operators/Combat/Melee/UnarmedCombatOperator.cs
ShadowCommander 6870b88a56 Interaction clean up (#4091)
* Rename and clean up interaction events

* Fix hand equip events

* Refactor duplicate client input validation

* Rename Use handler

* Move unneeded InRangeUnobstructed methods to extensions only

* Clean up UseInteractions

* Clean up ActivateItemInWorld

* Replace explicit range check with InRangeUnobstructed

Remove TransformComponent check, since transform is guaranteed now.

* Revert transform check removal

* More cleanup

* Reorder interaction checks

* Rename attack eventargs to interact

* Test V1

* Add interaction test

* Fix interaction test

* Fix container interaction test

* Rename interaction methods

* Rename player to user and attacked to target

* Clean up InteractAfter

* Clean up InRangeUnobstructed usages

* Rename attack to interact and weapon to used

* Changed can't reach message to only play when holding something

Cleaned up bracket formatting

* Fix Airtight validation check

* Remove extra words in comments

* Fix FaceClick rotation

* Move duplicate map check and face to method

* Fix test
2021-06-07 05:49:43 -07:00

92 lines
2.6 KiB
C#

using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Weapon.Melee;
using Content.Server.GameObjects.EntitySystems.Click;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Operators.Combat.Melee
{
public sealed class UnarmedCombatOperator : AiOperator
{
private readonly float _burstTime;
private float _elapsedTime;
private readonly IEntity _owner;
private readonly IEntity _target;
private UnarmedCombatComponent? _unarmedCombat;
public UnarmedCombatOperator(IEntity owner, IEntity target, float burstTime = 1.0f)
{
_owner = owner;
_target = target;
_burstTime = burstTime;
}
public override bool Startup()
{
if (!base.Startup())
{
return true;
}
if (!_owner.TryGetComponent(out CombatModeComponent? combatModeComponent))
{
return false;
}
if (!combatModeComponent.IsInCombatMode)
{
combatModeComponent.IsInCombatMode = true;
}
if (_owner.TryGetComponent(out UnarmedCombatComponent? unarmedCombatComponent))
{
_unarmedCombat = unarmedCombatComponent;
}
else
{
return false;
}
return true;
}
public override bool Shutdown(Outcome outcome)
{
if (!base.Shutdown(outcome))
return false;
if (_owner.TryGetComponent(out CombatModeComponent? combatModeComponent))
{
combatModeComponent.IsInCombatMode = false;
}
return true;
}
public override Outcome Execute(float frameTime)
{
if (_burstTime <= _elapsedTime)
{
return Outcome.Success;
}
if (_unarmedCombat?.Deleted ?? true)
{
return Outcome.Failed;
}
if ((_target.Transform.Coordinates.Position - _owner.Transform.Coordinates.Position).Length >
_unarmedCombat.Range)
{
return Outcome.Failed;
}
var interactionSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<InteractionSystem>();
interactionSystem.AiUseInteraction(_owner, _target.Transform.Coordinates, _target.Uid);
_elapsedTime += frameTime;
return Outcome.Continuing;
}
}
}