Replaced static Rounders with an impleneted interface
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Content.Shared.Interfaces.Chemistry;
|
||||
using Content.Shared.Maths;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.Chemistry.Metabolism
|
||||
@@ -14,6 +13,9 @@ namespace Content.Server.Chemistry.Metabolism
|
||||
/// </summary>
|
||||
class DefaultFood : IMetabolizable
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IRounderForReagents _rounder;
|
||||
#pragma warning restore 649
|
||||
//Rate of metabolism in units / second
|
||||
private decimal _metabolismRate;
|
||||
public decimal MetabolismRate => _metabolismRate;
|
||||
@@ -31,7 +33,7 @@ namespace Content.Server.Chemistry.Metabolism
|
||||
//Remove reagent at set rate, satiate hunger if a HungerComponent can be found
|
||||
decimal IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime)
|
||||
{
|
||||
var metabolismAmount = (MetabolismRate * (decimal) tickTime).RoundForReagents();
|
||||
var metabolismAmount = _rounder.Round(MetabolismRate * (decimal) tickTime);
|
||||
if (solutionEntity.TryGetComponent(out HungerComponent hunger))
|
||||
hunger.UpdateFood((float)(metabolismAmount * NutritionFactor));
|
||||
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using Content.Server.Chemistry;
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Content.Server.Chemistry;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.Maths;
|
||||
using Content.Shared.Interfaces.Chemistry;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
@@ -15,6 +10,8 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
@@ -25,6 +22,7 @@ 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;
|
||||
@@ -226,8 +224,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
public bool TryAddReagent(string reagentId, decimal quantity, out decimal acceptedQuantity, bool skipReactionCheck = false, bool skipColor = false)
|
||||
{
|
||||
quantity = quantity.RoundForReagents();
|
||||
var toAcceptQuantity = (_maxVolume - _containedSolution.TotalVolume).RoundForReagents();
|
||||
quantity = _rounder.Round(quantity);
|
||||
var toAcceptQuantity = _rounder.Round(MaxVolume - ContainedSolution.TotalVolume);
|
||||
if (quantity > toAcceptQuantity)
|
||||
{
|
||||
acceptedQuantity = toAcceptQuantity;
|
||||
@@ -238,7 +236,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
acceptedQuantity = quantity;
|
||||
}
|
||||
|
||||
_containedSolution.AddReagent(reagentId, acceptedQuantity);
|
||||
ContainedSolution.AddReagent(reagentId, acceptedQuantity);
|
||||
if (!skipColor) {
|
||||
RecalculateColor();
|
||||
}
|
||||
@@ -250,10 +248,10 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
public bool TryAddSolution(Solution solution, bool skipReactionCheck = false, bool skipColor = false)
|
||||
{
|
||||
if (solution.TotalVolume > (_maxVolume - _containedSolution.TotalVolume))
|
||||
if (solution.TotalVolume > (MaxVolume - ContainedSolution.TotalVolume))
|
||||
return false;
|
||||
|
||||
_containedSolution.AddSolution(solution);
|
||||
ContainedSolution.AddSolution(solution);
|
||||
if (!skipColor) {
|
||||
RecalculateColor();
|
||||
}
|
||||
@@ -279,7 +277,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var currentUnitReactions = (reagentQuantity / reactant.Value.Amount).RoundForReagents();
|
||||
var currentUnitReactions = _rounder.Round(reagentQuantity / reactant.Value.Amount);
|
||||
if (currentUnitReactions < unitReactions)
|
||||
{
|
||||
unitReactions = currentUnitReactions;
|
||||
@@ -309,7 +307,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
if (!reactant.Value.Catalyst)
|
||||
{
|
||||
var amountToRemove = (unitReactions * reactant.Value.Amount).RoundForReagents();
|
||||
var amountToRemove = _rounder.Round(unitReactions * reactant.Value.Amount);
|
||||
TryRemoveReagent(reactant.Key, amountToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Server.Cargo;
|
||||
using Content.Server.Cargo;
|
||||
using Content.Server.Chat;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Interfaces;
|
||||
@@ -7,7 +7,9 @@ using Content.Server.Interfaces.GameTicking;
|
||||
using Content.Server.Preferences;
|
||||
using Content.Server.Sandbox;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.Chemistry;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server
|
||||
@@ -26,6 +28,7 @@ namespace Content.Server
|
||||
IoCManager.Register<ICargoOrderDataManager, CargoOrderDataManager>();
|
||||
IoCManager.Register<IModuleManager, ServerModuleManager>();
|
||||
IoCManager.Register<IServerPreferencesManager, ServerPreferencesManager>();
|
||||
IoCManager.Register<IRounderForReagents, RounderForReagents>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user