internal static bool NotifyGetCanSleep(Player player) { if (DayNightCycle.main.IsInSkipTimeMode()) { return(false); } if (player.GetMode() != Player.Mode.Normal) { return(false); } if (player.isPiloting) { return(false); } if (player.movementSpeed != 0f) { return(false); } if (player.IsUnderwater() || player.IsSwimming() || player.IsUnderwaterForSwimming()) { ErrorMessage.AddWarning("You can not sleep in the water."); return(false); } if (SurvivalHelper.IsSurvival() && (StatManager.sleep.RealValue >= 100 || StatManager.tiredness.RealValue < 25 || StatManager.coffee.RealValue >= 20)) { if (StatManager.coffee.RealValue >= 20) { ErrorMessage.AddWarning("You shouldn't drink coffee before going to sleep!"); } else if (StatManager.sleep.RealValue >= 100 || StatManager.tiredness.RealValue < 25) { ErrorMessage.AddWarning("You aren't tired enough!"); } return(false); } Survival pSurvival = player.GetComponent <Survival>(); if (SurvivalHelper.IsSurvival() && (pSurvival.food <= 20f || pSurvival.water <= 20f)) { if (pSurvival.food <= 20f && pSurvival.water <= 20f) { ErrorMessage.AddWarning("You need to eat and drink something before going to sleep!"); } else if (pSurvival.food <= 20f) { ErrorMessage.AddWarning("You need to eat something before going to sleep!"); } else if (pSurvival.water <= 20f) { ErrorMessage.AddWarning("You need to drink something before going to sleep!"); } return(false); } return(true); }
public void Update() { if (SceneManager.isIngame) { if (StatManager.sleep == null) { return; } if (StatManager.tiredness == null) { return; } if (StatManager.coffee == null) { return; } if (StatManager.vision == null) { return; } if (sleeping) { if (sleepLocation == SleepLocation.Floor && !DayNightCycle.main.IsInSkipTimeMode()) { StopSleep(Player.main, false); } } if (InputHelper.IsKeyDown(SettingsManager.keySleepStart) && !keySleepStartDown) { keySleepStartDown = true; if (!sleeping) { if (NotifyGetCanSleep(Player.main)) { if (SettingsManager.keySleepStart == SettingsManager.keySleepStop) { keySleepStopDown = true; } StartSleep(Player.main); } } } else if (!InputHelper.IsKeyDown(SettingsManager.keySleepStart) && keySleepStartDown) { keySleepStartDown = false; } if (InputHelper.IsKeyDown(SettingsManager.keySleepStop) && !keySleepStopDown) { keySleepStopDown = true; if (sleeping) { if (SettingsManager.keySleepStart == SettingsManager.keySleepStop) { keySleepStartDown = true; } StopSleep(Player.main, false); } } else if (!InputHelper.IsKeyDown(SettingsManager.keySleepStop) && keySleepStopDown) { keySleepStopDown = false; } float oldTime = lastTime; float newTime = SurvivalHelper.GetTime(); float timePassed = newTime - oldTime; float timePassedHours = (float)(timePassed / (1d / 24)); float timePassedMinutes = (float)(timePassedHours * 60); if (timePassedMinutes >= 1) { lastTime = newTime; if (SurvivalHelper.IsSurvival()) { StatManager.coffee.Value += SurvivalHelper.GetChangeValue(timePassedMinutes, coffeeFactor); float oldCoffeeMod = StatManager.tiredness.GetModifier("coffee"); float newCoffeeMod = (StatManager.coffee.RealValue / 100) * -30f; if (Math.Abs(oldCoffeeMod - newCoffeeMod) >= 0.5f) { StatManager.tiredness.SetModifier("coffee", Stat.ModifierType.ValueAbsolute, newCoffeeMod); } } else { float oldCoffeeMod = StatManager.tiredness.GetModifier("coffee"); if (oldCoffeeMod != 0f) { StatManager.tiredness.SetModifier("coffee", Stat.ModifierType.ValueAbsolute, 0f); } } if (sleeping) { if (sleepLocation == SleepLocation.Bed) { float hpOut = Player.main.liveMixin.health + SurvivalHelper.GetChangeValue(timePassedMinutes, healthFactorSleepingEfficient); hpOut = hpOut > 100 ? 100 : hpOut < 0 ? 0 : hpOut; Player.main.liveMixin.health = hpOut; if (SurvivalHelper.IsSurvival()) { StatManager.sleep.Value += SurvivalHelper.GetChangeValue(timePassedMinutes, sleepFactorSleepingEfficient); StatManager.tiredness.Value += SurvivalHelper.GetChangeValue(timePassedMinutes, tirednessFactorSleepingEfficient); if (StatManager.sleep.RealValue >= 100) { StopSleep(Player.main, false); } } } else { float hpOut = Player.main.liveMixin.health + SurvivalHelper.GetChangeValue(timePassedMinutes, healthFactorSleepingInefficient); hpOut = hpOut > 100 ? 100 : hpOut < 0 ? 0 : hpOut; Player.main.liveMixin.health = hpOut; if (SurvivalHelper.IsSurvival()) { StatManager.sleep.Value += SurvivalHelper.GetChangeValue(timePassedMinutes, sleepFactorSleepingInefficient); StatManager.tiredness.Value += SurvivalHelper.GetChangeValue(timePassedMinutes, tirednessFactorSleepingInefficient); if (StatManager.sleep.RealValue >= 100) { StopSleep(Player.main, false); } } } if (SurvivalHelper.IsSurvival()) { Survival pSurvival = Player.main.GetComponent <Survival>(); pSurvival.food += SurvivalHelper.GetChangeValue(timePassedMinutes, foodFactorSleeping); pSurvival.water += SurvivalHelper.GetChangeValue(timePassedMinutes, waterFactorSleeping); if (pSurvival.food <= 10f || pSurvival.water <= 10f) { StopSleep(Player.main, false); if (pSurvival.food <= 10f) { pSurvival.foodWarningSounds[1].Play(); } else if (pSurvival.water <= 10f) { pSurvival.waterWarningSounds[1].Play(); } } } } else if (sitting) { if (SurvivalHelper.IsSurvival()) { StatManager.sleep.Value += SurvivalHelper.GetChangeValue(timePassedMinutes, sleepFactorNormal); } // TODO Find a good way to replenish stamina (TBD) and tiredness. } else { if (SurvivalHelper.IsSurvival()) { StatManager.sleep.Value += SurvivalHelper.GetChangeValue(timePassedMinutes, sleepFactorNormal); StatManager.tiredness.Value += SurvivalHelper.GetChangeValue(timePassedMinutes, tirednessFactorNormal); } } if (SurvivalHelper.IsSurvival()) { if (StatManager.sleep.RealValue <= 0) { Player.main.liveMixin.TakeDamage(-SurvivalHelper.GetChangeValue(timePassedMinutes, healthFactorDying), default, DamageType.Starve);