From ea3ffb4e18904c0005f5a3cc36eb9c6029e28abf Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Fri, 21 Jan 2022 14:21:43 +0530 Subject: [PATCH] Added junimo bundle narration in read tile --- stardew-access/Game/ReadTile.cs | 132 +++++++++++++++++--------- stardew-access/Patches/MenuPatches.cs | 5 +- 2 files changed, 89 insertions(+), 48 deletions(-) diff --git a/stardew-access/Game/ReadTile.cs b/stardew-access/Game/ReadTile.cs index fe19f4c..dc33502 100644 --- a/stardew-access/Game/ReadTile.cs +++ b/stardew-access/Game/ReadTile.cs @@ -81,14 +81,25 @@ namespace stardew_access.Game { toSpeak = getBuildingAtTile(x, y); } + else if(getJunimoBundleAt(x, y) != null) + { + toSpeak = getJunimoBundleAt(x, y); + } #endregion #region Narrate toSpeak if (toSpeak != " ") - if (manuallyTriggered) - ScreenReader.say(toSpeak, true); - else - ScreenReader.sayWithTileQuery(toSpeak, x, y, true); + if (manuallyTriggered) + ScreenReader.say(toSpeak, true); + else + ScreenReader.sayWithTileQuery(toSpeak, x, y, true); + #endregion + + #region Play colliding sound effect + if (isCollidingAtTile(x, y) && prevTile != gt) + { + Game1.playSound("colliding"); + } #endregion prevTile = gt; @@ -104,6 +115,42 @@ namespace stardew_access.Game isReadingTile = false; } + private static string? getJunimoBundleAt(int x, int y) + { + if (Game1.currentLocation is not CommunityCenter) + return null; + + CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); + + string? name = (x, y) switch + { + (14, 5) => "Pantry", + (14, 23) => "Crafts Room", + (40, 10) => "Fish Tank", + (63, 14) => "Boiler Room", + (55, 6) => "Vault", + (46, 11) => "Bulletin Board", + _ => null, + }; + + if (communityCenter.shouldNoteAppearInArea(CommunityCenter.getAreaNumberFromName(name))) + return $"{name} bundle"; + else + return null; + } + + public static bool isCollidingAtTile(int x, int y) + { + Rectangle rect = new Rectangle(x * 64 + 1,y * 64 + 1, 62, 62); + + if (Game1.currentLocation.isCollidingPosition(rect, Game1.viewport, true, 0, glider: false, Game1.player, pathfinding: true)) + { + return true; + } + + return false; + } + public static string? getFarmAnimalAt(GameLocation? location, int x, int y, bool onlyName = false) { if (location == null) @@ -147,56 +194,51 @@ namespace stardew_access.Game { string? toReturn = null; - // It throws error if it can't find the index, do something else to fix this - try + int? index = null; + + if (Game1.currentLocation.Map.GetLayer("Buildings").Tiles[x, y] != null) + index = Game1.currentLocation.Map.GetLayer("Buildings").Tiles[x, y].TileIndex; + /* Add More + MainClass.monitor.Log(index.ToString(), LogLevel.Debug); + */ + if (index != null) { - int? index = null; - - if (Game1.currentLocation.Map.GetLayer("Buildings").Tiles[x, y]!=null) - index = Game1.currentLocation.Map.GetLayer("Buildings").Tiles[x, y].TileIndex; - /* Add More - MainClass.monitor.Log(index.ToString(), LogLevel.Debug); - */ - if (index != null) + switch (index) + { + case 1955: + case 41: + toReturn = "Mail Box"; + break; + case 1003: + toReturn = "Street lamp"; + break; + case 78: + toReturn = "Trash bin"; + break; + case 617: + toReturn = "Daily quest"; + break; + case 616: + toReturn = "Calender"; + break; + } + + if (Game1.currentLocation is FarmHouse || Game1.currentLocation is IslandFarmHouse) { switch (index) { - case 1955: - case 41: - toReturn = "Mail Box"; + case 173: + toReturn = "Fridge"; break; - case 1003: - toReturn = "Street lamp"; + case 169: + case 170: + case 171: + case 172: + toReturn = "Kitchen"; break; - case 78: - toReturn = "Trash bin"; - break; - case 617: - toReturn = "Daily quest"; - break; - case 616: - toReturn = "Calender"; - break; - } - - if(Game1.currentLocation is FarmHouse || Game1.currentLocation is IslandFarmHouse) - { - switch (index) - { - case 173: - toReturn = "Fridge"; - break; - case 169: - case 170: - case 171: - case 172: - toReturn = "Kitchen"; - break; - } } } } - catch (Exception) {} return toReturn; } diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 9c53b77..946e1ce 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -25,13 +25,12 @@ namespace stardew_access.Patches if(cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep") { Vector2 nextTile = CurrentPlayer.getNextTile(); - Rectangle rect = new Rectangle((int)nextTile.X * 64 + 1,(int) nextTile.Y * 64 + 1, 62, 62); - if (Game1.currentLocation.isCollidingPosition(rect, Game1.viewport, true, 0, glider: false, Game1.player, pathfinding: false)) + if (ReadTile.isCollidingAtTile((int)nextTile.X, (int)nextTile.Y)) { if (prevTile != nextTile) { prevTile = nextTile; - Game1.playSound("colliding"); + //Game1.playSound("colliding"); } return false; }