* Update RobustToolbox * Transition direct type usages * More updates * Fix invalid use of to map * Update RobustToolbox * Fix dropping items * Rename name usages of "GridCoordinates" to "EntityCoordinates" * Revert "Update RobustToolbox" This reverts commit 9f334a17c5908ded0043a63158bb671e4aa3f346. * Revert "Update RobustToolbox" This reverts commit 3a9c8cfa3606fa501aa84407796d2ad920853a09. # Conflicts: # RobustToolbox * Fix cursed IMapGrid method usage. * GridTileLookupTest now uses EntityCoordinates Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Co-authored-by: Víctor Aguilera Puerto <zddm@outlook.es>
83 lines
2.5 KiB
C#
83 lines
2.5 KiB
C#
using Content.Server.GameObjects.Components.GUI;
|
|
using Content.Server.GameObjects.Components.Mobs;
|
|
using Content.Server.GameObjects.Components.Weapon.Melee;
|
|
using Content.Server.GameObjects.EntitySystems.Click;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
|
|
namespace Content.Server.AI.Operators.Combat.Melee
|
|
{
|
|
public class SwingMeleeWeaponOperator : AiOperator
|
|
{
|
|
private float _burstTime;
|
|
private float _elapsedTime;
|
|
|
|
private readonly IEntity _owner;
|
|
private readonly IEntity _target;
|
|
|
|
public SwingMeleeWeaponOperator(IEntity owner, IEntity target, float burstTime = 1.0f)
|
|
{
|
|
_owner = owner;
|
|
_target = target;
|
|
_burstTime = burstTime;
|
|
}
|
|
|
|
public override bool TryStartup()
|
|
{
|
|
if (!base.TryStartup())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (!_owner.TryGetComponent(out CombatModeComponent combatModeComponent))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!combatModeComponent.IsInCombatMode)
|
|
{
|
|
combatModeComponent.IsInCombatMode = true;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override void Shutdown(Outcome outcome)
|
|
{
|
|
base.Shutdown(outcome);
|
|
if (_owner.TryGetComponent(out CombatModeComponent combatModeComponent))
|
|
{
|
|
combatModeComponent.IsInCombatMode = false;
|
|
}
|
|
}
|
|
|
|
public override Outcome Execute(float frameTime)
|
|
{
|
|
if (_burstTime <= _elapsedTime)
|
|
{
|
|
return Outcome.Success;
|
|
}
|
|
|
|
if (!_owner.TryGetComponent(out HandsComponent hands) || hands.GetActiveHand == null)
|
|
{
|
|
return Outcome.Failed;
|
|
}
|
|
|
|
var meleeWeapon = hands.GetActiveHand.Owner;
|
|
meleeWeapon.TryGetComponent(out MeleeWeaponComponent meleeWeaponComponent);
|
|
|
|
if ((_target.Transform.Coordinates.Position - _owner.Transform.Coordinates.Position).Length >
|
|
meleeWeaponComponent.Range)
|
|
{
|
|
return Outcome.Failed;
|
|
}
|
|
|
|
var interactionSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<InteractionSystem>();
|
|
|
|
interactionSystem.UseItemInHand(_owner, _target.Transform.Coordinates, _target.Uid);
|
|
_elapsedTime += frameTime;
|
|
return Outcome.Continuing;
|
|
}
|
|
}
|
|
}
|