Makes AccessReaderComponent support containers (#17927)
This commit is contained in:
@@ -37,6 +37,14 @@ public sealed class AccessReaderComponent : Component
|
||||
/// </summary>
|
||||
[DataField("accessKeys")]
|
||||
public HashSet<StationRecordKey> AccessKeys = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The name of the container in which additional
|
||||
/// AccessReaderComponents may be found.
|
||||
/// </summary>
|
||||
[DataField("containerAccessProvider")]
|
||||
public string? ContainerAccessProvider = null;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
|
||||
@@ -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,9 +62,32 @@ public sealed class AccessReaderSystem : EntitySystem
|
||||
Dirty(reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds all AccessReaderComponents in the container of the
|
||||
/// required entity.
|
||||
/// </summary>
|
||||
/// <param name="target">The entity to search for a container</param>
|
||||
private bool FindAccessReadersInContainer(EntityUid target, AccessReaderComponent accessReader, out List<AccessReaderComponent> 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<AccessReaderComponent>(entity, out var entityAccessReader))
|
||||
result.Add(entityAccessReader);
|
||||
}
|
||||
|
||||
return result.Any();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="source">The entity that wants access.</param>
|
||||
/// <param name="target">The entity to search for an access reader</param>
|
||||
@@ -71,9 +96,20 @@ public sealed class AccessReaderSystem : EntitySystem
|
||||
{
|
||||
if (!Resolve(target, ref reader, false))
|
||||
return true;
|
||||
return IsAllowed(source, reader);
|
||||
|
||||
if (FindAccessReadersInContainer(target, reader, out var accessReaderList))
|
||||
{
|
||||
foreach (var access in accessReaderList)
|
||||
{
|
||||
if (IsAllowed(source, access))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsAllowed(source, reader);
|
||||
}
|
||||
/// <summary>
|
||||
/// Searches the given entity for access tags
|
||||
/// then compares it with the readers access list to see if it is allowed.
|
||||
|
||||
Reference in New Issue
Block a user