Bug fixes for metabolisable reagents (#4385)

* HealthChangeMetabolism now scales with ticktime and metabolism rate

Both Food and Drink metabolisms scale with ticktime, Now HealthChangeMetabolism also does so.

Additionally, 'healthChange' now correctly scales with the metabolism rate, so it's description is now correct.

* LiverBehaviour now uses correct frameTime

Previously, the liver only metabolised reagants once every second, but incorrectly passes the current frameTime to the metabilism function, not 1 second.

* Stomach now only transfers non-empty solutions.

Makes debugging bloodstream bugs easier if the stomach is not constantly adding empty solution to it.

* Fixed StomachBehaviour using wrong SolutionContainerComponent

Stomach was using the first SolutionContainerComponent in the owner of the body, instead of the container in the owner of the mechanism (stomach). As a result, it used to use the BloodStreamComponent.Solution as a "Stomach".

* Update StomachBehavior.cs

Somach now checks if it still contains a reagant, before transferring it.

* Added argument to IMetabolizable.Metabolize()

Added availableReagent argument to IMetabolizable.Metabolize(), This ensures that this function does not over-metabolize a reagant, which can happen if tickTime*metabolismRate is larger than the available reagant

* Revert "Stomach now only transfers non-empty solutions."

This reverts commit 2a51e2d87e6e17ab76b48e5316ce501ec05ac061.

* Renamed _updateInterval to _updateIntervalSeconds

Also modified doc comment specifying units

* Fix spelling of healthChangeAmount

Changed from healthChangeAmmount to healthChangeAmount

* Fixed comment

comment used to mention _updateInterval, which has been renamed  _updateIntervalSeconds

* Fixed typo in comment

* fixed typos: reagant -> reagent

Most typos were just in comments.

* Make metabolizable classes inherit from DefaultMetabolizable

Also involved changing around IMetabolizable

* Renamed variables

metabolismAmount -> amountMetabolized

* Updated Comments in DefaultMetabolizable

Makes it clearer why DefaultMetabolizable works as it does, and that other classes depend on it.
This commit is contained in:
Leon Friedrich
2021-07-31 14:11:02 +10:00
committed by GitHub
parent 881c9c9856
commit dbc90f202a
7 changed files with 96 additions and 55 deletions

View File

@@ -17,6 +17,11 @@ namespace Content.Server.Body.Behavior
private float _accumulatedFrameTime;
/// <summary>
/// Delay time that determines how often to metabolise blood contents (in seconds).
/// </summary>
private float _updateIntervalSeconds = 1.0f;
/// <summary>
/// Whether the liver is functional.
/// </summary>
@@ -63,13 +68,13 @@ namespace Content.Server.Body.Behavior
_accumulatedFrameTime += frameTime;
// Update at most once per second
if (_accumulatedFrameTime < 1)
// Update at most once every _updateIntervalSeconds
if (_accumulatedFrameTime < _updateIntervalSeconds)
{
return;
}
_accumulatedFrameTime -= 1;
_accumulatedFrameTime -= _updateIntervalSeconds;
if (!Body.Owner.TryGetComponent(out BloodstreamComponent? bloodstream))
{
@@ -90,6 +95,10 @@ namespace Content.Server.Body.Behavior
continue;
}
// How much reagent is available to metabolise?
// This needs to be passed to other functions that have metabolism rate information, such that they don't "overmetabolise" a reagent.
var availableReagent = bloodstream.Solution.Solution.GetReagentQuantity(reagent.ReagentId);
//TODO BODY Check if it's a Toxin. If volume < _toxinTolerance, just remove it. If greater, add damage = volume * _toxinLethality
//TODO BODY Check if it has BoozePower > 0. Affect drunkenness, apply damage. Proposed formula (SS13-derived): damage = sqrt(volume) * BoozePower^_alcoholExponent * _alcoholLethality / 10
//TODO BODY Liver failure.
@@ -99,8 +108,9 @@ namespace Content.Server.Body.Behavior
// Run metabolism code for each reagent
foreach (var metabolizable in prototype.Metabolism)
{
var reagentDelta = metabolizable.Metabolize(Body.Owner, reagent.ReagentId, frameTime);
var reagentDelta = metabolizable.Metabolize(Body.Owner, reagent.ReagentId, _updateIntervalSeconds, availableReagent);
bloodstream.Solution.TryRemoveReagent(reagent.ReagentId, reagentDelta);
availableReagent -= reagentDelta;
}
}
}