stardew-access/stardew-access/Features/Warnings.cs

90 lines
2.9 KiB
C#
Raw Normal View History

2022-05-11 07:59:12 +00:00
namespace stardew_access.Features
{
/// <summary>
/// Warns the player when their health or stamina/energy is low. Also warns when its past midnight.
/// </summary>
2022-05-11 07:59:12 +00:00
public class Warnings
{
// Store the previously checked value
private int prevStamina;
private int prevHealth;
2022-05-12 17:52:59 +00:00
private int prevHour;
public Warnings()
{
prevStamina = 100;
prevHealth = 100;
2022-05-12 17:52:59 +00:00
prevHour = 6;
}
2022-05-11 07:59:12 +00:00
public void update()
{
this.checkForHealth();
this.checkForStamina();
2022-05-12 17:52:59 +00:00
this.checkForTimeOfDay();
}
/// <summary>
/// Warns when its past 12:00 am and 1:00 am
/// </summary>
2022-05-12 17:52:59 +00:00
private void checkForTimeOfDay()
{
if (MainClass.ModHelper == null)
return;
int hours = StardewValley.Game1.timeOfDay / 100;
string toSpeak = MainClass.ModHelper.Translation.Get("warnings.time", new { value = CurrentPlayer.TimeOfDay });
if (hours < 1 && prevHour > 2 || hours >= 1 && prevHour < 1)
{
MainClass.ScreenReader.Say(toSpeak, true);
// Pause the read tile feature to prevent interruption in warning message
2022-05-16 15:37:08 +00:00
MainClass.ReadTileFeature.pauseUntil();
2022-05-12 17:52:59 +00:00
}
prevHour = hours;
2022-05-11 07:59:12 +00:00
}
/// <summary>
/// Warns when stamina reaches below 50, 25 and 10.
/// </summary>
2022-05-11 07:59:12 +00:00
public void checkForStamina()
{
if (MainClass.ModHelper == null)
return;
int stamina = CurrentPlayer.PercentStamina;
string toSpeak = MainClass.ModHelper.Translation.Get("warnings.stamina", new { value = stamina });
2022-05-11 07:59:12 +00:00
if ((stamina <= 50 && prevStamina > 50) || (stamina <= 25 && prevStamina > 25) || (stamina <= 10 && prevStamina > 10))
2022-05-11 07:59:12 +00:00
{
MainClass.ScreenReader.Say(toSpeak, true);
// Pause the read tile feature to prevent interruption in warning message
2022-05-16 15:37:08 +00:00
MainClass.ReadTileFeature.pauseUntil();
2022-05-11 07:59:12 +00:00
}
prevStamina = stamina;
2022-05-11 07:59:12 +00:00
}
/// <summary>
/// Warns when health reaches below 50, 25 and 10.
/// </summary>
2022-05-11 07:59:12 +00:00
public void checkForHealth()
{
if (MainClass.ModHelper == null)
return;
int health = CurrentPlayer.PercentHealth;
string toSpeak = MainClass.ModHelper.Translation.Get("warnings.health", new { value = health });
2022-05-11 07:59:12 +00:00
if ((health <= 50 && prevHealth > 50) || (health <= 25 && prevHealth > 25) || (health <= 10 && prevHealth > 10))
2022-05-11 07:59:12 +00:00
{
MainClass.ScreenReader.Say(toSpeak, true);
// Pause the read tile feature to prevent interruption in warning message
2022-05-16 15:37:08 +00:00
MainClass.ReadTileFeature.pauseUntil();
2022-05-11 07:59:12 +00:00
}
prevHealth = health;
2022-05-11 07:59:12 +00:00
}
}
}