Slight nutrition clean (#1224)
Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -19,23 +19,39 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class HungerComponent : SharedHungerComponent
|
public sealed class HungerComponent : SharedHungerComponent
|
||||||
{
|
{
|
||||||
#pragma warning disable 649
|
|
||||||
[Dependency] private readonly IRobustRandom _random;
|
|
||||||
#pragma warning restore 649
|
|
||||||
|
|
||||||
// Base stuff
|
// Base stuff
|
||||||
public float BaseDecayRate => _baseDecayRate;
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[ViewVariables] private float _baseDecayRate;
|
public float BaseDecayRate
|
||||||
public float ActualDecayRate => _actualDecayRate;
|
{
|
||||||
[ViewVariables] private float _actualDecayRate;
|
get => _baseDecayRate;
|
||||||
|
set => _baseDecayRate = value;
|
||||||
|
}
|
||||||
|
private float _baseDecayRate;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public float ActualDecayRate
|
||||||
|
{
|
||||||
|
get => _actualDecayRate;
|
||||||
|
set => _actualDecayRate = value;
|
||||||
|
}
|
||||||
|
private float _actualDecayRate;
|
||||||
|
|
||||||
// Hunger
|
// Hunger
|
||||||
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public override HungerThreshold CurrentHungerThreshold => _currentHungerThreshold;
|
public override HungerThreshold CurrentHungerThreshold => _currentHungerThreshold;
|
||||||
private HungerThreshold _currentHungerThreshold;
|
private HungerThreshold _currentHungerThreshold;
|
||||||
private HungerThreshold _lastHungerThreshold;
|
|
||||||
public float CurrentHunger => _currentHunger;
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)] private float _currentHunger;
|
|
||||||
|
|
||||||
|
private HungerThreshold _lastHungerThreshold;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public float CurrentHunger
|
||||||
|
{
|
||||||
|
get => _currentHunger;
|
||||||
|
set => _currentHunger = value;
|
||||||
|
}
|
||||||
|
private float _currentHunger;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public Dictionary<HungerThreshold, float> HungerThresholds => _hungerThresholds;
|
public Dictionary<HungerThreshold, float> HungerThresholds => _hungerThresholds;
|
||||||
private Dictionary<HungerThreshold, float> _hungerThresholds = new Dictionary<HungerThreshold, float>
|
private Dictionary<HungerThreshold, float> _hungerThresholds = new Dictionary<HungerThreshold, float>
|
||||||
{
|
{
|
||||||
@@ -67,8 +83,6 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
{
|
{
|
||||||
if (_currentHungerThreshold != _lastHungerThreshold || force)
|
if (_currentHungerThreshold != _lastHungerThreshold || force)
|
||||||
{
|
{
|
||||||
Logger.InfoS("hunger", $"Updating hunger state for {Owner.Name}");
|
|
||||||
|
|
||||||
// Revert slow speed if required
|
// Revert slow speed if required
|
||||||
if (_lastHungerThreshold == HungerThreshold.Starving && _currentHungerThreshold != HungerThreshold.Dead &&
|
if (_lastHungerThreshold == HungerThreshold.Starving && _currentHungerThreshold != HungerThreshold.Dead &&
|
||||||
Owner.TryGetComponent(out MovementSpeedModifierComponent movementSlowdownComponent))
|
Owner.TryGetComponent(out MovementSpeedModifierComponent movementSlowdownComponent))
|
||||||
@@ -121,7 +135,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
{
|
{
|
||||||
base.Startup();
|
base.Startup();
|
||||||
// Similar functionality to SS13. Should also stagger people going to the chef.
|
// Similar functionality to SS13. Should also stagger people going to the chef.
|
||||||
_currentHunger = _random.Next(
|
_currentHunger = IoCManager.Resolve<IRobustRandom>().Next(
|
||||||
(int)_hungerThresholds[HungerThreshold.Peckish] + 10,
|
(int)_hungerThresholds[HungerThreshold.Peckish] + 10,
|
||||||
(int)_hungerThresholds[HungerThreshold.Okay] - 1);
|
(int)_hungerThresholds[HungerThreshold.Okay] - 1);
|
||||||
_currentHungerThreshold = GetHungerThreshold(_currentHunger);
|
_currentHungerThreshold = GetHungerThreshold(_currentHunger);
|
||||||
@@ -166,19 +180,21 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
}
|
}
|
||||||
if (_currentHungerThreshold == HungerThreshold.Dead)
|
if (_currentHungerThreshold == HungerThreshold.Dead)
|
||||||
{
|
{
|
||||||
// TODO: Remove from dead people
|
|
||||||
if (Owner.TryGetComponent(out DamageableComponent damage))
|
if (Owner.TryGetComponent(out DamageableComponent damage))
|
||||||
|
{
|
||||||
|
if (!damage.IsDead())
|
||||||
{
|
{
|
||||||
damage.TakeDamage(DamageType.Brute, 2);
|
damage.TakeDamage(DamageType.Brute, 2);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetFood()
|
public void ResetFood()
|
||||||
{
|
{
|
||||||
_currentHunger = HungerThresholds[HungerThreshold.Okay];
|
_currentHungerThreshold = HungerThreshold.Okay;
|
||||||
|
_currentHunger = HungerThresholds[_currentHungerThreshold];
|
||||||
|
HungerThresholdEffect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ComponentState GetComponentState()
|
public override ComponentState GetComponentState()
|
||||||
|
|||||||
@@ -17,27 +17,43 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Server.GameObjects.Components.Nutrition
|
namespace Content.Server.GameObjects.Components.Nutrition
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[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
|
// Base stuff
|
||||||
public float BaseDecayRate => _baseDecayRate;
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[ViewVariables] private float _baseDecayRate;
|
public float BaseDecayRate
|
||||||
public float ActualDecayRate => _actualDecayRate;
|
{
|
||||||
[ViewVariables] private float _actualDecayRate;
|
get => _baseDecayRate;
|
||||||
|
set => _baseDecayRate = value;
|
||||||
|
}
|
||||||
|
private float _baseDecayRate;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public float ActualDecayRate
|
||||||
|
{
|
||||||
|
get => _actualDecayRate;
|
||||||
|
set => _actualDecayRate = value;
|
||||||
|
}
|
||||||
|
private float _actualDecayRate;
|
||||||
|
|
||||||
// Thirst
|
// Thirst
|
||||||
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public override ThirstThreshold CurrentThirstThreshold => _currentThirstThreshold;
|
public override ThirstThreshold CurrentThirstThreshold => _currentThirstThreshold;
|
||||||
private ThirstThreshold _currentThirstThreshold;
|
private ThirstThreshold _currentThirstThreshold;
|
||||||
private ThirstThreshold _lastThirstThreshold;
|
|
||||||
public float CurrentThirst => _currentThirst;
|
|
||||||
[ViewVariables] private float _currentThirst;
|
|
||||||
|
|
||||||
|
private ThirstThreshold _lastThirstThreshold;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public float CurrentThirst
|
||||||
|
{
|
||||||
|
get => _currentThirst;
|
||||||
|
set => _currentThirst = value;
|
||||||
|
}
|
||||||
|
private float _currentThirst;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public Dictionary<ThirstThreshold, float> ThirstThresholds => _thirstThresholds;
|
public Dictionary<ThirstThreshold, float> ThirstThresholds => _thirstThresholds;
|
||||||
private Dictionary<ThirstThreshold, float> _thirstThresholds = new Dictionary<ThirstThreshold, float>
|
private readonly Dictionary<ThirstThreshold, float> _thirstThresholds = new Dictionary<ThirstThreshold, float>
|
||||||
{
|
{
|
||||||
{ThirstThreshold.OverHydrated, 600.0f},
|
{ThirstThreshold.OverHydrated, 600.0f},
|
||||||
{ThirstThreshold.Okay, 450.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/Parched.png",
|
||||||
"/Textures/Mob/UI/Thirst/Dead.png",
|
"/Textures/Mob/UI/Thirst/Dead.png",
|
||||||
};
|
};
|
||||||
|
|
||||||
public override void ExposeData(ObjectSerializer serializer)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
@@ -66,8 +83,6 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
{
|
{
|
||||||
if (_currentThirstThreshold != _lastThirstThreshold || force)
|
if (_currentThirstThreshold != _lastThirstThreshold || force)
|
||||||
{
|
{
|
||||||
Logger.InfoS("thirst", $"Updating Thirst state for {Owner.Name}");
|
|
||||||
|
|
||||||
// Revert slow speed if required
|
// Revert slow speed if required
|
||||||
if (_lastThirstThreshold == ThirstThreshold.Parched && _currentThirstThreshold != ThirstThreshold.Dead &&
|
if (_lastThirstThreshold == ThirstThreshold.Parched && _currentThirstThreshold != ThirstThreshold.Dead &&
|
||||||
Owner.TryGetComponent(out MovementSpeedModifierComponent movementSlowdownComponent))
|
Owner.TryGetComponent(out MovementSpeedModifierComponent movementSlowdownComponent))
|
||||||
@@ -119,7 +134,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
protected override void Startup()
|
protected override void Startup()
|
||||||
{
|
{
|
||||||
base.Startup();
|
base.Startup();
|
||||||
_currentThirst = _random.Next(
|
_currentThirst = IoCManager.Resolve<IRobustRandom>().Next(
|
||||||
(int)_thirstThresholds[ThirstThreshold.Thirsty] + 10,
|
(int)_thirstThresholds[ThirstThreshold.Thirsty] + 10,
|
||||||
(int)_thirstThresholds[ThirstThreshold.Okay] - 1);
|
(int)_thirstThresholds[ThirstThreshold.Okay] - 1);
|
||||||
_currentThirstThreshold = GetThirstThreshold(_currentThirst);
|
_currentThirstThreshold = GetThirstThreshold(_currentThirst);
|
||||||
@@ -166,20 +181,22 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
|
|
||||||
if (_currentThirstThreshold == ThirstThreshold.Dead)
|
if (_currentThirstThreshold == ThirstThreshold.Dead)
|
||||||
{
|
{
|
||||||
// TODO: Remove from dead people
|
|
||||||
if (Owner.TryGetComponent(out DamageableComponent damage))
|
if (Owner.TryGetComponent(out DamageableComponent damage))
|
||||||
|
{
|
||||||
|
if (!damage.IsDead())
|
||||||
{
|
{
|
||||||
damage.TakeDamage(DamageType.Brute, 2);
|
damage.TakeDamage(DamageType.Brute, 2);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void ResetThirst()
|
public void ResetThirst()
|
||||||
{
|
{
|
||||||
_currentThirst = ThirstThresholds[ThirstThreshold.Okay];
|
_currentThirstThreshold = ThirstThreshold.Okay;
|
||||||
|
_currentThirst = ThirstThresholds[_currentThirstThreshold];
|
||||||
|
ThirstThresholdEffect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ComponentState GetComponentState()
|
public override ComponentState GetComponentState()
|
||||||
|
|||||||
Reference in New Issue
Block a user