* Add pirate shooting * Shooting working * Basics working * Refactor time * More conversion * Update primitives * Update yml * weh * Building again * Draft * weh * b * Start shutdown * Starting to take form * Code side done * is it worky * Fix prototypes * stuff * Shitty working * Juke events working * Even more cleanup * RTX * Fix interaction combat mode and compquery * GetAmmoCount relays * Fix rotation speed * Juke fixes * fixes * weh * The collision avoidance never ends * Fixes * Pause support * framework * lazy * Fix idling * Fix drip * goobed * Fix takeover shutdown bug * Merge fixes * shitter * Fix carpos
54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using Content.Shared.Interaction;
|
|
|
|
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators;
|
|
|
|
public sealed class RotateToTargetOperator : HTNOperator
|
|
{
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
private RotateToFaceSystem _rotate = default!;
|
|
|
|
[DataField("targetKey")]
|
|
public string TargetKey = "RotateTarget";
|
|
|
|
[DataField("rotateSpeedKey")]
|
|
public string RotationSpeedKey = NPCBlackboard.RotateSpeed;
|
|
|
|
// Didn't use a key because it's likely the same between all NPCs
|
|
[DataField("tolerance")]
|
|
public Angle Tolerance = Angle.FromDegrees(1);
|
|
|
|
public override void Initialize(IEntitySystemManager sysManager)
|
|
{
|
|
base.Initialize(sysManager);
|
|
_rotate = sysManager.GetEntitySystem<RotateToFaceSystem>();
|
|
}
|
|
|
|
public override void TaskShutdown(NPCBlackboard blackboard, HTNOperatorStatus status)
|
|
{
|
|
base.TaskShutdown(blackboard, status);
|
|
blackboard.Remove<Angle>(TargetKey);
|
|
}
|
|
|
|
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
|
|
{
|
|
if (!blackboard.TryGetValue<Angle>(TargetKey, out var rotateTarget, _entityManager))
|
|
{
|
|
return HTNOperatorStatus.Failed;
|
|
}
|
|
|
|
if (!blackboard.TryGetValue<float>(RotationSpeedKey, out var rotateSpeed, _entityManager))
|
|
{
|
|
return HTNOperatorStatus.Failed;
|
|
}
|
|
|
|
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
|
|
|
|
if (_rotate.TryRotateTo(owner, rotateTarget, frameTime, Tolerance, rotateSpeed))
|
|
{
|
|
return HTNOperatorStatus.Finished;
|
|
}
|
|
|
|
return HTNOperatorStatus.Continuing;
|
|
}
|
|
}
|