1
0

SharedInteractionSystem.Blocking.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Content.Shared.Hands;
  2. using Content.Shared.Interaction.Components;
  3. using Content.Shared.Interaction.Events;
  4. using Content.Shared.Item;
  5. using Content.Shared.Movement.Events;
  6. namespace Content.Shared.Interaction;
  7. // TODO deduplicate with AdminFrozenComponent
  8. /// <summary>
  9. /// Handles <see cref="BlockMovementComponent"/>, which prevents various
  10. /// kinds of movement and interactions when attached to an entity.
  11. /// </summary>
  12. public partial class SharedInteractionSystem
  13. {
  14. public void InitializeBlocking()
  15. {
  16. SubscribeLocalEvent<BlockMovementComponent, UpdateCanMoveEvent>(OnMoveAttempt);
  17. SubscribeLocalEvent<BlockMovementComponent, UseAttemptEvent>(CancelEvent);
  18. SubscribeLocalEvent<BlockMovementComponent, InteractionAttemptEvent>(CancelInteractEvent);
  19. SubscribeLocalEvent<BlockMovementComponent, DropAttemptEvent>(CancelEvent);
  20. SubscribeLocalEvent<BlockMovementComponent, PickupAttemptEvent>(CancelEvent);
  21. SubscribeLocalEvent<BlockMovementComponent, ChangeDirectionAttemptEvent>(CancelEvent);
  22. SubscribeLocalEvent<BlockMovementComponent, ComponentStartup>(OnBlockingStartup);
  23. SubscribeLocalEvent<BlockMovementComponent, ComponentShutdown>(OnBlockingShutdown);
  24. }
  25. private void CancelInteractEvent(Entity<BlockMovementComponent> ent, ref InteractionAttemptEvent args)
  26. {
  27. if (ent.Comp.BlockInteraction)
  28. args.Cancelled = true;
  29. }
  30. private void OnMoveAttempt(EntityUid uid, BlockMovementComponent component, UpdateCanMoveEvent args)
  31. {
  32. if (component.LifeStage > ComponentLifeStage.Running)
  33. return;
  34. args.Cancel(); // no more scurrying around
  35. }
  36. private void CancelEvent(EntityUid uid, BlockMovementComponent component, CancellableEntityEventArgs args)
  37. {
  38. args.Cancel();
  39. }
  40. private void OnBlockingStartup(EntityUid uid, BlockMovementComponent component, ComponentStartup args)
  41. {
  42. _actionBlockerSystem.UpdateCanMove(uid);
  43. }
  44. private void OnBlockingShutdown(EntityUid uid, BlockMovementComponent component, ComponentShutdown args)
  45. {
  46. _actionBlockerSystem.UpdateCanMove(uid);
  47. }
  48. }