From e916e274277d41a48258db7587cf1d421868961d Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Thu, 20 Jan 2022 19:07:21 +0530 Subject: [PATCH] Added animal narration | Bug fix in location narration --- stardew-access/Game/Radar.cs | 8 ++++ stardew-access/Game/ReadTile.cs | 56 +++++++++++++++++++++++++- stardew-access/Game/SlotAndLocation.cs | 2 +- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/stardew-access/Game/Radar.cs b/stardew-access/Game/Radar.cs index 994b4c6..3565a9a 100644 --- a/stardew-access/Game/Radar.cs +++ b/stardew-access/Game/Radar.cs @@ -99,6 +99,12 @@ namespace stardew_access.Game playSoundAt(position, npc.displayName, typeof(NPC)); } } + // Check for animals + else if (ReadTile.getFarmAnimalAt(Game1.currentLocation, (int)position.X, (int)position.Y) != null && !exclusions.Contains("animals")) + { + string name = ReadTile.getFarmAnimalAt(Game1.currentLocation, (int)position.X, (int)position.Y, onlyName: true); + playSoundAt(position, name, typeof(FarmAnimal)); + } // Check for water else if (Game1.currentLocation.isWaterTile((int)position.X, (int)position.Y) && !exclusions.Contains("water")) { @@ -247,6 +253,8 @@ namespace stardew_access.Game if(soundType == typeof(Farmer)) // Villagers and farmers soundName = $"npc{soundName}"; + if (soundType == typeof(FarmAnimal)) // Farm Animals + soundName = $"npc{soundName}"; else if(soundType == typeof(NPC)) // Other npcs, also includes enemies soundName = $"obj{soundName}"; else if(soundType == typeof(WaterTiles)) // Water tiles diff --git a/stardew-access/Game/ReadTile.cs b/stardew-access/Game/ReadTile.cs index c77410b..b907a0c 100644 --- a/stardew-access/Game/ReadTile.cs +++ b/stardew-access/Game/ReadTile.cs @@ -2,6 +2,7 @@ using StardewModdingAPI; using StardewValley; using StardewValley.Locations; +using StardewValley.Objects; using StardewValley.TerrainFeatures; namespace stardew_access.Game @@ -44,6 +45,10 @@ namespace stardew_access.Game NPC npc = Game1.currentLocation.isCharacterAtTile(gt); toSpeak = npc.displayName; } + else if(getFarmAnimalAt(Game1.currentLocation, x, y) != null) + { + toSpeak = getFarmAnimalAt(Game1.currentLocation, x, y); + } else if (Game1.currentLocation.isWaterTile(x, y)) { toSpeak = "Water"; @@ -99,6 +104,45 @@ namespace stardew_access.Game isReadingTile = false; } + public static string? getFarmAnimalAt(GameLocation? location, int x, int y, bool onlyName = false) + { + if (location == null) + return null; + + if (location is not Farm && location is not AnimalHouse) + return null; + + List? farmAnimals = null; + + if(location is Farm) + farmAnimals = (location as Farm).getAllFarmAnimals(); + else if(location is AnimalHouse) + farmAnimals = (location as AnimalHouse).animals.Values.ToList(); + + if (farmAnimals == null || farmAnimals.Count <= 0) + return null; + + for(int i = 0; i < farmAnimals.Count; i++) + { + int fx = farmAnimals[i].getTileX(); + int fy = farmAnimals[i].getTileY(); + + if (fx.Equals(x) && fy.Equals(y)) + { + string name = farmAnimals[i].displayName; + int age = farmAnimals[i].age.Value; + string type = farmAnimals[i].displayType; + + if (onlyName) + return name; + + return $"{name}, {type}, age {age}"; + } + } + + return null; + } + public static string? getBuildingAtTile(int x, int y) { string? toReturn = null; @@ -106,7 +150,10 @@ namespace stardew_access.Game // It throws error if it can't find the index, do something else to fix this try { - int? index = Game1.currentLocation.Map.GetLayer("Buildings").Tiles[x, y].TileIndex; + 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); */ @@ -465,6 +512,13 @@ namespace stardew_access.Game } } + if(obj is Chest) + { + Chest chest = (Chest)obj; + toReturn = chest.Type; + toReturn = chest.DisplayName; + } + return toReturn; } diff --git a/stardew-access/Game/SlotAndLocation.cs b/stardew-access/Game/SlotAndLocation.cs index adc9b7f..9b2bc85 100644 --- a/stardew-access/Game/SlotAndLocation.cs +++ b/stardew-access/Game/SlotAndLocation.cs @@ -39,7 +39,7 @@ namespace stardew_access.Game return; previousLocation = currentLocation; - ScreenReader.say($"{currentLocation.NameOrUniqueName} Entered",true); + ScreenReader.say($"{currentLocation.Name} Entered",true); } } }