From 03a5a71243a8961ce148aa9b3233fd69fe24ff21 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 7 Feb 2022 13:10:43 +1100 Subject: [PATCH] Gas Thermo ECS (#6442) --- .../Atmos/EntitySystems/GasThermoSystem.cs | 49 +++++++++++++++++++ .../Components/GasThermoMachineComponent.cs | 39 +-------------- .../ConstructionSystem.Machine.cs | 19 +++++-- 3 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 Content.Server/Atmos/EntitySystems/GasThermoSystem.cs diff --git a/Content.Server/Atmos/EntitySystems/GasThermoSystem.cs b/Content.Server/Atmos/EntitySystems/GasThermoSystem.cs new file mode 100644 index 0000000000..1f62dba223 --- /dev/null +++ b/Content.Server/Atmos/EntitySystems/GasThermoSystem.cs @@ -0,0 +1,49 @@ +using System; +using Content.Server.Atmos.Piping.Unary.Components; +using Content.Server.Construction; +using Content.Shared.Atmos; +using Robust.Shared.GameObjects; + +namespace Content.Server.Atmos.EntitySystems; + +public sealed class GasThermoSystem : EntitySystem +{ + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnGasThermoRefreshParts); + } + + private static void OnGasThermoRefreshParts(EntityUid uid, GasThermoMachineComponent component, RefreshPartsEvent args) + { + var matterBinRating = 0; + var laserRating = 0; + + foreach (var part in args.Parts) + { + switch (part.PartType) + { + case MachinePart.MatterBin: + matterBinRating += part.Rating; + break; + case MachinePart.Laser: + laserRating += part.Rating; + break; + } + } + + component.HeatCapacity = 5000 * MathF.Pow((matterBinRating - 1), 2); + + switch (component.Mode) + { + // 573.15K with stock parts. + case ThermoMachineMode.Heater: + component.MaxTemperature = Atmospherics.T20C + (component.InitialMaxTemperature * laserRating); + break; + // 73.15K with stock parts. + case ThermoMachineMode.Freezer: + component.MinTemperature = MathF.Max(Atmospherics.T0C - component.InitialMinTemperature + laserRating * 15f, Atmospherics.TCMB); + break; + } + } +} diff --git a/Content.Server/Atmos/Piping/Unary/Components/GasThermoMachineComponent.cs b/Content.Server/Atmos/Piping/Unary/Components/GasThermoMachineComponent.cs index a8726d1a76..0560554dbb 100644 --- a/Content.Server/Atmos/Piping/Unary/Components/GasThermoMachineComponent.cs +++ b/Content.Server/Atmos/Piping/Unary/Components/GasThermoMachineComponent.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Content.Server.Construction; -using Content.Server.Construction.Components; using Content.Shared.Atmos; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; @@ -11,7 +7,7 @@ using Robust.Shared.ViewVariables; namespace Content.Server.Atmos.Piping.Unary.Components { [RegisterComponent] - public class GasThermoMachineComponent : Component, IRefreshParts, ISerializationHooks + public sealed class GasThermoMachineComponent : Component, ISerializationHooks { [DataField("inlet")] public string InletName { get; set; } = "pipe"; @@ -40,39 +36,6 @@ namespace Content.Server.Atmos.Piping.Unary.Components public float InitialMinTemperature { get; private set; } public float InitialMaxTemperature { get; private set; } - void IRefreshParts.RefreshParts(IEnumerable parts) - { - var matterBinRating = 0; - var laserRating = 0; - - foreach (var part in parts) - { - switch (part.PartType) - { - case MachinePart.MatterBin: - matterBinRating += part.Rating; - break; - case MachinePart.Laser: - laserRating += part.Rating; - break; - } - } - - HeatCapacity = 5000 * MathF.Pow((matterBinRating - 1), 2); - - switch (Mode) - { - // 573.15K with stock parts. - case ThermoMachineMode.Heater: - MaxTemperature = Atmospherics.T20C + (InitialMaxTemperature * laserRating); - break; - // 73.15K with stock parts. - case ThermoMachineMode.Freezer: - MinTemperature = MathF.Max(Atmospherics.T0C - InitialMinTemperature + laserRating * 15f, Atmospherics.TCMB); - break; - } - } - void ISerializationHooks.AfterDeserialization() { InitialMinTemperature = MinTemperature; diff --git a/Content.Server/Construction/ConstructionSystem.Machine.cs b/Content.Server/Construction/ConstructionSystem.Machine.cs index 9e03a622ba..fc00c8d269 100644 --- a/Content.Server/Construction/ConstructionSystem.Machine.cs +++ b/Content.Server/Construction/ConstructionSystem.Machine.cs @@ -26,21 +26,25 @@ public sealed partial class ConstructionSystem RefreshParts(component); } - public IEnumerable GetAllParts(MachineComponent component) + public List GetAllParts(MachineComponent component) { + var parts = new List(); + foreach (var entity in component.PartContainer.ContainedEntities) { if (TryComp(entity, out var machinePart)) - yield return machinePart; + parts.Add(machinePart); } + + return parts; } public void RefreshParts(MachineComponent component) { - foreach (var refreshable in EntityManager.GetComponents(component.Owner)) + EntityManager.EventBus.RaiseLocalEvent(component.Owner, new RefreshPartsEvent() { - refreshable.RefreshParts(GetAllParts(component)); - } + Parts = GetAllParts(component), + }); } public void CreateBoardAndStockParts(MachineComponent component) @@ -110,3 +114,8 @@ public sealed partial class ConstructionSystem } } } + +public sealed class RefreshPartsEvent : EntityEventArgs +{ + public IReadOnlyList Parts = new List(); +}