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;
|
2023-06-28 14:28:38 +03:00
|
|
|
using Content.Server.NodeContainer.EntitySystems;
|
2021-07-04 18:11:52 +02:00
|
|
|
using Content.Server.NodeContainer.Nodes;
|
2022-06-21 14:04:55 +12:00
|
|
|
using Content.Shared.Atmos.Piping;
|
|
|
|
|
using Content.Shared.Interaction;
|
2021-06-19 13:25:05 +02:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
|
|
|
|
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!;
|
2023-02-02 17:34:53 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2023-06-28 14:28:38 +03:00
|
|
|
[Dependency] private readonly NodeContainerSystem _nodeContainer = 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);
|
2022-06-21 14:04:55 +12:00
|
|
|
SubscribeLocalEvent<GasOutletInjectorComponent, ActivateInWorldEvent>(OnActivate);
|
|
|
|
|
SubscribeLocalEvent<GasOutletInjectorComponent, MapInitEvent>(OnMapInit);
|
2021-06-19 13:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-21 14:04:55 +12:00
|
|
|
private void OnMapInit(EntityUid uid, GasOutletInjectorComponent component, MapInitEvent args)
|
|
|
|
|
{
|
2023-02-02 17:34:53 +01:00
|
|
|
UpdateAppearance(uid, component);
|
2022-06-21 14:04:55 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnActivate(EntityUid uid, GasOutletInjectorComponent component, ActivateInWorldEvent args)
|
2021-06-19 13:25:05 +02:00
|
|
|
{
|
2024-05-31 16:26:19 -04:00
|
|
|
if (args.Handled || !args.Complex)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-06-21 14:04:55 +12:00
|
|
|
component.Enabled = !component.Enabled;
|
2023-02-02 17:34:53 +01:00
|
|
|
UpdateAppearance(uid, component);
|
2024-05-31 16:26:19 -04:00
|
|
|
args.Handled = true;
|
2022-06-21 14:04:55 +12:00
|
|
|
}
|
|
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
public void UpdateAppearance(EntityUid uid, GasOutletInjectorComponent component, AppearanceComponent? appearance = null)
|
2022-06-21 14:04:55 +12:00
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
if (!Resolve(uid, ref appearance, false))
|
2022-06-21 14:04:55 +12:00
|
|
|
return;
|
2021-06-19 13:25:05 +02:00
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(uid, OutletInjectorVisuals.Enabled, component.Enabled, appearance);
|
2022-06-21 14:04:55 +12:00
|
|
|
}
|
|
|
|
|
|
2023-12-21 18:48:18 -07:00
|
|
|
private void OnOutletInjectorUpdated(EntityUid uid, GasOutletInjectorComponent injector, ref AtmosDeviceUpdateEvent args)
|
2022-06-21 14:04:55 +12:00
|
|
|
{
|
2021-06-19 13:25:05 +02:00
|
|
|
if (!injector.Enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-03-30 17:17:53 +13:00
|
|
|
if (!_nodeContainer.TryGetNode(uid, injector.InletName, out PipeNode? inlet))
|
2021-06-19 13:25:05 +02:00
|
|
|
return;
|
|
|
|
|
|
2024-03-30 17:17:53 +13:00
|
|
|
var environment = _atmosphereSystem.GetContainingMixture(uid, args.Grid, args.Map, true, 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-06-21 14:04:55 +12:00
|
|
|
if (environment.Pressure > injector.MaxPressure)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-08-12 23:42:12 -07:00
|
|
|
var timeDelta = args.dt;
|
2022-06-21 14:04:55 +12:00
|
|
|
|
|
|
|
|
// TODO adjust ratio so that environment does not go above MaxPressure?
|
2023-12-11 15:59:47 -08:00
|
|
|
var ratio = MathF.Min(1f, timeDelta * injector.TransferRate * _atmosphereSystem.PumpSpeedup() / inlet.Air.Volume);
|
2022-03-01 03:39:30 +13:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|