diff --git a/Content.Shared/Access/Components/AccessReaderComponent.cs b/Content.Shared/Access/Components/AccessReaderComponent.cs index 94aec90355..c3ed9eeb17 100644 --- a/Content.Shared/Access/Components/AccessReaderComponent.cs +++ b/Content.Shared/Access/Components/AccessReaderComponent.cs @@ -37,6 +37,14 @@ public sealed class AccessReaderComponent : Component /// [DataField("accessKeys")] public HashSet AccessKeys = new(); + + + /// + /// The name of the container in which additional + /// AccessReaderComponents may be found. + /// + [DataField("containerAccessProvider")] + public string? ContainerAccessProvider = null; } [Serializable, NetSerializable] diff --git a/Content.Shared/Access/Systems/AccessReaderSystem.cs b/Content.Shared/Access/Systems/AccessReaderSystem.cs index 01eb4eb7e6..f01ec061d7 100644 --- a/Content.Shared/Access/Systems/AccessReaderSystem.cs +++ b/Content.Shared/Access/Systems/AccessReaderSystem.cs @@ -6,6 +6,7 @@ using Content.Shared.Emag.Systems; using Content.Shared.PDA; using Content.Shared.Access.Components; using Content.Shared.DeviceLinking.Events; +using Robust.Shared.Containers; using Robust.Shared.Prototypes; using Content.Shared.Hands.EntitySystems; using Content.Shared.StationRecords; @@ -17,6 +18,7 @@ public sealed class AccessReaderSystem : EntitySystem { [Dependency] private readonly InventorySystem _inventorySystem = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; + [Dependency] private readonly SharedContainerSystem _containerSystem = default!; public override void Initialize() { @@ -60,20 +62,54 @@ public sealed class AccessReaderSystem : EntitySystem Dirty(reader); } + /// + /// Finds all AccessReaderComponents in the container of the + /// required entity. + /// + /// The entity to search for a container + private bool FindAccessReadersInContainer(EntityUid target, AccessReaderComponent accessReader, out List result) + { + result = new(); + if (accessReader.ContainerAccessProvider == null) + return false; + + if (!_containerSystem.TryGetContainer(target, accessReader.ContainerAccessProvider, out var container)) + return false; + + foreach (var entity in container.ContainedEntities) + { + if (TryComp(entity, out var entityAccessReader)) + result.Add(entityAccessReader); + } + + return result.Any(); + } + /// /// Searches the source for access tags - /// then compares it with the targets readers access list to see if it is allowed. + /// then compares it with the all targets accesses to see if it is allowed. /// /// The entity that wants access. /// The entity to search for an access reader /// Optional reader from the target entity public bool IsAllowed(EntityUid source, EntityUid target, AccessReaderComponent? reader = null) { - if (!Resolve(target, ref reader, false)) - return true; - return IsAllowed(source, reader); - } + if (!Resolve(target, ref reader, false)) + return true; + if (FindAccessReadersInContainer(target, reader, out var accessReaderList)) + { + foreach (var access in accessReaderList) + { + if (IsAllowed(source, access)) + return true; + } + + return false; + } + + return IsAllowed(source, reader); + } /// /// Searches the given entity for access tags /// then compares it with the readers access list to see if it is allowed.