54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using Content.Server.Atmos.EntitySystems;
|
|
using Content.Server.Atmos.Piping.Components;
|
|
using Content.Server.Atmos.Piping.Unary.Components;
|
|
using Content.Server.NodeContainer;
|
|
using Content.Server.NodeContainer.Nodes;
|
|
using Content.Shared.Atmos;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
|
|
namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|
{
|
|
[UsedImplicitly]
|
|
public class GasOutletInjectorSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
|
|
|
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;
|
|
|
|
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
|
|
return;
|
|
|
|
if (!nodeContainer.TryGetNode(injector.InletName, out PipeNode? inlet))
|
|
return;
|
|
|
|
var environment = _atmosphereSystem.GetTileMixture(EntityManager.GetComponent<TransformComponent>(injector.Owner).Coordinates, true);
|
|
|
|
if (environment == null)
|
|
return;
|
|
|
|
if (inlet.Air.Temperature > 0)
|
|
{
|
|
var transferMoles = inlet.Air.Pressure * injector.VolumeRate / (inlet.Air.Temperature * Atmospherics.R);
|
|
|
|
var removed = inlet.Air.Remove(transferMoles);
|
|
|
|
_atmosphereSystem.Merge(environment, removed);
|
|
}
|
|
}
|
|
}
|
|
}
|