Replace decimal with ReagentUnit
This commit is contained in:
@@ -37,13 +37,13 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
/// attempt to inject it's entire contents upon use.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private decimal _transferAmount;
|
||||
private ReagentUnit _transferAmount;
|
||||
|
||||
/// <summary>
|
||||
/// Initial storage volume of the injector
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private int _initialMaxVolume;
|
||||
private ReagentUnit _initialMaxVolume;
|
||||
|
||||
/// <summary>
|
||||
/// The state of the injector. Determines it's attack behavior. Containers must have the
|
||||
@@ -62,8 +62,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(ref _injectOnly, "injectOnly", false);
|
||||
serializer.DataField(ref _initialMaxVolume, "initialMaxVolume", 15);
|
||||
serializer.DataField(ref _transferAmount, "transferAmount", 5);
|
||||
serializer.DataField(ref _initialMaxVolume, "initialMaxVolume", ReagentUnit.New(15));
|
||||
serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(5));
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
@@ -165,7 +165,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
decimal realTransferAmount = Math.Min(_transferAmount, targetBloodstream.EmptyVolume);
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetBloodstream.EmptyVolume);
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
_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
|
||||
decimal realTransferAmount = Math.Min(_transferAmount, targetSolution.EmptyVolume);
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.EmptyVolume);
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
_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
|
||||
decimal realTransferAmount = Math.Min(_transferAmount, targetSolution.CurrentVolume);
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.CurrentVolume);
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner.Transform.GridPosition, user,
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Text;
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Shared.Chemistry;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -28,13 +29,13 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
public override string Name => "Pourable";
|
||||
|
||||
private decimal _transferAmount;
|
||||
private ReagentUnit _transferAmount;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of solution to be transferred from this solution when clicking on other solutions with it.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public decimal TransferAmount
|
||||
public ReagentUnit TransferAmount
|
||||
{
|
||||
get => _transferAmount;
|
||||
set => _transferAmount = value;
|
||||
@@ -43,7 +44,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(ref _transferAmount, "transferAmount", 5.0M);
|
||||
serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(5.0M));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -69,7 +70,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
return false;
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
decimal realTransferAmount = Math.Min(attackPourable.TransferAmount, targetSolution.EmptyVolume);
|
||||
var realTransferAmount = ReagentUnit.Min(attackPourable.TransferAmount, targetSolution.EmptyVolume);
|
||||
if (realTransferAmount <= 0) //Special message if container is full
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner.Transform.GridPosition, eventArgs.User,
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
[ViewVariables] private string _packPrototypeId;
|
||||
|
||||
[ViewVariables] private bool HasBeaker => _beakerContainer.ContainedEntity != null;
|
||||
[ViewVariables] private decimal _dispenseAmount = 10;
|
||||
[ViewVariables] private ReagentUnit _dispenseAmount = ReagentUnit.New(10);
|
||||
|
||||
[ViewVariables]
|
||||
private SolutionComponent Solution => _beakerContainer.ContainedEntity.GetComponent<SolutionComponent>();
|
||||
@@ -115,22 +115,22 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
TryClear();
|
||||
break;
|
||||
case UiButton.SetDispenseAmount1:
|
||||
_dispenseAmount = 1;
|
||||
_dispenseAmount = ReagentUnit.New(1);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount5:
|
||||
_dispenseAmount = 5;
|
||||
_dispenseAmount = ReagentUnit.New(5);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount10:
|
||||
_dispenseAmount = 10;
|
||||
_dispenseAmount = ReagentUnit.New(10);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount25:
|
||||
_dispenseAmount = 25;
|
||||
_dispenseAmount = ReagentUnit.New(25);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount50:
|
||||
_dispenseAmount = 50;
|
||||
_dispenseAmount = ReagentUnit.New(50);
|
||||
break;
|
||||
case UiButton.SetDispenseAmount100:
|
||||
_dispenseAmount = 100;
|
||||
_dispenseAmount = ReagentUnit.New(100);
|
||||
break;
|
||||
case UiButton.Dispense:
|
||||
if (HasBeaker)
|
||||
@@ -172,7 +172,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
var beaker = _beakerContainer.ContainedEntity;
|
||||
if (beaker == null)
|
||||
{
|
||||
return new ReagentDispenserBoundUserInterfaceState(false, 0, 0,
|
||||
return new ReagentDispenserBoundUserInterfaceState(false, ReagentUnit.New(0), ReagentUnit.New(0),
|
||||
"", Inventory, Owner.Name, null, _dispenseAmount);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
internal class SolutionComponent : Shared.GameObjects.Components.Chemistry.SolutionComponent, IExamine
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IRounderForReagents _rounder;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager;
|
||||
[Dependency] private readonly ILocalizationManager _loc;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||
@@ -105,8 +104,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
if ((handSolutionComp.Capabilities & SolutionCaps.PourOut) == 0 || (component.Capabilities & SolutionCaps.PourIn) == 0)
|
||||
return;
|
||||
|
||||
var transferQuantity = Math.Min(component.MaxVolume - component.CurrentVolume, handSolutionComp.CurrentVolume);
|
||||
transferQuantity = Math.Min(transferQuantity, 10);
|
||||
var transferQuantity = ReagentUnit.Min(component.MaxVolume - component.CurrentVolume, handSolutionComp.CurrentVolume, ReagentUnit.New(10));
|
||||
|
||||
// nothing to transfer
|
||||
if (transferQuantity <= 0)
|
||||
@@ -185,8 +183,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
if ((handSolutionComp.Capabilities & SolutionCaps.PourIn) == 0 || (component.Capabilities & SolutionCaps.PourOut) == 0)
|
||||
return;
|
||||
|
||||
var transferQuantity = Math.Min(handSolutionComp.MaxVolume - handSolutionComp.CurrentVolume, component.CurrentVolume);
|
||||
transferQuantity = Math.Min(transferQuantity, 10);
|
||||
var transferQuantity = ReagentUnit.Min(handSolutionComp.MaxVolume - handSolutionComp.CurrentVolume, component.CurrentVolume, ReagentUnit.New(10));
|
||||
|
||||
// pulling from an empty container, pointless to continue
|
||||
if (transferQuantity <= 0)
|
||||
@@ -223,10 +220,9 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryAddReagent(string reagentId, decimal quantity, out decimal acceptedQuantity, bool skipReactionCheck = false, bool skipColor = false)
|
||||
public bool TryAddReagent(string reagentId, ReagentUnit quantity, out ReagentUnit acceptedQuantity, bool skipReactionCheck = false, bool skipColor = false)
|
||||
{
|
||||
quantity = _rounder.Round(quantity);
|
||||
var toAcceptQuantity = _rounder.Round(MaxVolume - ContainedSolution.TotalVolume);
|
||||
var toAcceptQuantity = MaxVolume - ContainedSolution.TotalVolume;
|
||||
if (quantity > toAcceptQuantity)
|
||||
{
|
||||
acceptedQuantity = toAcceptQuantity;
|
||||
@@ -269,16 +265,16 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
/// <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>
|
||||
/// <returns></returns>
|
||||
private bool SolutionValidReaction(ReactionPrototype reaction, out decimal unitReactions)
|
||||
private bool SolutionValidReaction(ReactionPrototype reaction, out ReagentUnit unitReactions)
|
||||
{
|
||||
unitReactions = decimal.MaxValue; //Set to some impossibly large number initially
|
||||
unitReactions = ReagentUnit.MaxValue; //Set to some impossibly large number initially
|
||||
foreach (var reactant in reaction.Reactants)
|
||||
{
|
||||
if (!ContainsReagent(reactant.Key, out decimal reagentQuantity))
|
||||
if (!ContainsReagent(reactant.Key, out ReagentUnit reagentQuantity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var currentUnitReactions = _rounder.Round(reagentQuantity / reactant.Value.Amount);
|
||||
var currentUnitReactions = reagentQuantity / reactant.Value.Amount;
|
||||
if (currentUnitReactions < unitReactions)
|
||||
{
|
||||
unitReactions = currentUnitReactions;
|
||||
@@ -301,26 +297,26 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
/// <param name="solution">Solution to be reacted.</param>
|
||||
/// <param name="reaction">Reaction to occur.</param>
|
||||
/// <param name="unitReactions">The number of times to cause this reaction.</param>
|
||||
private void PerformReaction(ReactionPrototype reaction, decimal unitReactions)
|
||||
private void PerformReaction(ReactionPrototype reaction, ReagentUnit unitReactions)
|
||||
{
|
||||
//Remove non-catalysts
|
||||
foreach (var reactant in reaction.Reactants)
|
||||
{
|
||||
if (!reactant.Value.Catalyst)
|
||||
{
|
||||
var amountToRemove = _rounder.Round(unitReactions * reactant.Value.Amount);
|
||||
var amountToRemove = unitReactions * reactant.Value.Amount;
|
||||
TryRemoveReagent(reactant.Key, amountToRemove);
|
||||
}
|
||||
}
|
||||
//Add products
|
||||
foreach (var product in reaction.Products)
|
||||
{
|
||||
TryAddReagent(product.Key, (int)(unitReactions * product.Value), out var acceptedQuantity, true);
|
||||
TryAddReagent(product.Key, product.Value * unitReactions, out var acceptedQuantity, true);
|
||||
}
|
||||
//Trigger reaction effects
|
||||
foreach (var effect in reaction.Effects)
|
||||
{
|
||||
effect.React(Owner, unitReactions);
|
||||
effect.React(Owner, unitReactions.Decimal());
|
||||
}
|
||||
|
||||
//Play reaction sound client-side
|
||||
|
||||
Reference in New Issue
Block a user