Hunger and thirst won't infinitely decrease below zero (#11367)

This commit is contained in:
corentt
2022-09-17 16:26:39 +02:00
committed by GitHub
parent 611b11976e
commit b94086ee0a
2 changed files with 4 additions and 4 deletions

View File

@@ -151,14 +151,14 @@ namespace Content.Server.Nutrition.Components
public void UpdateFood(float amount) public void UpdateFood(float amount)
{ {
_currentHunger = Math.Min(_currentHunger + amount, HungerThresholds[HungerThreshold.Overfed]); _currentHunger = Math.Clamp(_currentHunger + amount, HungerThresholds[HungerThreshold.Dead], HungerThresholds[HungerThreshold.Overfed]);
} }
// TODO: If mob is moving increase rate of consumption? // TODO: If mob is moving increase rate of consumption?
// Should use a multiplier as something like a disease would overwrite decay rate. // Should use a multiplier as something like a disease would overwrite decay rate.
public void OnUpdate(float frametime) public void OnUpdate(float frametime)
{ {
_currentHunger -= frametime * ActualDecayRate; UpdateFood(- frametime * ActualDecayRate);
UpdateCurrentThreshold(); UpdateCurrentThreshold();
} }

View File

@@ -72,7 +72,7 @@ namespace Content.Server.Nutrition.EntitySystems
public void UpdateThirst(ThirstComponent component, float amount) public void UpdateThirst(ThirstComponent component, float amount)
{ {
component.CurrentThirst = Math.Min(component.CurrentThirst + amount, component.ThirstThresholds[ThirstThreshold.OverHydrated]); component.CurrentThirst = Math.Clamp(component.CurrentThirst + amount, component.ThirstThresholds[ThirstThreshold.Dead], component.ThirstThresholds[ThirstThreshold.OverHydrated]);
} }
public void ResetThirst(ThirstComponent component) public void ResetThirst(ThirstComponent component)
@@ -153,7 +153,7 @@ namespace Content.Server.Nutrition.EntitySystems
{ {
foreach (var component in EntityManager.EntityQuery<ThirstComponent>()) foreach (var component in EntityManager.EntityQuery<ThirstComponent>())
{ {
component.CurrentThirst -= component.ActualDecayRate; UpdateThirst(component, - component.ActualDecayRate);
var calculatedThirstThreshold = GetThirstThreshold(component, component.CurrentThirst); var calculatedThirstThreshold = GetThirstThreshold(component, component.CurrentThirst);
if (calculatedThirstThreshold != component.CurrentThirstThreshold) if (calculatedThirstThreshold != component.CurrentThirstThreshold)
{ {