diff --git a/Content.Shared/_CP14/MagicSpell/Spells/CP14AdjustAllSolutionThermalEnergy.cs b/Content.Shared/_CP14/MagicSpell/Spells/CP14AdjustAllSolutionThermalEnergy.cs new file mode 100644 index 0000000000..a76fd871d4 --- /dev/null +++ b/Content.Shared/_CP14/MagicSpell/Spells/CP14AdjustAllSolutionThermalEnergy.cs @@ -0,0 +1,57 @@ +using Content.Shared.Chemistry.Components.SolutionManager; +using Content.Shared.Chemistry.EntitySystems; + +namespace Content.Shared._CP14.MagicSpell.Spells; + +/// +/// Adjusts the thermal energy of all the solutions inside the container. +/// +public sealed partial class CP14AdjustAllSolutionThermalEnergy : CP14SpellEffect +{ + /// + /// The change in 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; + + public override void Effect(EntityManager entManager, CP14SpellEffectBaseArgs args) + { + var solutionContainer = entManager.System(); + + if (!entManager.TryGetComponent(args.Target, out var solutionComp)) + return; + + var target = new Entity(args.Target.Value, solutionComp); + foreach (var (_, solution) in solutionContainer.EnumerateSolutions(target)) + { + if (solution.Comp.Solution.Volume == 0) + continue; + + var maxTemp = MaxTemp ?? float.PositiveInfinity; + var minTemp = Math.Max(MinTemp ?? 0, 0); + var oldTemp = solution.Comp.Solution.Temperature; + + if (Delta > 0 && oldTemp >= maxTemp) + continue; + if (Delta < 0 && oldTemp <= minTemp) + continue; + + var heatCap = solution.Comp.Solution.GetHeatCapacity(null); + var deltaT = Delta / heatCap; + + solutionContainer.SetTemperature(solution, Math.Clamp(oldTemp + deltaT, minTemp, maxTemp)); + } + } +} diff --git a/Resources/Prototypes/_CP14/Entities/Actions/Spells/Fire/heat.yml b/Resources/Prototypes/_CP14/Entities/Actions/Spells/Fire/heat.yml index bf073bb3f6..aed873d34d 100644 --- a/Resources/Prototypes/_CP14/Entities/Actions/Spells/Fire/heat.yml +++ b/Resources/Prototypes/_CP14/Entities/Actions/Spells/Fire/heat.yml @@ -16,6 +16,8 @@ - !type:CP14SpellSpawnEntityOnTarget spawns: - CP14ImpactEffectHeat + - !type:CP14AdjustAllSolutionThermalEnergy + delta: 3600 # One full use heats 100u from ~300k to ~650k - !type:CP14SpellApplyEntityEffect effects: - !type:AdjustTemperature diff --git a/Resources/Prototypes/_CP14/Entities/Actions/Spells/Water/freeze.yml b/Resources/Prototypes/_CP14/Entities/Actions/Spells/Water/freeze.yml index c0093a92ee..796547311e 100644 --- a/Resources/Prototypes/_CP14/Entities/Actions/Spells/Water/freeze.yml +++ b/Resources/Prototypes/_CP14/Entities/Actions/Spells/Water/freeze.yml @@ -16,6 +16,8 @@ - !type:CP14SpellSpawnEntityOnTarget spawns: - CP14ImpactEffectFreeze + - !type:CP14AdjustAllSolutionThermalEnergy + delta: -1200 # One full use cools 100u from ~300k to ~250k - !type:CP14SpellApplyEntityEffect effects: - !type:MovespeedModifier @@ -77,4 +79,4 @@ components: - type: CP14SpellStorage spells: - - CP14ActionSpellFreeze \ No newline at end of file + - CP14ActionSpellFreeze