From 6c8eddd08b16ad87d1d737cd89d49321bbbe0fbb Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Wed, 19 Jan 2022 12:26:13 +0530 Subject: [PATCH] Added other things to the radar --- stardew-access/Game/Radar.cs | 125 +++++++++++++++++++++----------- stardew-access/Game/ReadTile.cs | 81 +++++++++++---------- stardew-access/ModEntry.cs | 5 +- 3 files changed, 129 insertions(+), 82 deletions(-) diff --git a/stardew-access/Game/Radar.cs b/stardew-access/Game/Radar.cs index ea6d418..631f7d9 100644 --- a/stardew-access/Game/Radar.cs +++ b/stardew-access/Game/Radar.cs @@ -10,6 +10,7 @@ namespace stardew_access.Game { private List closed; private List furnitures; + private List npcs; public List exclusions; public bool isRunning; @@ -18,6 +19,7 @@ namespace stardew_access.Game isRunning = false; closed = new List(); furnitures = new List(); + npcs = new List(); exclusions = new List(); exclusions.Add("stone"); @@ -32,6 +34,8 @@ namespace stardew_access.Game exclusions.Add("grass"); exclusions.Add("tree"); exclusions.Add("flooring"); + exclusions.Add("water"); + exclusions.Add("door"); } public async void run() @@ -42,6 +46,7 @@ namespace stardew_access.Game closed.Clear(); furnitures.Clear(); + npcs.Clear(); findTile(currPosition, currPosition, limit); await Task.Delay(3000); @@ -60,10 +65,10 @@ namespace stardew_access.Game closed.Add(position); checkTile(position); - Vector2 northPosition = new Vector2(position.X, position.Y-1); - Vector2 eastPosition = new Vector2(position.X+1, position.Y); - Vector2 westPosition = new Vector2(position.X-1, position.Y); - Vector2 southPosition = new Vector2(position.X, position.Y+1); + Vector2 northPosition = new(position.X, position.Y-1); + Vector2 eastPosition = new(position.X+1, position.Y); + Vector2 westPosition = new(position.X-1, position.Y); + Vector2 southPosition = new(position.X, position.Y+1); findTile(northPosition, center, limit); findTile(eastPosition, center, limit); @@ -75,84 +80,120 @@ namespace stardew_access.Game { Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; - if (Game1.currentLocation.isObjectAtTile((int)position.X, (int)position.Y)) + // Check for npcs + if (Game1.currentLocation.isCharacterAtTile(position) != null && !exclusions.Contains("npc")) { - string? obj = ReadTile.getObjectNameAtTile((int)position.X, (int)position.Y); - StardewValley.Object @object = Game1.currentLocation.getObjectAtTile((int)position.X, (int)position.Y); - - if (@object is Furniture && !exclusions.Contains("furniture")) + NPC npc = Game1.currentLocation.isCharacterAtTile(position); + if (!npcs.Contains(npc)) { - if (!furnitures.Contains(@object as Furniture)) - { - furnitures.Add(@object as Furniture); - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"FUR:{@object.DisplayName}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); - } - } - else if (!exclusions.Contains(obj.ToLower())) - { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"OBJ:{obj}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, npc.displayName); } } + // Check for water + else if (Game1.currentLocation.isWaterTile((int)position.X, (int)position.Y) && !exclusions.Contains("water")) + { + playSoundAt(position, null); + } + // Check for objects + else if (Game1.currentLocation.isObjectAtTile((int)position.X, (int)position.Y)) + { + string? objectName = ReadTile.getObjectNameAtTile((int)position.X, (int)position.Y); + StardewValley.Object obj = Game1.currentLocation.getObjectAtTile((int)position.X, (int)position.Y); + + if (objectName != null) + { + if (obj is Furniture && !exclusions.Contains("furniture")) + { + if (!furnitures.Contains(obj as Furniture)) + { + furnitures.Add(obj as Furniture); + playSoundAt(position, objectName); + } + } + else + { + playSoundAt(position, objectName); + } + } + } + // Check for terrain features else if (terrainFeature.ContainsKey(position)) { Netcode.NetRef tr = terrainFeature[position]; - string? terrain = ReadTile.getTerrainFeatureAtTile(tr); - if (tr != null) + string? terrain = ReadTile.getTerrainFeatureAtTile(tr).ToLower(); + if (terrain != null) { if(tr.Get() is HoeDirt && !exclusions.Contains("crop")) { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"CROP:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, terrain); } else if(tr.Get() is GiantCrop && !exclusions.Contains("giant crop")) { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"BUSH:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, terrain); } else if (tr.Get() is Bush && !exclusions.Contains("bush")) { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"BUSH:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, terrain); } else if (tr.Get() is CosmeticPlant && !exclusions.Contains("cosmetic plant")) { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"COSMETIC_PLANT:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, terrain); } else if (tr.Get() is Flooring && !exclusions.Contains("flooring")) { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"FLOORING:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, terrain); } else if (tr.Get() is FruitTree && !exclusions.Contains("fruit tree")) { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"FRUTI_TREE:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, terrain); } else if (tr.Get() is Grass && !exclusions.Contains("grass")) { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"GRASS:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, terrain); } else if (tr.Get() is Tree && !exclusions.Contains("tree")) { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"TREE:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, terrain); } else if (tr.Get() is Quartz && !exclusions.Contains("quartz")) { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"QUARTZ:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, terrain); } else if (tr.Get() is Leaf && !exclusions.Contains("leaf")) { - Game1.currentLocation.localSoundAt("sa_poi", position); - MainClass.monitor.Log($"LEAF:{terrain}\tX:{position.X}\tY:{position.Y}", StardewModdingAPI.LogLevel.Debug); + playSoundAt(position, terrain); } } } + // Check for Mine ladders + else if (ReadTile.isMineLadderAtTile((int)position.X, (int)position.Y) && !exclusions.Contains("ladder")) + { + playSoundAt(position, null); + } + // Check for doors + else if (ReadTile.isDoorAtTile((int)position.X, (int)position.Y) && !exclusions.Contains("door")) + { + playSoundAt(position, null); + } + // Check for buildings on maps + else if (ReadTile.getBuildingAtTile((int)position.X, (int)position.Y) != null) + { + playSoundAt(position, ReadTile.getBuildingAtTile((int)position.X, (int)position.Y)); + } + // Check for resource clumps + else if (ReadTile.getResourceClumpAtTile((int)position.X, (int)position.Y) != null) + { + playSoundAt(position, ReadTile.getResourceClumpAtTile((int)position.X, (int)position.Y)); + } + } + + public void playSoundAt(Vector2 position, String? searchQuery) + { + if (searchQuery == null || !exclusions.Contains(searchQuery)) + { + MainClass.monitor.Log($"{searchQuery}:X={position.X} Y={position.Y}", StardewModdingAPI.LogLevel.Debug); + Game1.currentLocation.localSoundAt("sa_poi", position); + } } } } diff --git a/stardew-access/Game/ReadTile.cs b/stardew-access/Game/ReadTile.cs index 0c2d6bc..dca5abe 100644 --- a/stardew-access/Game/ReadTile.cs +++ b/stardew-access/Game/ReadTile.cs @@ -74,44 +74,9 @@ namespace stardew_access.Game { toSpeak = "Ladder"; } - else + else if(getBuildingAtTile(x, y) != null) { - try - { - int index = Game1.currentLocation.Map.GetLayer("Buildings").Tiles[x, y].TileIndex; - /* Add More - MainClass.monitor.Log(index.ToString(), LogLevel.Debug); - */ - switch (index) - { - case 1955: - case 41: - toSpeak = "Mail Box"; - break; - case 173: - toSpeak = "Fridge"; - break; - case 169: - case 170: - case 171: - case 172: - toSpeak = "Kitchen"; - break; - case 1003: - toSpeak = "Street lamp"; - break; - case 78: - toSpeak = "Trash bin"; - break; - case 617: - toSpeak = "Daily quest"; - break; - case 616: - toSpeak = "Calender"; - break; - } - } - catch (Exception) {} + toSpeak = getBuildingAtTile(x, y); } #endregion @@ -136,6 +101,48 @@ namespace stardew_access.Game isReadingTile = false; } + public static string? getBuildingAtTile(int x, int y) + { + string? toReturn = null; + int? 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 173: + toReturn = "Fridge"; + break; + case 169: + case 170: + case 171: + case 172: + toReturn = "Kitchen"; + break; + case 1003: + toReturn = "Street lamp"; + break; + case 78: + toReturn = "Trash bin"; + break; + case 617: + toReturn = "Daily quest"; + break; + case 616: + toReturn = "Calender"; + break; + } + } + + return toReturn; + } + public static string getTerrainFeatureAtTile(Netcode.NetRef terrain) { string? toReturn = null; diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 4a6d6ab..f3ce949 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -383,12 +383,11 @@ namespace stardew_access ReadTile.run(manuallyTriggered: true); } - // Manual read tile - if (Equals(e.Button, SButton.B)) + /*if (Equals(e.Button, SButton.B)) { Game1.player.controller = new PathFindController(Game1.player, Game1.currentLocation, new Point(49,13), 2); monitor.Log($"{Game1.player.controller.pathToEndPoint==null}", LogLevel.Debug); // true if path not found - } + }*/ } private void SnapMouseToPlayer()