using Content.Server.Administration.Logs;
using Content.Server.Mind;
using Content.Server.Popups;
using Content.Server.Roles;
using Content.Shared.Database;
using Content.Shared.Implants;
using Content.Shared.Mindshield.Components;
using Content.Shared.Revolutionary.Components;
using Robust.Shared.Containers;
namespace Content.Server.Mindshield;
///
/// System used for adding or removing components with a mindshield implant
/// as well as checking if the implanted is a Rev or Head Rev.
///
public sealed class MindShieldSystem : EntitySystem
{
[Dependency] private readonly IAdminLogManager _adminLogManager = default!;
[Dependency] private readonly RoleSystem _roleSystem = default!;
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnImplantImplanted);
SubscribeLocalEvent(OnImplantDraw);
}
private void OnImplantImplanted(Entity ent, ref ImplantImplantedEvent ev)
{
if (ev.Implanted == null)
return;
EnsureComp(ev.Implanted.Value);
MindShieldRemovalCheck(ev.Implanted.Value, ev.Implant);
}
///
/// Checks if the implanted person was a Rev or Head Rev and remove role or destroy mindshield respectively.
///
private void MindShieldRemovalCheck(EntityUid implanted, EntityUid implant)
{
if (HasComp(implanted))
{
_popupSystem.PopupEntity(Loc.GetString("head-rev-break-mindshield"), implanted);
QueueDel(implant);
return;
}
if (_mindSystem.TryGetMind(implanted, out var mindId, out _) &&
_roleSystem.MindTryRemoveRole(mindId))
{
_adminLogManager.Add(LogType.Mind, LogImpact.Medium, $"{ToPrettyString(implanted)} was deconverted due to being implanted with a Mindshield.");
}
}
private void OnImplantDraw(Entity ent, ref EntGotRemovedFromContainerMessage args)
{
RemComp(args.Container.Owner);
}
}