Generalize ReagentUnit into FixedPoint2 and use it for damage calculations (#5151)

* Damage units

* sum ext method
This commit is contained in:
mirrorcult
2021-11-03 16:48:03 -07:00
committed by GitHub
parent 8165d8f38c
commit 3ab4a30a0f
100 changed files with 730 additions and 601 deletions

View File

@@ -5,6 +5,7 @@ using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Body.Networks;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -65,7 +66,7 @@ namespace Content.Server.Body.Behavior
// This reagent has been in the stomach long enough, TRY to transfer it.
// But first, check if the reagent still exists, and how much is left.
// Some poor spessman may have washed down a potassium snack with some water.
if (StomachSolution.ContainsReagent(delta.ReagentId, out ReagentUnit quantity))
if (StomachSolution.ContainsReagent(delta.ReagentId, out FixedPoint2 quantity))
{
if (quantity > delta.Quantity)
{
@@ -97,10 +98,10 @@ namespace Content.Server.Body.Behavior
/// <summary>
/// Max volume of internal solution storage
/// </summary>
public ReagentUnit MaxVolume
public FixedPoint2 MaxVolume
{
get =>
StomachSolution?.MaxVolume ?? ReagentUnit.Zero;
StomachSolution?.MaxVolume ?? FixedPoint2.Zero;
set
{
@@ -116,7 +117,7 @@ namespace Content.Server.Body.Behavior
/// </summary>
[DataField("maxVolume")]
[ViewVariables]
protected ReagentUnit InitialMaxVolume { get; private set; } = ReagentUnit.New(100);
protected FixedPoint2 InitialMaxVolume { get; private set; } = FixedPoint2.New(100);
/// <summary>
/// Time in seconds between reagents being ingested and them being
@@ -181,10 +182,10 @@ namespace Content.Server.Body.Behavior
protected class ReagentDelta
{
public readonly string ReagentId;
public readonly ReagentUnit Quantity;
public readonly FixedPoint2 Quantity;
public float Lifetime { get; private set; }
public ReagentDelta(string reagentId, ReagentUnit quantity)
public ReagentDelta(string reagentId, FixedPoint2 quantity)
{
ReagentId = reagentId;
Quantity = quantity;

View File

@@ -7,6 +7,7 @@ using Content.Shared.Atmos;
using Content.Shared.Body.Networks;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -23,7 +24,7 @@ namespace Content.Server.Body.Circulatory
/// Max volume of internal solution storage
/// </summary>
[DataField("maxVolume")] [ViewVariables]
private ReagentUnit _initialMaxVolume = ReagentUnit.New(250);
private FixedPoint2 _initialMaxVolume = FixedPoint2.New(250);
/// <summary>
/// Internal solution for reagent storage
@@ -34,7 +35,7 @@ namespace Content.Server.Body.Circulatory
/// Empty volume of internal solution
/// </summary>
[ViewVariables]
public ReagentUnit EmptyVolume => _internalSolution?.AvailableVolume ?? ReagentUnit.Zero;
public FixedPoint2 EmptyVolume => _internalSolution?.AvailableVolume ?? FixedPoint2.Zero;
[ViewVariables]
public GasMixture Air { get; set; } = new(6)
@@ -60,8 +61,8 @@ namespace Content.Server.Body.Circulatory
public override bool TryTransferSolution(Solution solution)
{
// For now doesn't support partial transfers
var current = _internalSolution?.CurrentVolume ?? ReagentUnit.Zero;
var max = _internalSolution?.MaxVolume ?? ReagentUnit.Zero;
var current = _internalSolution?.CurrentVolume ?? FixedPoint2.Zero;
var max = _internalSolution?.MaxVolume ?? FixedPoint2.Zero;
if (solution.TotalVolume + current > max)
{
return false;

View File

@@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations;
using Content.Shared.Body.Networks;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
@@ -47,7 +48,7 @@ namespace Content.Server.Body.Metabolism
/// Amount of reagent to metabolize, per metabolism cycle.
/// </summary>
[DataField("metabolismRate")]
public ReagentUnit MetabolismRate = ReagentUnit.New(1.0f);
public FixedPoint2 MetabolismRate = FixedPoint2.New(1.0f);
/// <summary>
/// A list of effects to apply when these reagents are metabolized.

View File

@@ -5,6 +5,7 @@ using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -64,7 +65,7 @@ namespace Content.Server.Body.Metabolism
{
if (body.Owner.HasComponent<BloodstreamComponent>()
&& solutionsSys.TryGetSolution(body.Owner.Uid, comp.SolutionName, out solution)
&& solution.CurrentVolume >= ReagentUnit.Zero)
&& solution.CurrentVolume >= FixedPoint2.Zero)
{
reagentList = solution.Contents;
}