diff --git a/Content.Server/Chemistry/ReagentEffects/SatiateThirst.cs b/Content.Server/Chemistry/ReagentEffects/SatiateThirst.cs index 529aa8adf1..1208e74367 100644 --- a/Content.Server/Chemistry/ReagentEffects/SatiateThirst.cs +++ b/Content.Server/Chemistry/ReagentEffects/SatiateThirst.cs @@ -1,6 +1,6 @@ -using Content.Server.Nutrition.EntitySystems; using Content.Shared.Chemistry.Reagent; using Content.Shared.Nutrition.Components; +using Content.Shared.Nutrition.EntitySystems; using Robust.Shared.Prototypes; namespace Content.Server.Chemistry.ReagentEffects @@ -21,8 +21,9 @@ namespace Content.Server.Chemistry.ReagentEffects /// Satiate thirst if a ThirstComponent can be found public override void Effect(ReagentEffectArgs args) { - if (args.EntityManager.TryGetComponent(args.SolutionEntity, out ThirstComponent? thirst)) - EntitySystem.Get().UpdateThirst(thirst, HydrationFactor); + var uid = args.SolutionEntity; + if (args.EntityManager.TryGetComponent(uid, out ThirstComponent? thirst)) + EntitySystem.Get().ModifyThirst(uid, thirst, HydrationFactor); } protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) diff --git a/Content.Server/Medical/VomitSystem.cs b/Content.Server/Medical/VomitSystem.cs index a764cd2b19..37ad658825 100644 --- a/Content.Server/Medical/VomitSystem.cs +++ b/Content.Server/Medical/VomitSystem.cs @@ -44,7 +44,7 @@ namespace Content.Server.Medical _hunger.ModifyHunger(uid, hungerAdded, hunger); if (TryComp(uid, out var thirst)) - _thirst.UpdateThirst(thirst, thirstAdded); + _thirst.ModifyThirst(uid, thirst, thirstAdded); // It fully empties the stomach, this amount from the chem stream is relatively small var solutionSize = (MathF.Abs(thirstAdded) + MathF.Abs(hungerAdded)) / 6; diff --git a/Content.Shared/Nutrition/Components/ThirstComponent.cs b/Content.Shared/Nutrition/Components/ThirstComponent.cs index da75a8e5de..e5604de57b 100644 --- a/Content.Shared/Nutrition/Components/ThirstComponent.cs +++ b/Content.Shared/Nutrition/Components/ThirstComponent.cs @@ -1,5 +1,5 @@ -using Content.Server.Nutrition.EntitySystems; using Content.Shared.Alert; +using Content.Shared.Nutrition.EntitySystems; using Robust.Shared.GameStates; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; diff --git a/Content.Shared/Nutrition/EntitySystems/ThirstSystem.cs b/Content.Shared/Nutrition/EntitySystems/ThirstSystem.cs index 4fa7c417aa..b75a6d1a0a 100644 --- a/Content.Shared/Nutrition/EntitySystems/ThirstSystem.cs +++ b/Content.Shared/Nutrition/EntitySystems/ThirstSystem.cs @@ -7,7 +7,7 @@ using JetBrains.Annotations; using Robust.Shared.Random; using Robust.Shared.Timing; -namespace Content.Server.Nutrition.EntitySystems; +namespace Content.Shared.Nutrition.EntitySystems; [UsedImplicitly] public sealed class ThirstSystem : EntitySystem @@ -27,12 +27,12 @@ public sealed class ThirstSystem : EntitySystem _sawmill = Logger.GetSawmill("thirst"); SubscribeLocalEvent(OnRefreshMovespeed); - SubscribeLocalEvent(OnComponentStartup); + SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnRejuvenate); SubscribeLocalEvent(OnUnpaused); } - private void OnComponentStartup(EntityUid uid, ThirstComponent component, ComponentStartup args) + private void OnMapInit(EntityUid uid, ThirstComponent component, MapInitEvent args) { // Do not change behavior unless starting value is explicitly defined if (component.CurrentThirst < 0) @@ -41,6 +41,7 @@ public sealed class ThirstSystem : EntitySystem (int) component.ThirstThresholds[ThirstThreshold.Thirsty] + 10, (int) component.ThirstThresholds[ThirstThreshold.Okay] - 1); } + component.NextUpdateTime = _timing.CurTime; component.CurrentThirstThreshold = GetThirstThreshold(component, component.CurrentThirst); component.LastThirstThreshold = ThirstThreshold.Okay; // TODO: Potentially change this -> Used Okay because no effects. // TODO: Check all thresholds make sense and throw if they don't. @@ -59,7 +60,7 @@ public sealed class ThirstSystem : EntitySystem private void OnRejuvenate(EntityUid uid, ThirstComponent component, RejuvenateEvent args) { - ResetThirst(component); + SetThirst(uid, component, component.ThirstThresholds[ThirstThreshold.Okay]); } private ThirstThreshold GetThirstThreshold(ThirstComponent component, float amount) @@ -78,14 +79,18 @@ public sealed class ThirstSystem : EntitySystem return result; } - public void UpdateThirst(ThirstComponent component, float amount) + public void ModifyThirst(EntityUid uid, ThirstComponent component, float amount) { - component.CurrentThirst = Math.Clamp(component.CurrentThirst + amount, component.ThirstThresholds[ThirstThreshold.Dead], component.ThirstThresholds[ThirstThreshold.OverHydrated]); + SetThirst(uid, component, component.CurrentThirst + amount); } - public void ResetThirst(ThirstComponent component) + public void SetThirst(EntityUid uid, ThirstComponent component, float amount) { - component.CurrentThirst = component.ThirstThresholds[ThirstThreshold.Okay]; + component.CurrentThirst = Math.Clamp(amount, + component.ThirstThresholds[ThirstThreshold.Dead], + component.ThirstThresholds[ThirstThreshold.OverHydrated] + ); + Dirty(uid, component); } private bool IsMovementThreshold(ThirstThreshold threshold) @@ -166,7 +171,7 @@ public sealed class ThirstSystem : EntitySystem thirst.NextUpdateTime += thirst.UpdateRate; - UpdateThirst(thirst, -thirst.ActualDecayRate); + ModifyThirst(uid, thirst, -thirst.ActualDecayRate); var calculatedThirstThreshold = GetThirstThreshold(thirst, thirst.CurrentThirst); if (calculatedThirstThreshold == thirst.CurrentThirstThreshold)