Exemplo n.º 1
0
 private void OnComponentStartup(EntityUid uid, ThirstComponent component, ComponentStartup args)
 {
     component.CurrentThirst = _random.Next(
         (int)component.ThirstThresholds[ThirstThreshold.Thirsty] + 10,
         (int)component.ThirstThresholds[ThirstThreshold.Okay] - 1);
     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.
     UpdateEffects(component);
 }
Exemplo n.º 2
0
        private void OnRefreshMovespeed(EntityUid uid, ThirstComponent component, RefreshMovementSpeedModifiersEvent args)
        {
            if (_jetpack.IsUserFlying(component.Owner))
            {
                return;
            }

            var mod = component.CurrentThirstThreshold <= ThirstThreshold.Parched ? 0.75f : 1.0f;

            args.ModifySpeed(mod, mod);
        }
Exemplo n.º 3
0
        private void UpdateEffects(ThirstComponent component)
        {
            if (IsMovementThreshold(component.LastThirstThreshold) != IsMovementThreshold(component.CurrentThirstThreshold) &&
                TryComp(component.Owner, out MovementSpeedModifierComponent? movementSlowdownComponent))
            {
                _movement.RefreshMovementSpeedModifiers(component.Owner, movementSlowdownComponent);
            }

            // Update UI
            if (ThirstComponent.ThirstThresholdAlertTypes.TryGetValue(component.CurrentThirstThreshold, out var alertId))
            {
                _alerts.ShowAlert(component.Owner, alertId);
            }
            else
            {
                _alerts.ClearAlertCategory(component.Owner, AlertCategory.Thirst);
            }

            switch (component.CurrentThirstThreshold)
            {
            case ThirstThreshold.OverHydrated:
                component.LastThirstThreshold = component.CurrentThirstThreshold;
                component.ActualDecayRate     = component.BaseDecayRate * 1.2f;
                return;

            case ThirstThreshold.Okay:
                component.LastThirstThreshold = component.CurrentThirstThreshold;
                component.ActualDecayRate     = component.BaseDecayRate;
                return;

            case ThirstThreshold.Thirsty:
                // Same as okay except with UI icon saying drink soon.
                component.LastThirstThreshold = component.CurrentThirstThreshold;
                component.ActualDecayRate     = component.BaseDecayRate * 0.8f;
                return;

            case ThirstThreshold.Parched:
                _movement.RefreshMovementSpeedModifiers(component.Owner);
                component.LastThirstThreshold = component.CurrentThirstThreshold;
                component.ActualDecayRate     = component.BaseDecayRate * 0.6f;
                return;

            case ThirstThreshold.Dead:
                return;

            default:
                _sawmill.Error($"No thirst threshold found for {component.CurrentThirstThreshold}");
                throw new ArgumentOutOfRangeException($"No thirst threshold found for {component.CurrentThirstThreshold}");
            }
        }
Exemplo n.º 4
0
        private ThirstThreshold GetThirstThreshold(ThirstComponent component, float amount)
        {
            ThirstThreshold result = ThirstThreshold.Dead;
            var             value  = component.ThirstThresholds[ThirstThreshold.OverHydrated];

            foreach (var threshold in component.ThirstThresholds)
            {
                if (threshold.Value <= value && threshold.Value >= amount)
                {
                    result = threshold.Key;
                    value  = threshold.Value;
                }
            }

            return(result);
        }
Exemplo n.º 5
0
 public void ResetThirst(ThirstComponent component)
 {
     component.CurrentThirst = component.ThirstThresholds[ThirstThreshold.Okay];
 }
Exemplo n.º 6
0
 public void UpdateThirst(ThirstComponent component, float amount)
 {
     component.CurrentThirst = Math.Min(component.CurrentThirst + amount, component.ThirstThresholds[ThirstThreshold.OverHydrated]);
 }
Exemplo n.º 7
0
        private void OnRefreshMovespeed(EntityUid uid, ThirstComponent component, RefreshMovementSpeedModifiersEvent args)
        {
            var mod = (component.CurrentThirstThreshold & (ThirstThreshold.Parched | ThirstThreshold.Dead)) != 0x0 ? 0.75f : 1.0f;

            args.ModifySpeed(mod, mod);
        }