From b254fa95fa1b910b111b05d4e45d1617722ed1b7 Mon Sep 17 00:00:00 2001 From: yangzhi <@4F!xZpJwly&KbWq> Date: Wed, 12 Feb 2020 12:01:59 +0800 Subject: [PATCH] Rewrite for missing Utility.getRandomItemFromSeason method --- .../RewriteFacades/UtilityMethods.cs | 64 ++++++++++++++++++- src/SMAPI/SMAPI.csproj | 12 ++-- 2 files changed, 68 insertions(+), 8 deletions(-) diff --git a/src/SMAPI/Framework/RewriteFacades/UtilityMethods.cs b/src/SMAPI/Framework/RewriteFacades/UtilityMethods.cs index b4f225ae..83efc9d5 100644 --- a/src/SMAPI/Framework/RewriteFacades/UtilityMethods.cs +++ b/src/SMAPI/Framework/RewriteFacades/UtilityMethods.cs @@ -1,5 +1,9 @@ +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Reflection; using StardewValley; +using StardewValley.Locations; namespace StardewModdingAPI.Framework.RewriteFacades { @@ -18,9 +22,65 @@ namespace StardewModdingAPI.Framework.RewriteFacades } [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] - public static new int getRandomItemFromSeason(string season, int randomSeedAddition, bool forQuest, bool changeDaily = true) + public static int getRandomItemFromSeason(string season, int randomSeedAddition, bool forQuest, bool changeDaily = true) { - return getRandomItemFromSeason(season, randomSeedAddition, forQuest); + Random random = new Random((int)Game1.uniqueIDForThisGame + (changeDaily ? (int)Game1.stats.DaysPlayed : 0) + randomSeedAddition); + List source = new List() { 68, 66, 78, 80, 86, 152, 167, 153, 420 }; + List stringList1 = new List(Game1.player.craftingRecipes.Keys); + List stringList2 = new List(Game1.player.cookingRecipes.Keys); + if (forQuest) + { + stringList1 = Utility.GetAllPlayerUnlockedCraftingRecipes(); + stringList2 = Utility.GetAllPlayerUnlockedCookingRecipes(); + } + if (forQuest && (MineShaft.lowestLevelReached > 40 || Utility.GetAllPlayerDeepestMineLevel() >= 1) || !forQuest && (Game1.player.deepestMineLevel > 40 || Game1.player.timesReachedMineBottom >= 1)) + source.AddRange(new int[5] { 62, 70, 72, 84, 422 }); + if (forQuest && (MineShaft.lowestLevelReached > 80 || Utility.GetAllPlayerDeepestMineLevel() >= 1) || !forQuest && (Game1.player.deepestMineLevel > 80 || Game1.player.timesReachedMineBottom >= 1)) + source.AddRange(new int[3] { 64, 60, 82 }); + if (Utility.doesAnyFarmerHaveMail("ccVault")) + source.AddRange(new int[4] { 88, 90, 164, 165 }); + if (stringList1.Contains("Furnace")) + source.AddRange(new int[4] { 334, 335, 336, 338 }); + if (stringList1.Contains("Quartz Globe")) + source.Add(339); + if (season.Equals("spring")) + source.AddRange(new int[17] { 0x10, 0x12, 20, 0x16, 0x81, 0x83, 0x84, 0x88, 0x89, 0x8e, 0x8f, 0x91, 0x93, 0x94, 0x98, 0xa7, 0x10b }); + else if (season.Equals("summer")) + source.AddRange(new int[] { 0x80, 130, 0x84, 0x88, 0x8a, 0x8e, 0x90, 0x91, 0x92, 0x95, 150, 0x9b, 0x18c, 0x18e, 0x192, 0x10b }); + else if (season.Equals("fall")) + source.AddRange(new int[] { 0x194, 0x196, 0x198, 410, 0x81, 0x83, 0x84, 0x88, 0x89, 0x8b, 140, 0x8e, 0x8f, 0x94, 150, 0x9a, 0x9b, 0x10d }); + else if (season.Equals("winter")) + source.AddRange(new int[] { 0x19c, 0x19e, 0x1a0, 0x1a2, 130, 0x83, 0x84, 0x88, 140, 0x8d, 0x90, 0x92, 0x93, 150, 0x97, 0x9a, 0x10d }); + if (forQuest) + { + foreach (string key in stringList2) + { + if (random.NextDouble() >= 0.4) + { + List intList = Utility.possibleCropsAtThisTime(Game1.currentSeason, Game1.dayOfMonth <= 7); + Dictionary dictionary = Game1.content.Load>("Data//CookingRecipes"); + if (dictionary.ContainsKey(key)) + { + string[] strArray = dictionary[key].Split('/')[0].Split(' '); + bool flag = true; + for (int index = 0; index < strArray.Length; ++index) + { + MethodInfo isCategoryIngredientAvailable = typeof(Utility).GetMethod("isCategoryIngredientAvailable", BindingFlags.NonPublic | BindingFlags.Static); + if (!source.Contains(Convert.ToInt32(strArray[index])) + && !(bool)isCategoryIngredientAvailable.Invoke(null, new object[] { Convert.ToInt32(strArray[index]) }) + && (intList == null || !intList.Contains(Convert.ToInt32(strArray[index])))) + { + flag = false; + break; + } + } + if (flag) + source.Add(Convert.ToInt32(dictionary[key].Split('/')[2])); + } + } + } + } + return source[random.Next(source.Count)]; } } } diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index 2ed7c567..383a9aa4 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -42,10 +42,10 @@ ..\..\..\..\..\AndroidStudioProjects\SMAPI Android Installer\app\src\main\assets\Stardew\0Harmony.dll - ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.130\assemblies\Google.Android.Vending.Expansion.Downloader.dll + ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.131\assemblies\Google.Android.Vending.Expansion.Downloader.dll - ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.130\assemblies\Google.Android.Vending.Licensing.dll + ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.131\assemblies\Google.Android.Vending.Licensing.dll @@ -53,7 +53,7 @@ ..\..\..\..\..\AndroidStudioProjects\SMAPI Android Installer\app\src\main\assets\Stardew\Mono.Cecil.dll - ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.130\assemblies\MonoGame.Framework.dll + ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.131\assemblies\MonoGame.Framework.dll ..\..\..\..\..\AndroidStudioProjects\SMAPI Android Installer\app\src\main\assets\Stardew\MonoMod.RuntimeDetour.dll @@ -68,10 +68,10 @@ ..\SMAPI.Toolkit\bin\Debug\net4.5\SMAPI.Toolkit.dll - ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.130\assemblies\StardewValley.dll + ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.131\assemblies\StardewValley.dll - ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.130\assemblies\StardewValley.GameData.dll + ..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.4.131\assemblies\StardewValley.GameData.dll @@ -181,7 +181,6 @@ - @@ -338,6 +337,7 @@ +