using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
namespace Content.Server.Chemistry.ReactionEffects
{
///
/// Sets the temperature of the solution involved with the reaction to a new value.
///
[DataDefinition]
public sealed class SetSolutionTemperatureEffect : ReagentEffect
{
///
/// The temperature to set the solution to.
///
[DataField("temperature", required: true)] private float _temperature;
public override void Effect(ReagentEffectArgs args)
{
var solution = args.Source;
if (solution == null)
return;
solution.Temperature = _temperature;
}
}
///
/// Adjusts the temperature of the solution involved in the reaction.
///
[DataDefinition]
[Virtual]
public class AdjustSolutionTemperatureEffect : ReagentEffect
{
///
/// The total change in the thermal energy of the solution.
///
[DataField("delta", required: true)] protected float Delta;
///
/// The minimum temperature this effect can reach.
///
[DataField("minTemp")] private float _minTemp = 0.0f;
///
/// The maximum temperature this effect can reach.
///
[DataField("maxTemp")] private float _maxTemp = float.PositiveInfinity;
///
/// If true, then scale ranges by intensity. If not, the ranges are the same regardless of reactant amount.
///
[DataField("scaled")] private bool _scaled;
///
///
///
///
///
protected virtual float GetDeltaT(Solution solution) => Delta;
public override void Effect(ReagentEffectArgs args)
{
var solution = args.Source;
if (solution == null)
return;
var deltaT = GetDeltaT(solution);
if (_scaled)
deltaT = deltaT * (float) args.Quantity;
if (deltaT == 0.0d)
return;
if (deltaT > 0.0d && solution.Temperature >= _maxTemp)
return;
if (deltaT < 0.0d && solution.Temperature <= _minTemp)
return;
solution.Temperature = MathF.Max(MathF.Min(solution.Temperature + deltaT, _minTemp), _maxTemp);
}
}
///
/// Adjusts the thermal energy of the solution involved in the reaction.
///
public sealed class AdjustSolutionThermalEnergyEffect : AdjustSolutionTemperatureEffect
{
protected override float GetDeltaT(Solution solution)
{
var heatCapacity = solution.HeatCapacity;
if (heatCapacity == 0.0f)
return 0.0f;
return Delta / heatCapacity;
}
}
}