diff --git a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs index 409b705..1a90347 100644 --- a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs +++ b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs @@ -143,7 +143,7 @@ namespace stardew_access.Patches int itemStack = ___ingredients[i].Stack; string itemQuality = ""; - int qualityValue = ((StardewValley.Object)___ingredients[i]).quality; + int qualityValue = ((StardewValley.Object)___ingredients[i]).Quality; if (qualityValue == 1) { itemQuality = "Silver quality"; diff --git a/stardew-access/Patches/DialoguePatches.cs b/stardew-access/Patches/DialoguePatches.cs index a253d84..9eaab5b 100644 --- a/stardew-access/Patches/DialoguePatches.cs +++ b/stardew-access/Patches/DialoguePatches.cs @@ -216,9 +216,9 @@ namespace stardew_access.Patches #endregion #region Add quality of item - if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).quality > 0) + if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).Quality > 0) { - int quality = ((StardewValley.Object)hoveredItem).quality; + int quality = ((StardewValley.Object)hoveredItem).Quality; if (quality == 1) { toSpeak = $"{toSpeak} Silver quality"; diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index b6dfaa4..a50aef0 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -281,7 +281,7 @@ namespace stardew_access.Patches if ((item as StardewValley.Object) != null) { - int quality = ((StardewValley.Object)item).quality; + int quality = ((StardewValley.Object)item).Quality; if (quality == 1) { toSpeak = $"Silver quality {toSpeak}"; @@ -1477,9 +1477,9 @@ namespace stardew_access.Patches string requirements = ""; #region Add quality of item - if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).quality > 0) + if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).Quality > 0) { - int qualityIndex = ((StardewValley.Object)actualInventory[i]).quality; + int qualityIndex = ((StardewValley.Object)actualInventory[i]).Quality; if (qualityIndex == 1) { quality = "Silver quality"; diff --git a/stardew-access/Patches/MuseumMenuPatches.cs b/stardew-access/Patches/MuseumMenuPatches.cs index 3949de2..e472b77 100644 --- a/stardew-access/Patches/MuseumMenuPatches.cs +++ b/stardew-access/Patches/MuseumMenuPatches.cs @@ -1,3 +1,6 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using StardewModdingAPI; using StardewValley; using StardewValley.Locations; using StardewValley.Menus; @@ -8,6 +11,23 @@ namespace stardew_access.Patches { private static string museumQueryKey = " "; private static bool isMoving = false; + private static (int x, int y)[] donationTiles = + { + (26,5),(26,6),(26,7),(26,8),(26,9),(26,10),(26,11), + (29,5),(30,5),(31,5),(32,5),(33,5),(34,5),(35,5),(36,5), + (28,6),(29,6),(30,6),(31,6),(32,6),(33,6),(34,6),(35,6),(36,6),(37,6), + (28,9),(29,9),(30,9),(31,9),(32,9),(33,9),(34,9),(35,9),(36,9), + (28,10),(29,10),(30,10),(31,10),(32,10),(33,10),(34,10),(35,10),(36,10), + (30,13),(31,13),(32,13),(33,13),(34,13), + (30,14),(31,14),(32,14),(33,14),(34,14), + (28,15),(29,15),(30,15),(31,15),(32,15),(33,15),(34,15),(35,15),(36,15), + (28,16),(29,16),(30,16),(31,16),(32,16),(33,16),(34,16),(35,16),(36,16), + (39,6),(40,6),(41,6),(42,6),(43,6),(44,6),(45,6),(46,6), + (39,7),(40,7),(41,7),(42,7),(43,7),(44,7),(45,7),(46,7), + (48,5),(48,6),(48,7), + (42,15),(43,15),(44,15),(45,15),(46,15),(47,15), + (42,16),(43,16),(44,16),(45,16),(46,16),(47,16), + }; internal static bool MuseumMenuKeyPressPatch() { @@ -57,17 +77,67 @@ namespace stardew_access.Patches else { // Player Inventory - if (!narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + int i = narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y); + if (i != -9999) { - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + bool isCPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.C); // For donating hovered item + + if (isCPressed && __instance.inventory.actualInventory[i] != null) { - if (museumQueryKey != $"ok button") + foreach (var tile in donationTiles) { - museumQueryKey = $"ok button"; - MainClass.GetScreenReader().Say("ok button", true); + #region Manually donates the hovered item (https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Menus/MuseumMenu.cs#L206-L247) + int tileX = tile.x; + int tileY = tile.y; + + if (((LibraryMuseum)Game1.currentLocation).isTileSuitableForMuseumPiece(tileX, tileY) && ((LibraryMuseum)Game1.currentLocation).isItemSuitableForDonation(__instance.inventory.actualInventory[i])) + { + int objectID = __instance.inventory.actualInventory[i].parentSheetIndex; + int rewardsCount = ((LibraryMuseum)Game1.currentLocation).getRewardsForPlayer(Game1.player).Count; + ((LibraryMuseum)Game1.currentLocation).museumPieces.Add(new Vector2(tileX, tileY), ((StardewValley.Object)__instance.inventory.actualInventory[i]).parentSheetIndex); + Game1.playSound("stoneStep"); + if (((LibraryMuseum)Game1.currentLocation).getRewardsForPlayer(Game1.player).Count > rewardsCount) + { + Game1.playSound("reward"); + } + else + { + Game1.playSound("newArtifact"); + } + Game1.player.completeQuest(24); + __instance.inventory.actualInventory[i].Stack--; + if (__instance.inventory.actualInventory[i].Stack <= 0) + { + __instance.inventory.actualInventory[i] = null; + } + int pieces = ((LibraryMuseum)Game1.currentLocation).museumPieces.Count(); + Game1.stats.checkForArchaeologyAchievements(); + switch (pieces) + { + case 95: + globalChatInfoMessage("MuseumComplete", Game1.player.farmName); + break; + case 40: + globalChatInfoMessage("Museum40", Game1.player.farmName); + break; + default: + globalChatInfoMessage("donation", Game1.player.name, "object:" + objectID); + break; + } + break; + } + #endregion } } } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + if (museumQueryKey != $"ok button") + { + museumQueryKey = $"ok button"; + MainClass.GetScreenReader().Say("ok button", true); + } + } } } catch (Exception e) @@ -76,7 +146,8 @@ namespace stardew_access.Patches } } - internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y) + // Returns the index of the hovered item or -9999 + internal static int narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y) { #region Narrate hovered item for (int i = 0; i < inventory.Count; i++) @@ -93,9 +164,9 @@ namespace stardew_access.Patches string quality = ""; #region Add quality of item - if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).quality > 0) + if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).Quality > 0) { - int qualityIndex = ((StardewValley.Object)actualInventory[i]).quality; + int qualityIndex = ((StardewValley.Object)actualInventory[i]).Quality; if (qualityIndex == 1) { quality = "Silver quality"; @@ -136,11 +207,73 @@ namespace stardew_access.Patches museumQueryKey = $"{toSpeak}:{i}"; MainClass.GetScreenReader().Say(toSpeak, true); } - return true; + return i; } } #endregion - return false; + return -9999; } + + #region These methods are taken from the game's source code, https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Multiplayer.cs#L1331-L1395 + internal static void globalChatInfoMessage(string messageKey, params string[] args) + { + if (Game1.IsMultiplayer || Game1.multiplayerMode != 0) + { + receiveChatInfoMessage(Game1.player, messageKey, args); + sendChatInfoMessage(messageKey, args); + } + } + + internal static void sendChatInfoMessage(string messageKey, params string[] args) + { + if (Game1.IsClient) + { + Game1.client.sendMessage(15, messageKey, args); + } + else if (Game1.IsServer) + { + foreach (long id in Game1.otherFarmers.Keys) + { + Game1.server.sendMessage(id, 15, Game1.player, messageKey, args); + } + } + } + + internal static void receiveChatInfoMessage(Farmer sourceFarmer, string messageKey, string[] args) + { + if (Game1.chatBox != null) + { + try + { + string[] processedArgs = args.Select(delegate (string arg) + { + if (arg.StartsWith("achievement:")) + { + int key = Convert.ToInt32(arg.Substring("achievement:".Length)); + return Game1.content.Load>("Data\\Achievements")[key].Split('^')[0]; + } + return arg.StartsWith("object:") ? new StardewValley.Object(Convert.ToInt32(arg.Substring("object:".Length)), 1).DisplayName : arg; + }).ToArray(); + ChatBox chatBox = Game1.chatBox; + LocalizedContentManager content = Game1.content; + string path = "Strings\\UI:Chat_" + messageKey; + object[] substitutions = processedArgs; + chatBox.addInfoMessage(content.LoadString(path, substitutions)); + } + catch (ContentLoadException) + { + } + catch (FormatException) + { + } + catch (OverflowException) + { + } + catch (KeyNotFoundException) + { + } + } + } + #endregion } } \ No newline at end of file