using System.Diagnostics.CodeAnalysis;
using Content.Shared._DV.Access.Components;
using Content.Shared.Access.Components;
using Content.Shared.Implants.Components;
using Robust.Shared.Containers;
namespace Content.Shared._DV.Access.Systems;
///
/// Shared handling for subdermal ID Cards.
///
public abstract class SharedSubdermalIdCardSystem : EntitySystem
{
[Dependency] private readonly SharedContainerSystem _container = default!;
///
/// Name for the container, inside the subdermal implant, where the ID card will be spawned.
///
public const string SubdermalContainerId = "subdermalIdCard";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnRemoveAttempt);
}
///
/// Attempts to find an ID card from within the subdermal card container, if one exists.
///
/// Entity to search.
/// Variable to place the found entityuid into.
/// True if matching ID card entity was found, otherwise false.
public bool TryGetIdCard(EntityUid ent, [NotNullWhen(true)] out EntityUid? idEntity)
{
idEntity = default;
if (!_container.TryGetContainer(ent, ImplanterComponent.ImplantSlotId, out var implantContainer))
return false; // This entity is not implanted with anything
foreach (var implant in implantContainer.ContainedEntities)
{
if (!_container.TryGetContainer(implant, SubdermalContainerId, out var con) ||
con.ContainedEntities.Count == 0)
continue;
foreach (var item in con.ContainedEntities)
{
if (!HasComp(item))
continue; // Not an ID card
idEntity = item;
return true;
}
}
return false;
}
///
/// Handles when a subdermal ID card implant is attempted to be removed, blocking it completely.
///
/// The entity which is being removed.
/// Args for the event.
private void OnRemoveAttempt(Entity ent, ref ContainerGettingRemovedAttemptEvent args)
{
// Subdermal ID cards are NEVER removable by any means.
args.Cancel();
}
}