using Content.Shared.Access; using Content.Shared.Access.Components; using Content.Shared.Access.Systems; using Robust.Shared.Prototypes; namespace Content.Shared.EntityConditions.Conditions.Generic; /// /// Checks for a number of entities nearby with the specified accesses. /// public sealed partial class NearbyAccessConditionSystem : EntityConditionSystem { [Dependency] private EntityLookupSystem _lookup = default!; [Dependency] private AccessReaderSystem _reader = default!; protected override void Condition(Entity entity, ref EntityConditionEvent args) { if (entity.Comp.MapUid == null) { args.Result = false; return; } var found = false; var count = 0; foreach (var (ent, comp) in _lookup.GetEntitiesInRange(entity.Comp.Coordinates, args.Condition.Range)) { if (!_reader.AreAccessTagsAllowed(args.Condition.Access, comp) || args.Condition.Anchored && !Transform(ent).Anchored) continue; count++; if (count >= args.Condition.Count) { found = true; break; } } args.Result = found; } } /// public sealed partial class NearbyAccessCondition : EntityConditionBase { // This exists because of door electronics contained inside doors. /// /// Does the access entity need to be anchored. /// [DataField] public bool Anchored = true; /// /// Count of entities that need to be nearby. /// [DataField] public int Count = 1; [DataField(required: true)] public List> Access = new(); [DataField] public float Range = 10f; public override string EntityConditionGuidebookText(IPrototypeManager prototype) => String.Empty; }