Fix dual port vents 2: Electric Boogaloo (#8396)

This commit is contained in:
Leon Friedrich
2022-06-06 20:38:20 +12:00
committed by GitHub
parent 9964e20abd
commit cbae005d08
7 changed files with 100 additions and 153 deletions

View File

@@ -6,6 +6,8 @@ using Content.Server.Atmos.Piping.Unary.Components;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.MachineLinking.Events;
using Content.Server.MachineLinking.System;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.Nodes;
using Content.Server.Power.Components;
@@ -24,6 +26,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!;
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
@@ -37,6 +40,8 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
SubscribeLocalEvent<GasVentPumpComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
SubscribeLocalEvent<GasVentPumpComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<GasVentPumpComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
SubscribeLocalEvent<GasVentPumpComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<GasVentPumpComponent, SignalReceivedEvent>(OnSignalReceived);
}
private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, AtmosDeviceUpdateEvent args)
@@ -47,10 +52,17 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
return;
}
var nodeName = vent.PumpDirection switch
{
VentPumpDirection.Releasing => vent.Inlet,
VentPumpDirection.Siphoning => vent.Outlet,
_ => throw new ArgumentOutOfRangeException()
};
if (!vent.Enabled
|| !TryComp(uid, out AtmosDeviceComponent? device)
|| !TryComp(uid, out NodeContainerComponent? nodeContainer)
|| !nodeContainer.TryGetNode(vent.InletName, out PipeNode? pipe))
|| !nodeContainer.TryGetNode(nodeName, out PipeNode? pipe))
{
return;
}
@@ -191,6 +203,33 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
}
}
private void OnInit(EntityUid uid, GasVentPumpComponent component, ComponentInit args)
{
if (component.CanLink)
_signalSystem.EnsureReceiverPorts(uid, component.PressurizePort, component.DepressurizePort);
}
private void OnSignalReceived(EntityUid uid, GasVentPumpComponent component, SignalReceivedEvent args)
{
if (!component.CanLink)
return;
if (args.Port == component.PressurizePort)
{
component.PumpDirection = VentPumpDirection.Releasing;
component.ExternalPressureBound = component.PressurizePressure;
component.PressureChecks = VentPressureBound.ExternalBound;
UpdateState(uid, component);
}
else if (args.Port == component.DepressurizePort)
{
component.PumpDirection = VentPumpDirection.Siphoning;
component.ExternalPressureBound = component.DepressurizePressure;
component.PressureChecks = VentPressureBound.ExternalBound;
UpdateState(uid, component);
}
}
private void UpdateState(EntityUid uid, GasVentPumpComponent vent, AppearanceComponent? appearance = null)
{
if (!Resolve(uid, ref appearance, false))