1
0

SharedAdminFrozenSystem.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Content.Shared.ActionBlocker;
  2. using Content.Shared.Emoting;
  3. using Content.Shared.Interaction.Events;
  4. using Content.Shared.Item;
  5. using Content.Shared.Movement.Events;
  6. using Content.Shared.Movement.Pulling.Components;
  7. using Content.Shared.Movement.Pulling.Events;
  8. using Content.Shared.Movement.Pulling.Systems;
  9. using Content.Shared.Speech;
  10. using Content.Shared.Throwing;
  11. namespace Content.Shared.Administration;
  12. // TODO deduplicate with BlockMovementComponent
  13. public abstract class SharedAdminFrozenSystem : EntitySystem
  14. {
  15. [Dependency] private readonly ActionBlockerSystem _blocker = default!;
  16. [Dependency] private readonly PullingSystem _pulling = default!;
  17. public override void Initialize()
  18. {
  19. base.Initialize();
  20. SubscribeLocalEvent<AdminFrozenComponent, UseAttemptEvent>(OnAttempt);
  21. SubscribeLocalEvent<AdminFrozenComponent, PickupAttemptEvent>(OnAttempt);
  22. SubscribeLocalEvent<AdminFrozenComponent, ThrowAttemptEvent>(OnAttempt);
  23. SubscribeLocalEvent<AdminFrozenComponent, InteractionAttemptEvent>(OnInteractAttempt);
  24. SubscribeLocalEvent<AdminFrozenComponent, ComponentStartup>(OnStartup);
  25. SubscribeLocalEvent<AdminFrozenComponent, ComponentShutdown>(UpdateCanMove);
  26. SubscribeLocalEvent<AdminFrozenComponent, UpdateCanMoveEvent>(OnUpdateCanMove);
  27. SubscribeLocalEvent<AdminFrozenComponent, PullAttemptEvent>(OnPullAttempt);
  28. SubscribeLocalEvent<AdminFrozenComponent, AttackAttemptEvent>(OnAttempt);
  29. SubscribeLocalEvent<AdminFrozenComponent, ChangeDirectionAttemptEvent>(OnAttempt);
  30. SubscribeLocalEvent<AdminFrozenComponent, EmoteAttemptEvent>(OnEmoteAttempt);
  31. SubscribeLocalEvent<AdminFrozenComponent, SpeakAttemptEvent>(OnSpeakAttempt);
  32. }
  33. private void OnInteractAttempt(Entity<AdminFrozenComponent> ent, ref InteractionAttemptEvent args)
  34. {
  35. args.Cancelled = true;
  36. }
  37. private void OnSpeakAttempt(EntityUid uid, AdminFrozenComponent component, SpeakAttemptEvent args)
  38. {
  39. if (!component.Muted)
  40. return;
  41. args.Cancel();
  42. }
  43. private void OnAttempt(EntityUid uid, AdminFrozenComponent component, CancellableEntityEventArgs args)
  44. {
  45. args.Cancel();
  46. }
  47. private void OnPullAttempt(EntityUid uid, AdminFrozenComponent component, PullAttemptEvent args)
  48. {
  49. args.Cancelled = true;
  50. }
  51. private void OnStartup(EntityUid uid, AdminFrozenComponent component, ComponentStartup args)
  52. {
  53. if (TryComp<PullableComponent>(uid, out var pullable))
  54. {
  55. _pulling.TryStopPull(uid, pullable);
  56. }
  57. UpdateCanMove(uid, component, args);
  58. }
  59. private void OnUpdateCanMove(EntityUid uid, AdminFrozenComponent component, UpdateCanMoveEvent args)
  60. {
  61. if (component.LifeStage > ComponentLifeStage.Running)
  62. return;
  63. args.Cancel();
  64. }
  65. private void UpdateCanMove(EntityUid uid, AdminFrozenComponent component, EntityEventArgs args)
  66. {
  67. _blocker.UpdateCanMove(uid);
  68. }
  69. private void OnEmoteAttempt(EntityUid uid, AdminFrozenComponent component, EmoteAttemptEvent args)
  70. {
  71. if (component.Muted)
  72. args.Cancel();
  73. }
  74. }