Merge branch 'master' into replace-sounds-with-sound-specifier

# Conflicts:
#	Content.Server/Hands/Components/HandsComponent.cs
#	Content.Server/Light/Components/ExpendableLightComponent.cs
#	Content.Shared/Light/Component/SharedExpendableLightComponent.cs
This commit is contained in:
Galactic Chimp
2021-07-31 13:16:03 +02:00
105 changed files with 1483 additions and 1319 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;
}
}
}

View File

@@ -30,6 +30,8 @@ namespace Content.Server.Body.Behavior
/// </param>
public override void Update(float frameTime)
{
// Do not metabolise if the organ does not have a body.
if (Body == null)
{
return;
@@ -45,7 +47,9 @@ namespace Content.Server.Body.Behavior
_accumulatedFrameTime -= 1;
if (!Body.Owner.TryGetComponent(out SolutionContainerComponent? solution) ||
// Note that "Owner" should be the organ that has this behaviour/mechanism, and it should have a dedicated
// solution container. "Body.Owner" is something else, and may have more than one solution container.
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution) ||
!Body.Owner.TryGetComponent(out BloodstreamComponent? bloodstream))
{
return;
@@ -61,8 +65,19 @@ namespace Content.Server.Body.Behavior
delta.Increment(1);
if (delta.Lifetime > _digestionDelay)
{
solution.TryRemoveReagent(delta.ReagentId, delta.Quantity);
transferSolution.AddReagent(delta.ReagentId, delta.Quantity);
// This reagent has been in the somach long enough, TRY to transfer it.
// But first, check if the reagent still exists, and how much is left.
// Some poor spessman may have washed down a potassium snack with some water.
if (solution.Solution.ContainsReagent(delta.ReagentId, out ReagentUnit quantity)){
if (quantity > delta.Quantity) {
quantity = delta.Quantity;
}
solution.TryRemoveReagent(delta.ReagentId, quantity);
transferSolution.AddReagent(delta.ReagentId, quantity);
}
_reagentDeltas.Remove(delta);
}
}
@@ -133,10 +148,10 @@ namespace Content.Server.Body.Behavior
public bool TryTransferSolution(Solution solution)
{
if (Body == null || !CanTransferSolution(solution))
if (Owner == null || !CanTransferSolution(solution))
return false;
if (!Body.Owner.TryGetComponent(out SolutionContainerComponent? solutionComponent))
if (!Owner.TryGetComponent(out SolutionContainerComponent? solutionComponent))
{
return false;
}