Adds DamageMetabolism and some simple chems (#3958)

* adds damage metabolism

* tweaks words

* metabolism is kinda weird

* adds some simple chemicals

* renames DamageMetabolism to HealthChangeMetabolism

* tweaks like one chemical because it was annoying

* did some changes that the sloth told me to

* adds summary comments for those foolish enough to try and understand my code

* rewrites the component so that is uses a more elegant solution, and handles decimals

* Updates with suggestions from review

* changes stuff idk:

* git cringe

* changes one tiny lil thing

* Apply YAML suggestions

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
ScalyChimp
2021-06-05 14:23:09 +08:00
committed by GitHub
parent 0315aa0dbc
commit 31fc7f63b5
2 changed files with 115 additions and 2 deletions

View File

@@ -0,0 +1,68 @@
using Content.Server.GameObjects.Components.Nutrition;
using Content.Shared.Chemistry;
using Content.Shared.Interfaces.Chemistry;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Content.Shared.Damage;
using Content.Shared.GameObjects.Components.Damage;
namespace Content.Server.Chemistry.Metabolism
{
/// <summary>
/// Default metabolism for medicine reagents. Attempts to find a DamageableComponent on the target,
/// and to update its damage values.
/// </summary>
[DataDefinition]
public class HealthChangeMetabolism : IMetabolizable
{
/// <summary>
/// How much of the reagent should be metabolized each sec.
/// </summary>
[DataField("rate")]
public ReagentUnit MetabolismRate { get; set; } = ReagentUnit.New(1);
/// <summary>
/// How much damage is changed when 1u of the reagent is metabolized.
/// </summary>
[DataField("healthChange")]
public float HealthChange { get; set; } = 1.0f;
/// <summary>
/// Class of damage changed, Brute, Burn, Toxin, Airloss.
/// </summary>
[DataField("damageClass")]
public DamageClass DamageType { get; set; } = DamageClass.Brute;
private float _accumulatedHealth;
/// <summary>
/// Remove reagent at set rate, changes damage if a DamageableComponent can be found.
/// </summary>
/// <param name="solutionEntity"></param>
/// <param name="reagentId"></param>
/// <param name="tickTime"></param>
/// <returns></returns>
ReagentUnit IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime)
{
if (solutionEntity.TryGetComponent(out IDamageableComponent? health))
{
health.ChangeDamage(DamageType, (int)HealthChange, true);
float decHealthChange = (float) (HealthChange - (int) HealthChange);
_accumulatedHealth += decHealthChange;
if (_accumulatedHealth >= 1)
{
health.ChangeDamage(DamageType, 1, true);
_accumulatedHealth -= 1;
}
else if(_accumulatedHealth <= -1)
{
health.ChangeDamage(DamageType, -1, true);
_accumulatedHealth += 1;
}
}
return MetabolismRate;
}
}
}