1
0

SharedSiliconLawSystem.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Content.Shared.Emag.Systems;
  2. using Content.Shared.Mind;
  3. using Content.Shared.Popups;
  4. using Content.Shared.Silicons.Laws.Components;
  5. using Content.Shared.Stunnable;
  6. using Content.Shared.Wires;
  7. using Robust.Shared.Audio;
  8. namespace Content.Shared.Silicons.Laws;
  9. /// <summary>
  10. /// This handles getting and displaying the laws for silicons.
  11. /// </summary>
  12. public abstract partial class SharedSiliconLawSystem : EntitySystem
  13. {
  14. [Dependency] private readonly SharedPopupSystem _popup = default!;
  15. [Dependency] private readonly SharedStunSystem _stunSystem = default!;
  16. [Dependency] private readonly EmagSystem _emag = default!;
  17. [Dependency] private readonly SharedMindSystem _mind = default!;
  18. /// <inheritdoc/>
  19. public override void Initialize()
  20. {
  21. InitializeUpdater();
  22. SubscribeLocalEvent<EmagSiliconLawComponent, GotEmaggedEvent>(OnGotEmagged);
  23. }
  24. private void OnGotEmagged(EntityUid uid, EmagSiliconLawComponent component, ref GotEmaggedEvent args)
  25. {
  26. if (!_emag.CompareFlag(args.Type, EmagType.Interaction))
  27. return;
  28. if (_emag.CheckFlag(uid, EmagType.Interaction))
  29. return;
  30. // prevent self-emagging
  31. if (uid == args.UserUid)
  32. {
  33. _popup.PopupClient(Loc.GetString("law-emag-cannot-emag-self"), uid, args.UserUid);
  34. return;
  35. }
  36. if (component.RequireOpenPanel &&
  37. TryComp<WiresPanelComponent>(uid, out var panel) &&
  38. !panel.Open)
  39. {
  40. _popup.PopupClient(Loc.GetString("law-emag-require-panel"), uid, args.UserUid);
  41. return;
  42. }
  43. var ev = new SiliconEmaggedEvent(args.UserUid);
  44. RaiseLocalEvent(uid, ref ev);
  45. component.OwnerName = Name(args.UserUid);
  46. if (_mind.TryGetMind(uid, out var mindId, out _))
  47. EnsureSubvertedSiliconRole(mindId);
  48. _stunSystem.TryParalyze(uid, component.StunTime, true);
  49. args.Handled = true;
  50. }
  51. public virtual void NotifyLawsChanged(EntityUid uid, SoundSpecifier? cue = null)
  52. {
  53. }
  54. protected virtual void EnsureSubvertedSiliconRole(EntityUid mindId)
  55. {
  56. }
  57. protected virtual void RemoveSubvertedSiliconRole(EntityUid mindId)
  58. {
  59. }
  60. }
  61. [ByRefEvent]
  62. public record struct SiliconEmaggedEvent(EntityUid user);