Generalize ReagentUnit into FixedPoint2 and use it for damage calculations (#5151)
* Damage units * sum ext method
This commit is contained in:
@@ -2,6 +2,7 @@ using Content.Client.Eui;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
@@ -40,7 +41,7 @@ namespace Content.Client.Administration.UI
|
||||
_window.HandleState((AdminAddReagentEuiState) state);
|
||||
}
|
||||
|
||||
private void DoAdd(bool close, string reagentId, ReagentUnit amount)
|
||||
private void DoAdd(bool close, string reagentId, FixedPoint2 amount)
|
||||
{
|
||||
SendMessage(new AdminAddReagentEuiMsg.DoAdd
|
||||
{
|
||||
@@ -121,7 +122,7 @@ namespace Content.Client.Administration.UI
|
||||
_eui.DoAdd(
|
||||
close,
|
||||
_reagentIdEdit.Text,
|
||||
ReagentUnit.New(float.Parse(_amountEdit.Text)));
|
||||
FixedPoint2.New(float.Parse(_amountEdit.Text)));
|
||||
}
|
||||
|
||||
private void CheckErrors()
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Client.Message;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -15,8 +16,8 @@ namespace Content.Client.Chemistry.Components
|
||||
[RegisterComponent]
|
||||
public sealed class HyposprayComponent : SharedHyposprayComponent, IItemStatus
|
||||
{
|
||||
[ViewVariables] private ReagentUnit CurrentVolume { get; set; }
|
||||
[ViewVariables] private ReagentUnit TotalVolume { get; set; }
|
||||
[ViewVariables] private FixedPoint2 CurrentVolume { get; set; }
|
||||
[ViewVariables] private FixedPoint2 TotalVolume { get; set; }
|
||||
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Client.Message;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -18,8 +19,8 @@ namespace Content.Client.Chemistry.Components
|
||||
[RegisterComponent]
|
||||
public class InjectorComponent : SharedInjectorComponent, IItemStatus
|
||||
{
|
||||
[ViewVariables] private ReagentUnit CurrentVolume { get; set; }
|
||||
[ViewVariables] private ReagentUnit TotalVolume { get; set; }
|
||||
[ViewVariables] private FixedPoint2 CurrentVolume { get; set; }
|
||||
[ViewVariables] private FixedPoint2 TotalVolume { get; set; }
|
||||
[ViewVariables] private InjectorToggleMode CurrentMode { get; set; }
|
||||
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Client.Stylesheets;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
@@ -47,7 +48,7 @@ namespace Content.Client.Chemistry.UI
|
||||
BottleAmount.InitDefaultButtons();
|
||||
}
|
||||
|
||||
private ChemButton MakeChemButton(string text, ReagentUnit amount, string id, bool isBuffer, string styleClass)
|
||||
private ChemButton MakeChemButton(string text, FixedPoint2 amount, string id, bool isBuffer, string styleClass)
|
||||
{
|
||||
var button = new ChemButton(text, amount, id, isBuffer, styleClass);
|
||||
button.OnPressed += args
|
||||
@@ -129,11 +130,11 @@ namespace Content.Client.Chemistry.UI
|
||||
//Padding
|
||||
new Control {HorizontalExpand = true},
|
||||
|
||||
MakeChemButton("1", ReagentUnit.New(1), reagent.ReagentId, false, StyleBase.ButtonOpenRight),
|
||||
MakeChemButton("5", ReagentUnit.New(5), reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("10", ReagentUnit.New(10), reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("25", ReagentUnit.New(25), reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton(Loc.GetString("chem-master-window-buffer-all-amount"), ReagentUnit.New(-1), reagent.ReagentId, false, StyleBase.ButtonOpenLeft),
|
||||
MakeChemButton("1", FixedPoint2.New(1), reagent.ReagentId, false, StyleBase.ButtonOpenRight),
|
||||
MakeChemButton("5", FixedPoint2.New(5), reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("10", FixedPoint2.New(10), reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("25", FixedPoint2.New(25), reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton(Loc.GetString("chem-master-window-buffer-all-amount"), FixedPoint2.New(-1), reagent.ReagentId, false, StyleBase.ButtonOpenLeft),
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -189,11 +190,11 @@ namespace Content.Client.Chemistry.UI
|
||||
//Padding
|
||||
new Control {HorizontalExpand = true},
|
||||
|
||||
MakeChemButton("1", ReagentUnit.New(1), reagent.ReagentId, true, StyleBase.ButtonOpenRight),
|
||||
MakeChemButton("5", ReagentUnit.New(5), reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("10", ReagentUnit.New(10), reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("25", ReagentUnit.New(25), reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton(Loc.GetString("chem-master-window-buffer-all-amount"), ReagentUnit.New(-1), reagent.ReagentId, true, StyleBase.ButtonOpenLeft),
|
||||
MakeChemButton("1", FixedPoint2.New(1), reagent.ReagentId, true, StyleBase.ButtonOpenRight),
|
||||
MakeChemButton("5", FixedPoint2.New(5), reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("10", FixedPoint2.New(10), reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("25", FixedPoint2.New(25), reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton(Loc.GetString("chem-master-window-buffer-all-amount"), FixedPoint2.New(-1), reagent.ReagentId, true, StyleBase.ButtonOpenLeft),
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -203,10 +204,10 @@ namespace Content.Client.Chemistry.UI
|
||||
|
||||
public class ChemButton : Button
|
||||
{
|
||||
public ReagentUnit Amount { get; set; }
|
||||
public FixedPoint2 Amount { get; set; }
|
||||
public bool isBuffer = true;
|
||||
public string Id { get; set; }
|
||||
public ChemButton(string _text, ReagentUnit _amount, string _id, bool _isBuffer, string _styleClass)
|
||||
public ChemButton(string _text, FixedPoint2 _amount, string _id, bool _isBuffer, string _styleClass)
|
||||
{
|
||||
AddStyleClass(_styleClass);
|
||||
Text = _text;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -20,7 +21,7 @@ namespace Content.Client.Chemistry.UI
|
||||
{
|
||||
if (int.TryParse(_window.AmountLineEdit.Text, out var i))
|
||||
{
|
||||
SendMessage(new TransferAmountSetValueMessage(ReagentUnit.New(i)));
|
||||
SendMessage(new TransferAmountSetValueMessage(FixedPoint2.New(i)));
|
||||
_window.Close();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -58,7 +59,7 @@ namespace Content.Client.Damage
|
||||
/// isn't required for it.
|
||||
/// </remarks>
|
||||
[DataField("thresholds", required: true)]
|
||||
private List<int> _thresholds = new();
|
||||
private List<FixedPoint2> _thresholds = new();
|
||||
|
||||
/// <summary>
|
||||
/// Layers to target, by layerMapKey.
|
||||
@@ -295,7 +296,7 @@ namespace Content.Client.Damage
|
||||
|| !entity.TryGetComponent<AppearanceComponent>(out var appearanceComponent))
|
||||
return;
|
||||
|
||||
_thresholds.Add(0);
|
||||
_thresholds.Add(FixedPoint2.Zero);
|
||||
_thresholds.Sort();
|
||||
|
||||
if (_thresholds[0] != 0)
|
||||
@@ -324,7 +325,7 @@ namespace Content.Client.Damage
|
||||
return;
|
||||
}
|
||||
|
||||
damageData.LastThresholdPerGroup.Add(damageType, 0);
|
||||
damageData.LastThresholdPerGroup.Add(damageType, FixedPoint2.Zero);
|
||||
}
|
||||
}
|
||||
// Are we tracking a single damage group without overlay instead?
|
||||
@@ -338,7 +339,7 @@ namespace Content.Client.Damage
|
||||
return;
|
||||
}
|
||||
|
||||
damageData.LastThresholdPerGroup.Add(_damageGroup, 0);
|
||||
damageData.LastThresholdPerGroup.Add(_damageGroup, FixedPoint2.Zero);
|
||||
}
|
||||
}
|
||||
// Ditto above, but instead we go through every group.
|
||||
@@ -356,7 +357,7 @@ namespace Content.Client.Damage
|
||||
damageData.Valid = false;
|
||||
return;
|
||||
}
|
||||
damageData.LastThresholdPerGroup.Add(damageType, 0);
|
||||
damageData.LastThresholdPerGroup.Add(damageType, FixedPoint2.Zero);
|
||||
}
|
||||
else if (_damageGroup != null)
|
||||
{
|
||||
@@ -367,7 +368,7 @@ namespace Content.Client.Damage
|
||||
return;
|
||||
}
|
||||
|
||||
damageData.LastThresholdPerGroup.Add(_damageGroup, 0);
|
||||
damageData.LastThresholdPerGroup.Add(_damageGroup, FixedPoint2.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,7 +605,7 @@ namespace Content.Client.Damage
|
||||
{
|
||||
foreach (var (damageGroup, sprite) in _damageOverlayGroups)
|
||||
{
|
||||
int threshold = damageData.LastThresholdPerGroup[damageGroup];
|
||||
FixedPoint2 threshold = damageData.LastThresholdPerGroup[damageGroup];
|
||||
ReorderOverlaySprite(spriteComponent,
|
||||
damageData,
|
||||
sprite,
|
||||
@@ -625,12 +626,12 @@ namespace Content.Client.Damage
|
||||
}
|
||||
}
|
||||
|
||||
private void ReorderOverlaySprite(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, DamageVisualizerSprite sprite, string key, string statePrefix, int threshold)
|
||||
private void ReorderOverlaySprite(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, DamageVisualizerSprite sprite, string key, string statePrefix, FixedPoint2 threshold)
|
||||
{
|
||||
spriteComponent.LayerMapTryGet(key, out int spriteLayer);
|
||||
bool visibility = spriteComponent[spriteLayer].Visible;
|
||||
spriteComponent.RemoveLayer(spriteLayer);
|
||||
if (threshold == 0) // these should automatically be invisible
|
||||
if (threshold == FixedPoint2.Zero) // these should automatically be invisible
|
||||
threshold = _thresholds[1];
|
||||
spriteLayer = spriteComponent.AddLayer(
|
||||
new SpriteSpecifier.Rsi(
|
||||
@@ -650,7 +651,7 @@ namespace Content.Client.Damage
|
||||
/// </summary>
|
||||
private void UpdateDamageVisuals(DamageableComponent damageComponent, SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData)
|
||||
{
|
||||
if (!CheckThresholdBoundary(damageComponent.TotalDamage, damageData.LastDamageThreshold, out int threshold))
|
||||
if (!CheckThresholdBoundary(damageComponent.TotalDamage, damageData.LastDamageThreshold, out FixedPoint2 threshold))
|
||||
return;
|
||||
|
||||
damageData.LastDamageThreshold = threshold;
|
||||
@@ -679,11 +680,11 @@ namespace Content.Client.Damage
|
||||
continue;
|
||||
|
||||
if (!_prototypeManager.TryIndex<DamageGroupPrototype>(damageGroup, out var damageGroupPrototype)
|
||||
|| !damageComponent.Damage.TryGetDamageInGroup(damageGroupPrototype, out int damageTotal))
|
||||
|| !damageComponent.Damage.TryGetDamageInGroup(damageGroupPrototype, out FixedPoint2 damageTotal))
|
||||
continue;
|
||||
|
||||
if (!damageData.LastThresholdPerGroup.TryGetValue(damageGroup, out int lastThreshold)
|
||||
|| !CheckThresholdBoundary(damageTotal, lastThreshold, out int threshold))
|
||||
if (!damageData.LastThresholdPerGroup.TryGetValue(damageGroup, out FixedPoint2 lastThreshold)
|
||||
|| !CheckThresholdBoundary(damageTotal, lastThreshold, out FixedPoint2 threshold))
|
||||
continue;
|
||||
|
||||
damageData.LastThresholdPerGroup[damageGroup] = threshold;
|
||||
@@ -704,10 +705,10 @@ namespace Content.Client.Damage
|
||||
/// <summary>
|
||||
/// Checks if a threshold boundary was passed.
|
||||
/// </summary>
|
||||
private bool CheckThresholdBoundary(int damageTotal, int lastThreshold, out int threshold)
|
||||
private bool CheckThresholdBoundary(FixedPoint2 damageTotal, FixedPoint2 lastThreshold, out FixedPoint2 threshold)
|
||||
{
|
||||
threshold = 0;
|
||||
damageTotal = (int) Math.Floor(damageTotal / _divisor);
|
||||
threshold = FixedPoint2.Zero;
|
||||
damageTotal = damageTotal / _divisor;
|
||||
int thresholdIndex = _thresholds.BinarySearch(damageTotal);
|
||||
|
||||
if (thresholdIndex < 0)
|
||||
@@ -753,7 +754,7 @@ namespace Content.Client.Damage
|
||||
/// it assumes you're updating a layer that is tracking all
|
||||
/// damage.
|
||||
/// </summary>
|
||||
private void UpdateTargetLayer(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, object layerMapKey, int threshold)
|
||||
private void UpdateTargetLayer(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, object layerMapKey, FixedPoint2 threshold)
|
||||
{
|
||||
if (_overlay && _damageOverlayGroups != null)
|
||||
{
|
||||
@@ -783,7 +784,7 @@ namespace Content.Client.Damage
|
||||
/// <summary>
|
||||
/// Updates a target layer by damage group.
|
||||
/// </summary>
|
||||
private void UpdateTargetLayer(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, object layerMapKey, string damageGroup, int threshold)
|
||||
private void UpdateTargetLayer(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, object layerMapKey, string damageGroup, FixedPoint2 threshold)
|
||||
{
|
||||
if (_overlay && _damageOverlayGroups != null)
|
||||
{
|
||||
@@ -813,7 +814,7 @@ namespace Content.Client.Damage
|
||||
/// <summary>
|
||||
/// Updates an overlay that is tracking all damage.
|
||||
/// </summary>
|
||||
private void UpdateOverlay(SpriteComponent spriteComponent, int threshold)
|
||||
private void UpdateOverlay(SpriteComponent spriteComponent, FixedPoint2 threshold)
|
||||
{
|
||||
spriteComponent.LayerMapTryGet($"DamageOverlay", out int spriteLayer);
|
||||
|
||||
@@ -826,7 +827,7 @@ namespace Content.Client.Damage
|
||||
/// <summary>
|
||||
/// Updates an overlay based on damage group.
|
||||
/// </summary>
|
||||
private void UpdateOverlay(SpriteComponent spriteComponent, string damageGroup, int threshold)
|
||||
private void UpdateOverlay(SpriteComponent spriteComponent, string damageGroup, FixedPoint2 threshold)
|
||||
{
|
||||
if (_damageOverlayGroups != null)
|
||||
{
|
||||
@@ -848,7 +849,7 @@ namespace Content.Client.Damage
|
||||
/// function calls it), and what threshold
|
||||
/// was passed into it.
|
||||
/// </summary>
|
||||
private void UpdateDamageLayerState(SpriteComponent spriteComponent, int spriteLayer, string statePrefix, int threshold)
|
||||
private void UpdateDamageLayerState(SpriteComponent spriteComponent, int spriteLayer, string statePrefix, FixedPoint2 threshold)
|
||||
{
|
||||
if (threshold == 0)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Damage
|
||||
@@ -17,10 +18,10 @@ namespace Content.Client.Damage
|
||||
public List<object> TargetLayerMapKeys = new();
|
||||
public bool Disabled = false;
|
||||
public bool Valid = true;
|
||||
public int LastDamageThreshold = 0;
|
||||
public FixedPoint2 LastDamageThreshold = FixedPoint2.Zero;
|
||||
public Dictionary<object, bool> DisabledLayers = new();
|
||||
public Dictionary<object, string> LayerMapKeyStates = new();
|
||||
public Dictionary<string, int> LastThresholdPerGroup = new();
|
||||
public Dictionary<string, FixedPoint2> LastThresholdPerGroup = new();
|
||||
public string TopMostLayerKey = default!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Client.IoC;
|
||||
using Content.Client.Resources;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.MobState;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
@@ -84,7 +85,7 @@ namespace Content.Client.HealthOverlay.UI
|
||||
return;
|
||||
}
|
||||
|
||||
int threshold;
|
||||
FixedPoint2 threshold;
|
||||
|
||||
if (mobState.IsAlive())
|
||||
{
|
||||
@@ -97,7 +98,7 @@ namespace Content.Client.HealthOverlay.UI
|
||||
|
||||
CritBar.Ratio = 1;
|
||||
CritBar.Visible = true;
|
||||
HealthBar.Ratio = 1 - (float) damageable.TotalDamage / threshold;
|
||||
HealthBar.Ratio = 1 - (damageable.TotalDamage / threshold).Float();
|
||||
HealthBar.Visible = true;
|
||||
}
|
||||
else if (mobState.IsCritical())
|
||||
@@ -113,9 +114,9 @@ namespace Content.Client.HealthOverlay.UI
|
||||
}
|
||||
|
||||
CritBar.Visible = true;
|
||||
CritBar.Ratio = 1 - (float)
|
||||
(damageable.TotalDamage - critThreshold) /
|
||||
(deadThreshold - critThreshold);
|
||||
CritBar.Ratio = 1 -
|
||||
((damageable.TotalDamage - critThreshold) /
|
||||
(deadThreshold - critThreshold)).Float();
|
||||
}
|
||||
else if (mobState.IsDead())
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using static Content.Shared.MedicalScanner.SharedMedicalScannerComponent;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
@@ -39,6 +40,7 @@ namespace Content.Client.MedicalScanner.UI
|
||||
text.Append($"{Loc.GetString("medical-scanner-window-entity-health-text", ("entityName", entity.Name))}\n");
|
||||
|
||||
var totalDamage = state.DamagePerType.Values.Sum();
|
||||
|
||||
text.Append($"{Loc.GetString("medical-scanner-window-entity-damage-total-text", ("amount", totalDamage))}\n");
|
||||
|
||||
HashSet<string> shownTypes = new();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Reflection;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -9,18 +10,18 @@ using Robust.UnitTesting.Shared.Serialization;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Chemistry
|
||||
{
|
||||
public class ReagentUnitSerializationTest : SerializationTest
|
||||
public class FixedPoint2SerializationTest : SerializationTest
|
||||
{
|
||||
protected override Assembly[] Assemblies => new[]
|
||||
{
|
||||
typeof(ReagentUnitSerializationTest).Assembly
|
||||
typeof(FixedPoint2SerializationTest).Assembly
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void DeserializeNullTest()
|
||||
{
|
||||
var node = new ValueDataNode("null");
|
||||
var unit = Serialization.ReadValue<ReagentUnit?>(node);
|
||||
var unit = Serialization.ReadValue<FixedPoint2?>(node);
|
||||
|
||||
Assert.That(unit, Is.Null);
|
||||
}
|
||||
@@ -29,15 +30,15 @@ namespace Content.IntegrationTests.Tests.Chemistry
|
||||
public void DeserializeNullDefinitionTest()
|
||||
{
|
||||
var node = new MappingDataNode().Add("unit", "null");
|
||||
var definition = Serialization.ReadValueOrThrow<ReagentUnitTestDefinition>(node);
|
||||
var definition = Serialization.ReadValueOrThrow<FixedPoint2TestDefinition>(node);
|
||||
|
||||
Assert.That(definition.Unit, Is.Null);
|
||||
}
|
||||
}
|
||||
|
||||
[DataDefinition]
|
||||
public class ReagentUnitTestDefinition
|
||||
public class FixedPoint2TestDefinition
|
||||
{
|
||||
[DataField("unit")] public ReagentUnit? Unit { get; set; } = ReagentUnit.New(5);
|
||||
[DataField("unit")] public FixedPoint2? Unit { get; set; } = FixedPoint2.New(5);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Threading.Tasks;
|
||||
using Content.Server.Administration.Commands;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.MobState;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -56,7 +57,8 @@ namespace Content.IntegrationTests.Tests.Commands
|
||||
Assert.That(mobState.IsIncapacitated, Is.False);
|
||||
|
||||
// Kill the entity
|
||||
DamageSpecifier damage = new(prototypeManager.Index<DamageGroupPrototype>("Toxin"), 10000000);
|
||||
DamageSpecifier damage = new(prototypeManager.Index<DamageGroupPrototype>("Toxin"),
|
||||
FixedPoint2.New(10000000));
|
||||
EntitySystem.Get<DamageableSystem>().TryChangeDamage(human.Uid, damage, true);
|
||||
|
||||
// Check that it is dead
|
||||
@@ -74,7 +76,7 @@ namespace Content.IntegrationTests.Tests.Commands
|
||||
Assert.That(mobState.IsDead, Is.False);
|
||||
Assert.That(mobState.IsIncapacitated, Is.False);
|
||||
|
||||
Assert.That(damageable.TotalDamage, Is.Zero);
|
||||
Assert.That(damageable.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
@@ -108,7 +109,7 @@ namespace Content.IntegrationTests.Tests.Damageable
|
||||
DamageTypePrototype type3b = default!;
|
||||
DamageTypePrototype type3c = default!;
|
||||
|
||||
int typeDamage, groupDamage;
|
||||
FixedPoint2 typeDamage, groupDamage;
|
||||
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
@@ -148,7 +149,7 @@ namespace Content.IntegrationTests.Tests.Damageable
|
||||
|
||||
// Check that damage is evenly distributed over a group if its a nice multiple
|
||||
var types = group3.DamageTypes;
|
||||
var damageToDeal = types.Count() * 5;
|
||||
var damageToDeal = FixedPoint2.New(types.Count() * 5);
|
||||
DamageSpecifier damage = new(group3, damageToDeal);
|
||||
|
||||
sDamageableSystem.TryChangeDamage(uid, damage, true);
|
||||
@@ -166,73 +167,74 @@ namespace Content.IntegrationTests.Tests.Damageable
|
||||
sDamageableSystem.TryChangeDamage(uid, -damage);
|
||||
Assert.That(DamageChanged);
|
||||
DamageChanged = false;
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.Zero);
|
||||
Assert.That(sDamageableComponent.DamagePerGroup[group3.ID], Is.EqualTo(0));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
Assert.That(sDamageableComponent.DamagePerGroup[group3.ID], Is.EqualTo(FixedPoint2.Zero));
|
||||
foreach (var type in types)
|
||||
{
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict.TryGetValue(type, out typeDamage));
|
||||
Assert.That(typeDamage, Is.Zero);
|
||||
Assert.That(typeDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
}
|
||||
|
||||
// Check that damage works properly if it is NOT perfectly divisible among group members
|
||||
types = group3.DamageTypes;
|
||||
damageToDeal = types.Count() * 5 - 1;
|
||||
damageToDeal = FixedPoint2.New(types.Count() * 5 - 1);
|
||||
damage = new DamageSpecifier(group3, damageToDeal);
|
||||
sDamageableSystem.TryChangeDamage(uid, damage, true);
|
||||
Assert.That(DamageChanged);
|
||||
DamageChanged = false;
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(damageToDeal));
|
||||
Assert.That(sDamageableComponent.DamagePerGroup[group3.ID], Is.EqualTo(damageToDeal));
|
||||
// integer rounding. In this case, first member gets 1 less than others.
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3a.ID], Is.EqualTo(damageToDeal / types.Count()));
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3b.ID], Is.EqualTo(1 + damageToDeal / types.Count()));
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3c.ID], Is.EqualTo(1 + damageToDeal / types.Count()));
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3b.ID], Is.EqualTo(damageToDeal / types.Count()));
|
||||
|
||||
// last one will get 0.01 less, since its not perfectly divisble by 3
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3c.ID], Is.EqualTo(damageToDeal / types.Count() - 0.01));
|
||||
|
||||
// Heal
|
||||
sDamageableSystem.TryChangeDamage(uid, -damage);
|
||||
Assert.That(DamageChanged);
|
||||
DamageChanged = false;
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.Zero);
|
||||
Assert.That(sDamageableComponent.DamagePerGroup[group3.ID], Is.EqualTo(0));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
Assert.That(sDamageableComponent.DamagePerGroup[group3.ID], Is.EqualTo(FixedPoint2.Zero));
|
||||
foreach (var type in types)
|
||||
{
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict.TryGetValue(type, out typeDamage));
|
||||
Assert.That(typeDamage, Is.Zero);
|
||||
Assert.That(typeDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
}
|
||||
|
||||
// Test that unsupported groups return false when setting/getting damage (and don't change damage)
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
|
||||
damage = new DamageSpecifier(group1, 10) + new DamageSpecifier(type2b, 10);
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
damage = new DamageSpecifier(group1, FixedPoint2.New(10)) + new DamageSpecifier(type2b, FixedPoint2.New(10));
|
||||
sDamageableSystem.TryChangeDamage(uid, damage, true);
|
||||
Assert.That(DamageChanged, Is.False);
|
||||
Assert.That(sDamageableComponent.DamagePerGroup.TryGetValue(group1.ID, out groupDamage), Is.False);
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict.TryGetValue(type1.ID, out typeDamage), Is.False);
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
|
||||
// Test SetAll function
|
||||
sDamageableSystem.SetAllDamage(sDamageableComponent, 10);
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(10 * sDamageableComponent.Damage.DamageDict.Count()));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(10 * sDamageableComponent.Damage.DamageDict.Count())));
|
||||
sDamageableSystem.SetAllDamage(sDamageableComponent, 0);
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
|
||||
// Test 'wasted' healing
|
||||
sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(type3a, 5));
|
||||
sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(type3b, 7));
|
||||
sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(group3, -11));
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3a.ID], Is.EqualTo(2));
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3b.ID], Is.EqualTo(3));
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3c.ID], Is.EqualTo(0));
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3a.ID], Is.EqualTo(FixedPoint2.New(1.33)));
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3b.ID], Is.EqualTo(FixedPoint2.New(3.33)));
|
||||
Assert.That(sDamageableComponent.Damage.DamageDict[type3c.ID], Is.EqualTo(FixedPoint2.New(0)));
|
||||
|
||||
// Test Over-Healing
|
||||
sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(group3, -100));
|
||||
sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(group3, FixedPoint2.New(-100)));
|
||||
Assert.That(DamageChanged);
|
||||
DamageChanged = false;
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
|
||||
// Test that if no health change occurred, returns false
|
||||
sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(group3, -100));
|
||||
Assert.That(DamageChanged, Is.False);
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Threading.Tasks;
|
||||
using Content.Server.Destructible.Thresholds.Triggers;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -60,8 +61,8 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBrute");
|
||||
var burnDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBurn");
|
||||
|
||||
DamageSpecifier bruteDamage = new(bruteDamageGroup,5);
|
||||
DamageSpecifier burnDamage = new(burnDamageGroup,5);
|
||||
DamageSpecifier bruteDamage = new(bruteDamageGroup, FixedPoint2.New(5));
|
||||
DamageSpecifier burnDamage = new(burnDamageGroup, FixedPoint2.New(5));
|
||||
|
||||
// Raise brute damage to 5
|
||||
sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bruteDamage, true);
|
||||
@@ -112,7 +113,7 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
|
||||
// Lower brute damage to 0
|
||||
sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bruteDamage * -10);
|
||||
Assert.That(sDamageableComponent.TotalDamage,Is.EqualTo(20));
|
||||
Assert.That(sDamageableComponent.TotalDamage,Is.EqualTo(FixedPoint2.New(20)));
|
||||
|
||||
// No new thresholds reached, healing should not trigger it
|
||||
Assert.IsEmpty(sTestThresholdListenerSystem.ThresholdsReached);
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Server.Destructible.Thresholds.Behaviors;
|
||||
using Content.Server.Destructible.Thresholds.Triggers;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -186,7 +187,7 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bluntDamage*5, true);
|
||||
|
||||
// Check that the total damage matches
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50)));
|
||||
|
||||
// Both thresholds should have triggered
|
||||
Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Has.Exactly(2).Items);
|
||||
@@ -234,7 +235,7 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
sDamageableSystem.SetAllDamage(sDamageableComponent, 0);
|
||||
|
||||
// Check that the entity has 0 damage
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
|
||||
|
||||
// Set both thresholds to only trigger once
|
||||
foreach (var destructibleThreshold in sDestructibleComponent.Thresholds)
|
||||
@@ -247,7 +248,7 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bluntDamage*5, true);
|
||||
|
||||
// Check that the total damage matches
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50)));
|
||||
|
||||
// No thresholds should have triggered as they were already triggered before, and they are set to only trigger once
|
||||
Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty);
|
||||
@@ -260,7 +261,7 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
}
|
||||
|
||||
// Check that the total damage matches
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));
|
||||
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50)));
|
||||
|
||||
// They shouldn't have been triggered by changing TriggersOnce
|
||||
Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty);
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.Fluids.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Coordinates;
|
||||
using Content.Shared.FixedPoint;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
@@ -56,7 +57,7 @@ namespace Content.IntegrationTests.Tests.Fluids
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(20));
|
||||
var solution = new Solution("water", FixedPoint2.New(20));
|
||||
var puddle = solution.SpillAt(coordinates, "PuddleSmear");
|
||||
Assert.NotNull(puddle);
|
||||
});
|
||||
@@ -94,7 +95,7 @@ namespace Content.IntegrationTests.Tests.Fluids
|
||||
server.Assert(() =>
|
||||
{
|
||||
var coordinates = grid.ToCoordinates();
|
||||
var solution = new Solution("water", ReagentUnit.New(20));
|
||||
var solution = new Solution("water", FixedPoint2.New(20));
|
||||
var puddle = solution.SpillAt(coordinates, "PuddleSmear");
|
||||
Assert.Null(puddle);
|
||||
});
|
||||
@@ -154,7 +155,7 @@ namespace Content.IntegrationTests.Tests.Fluids
|
||||
// Spawn a puddle
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(amount));
|
||||
var solution = new Solution("water", FixedPoint2.New(amount));
|
||||
puddle = solution.SpillAt(sCoordinates, "PuddleSmear");
|
||||
|
||||
// Check that the puddle was created
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee
|
||||
}
|
||||
|
||||
// Just went with max health
|
||||
return meleeWeaponComponent.Damage.Total / 300.0f;
|
||||
return (meleeWeaponComponent.Damage.Total / 300.0f).Float();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
return damageableComponent.TotalDamage / 300.0f;
|
||||
return (float) damageableComponent.TotalDamage / 300.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Administration;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
@@ -42,8 +43,8 @@ namespace Content.Server.Administration.UI
|
||||
|
||||
return new AdminAddReagentEuiState
|
||||
{
|
||||
CurVolume = ReagentUnit.Zero,
|
||||
MaxVolume = ReagentUnit.Zero
|
||||
CurVolume = FixedPoint2.Zero,
|
||||
MaxVolume = FixedPoint2.Zero
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.Atmos.Components;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
@@ -71,7 +72,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
foreach (var (barotrauma, damageable, transform) in EntityManager.EntityQuery<BarotraumaComponent, DamageableComponent, ITransformComponent>())
|
||||
{
|
||||
var totalDamage = 0;
|
||||
var totalDamage = FixedPoint2.Zero;
|
||||
foreach (var (barotraumaDamageType, _) in barotrauma.Damage.DamageDict)
|
||||
{
|
||||
if (!damageable.Damage.DamageDict.TryGetValue(barotraumaDamageType, out var damage))
|
||||
|
||||
@@ -2,6 +2,7 @@ using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Maps;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -35,7 +36,7 @@ namespace Content.Server.Atmos.Reactions
|
||||
mixture.AdjustMoles(GasId, -MolesPerUnit);
|
||||
|
||||
var tileRef = tile.GridIndices.GetTileRef(tile.GridIndex);
|
||||
tileRef.SpillAt(new Solution(Reagent, ReagentUnit.New(MolesPerUnit)), PuddlePrototype, sound: false);
|
||||
tileRef.SpillAt(new Solution(Reagent, FixedPoint2.New(MolesPerUnit)), PuddlePrototype, sound: false);
|
||||
|
||||
return ReactionResult.Reacting;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using Content.Shared.Audio;
|
||||
using Content.Shared.Botany;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Random.Helpers;
|
||||
@@ -560,7 +561,7 @@ namespace Content.Server.Botany.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
var one = ReagentUnit.New(1);
|
||||
var one = FixedPoint2.New(1);
|
||||
foreach (var reagent in solutionSystem.RemoveEachReagent(solution, one))
|
||||
{
|
||||
var reagentProto = _prototypeManager.Index<ReagentPrototype>(reagent);
|
||||
@@ -727,7 +728,7 @@ namespace Content.Server.Botany.Components
|
||||
if (solutionSystem.TryGetDrainableSolution(usingItem.Uid, out var solution)
|
||||
&& solutionSystem.TryGetSolution(Owner.Uid, SoilSolutionName, out var targetSolution))
|
||||
{
|
||||
var amount = ReagentUnit.New(5);
|
||||
var amount = FixedPoint2.New(5);
|
||||
var sprayed = false;
|
||||
var targetEntity = Owner.Uid;
|
||||
var solutionEntity = usingItem.Uid;
|
||||
@@ -735,7 +736,7 @@ namespace Content.Server.Botany.Components
|
||||
if (usingItem.TryGetComponent(out SprayComponent? spray))
|
||||
{
|
||||
sprayed = true;
|
||||
amount = ReagentUnit.New(1);
|
||||
amount = FixedPoint2.New(1);
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(usingItem), spray.SpraySound.GetSound(), usingItem,
|
||||
AudioHelpers.WithVariation(0.125f));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -50,10 +51,10 @@ namespace Content.Server.Botany.Components
|
||||
solutionContainer.RemoveAllSolution();
|
||||
foreach (var (chem, quantity) in Seed.Chemicals)
|
||||
{
|
||||
var amount = ReagentUnit.New(quantity.Min);
|
||||
var amount = FixedPoint2.New(quantity.Min);
|
||||
if (quantity.PotencyDivisor > 0 && Potency > 0)
|
||||
amount += ReagentUnit.New(Potency / quantity.PotencyDivisor);
|
||||
amount = ReagentUnit.New((int) MathHelper.Clamp(amount.Float(), quantity.Min, quantity.Max));
|
||||
amount += FixedPoint2.New(Potency / quantity.PotencyDivisor);
|
||||
amount = FixedPoint2.New((int) MathHelper.Clamp(amount.Float(), quantity.Min, quantity.Max));
|
||||
solutionContainer.MaxVolume += amount;
|
||||
solutionContainer.AddReagent(chem, amount);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using Content.Server.UserInterface;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Random.Helpers;
|
||||
@@ -184,7 +185,7 @@ namespace Content.Server.Chemistry.Components
|
||||
if (beaker is null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var beakerSolution))
|
||||
{
|
||||
return new ChemMasterBoundUserInterfaceState(Powered, false, ReagentUnit.New(0), ReagentUnit.New(0),
|
||||
return new ChemMasterBoundUserInterfaceState(Powered, false, FixedPoint2.New(0), FixedPoint2.New(0),
|
||||
"", Owner.Name, new List<Solution.ReagentQuantity>(), BufferSolution.Contents, _bufferModeTransfer,
|
||||
BufferSolution.TotalVolume);
|
||||
}
|
||||
@@ -225,7 +226,7 @@ namespace Content.Server.Chemistry.Components
|
||||
hands.PutInHand(item);
|
||||
}
|
||||
|
||||
private void TransferReagent(string id, ReagentUnit amount, bool isBuffer)
|
||||
private void TransferReagent(string id, FixedPoint2 amount, bool isBuffer)
|
||||
{
|
||||
if (!HasBeaker && _bufferModeTransfer) return;
|
||||
var beaker = BeakerContainer.ContainedEntity;
|
||||
@@ -240,16 +241,16 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
if (reagent.ReagentId == id)
|
||||
{
|
||||
ReagentUnit actualAmount;
|
||||
FixedPoint2 actualAmount;
|
||||
if (
|
||||
amount == ReagentUnit
|
||||
.New(-1)) //amount is ReagentUnit.New(-1) when the client sends a message requesting to remove all solution from the container
|
||||
amount == FixedPoint2
|
||||
.New(-1)) //amount is FixedPoint2.New(-1) when the client sends a message requesting to remove all solution from the container
|
||||
{
|
||||
actualAmount = ReagentUnit.Min(reagent.Quantity, beakerSolution.AvailableVolume);
|
||||
actualAmount = FixedPoint2.Min(reagent.Quantity, beakerSolution.AvailableVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
actualAmount = ReagentUnit.Min(reagent.Quantity, amount, beakerSolution.AvailableVolume);
|
||||
actualAmount = FixedPoint2.Min(reagent.Quantity, amount, beakerSolution.AvailableVolume);
|
||||
}
|
||||
|
||||
|
||||
@@ -271,14 +272,14 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
if (reagent.ReagentId == id)
|
||||
{
|
||||
ReagentUnit actualAmount;
|
||||
if (amount == ReagentUnit.New(-1))
|
||||
FixedPoint2 actualAmount;
|
||||
if (amount == FixedPoint2.New(-1))
|
||||
{
|
||||
actualAmount = reagent.Quantity;
|
||||
}
|
||||
else
|
||||
{
|
||||
actualAmount = ReagentUnit.Min(reagent.Quantity, amount);
|
||||
actualAmount = FixedPoint2.Min(reagent.Quantity, amount);
|
||||
}
|
||||
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryRemoveReagent(beaker.Uid, beakerSolution, id, actualAmount);
|
||||
@@ -298,11 +299,11 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
if (action == UiAction.CreateBottles)
|
||||
{
|
||||
var individualVolume = BufferSolution.TotalVolume / ReagentUnit.New(bottleAmount);
|
||||
if (individualVolume < ReagentUnit.New(1))
|
||||
var individualVolume = BufferSolution.TotalVolume / FixedPoint2.New(bottleAmount);
|
||||
if (individualVolume < FixedPoint2.New(1))
|
||||
return;
|
||||
|
||||
var actualVolume = ReagentUnit.Min(individualVolume, ReagentUnit.New(30));
|
||||
var actualVolume = FixedPoint2.Min(individualVolume, FixedPoint2.New(30));
|
||||
for (int i = 0; i < bottleAmount; i++)
|
||||
{
|
||||
var bottle = Owner.EntityManager.SpawnEntity("ChemistryEmptyBottle01", Owner.Transform.Coordinates);
|
||||
@@ -331,11 +332,11 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
else //Pills
|
||||
{
|
||||
var individualVolume = BufferSolution.TotalVolume / ReagentUnit.New(pillAmount);
|
||||
if (individualVolume < ReagentUnit.New(1))
|
||||
var individualVolume = BufferSolution.TotalVolume / FixedPoint2.New(pillAmount);
|
||||
if (individualVolume < FixedPoint2.New(1))
|
||||
return;
|
||||
|
||||
var actualVolume = ReagentUnit.Min(individualVolume, ReagentUnit.New(50));
|
||||
var actualVolume = FixedPoint2.Min(individualVolume, FixedPoint2.New(50));
|
||||
for (int i = 0; i < pillAmount; i++)
|
||||
{
|
||||
var pill = Owner.EntityManager.SpawnEntity("pill", Owner.Transform.Coordinates);
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Inventory.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Foam;
|
||||
using Content.Shared.Inventory;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -56,7 +57,7 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
|
||||
var cloneSolution = solution.Clone();
|
||||
var transferAmount = ReagentUnit.Min(cloneSolution.TotalVolume * solutionFraction * (1 - protection),
|
||||
var transferAmount = FixedPoint2.Min(cloneSolution.TotalVolume * solutionFraction * (1 - protection),
|
||||
bloodstream.EmptyVolume);
|
||||
var transferSolution = cloneSolution.SplitSolution(transferAmount);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.Interaction.Components;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
@@ -27,7 +28,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
[DataField("TransferAmount")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(5);
|
||||
public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(5);
|
||||
|
||||
[DataField("InjectSound")]
|
||||
private SoundSpecifier _injectSound = new SoundPathSpecifier("/Audio/Items/hypospray.ogg");
|
||||
@@ -85,7 +86,7 @@ namespace Content.Server.Chemistry.Components
|
||||
SoundSystem.Play(Filter.Pvs(user), _injectSound.GetSound(), user);
|
||||
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(TransferAmount, targetSolution.AvailableVolume);
|
||||
var realTransferAmount = FixedPoint2.Min(TransferAmount, targetSolution.AvailableVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
@@ -126,7 +127,7 @@ namespace Content.Server.Chemistry.Components
|
||||
var solutionSys = Owner.EntityManager.EntitySysManager.GetEntitySystem<SolutionContainerSystem>();
|
||||
return solutionSys.TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
? new HyposprayComponentState(solution.CurrentVolume, solution.MaxVolume)
|
||||
: new HyposprayComponentState(ReagentUnit.Zero, ReagentUnit.Zero);
|
||||
: new HyposprayComponentState(FixedPoint2.Zero, FixedPoint2.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,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 Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Popups;
|
||||
@@ -41,14 +42,14 @@ namespace Content.Server.Chemistry.Components
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("transferAmount")]
|
||||
private ReagentUnit _transferAmount = ReagentUnit.New(5);
|
||||
private FixedPoint2 _transferAmount = FixedPoint2.New(5);
|
||||
|
||||
/// <summary>
|
||||
/// Initial storage volume of the injector
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("initialMaxVolume")]
|
||||
private ReagentUnit _initialMaxVolume = ReagentUnit.New(15);
|
||||
private FixedPoint2 _initialMaxVolume = FixedPoint2.New(15);
|
||||
|
||||
private InjectorToggleMode _toggleState;
|
||||
|
||||
@@ -180,7 +181,7 @@ namespace Content.Server.Chemistry.Components
|
||||
return;
|
||||
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetBloodstream.EmptyVolume);
|
||||
var realTransferAmount = FixedPoint2.Min(_transferAmount, targetBloodstream.EmptyVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
@@ -223,7 +224,7 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.AvailableVolume);
|
||||
var realTransferAmount = FixedPoint2.Min(_transferAmount, targetSolution.AvailableVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
@@ -285,7 +286,7 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.DrawAvailable);
|
||||
var realTransferAmount = FixedPoint2.Min(_transferAmount, targetSolution.DrawAvailable);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
@@ -317,8 +318,8 @@ namespace Content.Server.Chemistry.Components
|
||||
Owner.EntityManager.EntitySysManager.GetEntitySystem<SolutionContainerSystem>()
|
||||
.TryGetSolution(Owner.Uid, SolutionName, out var solution);
|
||||
|
||||
var currentVolume = solution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
var maxVolume = solution?.MaxVolume ?? ReagentUnit.Zero;
|
||||
var currentVolume = solution?.CurrentVolume ?? FixedPoint2.Zero;
|
||||
var maxVolume = solution?.MaxVolume ?? FixedPoint2.Zero;
|
||||
|
||||
return new InjectorComponentState(currentVolume, maxVolume, ToggleState);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -13,7 +14,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("transferAmount")]
|
||||
public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(1);
|
||||
public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(1);
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); }
|
||||
|
||||
@@ -12,6 +12,7 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Dispenser;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
@@ -53,7 +54,7 @@ namespace Content.Server.Chemistry.Components
|
||||
private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
|
||||
|
||||
[ViewVariables] public bool HasBeaker => BeakerContainer.ContainedEntity != null;
|
||||
[ViewVariables] private ReagentUnit _dispenseAmount = ReagentUnit.New(10);
|
||||
[ViewVariables] private FixedPoint2 _dispenseAmount = FixedPoint2.New(10);
|
||||
|
||||
[UsedImplicitly]
|
||||
[ViewVariables]
|
||||
@@ -163,31 +164,31 @@ namespace Content.Server.Chemistry.Components
|
||||
TryClear();
|
||||
break;
|
||||
case UiButton.SetDispenseAmount1:
|
||||
_dispenseAmount = ReagentUnit.New(1);
|
||||
_dispenseAmount = FixedPoint2.New(1);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount5:
|
||||
_dispenseAmount = ReagentUnit.New(5);
|
||||
_dispenseAmount = FixedPoint2.New(5);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount10:
|
||||
_dispenseAmount = ReagentUnit.New(10);
|
||||
_dispenseAmount = FixedPoint2.New(10);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount15:
|
||||
_dispenseAmount = ReagentUnit.New(15);
|
||||
_dispenseAmount = FixedPoint2.New(15);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount20:
|
||||
_dispenseAmount = ReagentUnit.New(20);
|
||||
_dispenseAmount = FixedPoint2.New(20);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount25:
|
||||
_dispenseAmount = ReagentUnit.New(25);
|
||||
_dispenseAmount = FixedPoint2.New(25);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount30:
|
||||
_dispenseAmount = ReagentUnit.New(30);
|
||||
_dispenseAmount = FixedPoint2.New(30);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount50:
|
||||
_dispenseAmount = ReagentUnit.New(50);
|
||||
_dispenseAmount = FixedPoint2.New(50);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount100:
|
||||
_dispenseAmount = ReagentUnit.New(100);
|
||||
_dispenseAmount = FixedPoint2.New(100);
|
||||
break;
|
||||
case UiButton.Dispense:
|
||||
if (HasBeaker)
|
||||
@@ -237,8 +238,8 @@ namespace Content.Server.Chemistry.Components
|
||||
if (beaker == null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var solution))
|
||||
{
|
||||
return new ReagentDispenserBoundUserInterfaceState(Powered, false, ReagentUnit.New(0),
|
||||
ReagentUnit.New(0),
|
||||
return new ReagentDispenserBoundUserInterfaceState(Powered, false, FixedPoint2.New(0),
|
||||
FixedPoint2.New(0),
|
||||
string.Empty, Inventory, Owner.Name, null, _dispenseAmount);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -13,7 +14,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
[DataField("transferAmount")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(10);
|
||||
public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(10);
|
||||
|
||||
[DataField("tankType")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.Body.Respiratory;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Smoking;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -39,12 +40,12 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
var chemistry = EntitySystem.Get<ChemistrySystem>();
|
||||
var cloneSolution = solution.Clone();
|
||||
var transferAmount = ReagentUnit.Min(cloneSolution.TotalVolume * solutionFraction, bloodstream.EmptyVolume);
|
||||
var transferAmount = FixedPoint2.Min(cloneSolution.TotalVolume * solutionFraction, bloodstream.EmptyVolume);
|
||||
var transferSolution = cloneSolution.SplitSolution(transferAmount);
|
||||
|
||||
foreach (var reagentQuantity in transferSolution.Contents.ToArray())
|
||||
{
|
||||
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;
|
||||
if (reagentQuantity.Quantity == FixedPoint2.Zero) continue;
|
||||
chemistry.ReactionEntity(entity, ReactionMethod.Ingestion, reagentQuantity.ReagentId, reagentQuantity.Quantity, transferSolution);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Server.Coordinates.Helpers;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
@@ -133,7 +134,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
foreach (var reagentQuantity in solution.Contents)
|
||||
{
|
||||
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;
|
||||
if (reagentQuantity.Quantity == FixedPoint2.Zero) continue;
|
||||
var reagent = PrototypeManager.Index<ReagentPrototype>(reagentQuantity.ReagentId);
|
||||
|
||||
// React with the tile the effect is on
|
||||
@@ -164,7 +165,7 @@ namespace Content.Server.Chemistry.Components
|
||||
return;
|
||||
|
||||
var addSolution =
|
||||
solution.SplitSolution(ReagentUnit.Min(solution.TotalVolume, solutionArea.AvailableVolume));
|
||||
solution.SplitSolution(FixedPoint2.Min(solution.TotalVolume, solutionArea.AvailableVolume));
|
||||
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(Owner.Uid, solutionArea, addSolution);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -16,7 +17,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("transferAmount")]
|
||||
public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(1);
|
||||
public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(1);
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); }
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Server.UserInterface;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Popups;
|
||||
@@ -35,21 +36,21 @@ namespace Content.Server.Chemistry.Components
|
||||
/// </summary>
|
||||
[DataField("transferAmount")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(5);
|
||||
public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(5);
|
||||
|
||||
/// <summary>
|
||||
/// The minimum amount of solution that can be transferred at once from this solution.
|
||||
/// </summary>
|
||||
[DataField("minTransferAmount")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ReagentUnit MinimumTransferAmount { get; set; } = ReagentUnit.New(5);
|
||||
public FixedPoint2 MinimumTransferAmount { get; set; } = FixedPoint2.New(5);
|
||||
|
||||
/// <summary>
|
||||
/// The maximum amount of solution that can be transferred at once from this solution.
|
||||
/// </summary>
|
||||
[DataField("maxTransferAmount")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ReagentUnit MaximumTransferAmount { get; set; } = ReagentUnit.New(50);
|
||||
public FixedPoint2 MaximumTransferAmount { get; set; } = FixedPoint2.New(50);
|
||||
|
||||
/// <summary>
|
||||
/// Can this entity take reagent from reagent tanks?
|
||||
@@ -95,14 +96,14 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
serverMsg.Session.AttachedEntity?.PopupMessage(Loc.GetString("comp-solution-transfer-set-amount",
|
||||
("amount", amount)));
|
||||
SetTransferAmount(ReagentUnit.New(amount));
|
||||
SetTransferAmount(FixedPoint2.New(amount));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTransferAmount(ReagentUnit amount)
|
||||
public void SetTransferAmount(FixedPoint2 amount)
|
||||
{
|
||||
amount = ReagentUnit.New(Math.Clamp(amount.Int(), MinimumTransferAmount.Int(),
|
||||
amount = FixedPoint2.New(Math.Clamp(amount.Int(), MinimumTransferAmount.Int(),
|
||||
MaximumTransferAmount.Int()));
|
||||
TransferAmount = amount;
|
||||
}
|
||||
@@ -162,30 +163,30 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
|
||||
/// <returns>The actual amount transferred.</returns>
|
||||
private static ReagentUnit DoTransfer(IEntity user,
|
||||
private static FixedPoint2 DoTransfer(IEntity user,
|
||||
IEntity sourceEntity,
|
||||
Solution source,
|
||||
IEntity targetEntity,
|
||||
Solution target,
|
||||
ReagentUnit amount)
|
||||
FixedPoint2 amount)
|
||||
{
|
||||
|
||||
if (source.DrainAvailable == 0)
|
||||
{
|
||||
sourceEntity.PopupMessage(user,
|
||||
Loc.GetString("comp-solution-transfer-is-empty", ("target", sourceEntity)));
|
||||
return ReagentUnit.Zero;
|
||||
return FixedPoint2.Zero;
|
||||
}
|
||||
|
||||
if (target.AvailableVolume == 0)
|
||||
{
|
||||
targetEntity.PopupMessage(user,
|
||||
Loc.GetString("comp-solution-transfer-is-full", ("target", targetEntity)));
|
||||
return ReagentUnit.Zero;
|
||||
return FixedPoint2.Zero;
|
||||
}
|
||||
|
||||
var actualAmount =
|
||||
ReagentUnit.Min(amount, ReagentUnit.Min(source.DrainAvailable, target.AvailableVolume));
|
||||
FixedPoint2.Min(amount, FixedPoint2.Min(source.DrainAvailable, target.AvailableVolume));
|
||||
|
||||
var solution = EntitySystem.Get<SolutionContainerSystem>().Drain(sourceEntity.Uid, source, actualAmount);
|
||||
EntitySystem.Get<SolutionContainerSystem>().Refill(targetEntity.Uid, target, solution);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Vapor;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
@@ -12,7 +13,7 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
[ViewVariables]
|
||||
[DataField("transferAmount")]
|
||||
internal ReagentUnit TransferAmount = ReagentUnit.New(0.5);
|
||||
internal FixedPoint2 TransferAmount = FixedPoint2.New(0.5);
|
||||
|
||||
internal bool Reached;
|
||||
internal float ReactTimer;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
@@ -9,7 +10,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
public class ChemicalReactionSystem : SharedChemicalReactionSystem
|
||||
{
|
||||
protected override void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, ReagentUnit unitReactions)
|
||||
protected override void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, FixedPoint2 unitReactions)
|
||||
{
|
||||
base.OnReaction(solution, reaction, owner, unitReactions);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -21,7 +22,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, RehydratableComponent component, SolutionChangedEvent args)
|
||||
{
|
||||
if (_solutionsSystem.GetReagentQuantity(uid, component.CatalystPrototype) > ReagentUnit.Zero)
|
||||
if (_solutionsSystem.GetReagentQuantity(uid, component.CatalystPrototype) > FixedPoint2.Zero)
|
||||
{
|
||||
Expand(component, component.Owner);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
@@ -26,7 +27,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
TryAddSolution(targetUid, targetSolution, addedSolution);
|
||||
}
|
||||
|
||||
public Solution Draw(EntityUid targetUid, Solution solution, ReagentUnit amount,
|
||||
public Solution Draw(EntityUid targetUid, Solution solution, FixedPoint2 amount,
|
||||
DrawableSolutionComponent? drawableSolution = null)
|
||||
{
|
||||
if (!Resolve(targetUid, ref drawableSolution, false))
|
||||
@@ -35,7 +36,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return SplitSolution(targetUid, solution, amount);
|
||||
}
|
||||
|
||||
public Solution Drain(EntityUid targetUid, Solution targetSolution, ReagentUnit amount,
|
||||
public Solution Drain(EntityUid targetUid, Solution targetSolution, FixedPoint2 amount,
|
||||
DrainableSolutionComponent? drainableSolution = null)
|
||||
{
|
||||
if (!Resolve(targetUid, ref drainableSolution, false))
|
||||
@@ -106,10 +107,10 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return true;
|
||||
}
|
||||
|
||||
public ReagentUnit DrainAvailable(EntityUid uid)
|
||||
public FixedPoint2 DrainAvailable(EntityUid uid)
|
||||
{
|
||||
return !TryGetDrainableSolution(uid, out var solution)
|
||||
? ReagentUnit.Zero
|
||||
? FixedPoint2.Zero
|
||||
: solution.CurrentVolume;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -51,7 +52,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
foreach (var keyValue in component.Solutions)
|
||||
{
|
||||
var solutionHolder = keyValue.Value;
|
||||
if (solutionHolder.MaxVolume == ReagentUnit.Zero)
|
||||
if (solutionHolder.MaxVolume == FixedPoint2.Zero)
|
||||
{
|
||||
solutionHolder.MaxVolume = solutionHolder.TotalVolume > solutionHolder.InitialMaxVolume
|
||||
? solutionHolder.TotalVolume
|
||||
@@ -115,7 +116,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
/// <param name="solutionHolder"></param>
|
||||
/// <param name="quantity">the volume of solution to remove.</param>
|
||||
/// <returns>The solution that was removed.</returns>
|
||||
public Solution SplitSolution(EntityUid targetUid, Solution solutionHolder, ReagentUnit quantity)
|
||||
public Solution SplitSolution(EntityUid targetUid, Solution solutionHolder, FixedPoint2 quantity)
|
||||
{
|
||||
var splitSol = solutionHolder.SplitSolution(quantity);
|
||||
UpdateChemicals(targetUid, solutionHolder);
|
||||
@@ -164,8 +165,8 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
/// <param name="quantity">The amount of reagent to add.</param>
|
||||
/// <param name="acceptedQuantity">The amount of reagent successfully added.</param>
|
||||
/// <returns>If all the reagent could be added.</returns>
|
||||
public bool TryAddReagent(EntityUid targetUid, Solution targetSolution, string reagentId, ReagentUnit quantity,
|
||||
out ReagentUnit acceptedQuantity)
|
||||
public bool TryAddReagent(EntityUid targetUid, Solution targetSolution, string reagentId, FixedPoint2 quantity,
|
||||
out FixedPoint2 acceptedQuantity)
|
||||
{
|
||||
acceptedQuantity = targetSolution.AvailableVolume > quantity ? quantity : targetSolution.AvailableVolume;
|
||||
targetSolution.AddReagent(reagentId, acceptedQuantity);
|
||||
@@ -184,7 +185,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
/// <param name="reagentId">The Id of the reagent to remove.</param>
|
||||
/// <param name="quantity">The amount of reagent to remove.</param>
|
||||
/// <returns>If the reagent to remove was found in the container.</returns>
|
||||
public bool TryRemoveReagent(EntityUid targetUid, Solution? container, string reagentId, ReagentUnit quantity)
|
||||
public bool TryRemoveReagent(EntityUid targetUid, Solution? container, string reagentId, FixedPoint2 quantity)
|
||||
{
|
||||
if (container == null || !container.ContainsReagent(reagentId))
|
||||
return false;
|
||||
@@ -248,7 +249,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return solutionsMgr.Solutions[name];
|
||||
}
|
||||
|
||||
public string[] RemoveEachReagent(Solution solution, ReagentUnit quantity)
|
||||
public string[] RemoveEachReagent(Solution solution, FixedPoint2 quantity)
|
||||
{
|
||||
var removedReagent = new string[solution.Contents.Count];
|
||||
if (quantity <= 0)
|
||||
@@ -284,9 +285,9 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit GetReagentQuantity(EntityUid ownerUid, string reagentId)
|
||||
public FixedPoint2 GetReagentQuantity(EntityUid ownerUid, string reagentId)
|
||||
{
|
||||
var reagentQuantity = ReagentUnit.New(0);
|
||||
var reagentQuantity = FixedPoint2.New(0);
|
||||
if (EntityManager.TryGetEntity(ownerUid, out var owner)
|
||||
&& owner.TryGetComponent(out SolutionContainerManagerComponent? managerComponent))
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using Robust.Shared.Localization;
|
||||
using Robust.Server.GameObjects;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Popups;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
@@ -53,7 +54,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
verb.Category = VerbCategory.SetTransferAmount;
|
||||
verb.Act = () =>
|
||||
{
|
||||
component.TransferAmount = ReagentUnit.New(amount);
|
||||
component.TransferAmount = FixedPoint2.New(amount);
|
||||
args.User.PopupMessage(Loc.GetString("comp-solution-transfer-set-amount", ("amount", amount)));
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Vapor;
|
||||
using JetBrains.Annotations;
|
||||
@@ -104,7 +105,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
var tile = mapGrid.GetTileRef(entity.Transform.Coordinates.ToVector2i(EntityManager, _mapManager));
|
||||
foreach (var reagentQuantity in contents.Contents.ToArray())
|
||||
{
|
||||
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;
|
||||
if (reagentQuantity.Quantity == FixedPoint2.Zero) continue;
|
||||
var reagent = _protoManager.Index<ReagentPrototype>(reagentQuantity.ReagentId);
|
||||
_solutionContainerSystem.TryRemoveReagent(vapor.Owner.Uid, contents, reagentQuantity.ReagentId,
|
||||
reagent.ReactionTile(tile, (reagentQuantity.Quantity / vapor.TransferAmount) * 0.25f));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
@@ -12,10 +13,10 @@ namespace Content.Server.Chemistry.ReagentEffectConditions
|
||||
public class ReagentThreshold : ReagentEffectCondition
|
||||
{
|
||||
[DataField("min")]
|
||||
public ReagentUnit Min = ReagentUnit.Zero;
|
||||
public FixedPoint2 Min = FixedPoint2.Zero;
|
||||
|
||||
[DataField("max")]
|
||||
public ReagentUnit Max = ReagentUnit.MaxValue;
|
||||
public FixedPoint2 Max = FixedPoint2.MaxValue;
|
||||
|
||||
public override bool Condition(IEntity solutionEntity, Solution.ReagentQuantity reagent)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -19,7 +20,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||
// ReSharper disable once CollectionNeverUpdated.Local
|
||||
private readonly HashSet<string> _reagents = new();
|
||||
|
||||
protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source)
|
||||
protected override void React(IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Solution? source)
|
||||
{
|
||||
// TODO see if this is correct
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>()
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -17,7 +18,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||
// ReSharper disable once CollectionNeverUpdated.Local
|
||||
private readonly HashSet<string> _reagents = new ();
|
||||
|
||||
protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source)
|
||||
protected override void React(IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Solution? source)
|
||||
{
|
||||
if (!entity.TryGetComponent(out FlammableComponent? flammable) || !_reagents.Contains(reagent.ID)) return;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -17,7 +18,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||
// ReSharper disable once CollectionNeverUpdated.Local
|
||||
private readonly HashSet<string> _reagents = new ();
|
||||
|
||||
protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source)
|
||||
protected override void React(IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Solution? source)
|
||||
{
|
||||
if (!entity.TryGetComponent(out FlammableComponent? flammable) || !_reagents.Contains(reagent.ID)) return;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using Content.Server.Nutrition.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -17,7 +18,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||
// ReSharper disable once CollectionNeverUpdated.Local
|
||||
private readonly HashSet<string> _reagents = new ();
|
||||
|
||||
protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source)
|
||||
protected override void React(IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Solution? source)
|
||||
{
|
||||
if (!entity.TryGetComponent(out CreamPiedComponent? creamPied) || !_reagents.Contains(reagent.ID)) return;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.GameObjects.Components;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
@@ -13,10 +14,10 @@ namespace Content.Server.Chemistry.TileReactions
|
||||
[DataDefinition]
|
||||
public class CleanTileReaction : ITileReaction
|
||||
{
|
||||
ReagentUnit ITileReaction.TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume)
|
||||
FixedPoint2 ITileReaction.TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume)
|
||||
{
|
||||
var entities = tile.GetEntitiesInTileFast().ToArray();
|
||||
var amount = ReagentUnit.Zero;
|
||||
var amount = FixedPoint2.Zero;
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (entity.TryGetComponent(out CleanableComponent? cleanable))
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Atmos;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Maps;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -19,17 +20,17 @@ namespace Content.Server.Chemistry.TileReactions
|
||||
{
|
||||
[DataField("coolingTemperature")] private float _coolingTemperature = 2f;
|
||||
|
||||
public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume)
|
||||
public FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume)
|
||||
{
|
||||
if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty)
|
||||
return ReagentUnit.Zero;
|
||||
if (reactVolume <= FixedPoint2.Zero || tile.Tile.IsEmpty)
|
||||
return FixedPoint2.Zero;
|
||||
|
||||
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
|
||||
|
||||
var environment = atmosphereSystem.GetTileMixture(tile.GridIndex, tile.GridIndices, true);
|
||||
|
||||
if (environment == null || !atmosphereSystem.IsHotspotActive(tile.GridIndex, tile.GridIndices))
|
||||
return ReagentUnit.Zero;
|
||||
return FixedPoint2.Zero;
|
||||
|
||||
environment.Temperature =
|
||||
MathF.Max(MathF.Min(environment.Temperature - (_coolingTemperature * 1000f),
|
||||
@@ -38,7 +39,7 @@ namespace Content.Server.Chemistry.TileReactions
|
||||
atmosphereSystem.React(tile.GridIndex, tile.GridIndices);
|
||||
atmosphereSystem.HotspotExtinguish(tile.GridIndex, tile.GridIndices);
|
||||
|
||||
return ReagentUnit.Zero;
|
||||
return FixedPoint2.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Maps;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -18,16 +19,16 @@ namespace Content.Server.Chemistry.TileReactions
|
||||
{
|
||||
[DataField("temperatureMultiplier")] private float _temperatureMultiplier = 1.15f;
|
||||
|
||||
public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume)
|
||||
public FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume)
|
||||
{
|
||||
if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty)
|
||||
return ReagentUnit.Zero;
|
||||
if (reactVolume <= FixedPoint2.Zero || tile.Tile.IsEmpty)
|
||||
return FixedPoint2.Zero;
|
||||
|
||||
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
|
||||
|
||||
var environment = atmosphereSystem.GetTileMixture(tile.GridIndex, tile.GridIndices, true);
|
||||
if (environment == null || !atmosphereSystem.IsHotspotActive(tile.GridIndex, tile.GridIndices))
|
||||
return ReagentUnit.Zero;
|
||||
return FixedPoint2.Zero;
|
||||
|
||||
environment.Temperature *= MathF.Max(_temperatureMultiplier * reactVolume.Float(), 1f);
|
||||
atmosphereSystem.React(tile.GridIndex, tile.GridIndices);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -12,11 +13,11 @@ namespace Content.Server.Chemistry.TileReactions
|
||||
[DataDefinition]
|
||||
public class SpillIfPuddlePresentTileReaction : ITileReaction
|
||||
{
|
||||
public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume)
|
||||
public FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume)
|
||||
{
|
||||
if (reactVolume < 5 || !tile.TryGetPuddle(null, out _)) return ReagentUnit.Zero;
|
||||
if (reactVolume < 5 || !tile.TryGetPuddle(null, out _)) return FixedPoint2.Zero;
|
||||
|
||||
return tile.SpillAt(new Solution(reagent.ID, reactVolume), "PuddleSmear", true, false) != null ? reactVolume : ReagentUnit.Zero;
|
||||
return tile.SpillAt(new Solution(reagent.ID, reactVolume), "PuddleSmear", true, false) != null ? reactVolume : FixedPoint2.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Slippery;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
@@ -18,9 +19,9 @@ namespace Content.Server.Chemistry.TileReactions
|
||||
[DataField("paralyzeTime")] private float _paralyzeTime = 1;
|
||||
[DataField("overflow")] private bool _overflow;
|
||||
|
||||
public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume)
|
||||
public FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume)
|
||||
{
|
||||
if (reactVolume < 5) return ReagentUnit.Zero;
|
||||
if (reactVolume < 5) return FixedPoint2.Zero;
|
||||
|
||||
// TODO Make this not puddle smear.
|
||||
var puddle = tile.SpillAt(new Solution(reagent.ID, reactVolume), "PuddleSmear", _overflow, false);
|
||||
@@ -35,7 +36,7 @@ namespace Content.Server.Chemistry.TileReactions
|
||||
return reactVolume;
|
||||
}
|
||||
|
||||
return ReagentUnit.Zero;
|
||||
return FixedPoint2.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -11,8 +12,8 @@ namespace Content.Server.Cleanable
|
||||
public override string Name => "Cleanable";
|
||||
|
||||
[DataField("cleanAmount")]
|
||||
private ReagentUnit _cleanAmount = ReagentUnit.Zero;
|
||||
private FixedPoint2 _cleanAmount = FixedPoint2.Zero;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ReagentUnit CleanAmount => _cleanAmount;
|
||||
public FixedPoint2 CleanAmount => _cleanAmount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Extinguisher;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -63,7 +64,7 @@ namespace Content.Server.Extinguisher
|
||||
&& solutionContainerSystem.TryGetDrainableSolution(targetEntity.Uid, out var targetSolution)
|
||||
&& solutionContainerSystem.TryGetDrainableSolution(Owner.Uid, out var container))
|
||||
{
|
||||
var transfer = ReagentUnit.Min(container.AvailableVolume, targetSolution.DrainAvailable);
|
||||
var transfer = FixedPoint2.Min(container.AvailableVolume, targetSolution.DrainAvailable);
|
||||
if (transfer > 0)
|
||||
{
|
||||
var drained = solutionContainerSystem.Drain(targetEntity.Uid, targetSolution, transfer);
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Popups;
|
||||
@@ -26,12 +27,12 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
private List<EntityUid> _currentlyUsing = new();
|
||||
|
||||
public ReagentUnit MaxVolume
|
||||
public FixedPoint2 MaxVolume
|
||||
{
|
||||
get =>
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
? solution.MaxVolume
|
||||
: ReagentUnit.Zero;
|
||||
: FixedPoint2.Zero;
|
||||
set
|
||||
{
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
@@ -41,9 +42,9 @@ namespace Content.Server.Fluids.Components
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume => EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
public FixedPoint2 CurrentVolume => EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
? solution.CurrentVolume
|
||||
: ReagentUnit.Zero;
|
||||
: FixedPoint2.Zero;
|
||||
|
||||
[DataField("sound")]
|
||||
private SoundSpecifier _sound = new SoundPathSpecifier("/Audio/Effects/Fluids/watersplash.ogg");
|
||||
@@ -93,7 +94,7 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
// Top up mops solution given it needs it to annihilate puddles I guess
|
||||
|
||||
var transferAmount = ReagentUnit.Min(mopComponent.MaxVolume - mopComponent.CurrentVolume, CurrentVolume);
|
||||
var transferAmount = FixedPoint2.Min(mopComponent.MaxVolume - mopComponent.CurrentVolume, CurrentVolume);
|
||||
if (transferAmount == 0)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -13,7 +14,7 @@ namespace Content.Server.Fluids.Components
|
||||
public override string Name => "Evaporation";
|
||||
|
||||
/// <summary>
|
||||
/// The time that it will take this puddle to lose one reagent unit of solution, in seconds.
|
||||
/// The time that it will take this puddle to lose one fixed unit of solution, in seconds.
|
||||
/// </summary>
|
||||
[DataField("evaporateTime")]
|
||||
public float EvaporateTime { get; set; } = 5f;
|
||||
@@ -29,14 +30,14 @@ namespace Content.Server.Fluids.Components
|
||||
/// Defaults to evaporate completely.
|
||||
/// </summary>
|
||||
[DataField("lowerLimit")]
|
||||
public ReagentUnit LowerLimit = ReagentUnit.Zero;
|
||||
public FixedPoint2 LowerLimit = FixedPoint2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Upper limit below which puddle won't evaporate. Useful when wanting to make sure large puddle will
|
||||
/// remain forever. Defaults to <see cref="PuddleComponent.DefaultOverflowVolume"/>.
|
||||
/// </summary>
|
||||
[DataField("upperLimit")]
|
||||
public ReagentUnit UpperLimit = PuddleComponent.DefaultOverflowVolume;
|
||||
public FixedPoint2 UpperLimit = PuddleComponent.DefaultOverflowVolume;
|
||||
|
||||
/// <summary>
|
||||
/// The time accumulated since the start.
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.DoAfter;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Popups;
|
||||
@@ -40,9 +41,9 @@ namespace Content.Server.Fluids.Components
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit MaxVolume
|
||||
public FixedPoint2 MaxVolume
|
||||
{
|
||||
get => MopSolution?.MaxVolume ?? ReagentUnit.Zero;
|
||||
get => MopSolution?.MaxVolume ?? FixedPoint2.Zero;
|
||||
set
|
||||
{
|
||||
var solution = MopSolution;
|
||||
@@ -53,14 +54,14 @@ namespace Content.Server.Fluids.Components
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume => MopSolution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
public FixedPoint2 CurrentVolume => MopSolution?.CurrentVolume ?? FixedPoint2.Zero;
|
||||
|
||||
// Currently there's a separate amount for pickup and dropoff so
|
||||
// Picking up a puddle requires multiple clicks
|
||||
// Dumping in a bucket requires 1 click
|
||||
// Long-term you'd probably use a cooldown and start the pickup once we have some form of global cooldown
|
||||
[DataField("pickup_amount")]
|
||||
public ReagentUnit PickupAmount { get; } = ReagentUnit.New(5);
|
||||
public FixedPoint2 PickupAmount { get; } = FixedPoint2.New(5);
|
||||
|
||||
[DataField("pickup_sound")]
|
||||
private SoundSpecifier _pickupSound = new SoundPathSpecifier("/Audio/Effects/Fluids/slosh.ogg");
|
||||
@@ -136,7 +137,7 @@ namespace Content.Server.Fluids.Components
|
||||
return false;
|
||||
|
||||
// Annihilate the puddle
|
||||
var transferAmount = ReagentUnit.Min(ReagentUnit.New(5), puddleComponent.CurrentVolume, CurrentVolume);
|
||||
var transferAmount = FixedPoint2.Min(FixedPoint2.New(5), puddleComponent.CurrentVolume, CurrentVolume);
|
||||
var puddleCleaned = puddleComponent.CurrentVolume - transferAmount <= 0;
|
||||
|
||||
var puddleSystem = EntitySystem.Get<PuddleSystem>();
|
||||
@@ -146,7 +147,7 @@ namespace Content.Server.Fluids.Components
|
||||
if (puddleSystem.EmptyHolder(puddleComponent.Owner.Uid, puddleComponent)) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
|
||||
{
|
||||
puddleComponent.Owner.Delete();
|
||||
transferAmount = ReagentUnit.Min(ReagentUnit.New(5), CurrentVolume);
|
||||
transferAmount = FixedPoint2.Min(FixedPoint2.New(5), CurrentVolume);
|
||||
puddleCleaned = true;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -16,8 +17,8 @@ namespace Content.Server.Fluids.Components
|
||||
public sealed class PuddleComponent : Component
|
||||
{
|
||||
public const string DefaultSolutionName = "puddle";
|
||||
private static readonly ReagentUnit DefaultSlipThreshold = ReagentUnit.New(3);
|
||||
public static readonly ReagentUnit DefaultOverflowVolume = ReagentUnit.New(20);
|
||||
private static readonly FixedPoint2 DefaultSlipThreshold = FixedPoint2.New(3);
|
||||
public static readonly FixedPoint2 DefaultOverflowVolume = FixedPoint2.New(20);
|
||||
|
||||
public override string Name => "Puddle";
|
||||
|
||||
@@ -35,7 +36,7 @@ namespace Content.Server.Fluids.Components
|
||||
// to check for low volumes for evaporation or whatever
|
||||
|
||||
|
||||
[DataField("slipThreshold")] public ReagentUnit SlipThreshold = DefaultSlipThreshold;
|
||||
[DataField("slipThreshold")] public FixedPoint2 SlipThreshold = DefaultSlipThreshold;
|
||||
|
||||
[DataField("spillSound")]
|
||||
public SoundSpecifier SpillSound = new SoundPathSpecifier("/Audio/Effects/Fluids/splat.ogg");
|
||||
@@ -46,12 +47,12 @@ namespace Content.Server.Fluids.Components
|
||||
public bool Overflown;
|
||||
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public ReagentUnit CurrentVolume => EntitySystem.Get<PuddleSystem>().CurrentVolume(Owner.Uid);
|
||||
public FixedPoint2 CurrentVolume => EntitySystem.Get<PuddleSystem>().CurrentVolume(Owner.Uid);
|
||||
|
||||
[ViewVariables] [DataField("overflowVolume")]
|
||||
public ReagentUnit OverflowVolume = DefaultOverflowVolume;
|
||||
public FixedPoint2 OverflowVolume = DefaultOverflowVolume;
|
||||
|
||||
public ReagentUnit OverflowLeft => CurrentVolume - OverflowVolume;
|
||||
public FixedPoint2 OverflowLeft => CurrentVolume - OverflowVolume;
|
||||
|
||||
[DataField("solution")] public string SolutionName { get; set; } = DefaultSolutionName;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.Coordinates.Helpers;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -132,7 +133,7 @@ namespace Content.Server.Fluids.Components
|
||||
.TryGetRefillableSolution(spillEntity.Uid, out var solutionContainerComponent))
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>().Refill(spillEntity.Uid, solutionContainerComponent,
|
||||
solution.SplitSolution(ReagentUnit.Min(
|
||||
solution.SplitSolution(FixedPoint2.Min(
|
||||
solutionContainerComponent.AvailableVolume,
|
||||
solutionContainerComponent.MaxSpillRefill))
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Cooldown;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Fluids;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
@@ -34,7 +35,7 @@ namespace Content.Server.Fluids.Components
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
[DataField("transferAmount")]
|
||||
private ReagentUnit _transferAmount = ReagentUnit.New(10);
|
||||
private FixedPoint2 _transferAmount = FixedPoint2.New(10);
|
||||
[DataField("sprayVelocity")]
|
||||
private float _sprayVelocity = 1.5f;
|
||||
[DataField("sprayAliveTime")]
|
||||
@@ -56,7 +57,7 @@ namespace Content.Server.Fluids.Components
|
||||
/// The amount of solution to be sprayer from this solution when using it
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public ReagentUnit TransferAmount
|
||||
public FixedPoint2 TransferAmount
|
||||
{
|
||||
get => _transferAmount;
|
||||
set => _transferAmount = value;
|
||||
@@ -75,11 +76,11 @@ namespace Content.Server.Fluids.Components
|
||||
[DataField("spraySound", required: true)]
|
||||
public SoundSpecifier SpraySound { get; } = default!;
|
||||
|
||||
public ReagentUnit CurrentVolume {
|
||||
public FixedPoint2 CurrentVolume {
|
||||
get
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution);
|
||||
return solution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
return solution?.CurrentVolume ?? FixedPoint2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
var solution = EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, contents, _transferAmount);
|
||||
|
||||
if (solution.TotalVolume <= ReagentUnit.Zero)
|
||||
if (solution.TotalVolume <= FixedPoint2.Zero)
|
||||
break;
|
||||
|
||||
var vapor = entManager.SpawnEntity(_vaporPrototype, playerPos.Offset(distance < 1 ? quarter : threeQuarters));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -36,7 +37,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
|
||||
|
||||
_solutionContainerSystem.SplitSolution(uid, solution,
|
||||
ReagentUnit.Min(ReagentUnit.New(1), solution.CurrentVolume));
|
||||
FixedPoint2.Min(FixedPoint2.New(1), solution.CurrentVolume));
|
||||
|
||||
if (solution.CurrentVolume == 0)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Directions;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Fluids;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Physics;
|
||||
@@ -46,7 +47,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
private void OnInit(EntityUid uid, PuddleComponent component, ComponentInit args)
|
||||
{
|
||||
var solution = _solutionContainerSystem.EnsureSolution(uid, component.SolutionName);
|
||||
solution.MaxVolume = ReagentUnit.New(1000);
|
||||
solution.MaxVolume = FixedPoint2.New(1000);
|
||||
}
|
||||
|
||||
private void OnUpdate(EntityUid uid, PuddleComponent component, SolutionChangedEvent args)
|
||||
@@ -74,7 +75,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
|
||||
private void UpdateSlip(EntityUid entityUid, PuddleComponent puddleComponent)
|
||||
{
|
||||
if ((puddleComponent.SlipThreshold == ReagentUnit.New(-1) ||
|
||||
if ((puddleComponent.SlipThreshold == FixedPoint2.New(-1) ||
|
||||
puddleComponent.CurrentVolume < puddleComponent.SlipThreshold) &&
|
||||
EntityManager.TryGetComponent(entityUid, out SlipperyComponent? oldSlippery))
|
||||
{
|
||||
@@ -95,7 +96,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
if (!_solutionContainerSystem.TryGetDrainableSolution(args.Target.Uid, out var solution))
|
||||
return;
|
||||
|
||||
if (solution.DrainAvailable == ReagentUnit.Zero)
|
||||
if (solution.DrainAvailable == FixedPoint2.Zero)
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
@@ -147,15 +148,15 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
|| solution.Contents.Count == 0;
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume(EntityUid uid, PuddleComponent? puddleComponent = null)
|
||||
public FixedPoint2 CurrentVolume(EntityUid uid, PuddleComponent? puddleComponent = null)
|
||||
{
|
||||
if (!Resolve(uid, ref puddleComponent))
|
||||
return ReagentUnit.Zero;
|
||||
return FixedPoint2.Zero;
|
||||
|
||||
return _solutionContainerSystem.TryGetSolution(puddleComponent.Owner.Uid, puddleComponent.SolutionName,
|
||||
out var solution)
|
||||
? solution.CurrentVolume
|
||||
: ReagentUnit.Zero;
|
||||
: FixedPoint2.Zero;
|
||||
}
|
||||
|
||||
public bool TryAddSolution(EntityUid uid, Solution solution,
|
||||
@@ -210,7 +211,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
var nextPuddles = new List<PuddleComponent>() { puddleComponent };
|
||||
var overflownPuddles = new List<PuddleComponent>();
|
||||
|
||||
while (puddleComponent.OverflowLeft > ReagentUnit.Zero && nextPuddles.Count > 0)
|
||||
while (puddleComponent.OverflowLeft > FixedPoint2.Zero && nextPuddles.Count > 0)
|
||||
{
|
||||
foreach (var next in nextPuddles.ToArray())
|
||||
{
|
||||
@@ -220,7 +221,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
overflownPuddles.Add(next);
|
||||
|
||||
var adjacentPuddles = GetAllAdjacentOverflow(next).ToArray();
|
||||
if (puddleComponent.OverflowLeft <= ReagentUnit.Epsilon * adjacentPuddles.Length)
|
||||
if (puddleComponent.OverflowLeft <= FixedPoint2.Epsilon * adjacentPuddles.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -230,12 +231,12 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
continue;
|
||||
}
|
||||
|
||||
var numberOfAdjacent = ReagentUnit.New(adjacentPuddles.Length);
|
||||
var numberOfAdjacent = FixedPoint2.New(adjacentPuddles.Length);
|
||||
var overflowSplit = puddleComponent.OverflowLeft / numberOfAdjacent;
|
||||
foreach (var adjacent in adjacentPuddles)
|
||||
{
|
||||
var adjacentPuddle = adjacent();
|
||||
var quantity = ReagentUnit.Min(overflowSplit, adjacentPuddle.OverflowVolume);
|
||||
var quantity = FixedPoint2.Min(overflowSplit, adjacentPuddle.OverflowVolume);
|
||||
var puddleSolution = _solutionContainerSystem.EnsureSolution(puddleComponent.Owner.Uid,
|
||||
puddleComponent.SolutionName);
|
||||
var spillAmount = _solutionContainerSystem.SplitSolution(puddleComponent.Owner.Uid,
|
||||
|
||||
@@ -15,6 +15,7 @@ using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Kitchen;
|
||||
using Content.Shared.Kitchen.Components;
|
||||
@@ -263,7 +264,7 @@ namespace Content.Server.Kitchen.Components
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(attackPourable.TransferAmount, solution.AvailableVolume);
|
||||
var realTransferAmount = FixedPoint2.Min(attackPourable.TransferAmount, solution.AvailableVolume);
|
||||
if (realTransferAmount <= 0) //Special message if container is full
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User,
|
||||
@@ -440,7 +441,7 @@ namespace Content.Server.Kitchen.Components
|
||||
foreach (var recipeReagent in recipe.IngredientsReagents)
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryRemoveReagent(solutionUid, solution, recipeReagent.Key, ReagentUnit.New(recipeReagent.Value));
|
||||
.TryRemoveReagent(solutionUid, solution, recipeReagent.Key, FixedPoint2.New(recipeReagent.Value));
|
||||
}
|
||||
|
||||
foreach (var recipeSolid in recipe.IngredientsSolids)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Alert;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.MobState.State;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -9,7 +10,7 @@ namespace Content.Server.MobState.States
|
||||
{
|
||||
public class NormalMobState : SharedNormalMobState
|
||||
{
|
||||
public override void UpdateState(IEntity entity, int threshold)
|
||||
public override void UpdateState(IEntity entity, FixedPoint2 threshold)
|
||||
{
|
||||
base.UpdateState(entity, threshold);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Server.Nutrition.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
@@ -217,7 +218,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
if (user != target && !user.InRangeUnobstructed(target, popup: true))
|
||||
return false;
|
||||
|
||||
var transferAmount = ReagentUnit.Min(component.TransferAmount, interactions.DrainAvailable);
|
||||
var transferAmount = FixedPoint2.Min(component.TransferAmount, interactions.DrainAvailable);
|
||||
var drain = _solutionContainerSystem.Drain(owner.Uid, interactions, transferAmount);
|
||||
var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(drain));
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Smoking;
|
||||
using Content.Shared.Temperature;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -83,12 +84,12 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
|
||||
var inhaledSolution = _solutionContainerSystem.SplitSolution(uid, solution, smokable.InhaleAmount * _timer);
|
||||
|
||||
if (solution.TotalVolume == ReagentUnit.Zero)
|
||||
if (solution.TotalVolume == FixedPoint2.Zero)
|
||||
{
|
||||
RaiseLocalEvent(uid, new SmokableSolutionEmptyEvent());
|
||||
}
|
||||
|
||||
if (inhaledSolution.TotalVolume == ReagentUnit.Zero)
|
||||
if (inhaledSolution.TotalVolume == FixedPoint2.Zero)
|
||||
continue;
|
||||
|
||||
// This is awful. I hate this so much.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -26,13 +27,13 @@ namespace Content.Server.Tools.Components
|
||||
/// Fuel consumption per second, while the welder is active.
|
||||
/// </summary>
|
||||
[DataField("fuelConsumption")]
|
||||
public ReagentUnit FuelConsumption { get; } = ReagentUnit.New(0.05f);
|
||||
public FixedPoint2 FuelConsumption { get; } = FixedPoint2.New(0.05f);
|
||||
|
||||
/// <summary>
|
||||
/// A fuel amount to be consumed when the welder goes from being unlit to being lit.
|
||||
/// </summary>
|
||||
[DataField("welderOnConsume")]
|
||||
public ReagentUnit FuelLitCost { get; } = ReagentUnit.New(0.5f);
|
||||
public FixedPoint2 FuelLitCost { get; } = FixedPoint2.New(0.5f);
|
||||
|
||||
/// <summary>
|
||||
/// Sound played when the welder is turned off.
|
||||
|
||||
@@ -8,6 +8,7 @@ using Content.Server.Tools.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Temperature;
|
||||
@@ -43,11 +44,11 @@ namespace Content.Server.Tools
|
||||
SubscribeLocalEvent<WelderComponent, ComponentGetState>(OnWelderGetState);
|
||||
}
|
||||
|
||||
public (ReagentUnit fuel, ReagentUnit capacity) GetWelderFuelAndCapacity(EntityUid uid, WelderComponent? welder = null, SolutionContainerManagerComponent? solutionContainer = null)
|
||||
public (FixedPoint2 fuel, FixedPoint2 capacity) GetWelderFuelAndCapacity(EntityUid uid, WelderComponent? welder = null, SolutionContainerManagerComponent? solutionContainer = null)
|
||||
{
|
||||
if (!Resolve(uid, ref welder, ref solutionContainer)
|
||||
|| !_solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var fuelSolution, solutionContainer))
|
||||
return (ReagentUnit.Zero, ReagentUnit.Zero);
|
||||
return (FixedPoint2.Zero, FixedPoint2.Zero);
|
||||
|
||||
return (_solutionContainerSystem.GetReagentQuantity(uid, welder.FuelReagent), fuelSolution.MaxVolume);
|
||||
}
|
||||
@@ -88,7 +89,7 @@ namespace Content.Server.Tools
|
||||
var fuel = solution.GetReagentQuantity(welder.FuelReagent);
|
||||
|
||||
// Not enough fuel to lit welder.
|
||||
if (fuel == ReagentUnit.Zero || fuel < welder.FuelLitCost)
|
||||
if (fuel == FixedPoint2.Zero || fuel < welder.FuelLitCost)
|
||||
{
|
||||
if(user != null)
|
||||
_popupSystem.PopupEntity(Loc.GetString("welder-component-no-fuel-message"), uid, Filter.Entities(user.Value));
|
||||
@@ -182,7 +183,7 @@ namespace Content.Server.Tools
|
||||
var (fuel, capacity) = GetWelderFuelAndCapacity(uid, welder);
|
||||
|
||||
args.PushMarkup(Loc.GetString("welder-component-on-examine-detailed-message",
|
||||
("colorName", fuel < capacity / ReagentUnit.New(4f) ? "darkorange" : "orange"),
|
||||
("colorName", fuel < capacity / FixedPoint2.New(4f) ? "darkorange" : "orange"),
|
||||
("fuelLeft", fuel),
|
||||
("fuelCapacity", capacity)));
|
||||
}
|
||||
@@ -213,7 +214,7 @@ namespace Content.Server.Tools
|
||||
&& _solutionContainerSystem.TryGetDrainableSolution(args.Target.Uid, out var targetSolution)
|
||||
&& _solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var welderSolution))
|
||||
{
|
||||
var trans = ReagentUnit.Min(welderSolution.AvailableVolume, targetSolution.DrainAvailable);
|
||||
var trans = FixedPoint2.Min(welderSolution.AvailableVolume, targetSolution.DrainAvailable);
|
||||
if (trans > 0)
|
||||
{
|
||||
var drained = _solutionContainerSystem.Drain(args.Target.Uid, targetSolution, trans);
|
||||
@@ -249,7 +250,7 @@ namespace Content.Server.Tools
|
||||
|
||||
var (fuel, _) = GetWelderFuelAndCapacity(uid, welder);
|
||||
|
||||
if (ReagentUnit.New(args.Fuel) > fuel)
|
||||
if (FixedPoint2.New(args.Fuel) > fuel)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("welder-component-cannot-weld-message"), uid, Filter.Entities(args.User));
|
||||
args.Cancel();
|
||||
@@ -271,7 +272,7 @@ namespace Content.Server.Tools
|
||||
|
||||
var (fuel, _) = GetWelderFuelAndCapacity(uid, welder);
|
||||
|
||||
var neededFuel = ReagentUnit.New(args.Fuel);
|
||||
var neededFuel = FixedPoint2.New(args.Fuel);
|
||||
|
||||
if (neededFuel > fuel)
|
||||
{
|
||||
@@ -320,7 +321,7 @@ namespace Content.Server.Tools
|
||||
|
||||
solution.RemoveReagent(welder.FuelReagent, welder.FuelConsumption * _welderTimer);
|
||||
|
||||
if (solution.GetReagentQuantity(welder.FuelReagent) <= ReagentUnit.Zero)
|
||||
if (solution.GetReagentQuantity(welder.FuelReagent) <= FixedPoint2.Zero)
|
||||
TryTurnWelderOff(tool, null, welder);
|
||||
|
||||
welder.Dirty();
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Administration
|
||||
@@ -9,8 +10,8 @@ namespace Content.Shared.Administration
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class AdminAddReagentEuiState : EuiStateBase
|
||||
{
|
||||
public ReagentUnit MaxVolume;
|
||||
public ReagentUnit CurVolume;
|
||||
public FixedPoint2 MaxVolume;
|
||||
public FixedPoint2 CurVolume;
|
||||
}
|
||||
|
||||
public static class AdminAddReagentEuiMsg
|
||||
@@ -25,7 +26,7 @@ namespace Content.Shared.Administration
|
||||
public sealed class DoAdd : EuiMessageBase
|
||||
{
|
||||
public bool CloseAfter;
|
||||
public ReagentUnit Amount;
|
||||
public FixedPoint2 Amount;
|
||||
public string ReagentId = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -21,14 +22,14 @@ namespace Content.Shared.Chemistry
|
||||
}
|
||||
}
|
||||
|
||||
public void ReactionEntity(IEntity entity, ReactionMethod method, string reagentId, ReagentUnit reactVolume, Solution? source)
|
||||
public void ReactionEntity(IEntity entity, ReactionMethod method, string reagentId, FixedPoint2 reactVolume, Solution? source)
|
||||
{
|
||||
// We throw if the reagent specified doesn't exist.
|
||||
ReactionEntity(entity, method, _prototypeManager.Index<ReagentPrototype>(reagentId), reactVolume, source);
|
||||
}
|
||||
|
||||
public void ReactionEntity(IEntity entity, ReactionMethod method, ReagentPrototype reagent,
|
||||
ReagentUnit reactVolume, Solution? source)
|
||||
FixedPoint2 reactVolume, Solution? source)
|
||||
{
|
||||
if (entity == null || entity.Deleted || !entity.TryGetComponent(out ReactiveComponent? reactive))
|
||||
return;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Cloning;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -22,8 +23,8 @@ namespace Content.Shared.Chemistry.Components
|
||||
{
|
||||
public readonly bool HasPower;
|
||||
public readonly bool HasBeaker;
|
||||
public readonly ReagentUnit BeakerCurrentVolume;
|
||||
public readonly ReagentUnit BeakerMaxVolume;
|
||||
public readonly FixedPoint2 BeakerCurrentVolume;
|
||||
public readonly FixedPoint2 BeakerMaxVolume;
|
||||
public readonly string ContainerName;
|
||||
|
||||
/// <summary>
|
||||
@@ -38,10 +39,10 @@ namespace Content.Shared.Chemistry.Components
|
||||
|
||||
public readonly bool BufferModeTransfer;
|
||||
|
||||
public readonly ReagentUnit BufferCurrentVolume;
|
||||
public readonly FixedPoint2 BufferCurrentVolume;
|
||||
|
||||
public ChemMasterBoundUserInterfaceState(bool hasPower, bool hasBeaker, ReagentUnit beakerCurrentVolume, ReagentUnit beakerMaxVolume, string containerName,
|
||||
string dispenserName, IReadOnlyList<Solution.ReagentQuantity> containerReagents, IReadOnlyList<Solution.ReagentQuantity> bufferReagents, bool bufferModeTransfer, ReagentUnit bufferCurrentVolume)
|
||||
public ChemMasterBoundUserInterfaceState(bool hasPower, bool hasBeaker, FixedPoint2 beakerCurrentVolume, FixedPoint2 beakerMaxVolume, string containerName,
|
||||
string dispenserName, IReadOnlyList<Solution.ReagentQuantity> containerReagents, IReadOnlyList<Solution.ReagentQuantity> bufferReagents, bool bufferModeTransfer, FixedPoint2 bufferCurrentVolume)
|
||||
{
|
||||
HasPower = hasPower;
|
||||
HasBeaker = hasBeaker;
|
||||
@@ -63,13 +64,13 @@ namespace Content.Shared.Chemistry.Components
|
||||
public class UiActionMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public readonly UiAction action;
|
||||
public readonly ReagentUnit amount;
|
||||
public readonly FixedPoint2 amount;
|
||||
public readonly string id = "";
|
||||
public readonly bool isBuffer;
|
||||
public readonly int pillAmount;
|
||||
public readonly int bottleAmount;
|
||||
|
||||
public UiActionMessage(UiAction _action, ReagentUnit? _amount, string? _id, bool? _isBuffer, int? _pillAmount, int? _bottleAmount)
|
||||
public UiActionMessage(UiAction _action, FixedPoint2? _amount, string? _id, bool? _isBuffer, int? _pillAmount, int? _bottleAmount)
|
||||
{
|
||||
action = _action;
|
||||
if (action == UiAction.ChemButton)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -15,10 +16,10 @@ namespace Content.Shared.Chemistry.Components
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class HyposprayComponentState : ComponentState
|
||||
{
|
||||
public ReagentUnit CurVolume { get; }
|
||||
public ReagentUnit MaxVolume { get; }
|
||||
public FixedPoint2 CurVolume { get; }
|
||||
public FixedPoint2 MaxVolume { get; }
|
||||
|
||||
public HyposprayComponentState(ReagentUnit curVolume, ReagentUnit maxVolume)
|
||||
public HyposprayComponentState(FixedPoint2 curVolume, FixedPoint2 maxVolume)
|
||||
{
|
||||
CurVolume = curVolume;
|
||||
MaxVolume = maxVolume;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -20,11 +21,11 @@ namespace Content.Shared.Chemistry.Components
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class InjectorComponentState : ComponentState
|
||||
{
|
||||
public ReagentUnit CurrentVolume { get; }
|
||||
public ReagentUnit TotalVolume { get; }
|
||||
public FixedPoint2 CurrentVolume { get; }
|
||||
public FixedPoint2 TotalVolume { get; }
|
||||
public InjectorToggleMode CurrentMode { get; }
|
||||
|
||||
public InjectorComponentState(ReagentUnit currentVolume, ReagentUnit totalVolume, InjectorToggleMode currentMode)
|
||||
public InjectorComponentState(FixedPoint2 currentVolume, FixedPoint2 totalVolume, InjectorToggleMode currentMode)
|
||||
{
|
||||
CurrentVolume = currentVolume;
|
||||
TotalVolume = totalVolume;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -18,10 +19,10 @@ namespace Content.Shared.Chemistry.Components
|
||||
/// Volume needed to fill this container.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public ReagentUnit AvailableVolume => MaxVolume - CurrentVolume;
|
||||
public FixedPoint2 AvailableVolume => MaxVolume - CurrentVolume;
|
||||
|
||||
public ReagentUnit DrawAvailable => CurrentVolume;
|
||||
public ReagentUnit DrainAvailable => CurrentVolume;
|
||||
public FixedPoint2 DrawAvailable => CurrentVolume;
|
||||
public FixedPoint2 DrainAvailable => CurrentVolume;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a solution can fit into the container.
|
||||
@@ -34,18 +35,18 @@ namespace Content.Shared.Chemistry.Components
|
||||
}
|
||||
|
||||
[DataField("maxSpillRefill")]
|
||||
public ReagentUnit MaxSpillRefill { get; set; }
|
||||
public FixedPoint2 MaxSpillRefill { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initially set <see cref="MaxVolume"/>. If empty will be calculated based
|
||||
/// on sum of <see cref="Contents"/> reagent units.
|
||||
/// on sum of <see cref="Contents"/> fixed units.
|
||||
/// </summary>
|
||||
[DataField("maxVol")] public ReagentUnit InitialMaxVolume;
|
||||
[DataField("maxVol")] public FixedPoint2 InitialMaxVolume;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ReagentUnit MaxVolume { get; set; } = ReagentUnit.Zero;
|
||||
public FixedPoint2 MaxVolume { get; set; } = FixedPoint2.Zero;
|
||||
|
||||
[ViewVariables]
|
||||
public ReagentUnit CurrentVolume => TotalVolume;
|
||||
public FixedPoint2 CurrentVolume => TotalVolume;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -32,7 +33,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
/// The calculated total volume of all reagents in the solution (ex. Total volume of liquid in beaker).
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public ReagentUnit TotalVolume { get; set; }
|
||||
public FixedPoint2 TotalVolume { get; set; }
|
||||
|
||||
public Color Color => GetColor();
|
||||
|
||||
@@ -46,14 +47,14 @@ namespace Content.Shared.Chemistry.Components
|
||||
/// </summary>
|
||||
/// <param name="reagentId">The prototype ID of the reagent to add.</param>
|
||||
/// <param name="quantity">The quantity in milli-units.</param>
|
||||
public Solution(string reagentId, ReagentUnit quantity)
|
||||
public Solution(string reagentId, FixedPoint2 quantity)
|
||||
{
|
||||
AddReagent(reagentId, quantity);
|
||||
}
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
TotalVolume = ReagentUnit.Zero;
|
||||
TotalVolume = FixedPoint2.Zero;
|
||||
Contents.ForEach(reagent => TotalVolume += reagent.Quantity);
|
||||
}
|
||||
|
||||
@@ -62,7 +63,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
return ContainsReagent(reagentId, out _);
|
||||
}
|
||||
|
||||
public bool ContainsReagent(string reagentId, out ReagentUnit quantity)
|
||||
public bool ContainsReagent(string reagentId, out FixedPoint2 quantity)
|
||||
{
|
||||
foreach (var reagent in Contents)
|
||||
{
|
||||
@@ -73,7 +74,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
}
|
||||
}
|
||||
|
||||
quantity = ReagentUnit.New(0);
|
||||
quantity = FixedPoint2.New(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -93,7 +94,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
/// </summary>
|
||||
/// <param name="reagentId">The prototype ID of the reagent to add.</param>
|
||||
/// <param name="quantity">The quantity in milli-units.</param>
|
||||
public void AddReagent(string reagentId, ReagentUnit quantity)
|
||||
public void AddReagent(string reagentId, FixedPoint2 quantity)
|
||||
{
|
||||
if (quantity <= 0)
|
||||
return;
|
||||
@@ -139,7 +140,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
/// </summary>
|
||||
/// <param name="reagentId">The prototype ID of the reagent to add.</param>
|
||||
/// <returns>The quantity in milli-units.</returns>
|
||||
public ReagentUnit GetReagentQuantity(string reagentId)
|
||||
public FixedPoint2 GetReagentQuantity(string reagentId)
|
||||
{
|
||||
for (var i = 0; i < Contents.Count; i++)
|
||||
{
|
||||
@@ -147,10 +148,10 @@ namespace Content.Shared.Chemistry.Components
|
||||
return Contents[i].Quantity;
|
||||
}
|
||||
|
||||
return ReagentUnit.New(0);
|
||||
return FixedPoint2.New(0);
|
||||
}
|
||||
|
||||
public void RemoveReagent(string reagentId, ReagentUnit quantity)
|
||||
public void RemoveReagent(string reagentId, FixedPoint2 quantity)
|
||||
{
|
||||
if(quantity <= 0)
|
||||
return;
|
||||
@@ -183,7 +184,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
/// Remove the specified quantity from this solution.
|
||||
/// </summary>
|
||||
/// <param name="quantity">The quantity of this solution to remove</param>
|
||||
public void RemoveSolution(ReagentUnit quantity)
|
||||
public void RemoveSolution(FixedPoint2 quantity)
|
||||
{
|
||||
if(quantity <= 0)
|
||||
return;
|
||||
@@ -214,10 +215,10 @@ namespace Content.Shared.Chemistry.Components
|
||||
public void RemoveAllSolution()
|
||||
{
|
||||
Contents.Clear();
|
||||
TotalVolume = ReagentUnit.New(0);
|
||||
TotalVolume = FixedPoint2.New(0);
|
||||
}
|
||||
|
||||
public Solution SplitSolution(ReagentUnit quantity)
|
||||
public Solution SplitSolution(FixedPoint2 quantity)
|
||||
{
|
||||
if (quantity <= 0)
|
||||
return new Solution();
|
||||
@@ -232,7 +233,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
}
|
||||
|
||||
newSolution = new Solution();
|
||||
var newTotalVolume = ReagentUnit.New(0);
|
||||
var newTotalVolume = FixedPoint2.New(0);
|
||||
var remainingVolume = TotalVolume;
|
||||
|
||||
for (var i = 0; i < Contents.Count; i++)
|
||||
@@ -291,7 +292,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
}
|
||||
|
||||
Color mixColor = default;
|
||||
var runningTotalQuantity = ReagentUnit.New(0);
|
||||
var runningTotalQuantity = FixedPoint2.New(0);
|
||||
var protoManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
foreach (var reagent in Contents)
|
||||
@@ -317,7 +318,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
|
||||
public Solution Clone()
|
||||
{
|
||||
var volume = ReagentUnit.New(0);
|
||||
var volume = FixedPoint2.New(0);
|
||||
var newSolution = new Solution();
|
||||
|
||||
for (var i = 0; i < Contents.Count; i++)
|
||||
@@ -348,9 +349,9 @@ namespace Content.Shared.Chemistry.Components
|
||||
[DataField("ReagentId", customTypeSerializer:typeof(PrototypeIdSerializer<ReagentPrototype>))]
|
||||
public readonly string ReagentId;
|
||||
[DataField("Quantity")]
|
||||
public readonly ReagentUnit Quantity;
|
||||
public readonly FixedPoint2 Quantity;
|
||||
|
||||
public ReagentQuantity(string reagentId, ReagentUnit quantity)
|
||||
public ReagentQuantity(string reagentId, FixedPoint2 quantity)
|
||||
{
|
||||
ReagentId = reagentId;
|
||||
Quantity = quantity;
|
||||
@@ -364,7 +365,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
|
||||
public int CompareTo(ReagentQuantity other) { return Quantity.Float().CompareTo(other.Quantity.Float()); }
|
||||
|
||||
public void Deconstruct(out string reagentId, out ReagentUnit quantity)
|
||||
public void Deconstruct(out string reagentId, out FixedPoint2 quantity)
|
||||
{
|
||||
reagentId = ReagentId;
|
||||
quantity = Quantity;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -26,8 +27,8 @@ namespace Content.Shared.Chemistry.Dispenser
|
||||
{
|
||||
public readonly bool HasPower;
|
||||
public readonly bool HasBeaker;
|
||||
public readonly ReagentUnit BeakerCurrentVolume;
|
||||
public readonly ReagentUnit BeakerMaxVolume;
|
||||
public readonly FixedPoint2 BeakerCurrentVolume;
|
||||
public readonly FixedPoint2 BeakerMaxVolume;
|
||||
public readonly string ContainerName;
|
||||
/// <summary>
|
||||
/// A list of the reagents which this dispenser can dispense.
|
||||
@@ -38,10 +39,10 @@ namespace Content.Shared.Chemistry.Dispenser
|
||||
/// </summary>
|
||||
public readonly List<Components.Solution.ReagentQuantity>? ContainerReagents;
|
||||
public readonly string DispenserName;
|
||||
public readonly ReagentUnit SelectedDispenseAmount;
|
||||
public readonly FixedPoint2 SelectedDispenseAmount;
|
||||
|
||||
public ReagentDispenserBoundUserInterfaceState(bool hasPower, bool hasBeaker, ReagentUnit beakerCurrentVolume, ReagentUnit beakerMaxVolume, string containerName,
|
||||
List<ReagentDispenserInventoryEntry> inventory, string dispenserName, List<Components.Solution.ReagentQuantity>? containerReagents, ReagentUnit selectedDispenseAmount)
|
||||
public ReagentDispenserBoundUserInterfaceState(bool hasPower, bool hasBeaker, FixedPoint2 beakerCurrentVolume, FixedPoint2 beakerMaxVolume, string containerName,
|
||||
List<ReagentDispenserInventoryEntry> inventory, string dispenserName, List<Components.Solution.ReagentQuantity>? containerReagents, FixedPoint2 selectedDispenseAmount)
|
||||
{
|
||||
HasPower = hasPower;
|
||||
HasBeaker = hasBeaker;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Shared.Chemistry.Reaction
|
||||
{
|
||||
public interface ITileReaction
|
||||
{
|
||||
ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume);
|
||||
FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -14,7 +15,7 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
public class ReactionPrototype : IPrototype
|
||||
{
|
||||
[DataField("reactants")] private Dictionary<string, ReactantPrototype> _reactants = new();
|
||||
[DataField("products")] private Dictionary<string, ReagentUnit> _products = new();
|
||||
[DataField("products")] private Dictionary<string, FixedPoint2> _products = new();
|
||||
[DataField("effects", serverOnly: true)] private List<IReactionEffect> _effects = new();
|
||||
|
||||
[ViewVariables]
|
||||
@@ -31,7 +32,7 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
/// <summary>
|
||||
/// Reagents created when the reaction occurs.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, ReagentUnit> Products => _products;
|
||||
public IReadOnlyDictionary<string, FixedPoint2> Products => _products;
|
||||
/// <summary>
|
||||
/// Effects to be triggered when the reaction occurs.
|
||||
/// </summary>
|
||||
@@ -48,14 +49,14 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
public class ReactantPrototype
|
||||
{
|
||||
[DataField("amount")]
|
||||
private ReagentUnit _amount = ReagentUnit.New(1);
|
||||
private FixedPoint2 _amount = FixedPoint2.New(1);
|
||||
[DataField("catalyst")]
|
||||
private bool _catalyst;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum amount of the reactant needed for the reaction to occur.
|
||||
/// </summary>
|
||||
public ReagentUnit Amount => _amount;
|
||||
public FixedPoint2 Amount => _amount;
|
||||
/// <summary>
|
||||
/// Whether or not the reactant is a catalyst. Catalysts aren't removed when a reaction occurs.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
@@ -29,9 +30,9 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
/// <param name="reaction">The reaction to check.</param>
|
||||
/// <param name="lowestUnitReactions">How many times this reaction can occur.</param>
|
||||
/// <returns></returns>
|
||||
private static bool CanReact(Solution solution, ReactionPrototype reaction, out ReagentUnit lowestUnitReactions)
|
||||
private static bool CanReact(Solution solution, ReactionPrototype reaction, out FixedPoint2 lowestUnitReactions)
|
||||
{
|
||||
lowestUnitReactions = ReagentUnit.MaxValue;
|
||||
lowestUnitReactions = FixedPoint2.MaxValue;
|
||||
|
||||
foreach (var reactantData in reaction.Reactants)
|
||||
{
|
||||
@@ -55,7 +56,7 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
/// Perform a reaction on a solution. This assumes all reaction criteria are met.
|
||||
/// Removes the reactants from the solution, then returns a solution with all products.
|
||||
/// </summary>
|
||||
private Solution PerformReaction(Solution solution, IEntity owner, ReactionPrototype reaction, ReagentUnit unitReactions)
|
||||
private Solution PerformReaction(Solution solution, IEntity owner, ReactionPrototype reaction, FixedPoint2 unitReactions)
|
||||
{
|
||||
//Remove reactants
|
||||
foreach (var reactant in reaction.Reactants)
|
||||
@@ -80,7 +81,7 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
return products;
|
||||
}
|
||||
|
||||
protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, ReagentUnit unitReactions)
|
||||
protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, FixedPoint2 unitReactions)
|
||||
{
|
||||
foreach (var effect in reaction.Effects)
|
||||
{
|
||||
@@ -130,7 +131,7 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
/// Continually react a solution until no more reactions occur, with a volume constraint.
|
||||
/// If a reaction's products would exceed the max volume, some product is deleted.
|
||||
/// </summary>
|
||||
public void FullyReactSolution(Solution solution, IEntity owner, ReagentUnit maxVolume)
|
||||
public void FullyReactSolution(Solution solution, IEntity owner, FixedPoint2 maxVolume)
|
||||
{
|
||||
for (var i = 0; i < MaxReactionIterations; i++)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -27,7 +28,7 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
[DataField("ingestion")]
|
||||
public bool Ingestion { get; } = false;
|
||||
|
||||
public void React(ReactionMethod method, IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Components.Solution? source)
|
||||
public void React(ReactionMethod method, IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Components.Solution? source)
|
||||
{
|
||||
switch (method)
|
||||
{
|
||||
@@ -50,6 +51,6 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
React(entity, reagent, volume, source);
|
||||
}
|
||||
|
||||
protected abstract void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Components.Solution? source);
|
||||
protected abstract void React(IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Components.Solution? source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Botany;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -77,9 +78,9 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
return SubstanceColor;
|
||||
}
|
||||
|
||||
public ReagentUnit ReactionTile(TileRef tile, ReagentUnit reactVolume)
|
||||
public FixedPoint2 ReactionTile(TileRef tile, FixedPoint2 reactVolume)
|
||||
{
|
||||
var removed = ReagentUnit.Zero;
|
||||
var removed = FixedPoint2.Zero;
|
||||
|
||||
if (tile.Tile.IsEmpty)
|
||||
return removed;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -8,10 +9,10 @@ namespace Content.Shared.Chemistry
|
||||
[Serializable, NetSerializable]
|
||||
public class TransferAmountBoundInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public ReagentUnit Max;
|
||||
public ReagentUnit Min;
|
||||
public FixedPoint2 Max;
|
||||
public FixedPoint2 Min;
|
||||
|
||||
public TransferAmountBoundInterfaceState(ReagentUnit max, ReagentUnit min)
|
||||
public TransferAmountBoundInterfaceState(FixedPoint2 max, FixedPoint2 min)
|
||||
{
|
||||
Max = max;
|
||||
Min = min;
|
||||
@@ -21,9 +22,9 @@ namespace Content.Shared.Chemistry
|
||||
[Serializable, NetSerializable]
|
||||
public class TransferAmountSetValueMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public ReagentUnit Value;
|
||||
public FixedPoint2 Value;
|
||||
|
||||
public TransferAmountSetValueMessage(ReagentUnit value)
|
||||
public TransferAmountSetValueMessage(FixedPoint2 value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
@@ -9,12 +9,10 @@ using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.FixedPoint;
|
||||
|
||||
namespace Content.Shared.Damage
|
||||
{
|
||||
// TODO DAMAGE UNITS Move this whole class away from, using integers. Also get rid of a lot of the rounding. Just
|
||||
// use DamageUnit math operators.
|
||||
|
||||
/// <summary>
|
||||
/// This class represents a collection of damage types and damage values.
|
||||
/// </summary>
|
||||
@@ -25,17 +23,17 @@ namespace Content.Shared.Damage
|
||||
[DataDefinition]
|
||||
public class DamageSpecifier
|
||||
{
|
||||
[DataField("types", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<int, DamageTypePrototype>))]
|
||||
private readonly Dictionary<string,int>? _damageTypeDictionary;
|
||||
[DataField("types", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<FixedPoint2, DamageTypePrototype>))]
|
||||
private readonly Dictionary<string,FixedPoint2>? _damageTypeDictionary;
|
||||
|
||||
[DataField("groups", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<int, DamageGroupPrototype>))]
|
||||
private readonly Dictionary<string, int>? _damageGroupDictionary;
|
||||
[DataField("groups", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<FixedPoint2, DamageGroupPrototype>))]
|
||||
private readonly Dictionary<string, FixedPoint2>? _damageGroupDictionary;
|
||||
|
||||
/// <summary>
|
||||
/// Main DamageSpecifier dictionary. Most DamageSpecifier functions exist to somehow modifying this.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Dictionary<string, int> DamageDict
|
||||
public Dictionary<string, FixedPoint2> DamageDict
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -45,7 +43,7 @@ namespace Content.Shared.Damage
|
||||
}
|
||||
set => _damageDict = value;
|
||||
}
|
||||
private Dictionary<string, int>? _damageDict;
|
||||
private Dictionary<string, FixedPoint2>? _damageDict;
|
||||
|
||||
/// <summary>
|
||||
/// Sum of the damage values.
|
||||
@@ -55,7 +53,7 @@ namespace Content.Shared.Damage
|
||||
/// in another. For this purpose, you should instead use <see cref="TrimZeros()"/> and then check the <see
|
||||
/// cref="Empty"/> property.
|
||||
/// </remarks>
|
||||
public int Total => DamageDict.Values.Sum();
|
||||
public FixedPoint2 Total => DamageDict.Values.Sum();
|
||||
|
||||
/// <summary>
|
||||
/// Whether this damage specifier has any entries.
|
||||
@@ -79,7 +77,7 @@ namespace Content.Shared.Damage
|
||||
/// <summary>
|
||||
/// Constructor that takes a single damage type prototype and a damage value.
|
||||
/// </summary>
|
||||
public DamageSpecifier(DamageTypePrototype type, int value)
|
||||
public DamageSpecifier(DamageTypePrototype type, FixedPoint2 value)
|
||||
{
|
||||
DamageDict = new() { { type.ID, value } };
|
||||
}
|
||||
@@ -87,14 +85,14 @@ namespace Content.Shared.Damage
|
||||
/// <summary>
|
||||
/// Constructor that takes a single damage group prototype and a damage value. The value is divided between members of the damage group.
|
||||
/// </summary>
|
||||
public DamageSpecifier(DamageGroupPrototype group, int value)
|
||||
public DamageSpecifier(DamageGroupPrototype group, FixedPoint2 value)
|
||||
{
|
||||
_damageGroupDictionary = new() { { group.ID, value } };
|
||||
}
|
||||
#endregion constructors
|
||||
|
||||
/// <summary>
|
||||
/// Combines the damage group and type datafield dictionaries into a single damage dictionary.
|
||||
/// Combines the damage group and type datafield dictionaries FixedPoint2o a single damage dictionary.
|
||||
/// </summary>
|
||||
public void DeserializeDamage()
|
||||
{
|
||||
@@ -128,7 +126,7 @@ namespace Content.Shared.Damage
|
||||
var remainingDamage = entry.Value;
|
||||
foreach (var damageType in group.DamageTypes)
|
||||
{
|
||||
var damage = remainingDamage / remainingTypes;
|
||||
var damage = remainingDamage / FixedPoint2.New(remainingTypes);
|
||||
if (!_damageDict.TryAdd(damageType, damage))
|
||||
{
|
||||
// Key already exists, add values
|
||||
@@ -149,7 +147,7 @@ namespace Content.Shared.Damage
|
||||
public static DamageSpecifier ApplyModifierSet(DamageSpecifier damageSpec, DamageModifierSet modifierSet)
|
||||
{
|
||||
// Make a copy of the given data. Don't modify the one passed to this function. I did this before, and weapons became
|
||||
// duller as you hit walls. Neat, but not intended. And confusing, when you realize your fists don't work no
|
||||
// duller as you hit walls. Neat, but not FixedPoint2ended. And confusing, when you realize your fists don't work no
|
||||
// more cause they're just bloody stumps.
|
||||
DamageSpecifier newDamage = new(damageSpec);
|
||||
|
||||
@@ -157,7 +155,7 @@ namespace Content.Shared.Damage
|
||||
{
|
||||
if (entry.Value <= 0) continue;
|
||||
|
||||
float newValue = entry.Value;
|
||||
float newValue = entry.Value.Float();
|
||||
|
||||
if (modifierSet.FlatReduction.TryGetValue(entry.Key, out var reduction))
|
||||
{
|
||||
@@ -165,7 +163,7 @@ namespace Content.Shared.Damage
|
||||
if (newValue <= 0)
|
||||
{
|
||||
// flat reductions cannot heal you
|
||||
newDamage.DamageDict[entry.Key] = 0;
|
||||
newDamage.DamageDict[entry.Key] = FixedPoint2.Zero;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -173,10 +171,10 @@ namespace Content.Shared.Damage
|
||||
if (modifierSet.Coefficients.TryGetValue(entry.Key, out var coefficient))
|
||||
{
|
||||
// negative coefficients **can** heal you.
|
||||
newValue = MathF.Round(newValue*coefficient, MidpointRounding.AwayFromZero);
|
||||
newValue = newValue * coefficient;
|
||||
}
|
||||
|
||||
newDamage.DamageDict[entry.Key] = (int) newValue;
|
||||
newDamage.DamageDict[entry.Key] = FixedPoint2.New(newValue);
|
||||
}
|
||||
|
||||
newDamage.TrimZeros();
|
||||
@@ -218,7 +216,7 @@ namespace Content.Shared.Damage
|
||||
/// <summary>
|
||||
/// Clamps each damage value to be within the given range.
|
||||
/// </summary>
|
||||
public void Clamp(int minValue = 0, int maxValue = 0)
|
||||
public void Clamp(FixedPoint2 minValue, FixedPoint2 maxValue)
|
||||
{
|
||||
DebugTools.Assert(minValue < maxValue);
|
||||
ClampMax(maxValue);
|
||||
@@ -231,7 +229,7 @@ namespace Content.Shared.Damage
|
||||
/// <remarks>
|
||||
/// Note that this only acts on damage types present in the dictionary. It will not add new damage types.
|
||||
/// </remarks>
|
||||
public void ClampMin(int minValue = 0)
|
||||
public void ClampMin(FixedPoint2 minValue)
|
||||
{
|
||||
foreach (var (key, value) in DamageDict)
|
||||
{
|
||||
@@ -246,7 +244,7 @@ namespace Content.Shared.Damage
|
||||
/// Sets all damage values to be at most some number. Note that if a damage type is not present in the
|
||||
/// dictionary, these will not be added.
|
||||
/// </summary>
|
||||
public void ClampMax(int maxValue = 0)
|
||||
public void ClampMax(FixedPoint2 maxValue)
|
||||
{
|
||||
foreach (var (key, value) in DamageDict)
|
||||
{
|
||||
@@ -282,10 +280,10 @@ namespace Content.Shared.Damage
|
||||
/// <remarks>
|
||||
/// If no members of the group are included in this specifier, returns false.
|
||||
/// </remarks>
|
||||
public bool TryGetDamageInGroup(DamageGroupPrototype group, out int total)
|
||||
public bool TryGetDamageInGroup(DamageGroupPrototype group, out FixedPoint2 total)
|
||||
{
|
||||
bool containsMemeber = false;
|
||||
total = 0;
|
||||
total = FixedPoint2.Zero;
|
||||
|
||||
foreach (var type in group.DamageTypes)
|
||||
{
|
||||
@@ -307,9 +305,9 @@ namespace Content.Shared.Damage
|
||||
/// total of each group. If no members of a group are present in this <see cref="DamageSpecifier"/>, the
|
||||
/// group is not included in the resulting dictionary.
|
||||
/// </remarks>
|
||||
public Dictionary<string, int> GetDamagePerGroup()
|
||||
public Dictionary<string, FixedPoint2> GetDamagePerGroup()
|
||||
{
|
||||
var damageGroupDict = new Dictionary<string, int>();
|
||||
var damageGroupDict = new Dictionary<string, FixedPoint2>();
|
||||
foreach (var group in IoCManager.Resolve<IPrototypeManager>().EnumeratePrototypes<DamageGroupPrototype>())
|
||||
{
|
||||
if (TryGetDamageInGroup(group, out var value))
|
||||
@@ -321,7 +319,7 @@ namespace Content.Shared.Damage
|
||||
}
|
||||
|
||||
#region Operators
|
||||
public static DamageSpecifier operator *(DamageSpecifier damageSpec, int factor)
|
||||
public static DamageSpecifier operator *(DamageSpecifier damageSpec, FixedPoint2 factor)
|
||||
{
|
||||
DamageSpecifier newDamage = new();
|
||||
foreach (var entry in damageSpec.DamageDict)
|
||||
@@ -336,17 +334,17 @@ namespace Content.Shared.Damage
|
||||
DamageSpecifier newDamage = new();
|
||||
foreach (var entry in damageSpec.DamageDict)
|
||||
{
|
||||
newDamage.DamageDict.Add(entry.Key, (int) MathF.Round(entry.Value * factor, MidpointRounding.AwayFromZero));
|
||||
newDamage.DamageDict.Add(entry.Key, entry.Value * factor);
|
||||
}
|
||||
return newDamage;
|
||||
}
|
||||
|
||||
public static DamageSpecifier operator /(DamageSpecifier damageSpec, int factor)
|
||||
public static DamageSpecifier operator /(DamageSpecifier damageSpec, FixedPoint2 factor)
|
||||
{
|
||||
DamageSpecifier newDamage = new();
|
||||
foreach (var entry in damageSpec.DamageDict)
|
||||
{
|
||||
newDamage.DamageDict.Add(entry.Key, (int) MathF.Round(entry.Value / (float) factor, MidpointRounding.AwayFromZero));
|
||||
newDamage.DamageDict.Add(entry.Key, entry.Value / factor);
|
||||
}
|
||||
return newDamage;
|
||||
}
|
||||
@@ -357,7 +355,7 @@ namespace Content.Shared.Damage
|
||||
|
||||
foreach (var entry in damageSpec.DamageDict)
|
||||
{
|
||||
newDamage.DamageDict.Add(entry.Key, (int) MathF.Round(entry.Value / factor, MidpointRounding.AwayFromZero));
|
||||
newDamage.DamageDict.Add(entry.Key, entry.Value / factor);
|
||||
}
|
||||
return newDamage;
|
||||
}
|
||||
@@ -387,7 +385,7 @@ namespace Content.Shared.Damage
|
||||
|
||||
public static DamageSpecifier operator *(float factor, DamageSpecifier damageSpec) => damageSpec * factor;
|
||||
|
||||
public static DamageSpecifier operator *(int factor, DamageSpecifier damageSpec) => damageSpec * factor;
|
||||
public static DamageSpecifier operator *(FixedPoint2 factor, DamageSpecifier damageSpec) => damageSpec * factor;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Radiation;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -64,12 +65,12 @@ namespace Content.Shared.Damage
|
||||
/// Groups which have no members that are supported by this component will not be present in this
|
||||
/// dictionary.
|
||||
/// </remarks>
|
||||
[ViewVariables] public Dictionary<string, int> DamagePerGroup = new();
|
||||
[ViewVariables] public Dictionary<string, FixedPoint2> DamagePerGroup = new();
|
||||
|
||||
/// <summary>
|
||||
/// The sum of all damages in the DamageableComponent.
|
||||
/// </summary>
|
||||
[ViewVariables] public int TotalDamage;
|
||||
[ViewVariables] public FixedPoint2 TotalDamage;
|
||||
|
||||
// Really these shouldn't be here. OnExplosion() and RadiationAct() should be handled elsewhere.
|
||||
[ViewVariables]
|
||||
@@ -82,7 +83,7 @@ namespace Content.Shared.Damage
|
||||
// TODO RADIATION Remove this.
|
||||
void IRadiationAct.RadiationAct(float frameTime, SharedRadiationPulseComponent radiation)
|
||||
{
|
||||
var damageValue = Math.Max((int) (frameTime * radiation.RadsPerSecond), 1);
|
||||
var damageValue = FixedPoint2.New(MathF.Max((frameTime * radiation.RadsPerSecond), 1));
|
||||
|
||||
// Radiation should really just be a damage group instead of a list of types.
|
||||
DamageSpecifier damage = new();
|
||||
@@ -99,9 +100,9 @@ namespace Content.Shared.Damage
|
||||
{
|
||||
var damageValue = eventArgs.Severity switch
|
||||
{
|
||||
ExplosionSeverity.Light => 20,
|
||||
ExplosionSeverity.Heavy => 60,
|
||||
ExplosionSeverity.Destruction => 250,
|
||||
ExplosionSeverity.Light => FixedPoint2.New(20),
|
||||
ExplosionSeverity.Heavy => FixedPoint2.New(60),
|
||||
ExplosionSeverity.Destruction => FixedPoint2.New(250),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
@@ -119,11 +120,11 @@ namespace Content.Shared.Damage
|
||||
[Serializable, NetSerializable]
|
||||
public class DamageableComponentState : ComponentState
|
||||
{
|
||||
public readonly Dictionary<string, int> DamageDict;
|
||||
public readonly Dictionary<string, FixedPoint2> DamageDict;
|
||||
public readonly string? ModifierSetId;
|
||||
|
||||
public DamageableComponentState(
|
||||
Dictionary<string, int> damageDict,
|
||||
Dictionary<string, FixedPoint2> damageDict,
|
||||
string? modifierSetId)
|
||||
{
|
||||
DamageDict = damageDict;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -33,7 +34,7 @@ namespace Content.Shared.Damage
|
||||
// container prototype
|
||||
foreach (var type in damageContainerPrototype.SupportedTypes)
|
||||
{
|
||||
component.Damage.DamageDict.TryAdd(type, 0);
|
||||
component.Damage.DamageDict.TryAdd(type, FixedPoint2.Zero);
|
||||
}
|
||||
|
||||
foreach (var groupID in damageContainerPrototype.SupportedGroups)
|
||||
@@ -41,7 +42,7 @@ namespace Content.Shared.Damage
|
||||
var group = _prototypeManager.Index<DamageGroupPrototype>(groupID);
|
||||
foreach (var type in group.DamageTypes)
|
||||
{
|
||||
component.Damage.DamageDict.TryAdd(type, 0);
|
||||
component.Damage.DamageDict.TryAdd(type, FixedPoint2.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +51,7 @@ namespace Content.Shared.Damage
|
||||
// No DamageContainerPrototype was given. So we will allow the container to support all damage types
|
||||
foreach (var type in _prototypeManager.EnumeratePrototypes<DamageTypePrototype>())
|
||||
{
|
||||
component.Damage.DamageDict.TryAdd(type.ID, 0);
|
||||
component.Damage.DamageDict.TryAdd(type.ID, FixedPoint2.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +144,7 @@ namespace Content.Shared.Damage
|
||||
DamageSpecifier oldDamage = new(damageable.Damage);
|
||||
|
||||
damageable.Damage.ExclusiveAdd(damage);
|
||||
damageable.Damage.ClampMin(0);
|
||||
damageable.Damage.ClampMin(FixedPoint2.Zero);
|
||||
|
||||
var delta = damageable.Damage - oldDamage;
|
||||
delta.TrimZeros();
|
||||
@@ -162,7 +163,7 @@ namespace Content.Shared.Damage
|
||||
/// <remakrs>
|
||||
/// Does nothing If the given damage value is negative.
|
||||
/// </remakrs>
|
||||
public void SetAllDamage(DamageableComponent component, int newValue)
|
||||
public void SetAllDamage(DamageableComponent component, FixedPoint2 newValue)
|
||||
{
|
||||
if (newValue < 0)
|
||||
{
|
||||
|
||||
@@ -1,40 +1,42 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Chemistry.Reagent
|
||||
namespace Content.Shared.FixedPoint
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a quantity of reagent, to a precision of 0.01.
|
||||
/// Represents a quantity of something, to a precision of 0.01.
|
||||
/// To enforce this level of precision, floats are shifted by 2 decimal points, rounded, and converted to an int.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct ReagentUnit : ISelfSerialize, IComparable<ReagentUnit>, IEquatable<ReagentUnit>
|
||||
public struct FixedPoint2 : ISelfSerialize, IComparable<FixedPoint2>, IEquatable<FixedPoint2>
|
||||
{
|
||||
private int _value;
|
||||
private static readonly int Shift = 2;
|
||||
|
||||
public static ReagentUnit MaxValue { get; } = new(int.MaxValue);
|
||||
public static ReagentUnit Epsilon { get; } = new(1);
|
||||
public static ReagentUnit Zero { get; } = new(0);
|
||||
public static FixedPoint2 MaxValue { get; } = new(int.MaxValue);
|
||||
public static FixedPoint2 Epsilon { get; } = new(1);
|
||||
public static FixedPoint2 Zero { get; } = new(0);
|
||||
|
||||
private readonly double ShiftDown()
|
||||
{
|
||||
return _value / Math.Pow(10, Shift);
|
||||
}
|
||||
|
||||
private ReagentUnit(int value)
|
||||
private FixedPoint2(int value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public static ReagentUnit New(int value)
|
||||
public static FixedPoint2 New(int value)
|
||||
{
|
||||
return new(value * (int) Math.Pow(10, Shift));
|
||||
}
|
||||
|
||||
public static ReagentUnit New(float value)
|
||||
public static FixedPoint2 New(float value)
|
||||
{
|
||||
return new(FromFloat(value));
|
||||
}
|
||||
@@ -44,12 +46,12 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
return (int) MathF.Round(value * MathF.Pow(10, Shift), MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
public static ReagentUnit New(double value)
|
||||
public static FixedPoint2 New(double value)
|
||||
{
|
||||
return new((int) Math.Round(value * Math.Pow(10, Shift), MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
public static ReagentUnit New(string value)
|
||||
public static FixedPoint2 New(string value)
|
||||
{
|
||||
return New(FloatFromString(value));
|
||||
}
|
||||
@@ -59,41 +61,41 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
return float.Parse(value, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static ReagentUnit operator +(ReagentUnit a) => a;
|
||||
public static FixedPoint2 operator +(FixedPoint2 a) => a;
|
||||
|
||||
public static ReagentUnit operator -(ReagentUnit a) => new(-a._value);
|
||||
public static FixedPoint2 operator -(FixedPoint2 a) => new(-a._value);
|
||||
|
||||
public static ReagentUnit operator +(ReagentUnit a, ReagentUnit b)
|
||||
public static FixedPoint2 operator +(FixedPoint2 a, FixedPoint2 b)
|
||||
=> new(a._value + b._value);
|
||||
|
||||
public static ReagentUnit operator -(ReagentUnit a, ReagentUnit b)
|
||||
public static FixedPoint2 operator -(FixedPoint2 a, FixedPoint2 b)
|
||||
=> a + -b;
|
||||
|
||||
public static ReagentUnit operator *(ReagentUnit a, ReagentUnit b)
|
||||
public static FixedPoint2 operator *(FixedPoint2 a, FixedPoint2 b)
|
||||
{
|
||||
var aD = a.ShiftDown();
|
||||
var bD = b.ShiftDown();
|
||||
return New(aD * bD);
|
||||
}
|
||||
|
||||
public static ReagentUnit operator *(ReagentUnit a, float b)
|
||||
public static FixedPoint2 operator *(FixedPoint2 a, float b)
|
||||
{
|
||||
var aD = (float) a.ShiftDown();
|
||||
return New(aD * b);
|
||||
}
|
||||
|
||||
public static ReagentUnit operator *(ReagentUnit a, double b)
|
||||
public static FixedPoint2 operator *(FixedPoint2 a, double b)
|
||||
{
|
||||
var aD = a.ShiftDown();
|
||||
return New(aD * b);
|
||||
}
|
||||
|
||||
public static ReagentUnit operator *(ReagentUnit a, int b)
|
||||
public static FixedPoint2 operator *(FixedPoint2 a, int b)
|
||||
{
|
||||
return new(a._value * b);
|
||||
}
|
||||
|
||||
public static ReagentUnit operator /(ReagentUnit a, ReagentUnit b)
|
||||
public static FixedPoint2 operator /(FixedPoint2 a, FixedPoint2 b)
|
||||
{
|
||||
if (b._value == 0)
|
||||
{
|
||||
@@ -104,62 +106,67 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
return New(aD / bD);
|
||||
}
|
||||
|
||||
public static bool operator <=(ReagentUnit a, int b)
|
||||
public static FixedPoint2 operator /(FixedPoint2 a, float b)
|
||||
{
|
||||
return a / FixedPoint2.New(b);
|
||||
}
|
||||
|
||||
public static bool operator <=(FixedPoint2 a, int b)
|
||||
{
|
||||
return a <= New(b);
|
||||
}
|
||||
|
||||
public static bool operator >=(ReagentUnit a, int b)
|
||||
public static bool operator >=(FixedPoint2 a, int b)
|
||||
{
|
||||
return a >= New(b);
|
||||
}
|
||||
|
||||
public static bool operator <(ReagentUnit a, int b)
|
||||
public static bool operator <(FixedPoint2 a, int b)
|
||||
{
|
||||
return a < New(b);
|
||||
}
|
||||
|
||||
public static bool operator >(ReagentUnit a, int b)
|
||||
public static bool operator >(FixedPoint2 a, int b)
|
||||
{
|
||||
return a > New(b);
|
||||
}
|
||||
|
||||
public static bool operator ==(ReagentUnit a, int b)
|
||||
public static bool operator ==(FixedPoint2 a, int b)
|
||||
{
|
||||
return a == New(b);
|
||||
}
|
||||
|
||||
public static bool operator !=(ReagentUnit a, int b)
|
||||
public static bool operator !=(FixedPoint2 a, int b)
|
||||
{
|
||||
return a != New(b);
|
||||
}
|
||||
|
||||
public static bool operator ==(ReagentUnit a, ReagentUnit b)
|
||||
public static bool operator ==(FixedPoint2 a, FixedPoint2 b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator !=(ReagentUnit a, ReagentUnit b)
|
||||
public static bool operator !=(FixedPoint2 a, FixedPoint2 b)
|
||||
{
|
||||
return !a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator <=(ReagentUnit a, ReagentUnit b)
|
||||
public static bool operator <=(FixedPoint2 a, FixedPoint2 b)
|
||||
{
|
||||
return a._value <= b._value;
|
||||
}
|
||||
|
||||
public static bool operator >=(ReagentUnit a, ReagentUnit b)
|
||||
public static bool operator >=(FixedPoint2 a, FixedPoint2 b)
|
||||
{
|
||||
return a._value >= b._value;
|
||||
}
|
||||
|
||||
public static bool operator <(ReagentUnit a, ReagentUnit b)
|
||||
public static bool operator <(FixedPoint2 a, FixedPoint2 b)
|
||||
{
|
||||
return a._value < b._value;
|
||||
}
|
||||
|
||||
public static bool operator >(ReagentUnit a, ReagentUnit b)
|
||||
public static bool operator >(FixedPoint2 a, FixedPoint2 b)
|
||||
{
|
||||
return a._value > b._value;
|
||||
}
|
||||
@@ -179,22 +186,31 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
return (int) ShiftDown();
|
||||
}
|
||||
|
||||
public static ReagentUnit Min(params ReagentUnit[] reagentUnits)
|
||||
// Implicit operators ftw
|
||||
public static implicit operator FixedPoint2(float n) => FixedPoint2.New(n);
|
||||
public static implicit operator FixedPoint2(double n) => FixedPoint2.New(n);
|
||||
public static implicit operator FixedPoint2(int n) => FixedPoint2.New(n);
|
||||
|
||||
public static explicit operator float(FixedPoint2 n) => n.Float();
|
||||
public static explicit operator double(FixedPoint2 n) => n.Double();
|
||||
public static explicit operator int(FixedPoint2 n) => n.Int();
|
||||
|
||||
public static FixedPoint2 Min(params FixedPoint2[] fixedPoints)
|
||||
{
|
||||
return reagentUnits.Min();
|
||||
return fixedPoints.Min();
|
||||
}
|
||||
|
||||
public static ReagentUnit Min(ReagentUnit a, ReagentUnit b)
|
||||
public static FixedPoint2 Min(FixedPoint2 a, FixedPoint2 b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
public static ReagentUnit Max(ReagentUnit a, ReagentUnit b)
|
||||
public static FixedPoint2 Max(FixedPoint2 a, FixedPoint2 b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
public static ReagentUnit Clamp(ReagentUnit reagent, ReagentUnit min, ReagentUnit max)
|
||||
public static FixedPoint2 Clamp(FixedPoint2 reagent, FixedPoint2 min, FixedPoint2 max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
@@ -206,7 +222,7 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
|
||||
public override readonly bool Equals(object? obj)
|
||||
{
|
||||
return obj is ReagentUnit unit &&
|
||||
return obj is FixedPoint2 unit &&
|
||||
_value == unit._value;
|
||||
}
|
||||
|
||||
@@ -228,12 +244,12 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
return ToString();
|
||||
}
|
||||
|
||||
public readonly bool Equals(ReagentUnit other)
|
||||
public readonly bool Equals(FixedPoint2 other)
|
||||
{
|
||||
return _value == other._value;
|
||||
}
|
||||
|
||||
public readonly int CompareTo(ReagentUnit other)
|
||||
public readonly int CompareTo(FixedPoint2 other)
|
||||
{
|
||||
if(other._value > _value)
|
||||
{
|
||||
@@ -245,5 +261,21 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class FixedPointEnumerableExt
|
||||
{
|
||||
public static FixedPoint2 Sum(this System.Collections.Generic.IEnumerable<FixedPoint2> source)
|
||||
{
|
||||
var acc = FixedPoint2.Zero;
|
||||
|
||||
foreach (var n in source)
|
||||
{
|
||||
acc += n;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -16,8 +17,8 @@ namespace Content.Shared.MedicalScanner
|
||||
public class MedicalScannerBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public readonly EntityUid? Entity;
|
||||
public readonly IReadOnlyDictionary<string, int> DamagePerGroup;
|
||||
public readonly IReadOnlyDictionary<string, int> DamagePerType;
|
||||
public readonly IReadOnlyDictionary<string, FixedPoint2> DamagePerGroup;
|
||||
public readonly IReadOnlyDictionary<string, FixedPoint2> DamagePerType;
|
||||
public readonly bool IsScanned;
|
||||
|
||||
public MedicalScannerBoundUserInterfaceState(
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.MobState.State;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
@@ -43,7 +44,7 @@ namespace Content.Shared.MobState.Components
|
||||
public IMobState? CurrentState { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public int? CurrentThreshold { get; private set; }
|
||||
public FixedPoint2? CurrentThreshold { get; private set; }
|
||||
|
||||
public IEnumerable<KeyValuePair<int, IMobState>> _highestToLowestStates => _lowestToHighestStates.Reverse();
|
||||
|
||||
@@ -59,7 +60,7 @@ namespace Content.Shared.MobState.Components
|
||||
else
|
||||
{
|
||||
// Initialize with some amount of damage, defaulting to 0.
|
||||
UpdateState(Owner.GetComponentOrNull<DamageableComponent>()?.TotalDamage ?? 0);
|
||||
UpdateState(Owner.GetComponentOrNull<DamageableComponent>()?.TotalDamage ?? FixedPoint2.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +123,7 @@ namespace Content.Shared.MobState.Components
|
||||
return CurrentState?.IsIncapacitated() ?? false;
|
||||
}
|
||||
|
||||
public (IMobState state, int threshold)? GetState(int damage)
|
||||
public (IMobState state, FixedPoint2 threshold)? GetState(FixedPoint2 damage)
|
||||
{
|
||||
foreach (var (threshold, state) in _highestToLowestStates)
|
||||
{
|
||||
@@ -136,9 +137,9 @@ namespace Content.Shared.MobState.Components
|
||||
}
|
||||
|
||||
public bool TryGetState(
|
||||
int damage,
|
||||
FixedPoint2 damage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold)
|
||||
out FixedPoint2 threshold)
|
||||
{
|
||||
var highestState = GetState(damage);
|
||||
|
||||
@@ -153,7 +154,7 @@ namespace Content.Shared.MobState.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
private (IMobState state, int threshold)? GetEarliestState(int minimumDamage, Predicate<IMobState> predicate)
|
||||
private (IMobState state, FixedPoint2 threshold)? GetEarliestState(FixedPoint2 minimumDamage, Predicate<IMobState> predicate)
|
||||
{
|
||||
foreach (var (threshold, state) in _lowestToHighestStates)
|
||||
{
|
||||
@@ -169,7 +170,7 @@ namespace Content.Shared.MobState.Components
|
||||
return null;
|
||||
}
|
||||
|
||||
private (IMobState state, int threshold)? GetPreviousState(int maximumDamage, Predicate<IMobState> predicate)
|
||||
private (IMobState state, FixedPoint2 threshold)? GetPreviousState(FixedPoint2 maximumDamage, Predicate<IMobState> predicate)
|
||||
{
|
||||
foreach (var (threshold, state) in _highestToLowestStates)
|
||||
{
|
||||
@@ -185,30 +186,30 @@ namespace Content.Shared.MobState.Components
|
||||
return null;
|
||||
}
|
||||
|
||||
public (IMobState state, int threshold)? GetEarliestCriticalState(int minimumDamage)
|
||||
public (IMobState state, FixedPoint2 threshold)? GetEarliestCriticalState(FixedPoint2 minimumDamage)
|
||||
{
|
||||
return GetEarliestState(minimumDamage, s => s.IsCritical());
|
||||
}
|
||||
|
||||
public (IMobState state, int threshold)? GetEarliestIncapacitatedState(int minimumDamage)
|
||||
public (IMobState state, FixedPoint2 threshold)? GetEarliestIncapacitatedState(FixedPoint2 minimumDamage)
|
||||
{
|
||||
return GetEarliestState(minimumDamage, s => s.IsIncapacitated());
|
||||
}
|
||||
|
||||
public (IMobState state, int threshold)? GetEarliestDeadState(int minimumDamage)
|
||||
public (IMobState state, FixedPoint2 threshold)? GetEarliestDeadState(FixedPoint2 minimumDamage)
|
||||
{
|
||||
return GetEarliestState(minimumDamage, s => s.IsDead());
|
||||
}
|
||||
|
||||
public (IMobState state, int threshold)? GetPreviousCriticalState(int minimumDamage)
|
||||
public (IMobState state, FixedPoint2 threshold)? GetPreviousCriticalState(FixedPoint2 minimumDamage)
|
||||
{
|
||||
return GetPreviousState(minimumDamage, s => s.IsCritical());
|
||||
}
|
||||
|
||||
private bool TryGetState(
|
||||
(IMobState state, int threshold)? tuple,
|
||||
(IMobState state, FixedPoint2 threshold)? tuple,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold)
|
||||
out FixedPoint2 threshold)
|
||||
{
|
||||
if (tuple == null)
|
||||
{
|
||||
@@ -222,9 +223,9 @@ namespace Content.Shared.MobState.Components
|
||||
}
|
||||
|
||||
public bool TryGetEarliestCriticalState(
|
||||
int minimumDamage,
|
||||
FixedPoint2 minimumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold)
|
||||
out FixedPoint2 threshold)
|
||||
{
|
||||
var earliestState = GetEarliestCriticalState(minimumDamage);
|
||||
|
||||
@@ -232,9 +233,9 @@ namespace Content.Shared.MobState.Components
|
||||
}
|
||||
|
||||
public bool TryGetEarliestIncapacitatedState(
|
||||
int minimumDamage,
|
||||
FixedPoint2 minimumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold)
|
||||
out FixedPoint2 threshold)
|
||||
{
|
||||
var earliestState = GetEarliestIncapacitatedState(minimumDamage);
|
||||
|
||||
@@ -242,9 +243,9 @@ namespace Content.Shared.MobState.Components
|
||||
}
|
||||
|
||||
public bool TryGetEarliestDeadState(
|
||||
int minimumDamage,
|
||||
FixedPoint2 minimumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold)
|
||||
out FixedPoint2 threshold)
|
||||
{
|
||||
var earliestState = GetEarliestDeadState(minimumDamage);
|
||||
|
||||
@@ -252,9 +253,9 @@ namespace Content.Shared.MobState.Components
|
||||
}
|
||||
|
||||
public bool TryGetPreviousCriticalState(
|
||||
int maximumDamage,
|
||||
FixedPoint2 maximumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold)
|
||||
out FixedPoint2 threshold)
|
||||
{
|
||||
var earliestState = GetPreviousCriticalState(maximumDamage);
|
||||
|
||||
@@ -273,7 +274,7 @@ namespace Content.Shared.MobState.Components
|
||||
/// <summary>
|
||||
/// Updates the mob state..
|
||||
/// </summary>
|
||||
public void UpdateState(int damage)
|
||||
public void UpdateState(FixedPoint2 damage)
|
||||
{
|
||||
if (!TryGetState(damage, out var newState, out var threshold))
|
||||
{
|
||||
@@ -286,7 +287,7 @@ namespace Content.Shared.MobState.Components
|
||||
/// <summary>
|
||||
/// Sets the mob state and marks the component as dirty.
|
||||
/// </summary>
|
||||
private void SetMobState(IMobState? old, (IMobState state, int threshold)? current)
|
||||
private void SetMobState(IMobState? old, (IMobState state, FixedPoint2 threshold)? current)
|
||||
{
|
||||
if (!current.HasValue)
|
||||
{
|
||||
@@ -324,9 +325,9 @@ namespace Content.Shared.MobState.Components
|
||||
[Serializable, NetSerializable]
|
||||
public class MobStateComponentState : ComponentState
|
||||
{
|
||||
public readonly int? CurrentThreshold;
|
||||
public readonly FixedPoint2? CurrentThreshold;
|
||||
|
||||
public MobStateComponentState(int? currentThreshold)
|
||||
public MobStateComponentState(FixedPoint2? currentThreshold)
|
||||
{
|
||||
CurrentThreshold = currentThreshold;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.MobState.State;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
@@ -16,34 +17,34 @@ namespace Content.Shared.MobState
|
||||
|
||||
bool IsIncapacitated();
|
||||
|
||||
(IMobState state, int threshold)? GetEarliestIncapacitatedState(int minimumDamage);
|
||||
(IMobState state, FixedPoint2 threshold)? GetEarliestIncapacitatedState(FixedPoint2 minimumDamage);
|
||||
|
||||
(IMobState state, int threshold)? GetEarliestCriticalState(int minimumDamage);
|
||||
(IMobState state, FixedPoint2 threshold)? GetEarliestCriticalState(FixedPoint2 minimumDamage);
|
||||
|
||||
(IMobState state, int threshold)? GetEarliestDeadState(int minimumDamage);
|
||||
(IMobState state, FixedPoint2 threshold)? GetEarliestDeadState(FixedPoint2 minimumDamage);
|
||||
|
||||
(IMobState state, int threshold)? GetPreviousCriticalState(int maximumDamage);
|
||||
(IMobState state, FixedPoint2 threshold)? GetPreviousCriticalState(FixedPoint2 maximumDamage);
|
||||
|
||||
bool TryGetEarliestIncapacitatedState(
|
||||
int minimumDamage,
|
||||
FixedPoint2 minimumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold);
|
||||
out FixedPoint2 threshold);
|
||||
|
||||
bool TryGetEarliestCriticalState(
|
||||
int minimumDamage,
|
||||
FixedPoint2 minimumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold);
|
||||
out FixedPoint2 threshold);
|
||||
|
||||
bool TryGetEarliestDeadState(
|
||||
int minimumDamage,
|
||||
FixedPoint2 minimumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold);
|
||||
out FixedPoint2 threshold);
|
||||
|
||||
bool TryGetPreviousCriticalState(
|
||||
int maximumDamage,
|
||||
FixedPoint2 maximumDamage,
|
||||
[NotNullWhen(true)] out IMobState? state,
|
||||
out int threshold);
|
||||
out FixedPoint2 threshold);
|
||||
|
||||
void UpdateState(int damage);
|
||||
void UpdateState(FixedPoint2 damage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.MobState.State
|
||||
@@ -32,6 +33,6 @@ namespace Content.Shared.MobState.State
|
||||
|
||||
public virtual void ExitState(IEntity entity) { }
|
||||
|
||||
public virtual void UpdateState(IEntity entity, int threshold) { }
|
||||
public virtual void UpdateState(IEntity entity, FixedPoint2 threshold) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.MobState.State
|
||||
@@ -36,6 +37,6 @@ namespace Content.Shared.MobState.State
|
||||
/// <summary>
|
||||
/// Called when this state is updated.
|
||||
/// </summary>
|
||||
void UpdateState(IEntity entity, int threshold);
|
||||
void UpdateState(IEntity entity, FixedPoint2 threshold);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,48 @@
|
||||
using System;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Content.Tests.Shared.Chemistry
|
||||
{
|
||||
[TestFixture, TestOf(typeof(ReagentUnit))]
|
||||
public class ReagentUnit_Tests
|
||||
[TestFixture, TestOf(typeof(FixedPoint2))]
|
||||
public class FixedPoint2_Tests
|
||||
{
|
||||
[Test]
|
||||
[TestCase(1, "1")]
|
||||
[TestCase(0, "0")]
|
||||
[TestCase(-1, "-1")]
|
||||
public void ReagentUnitIntegerTests(int value, string expected)
|
||||
public void FixedPoint2IntegerTests(int value, string expected)
|
||||
{
|
||||
var result = ReagentUnit.New(value);
|
||||
var result = FixedPoint2.New(value);
|
||||
Assert.That($"{result}", Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase(1.001f, "1")]
|
||||
[TestCase(0.999f, "1")]
|
||||
public void ReagentUnitFloatTests(float value, string expected)
|
||||
public void FixedPoint2FloatTests(float value, string expected)
|
||||
{
|
||||
var result = ReagentUnit.New(value);
|
||||
var result = FixedPoint2.New(value);
|
||||
Assert.That($"{result}", Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase(1.001d, "1")]
|
||||
[TestCase(0.999d, "1")]
|
||||
public void ReagentUnitDoubleTests(double value, string expected)
|
||||
public void FixedPoint2DoubleTests(double value, string expected)
|
||||
{
|
||||
var result = ReagentUnit.New(value);
|
||||
var result = FixedPoint2.New(value);
|
||||
Assert.That($"{result}", Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase("1.005", "1.01")]
|
||||
[TestCase("0.999", "1")]
|
||||
public void ReagentUnitStringTests(string value, string expected)
|
||||
public void FixedPoint2StringTests(string value, string expected)
|
||||
{
|
||||
var result = ReagentUnit.New(value);
|
||||
var result = FixedPoint2.New(value);
|
||||
Assert.That($"{result}", Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
@@ -52,8 +53,8 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[TestCase(1f, 2.005f, "3.01")]
|
||||
public void CalculusPlus(float aFloat, float bFloat, string expected)
|
||||
{
|
||||
var a = ReagentUnit.New(aFloat);
|
||||
var b = ReagentUnit.New(bFloat);
|
||||
var a = FixedPoint2.New(aFloat);
|
||||
var b = FixedPoint2.New(bFloat);
|
||||
|
||||
var result = a + b;
|
||||
|
||||
@@ -66,8 +67,8 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[TestCase(1f, 2.005f, "-1.01")]
|
||||
public void CalculusMinus(float aFloat, float bFloat, string expected)
|
||||
{
|
||||
var a = ReagentUnit.New(aFloat);
|
||||
var b = ReagentUnit.New(bFloat);
|
||||
var a = FixedPoint2.New(aFloat);
|
||||
var b = FixedPoint2.New(bFloat);
|
||||
|
||||
var result = a - b;
|
||||
|
||||
@@ -80,8 +81,8 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[TestCase(2.1f, 3f, "0.7")]
|
||||
public void CalculusDivision(float aFloat, float bFloat, string expected)
|
||||
{
|
||||
var a = ReagentUnit.New(aFloat);
|
||||
var b = ReagentUnit.New(bFloat);
|
||||
var a = FixedPoint2.New(aFloat);
|
||||
var b = FixedPoint2.New(bFloat);
|
||||
|
||||
var result = a / b;
|
||||
|
||||
@@ -93,8 +94,8 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[TestCase(0.999f, 3f, "3")]
|
||||
public void CalculusMultiplication(float aFloat, float bFloat, string expected)
|
||||
{
|
||||
var a = ReagentUnit.New(aFloat);
|
||||
var b = ReagentUnit.New(bFloat);
|
||||
var a = FixedPoint2.New(aFloat);
|
||||
var b = FixedPoint2.New(bFloat);
|
||||
|
||||
var result = a * b;
|
||||
|
||||
@@ -112,18 +113,18 @@ namespace Content.Tests.Shared.Chemistry
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReagentUnitMin()
|
||||
public void FixedPoint2Min()
|
||||
{
|
||||
var unorderedList = new[]
|
||||
{
|
||||
ReagentUnit.New(5),
|
||||
ReagentUnit.New(3),
|
||||
ReagentUnit.New(1),
|
||||
ReagentUnit.New(2),
|
||||
ReagentUnit.New(4),
|
||||
FixedPoint2.New(5),
|
||||
FixedPoint2.New(3),
|
||||
FixedPoint2.New(1),
|
||||
FixedPoint2.New(2),
|
||||
FixedPoint2.New(4),
|
||||
};
|
||||
var min = ReagentUnit.Min(unorderedList);
|
||||
Assert.That(min, Is.EqualTo(ReagentUnit.New(1)));
|
||||
var min = FixedPoint2.Min(unorderedList);
|
||||
Assert.That(min, Is.EqualTo(FixedPoint2.New(1)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -133,10 +134,10 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[TestCase(1, 1, true)]
|
||||
[TestCase(0, 1, false)]
|
||||
[TestCase(-1, 1, false)]
|
||||
public void ReagentUnitEquals(int a, int b, bool expected)
|
||||
public void FixedPoint2Equals(int a, int b, bool expected)
|
||||
{
|
||||
var parameter = ReagentUnit.New(a);
|
||||
var comparison = ReagentUnit.New(b);
|
||||
var parameter = FixedPoint2.New(a);
|
||||
var comparison = FixedPoint2.New(b);
|
||||
Assert.That(parameter.Equals(comparison), Is.EqualTo(comparison.Equals(parameter)));
|
||||
Assert.That(comparison.Equals(parameter), Is.EqualTo(expected));
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Content.Tests.Shared.Chemistry
|
||||
@@ -11,7 +12,7 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void AddReagentAndGetSolution()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(1000));
|
||||
solution.AddReagent("water", FixedPoint2.New(1000));
|
||||
var quantity = solution.GetReagentQuantity("water");
|
||||
|
||||
Assert.That(quantity.Int(), Is.EqualTo(1000));
|
||||
@@ -20,7 +21,7 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[Test]
|
||||
public void ConstructorAddReagent()
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(1000));
|
||||
var solution = new Solution("water", FixedPoint2.New(1000));
|
||||
var quantity = solution.GetReagentQuantity("water");
|
||||
|
||||
Assert.That(quantity.Int(), Is.EqualTo(1000));
|
||||
@@ -38,7 +39,7 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[Test]
|
||||
public void AddLessThanZeroReagentReturnsZero()
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(-1000));
|
||||
var solution = new Solution("water", FixedPoint2.New(-1000));
|
||||
var quantity = solution.GetReagentQuantity("water");
|
||||
|
||||
Assert.That(quantity.Int(), Is.EqualTo(0));
|
||||
@@ -48,8 +49,8 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void AddingReagentsSumsProperly()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(1000));
|
||||
solution.AddReagent("water", ReagentUnit.New(2000));
|
||||
solution.AddReagent("water", FixedPoint2.New(1000));
|
||||
solution.AddReagent("water", FixedPoint2.New(2000));
|
||||
var quantity = solution.GetReagentQuantity("water");
|
||||
|
||||
Assert.That(quantity.Int(), Is.EqualTo(3000));
|
||||
@@ -59,8 +60,8 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void ReagentQuantitiesStayUnique()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(1000));
|
||||
solution.AddReagent("fire", ReagentUnit.New(2000));
|
||||
solution.AddReagent("water", FixedPoint2.New(1000));
|
||||
solution.AddReagent("fire", FixedPoint2.New(2000));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(1000));
|
||||
Assert.That(solution.GetReagentQuantity("fire").Int(), Is.EqualTo(2000));
|
||||
@@ -70,8 +71,8 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void TotalVolumeIsCorrect()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(1000));
|
||||
solution.AddReagent("fire", ReagentUnit.New(2000));
|
||||
solution.AddReagent("water", FixedPoint2.New(1000));
|
||||
solution.AddReagent("fire", FixedPoint2.New(2000));
|
||||
|
||||
Assert.That(solution.TotalVolume.Int(), Is.EqualTo(3000));
|
||||
}
|
||||
@@ -80,8 +81,8 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void CloningSolutionIsCorrect()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(1000));
|
||||
solution.AddReagent("fire", ReagentUnit.New(2000));
|
||||
solution.AddReagent("water", FixedPoint2.New(1000));
|
||||
solution.AddReagent("fire", FixedPoint2.New(2000));
|
||||
|
||||
var newSolution = solution.Clone();
|
||||
|
||||
@@ -94,10 +95,10 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void RemoveSolutionRecalculatesProperly()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(1000));
|
||||
solution.AddReagent("fire", ReagentUnit.New(2000));
|
||||
solution.AddReagent("water", FixedPoint2.New(1000));
|
||||
solution.AddReagent("fire", FixedPoint2.New(2000));
|
||||
|
||||
solution.RemoveReagent("water", ReagentUnit.New(500));
|
||||
solution.RemoveReagent("water", FixedPoint2.New(500));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(500));
|
||||
Assert.That(solution.GetReagentQuantity("fire").Int(), Is.EqualTo(2000));
|
||||
@@ -107,9 +108,9 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[Test]
|
||||
public void RemoveLessThanOneQuantityDoesNothing()
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(100));
|
||||
var solution = new Solution("water", FixedPoint2.New(100));
|
||||
|
||||
solution.RemoveReagent("water", ReagentUnit.New(-100));
|
||||
solution.RemoveReagent("water", FixedPoint2.New(-100));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(100));
|
||||
Assert.That(solution.TotalVolume.Int(), Is.EqualTo(100));
|
||||
@@ -118,9 +119,9 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[Test]
|
||||
public void RemoveMoreThanTotalRemovesAllReagent()
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(100));
|
||||
var solution = new Solution("water", FixedPoint2.New(100));
|
||||
|
||||
solution.RemoveReagent("water", ReagentUnit.New(1000));
|
||||
solution.RemoveReagent("water", FixedPoint2.New(1000));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(0));
|
||||
Assert.That(solution.TotalVolume.Int(), Is.EqualTo(0));
|
||||
@@ -129,9 +130,9 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[Test]
|
||||
public void RemoveNonExistReagentDoesNothing()
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(100));
|
||||
var solution = new Solution("water", FixedPoint2.New(100));
|
||||
|
||||
solution.RemoveReagent("fire", ReagentUnit.New(1000));
|
||||
solution.RemoveReagent("fire", FixedPoint2.New(1000));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(100));
|
||||
Assert.That(solution.TotalVolume.Int(), Is.EqualTo(100));
|
||||
@@ -140,9 +141,9 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[Test]
|
||||
public void RemoveSolution()
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(700));
|
||||
var solution = new Solution("water", FixedPoint2.New(700));
|
||||
|
||||
solution.RemoveSolution(ReagentUnit.New(500));
|
||||
solution.RemoveSolution(FixedPoint2.New(500));
|
||||
|
||||
//Check that edited solution is correct
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(200));
|
||||
@@ -152,9 +153,9 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[Test]
|
||||
public void RemoveSolutionMoreThanTotalRemovesAll()
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(800));
|
||||
var solution = new Solution("water", FixedPoint2.New(800));
|
||||
|
||||
solution.RemoveSolution(ReagentUnit.New(1000));
|
||||
solution.RemoveSolution(FixedPoint2.New(1000));
|
||||
|
||||
//Check that edited solution is correct
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(0));
|
||||
@@ -165,10 +166,10 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void RemoveSolutionRatioPreserved()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(1000));
|
||||
solution.AddReagent("fire", ReagentUnit.New(2000));
|
||||
solution.AddReagent("water", FixedPoint2.New(1000));
|
||||
solution.AddReagent("fire", FixedPoint2.New(2000));
|
||||
|
||||
solution.RemoveSolution(ReagentUnit.New(1500));
|
||||
solution.RemoveSolution(FixedPoint2.New(1500));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(500));
|
||||
Assert.That(solution.GetReagentQuantity("fire").Int(), Is.EqualTo(1000));
|
||||
@@ -178,9 +179,9 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[Test]
|
||||
public void RemoveSolutionLessThanOneDoesNothing()
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(800));
|
||||
var solution = new Solution("water", FixedPoint2.New(800));
|
||||
|
||||
solution.RemoveSolution(ReagentUnit.New(-200));
|
||||
solution.RemoveSolution(FixedPoint2.New(-200));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(800));
|
||||
Assert.That(solution.TotalVolume.Int(), Is.EqualTo(800));
|
||||
@@ -190,10 +191,10 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void SplitSolution()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(1000));
|
||||
solution.AddReagent("fire", ReagentUnit.New(2000));
|
||||
solution.AddReagent("water", FixedPoint2.New(1000));
|
||||
solution.AddReagent("fire", FixedPoint2.New(2000));
|
||||
|
||||
var splitSolution = solution.SplitSolution(ReagentUnit.New(750));
|
||||
var splitSolution = solution.SplitSolution(FixedPoint2.New(750));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(750));
|
||||
Assert.That(solution.GetReagentQuantity("fire").Int(), Is.EqualTo(1500));
|
||||
@@ -208,10 +209,10 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void SplitSolutionFractional()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(1));
|
||||
solution.AddReagent("fire", ReagentUnit.New(2));
|
||||
solution.AddReagent("water", FixedPoint2.New(1));
|
||||
solution.AddReagent("fire", FixedPoint2.New(2));
|
||||
|
||||
var splitSolution = solution.SplitSolution(ReagentUnit.New(1));
|
||||
var splitSolution = solution.SplitSolution(FixedPoint2.New(1));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Float(), Is.EqualTo(0.67f));
|
||||
Assert.That(solution.GetReagentQuantity("fire").Float(), Is.EqualTo(1.33f));
|
||||
@@ -226,10 +227,10 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void SplitSolutionFractionalOpposite()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(1));
|
||||
solution.AddReagent("fire", ReagentUnit.New(2));
|
||||
solution.AddReagent("water", FixedPoint2.New(1));
|
||||
solution.AddReagent("fire", FixedPoint2.New(2));
|
||||
|
||||
var splitSolution = solution.SplitSolution(ReagentUnit.New(2));
|
||||
var splitSolution = solution.SplitSolution(FixedPoint2.New(2));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Float(), Is.EqualTo(0.33f));
|
||||
Assert.That(solution.GetReagentQuantity("fire").Float(), Is.EqualTo(0.67f));
|
||||
@@ -246,9 +247,9 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void SplitSolutionTinyFractionalBigSmall(float initial, float reduce, float remainder)
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", ReagentUnit.New(initial));
|
||||
solution.AddReagent("water", FixedPoint2.New(initial));
|
||||
|
||||
var splitSolution = solution.SplitSolution(ReagentUnit.New(reduce));
|
||||
var splitSolution = solution.SplitSolution(FixedPoint2.New(reduce));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Float(), Is.EqualTo(remainder));
|
||||
Assert.That(solution.TotalVolume.Float(), Is.EqualTo(remainder));
|
||||
@@ -265,11 +266,11 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void SplitRounding(int amount)
|
||||
{
|
||||
var solutionOne = new Solution();
|
||||
solutionOne.AddReagent("foo", ReagentUnit.New(amount));
|
||||
solutionOne.AddReagent("bar", ReagentUnit.New(amount));
|
||||
solutionOne.AddReagent("baz", ReagentUnit.New(amount));
|
||||
solutionOne.AddReagent("foo", FixedPoint2.New(amount));
|
||||
solutionOne.AddReagent("bar", FixedPoint2.New(amount));
|
||||
solutionOne.AddReagent("baz", FixedPoint2.New(amount));
|
||||
|
||||
var splitAmount = ReagentUnit.New(5);
|
||||
var splitAmount = FixedPoint2.New(5);
|
||||
var split = solutionOne.SplitSolution(splitAmount);
|
||||
|
||||
Assert.That(split.TotalVolume, Is.EqualTo(splitAmount));
|
||||
@@ -278,9 +279,9 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[Test]
|
||||
public void SplitSolutionMoreThanTotalRemovesAll()
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(800));
|
||||
var solution = new Solution("water", FixedPoint2.New(800));
|
||||
|
||||
var splitSolution = solution.SplitSolution(ReagentUnit.New(1000));
|
||||
var splitSolution = solution.SplitSolution(FixedPoint2.New(1000));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(0));
|
||||
Assert.That(solution.TotalVolume.Int(), Is.EqualTo(0));
|
||||
@@ -292,9 +293,9 @@ namespace Content.Tests.Shared.Chemistry
|
||||
[Test]
|
||||
public void SplitSolutionLessThanOneDoesNothing()
|
||||
{
|
||||
var solution = new Solution("water", ReagentUnit.New(800));
|
||||
var solution = new Solution("water", FixedPoint2.New(800));
|
||||
|
||||
var splitSolution = solution.SplitSolution(ReagentUnit.New(-200));
|
||||
var splitSolution = solution.SplitSolution(FixedPoint2.New(-200));
|
||||
|
||||
Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(800));
|
||||
Assert.That(solution.TotalVolume.Int(), Is.EqualTo(800));
|
||||
@@ -307,33 +308,33 @@ namespace Content.Tests.Shared.Chemistry
|
||||
public void SplitSolutionZero()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("Impedrezene", ReagentUnit.New(0.01 + 0.19));
|
||||
solution.AddReagent("Thermite", ReagentUnit.New(0.01 + 0.39));
|
||||
solution.AddReagent("Li", ReagentUnit.New(0.01 + 0.17));
|
||||
solution.AddReagent("F", ReagentUnit.New(0.01 + 0.17));
|
||||
solution.AddReagent("Na", ReagentUnit.New(0 + 0.13));
|
||||
solution.AddReagent("Hg", ReagentUnit.New(0.15 + 4.15));
|
||||
solution.AddReagent("Cu", ReagentUnit.New(0 + 0.13));
|
||||
solution.AddReagent("U", ReagentUnit.New(0.76 + 20.77));
|
||||
solution.AddReagent("Fe", ReagentUnit.New(0.01 + 0.36));
|
||||
solution.AddReagent("SpaceDrugs", ReagentUnit.New(0.02 + 0.41));
|
||||
solution.AddReagent("Al", ReagentUnit.New(0));
|
||||
solution.AddReagent("Glucose", ReagentUnit.New(0));
|
||||
solution.AddReagent("O", ReagentUnit.New(0));
|
||||
solution.AddReagent("Impedrezene", FixedPoint2.New(0.01 + 0.19));
|
||||
solution.AddReagent("Thermite", FixedPoint2.New(0.01 + 0.39));
|
||||
solution.AddReagent("Li", FixedPoint2.New(0.01 + 0.17));
|
||||
solution.AddReagent("F", FixedPoint2.New(0.01 + 0.17));
|
||||
solution.AddReagent("Na", FixedPoint2.New(0 + 0.13));
|
||||
solution.AddReagent("Hg", FixedPoint2.New(0.15 + 4.15));
|
||||
solution.AddReagent("Cu", FixedPoint2.New(0 + 0.13));
|
||||
solution.AddReagent("U", FixedPoint2.New(0.76 + 20.77));
|
||||
solution.AddReagent("Fe", FixedPoint2.New(0.01 + 0.36));
|
||||
solution.AddReagent("SpaceDrugs", FixedPoint2.New(0.02 + 0.41));
|
||||
solution.AddReagent("Al", FixedPoint2.New(0));
|
||||
solution.AddReagent("Glucose", FixedPoint2.New(0));
|
||||
solution.AddReagent("O", FixedPoint2.New(0));
|
||||
|
||||
solution.SplitSolution(ReagentUnit.New(0.98));
|
||||
solution.SplitSolution(FixedPoint2.New(0.98));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddSolution()
|
||||
{
|
||||
var solutionOne = new Solution();
|
||||
solutionOne.AddReagent("water", ReagentUnit.New(1000));
|
||||
solutionOne.AddReagent("fire", ReagentUnit.New(2000));
|
||||
solutionOne.AddReagent("water", FixedPoint2.New(1000));
|
||||
solutionOne.AddReagent("fire", FixedPoint2.New(2000));
|
||||
|
||||
var solutionTwo = new Solution();
|
||||
solutionTwo.AddReagent("water", ReagentUnit.New(500));
|
||||
solutionTwo.AddReagent("earth", ReagentUnit.New(1000));
|
||||
solutionTwo.AddReagent("water", FixedPoint2.New(500));
|
||||
solutionTwo.AddReagent("earth", FixedPoint2.New(1000));
|
||||
|
||||
solutionOne.AddSolution(solutionTwo);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.FixedPoint;
|
||||
|
||||
namespace Content.Tests.Shared
|
||||
{
|
||||
@@ -21,7 +22,7 @@ namespace Content.Tests.Shared
|
||||
// "missing" blunt entry
|
||||
{ "Piercing", -2 },// Turn Piercing into Healing
|
||||
{ "Slash", 3 },
|
||||
{ "Radiation", 1.06f }, // Small change, paired with fractional reduction
|
||||
{ "Radiation", 1.5f },
|
||||
};
|
||||
|
||||
static private Dictionary<string, float> _resistanceReductionDict = new()
|
||||
@@ -59,75 +60,75 @@ namespace Content.Tests.Shared
|
||||
DamageSpecifier damageSpec = new(_damageSpec);
|
||||
|
||||
// Check that it properly split up the groups into types
|
||||
int damage;
|
||||
Assert.That(damageSpec.Total, Is.EqualTo(8));
|
||||
FixedPoint2 damage;
|
||||
Assert.That(damageSpec.Total, Is.EqualTo(FixedPoint2.New(8)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage));
|
||||
Assert.That(damage, Is.EqualTo(2));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(2)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage));
|
||||
Assert.That(damage, Is.EqualTo(2));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(2)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage));
|
||||
Assert.That(damage, Is.EqualTo(1));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(1)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Radiation", out damage));
|
||||
Assert.That(damage, Is.EqualTo(3));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(3)));
|
||||
|
||||
// check that integer multiplication works
|
||||
damageSpec = damageSpec * 2;
|
||||
Assert.That(damageSpec.Total, Is.EqualTo(16));
|
||||
Assert.That(damageSpec.Total, Is.EqualTo(FixedPoint2.New(16)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage));
|
||||
Assert.That(damage, Is.EqualTo(4));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(4)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage));
|
||||
Assert.That(damage, Is.EqualTo(4));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(4)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage));
|
||||
Assert.That(damage, Is.EqualTo(2));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(2)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Radiation", out damage));
|
||||
Assert.That(damage, Is.EqualTo(6));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(6)));
|
||||
|
||||
// check that float multiplication works
|
||||
damageSpec = damageSpec * 2.2f;
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage));
|
||||
Assert.That(damage, Is.EqualTo(9));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(8.8)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage));
|
||||
Assert.That(damage, Is.EqualTo(9));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(8.8)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage));
|
||||
Assert.That(damage, Is.EqualTo(4));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(4.4)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Radiation", out damage));
|
||||
Assert.That(damage, Is.EqualTo(13));
|
||||
Assert.That(damageSpec.Total, Is.EqualTo(9 + 9 + 4 + 13));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(13.2)));
|
||||
Assert.That(damageSpec.Total, Is.EqualTo(FixedPoint2.New(8.8 + 8.8 + 4.4 + 13.2)));
|
||||
|
||||
// check that integer division works
|
||||
damageSpec = damageSpec / 2;
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage));
|
||||
Assert.That(damage, Is.EqualTo(5));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(4.4)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage));
|
||||
Assert.That(damage, Is.EqualTo(5));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(4.4)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage));
|
||||
Assert.That(damage, Is.EqualTo(2));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(2.2)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Radiation", out damage));
|
||||
Assert.That(damage, Is.EqualTo(7));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(6.6)));
|
||||
|
||||
// check that float division works
|
||||
damageSpec = damageSpec / 2.4f;
|
||||
damageSpec = damageSpec / 2.2f;
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage));
|
||||
Assert.That(damage, Is.EqualTo(2));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(2)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage));
|
||||
Assert.That(damage, Is.EqualTo(2));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(2)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage));
|
||||
Assert.That(damage, Is.EqualTo(1));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(1)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Radiation", out damage));
|
||||
Assert.That(damage, Is.EqualTo(3));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(3)));
|
||||
|
||||
// Lets also test the constructor with damage types and damage groups works properly.
|
||||
damageSpec = new(_prototypeManager.Index<DamageGroupPrototype>("Brute"), 4);
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage));
|
||||
Assert.That(damage, Is.EqualTo(1));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(1.33)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage));
|
||||
Assert.That(damage, Is.EqualTo(2)); // integer rounding. Piercing is defined as last group member in yaml.
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(1.33)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage));
|
||||
Assert.That(damage, Is.EqualTo(1));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(1.34))); // doesn't divide evenly, so the 0.01 goes to the last one
|
||||
|
||||
damageSpec = new(_prototypeManager.Index<DamageTypePrototype>("Piercing"), 4);
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage));
|
||||
Assert.That(damage, Is.EqualTo(4));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(4)));
|
||||
}
|
||||
|
||||
//Check that DamageSpecifier will be properly adjusted by a resistance set
|
||||
@@ -146,21 +147,21 @@ namespace Content.Tests.Shared
|
||||
|
||||
//damage is initially 20 / 20 / 10 / 30
|
||||
//Each time we subtract -5 / 0 / 8 / 0.5
|
||||
//then multiply by 1 / -2 / 3 / 1.06
|
||||
//then multiply by 1 / -2 / 3 / 1.5
|
||||
|
||||
// Apply once
|
||||
damageSpec = DamageSpecifier.ApplyModifierSet(damageSpec, modifierSet);
|
||||
Assert.That(damageSpec.DamageDict["Blunt"], Is.EqualTo(25));
|
||||
Assert.That(damageSpec.DamageDict["Piercing"], Is.EqualTo(-40)); // became healing
|
||||
Assert.That(damageSpec.DamageDict["Slash"], Is.EqualTo(6));
|
||||
Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(31)); // would be 32 w/o fraction adjustment
|
||||
Assert.That(damageSpec.DamageDict["Blunt"], Is.EqualTo(FixedPoint2.New(25)));
|
||||
Assert.That(damageSpec.DamageDict["Piercing"], Is.EqualTo(FixedPoint2.New(-40))); // became healing
|
||||
Assert.That(damageSpec.DamageDict["Slash"], Is.EqualTo(FixedPoint2.New(6)));
|
||||
Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(FixedPoint2.New(44.25)));
|
||||
|
||||
// And again, checking for some other behavior
|
||||
damageSpec = DamageSpecifier.ApplyModifierSet(damageSpec, modifierSet);
|
||||
Assert.That(damageSpec.DamageDict["Blunt"], Is.EqualTo(30));
|
||||
Assert.That(damageSpec.DamageDict["Piercing"], Is.EqualTo(-40)); // resistances don't apply to healing
|
||||
Assert.That(damageSpec.DamageDict["Blunt"], Is.EqualTo(FixedPoint2.New(30)));
|
||||
Assert.That(damageSpec.DamageDict["Piercing"], Is.EqualTo(FixedPoint2.New(-40))); // resistances don't apply to healing
|
||||
Assert.That(!damageSpec.DamageDict.ContainsKey("Slash")); // Reduction reduced to 0, and removed from specifier
|
||||
Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(32));
|
||||
Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(FixedPoint2.New(65.63)));
|
||||
}
|
||||
|
||||
// Default damage Yaml
|
||||
|
||||
Reference in New Issue
Block a user