2022-09-06 00:28:23 +10:00
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.NPC.HTN.Preconditions;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Is the specified coordinate not in range of us.
|
|
|
|
|
/// </summary>
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class CoordinatesNotInRangePrecondition : HTNPrecondition
|
2022-09-06 00:28:23 +10:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
2024-07-13 14:25:51 -07:00
|
|
|
private SharedTransformSystem _transformSystem = default!;
|
2022-09-06 00:28:23 +10:00
|
|
|
|
2022-11-16 20:22:11 +01:00
|
|
|
[DataField("targetKey", required: true)] public string TargetKey = default!;
|
2022-09-06 00:28:23 +10:00
|
|
|
|
2022-11-16 20:22:11 +01:00
|
|
|
[DataField("rangeKey", required: true)]
|
2022-09-06 00:28:23 +10:00
|
|
|
public string RangeKey = default!;
|
|
|
|
|
|
2024-07-13 14:25:51 -07:00
|
|
|
public override void Initialize(IEntitySystemManager sysManager)
|
|
|
|
|
{
|
|
|
|
|
base.Initialize(sysManager);
|
|
|
|
|
_transformSystem = sysManager.GetEntitySystem<SharedTransformSystem>();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-06 00:28:23 +10:00
|
|
|
public override bool IsMet(NPCBlackboard blackboard)
|
|
|
|
|
{
|
2022-11-19 08:07:52 +11:00
|
|
|
if (!blackboard.TryGetValue<EntityCoordinates>(NPCBlackboard.OwnerCoordinates, out var coordinates, _entManager))
|
2022-09-06 00:28:23 +10:00
|
|
|
return false;
|
|
|
|
|
|
2022-11-19 08:07:52 +11:00
|
|
|
if (!blackboard.TryGetValue<EntityCoordinates>(TargetKey, out var target, _entManager))
|
2022-09-06 00:28:23 +10:00
|
|
|
return false;
|
|
|
|
|
|
2024-07-13 14:25:51 -07:00
|
|
|
return !_transformSystem.InRange(coordinates, target, blackboard.GetValueOrDefault<float>(RangeKey, _entManager));
|
2022-09-06 00:28:23 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|