private void OnPumpUpdated(EntityUid uid, GasPressurePumpComponent pump, AtmosDeviceUpdateEvent args)
        {
            var appearance = pump.Owner.GetComponentOrNull <AppearanceComponent>();

            if (!pump.Enabled ||
                !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) ||
                !nodeContainer.TryGetNode(pump.InletName, out PipeNode? inlet) ||
                !nodeContainer.TryGetNode(pump.OutletName, out PipeNode? outlet))
            {
                appearance?.SetData(PressurePumpVisuals.Enabled, false);
                return;
            }

            var outputStartingPressure = outlet.Air.Pressure;

            if (MathHelper.CloseToPercent(pump.TargetPressure, outputStartingPressure))
            {
                appearance?.SetData(PressurePumpVisuals.Enabled, false);
                return; // No need to pump gas if target has been reached.
            }

            if (inlet.Air.TotalMoles > 0 && inlet.Air.Temperature > 0)
            {
                appearance?.SetData(PressurePumpVisuals.Enabled, true);

                // We calculate the necessary moles to transfer using our good ol' friend PV=nRT.
                var pressureDelta = pump.TargetPressure - outputStartingPressure;
                var transferMoles = pressureDelta * outlet.Air.Volume / inlet.Air.Temperature * Atmospherics.R;

                var removed = inlet.Air.Remove(transferMoles);
                outlet.AssumeAir(removed);
            }
        }
 private void OnPumpLeaveAtmosphere(EntityUid uid, GasPressurePumpComponent component, AtmosDeviceDisabledEvent args)
 {
     if (ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance))
     {
         appearance.SetData(PressurePumpVisuals.Enabled, false);
     }
 }
 private void OnOutputPressureChangeMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpChangeOutputPressureMessage args)
 {
     pump.TargetPressure = Math.Clamp(args.Pressure, 0f, Atmospherics.MaxOutputPressure);
     _adminLogSystem.Add(LogType.AtmosPressureChanged, LogImpact.Medium,
                         $"{ToPrettyString(args.Session.AttachedEntity!.Value):player} set the pressure on {ToPrettyString(uid):device} to {args.Pressure}kPa");
     DirtyUI(uid, pump);
 }
 private void OnToggleStatusMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpToggleStatusMessage args)
 {
     pump.Enabled = args.Enabled;
     _adminLogSystem.Add(LogType.AtmosPowerChanged, LogImpact.Medium,
                         $"{ToPrettyString(args.Session.AttachedEntity!.Value):player} set the power on {ToPrettyString(uid):device} to {args.Enabled}");
     DirtyUI(uid, pump);
 }
        private void OnPumpUpdated(EntityUid uid, GasPressurePumpComponent pump, AtmosDeviceUpdateEvent args)
        {
            if (!pump.Enabled ||
                !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) ||
                !nodeContainer.TryGetNode(pump.InletName, out PipeNode? inlet) ||
                !nodeContainer.TryGetNode(pump.OutletName, out PipeNode? outlet))
            {
                _ambientSoundSystem.SetAmbience(pump.Owner, false);
                return;
            }

            var outputStartingPressure = outlet.Air.Pressure;

            if (outputStartingPressure >= pump.TargetPressure)
            {
                _ambientSoundSystem.SetAmbience(pump.Owner, false);
                return; // No need to pump gas if target has been reached.
            }

            if (inlet.Air.TotalMoles > 0 && inlet.Air.Temperature > 0)
            {
                // We calculate the necessary moles to transfer using our good ol' friend PV=nRT.
                var pressureDelta = pump.TargetPressure - outputStartingPressure;
                var transferMoles = (pressureDelta * outlet.Air.Volume) / (inlet.Air.Temperature * Atmospherics.R);

                var removed = inlet.Air.Remove(transferMoles);
                _atmosphereSystem.Merge(outlet.Air, removed);
                _ambientSoundSystem.SetAmbience(pump.Owner, removed.TotalMoles > 0f);
            }
        }
        private void OnPumpLeaveAtmosphere(EntityUid uid, GasPressurePumpComponent pump, AtmosDeviceDisabledEvent args)
        {
            pump.Enabled = false;
            UpdateAppearance(uid, pump);

            DirtyUI(uid, pump);
            _userInterfaceSystem.TryCloseAll(uid, GasPressurePumpUiKey.Key);
        }
        private void OnExamined(EntityUid uid, GasPressurePumpComponent pump, ExaminedEvent args)
        {
            if (!pump.Owner.Transform.Anchored || !args.IsInDetailsRange) // Not anchored? Out of range? No status.
            {
                return;
            }

            if (Loc.TryGetString("gas-pressure-pump-system-examined", out var str,
                                 ("statusColor", "lightblue"), // TODO: change with pressure?
                                 ("pressure", pump.TargetPressure)
                                 ))
            {
                args.PushMarkup(str);
            }
        }
        private void OnPumpInteractHand(EntityUid uid, GasPressurePumpComponent component, InteractHandEvent args)
        {
            if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
            {
                return;
            }

            if (EntityManager.GetComponent <TransformComponent>(component.Owner).Anchored)
            {
                _userInterfaceSystem.TryOpen(uid, GasPressurePumpUiKey.Key, actor.PlayerSession);
                DirtyUI(uid, component);
            }
            else
            {
                args.User.PopupMessageCursor(Loc.GetString("comp-gas-pump-ui-needs-anchor"));
            }

            args.Handled = true;
        }
 private void OnOutputPressureChangeMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpChangeOutputPressureMessage args)
 {
     pump.TargetPressure = Math.Clamp(args.Pressure, 0f, Atmospherics.MaxOutputPressure);
     DirtyUI(uid, pump);
 }
 private void OnToggleStatusMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpToggleStatusMessage args)
 {
     pump.Enabled = args.Enabled;
     DirtyUI(uid, pump);
 }
 private void OnInit(EntityUid uid, GasPressurePumpComponent pump, ComponentInit args)
 {
     UpdateAppearance(uid, pump);
 }