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 Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
using Content.Server.Nutrition.EntitySystems;
using Content.Shared.FixedPoint;
using Robust.Shared.Analyzers;
namespace Content.Server.Nutrition.Components
@@ -28,7 +29,7 @@ namespace Content.Server.Nutrition.Components
internal bool DefaultToOpened;
[ViewVariables(VVAccess.ReadWrite)]
public ReagentUnit TransferAmount { get; [UsedImplicitly] private set; } = ReagentUnit.New(5);
public FixedPoint2 TransferAmount { get; [UsedImplicitly] private set; } = FixedPoint2.New(5);
[ViewVariables(VVAccess.ReadWrite)]
public bool Opened;

View File

@@ -8,6 +8,7 @@ using Content.Server.Hands.Components;
using Content.Server.Items;
using Content.Shared.Body.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Popups;
@@ -42,7 +43,7 @@ namespace Content.Server.Nutrition.Components
[ViewVariables]
[DataField("transferAmount")]
private ReagentUnit? TransferAmount { get; set; } = ReagentUnit.New(5);
private FixedPoint2? TransferAmount { get; set; } = FixedPoint2.New(5);
[DataField("utensilsNeeded")]
private UtensilType _utensilsNeeded = UtensilType.None;
@@ -65,7 +66,7 @@ namespace Content.Server.Nutrition.Components
return solution.CurrentVolume == 0
? 0
: Math.Max(1, (int) Math.Ceiling((solution.CurrentVolume / (ReagentUnit)TransferAmount).Float()));
: Math.Max(1, (int) Math.Ceiling((solution.CurrentVolume / (FixedPoint2)TransferAmount).Float()));
}
}
@@ -162,7 +163,7 @@ namespace Content.Server.Nutrition.Components
return false;
}
var transferAmount = TransferAmount != null ? ReagentUnit.Min((ReagentUnit)TransferAmount, solution.CurrentVolume) : solution.CurrentVolume;
var transferAmount = TransferAmount != null ? FixedPoint2.Min((FixedPoint2)TransferAmount, solution.CurrentVolume) : solution.CurrentVolume;
var split = solutionContainerSys.SplitSolution(Owner.Uid, solution, transferAmount);
var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split));

View File

@@ -5,6 +5,7 @@ using Content.Server.Hands.Components;
using Content.Server.Items;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Sound;
using Robust.Shared.Audio;
@@ -75,7 +76,7 @@ namespace Content.Server.Nutrition.Components
// Basically, we want to:
// 1. Split off a representative chunk
var lostSolution = scs.SplitSolution(Owner.Uid, solution,
solution.CurrentVolume / ReagentUnit.New(Count));
solution.CurrentVolume / FixedPoint2.New(Count));
// 2. Delete the Nutriment (it's already in the target) so we just have additives
// It might be an idea to remove the removal of Nutriment & clear the food
lostSolution.RemoveReagent("Nutriment", lostSolution.GetReagentQuantity("Nutriment"));

View File

@@ -1,5 +1,6 @@
using Content.Server.Nutrition.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Smoking;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
@@ -19,7 +20,7 @@ namespace Content.Server.Nutrition.Components
/// Solution inhale amount per second.
/// </summary>
[DataField("inhaleAmount")]
public ReagentUnit InhaleAmount { get; } = ReagentUnit.New(0.05f);
public FixedPoint2 InhaleAmount { get; } = FixedPoint2.New(0.05f);
[DataField("state")]
public SmokableState State { get; set; } = SmokableState.Unlit;