using System.Linq; using System.Threading; using System.Threading.Tasks; using Content.Server.NPC.Components; using Robust.Shared.Random; namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Test; public sealed partial class PickPathfindPointOperator : HTNOperator { [Dependency] private readonly IEntityManager _entManager = default!; [Dependency] private readonly IRobustRandom _random = default!; public override async Task<(bool Valid, Dictionary? Effects)> Plan(NPCBlackboard blackboard, CancellationToken cancelToken) { var owner = blackboard.GetValue(NPCBlackboard.Owner); // Find all pathfind points on the same grid and choose to move to it. var xform = _entManager.GetComponent(owner); var gridUid = xform.GridUid; if (gridUid == null) return (false, null); var points = new List(); foreach (var (point, pointXform) in _entManager.EntityQuery(true)) { if (gridUid != pointXform.GridUid) continue; points.Add(pointXform); } if (points.Count == 0) return (false, null); var selected = _random.Pick(points); return (true, new Dictionary() { { NPCBlackboard.MovementTarget, selected.Coordinates } }); } }