Predict gasthermomachines (#33837)
* Predict gasthermomachines * despawn * smellby
This commit is contained in:
@@ -9,11 +9,8 @@ using Content.Server.Power.Components;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Atmos.Piping.Unary.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Shared.UserInterface;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Atmos.Piping.Unary.Systems;
|
||||
using Content.Shared.DeviceNetwork;
|
||||
using Content.Shared.DeviceNetwork.Events;
|
||||
using Content.Shared.Examine;
|
||||
@@ -22,36 +19,23 @@ using Content.Shared.DeviceNetwork.Components;
|
||||
namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class GasThermoMachineSystem : EntitySystem
|
||||
public sealed class GasThermoMachineSystem : SharedGasThermoMachineSystem
|
||||
{
|
||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
||||
[Dependency] private readonly PowerReceiverSystem _power = default!;
|
||||
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
|
||||
[Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GasThermoMachineComponent, AtmosDeviceUpdateEvent>(OnThermoMachineUpdated);
|
||||
SubscribeLocalEvent<GasThermoMachineComponent, ExaminedEvent>(OnExamined);
|
||||
|
||||
// UI events
|
||||
SubscribeLocalEvent<GasThermoMachineComponent, BeforeActivatableUIOpenEvent>(OnBeforeOpened);
|
||||
SubscribeLocalEvent<GasThermoMachineComponent, GasThermomachineToggleMessage>(OnToggleMessage);
|
||||
SubscribeLocalEvent<GasThermoMachineComponent, GasThermomachineChangeTemperatureMessage>(OnChangeTemperature);
|
||||
|
||||
// Device network
|
||||
SubscribeLocalEvent<GasThermoMachineComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
||||
}
|
||||
|
||||
private void OnBeforeOpened(Entity<GasThermoMachineComponent> ent, ref BeforeActivatableUIOpenEvent args)
|
||||
{
|
||||
DirtyUI(ent, ent.Comp);
|
||||
}
|
||||
|
||||
private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, ref AtmosDeviceUpdateEvent args)
|
||||
{
|
||||
thermoMachine.LastEnergyDelta = 0f;
|
||||
@@ -135,56 +119,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsHeater(GasThermoMachineComponent comp)
|
||||
{
|
||||
return comp.Cp >= 0;
|
||||
}
|
||||
|
||||
private void OnToggleMessage(EntityUid uid, GasThermoMachineComponent thermoMachine, GasThermomachineToggleMessage args)
|
||||
{
|
||||
var powerState = _power.TogglePower(uid);
|
||||
_adminLogger.Add(LogType.AtmosPowerChanged, $"{ToPrettyString(args.Actor)} turned {(powerState ? "On" : "Off")} {ToPrettyString(uid)}");
|
||||
DirtyUI(uid, thermoMachine);
|
||||
}
|
||||
|
||||
private void OnChangeTemperature(EntityUid uid, GasThermoMachineComponent thermoMachine, GasThermomachineChangeTemperatureMessage args)
|
||||
{
|
||||
if (IsHeater(thermoMachine))
|
||||
thermoMachine.TargetTemperature = MathF.Min(args.Temperature, thermoMachine.MaxTemperature);
|
||||
else
|
||||
thermoMachine.TargetTemperature = MathF.Max(args.Temperature, thermoMachine.MinTemperature);
|
||||
thermoMachine.TargetTemperature = MathF.Max(thermoMachine.TargetTemperature, Atmospherics.TCMB);
|
||||
_adminLogger.Add(LogType.AtmosTemperatureChanged, $"{ToPrettyString(args.Actor)} set temperature on {ToPrettyString(uid)} to {thermoMachine.TargetTemperature}");
|
||||
DirtyUI(uid, thermoMachine);
|
||||
}
|
||||
|
||||
private void DirtyUI(EntityUid uid, GasThermoMachineComponent? thermoMachine, UserInterfaceComponent? ui=null)
|
||||
{
|
||||
if (!Resolve(uid, ref thermoMachine, ref ui, false))
|
||||
return;
|
||||
|
||||
ApcPowerReceiverComponent? powerReceiver = null;
|
||||
if (!Resolve(uid, ref powerReceiver))
|
||||
return;
|
||||
|
||||
_userInterfaceSystem.SetUiState(uid, ThermomachineUiKey.Key,
|
||||
new GasThermomachineBoundUserInterfaceState(thermoMachine.MinTemperature, thermoMachine.MaxTemperature, thermoMachine.TargetTemperature, !powerReceiver.PowerDisabled, IsHeater(thermoMachine)));
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, GasThermoMachineComponent thermoMachine, ExaminedEvent args)
|
||||
{
|
||||
if (!args.IsInDetailsRange)
|
||||
return;
|
||||
|
||||
if (Loc.TryGetString("gas-thermomachine-system-examined", out var str,
|
||||
("machineName", !IsHeater(thermoMachine) ? "freezer" : "heater"),
|
||||
("tempColor", !IsHeater(thermoMachine) ? "deepskyblue" : "red"),
|
||||
("temp", Math.Round(thermoMachine.TargetTemperature,2))
|
||||
))
|
||||
|
||||
args.PushMarkup(str);
|
||||
}
|
||||
|
||||
private void OnPacketRecv(EntityUid uid, GasThermoMachineComponent component, DeviceNetworkPacketEvent args)
|
||||
{
|
||||
if (!TryComp(uid, out DeviceNetworkComponent? netConn)
|
||||
|
||||
Reference in New Issue
Block a user