1
0

MindShieldSystem.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Content.Server.Administration.Logs;
  2. using Content.Server.Mind;
  3. using Content.Server.Popups;
  4. using Content.Server.Roles;
  5. using Content.Shared.Database;
  6. using Content.Shared.Implants;
  7. using Content.Shared.Implants.Components;
  8. using Content.Shared.Mindshield.Components;
  9. using Content.Shared.Revolutionary.Components;
  10. using Content.Shared.Tag;
  11. using Robust.Shared.Containers;
  12. namespace Content.Server.Mindshield;
  13. /// <summary>
  14. /// System used for checking if the implanted is a Rev or Head Rev.
  15. /// </summary>
  16. public sealed class MindShieldSystem : EntitySystem
  17. {
  18. [Dependency] private readonly IAdminLogManager _adminLogManager = default!;
  19. [Dependency] private readonly RoleSystem _roleSystem = default!;
  20. [Dependency] private readonly MindSystem _mindSystem = default!;
  21. [Dependency] private readonly TagSystem _tag = default!;
  22. [Dependency] private readonly PopupSystem _popupSystem = default!;
  23. [ValidatePrototypeId<TagPrototype>]
  24. public const string MindShieldTag = "MindShield";
  25. public override void Initialize()
  26. {
  27. base.Initialize();
  28. SubscribeLocalEvent<SubdermalImplantComponent, ImplantImplantedEvent>(ImplantCheck);
  29. SubscribeLocalEvent<MindShieldImplantComponent, EntGotRemovedFromContainerMessage>(OnImplantDraw);
  30. }
  31. /// <summary>
  32. /// Checks if the implant was a mindshield or not
  33. /// </summary>
  34. public void ImplantCheck(EntityUid uid, SubdermalImplantComponent comp, ref ImplantImplantedEvent ev)
  35. {
  36. if (_tag.HasTag(ev.Implant, MindShieldTag) && ev.Implanted != null)
  37. {
  38. EnsureComp<MindShieldComponent>(ev.Implanted.Value);
  39. MindShieldRemovalCheck(ev.Implanted.Value, ev.Implant);
  40. }
  41. }
  42. /// <summary>
  43. /// Checks if the implanted person was a Rev or Head Rev and remove role or destroy mindshield respectively.
  44. /// </summary>
  45. public void MindShieldRemovalCheck(EntityUid implanted, EntityUid implant)
  46. {
  47. if (HasComp<HeadRevolutionaryComponent>(implanted))
  48. {
  49. _popupSystem.PopupEntity(Loc.GetString("head-rev-break-mindshield"), implanted);
  50. QueueDel(implant);
  51. return;
  52. }
  53. if (_mindSystem.TryGetMind(implanted, out var mindId, out _) &&
  54. _roleSystem.MindTryRemoveRole<RevolutionaryRoleComponent>(mindId))
  55. {
  56. _adminLogManager.Add(LogType.Mind, LogImpact.Medium, $"{ToPrettyString(implanted)} was deconverted due to being implanted with a Mindshield.");
  57. }
  58. }
  59. private void OnImplantDraw(Entity<MindShieldImplantComponent> ent, ref EntGotRemovedFromContainerMessage args)
  60. {
  61. RemComp<MindShieldComponent>(args.Container.Owner);
  62. }
  63. }