SharedSiliconLawSystem.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. NotifyLawsChanged(uid, component.EmaggedSound);
  47. if(_mind.TryGetMind(uid, out var mindId, out _))
  48. EnsureSubvertedSiliconRole(mindId);
  49. _stunSystem.TryParalyze(uid, component.StunTime, true);
  50. args.Handled = true;
  51. }
  52. public virtual void NotifyLawsChanged(EntityUid uid, SoundSpecifier? cue = null)
  53. {
  54. }
  55. protected virtual void EnsureSubvertedSiliconRole(EntityUid mindId)
  56. {
  57. }
  58. protected virtual void RemoveSubvertedSiliconRole(EntityUid mindId)
  59. {
  60. }
  61. }
  62. [ByRefEvent]
  63. public record struct SiliconEmaggedEvent(EntityUid user);