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