public void ThirstThresholdEffect(bool force = false) { 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 PlayerInputMoverComponent playerSpeedupComponent)) { // TODO shitcode: Come up something better playerSpeedupComponent.WalkMoveSpeed = playerSpeedupComponent.WalkMoveSpeed * 2; playerSpeedupComponent.SprintMoveSpeed = playerSpeedupComponent.SprintMoveSpeed * 4; } // Update UI Owner.TryGetComponent(out ServerStatusEffectsComponent statusEffectsComponent); statusEffectsComponent?.ChangeStatus(StatusEffect.Thirst, "/Textures/Mob/UI/Thirst/" + _currentThirstThreshold + ".png"); switch (_currentThirstThreshold) { case ThirstThreshold.OverHydrated: _lastThirstThreshold = _currentThirstThreshold; _actualDecayRate = _baseDecayRate * 1.2f; return; case ThirstThreshold.Okay: _lastThirstThreshold = _currentThirstThreshold; _actualDecayRate = _baseDecayRate; return; case ThirstThreshold.Thirsty: // Same as okay except with UI icon saying drink soon. _lastThirstThreshold = _currentThirstThreshold; _actualDecayRate = _baseDecayRate * 0.8f; return; case ThirstThreshold.Parched: // TODO: If something else bumps this could cause mega-speed. // If some form of speed update system if multiple things are touching it use that. if (Owner.TryGetComponent(out PlayerInputMoverComponent playerInputMoverComponent)) { playerInputMoverComponent.WalkMoveSpeed = playerInputMoverComponent.WalkMoveSpeed / 2; playerInputMoverComponent.SprintMoveSpeed = playerInputMoverComponent.SprintMoveSpeed / 4; } _lastThirstThreshold = _currentThirstThreshold; _actualDecayRate = _baseDecayRate * 0.6f; return; case ThirstThreshold.Dead: return; default: Logger.ErrorS("thirst", $"No thirst threshold found for {_currentThirstThreshold}"); throw new ArgumentOutOfRangeException($"No thirst threshold found for {_currentThirstThreshold}"); } } }
protected override void Startup() { base.Startup(); _currentThirst = _random.Next( (int)_thirstThresholds[ThirstThreshold.Thirsty] + 10, (int)_thirstThresholds[ThirstThreshold.Okay] - 1); _currentThirstThreshold = GetThirstThreshold(_currentThirst); _lastThirstThreshold = ThirstThreshold.Okay; // TODO: Potentially change this -> Used Okay because no effects. // TODO: Check all thresholds make sense and throw if they don't. ThirstThresholdEffect(true); }
public void ThirstThresholdEffect(bool force = false) { 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)) { movementSlowdownComponent.RefreshMovementSpeedModifiers(); } // Update UI Owner.TryGetComponent(out ServerStatusEffectsComponent statusEffectsComponent); statusEffectsComponent?.ChangeStatus(StatusEffect.Thirst, "/Textures/Mob/UI/Thirst/" + _currentThirstThreshold + ".png"); switch (_currentThirstThreshold) { case ThirstThreshold.OverHydrated: _lastThirstThreshold = _currentThirstThreshold; _actualDecayRate = _baseDecayRate * 1.2f; return; case ThirstThreshold.Okay: _lastThirstThreshold = _currentThirstThreshold; _actualDecayRate = _baseDecayRate; return; case ThirstThreshold.Thirsty: // Same as okay except with UI icon saying drink soon. _lastThirstThreshold = _currentThirstThreshold; _actualDecayRate = _baseDecayRate * 0.8f; return; case ThirstThreshold.Parched: if (Owner.TryGetComponent(out MovementSpeedModifierComponent movementSlowdownComponent1)) { movementSlowdownComponent1.RefreshMovementSpeedModifiers(); } _lastThirstThreshold = _currentThirstThreshold; _actualDecayRate = _baseDecayRate * 0.6f; return; case ThirstThreshold.Dead: return; default: Logger.ErrorS("thirst", $"No thirst threshold found for {_currentThirstThreshold}"); throw new ArgumentOutOfRangeException($"No thirst threshold found for {_currentThirstThreshold}"); } } }
public override void HandleComponentState(ComponentState?curState, ComponentState?nextState) { base.HandleComponentState(curState, nextState); if (curState is not ThirstComponentState thirst) { return; } _currentThirstThreshold = thirst.CurrentThreshold; EntitySystem.Get <MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(Owner); }
public override void HandleComponentState(ComponentState?curState, ComponentState?nextState) { if (!(curState is ThirstComponentState thirst)) { return; } _currentThirstThreshold = thirst.CurrentThreshold; if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movement)) { movement.RefreshMovementSpeedModifiers(); } }
public ThirstThreshold GetThirstThreshold(float drink) { ThirstThreshold result = ThirstThreshold.Dead; var value = ThirstThresholds[ThirstThreshold.OverHydrated]; foreach (var threshold in _thirstThresholds) { if (threshold.Value <= value && threshold.Value >= drink) { result = threshold.Key; value = threshold.Value; } } return(result); }
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); }
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); } }
// TODO: If mob is moving increase rate of consumption. // Should use a multiplier as something like a disease would overwrite decay rate. public void OnUpdate(float frametime) { _currentThirst -= frametime * ActualDecayRate; var calculatedThirstThreshold = GetThirstThreshold(_currentThirst); // _trySound(calculatedThreshold); if (calculatedThirstThreshold != _currentThirstThreshold) { _currentThirstThreshold = calculatedThirstThreshold; ThirstThresholdEffect(); } if (_currentThirstThreshold == ThirstThreshold.Dead) { // TODO: Remove from dead people if (Owner.TryGetComponent(out DamageableComponent damage)) { damage.TakeDamage(DamageType.Brute, 2); return; } return; } }
public ThirstComponentState(ThirstThreshold currentThreshold) : base(ContentNetIDs.THIRST) { CurrentThreshold = currentThreshold; }
public ThirstComponentState(ThirstThreshold currentThreshold) { CurrentThreshold = currentThreshold; }