/*public static int AddTimeToIntTime(int s1, int s2) //Is this one an int time (e.g. 1620) and an int minutes? * { * SDVTime sTime = new SDVTime(s1); * sTime.AddTime(s2); * return sTime.ReturnIntTime(); * }*/ //operator functions ///<summary>Adds two instances of SDVTime</summary> public static SDVTime operator +(SDVTime s1, SDVTime s2) { SDVTime ret = new SDVTime(s1); ret.AddTime(s2); return(ret); }
///<summary>Returns the difference of two instances of SDVTime</summary> public static SDVTime operator -(SDVTime s1, SDVTime s2) { SDVTime ret = new SDVTime(s1); ret.hour -= s2.hour; ret.minute -= s2.minute; while (ret.minute > (MINPERHR - 1)) { ret.hour++; ret.minute -= MINPERHR; } while (ret.minute < 0) { ret.hour--; ret.minute += MINPERHR; } /*if (ret.hour >= MAXHOUR) * { * ret.hour -= MAXHOUR; * }*///No rollover return(ret); }
/// <summary>Apply (or reapply) suncreen protection.</summary> public void ApplySunscreen(SDVTime time = null) { if (time == null) { time = SDVTime.CurrentTime; } TimeOfApplication = time; }
/// <summary>Returns the time when the applied sunscreen will wear off.</summary> SDVTime GetExpiryTime() { if (TimeOfApplication == null) { return(null); } SDVTime expiry = new SDVTime(TimeOfApplication); expiry.AddMinutes(SDVTime.MINPERHR * Config.SunscreenDuration); return(expiry); }
/// <summary>Calculates current UV intensity and adds that value to the damage counter.</summary> public void CheckForBurnDamage(SDVTime time) { //TODO? maybe check for sunscreen here int newDamage = UVIndex.UVIntensityAt(time); SunDamageCounter += newDamage; if (Config.DebugMode) { Monitor.Log($"New burn damage level is {NewBurnDamageLevel} | SunDamageCounter is at {SunDamageCounter}", LogLevel.Debug); } }
/// <summary>Check if sunscreen protection is active at the current time.</summary> public bool IsProtected() { if (TimeOfApplication != null) { SDVTime time = SDVTime.CurrentTime; if (time >= TimeOfApplication && time < TimeOfExpiry) { return(true); } } return(false); }
/// <summary>Check if new suncreen was applied within the last 30 minutes.</summary> public bool AppliedSunscreenRecently() { SDVTime now = SDVTime.CurrentTime; SDVTime last30Mins = new SDVTime(now); last30Mins.AddMinutes(-30); if (IsProtected() && TimeOfApplication > last30Mins) { return(true); } return(false); }
/// <summary>Calculates immediate UV intensity for the current date at a given time.</summary> /// <param name="time">Time of day to calculate for</param> /// <returns>UV intensity at time of day</returns> public static int UVIntensityAt(SDVTime time) { if (!Context.IsWorldReady) { throw new Exception("Couldn't get date and time as no save is loaded."); //Ignore before a save is loaded. } int today = SDate.Now().DaysSinceStart; int todaysWeather = Game1.weather_sunny; if (Game1.isDebrisWeather) { todaysWeather = Game1.weather_debris; } if (Game1.isRaining) { todaysWeather = Game1.weather_rain; } if (Game1.isLightning) { todaysWeather = Game1.weather_lightning; } if (Game1.isSnowing) { todaysWeather = Game1.weather_snow; } int todayMaxUV = DailyMaxUV(today, todaysWeather); SDVTime solarNoon = new SDVTime(SOLAR_NOON); SDVTime sunset = new SDVTime(Game1.getTrulyDarkTime()); int halfCycleMinutes = SDVTime.ConvertTimeToMinutes(sunset - solarNoon); int solarNoonMinutes = SDVTime.ConvertTimeToMinutes(solarNoon); int timeMinutes = SDVTime.ConvertTimeToMinutes(time); SDVTime sunrise = new SDVTime(solarNoon); sunrise.AddMinutes(-1 * halfCycleMinutes); if (time <= sunrise || time >= sunset) { return(0); } else { double ampitude = todayMaxUV / 2; double UV = ampitude * Math.Cos(Math.PI / halfCycleMinutes * (timeMinutes - solarNoonMinutes)) + ampitude; return(Convert.ToInt32(UV)); } }
///<summary>Adds a SDVTime to this SDVTime instance</summary> public void AddTime(SDVTime sTime) { hour += sTime.hour; minute += sTime.minute; while (minute > (MINPERHR - 1)) { hour++; minute -= MINPERHR; } while (minute < 0) { hour--; minute += MAXHOUR; } /*if (hour >= MAXHOUR) * { * hour -= MAXHOUR; * }*///No rollover }
/// <summary> /// Update suncreen status and check for damage from sun exposure. Raised when the game time changes (10-minute intervals). /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void onTimeChanged(object sender, TimeChangedEventArgs e) { SDVTime time = SDVTime.CurrentTime; int UV = UVIndex.UVIntensityAt(time); int uvIndex = Convert.ToInt32((double)UV / 25); TotalUVExposure += UV; if (Config.DebugMode) { Monitor.Log($"Time is {time.Get12HourTime()} - current UV strength is {UV} or index {uvIndex}. Total exposure is {TotalUVExposure}", LogLevel.Debug); } //Possibly redundant? (Also in this.onHalfSecondUpdateTicked) Sunscreen.UpdateStatus(); //Checks and updates if sunscreen has worn off or washed off if (Config.EnableSunburn && Config.SunburnPossible(SDate.Now()) && //Check config settings e.NewTime != e.OldTime && e.NewTime % 10 == 0 && Game1.currentLocation.IsOutdoors && !Sunscreen.IsProtected()) // Outdoors and not protected by sunscreen { Burn.CheckForBurnDamage(time); } }
/// <summary>Remove all suncreen protection.</summary> public void RemoveSunscreen() { TimeOfApplication = null; }
///<summary>Constructs an instance by copying another SDVTime instance</summary> public SDVTime(SDVTime c) { hour = c.hour; minute = c.minute; }
/// <summary> /// This function takes two integer times and returns minutes between. Note: this returns an absolute value. /// </summary> /// <param name="t1">The first int time.</param> /// <param name="t2">The second int time</param> /// <returns>Amount of minutes between the two times</returns> public static int MinutesBetweenTwoIntTimes(int t1, int t2) { return(Math.Abs(SDVTime.ConvertIntTimeToMinutes(t1) - SDVTime.ConvertIntTimeToMinutes(t2))); }
///<summary>Constructs an SDVTime value to minutes</summary> public static int ConvertTimeToMinutes(SDVTime sTime) { return(sTime.hour * MINPERHR + sTime.minute); }