using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Chemistry.Components
{
public sealed partial class Solution
{
///
/// If reactions will be checked for when adding reagents to the container.
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("canReact")]
public bool CanReact { get; set; } = true;
///
/// Volume needed to fill this container.
///
[ViewVariables]
public FixedPoint2 AvailableVolume => MaxVolume - CurrentVolume;
public FixedPoint2 DrawAvailable => CurrentVolume;
public FixedPoint2 DrainAvailable => CurrentVolume;
///
/// Checks if a solution can fit into the container.
///
/// The solution that is trying to be added.
/// If the solution can be fully added.
public bool CanAddSolution(Solution solution)
{
return solution.TotalVolume <= AvailableVolume;
}
[DataField("maxSpillRefill")]
public FixedPoint2 MaxSpillRefill { get; set; }
///
/// Initially set . If empty will be calculated based
/// on sum of fixed units.
///
[DataField("maxVol")] public FixedPoint2 InitialMaxVolume;
[ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2 MaxVolume { get; set; } = FixedPoint2.Zero;
[ViewVariables]
public FixedPoint2 CurrentVolume => TotalVolume;
///
/// The total heat capacity of all reagents in the solution.
///
[ViewVariables]
public float HeatCapacity => GetHeatCapacity();
///
/// The average specific heat of all reagents in the solution.
///
[ViewVariables]
public float SpecificHeat => HeatCapacity / (float) TotalVolume;
///
/// The total thermal energy of the reagents in the solution.
///
[ViewVariables(VVAccess.ReadWrite)]
public float ThermalEnergy {
get { return Temperature * HeatCapacity; }
set { Temperature = ((HeatCapacity == 0.0f) ? 0.0f : (value / HeatCapacity)); }
}
///
/// Returns the total heat capacity of the reagents in this solution.
///
/// The total heat capacity of the reagents in this solution.
private float GetHeatCapacity()
{
var heatCapacity = 0.0f;
var prototypeManager = IoCManager.Resolve();
foreach(var reagent in Contents)
{
if (!prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto))
proto = new ReagentPrototype();
heatCapacity += (float) reagent.Quantity * proto.SpecificHeat;
}
return heatCapacity;
}
}
}