using System.Threading; using System.Threading.Tasks; using Robust.Shared.Random; namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators; public sealed class RandomOperator : HTNOperator { [Dependency] private readonly IEntityManager _entManager = default!; [Dependency] private readonly IRobustRandom _random = default!; /// /// Target blackboard key to set the value to. Doesn't need to exist beforehand. /// [DataField("targetKey", required: true)] public string TargetKey = string.Empty; /// /// Minimum idle time. /// [DataField("minKey", required: true)] public string MinKey = string.Empty; /// /// Maximum idle time. /// [DataField("maxKey", required: true)] public string MaxKey = string.Empty; public override async Task<(bool Valid, Dictionary? Effects)> Plan(NPCBlackboard blackboard, CancellationToken cancelToken) { return (true, new Dictionary() { { TargetKey, _random.NextFloat(blackboard.GetValueOrDefault(MinKey, _entManager), blackboard.GetValueOrDefault(MaxKey, _entManager)) } }); } }