Files
tbd-station-14/Content.Server/NPC/HTN/Preconditions/TargetInRangePrecondition.cs
Tayrtahn f4cb02fb0c Code cleanup: Purge calls to obsolete EntityCoordinates methods (#26292)
* Purge calls to obsolete EntityCoordinates methods

* Pizza defruited; rerun those tests!
2024-03-21 12:59:56 +11:00

29 lines
1.1 KiB
C#

using Robust.Shared.Map;
namespace Content.Server.NPC.HTN.Preconditions;
/// <summary>
/// Is the specified key within the specified range of us.
/// </summary>
public sealed partial class TargetInRangePrecondition : HTNPrecondition
{
[Dependency] private readonly IEntityManager _entManager = default!;
[DataField("targetKey", required: true)] public string TargetKey = default!;
[DataField("rangeKey", required: true)]
public string RangeKey = default!;
public override bool IsMet(NPCBlackboard blackboard)
{
if (!blackboard.TryGetValue<EntityCoordinates>(NPCBlackboard.OwnerCoordinates, out var coordinates, _entManager))
return false;
if (!blackboard.TryGetValue<EntityUid>(TargetKey, out var target, _entManager) ||
!_entManager.TryGetComponent<TransformComponent>(target, out var targetXform))
return false;
return coordinates.InRange(_entManager, _entManager.System<SharedTransformSystem>(), targetXform.Coordinates, blackboard.GetValueOrDefault<float>(RangeKey, _entManager));
}
}