1
0

ShuttleConsoleSystem.Drone.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Content.Server.Shuttles.Components;
  2. using Content.Server.Shuttles.Events;
  3. using Content.Shared.Station.Components;
  4. using Content.Shared.UserInterface;
  5. namespace Content.Server.Shuttles.Systems;
  6. public sealed partial class ShuttleConsoleSystem
  7. {
  8. /// <summary>
  9. /// Gets the drone console target if applicable otherwise returns itself.
  10. /// </summary>
  11. public EntityUid? GetDroneConsole(EntityUid consoleUid)
  12. {
  13. var getShuttleEv = new ConsoleShuttleEvent
  14. {
  15. Console = consoleUid,
  16. };
  17. RaiseLocalEvent(consoleUid, ref getShuttleEv);
  18. return getShuttleEv.Console;
  19. }
  20. /// <summary>
  21. /// Refreshes all drone console entities.
  22. /// </summary>
  23. public void RefreshDroneConsoles()
  24. {
  25. var query = AllEntityQuery<DroneConsoleComponent>();
  26. while (query.MoveNext(out var uid, out var comp))
  27. {
  28. comp.Entity = GetShuttleConsole(uid, comp);
  29. }
  30. }
  31. private void OnDronePilotConsoleOpen(EntityUid uid, DroneConsoleComponent component, AfterActivatableUIOpenEvent args)
  32. {
  33. component.Entity = GetShuttleConsole(uid);
  34. }
  35. private void OnDronePilotConsoleClose(EntityUid uid, DroneConsoleComponent component, BoundUIClosedEvent args)
  36. {
  37. // Only if last person closed UI.
  38. if (!_ui.IsUiOpen(uid, args.UiKey))
  39. component.Entity = null;
  40. }
  41. private void OnCargoGetConsole(EntityUid uid, DroneConsoleComponent component, ref ConsoleShuttleEvent args)
  42. {
  43. args.Console = GetShuttleConsole(uid, component);
  44. }
  45. /// <summary>
  46. /// Gets the relevant shuttle console to proxy from the drone console.
  47. /// </summary>
  48. private EntityUid? GetShuttleConsole(EntityUid uid, DroneConsoleComponent? component = null)
  49. {
  50. if (!Resolve(uid, ref component))
  51. return null;
  52. var stationUid = _station.GetOwningStation(uid);
  53. if (stationUid == null)
  54. return null;
  55. // I know this sucks but needs device linking or something idunno
  56. var query = AllEntityQuery<ShuttleConsoleComponent, TransformComponent>();
  57. while (query.MoveNext(out var cUid, out _, out var xform))
  58. {
  59. if (xform.GridUid == null ||
  60. !TryComp<StationMemberComponent>(xform.GridUid, out var member) ||
  61. member.Station != stationUid)
  62. {
  63. continue;
  64. }
  65. foreach (var compType in component.Components.Values)
  66. {
  67. if (!HasComp(xform.GridUid, compType.Component.GetType()))
  68. continue;
  69. return cUid;
  70. }
  71. }
  72. return null;
  73. }
  74. }