Replace decimal with ReagentUnit
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Interfaces.Chemistry;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
@@ -14,8 +15,8 @@ namespace Content.Server.Chemistry.Metabolism
|
||||
class DefaultDrink : IMetabolizable
|
||||
{
|
||||
//Rate of metabolism in units / second
|
||||
private int _metabolismRate;
|
||||
public int MetabolismRate => _metabolismRate;
|
||||
private ReagentUnit _metabolismRate;
|
||||
public ReagentUnit MetabolismRate => _metabolismRate;
|
||||
|
||||
//How much thirst is satiated when 1u of the reagent is metabolized
|
||||
private float _hydrationFactor;
|
||||
@@ -23,16 +24,16 @@ namespace Content.Server.Chemistry.Metabolism
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(ref _metabolismRate, "rate", 1);
|
||||
serializer.DataField(ref _metabolismRate, "rate", ReagentUnit.New(1));
|
||||
serializer.DataField(ref _hydrationFactor, "nutrimentFactor", 30.0f);
|
||||
}
|
||||
|
||||
//Remove reagent at set rate, satiate thirst if a ThirstComponent can be found
|
||||
decimal IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime)
|
||||
ReagentUnit IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime)
|
||||
{
|
||||
int metabolismAmount = (int)Math.Round(MetabolismRate * tickTime);
|
||||
var metabolismAmount = MetabolismRate * tickTime;
|
||||
if (solutionEntity.TryGetComponent(out ThirstComponent thirst))
|
||||
thirst.UpdateThirst(metabolismAmount * HydrationFactor);
|
||||
thirst.UpdateThirst(metabolismAmount.Float() * HydrationFactor);
|
||||
|
||||
//Return amount of reagent to be removed, remove reagent regardless of ThirstComponent presence
|
||||
return metabolismAmount;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Interfaces.Chemistry;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
@@ -13,29 +14,26 @@ 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;
|
||||
private ReagentUnit _metabolismRate;
|
||||
public ReagentUnit MetabolismRate => _metabolismRate;
|
||||
|
||||
//How much hunger is satiated when 1u of the reagent is metabolized
|
||||
private decimal _nutritionFactor;
|
||||
public decimal NutritionFactor => _nutritionFactor;
|
||||
private float _nutritionFactor;
|
||||
public float NutritionFactor => _nutritionFactor;
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(ref _metabolismRate, "rate", 1M);
|
||||
serializer.DataField(ref _nutritionFactor, "nutrimentFactor", 30.0M);
|
||||
serializer.DataField(ref _metabolismRate, "rate", ReagentUnit.New(1M));
|
||||
serializer.DataField(ref _nutritionFactor, "nutrimentFactor", 30.0f);
|
||||
}
|
||||
|
||||
//Remove reagent at set rate, satiate hunger if a HungerComponent can be found
|
||||
decimal IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime)
|
||||
ReagentUnit IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime)
|
||||
{
|
||||
var metabolismAmount = _rounder.Round(MetabolismRate * (decimal) tickTime);
|
||||
var metabolismAmount = MetabolismRate * tickTime;
|
||||
if (solutionEntity.TryGetComponent(out HungerComponent hunger))
|
||||
hunger.UpdateFood((float)(metabolismAmount * NutritionFactor));
|
||||
hunger.UpdateFood(metabolismAmount.Float() * NutritionFactor);
|
||||
|
||||
//Return amount of reagent to be removed, remove reagent regardless of HungerComponent presence
|
||||
return metabolismAmount;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -16,7 +17,7 @@ namespace Content.Server.Chemistry
|
||||
private string _id;
|
||||
private string _name;
|
||||
private Dictionary<string, ReactantPrototype> _reactants;
|
||||
private Dictionary<string, uint> _products;
|
||||
private Dictionary<string, ReagentUnit> _products;
|
||||
private List<IReactionEffect> _effects;
|
||||
|
||||
public string ID => _id;
|
||||
@@ -28,7 +29,7 @@ namespace Content.Server.Chemistry
|
||||
/// <summary>
|
||||
/// Reagents created when the reaction occurs.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, uint> Products => _products;
|
||||
public IReadOnlyDictionary<string, ReagentUnit> Products => _products;
|
||||
/// <summary>
|
||||
/// Effects to be triggered when the reaction occurs.
|
||||
/// </summary>
|
||||
@@ -41,7 +42,7 @@ namespace Content.Server.Chemistry
|
||||
serializer.DataField(ref _id, "id", string.Empty);
|
||||
serializer.DataField(ref _name, "name", string.Empty);
|
||||
serializer.DataField(ref _reactants, "reactants", new Dictionary<string, ReactantPrototype>());
|
||||
serializer.DataField(ref _products, "products", new Dictionary<string, uint>());
|
||||
serializer.DataField(ref _products, "products", new Dictionary<string, ReagentUnit>());
|
||||
serializer.DataField(ref _effects, "effects", new List<IReactionEffect>());
|
||||
}
|
||||
}
|
||||
@@ -51,13 +52,13 @@ namespace Content.Server.Chemistry
|
||||
/// </summary>
|
||||
public class ReactantPrototype : IExposeData
|
||||
{
|
||||
private int _amount;
|
||||
private ReagentUnit _amount;
|
||||
private bool _catalyst;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum amount of the reactant needed for the reaction to occur.
|
||||
/// </summary>
|
||||
public int Amount => _amount;
|
||||
public ReagentUnit Amount => _amount;
|
||||
/// <summary>
|
||||
/// Whether or not the reactant is a catalyst. Catalysts aren't removed when a reaction occurs.
|
||||
/// </summary>
|
||||
@@ -65,7 +66,7 @@ namespace Content.Server.Chemistry
|
||||
|
||||
public void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(ref _amount, "amount", 1);
|
||||
serializer.DataField(ref _amount, "amount", ReagentUnit.New(1));
|
||||
serializer.DataField(ref _catalyst, "catalyst", false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user