Replace decimal with ReagentUnit
This commit is contained in:
@@ -33,18 +33,18 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
[ViewVariables]
|
||||
private string _finishPrototype;
|
||||
|
||||
public decimal TransferAmount => _transferAmount;
|
||||
public ReagentUnit TransferAmount => _transferAmount;
|
||||
[ViewVariables]
|
||||
private decimal _transferAmount = 2;
|
||||
private ReagentUnit _transferAmount = ReagentUnit.New(2);
|
||||
|
||||
public decimal MaxVolume
|
||||
public ReagentUnit MaxVolume
|
||||
{
|
||||
get => _contents.MaxVolume;
|
||||
set => _contents.MaxVolume = value;
|
||||
}
|
||||
|
||||
private Solution _initialContents; // This is just for loading from yaml
|
||||
private int _maxVolume;
|
||||
private ReagentUnit _maxVolume;
|
||||
|
||||
private bool _despawnOnFinish;
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return Math.Max(1, (int)Math.Ceiling(_contents.CurrentVolume / _transferAmount));
|
||||
return Math.Max(1, (int)Math.Ceiling((_contents.CurrentVolume / _transferAmount).Float()));
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(ref _initialContents, "contents", null);
|
||||
serializer.DataField(ref _maxVolume, "max_volume", 0);
|
||||
serializer.DataField(ref _maxVolume, "max_volume", ReagentUnit.New(0));
|
||||
serializer.DataField(ref _useSound, "use_sound", "/Audio/items/drink.ogg");
|
||||
// E.g. cola can when done or clear bottle, whatever
|
||||
// Currently this will enforce it has the same volume but this may change.
|
||||
@@ -91,7 +91,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
| SolutionCaps.Injectable;
|
||||
|
||||
var pourable = Owner.AddComponent<PourableComponent>();
|
||||
pourable.TransferAmount = 5;
|
||||
pourable.TransferAmount = ReagentUnit.New(5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
if (user.TryGetComponent(out StomachComponent stomachComponent))
|
||||
{
|
||||
_drinking = true;
|
||||
var transferAmount = Math.Min(_transferAmount, _contents.CurrentVolume);
|
||||
var transferAmount = ReagentUnit.Min(_transferAmount, _contents.CurrentVolume);
|
||||
var split = _contents.SplitSolution(transferAmount);
|
||||
if (stomachComponent.TryTransferSolution(split))
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
[ViewVariables]
|
||||
private SolutionComponent _contents;
|
||||
[ViewVariables]
|
||||
private int _transferAmount;
|
||||
private ReagentUnit _transferAmount;
|
||||
|
||||
private Solution _initialContents; // This is just for loading from yaml
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
serializer.DataField(ref _initialContents, "contents", null);
|
||||
serializer.DataField(ref _useSound, "use_sound", "/Audio/items/eatfood.ogg");
|
||||
// Default is transfer 30 units
|
||||
serializer.DataField(ref _transferAmount, "transfer_amount", 5);
|
||||
serializer.DataField(ref _transferAmount, "transfer_amount", ReagentUnit.New(5));
|
||||
// E.g. empty chip packet when done
|
||||
serializer.DataField(ref _finishPrototype, "spawn_on_finish", null);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
_initialContents = null;
|
||||
if (_contents.CurrentVolume == 0)
|
||||
{
|
||||
_contents.TryAddReagent("chem.Nutriment", 5, out _);
|
||||
_contents.TryAddReagent("chem.Nutriment", ReagentUnit.New(5), out _);
|
||||
}
|
||||
Owner.TryGetComponent(out AppearanceComponent appearance);
|
||||
_appearanceComponent = appearance;
|
||||
@@ -99,7 +99,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return Math.Max(1, (int)Math.Ceiling(_contents.CurrentVolume / _transferAmount));
|
||||
return Math.Max(1, (int)Math.Ceiling((_contents.CurrentVolume / _transferAmount).Float()));
|
||||
}
|
||||
|
||||
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
||||
@@ -130,7 +130,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
// TODO: Add putting food back in boxes here?
|
||||
if (user.TryGetComponent(out StomachComponent stomachComponent))
|
||||
{
|
||||
var transferAmount = Math.Min(_transferAmount, _contents.CurrentVolume);
|
||||
var transferAmount = ReagentUnit.Min(_transferAmount, _contents.CurrentVolume);
|
||||
var split = _contents.SplitSolution(transferAmount);
|
||||
if (stomachComponent.TryTransferSolution(split))
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
/// <summary>
|
||||
/// Max volume of internal solution storage
|
||||
/// </summary>
|
||||
public decimal MaxVolume
|
||||
public ReagentUnit MaxVolume
|
||||
{
|
||||
get => _stomachContents.MaxVolume;
|
||||
set => _stomachContents.MaxVolume = value;
|
||||
@@ -43,7 +43,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
/// Initial internal solution storage volume
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private int _initialMaxVolume;
|
||||
private ReagentUnit _initialMaxVolume;
|
||||
|
||||
/// <summary>
|
||||
/// Time in seconds between reagents being ingested and them being transferred to <see cref="BloodstreamComponent"/>
|
||||
@@ -64,7 +64,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(ref _initialMaxVolume, "maxVolume", 100);
|
||||
serializer.DataField(ref _initialMaxVolume, "maxVolume", ReagentUnit.New(100));
|
||||
serializer.DataField(ref _digestionDelay, "digestionDelay", 20);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
}
|
||||
|
||||
//Add reagents ready for transfer to bloodstream to transferSolution
|
||||
var transferSolution = IoCManager.InjectDependencies(new Solution());
|
||||
var transferSolution = new Solution();
|
||||
foreach (var delta in _reagentDeltas.ToList()) //Use ToList here to remove entries while iterating
|
||||
{
|
||||
//Increment lifetime of reagents
|
||||
@@ -141,10 +141,10 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
private class ReagentDelta
|
||||
{
|
||||
public readonly string ReagentId;
|
||||
public readonly decimal Quantity;
|
||||
public readonly ReagentUnit Quantity;
|
||||
public float Lifetime { get; private set; }
|
||||
|
||||
public ReagentDelta(string reagentId, decimal quantity)
|
||||
public ReagentDelta(string reagentId, ReagentUnit quantity)
|
||||
{
|
||||
ReagentId = reagentId;
|
||||
Quantity = quantity;
|
||||
|
||||
Reference in New Issue
Block a user