Probably fix thirst mispredict (#9656)

* Probably fix thirst mispredict

* thanks rider
This commit is contained in:
metalgearsloth
2022-07-13 03:45:30 +10:00
committed by GitHub
parent 9ed9888f86
commit 365f388b8e
3 changed files with 19 additions and 8 deletions

View File

@@ -13,8 +13,6 @@ namespace Content.Server.Nutrition.Components
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IRobustRandom _random = default!;
private float _accumulatedFrameTime;
// Base stuff
[ViewVariables(VVAccess.ReadWrite)]
public float BaseDecayRate

View File

@@ -16,7 +16,6 @@ namespace Content.Server.Nutrition.Components
[RegisterComponent]
public sealed class ThirstComponent : Component
{
// Base stuff
[ViewVariables(VVAccess.ReadWrite)]
[DataField("baseDecayRate")]

View File

@@ -16,8 +16,6 @@ namespace Content.Server.Nutrition.EntitySystems
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly DamageableSystem _damage = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly SharedJetpackSystem _jetpack = default!;
@@ -78,12 +76,28 @@ namespace Content.Server.Nutrition.EntitySystems
component.CurrentThirst = component.ThirstThresholds[ThirstThreshold.Okay];
}
private bool IsMovementThreshold(ThirstThreshold threshold)
{
switch (threshold)
{
case ThirstThreshold.Dead:
case ThirstThreshold.Parched:
return true;
case ThirstThreshold.Thirsty:
case ThirstThreshold.Okay:
case ThirstThreshold.OverHydrated:
return false;
default:
throw new ArgumentOutOfRangeException(nameof(threshold), threshold, null);
}
}
private void UpdateEffects(ThirstComponent component)
{
if (component.LastThirstThreshold == ThirstThreshold.Parched && component.CurrentThirstThreshold != ThirstThreshold.Dead &&
EntityManager.TryGetComponent(component.Owner, out MovementSpeedModifierComponent? movementSlowdownComponent))
if (IsMovementThreshold(component.LastThirstThreshold) != IsMovementThreshold(component.CurrentThirstThreshold) &&
TryComp(component.Owner, out MovementSpeedModifierComponent? movementSlowdownComponent))
{
_movement.RefreshMovementSpeedModifiers(component.Owner);
_movement.RefreshMovementSpeedModifiers(component.Owner, movementSlowdownComponent);
}
// Update UI