Changed all int and some float things in Reagent code to Decimals

This commit is contained in:
PrPleGoo
2020-03-14 12:55:07 +01:00
parent b9f9eb6651
commit f05fdfb5fc
19 changed files with 101 additions and 81 deletions

View File

@@ -16,8 +16,8 @@ namespace Content.Client.GameObjects.Components.Chemistry
[RegisterComponent] [RegisterComponent]
public class InjectorComponent : SharedInjectorComponent, IItemStatus public class InjectorComponent : SharedInjectorComponent, IItemStatus
{ {
[ViewVariables] private int CurrentVolume { get; set; } [ViewVariables] private decimal CurrentVolume { get; set; }
[ViewVariables] private int TotalVolume { get; set; } [ViewVariables] private decimal 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;
@@ -28,9 +28,9 @@ namespace Content.Client.GameObjects.Components.Chemistry
//Handle net updates //Handle net updates
public override void HandleComponentState(ComponentState curState, ComponentState nextState) public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{ {
var cast = (InjectorComponentState)curState; if(curState.GetType() == typeof(InjectorComponentState))
if (cast != null)
{ {
var cast = (InjectorComponentState) curState;
CurrentVolume = cast.CurrentVolume; CurrentVolume = cast.CurrentVolume;
TotalVolume = cast.TotalVolume; TotalVolume = cast.TotalVolume;
CurrentMode = cast.CurrentMode; CurrentMode = cast.CurrentMode;

View File

@@ -28,7 +28,7 @@ namespace Content.Server.Chemistry.Metabolism
} }
//Remove reagent at set rate, satiate thirst if a ThirstComponent can be found //Remove reagent at set rate, satiate thirst if a ThirstComponent can be found
int IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime) decimal IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime)
{ {
int metabolismAmount = (int)Math.Round(MetabolismRate * tickTime); int metabolismAmount = (int)Math.Round(MetabolismRate * tickTime);
if (solutionEntity.TryGetComponent(out ThirstComponent thirst)) if (solutionEntity.TryGetComponent(out ThirstComponent thirst))

View File

@@ -1,6 +1,7 @@
using System; using System;
using Content.Server.GameObjects.Components.Nutrition; using Content.Server.GameObjects.Components.Nutrition;
using Content.Shared.Interfaces.Chemistry; using Content.Shared.Interfaces.Chemistry;
using Content.Shared.Maths;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Serialization; using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -14,25 +15,25 @@ namespace Content.Server.Chemistry.Metabolism
class DefaultFood : IMetabolizable class DefaultFood : IMetabolizable
{ {
//Rate of metabolism in units / second //Rate of metabolism in units / second
private int _metabolismRate; private decimal _metabolismRate;
public int MetabolismRate => _metabolismRate; public decimal MetabolismRate => _metabolismRate;
//How much hunger is satiated when 1u of the reagent is metabolized //How much hunger is satiated when 1u of the reagent is metabolized
private float _nutritionFactor; private decimal _nutritionFactor;
public float NutritionFactor => _nutritionFactor; public decimal NutritionFactor => _nutritionFactor;
void IExposeData.ExposeData(ObjectSerializer serializer) void IExposeData.ExposeData(ObjectSerializer serializer)
{ {
serializer.DataField(ref _metabolismRate, "rate", 1); serializer.DataField(ref _metabolismRate, "rate", 1M);
serializer.DataField(ref _nutritionFactor, "nutrimentFactor", 30.0f); serializer.DataField(ref _nutritionFactor, "nutrimentFactor", 30.0M);
} }
//Remove reagent at set rate, satiate hunger if a HungerComponent can be found //Remove reagent at set rate, satiate hunger if a HungerComponent can be found
int IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime) decimal IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime)
{ {
int metabolismAmount = (int)Math.Round(MetabolismRate * tickTime); var metabolismAmount = (MetabolismRate * (decimal) tickTime).RoundForReagents();
if (solutionEntity.TryGetComponent(out HungerComponent hunger)) if (solutionEntity.TryGetComponent(out HungerComponent hunger))
hunger.UpdateFood(metabolismAmount * NutritionFactor); hunger.UpdateFood((float)(metabolismAmount * NutritionFactor));
//Return amount of reagent to be removed, remove reagent regardless of HungerComponent presence //Return amount of reagent to be removed, remove reagent regardless of HungerComponent presence
return metabolismAmount; return metabolismAmount;

View File

@@ -35,9 +35,9 @@ namespace Content.Server.Chemistry.ReactionEffects
serializer.DataField(ref _maxScale, "maxScale", 1); serializer.DataField(ref _maxScale, "maxScale", 1);
} }
public void React(IEntity solutionEntity, int intensity) public void React(IEntity solutionEntity, decimal intensity)
{ {
float floatIntensity = intensity; //Use float to avoid truncation in scaling float floatIntensity = (float)intensity;
if (solutionEntity == null) if (solutionEntity == null)
return; return;
if(!solutionEntity.TryGetComponent(out SolutionComponent solution)) if(!solutionEntity.TryGetComponent(out SolutionComponent solution))

View File

@@ -37,7 +37,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
/// attempt to inject it's entire contents upon use. /// attempt to inject it's entire contents upon use.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
private int _transferAmount; private decimal _transferAmount;
/// <summary> /// <summary>
/// Initial storage volume of the injector /// Initial storage volume of the injector
@@ -165,7 +165,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
} }
//Get transfer amount. May be smaller than _transferAmount if not enough room //Get transfer amount. May be smaller than _transferAmount if not enough room
int realTransferAmount = Math.Min(_transferAmount, targetBloodstream.EmptyVolume); decimal realTransferAmount = Math.Min(_transferAmount, targetBloodstream.EmptyVolume);
if (realTransferAmount <= 0) if (realTransferAmount <= 0)
{ {
_notifyManager.PopupMessage(Owner.Transform.GridPosition, user, _notifyManager.PopupMessage(Owner.Transform.GridPosition, user,
@@ -193,7 +193,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
} }
//Get transfer amount. May be smaller than _transferAmount if not enough room //Get transfer amount. May be smaller than _transferAmount if not enough room
int realTransferAmount = Math.Min(_transferAmount, targetSolution.EmptyVolume); decimal realTransferAmount = Math.Min(_transferAmount, targetSolution.EmptyVolume);
if (realTransferAmount <= 0) if (realTransferAmount <= 0)
{ {
_notifyManager.PopupMessage(Owner.Transform.GridPosition, user, _notifyManager.PopupMessage(Owner.Transform.GridPosition, user,
@@ -221,7 +221,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
} }
//Get transfer amount. May be smaller than _transferAmount if not enough room //Get transfer amount. May be smaller than _transferAmount if not enough room
int realTransferAmount = Math.Min(_transferAmount, targetSolution.CurrentVolume); decimal realTransferAmount = Math.Min(_transferAmount, targetSolution.CurrentVolume);
if (realTransferAmount <= 0) if (realTransferAmount <= 0)
{ {
_notifyManager.PopupMessage(Owner.Transform.GridPosition, user, _notifyManager.PopupMessage(Owner.Transform.GridPosition, user,

View File

@@ -69,7 +69,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
return false; return false;
//Get transfer amount. May be smaller than _transferAmount if not enough room //Get transfer amount. May be smaller than _transferAmount if not enough room
int realTransferAmount = Math.Min(attackPourable.TransferAmount, targetSolution.EmptyVolume); decimal realTransferAmount = Math.Min(attackPourable.TransferAmount, targetSolution.EmptyVolume);
if (realTransferAmount <= 0) //Special message if container is full if (realTransferAmount <= 0) //Special message if container is full
{ {
_notifyManager.PopupMessage(Owner.Transform.GridPosition, eventArgs.User, _notifyManager.PopupMessage(Owner.Transform.GridPosition, eventArgs.User,

View File

@@ -7,6 +7,7 @@ using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces; using Content.Server.Interfaces;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Content.Shared.GameObjects; using Content.Shared.GameObjects;
using Content.Shared.Maths;
using Robust.Server.GameObjects.EntitySystems; using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
@@ -205,7 +206,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
//Check the solution for every reaction //Check the solution for every reaction
foreach (var reaction in _reactions) foreach (var reaction in _reactions)
{ {
if (SolutionValidReaction(reaction, out int unitReactions)) if (SolutionValidReaction(reaction, out var unitReactions))
{ {
PerformReaction(reaction, unitReactions); PerformReaction(reaction, unitReactions);
checkForNewReaction = true; checkForNewReaction = true;
@@ -223,11 +224,13 @@ namespace Content.Server.GameObjects.Components.Chemistry
} }
} }
public bool TryAddReagent(string reagentId, int quantity, out int acceptedQuantity, bool skipReactionCheck = false, bool skipColor = false) public bool TryAddReagent(string reagentId, decimal quantity, out decimal acceptedQuantity, bool skipReactionCheck = false, bool skipColor = false)
{ {
if (quantity > _maxVolume - _containedSolution.TotalVolume) quantity = quantity.RoundForReagents();
var toAcceptQuantity = (_maxVolume - _containedSolution.TotalVolume).RoundForReagents();
if (quantity > toAcceptQuantity)
{ {
acceptedQuantity = _maxVolume - _containedSolution.TotalVolume; acceptedQuantity = toAcceptQuantity;
if (acceptedQuantity == 0) return false; if (acceptedQuantity == 0) return false;
} }
else else
@@ -267,16 +270,16 @@ namespace Content.Server.GameObjects.Components.Chemistry
/// <param name="reaction">The reaction whose reactants will be checked for in the solution.</param> /// <param name="reaction">The reaction whose reactants will be checked for in the solution.</param>
/// <param name="unitReactions">The number of times the reaction can occur with the given solution.</param> /// <param name="unitReactions">The number of times the reaction can occur with the given solution.</param>
/// <returns></returns> /// <returns></returns>
private bool SolutionValidReaction(ReactionPrototype reaction, out int unitReactions) private bool SolutionValidReaction(ReactionPrototype reaction, out decimal unitReactions)
{ {
unitReactions = int.MaxValue; //Set to some impossibly large number initially unitReactions = decimal.MaxValue; //Set to some impossibly large number initially
foreach (var reactant in reaction.Reactants) foreach (var reactant in reaction.Reactants)
{ {
if (!ContainsReagent(reactant.Key, out int reagentQuantity)) if (!ContainsReagent(reactant.Key, out decimal reagentQuantity))
{ {
return false; return false;
} }
int currentUnitReactions = reagentQuantity / reactant.Value.Amount; var currentUnitReactions = (reagentQuantity / reactant.Value.Amount).RoundForReagents();
if (currentUnitReactions < unitReactions) if (currentUnitReactions < unitReactions)
{ {
unitReactions = currentUnitReactions; unitReactions = currentUnitReactions;
@@ -299,21 +302,21 @@ namespace Content.Server.GameObjects.Components.Chemistry
/// <param name="solution">Solution to be reacted.</param> /// <param name="solution">Solution to be reacted.</param>
/// <param name="reaction">Reaction to occur.</param> /// <param name="reaction">Reaction to occur.</param>
/// <param name="unitReactions">The number of times to cause this reaction.</param> /// <param name="unitReactions">The number of times to cause this reaction.</param>
private void PerformReaction(ReactionPrototype reaction, int unitReactions) private void PerformReaction(ReactionPrototype reaction, decimal unitReactions)
{ {
//Remove non-catalysts //Remove non-catalysts
foreach (var reactant in reaction.Reactants) foreach (var reactant in reaction.Reactants)
{ {
if (!reactant.Value.Catalyst) if (!reactant.Value.Catalyst)
{ {
int amountToRemove = unitReactions * reactant.Value.Amount; var amountToRemove = (unitReactions * reactant.Value.Amount).RoundForReagents();
TryRemoveReagent(reactant.Key, amountToRemove); TryRemoveReagent(reactant.Key, amountToRemove);
} }
} }
//Add products //Add products
foreach (var product in reaction.Products) foreach (var product in reaction.Products)
{ {
TryAddReagent(product.Key, (int)(unitReactions * product.Value), out int acceptedQuantity, true); TryAddReagent(product.Key, (int)(unitReactions * product.Value), out var acceptedQuantity, true);
} }
//Trigger reaction effects //Trigger reaction effects
foreach (var effect in reaction.Effects) foreach (var effect in reaction.Effects)

View File

@@ -39,7 +39,7 @@ namespace Content.Server.GameObjects.Components.Metabolism
/// <summary> /// <summary>
/// Empty volume of internal solution /// Empty volume of internal solution
/// </summary> /// </summary>
public int EmptyVolume => _internalSolution.EmptyVolume; public decimal EmptyVolume => _internalSolution.EmptyVolume;
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
{ {
@@ -98,7 +98,7 @@ namespace Content.Server.GameObjects.Components.Metabolism
//Run metabolism code for each reagent //Run metabolism code for each reagent
foreach (var metabolizable in proto.Metabolism) foreach (var metabolizable in proto.Metabolism)
{ {
int reagentDelta = metabolizable.Metabolize(Owner, reagent.ReagentId, tickTime); var reagentDelta = metabolizable.Metabolize(Owner, reagent.ReagentId, tickTime);
_internalSolution.TryRemoveReagent(reagent.ReagentId, reagentDelta); _internalSolution.TryRemoveReagent(reagent.ReagentId, reagentDelta);
} }
} }

View File

@@ -5,6 +5,7 @@ using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Nutrition; using Content.Shared.GameObjects.Components.Nutrition;
using Content.Shared.Interfaces; using Content.Shared.Interfaces;
using Content.Shared.Maths;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
@@ -32,11 +33,11 @@ namespace Content.Server.GameObjects.Components.Nutrition
[ViewVariables] [ViewVariables]
private string _finishPrototype; private string _finishPrototype;
public int TransferAmount => _transferAmount; public decimal TransferAmount => _transferAmount;
[ViewVariables] [ViewVariables]
private int _transferAmount = 2; private decimal _transferAmount = 2;
public int MaxVolume public decimal MaxVolume
{ {
get => _contents.MaxVolume; get => _contents.MaxVolume;
set => _contents.MaxVolume = value; set => _contents.MaxVolume = value;
@@ -56,7 +57,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
{ {
return 0; return 0;
} }
return Math.Max(1, _contents.CurrentVolume / _transferAmount); return Math.Max(1, (int)Math.Ceiling(_contents.CurrentVolume / _transferAmount));
} }

View File

@@ -99,7 +99,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
{ {
return 0; return 0;
} }
return Math.Max(1, _contents.CurrentVolume / _transferAmount); return Math.Max(1, (int)Math.Ceiling(_contents.CurrentVolume / _transferAmount));
} }
bool IUse.UseEntity(UseEntityEventArgs eventArgs) bool IUse.UseEntity(UseEntityEventArgs eventArgs)

View File

@@ -27,7 +27,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
/// <summary> /// <summary>
/// Max volume of internal solution storage /// Max volume of internal solution storage
/// </summary> /// </summary>
public int MaxVolume public decimal MaxVolume
{ {
get => _stomachContents.MaxVolume; get => _stomachContents.MaxVolume;
set => _stomachContents.MaxVolume = value; set => _stomachContents.MaxVolume = value;
@@ -141,10 +141,10 @@ namespace Content.Server.GameObjects.Components.Nutrition
private class ReagentDelta private class ReagentDelta
{ {
public readonly string ReagentId; public readonly string ReagentId;
public readonly int Quantity; public readonly decimal Quantity;
public float Lifetime { get; private set; } public float Lifetime { get; private set; }
public ReagentDelta(string reagentId, int quantity) public ReagentDelta(string reagentId, decimal quantity)
{ {
ReagentId = reagentId; ReagentId = reagentId;
Quantity = quantity; Quantity = quantity;

View File

@@ -8,6 +8,6 @@ namespace Content.Shared.Interfaces
/// </summary> /// </summary>
public interface IReactionEffect : IExposeData public interface IReactionEffect : IExposeData
{ {
void React(IEntity solutionEntity, int intensity); void React(IEntity solutionEntity, decimal intensity);
} }
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using Content.Shared.Interfaces.Chemistry; using Content.Shared.Interfaces.Chemistry;
using Content.Shared.Maths;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Serialization; using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -10,17 +11,17 @@ namespace Content.Shared.Chemistry
class DefaultMetabolizable : IMetabolizable class DefaultMetabolizable : IMetabolizable
{ {
//Rate of metabolism in units / second //Rate of metabolism in units / second
private int _metabolismRate = 1; private decimal _metabolismRate = 1;
public int MetabolismRate => _metabolismRate; public decimal MetabolismRate => _metabolismRate;
void IExposeData.ExposeData(ObjectSerializer serializer) void IExposeData.ExposeData(ObjectSerializer serializer)
{ {
serializer.DataField(ref _metabolismRate, "rate", 1); serializer.DataField(ref _metabolismRate, "rate", 1);
} }
int IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime) decimal IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime)
{ {
int metabolismAmount = (int)Math.Round(MetabolismRate * tickTime); var metabolismAmount = (MetabolismRate * (decimal)tickTime).RoundForReagents();
return metabolismAmount; return metabolismAmount;
} }
} }

View File

@@ -2,6 +2,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Content.Shared.Maths;
using Robust.Shared.Interfaces.Serialization; using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -23,7 +24,7 @@ namespace Content.Shared.Chemistry
/// 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 int TotalVolume { get; private set; } public decimal TotalVolume { get; private set; }
/// <summary> /// <summary>
/// Constructs an empty solution (ex. an empty beaker). /// Constructs an empty solution (ex. an empty beaker).
@@ -60,9 +61,10 @@ namespace Content.Shared.Chemistry
/// </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, int quantity) public void AddReagent(string reagentId, decimal quantity)
{ {
if(quantity <= 0) quantity = quantity.RoundForReagents();
if (quantity <= 0)
return; return;
for (var i = 0; i < _contents.Count; i++) for (var i = 0; i < _contents.Count; i++)
@@ -85,7 +87,7 @@ namespace Content.Shared.Chemistry
/// </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 int GetReagentQuantity(string reagentId) public decimal GetReagentQuantity(string reagentId)
{ {
for (var i = 0; i < _contents.Count; i++) for (var i = 0; i < _contents.Count; i++)
{ {
@@ -96,7 +98,7 @@ namespace Content.Shared.Chemistry
return 0; return 0;
} }
public void RemoveReagent(string reagentId, int quantity) public void RemoveReagent(string reagentId, decimal quantity)
{ {
if(quantity <= 0) if(quantity <= 0)
return; return;
@@ -109,7 +111,7 @@ namespace Content.Shared.Chemistry
var curQuantity = reagent.Quantity; var curQuantity = reagent.Quantity;
var newQuantity = curQuantity - quantity; var newQuantity = (curQuantity - quantity).RoundForReagents();
if (newQuantity <= 0) if (newQuantity <= 0)
{ {
_contents.RemoveSwap(i); _contents.RemoveSwap(i);
@@ -129,12 +131,12 @@ namespace Content.Shared.Chemistry
/// 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(int quantity) public void RemoveSolution(decimal quantity)
{ {
if(quantity <= 0) if(quantity <= 0)
return; return;
var ratio = (float)(TotalVolume - quantity) / TotalVolume; var ratio = (TotalVolume - quantity).RoundForReagents() / TotalVolume;
if (ratio <= 0) if (ratio <= 0)
{ {
@@ -149,12 +151,12 @@ namespace Content.Shared.Chemistry
// quantity taken is always a little greedy, so fractional quantities get rounded up to the nearest // quantity taken is always a little greedy, so fractional quantities get rounded up to the nearest
// whole unit. This should prevent little bits of chemical remaining because of float rounding errors. // whole unit. This should prevent little bits of chemical remaining because of float rounding errors.
var newQuantity = (int)Math.Floor(oldQuantity * ratio); var newQuantity = (oldQuantity * ratio).RoundForReagents();
_contents[i] = new ReagentQuantity(reagent.ReagentId, newQuantity); _contents[i] = new ReagentQuantity(reagent.ReagentId, newQuantity);
} }
TotalVolume = (int)Math.Floor(TotalVolume * ratio); TotalVolume = (TotalVolume * ratio).RoundForReagents();
} }
public void RemoveAllSolution() public void RemoveAllSolution()
@@ -163,7 +165,7 @@ namespace Content.Shared.Chemistry
TotalVolume = 0; TotalVolume = 0;
} }
public Solution SplitSolution(int quantity) public Solution SplitSolution(decimal quantity)
{ {
if (quantity <= 0) if (quantity <= 0)
return new Solution(); return new Solution();
@@ -178,8 +180,8 @@ namespace Content.Shared.Chemistry
} }
newSolution = new Solution(); newSolution = new Solution();
var newTotalVolume = 0; var newTotalVolume = 0M;
var ratio = (float)(TotalVolume - quantity) / TotalVolume; var ratio = (TotalVolume - quantity) / TotalVolume;
for (var i = 0; i < _contents.Count; i++) for (var i = 0; i < _contents.Count; i++)
{ {
@@ -228,7 +230,7 @@ namespace Content.Shared.Chemistry
public Solution Clone() public Solution Clone()
{ {
var volume = 0; var volume = 0M;
var newSolution = new Solution(); var newSolution = new Solution();
for (var i = 0; i < _contents.Count; i++) for (var i = 0; i < _contents.Count; i++)
@@ -246,9 +248,9 @@ namespace Content.Shared.Chemistry
public readonly struct ReagentQuantity public readonly struct ReagentQuantity
{ {
public readonly string ReagentId; public readonly string ReagentId;
public readonly int Quantity; public readonly decimal Quantity;
public ReagentQuantity(string reagentId, int quantity) public ReagentQuantity(string reagentId, decimal quantity)
{ {
ReagentId = reagentId; ReagentId = reagentId;
Quantity = quantity; Quantity = quantity;

View File

@@ -18,11 +18,11 @@ namespace Content.Shared.GameObjects.Components.Chemistry
[Serializable, NetSerializable] [Serializable, NetSerializable]
protected sealed class InjectorComponentState : ComponentState protected sealed class InjectorComponentState : ComponentState
{ {
public int CurrentVolume { get; } public decimal CurrentVolume { get; }
public int TotalVolume { get; } public decimal TotalVolume { get; }
public InjectorToggleMode CurrentMode { get; } public InjectorToggleMode CurrentMode { get; }
public InjectorComponentState(int currentVolume, int totalVolume, InjectorToggleMode currentMode) : base(ContentNetIDs.REAGENT_INJECTOR) public InjectorComponentState(decimal currentVolume, decimal totalVolume, InjectorToggleMode currentMode) : base(ContentNetIDs.REAGENT_INJECTOR)
{ {
CurrentVolume = currentVolume; CurrentVolume = currentVolume;
TotalVolume = totalVolume; TotalVolume = totalVolume;

View File

@@ -26,8 +26,8 @@ namespace Content.Shared.GameObjects.Components.Chemistry
public class ReagentDispenserBoundUserInterfaceState : BoundUserInterfaceState public class ReagentDispenserBoundUserInterfaceState : BoundUserInterfaceState
{ {
public readonly bool HasBeaker; public readonly bool HasBeaker;
public readonly int BeakerCurrentVolume; public readonly decimal BeakerCurrentVolume;
public readonly int BeakerMaxVolume; public readonly decimal 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 +38,10 @@ namespace Content.Shared.GameObjects.Components.Chemistry
/// </summary> /// </summary>
public readonly List<Solution.ReagentQuantity> ContainerReagents; public readonly List<Solution.ReagentQuantity> ContainerReagents;
public readonly string DispenserName; public readonly string DispenserName;
public readonly int SelectedDispenseAmount; public readonly decimal SelectedDispenseAmount;
public ReagentDispenserBoundUserInterfaceState(bool hasBeaker, int beakerCurrentVolume, int beakerMaxVolume, string containerName, public ReagentDispenserBoundUserInterfaceState(bool hasBeaker, decimal beakerCurrentVolume, decimal beakerMaxVolume, string containerName,
List<ReagentDispenserInventoryEntry> inventory, string dispenserName, List<Solution.ReagentQuantity> containerReagents, int selectedDispenseAmount) List<ReagentDispenserInventoryEntry> inventory, string dispenserName, List<Solution.ReagentQuantity> containerReagents, decimal selectedDispenseAmount)
{ {
HasBeaker = hasBeaker; HasBeaker = hasBeaker;
BeakerCurrentVolume = beakerCurrentVolume; BeakerCurrentVolume = beakerCurrentVolume;

View File

@@ -18,7 +18,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
[ViewVariables] [ViewVariables]
protected Solution _containedSolution = new Solution(); protected Solution _containedSolution = new Solution();
protected int _maxVolume; protected decimal _maxVolume;
private SolutionCaps _capabilities; private SolutionCaps _capabilities;
/// <summary> /// <summary>
@@ -30,7 +30,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
/// The maximum volume of the container. /// The maximum volume of the container.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public int MaxVolume public decimal MaxVolume
{ {
get => _maxVolume; get => _maxVolume;
set => _maxVolume = value; // Note that the contents won't spill out if the capacity is reduced. set => _maxVolume = value; // Note that the contents won't spill out if the capacity is reduced.
@@ -40,13 +40,13 @@ namespace Content.Shared.GameObjects.Components.Chemistry
/// The total volume of all the of the reagents in the container. /// The total volume of all the of the reagents in the container.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
public int CurrentVolume => _containedSolution.TotalVolume; public decimal CurrentVolume => _containedSolution.TotalVolume;
/// <summary> /// <summary>
/// The volume without reagents remaining in the container. /// The volume without reagents remaining in the container.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
public int EmptyVolume => MaxVolume - CurrentVolume; public decimal EmptyVolume => MaxVolume - CurrentVolume;
/// <summary> /// <summary>
/// The current blended color of all the reagents in the container. /// The current blended color of all the reagents in the container.
@@ -122,7 +122,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
OnSolutionChanged(); OnSolutionChanged();
} }
public bool TryRemoveReagent(string reagentId, int quantity) public bool TryRemoveReagent(string reagentId, decimal quantity)
{ {
if (!ContainsReagent(reagentId, out var currentQuantity)) return false; if (!ContainsReagent(reagentId, out var currentQuantity)) return false;
@@ -146,7 +146,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
return true; return true;
} }
public Solution SplitSolution(int quantity) public Solution SplitSolution(decimal quantity)
{ {
var solutionSplit = _containedSolution.SplitSolution(quantity); var solutionSplit = _containedSolution.SplitSolution(quantity);
OnSolutionChanged(); OnSolutionChanged();
@@ -159,7 +159,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
SubstanceColor = Color.White; SubstanceColor = Color.White;
Color mixColor = default; Color mixColor = default;
float runningTotalQuantity = 0; var runningTotalQuantity = 0M;
foreach (var reagent in _containedSolution) foreach (var reagent in _containedSolution)
{ {
@@ -171,7 +171,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
if (mixColor == default) if (mixColor == default)
mixColor = proto.SubstanceColor; mixColor = proto.SubstanceColor;
mixColor = BlendRGB(mixColor, proto.SubstanceColor, reagent.Quantity / runningTotalQuantity); mixColor = BlendRGB(mixColor, proto.SubstanceColor, (float) (reagent.Quantity / runningTotalQuantity));
} }
} }
@@ -216,7 +216,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
/// <param name="reagentId">The reagent to check for.</param> /// <param name="reagentId">The reagent to check for.</param>
/// <param name="quantity">Output the quantity of the reagent if it is contained, 0 if it isn't.</param> /// <param name="quantity">Output the quantity of the reagent if it is contained, 0 if it isn't.</param>
/// <returns>Return true if the solution contains the reagent.</returns> /// <returns>Return true if the solution contains the reagent.</returns>
public bool ContainsReagent(string reagentId, out int quantity) public bool ContainsReagent(string reagentId, out decimal quantity)
{ {
foreach (var reagent in _containedSolution.Contents) foreach (var reagent in _containedSolution.Contents)
{ {

View File

@@ -19,6 +19,6 @@ namespace Content.Shared.Interfaces.Chemistry
/// <param name="reagentId">The reagent id</param> /// <param name="reagentId">The reagent id</param>
/// <param name="tickTime">The time since the last metabolism tick in seconds.</param> /// <param name="tickTime">The time since the last metabolism tick in seconds.</param>
/// <returns>The amount of reagent to be removed. The metabolizing organ should handle removing the reagent.</returns> /// <returns>The amount of reagent to be removed. The metabolizing organ should handle removing the reagent.</returns>
int Metabolize(IEntity solutionEntity, string reagentId, float tickTime); decimal Metabolize(IEntity solutionEntity, string reagentId, float tickTime);
} }
} }

View File

@@ -0,0 +1,12 @@
using System;
namespace Content.Shared.Maths
{
public static class Rounders
{
public static decimal RoundForReagents(this decimal me)
{
return Math.Round(me, 2);
}
}
}