Fix hunger not updating thresholds correctly from rejuvenate.

This commit is contained in:
Pieter-Jan Briers
2021-01-12 21:24:11 +01:00
parent ec492a0d6a
commit af1838c641
4 changed files with 36 additions and 23 deletions

View File

@@ -178,14 +178,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
public void OnUpdate(float frametime)
{
_currentHunger -= frametime * ActualDecayRate;
var calculatedHungerThreshold = GetHungerThreshold(_currentHunger);
// _trySound(calculatedThreshold);
if (calculatedHungerThreshold != _currentHungerThreshold)
{
_currentHungerThreshold = calculatedHungerThreshold;
HungerThresholdEffect();
Dirty();
}
UpdateCurrentThreshold();
if (_currentHungerThreshold != HungerThreshold.Dead)
return;
@@ -202,11 +195,22 @@ namespace Content.Server.GameObjects.Components.Nutrition
}
}
private void UpdateCurrentThreshold()
{
var calculatedHungerThreshold = GetHungerThreshold(_currentHunger);
// _trySound(calculatedThreshold);
if (calculatedHungerThreshold != _currentHungerThreshold)
{
_currentHungerThreshold = calculatedHungerThreshold;
HungerThresholdEffect();
Dirty();
}
}
public void ResetFood()
{
_currentHungerThreshold = HungerThreshold.Okay;
_currentHunger = HungerThresholds[_currentHungerThreshold];
HungerThresholdEffect();
_currentHunger = HungerThresholds[HungerThreshold.Okay];
UpdateCurrentThreshold();
}
public override ComponentState GetComponentState()

View File

@@ -4,7 +4,6 @@ using Content.Server.GameObjects.Components.Mobs;
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Mobs.State;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Nutrition;
@@ -175,14 +174,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
public void OnUpdate(float frametime)
{
_currentThirst -= frametime * ActualDecayRate;
var calculatedThirstThreshold = GetThirstThreshold(_currentThirst);
// _trySound(calculatedThreshold);
if (calculatedThirstThreshold != _currentThirstThreshold)
{
_currentThirstThreshold = calculatedThirstThreshold;
ThirstThresholdEffect();
Dirty();
}
UpdateCurrentThreshold();
if (_currentThirstThreshold != ThirstThreshold.Dead)
return;
@@ -199,11 +191,22 @@ namespace Content.Server.GameObjects.Components.Nutrition
}
}
private void UpdateCurrentThreshold()
{
var calculatedThirstThreshold = GetThirstThreshold(_currentThirst);
// _trySound(calculatedThreshold);
if (calculatedThirstThreshold != _currentThirstThreshold)
{
_currentThirstThreshold = calculatedThirstThreshold;
ThirstThresholdEffect();
Dirty();
}
}
public void ResetThirst()
{
_currentThirstThreshold = ThirstThreshold.Okay;
_currentThirst = ThirstThresholds[_currentThirstThreshold];
ThirstThresholdEffect();
_currentThirst = ThirstThresholds[ThirstThreshold.Okay];
UpdateCurrentThreshold();
}
public override ComponentState GetComponentState()

View File

@@ -2,6 +2,7 @@ using System;
using Content.Shared.GameObjects.Components.Movement;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Nutrition
{
@@ -11,6 +12,7 @@ namespace Content.Shared.GameObjects.Components.Nutrition
public sealed override uint? NetID => ContentNetIDs.HUNGER;
[ViewVariables]
public abstract HungerThreshold CurrentHungerThreshold { get; }
@@ -49,6 +51,7 @@ namespace Content.Shared.GameObjects.Components.Nutrition
}
}
[Serializable, NetSerializable]
public enum HungerThreshold : byte
{
Overfed,

View File

@@ -2,6 +2,7 @@ using System;
using Content.Shared.GameObjects.Components.Movement;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Nutrition
{
@@ -11,6 +12,7 @@ namespace Content.Shared.GameObjects.Components.Nutrition
public sealed override uint? NetID => ContentNetIDs.THIRST;
[ViewVariables]
public abstract ThirstThreshold CurrentThirstThreshold { get; }
float IMoveSpeedModifier.SprintSpeedModifier
@@ -49,6 +51,7 @@ namespace Content.Shared.GameObjects.Components.Nutrition
}
[NetSerializable, Serializable]
public enum ThirstThreshold : byte
{
// Hydrohomies