SharedShuttleConsoleSystem.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Content.Shared.ActionBlocker;
  2. using Content.Shared.Movement.Events;
  3. using Content.Shared.Shuttles.BUIStates;
  4. using Content.Shared.Shuttles.Components;
  5. using Robust.Shared.Serialization;
  6. namespace Content.Shared.Shuttles.Systems
  7. {
  8. public abstract class SharedShuttleConsoleSystem : EntitySystem
  9. {
  10. [Dependency] protected readonly ActionBlockerSystem ActionBlockerSystem = default!;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<PilotComponent, UpdateCanMoveEvent>(HandleMovementBlock);
  15. SubscribeLocalEvent<PilotComponent, ComponentStartup>(OnStartup);
  16. SubscribeLocalEvent<PilotComponent, ComponentShutdown>(HandlePilotShutdown);
  17. }
  18. [Serializable, NetSerializable]
  19. protected sealed class PilotComponentState : ComponentState
  20. {
  21. public NetEntity? Console { get; }
  22. public PilotComponentState(NetEntity? uid)
  23. {
  24. Console = uid;
  25. }
  26. }
  27. protected virtual void HandlePilotShutdown(EntityUid uid, PilotComponent component, ComponentShutdown args)
  28. {
  29. ActionBlockerSystem.UpdateCanMove(uid);
  30. }
  31. private void OnStartup(EntityUid uid, PilotComponent component, ComponentStartup args)
  32. {
  33. ActionBlockerSystem.UpdateCanMove(uid);
  34. }
  35. private void HandleMovementBlock(EntityUid uid, PilotComponent component, UpdateCanMoveEvent args)
  36. {
  37. if (component.LifeStage > ComponentLifeStage.Running)
  38. return;
  39. if (component.Console == null)
  40. return;
  41. args.Cancel();
  42. }
  43. }
  44. }