diff --git a/stardew-access/Features/CurrentPlayer.cs b/stardew-access/Features/CurrentPlayer.cs index 3f29382..7a2f525 100644 --- a/stardew-access/Features/CurrentPlayer.cs +++ b/stardew-access/Features/CurrentPlayer.cs @@ -6,121 +6,171 @@ namespace stardew_access.Features internal class CurrentPlayer { - public static int getHealth() + /// + /// Returns the percentage health remaining of player. + /// + public static int Health { - if (Game1.player == null) - return 0; - - int maxHealth = Game1.player.maxHealth; - int currentHealth = Game1.player.health; - - int healthPercentage = (int)(currentHealth * 100) / maxHealth; - return healthPercentage; - } - - public static int getStamina() - { - if (Game1.player == null) - return 0; - - int maxStamina = Game1.player.maxStamina.Value; - int currentStamine = (int)Game1.player.stamina; - - int staminaPercentage = (int)(currentStamine * 100) / maxStamina; - - return staminaPercentage; - } - - public static Vector2 getPosition() - { - if (Game1.player == null) - return Vector2.Zero; - - return Game1.player.getTileLocation(); - } - - public static int getPositionX() - { - if (Game1.player == null) - return 0; - - return (int)getPosition().X; - } - - public static int getPositionY() - { - if (Game1.player == null) - return 0; - - return (int)getPosition().Y; - } - - public static string getTimeOfDay() - { - int timeOfDay = Game1.timeOfDay; - - int minutes = timeOfDay % 100; - int hours = timeOfDay / 100; - string amOrpm = "A M"; - if (hours >= 12) + get { - amOrpm = "P M"; - if (hours > 12) - hours -= 12; + if (Game1.player == null) + return 0; + + int maxHealth = Game1.player.maxHealth; + int currentHealth = Game1.player.health; + + int healthPercentage = (int)(currentHealth * 100) / maxHealth; + return healthPercentage; } - - return $"{hours}:{minutes} {amOrpm}"; } - public static string getSeason() + /// + /// Returns the percentage stamine/energy remaining of player. + /// + public static int Stamina { - return Game1.CurrentSeasonDisplayName; - } - - public static int getDate() - { - return Game1.dayOfMonth; - } - - public static string getDay() - { - return Game1.Date.DayOfWeek.ToString(); - } - - public static int getMoney() - { - if (Game1.player == null) - return -1; - - return Game1.player.Money; - } - - public static Vector2 getNextTile() - { - int x = Game1.player.GetBoundingBox().Center.X; - int y = Game1.player.GetBoundingBox().Center.Y; - - int offset = 64; - - switch (Game1.player.FacingDirection) + get { - case 0: - y -= offset; - break; - case 1: - x += offset; - break; - case 2: - y += offset; - break; - case 3: - x -= offset; - break; - } + if (Game1.player == null) + return 0; - x /= Game1.tileSize; - y /= Game1.tileSize; - return new Vector2(x, y); + int maxStamina = Game1.player.maxStamina.Value; + int currentStamine = (int)Game1.player.stamina; + + int staminaPercentage = (int)(currentStamine * 100) / maxStamina; + + return staminaPercentage; + } + } + + /// + /// Returns the tile location of the player + /// + public static Vector2 Position + { + get + { + if (Game1.player == null) + return Vector2.Zero; + + return Game1.player.getTileLocation(); + } + } + + /// + /// Returns the X coordinate of the player + /// + public static int PositionX + { + get + { + if (Game1.player == null) + return 0; + + return (int)Position.X; + } + } + + /// + /// Returns the Y coordinate of the player + /// + public static int PositionY + { + get + { + if (Game1.player == null) + return 0; + + return (int)Position.Y; + } + } + + /// + /// Returns the time in the 12 hours format + /// + public static string TimeOfDay + { + get + { + int timeOfDay = Game1.timeOfDay; + + int minutes = timeOfDay % 100; + int hours = timeOfDay / 100; + string amOrpm = "A M"; + if (hours >= 12) + { + amOrpm = "P M"; + if (hours > 12) + hours -= 12; + } + + return $"{hours}:{minutes} {amOrpm}"; + } + } + + /// + /// Returns the current season + /// + public static string Season => Game1.CurrentSeasonDisplayName; + + /// + /// Returns the current date of month + /// + public static int Date => Game1.dayOfMonth; + + /// + /// Returns the current day of week + /// + /// + public static string Day => Game1.Date.DayOfWeek.ToString(); + + /// + /// Returns the amount of money the player has currently + /// + public static int Money + { + get + { + if (Game1.player == null) + return -1; + + return Game1.player.Money; + } + } + + /// + /// Returns the tile position of the tile the player is facing + /// + /// + public static Vector2 FacingTile + { + get + { + int x = Game1.player.GetBoundingBox().Center.X; + int y = Game1.player.GetBoundingBox().Center.Y; + + int offset = 64; + + switch (Game1.player.FacingDirection) + { + case 0: + y -= offset; + break; + case 1: + x += offset; + break; + case 2: + y += offset; + break; + case 3: + x -= offset; + break; + } + + x /= Game1.tileSize; + y /= Game1.tileSize; + return new Vector2(x, y); + } } } } diff --git a/stardew-access/Features/Radar.cs b/stardew-access/Features/Radar.cs index 5253de9..2c3c050 100644 --- a/stardew-access/Features/Radar.cs +++ b/stardew-access/Features/Radar.cs @@ -262,7 +262,7 @@ namespace stardew_access.Features #region Check whether to skip the object or not // Skip if player is directly looking at the tile - if (CurrentPlayer.getNextTile().Equals(position)) + if (CurrentPlayer.FacingTile.Equals(position)) return; if (!radarFocus) diff --git a/stardew-access/Features/ReadTile.cs b/stardew-access/Features/ReadTile.cs index 40ad4c5..5017cb7 100644 --- a/stardew-access/Features/ReadTile.cs +++ b/stardew-access/Features/ReadTile.cs @@ -25,12 +25,12 @@ namespace stardew_access.Features if (!playersPosition) { // Grab tile - tile = CurrentPlayer.getNextTile(); + tile = CurrentPlayer.FacingTile; } else { // Player's standing tile - tile = CurrentPlayer.getPosition(); + tile = CurrentPlayer.Position; } x = (int)tile.X; y = (int)tile.Y; diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 28776c4..c79e472 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -220,11 +220,11 @@ namespace stardew_access string toSpeak; if (Config.VerboseCoordinates) { - toSpeak = $"X: {CurrentPlayer.getPositionX()}, Y: {CurrentPlayer.getPositionY()}"; + toSpeak = $"X: {CurrentPlayer.PositionX}, Y: {CurrentPlayer.PositionY}"; } else { - toSpeak = $"{CurrentPlayer.getPositionX()}, {CurrentPlayer.getPositionY()}"; + toSpeak = $"{CurrentPlayer.PositionX}, {CurrentPlayer.PositionY}"; } MainClass.ScreenReader.Say(toSpeak, true); @@ -234,7 +234,7 @@ namespace stardew_access // Narrate health and stamina if (Config.HealthNStaminaKey.JustPressed()) { - string toSpeak = $"Health is {CurrentPlayer.getHealth()} and Stamina is {CurrentPlayer.getStamina()}"; + string toSpeak = $"Health is {CurrentPlayer.Health} and Stamina is {CurrentPlayer.Stamina}"; MainClass.ScreenReader.Say(toSpeak, true); return; } @@ -242,7 +242,7 @@ namespace stardew_access // Narrate money at hand if (Config.MoneyKey.JustPressed()) { - string toSpeak = $"You have {CurrentPlayer.getMoney()}g"; + string toSpeak = $"You have {CurrentPlayer.Money}g"; MainClass.ScreenReader.Say(toSpeak, true); return; } @@ -250,7 +250,7 @@ namespace stardew_access // Narrate time and season if (Config.TimeNSeasonKey.JustPressed()) { - string toSpeak = $"Time is {CurrentPlayer.getTimeOfDay()} and it is {CurrentPlayer.getDay()} {CurrentPlayer.getDate()} of {CurrentPlayer.getSeason()}"; + string toSpeak = $"Time is {CurrentPlayer.TimeOfDay} and it is {CurrentPlayer.Day} {CurrentPlayer.Date} of {CurrentPlayer.Season}"; MainClass.ScreenReader.Say(toSpeak, true); return; } diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index d8c0ce8..7fffaef 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -436,7 +436,7 @@ namespace stardew_access.Patches if (cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep") { - Vector2 nextTile = CurrentPlayer.getNextTile(); + Vector2 nextTile = CurrentPlayer.FacingTile; if (TileInfo.isCollidingAtTile((int)nextTile.X, (int)nextTile.Y)) { if (prevTile != nextTile)