1
0

ShuttleSystem.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using Content.Server.Administration.Logs;
  2. using Content.Server.Body.Systems;
  3. using Content.Server.Doors.Systems;
  4. using Content.Server.Parallax;
  5. using Content.Server.Procedural;
  6. using Content.Server.Shuttles.Components;
  7. using Content.Server.Station.Systems;
  8. using Content.Server.Stunnable;
  9. using Content.Shared.GameTicking;
  10. using Content.Shared.Mobs.Systems;
  11. using Content.Shared.Salvage;
  12. using Content.Shared.Shuttles.Systems;
  13. using Content.Shared.Throwing;
  14. using JetBrains.Annotations;
  15. using Robust.Server.GameObjects;
  16. using Robust.Server.GameStates;
  17. using Robust.Shared.Audio;
  18. using Robust.Shared.Audio.Systems;
  19. using Robust.Shared.Configuration;
  20. using Robust.Shared.EntitySerialization.Systems;
  21. using Robust.Shared.Map;
  22. using Robust.Shared.Map.Components;
  23. using Robust.Shared.Physics;
  24. using Robust.Shared.Physics.Components;
  25. using Robust.Shared.Physics.Systems;
  26. using Robust.Shared.Prototypes;
  27. using Robust.Shared.Random;
  28. using Robust.Shared.Timing;
  29. namespace Content.Server.Shuttles.Systems;
  30. [UsedImplicitly]
  31. public sealed partial class ShuttleSystem : SharedShuttleSystem
  32. {
  33. [Dependency] private readonly IAdminLogManager _logger = default!;
  34. [Dependency] private readonly IComponentFactory _factory = default!;
  35. [Dependency] private readonly IConfigurationManager _cfg = default!;
  36. [Dependency] private readonly IGameTiming _gameTiming = default!;
  37. [Dependency] private readonly MapSystem _mapSystem = default!;
  38. [Dependency] private readonly IMapManager _mapManager = default!;
  39. [Dependency] private readonly IPrototypeManager _protoManager = default!;
  40. [Dependency] private readonly IRobustRandom _random = default!;
  41. [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
  42. [Dependency] private readonly BiomeSystem _biomes = default!;
  43. [Dependency] private readonly BodySystem _bobby = default!;
  44. [Dependency] private readonly DockingSystem _dockSystem = default!;
  45. [Dependency] private readonly DungeonSystem _dungeon = default!;
  46. [Dependency] private readonly EntityLookupSystem _lookup = default!;
  47. [Dependency] private readonly FixtureSystem _fixtures = default!;
  48. [Dependency] private readonly MapLoaderSystem _loader = default!;
  49. [Dependency] private readonly MetaDataSystem _metadata = default!;
  50. [Dependency] private readonly PvsOverrideSystem _pvs = default!;
  51. [Dependency] private readonly SharedAudioSystem _audio = default!;
  52. [Dependency] private readonly SharedPhysicsSystem _physics = default!;
  53. [Dependency] private readonly SharedTransformSystem _transform = default!;
  54. [Dependency] private readonly SharedSalvageSystem _salvage = default!;
  55. [Dependency] private readonly ShuttleConsoleSystem _console = default!;
  56. [Dependency] private readonly StationSystem _station = default!;
  57. [Dependency] private readonly StunSystem _stuns = default!;
  58. [Dependency] private readonly ThrowingSystem _throwing = default!;
  59. [Dependency] private readonly ThrusterSystem _thruster = default!;
  60. [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
  61. private EntityQuery<MapGridComponent> _gridQuery;
  62. public const float TileMassMultiplier = 0.5f;
  63. public override void Initialize()
  64. {
  65. base.Initialize();
  66. _gridQuery = GetEntityQuery<MapGridComponent>();
  67. InitializeFTL();
  68. InitializeGridFills();
  69. InitializeIFF();
  70. InitializeImpact();
  71. SubscribeLocalEvent<ShuttleComponent, ComponentStartup>(OnShuttleStartup);
  72. SubscribeLocalEvent<ShuttleComponent, ComponentShutdown>(OnShuttleShutdown);
  73. SubscribeLocalEvent<GridInitializeEvent>(OnGridInit);
  74. SubscribeLocalEvent<FixturesComponent, GridFixtureChangeEvent>(OnGridFixtureChange);
  75. }
  76. public override void Update(float frameTime)
  77. {
  78. base.Update(frameTime);
  79. UpdateHyperspace();
  80. }
  81. private void OnGridFixtureChange(EntityUid uid, FixturesComponent manager, GridFixtureChangeEvent args)
  82. {
  83. foreach (var fixture in args.NewFixtures)
  84. {
  85. _physics.SetDensity(uid, fixture.Key, fixture.Value, TileMassMultiplier, false, manager);
  86. _fixtures.SetRestitution(uid, fixture.Key, fixture.Value, 0.1f, false, manager);
  87. }
  88. }
  89. private void OnGridInit(GridInitializeEvent ev)
  90. {
  91. if (HasComp<MapComponent>(ev.EntityUid))
  92. return;
  93. EntityManager.EnsureComponent<ShuttleComponent>(ev.EntityUid);
  94. }
  95. private void OnShuttleStartup(EntityUid uid, ShuttleComponent component, ComponentStartup args)
  96. {
  97. if (!EntityManager.HasComponent<MapGridComponent>(uid))
  98. {
  99. return;
  100. }
  101. if (!EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent))
  102. {
  103. return;
  104. }
  105. if (component.Enabled)
  106. {
  107. Enable(uid, component: physicsComponent, shuttle: component);
  108. }
  109. }
  110. public void Toggle(EntityUid uid, ShuttleComponent component)
  111. {
  112. if (!EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent))
  113. return;
  114. component.Enabled = !component.Enabled;
  115. if (component.Enabled)
  116. {
  117. Enable(uid, component: physicsComponent, shuttle: component);
  118. }
  119. else
  120. {
  121. Disable(uid, component: physicsComponent);
  122. }
  123. }
  124. public void Enable(EntityUid uid, FixturesComponent? manager = null, PhysicsComponent? component = null, ShuttleComponent? shuttle = null)
  125. {
  126. if (!Resolve(uid, ref manager, ref component, ref shuttle, false))
  127. return;
  128. _physics.SetBodyType(uid, BodyType.Dynamic, manager: manager, body: component);
  129. _physics.SetBodyStatus(uid, component, BodyStatus.InAir);
  130. _physics.SetFixedRotation(uid, false, manager: manager, body: component);
  131. _physics.SetLinearDamping(uid, component, shuttle.LinearDamping);
  132. _physics.SetAngularDamping(uid, component, shuttle.AngularDamping);
  133. }
  134. public void Disable(EntityUid uid, FixturesComponent? manager = null, PhysicsComponent? component = null)
  135. {
  136. if (!Resolve(uid, ref manager, ref component, false))
  137. return;
  138. _physics.SetBodyType(uid, BodyType.Static, manager: manager, body: component);
  139. _physics.SetBodyStatus(uid, component, BodyStatus.OnGround);
  140. _physics.SetFixedRotation(uid, true, manager: manager, body: component);
  141. }
  142. private void OnShuttleShutdown(EntityUid uid, ShuttleComponent component, ComponentShutdown args)
  143. {
  144. // None of the below is necessary for any cleanup if we're just deleting.
  145. if (EntityManager.GetComponent<MetaDataComponent>(uid).EntityLifeStage >= EntityLifeStage.Terminating)
  146. return;
  147. Disable(uid);
  148. }
  149. }