make heat and freeze work on reagents (#1314)

* make heat and freeze work on reagents

* has to run before AdjustTemperature

* implement suggested changes

* almost missed this edge case

* 0k is the limit

* cleanup
This commit is contained in:
Ignaz "Ian" Kraft
2025-05-27 23:24:01 +02:00
committed by GitHub
parent 2607eaeddd
commit 33bb537f81
3 changed files with 62 additions and 1 deletions

View File

@@ -0,0 +1,57 @@
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
namespace Content.Shared._CP14.MagicSpell.Spells;
/// <summary>
/// Adjusts the thermal energy of all the solutions inside the container.
/// </summary>
public sealed partial class CP14AdjustAllSolutionThermalEnergy : CP14SpellEffect
{
/// <summary>
/// The change in energy.
/// </summary>
[DataField(required: true)]
public float Delta;
/// <summary>
/// The minimum temperature this effect can reach.
/// </summary>
[DataField]
public float? MinTemp;
/// <summary>
/// The maximum temperature this effect can reach.
/// </summary>
[DataField]
public float? MaxTemp;
public override void Effect(EntityManager entManager, CP14SpellEffectBaseArgs args)
{
var solutionContainer = entManager.System<SharedSolutionContainerSystem>();
if (!entManager.TryGetComponent<SolutionContainerManagerComponent>(args.Target, out var solutionComp))
return;
var target = new Entity<SolutionContainerManagerComponent?>(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));
}
}
}

View File

@@ -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

View File

@@ -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
- CP14ActionSpellFreeze