using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.EntitySystems; using Robust.Shared.Prototypes; namespace Content.Shared.EntityEffects.Effects.Solution; // TODO: Energy conservation!!! Once HeatContainers are merged nuke this and everything in SolutionContainerSystem to respect energy conservation! /// /// Sets the temperature of this solution to a fixed value. /// /// public sealed class SetSolutionTemperatureEntityEffectSystem : EntityEffectSystem { [Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!; protected override void Effect(Entity entity, ref EntityEffectEvent args) { _solutionContainer.SetTemperature(entity, args.Effect.Temperature); } } /// public sealed partial class SetSolutionTemperature : EntityEffectBase { /// /// The temperature to set the solution to. /// [DataField(required: true)] public float Temperature; public override string EntityEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("entity-effect-guidebook-set-solution-temperature-effect", ("chance", Probability), ("temperature", Temperature)); } /// /// Adjusts the temperature of this solution by a given amount. /// The temperature adjustment is modified by scale. /// /// public sealed class AdjustSolutionTemperatureEntityEffectSystem : EntityEffectSystem { [Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!; protected override void Effect(Entity entity, ref EntityEffectEvent args) { var solution = entity.Comp.Solution; var temperature = Math.Clamp(solution.Temperature + args.Scale * args.Effect.Delta, args.Effect.MinTemp, args.Effect.MaxTemp); _solutionContainer.SetTemperature(entity, temperature); } } /// public sealed partial class AdjustSolutionTemperature : EntityEffectBase { /// /// The change in temperature. /// [DataField(required: true)] public float Delta; /// /// The minimum temperature this effect can reach. /// [DataField] public float MinTemp; /// /// The maximum temperature this effect can reach. /// [DataField] public float MaxTemp = float.PositiveInfinity; public override string EntityEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("entity-effect-guidebook-adjust-solution-temperature-effect", ("chance", Probability), ("deltasign", MathF.Sign(Delta)), ("mintemp", MinTemp), ("maxtemp", MaxTemp)); } /// /// Adjusts the thermal energy of this solution by a given amount. /// The energy adjustment is modified by scale. /// /// public sealed class AdjustSolutionThermalEnergyEntityEffectSystem : EntityEffectSystem { [Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!; protected override void Effect(Entity entity, ref EntityEffectEvent args) { var solution = entity.Comp.Solution; var delta = args.Scale * args.Effect.Delta; // Don't adjust thermal energy if we're already at or above max temperature. switch (delta) { case > 0: if (solution.Temperature >= args.Effect.MaxTemp) return; break; case < 0: if (solution.Temperature <= args.Effect.MinTemp) return; break; default: return; } _solutionContainer.AddThermalEnergyClamped(entity, delta, args.Effect.MinTemp, args.Effect.MaxTemp); } } /// public sealed partial class AdjustSolutionThermalEnergy : EntityEffectBase { /// /// The change in thermal energy. /// [DataField(required: true)] public float Delta; /// /// The minimum temperature this effect can reach. /// [DataField] public float MinTemp; /// /// The maximum temperature this effect can reach. /// [DataField] public float MaxTemp = float.PositiveInfinity; public override string EntityEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("entity-effect-guidebook-adjust-solution-temperature-effect", ("chance", Probability), ("deltasign", MathF.Sign(Delta)), ("mintemp", MinTemp), ("maxtemp", MaxTemp)); }