using Content.Shared.Whitelist; using Robust.Shared.Prototypes; namespace Content.Shared.EntityConditions.Conditions.Generic; /// /// Checks for entities matching the whitelist in range. /// public sealed partial class NearbyEntitiesConditionSystem : EntityConditionSystem { [Dependency] private SharedTransformSystem _transform = default!; [Dependency] private EntityLookupSystem _lookup = default!; [Dependency] private EntityWhitelistSystem _whitelist = default!; protected override void Condition(Entity entity, ref EntityConditionEvent args) { if (entity.Comp.MapUid == null) { args.Result = false; return; } var found = false; var worldPos = _transform.GetWorldPosition(entity.Comp); var count = 0; foreach (var ent in _lookup.GetEntitiesInRange(entity.Comp.MapID, worldPos, args.Condition.Range)) { if (_whitelist.IsWhitelistFail(args.Condition.Whitelist, ent)) continue; count++; if (count >= args.Condition.Count) { found = true; break; } } args.Result = found; } } /// public sealed partial class NearbyEntitiesCondition : EntityConditionBase { /// /// How many of the entity need to be nearby. /// [DataField] public int Count = 1; [DataField(required: true)] public EntityWhitelist Whitelist = new(); [DataField] public float Range = 10f; public override string EntityConditionGuidebookText(IPrototypeManager prototype) => String.Empty; }