Gas Thermo ECS (#6442)
This commit is contained in:
parent
133134d9cc
commit
03a5a71243
|
|
@ -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<GasThermoMachineComponent, RefreshPartsEvent>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<MachinePartComponent> 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;
|
||||
|
|
|
|||
|
|
@ -26,21 +26,25 @@ public sealed partial class ConstructionSystem
|
|||
RefreshParts(component);
|
||||
}
|
||||
|
||||
public IEnumerable<MachinePartComponent> GetAllParts(MachineComponent component)
|
||||
public List<MachinePartComponent> GetAllParts(MachineComponent component)
|
||||
{
|
||||
var parts = new List<MachinePartComponent>();
|
||||
|
||||
foreach (var entity in component.PartContainer.ContainedEntities)
|
||||
{
|
||||
if (TryComp<MachinePartComponent?>(entity, out var machinePart))
|
||||
yield return machinePart;
|
||||
parts.Add(machinePart);
|
||||
}
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
public void RefreshParts(MachineComponent component)
|
||||
{
|
||||
foreach (var refreshable in EntityManager.GetComponents<IRefreshParts>(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<MachinePartComponent> Parts = new List<MachinePartComponent>();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue