From 49586e5dcb15493bd819901f3611b72bd7807a63 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 29 Jun 2020 01:52:34 +1000 Subject: [PATCH] Slight nutrition clean (#1224) Co-authored-by: Metal Gear Sloth --- .../Components/Nutrition/HungerComponent.cs | 52 +++++++++++------ .../Components/Nutrition/ThirstComponent.cs | 57 ++++++++++++------- 2 files changed, 71 insertions(+), 38 deletions(-) diff --git a/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs b/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs index 82233841b4..edf37b0400 100644 --- a/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs @@ -19,23 +19,39 @@ namespace Content.Server.GameObjects.Components.Nutrition [RegisterComponent] public sealed class HungerComponent : SharedHungerComponent { -#pragma warning disable 649 - [Dependency] private readonly IRobustRandom _random; -#pragma warning restore 649 - // Base stuff - public float BaseDecayRate => _baseDecayRate; - [ViewVariables] private float _baseDecayRate; - public float ActualDecayRate => _actualDecayRate; - [ViewVariables] private float _actualDecayRate; + [ViewVariables(VVAccess.ReadWrite)] + public float BaseDecayRate + { + get => _baseDecayRate; + set => _baseDecayRate = value; + } + private float _baseDecayRate; + + [ViewVariables(VVAccess.ReadWrite)] + public float ActualDecayRate + { + get => _actualDecayRate; + set => _actualDecayRate = value; + } + private float _actualDecayRate; // Hunger + [ViewVariables(VVAccess.ReadOnly)] public override HungerThreshold CurrentHungerThreshold => _currentHungerThreshold; private HungerThreshold _currentHungerThreshold; + private HungerThreshold _lastHungerThreshold; - public float CurrentHunger => _currentHunger; - [ViewVariables(VVAccess.ReadWrite)] private float _currentHunger; + [ViewVariables(VVAccess.ReadWrite)] + public float CurrentHunger + { + get => _currentHunger; + set => _currentHunger = value; + } + private float _currentHunger; + + [ViewVariables(VVAccess.ReadOnly)] public Dictionary HungerThresholds => _hungerThresholds; private Dictionary _hungerThresholds = new Dictionary { @@ -67,8 +83,6 @@ namespace Content.Server.GameObjects.Components.Nutrition { if (_currentHungerThreshold != _lastHungerThreshold || force) { - Logger.InfoS("hunger", $"Updating hunger state for {Owner.Name}"); - // Revert slow speed if required if (_lastHungerThreshold == HungerThreshold.Starving && _currentHungerThreshold != HungerThreshold.Dead && Owner.TryGetComponent(out MovementSpeedModifierComponent movementSlowdownComponent)) @@ -121,7 +135,7 @@ namespace Content.Server.GameObjects.Components.Nutrition { base.Startup(); // Similar functionality to SS13. Should also stagger people going to the chef. - _currentHunger = _random.Next( + _currentHunger = IoCManager.Resolve().Next( (int)_hungerThresholds[HungerThreshold.Peckish] + 10, (int)_hungerThresholds[HungerThreshold.Okay] - 1); _currentHungerThreshold = GetHungerThreshold(_currentHunger); @@ -166,19 +180,21 @@ namespace Content.Server.GameObjects.Components.Nutrition } if (_currentHungerThreshold == HungerThreshold.Dead) { - // TODO: Remove from dead people if (Owner.TryGetComponent(out DamageableComponent damage)) { - damage.TakeDamage(DamageType.Brute, 2); - return; + if (!damage.IsDead()) + { + damage.TakeDamage(DamageType.Brute, 2); + } } - return; } } public void ResetFood() { - _currentHunger = HungerThresholds[HungerThreshold.Okay]; + _currentHungerThreshold = HungerThreshold.Okay; + _currentHunger = HungerThresholds[_currentHungerThreshold]; + HungerThresholdEffect(); } public override ComponentState GetComponentState() diff --git a/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs b/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs index cfd820e5e2..62ad13e2a2 100644 --- a/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs @@ -17,27 +17,43 @@ using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Nutrition { [RegisterComponent] - public sealed class ThirstComponent : SharedThirstComponent, IMoveSpeedModifier + public sealed class ThirstComponent : SharedThirstComponent { -#pragma warning disable 649 - [Dependency] private readonly IRobustRandom _random; -#pragma warning restore 649 - // Base stuff - public float BaseDecayRate => _baseDecayRate; - [ViewVariables] private float _baseDecayRate; - public float ActualDecayRate => _actualDecayRate; - [ViewVariables] private float _actualDecayRate; + [ViewVariables(VVAccess.ReadWrite)] + public float BaseDecayRate + { + get => _baseDecayRate; + set => _baseDecayRate = value; + } + private float _baseDecayRate; + + [ViewVariables(VVAccess.ReadWrite)] + public float ActualDecayRate + { + get => _actualDecayRate; + set => _actualDecayRate = value; + } + private float _actualDecayRate; // Thirst + [ViewVariables(VVAccess.ReadOnly)] public override ThirstThreshold CurrentThirstThreshold => _currentThirstThreshold; private ThirstThreshold _currentThirstThreshold; + private ThirstThreshold _lastThirstThreshold; - public float CurrentThirst => _currentThirst; - [ViewVariables] private float _currentThirst; + [ViewVariables(VVAccess.ReadWrite)] + public float CurrentThirst + { + get => _currentThirst; + set => _currentThirst = value; + } + private float _currentThirst; + + [ViewVariables(VVAccess.ReadOnly)] public Dictionary ThirstThresholds => _thirstThresholds; - private Dictionary _thirstThresholds = new Dictionary + private readonly Dictionary _thirstThresholds = new Dictionary { {ThirstThreshold.OverHydrated, 600.0f}, {ThirstThreshold.Okay, 450.0f}, @@ -56,6 +72,7 @@ namespace Content.Server.GameObjects.Components.Nutrition "/Textures/Mob/UI/Thirst/Parched.png", "/Textures/Mob/UI/Thirst/Dead.png", }; + public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); @@ -66,8 +83,6 @@ namespace Content.Server.GameObjects.Components.Nutrition { if (_currentThirstThreshold != _lastThirstThreshold || force) { - Logger.InfoS("thirst", $"Updating Thirst state for {Owner.Name}"); - // Revert slow speed if required if (_lastThirstThreshold == ThirstThreshold.Parched && _currentThirstThreshold != ThirstThreshold.Dead && Owner.TryGetComponent(out MovementSpeedModifierComponent movementSlowdownComponent)) @@ -119,7 +134,7 @@ namespace Content.Server.GameObjects.Components.Nutrition protected override void Startup() { base.Startup(); - _currentThirst = _random.Next( + _currentThirst = IoCManager.Resolve().Next( (int)_thirstThresholds[ThirstThreshold.Thirsty] + 10, (int)_thirstThresholds[ThirstThreshold.Okay] - 1); _currentThirstThreshold = GetThirstThreshold(_currentThirst); @@ -166,20 +181,22 @@ namespace Content.Server.GameObjects.Components.Nutrition if (_currentThirstThreshold == ThirstThreshold.Dead) { - // TODO: Remove from dead people if (Owner.TryGetComponent(out DamageableComponent damage)) { - damage.TakeDamage(DamageType.Brute, 2); - return; + if (!damage.IsDead()) + { + damage.TakeDamage(DamageType.Brute, 2); + } } - return; } } public void ResetThirst() { - _currentThirst = ThirstThresholds[ThirstThreshold.Okay]; + _currentThirstThreshold = ThirstThreshold.Okay; + _currentThirst = ThirstThresholds[_currentThirstThreshold]; + ThirstThresholdEffect(); } public override ComponentState GetComponentState()