2021-07-19 12:07:37 +02:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Server.Atmos.Piping.Components;
|
|
|
|
|
using Content.Server.Atmos.Piping.Unary.Components;
|
|
|
|
|
using Content.Server.NodeContainer;
|
2021-07-04 18:11:52 +02:00
|
|
|
using Content.Server.NodeContainer.Nodes;
|
2021-06-19 13:25:05 +02:00
|
|
|
using JetBrains.Annotations;
|
2022-03-01 03:39:30 +13:00
|
|
|
using Robust.Shared.Timing;
|
2021-06-19 13:25:05 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class GasOutletInjectorSystem : EntitySystem
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
2022-03-01 03:39:30 +13:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2021-07-26 12:58:17 +02:00
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<GasOutletInjectorComponent, AtmosDeviceUpdateEvent>(OnOutletInjectorUpdated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnOutletInjectorUpdated(EntityUid uid, GasOutletInjectorComponent injector, AtmosDeviceUpdateEvent args)
|
|
|
|
|
{
|
|
|
|
|
injector.Injecting = false;
|
|
|
|
|
|
|
|
|
|
if (!injector.Enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-09-28 13:35:29 +02:00
|
|
|
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
|
2021-06-19 13:25:05 +02:00
|
|
|
return;
|
|
|
|
|
|
2022-03-01 03:39:30 +13:00
|
|
|
if (!TryComp(uid, out AtmosDeviceComponent? device))
|
|
|
|
|
return;
|
|
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
if (!nodeContainer.TryGetNode(injector.InletName, out PipeNode? inlet))
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
var environment = _atmosphereSystem.GetTileMixture(EntityManager.GetComponent<TransformComponent>(injector.Owner).Coordinates, true);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2021-07-19 12:07:37 +02:00
|
|
|
if (environment == null)
|
2021-06-19 13:25:05 +02:00
|
|
|
return;
|
|
|
|
|
|
2022-03-01 03:39:30 +13:00
|
|
|
if (inlet.Air.Temperature < 0)
|
|
|
|
|
return;
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2022-03-01 03:39:30 +13:00
|
|
|
var timeDelta = (float) (_gameTiming.CurTime - device.LastProcess).TotalSeconds;
|
|
|
|
|
var ratio = MathF.Min(1f, timeDelta * injector.TransferRate / inlet.Air.Volume);
|
|
|
|
|
var removed = inlet.Air.RemoveRatio(ratio);
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2022-03-01 03:39:30 +13:00
|
|
|
_atmosphereSystem.Merge(environment, removed);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|