mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-02 00:57:26 +00:00
* Medibot doAfter and some other improvements * Clean-up * Review fixes * the army of medibots chasing someone is really funny * misc cleanup --------- Co-authored-by: SlamBamActionman <slambamactionman@gmail.com> Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
38 lines
1.3 KiB
C#
38 lines
1.3 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!;
|
|
private SharedTransformSystem _transformSystem = default!;
|
|
|
|
[DataField("targetKey", required: true)] public string TargetKey = default!;
|
|
|
|
[DataField("rangeKey", required: true)]
|
|
public string RangeKey = default!;
|
|
public override void Initialize(IEntitySystemManager sysManager)
|
|
{
|
|
base.Initialize(sysManager);
|
|
_transformSystem = sysManager.GetEntitySystem<SharedTransformSystem>();
|
|
}
|
|
|
|
[DataField]
|
|
public bool Invert;
|
|
|
|
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 _transformSystem.InRange(coordinates, targetXform.Coordinates, blackboard.GetValueOrDefault<float>(RangeKey, _entManager)) ^ Invert;
|
|
}
|
|
}
|