ECS BloodstreamComponent (#5629)
This commit is contained in:
@@ -1,104 +1,34 @@
|
||||
using System;
|
||||
using Content.Server.Atmos;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Body.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedBloodstreamComponent))]
|
||||
public class BloodstreamComponent : SharedBloodstreamComponent, IGasMixtureHolder
|
||||
[RegisterComponent, Friend(typeof(BloodstreamSystem))]
|
||||
public class BloodstreamComponent : Component, IGasMixtureHolder
|
||||
{
|
||||
public override string Name => "Bloodstream";
|
||||
|
||||
/// <summary>
|
||||
/// Max volume of internal solution storage
|
||||
/// </summary>
|
||||
[DataField("maxVolume")] [ViewVariables]
|
||||
private FixedPoint2 _initialMaxVolume = FixedPoint2.New(250);
|
||||
[DataField("maxVolume")]
|
||||
public FixedPoint2 InitialMaxVolume = FixedPoint2.New(250);
|
||||
|
||||
/// <summary>
|
||||
/// Internal solution for reagent storage
|
||||
/// </summary>
|
||||
[ViewVariables] private Solution? _internalSolution;
|
||||
|
||||
/// <summary>
|
||||
/// Empty volume of internal solution
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public FixedPoint2 EmptyVolume => _internalSolution?.AvailableVolume ?? FixedPoint2.Zero;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Solution Solution = default!;
|
||||
|
||||
[ViewVariables]
|
||||
public GasMixture Air { get; set; } = new(6)
|
||||
{ Temperature = Atmospherics.NormalBodyTemperature };
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_internalSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner.Uid, DefaultSolutionName);
|
||||
if (_internalSolution != null)
|
||||
{
|
||||
_internalSolution.MaxVolume = _initialMaxVolume;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to transfer provided solution to internal solution.
|
||||
/// Only supports complete transfers
|
||||
/// </summary>
|
||||
/// <param name="solution">Solution to be transferred</param>
|
||||
/// <returns>Whether or not transfer was a success</returns>
|
||||
public override bool TryTransferSolution(Solution solution)
|
||||
{
|
||||
// For now doesn't support partial transfers
|
||||
var current = _internalSolution?.CurrentVolume ?? FixedPoint2.Zero;
|
||||
var max = _internalSolution?.MaxVolume ?? FixedPoint2.Zero;
|
||||
if (solution.TotalVolume + current > max)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(Owner.Uid, _internalSolution, solution);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void PumpToxins(GasMixture to)
|
||||
{
|
||||
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
|
||||
var respiratorSystem = EntitySystem.Get<RespiratorSystem>();
|
||||
|
||||
if (!Owner.TryGetComponent(out RespiratorComponent? metabolism))
|
||||
{
|
||||
atmosphereSystem.Merge(to, Air);
|
||||
Air.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
var toxins = respiratorSystem.Clean(OwnerUid, metabolism, this);
|
||||
var toOld = new float[to.Moles.Length];
|
||||
Array.Copy(to.Moles, toOld, toOld.Length);
|
||||
|
||||
atmosphereSystem.Merge(to, toxins);
|
||||
|
||||
for (var i = 0; i < toOld.Length; i++)
|
||||
{
|
||||
var newAmount = to.GetMoles(i);
|
||||
var oldAmount = toOld[i];
|
||||
var delta = newAmount - oldAmount;
|
||||
|
||||
toxins.AdjustMoles(i, -delta);
|
||||
}
|
||||
|
||||
atmosphereSystem.Merge(Air, toxins);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Content.Server.Body.Components
|
||||
/// From which solution will this metabolizer attempt to metabolize chemicals
|
||||
/// </summary>
|
||||
[DataField("solution")]
|
||||
public string SolutionName { get; set; } = SharedBloodstreamComponent.DefaultSolutionName;
|
||||
public string SolutionName { get; set; } = BloodstreamSystem.DefaultSolutionName;
|
||||
|
||||
/// <summary>
|
||||
/// Does this component use a solution on it's parent entity (the body) or itself
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Content.Server.Body.Components
|
||||
/// What solution should this stomach push reagents into, on the body?
|
||||
/// </summary>
|
||||
[DataField("bodySolutionName")]
|
||||
public string BodySolutionName = SharedBloodstreamComponent.DefaultSolutionName;
|
||||
public string BodySolutionName = BloodstreamSystem.DefaultSolutionName;
|
||||
|
||||
/// <summary>
|
||||
/// Initial internal solution storage volume
|
||||
@@ -36,7 +36,7 @@ namespace Content.Server.Body.Components
|
||||
|
||||
/// <summary>
|
||||
/// Time in seconds between reagents being ingested and them being
|
||||
/// transferred to <see cref="SharedBloodstreamComponent"/>
|
||||
/// transferred to <see cref="BloodstreamComponent"/>
|
||||
/// </summary>
|
||||
[DataField("digestionDelay")]
|
||||
public float DigestionDelay = 20;
|
||||
|
||||
Reference in New Issue
Block a user