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.Piping; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; namespace Content.Server.Atmos.Piping.Unary.EntitySystems { [UsedImplicitly] public class GasThermoMachineSystem : EntitySystem { [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnThermoMachineUpdated); SubscribeLocalEvent(OnThermoMachineLeaveAtmosphere); } private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, AtmosDeviceUpdateEvent args) { var appearance = EntityManager.GetComponentOrNull(thermoMachine.Owner); if (!thermoMachine.Enabled || !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) || !nodeContainer.TryGetNode(thermoMachine.InletName, out PipeNode? inlet)) { appearance?.SetData(ThermoMachineVisuals.Enabled, false); return; } var airHeatCapacity = _atmosphereSystem.GetHeatCapacity(inlet.Air); var combinedHeatCapacity = airHeatCapacity + thermoMachine.HeatCapacity; var oldTemperature = inlet.Air.Temperature; if (combinedHeatCapacity > 0) { appearance?.SetData(ThermoMachineVisuals.Enabled, true); var combinedEnergy = thermoMachine.HeatCapacity * thermoMachine.TargetTemperature + airHeatCapacity * inlet.Air.Temperature; inlet.Air.Temperature = combinedEnergy / combinedHeatCapacity; } // TODO ATMOS: Active power usage. } private void OnThermoMachineLeaveAtmosphere(EntityUid uid, GasThermoMachineComponent component, AtmosDeviceDisabledEvent args) { if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance)) { appearance.SetData(ThermoMachineVisuals.Enabled, false); } } } }