From 062497e7ae7862ce23be405681d694c961b02a55 Mon Sep 17 00:00:00 2001 From: Miguel Angel Padilla Abrego Date: Fri, 31 May 2024 19:31:26 -0600 Subject: [PATCH 1/2] ReplaceJunimoHutupdateWhenFarmNotCurrentLocation --- BetterJunimos/BetterJunimos.cs | 4 +- BetterJunimos/Patches/JunimoHutPatches.cs | 59 ++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/BetterJunimos/BetterJunimos.cs b/BetterJunimos/BetterJunimos.cs index 758b08f..7a364bb 100644 --- a/BetterJunimos/BetterJunimos.cs +++ b/BetterJunimos/BetterJunimos.cs @@ -122,6 +122,7 @@ private void DoHarmonyRegistration() { // replacements for hardcoded max junimos replacements.Add("Update", junimoHutType, typeof(ReplaceJunimoHutUpdate)); + replacements.Add("updateWhenFarmNotCurrentLocation", junimoHutType, typeof(ReplaceJunimoHutupdateWhenFarmNotCurrentLocation)); replacements.Add("getUnusedJunimoNumber", junimoHutType, typeof(ReplaceJunimoHutNumber)); replacements.Add("performTenMinuteAction", junimoHutType, typeof(ReplaceJunimoTimerNumber)); @@ -254,7 +255,8 @@ void OnDayStarted(object sender, DayStartedEventArgs e) { Util.Payments.JunimoPaymentsToday.Clear(); Util.Payments.WereJunimosPaidToday = false; } - + Monitor.Log($"On day starter", + LogLevel.Debug); var huts = Util.GetAllHuts(); // tag each hut chest so later we can tell whether a GrabMenu close is for a Junimo chest or some other chest diff --git a/BetterJunimos/Patches/JunimoHutPatches.cs b/BetterJunimos/Patches/JunimoHutPatches.cs index a5c7a75..d9cd3f9 100644 --- a/BetterJunimos/Patches/JunimoHutPatches.cs +++ b/BetterJunimos/Patches/JunimoHutPatches.cs @@ -122,6 +122,63 @@ private static bool SearchHutGrid(JunimoHut hut, int radius, GameLocation farm, } } + /* Update + * + * To allow more junimos, allow working in rain + */ + [HarmonyPriority(Priority.Low)] + internal class ReplaceJunimoHutupdateWhenFarmNotCurrentLocation + { + // This is to prevent the update function from running, other than base.Update() + // Capture sendOutTimer and use to stop execution + public static void Prefix(JunimoHut __instance, ref int ___junimoSendOutTimer, out int __state) { + __state = ___junimoSendOutTimer; + ___junimoSendOutTimer = 0; + } + public static void Postfix(JunimoHut __instance, GameTime time, ref int ___junimoSendOutTimer, int __state) + { + BetterJunimos.SMonitor.Log($"ReplaceJunimoHutupdateWhenFarmNotCurrentLocation: postfix starts v1"); + if (__state <= 0) return; + if (!Context.IsMainPlayer) return; + BetterJunimos.SMonitor.Log($"ReplaceJunimoHutupdateWhenFarmNotCurrentLocation: postfix starts"); + + ___junimoSendOutTimer = __state - time.ElapsedGameTime.Milliseconds; + __instance.shouldSendOutJunimos.Value = true; + // Don't work on farmEvent days + // Base game work on event days + // if (Game1.farmEvent != null) + // return; + // Winter + if (Game1.IsWinter && !Util.Progression.CanWorkInWinter) { + return; + } + // Rain + if (Game1.isRaining && !Util.Progression.CanWorkInRain){ + BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: rain"); + return; + } + // Currently sending out a junimo + if (___junimoSendOutTimer > 0) { + BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} - ReplaceJunimoHutUpdate: sending"); + return; + } + // Already enough junimos + if (__instance.myJunimos.Count >= Util.Progression.MaxJunimosUnlocked){ + BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} Already {__instance.myJunimos.Count} Junimos, limit is {Util.Progression.MaxJunimosUnlocked}"); + return; + } + // Nothing to do + if (!__instance.areThereMatureCropsWithinRadius()) { + BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} No work for Junimos to do, not spawning another"); + return; + } + // BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: spawning"); + Util.SpawnJunimoAtHut(__instance); + // BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: postfix ends"); + ___junimoSendOutTimer = 1000; + } + } + /* Update * * To allow more junimos, allow working in rain @@ -142,7 +199,7 @@ public static void Postfix(JunimoHut __instance, GameTime time, ref int ___junim // BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: postfix starts"); ___junimoSendOutTimer = __state - time.ElapsedGameTime.Milliseconds; - + // Don't work on farmEvent days if (Game1.farmEvent != null) return; From bd1a8ade24ed62bbb8a6320b273993f05d6d60d9 Mon Sep 17 00:00:00 2001 From: Miguel Angel Padilla Abrego Date: Fri, 31 May 2024 23:20:18 -0600 Subject: [PATCH 2/2] Always On Tested --- BetterJunimos/BetterJunimos.cs | 1 + .../Patches/JunimoHarvesterPatches.cs | 5 +- BetterJunimos/Patches/JunimoHutPatches.cs | 69 +++++++++++-------- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/BetterJunimos/BetterJunimos.cs b/BetterJunimos/BetterJunimos.cs index d105645..0bcee37 100644 --- a/BetterJunimos/BetterJunimos.cs +++ b/BetterJunimos/BetterJunimos.cs @@ -121,6 +121,7 @@ private void DoHarmonyRegistration() { replacements.Add("areThereMatureCropsWithinRadius", junimoHutType, typeof(PatchSearchAroundHut)); // replacements for hardcoded max junimos + replacements.Add("dayUpdate", junimoHutType, typeof(ReplaceJunimoHutdayUpdate)); replacements.Add("Update", junimoHutType, typeof(ReplaceJunimoHutUpdate)); replacements.Add("updateWhenFarmNotCurrentLocation", junimoHutType, typeof(ReplaceJunimoHutupdateWhenFarmNotCurrentLocation)); replacements.Add("getUnusedJunimoNumber", junimoHutType, typeof(ReplaceJunimoHutNumber)); diff --git a/BetterJunimos/Patches/JunimoHarvesterPatches.cs b/BetterJunimos/Patches/JunimoHarvesterPatches.cs index 06f19f7..154a82e 100644 --- a/BetterJunimos/Patches/JunimoHarvesterPatches.cs +++ b/BetterJunimos/Patches/JunimoHarvesterPatches.cs @@ -37,7 +37,10 @@ public static bool Prefix(JunimoHarvester __instance, ref PathNode currentNode, public class PatchTryToHarvestHere { public static bool Prefix(JunimoHarvester __instance, ref int ___harvestTimer, ref NetGuid ___netHome) { if (!Context.IsMainPlayer) return true; - + if (__instance.home is null) { + //BetterJunimos.SMonitor.Log($"No hut assigned"); + return false; + } var id = ___netHome.Value; var pos = __instance.Tile; diff --git a/BetterJunimos/Patches/JunimoHutPatches.cs b/BetterJunimos/Patches/JunimoHutPatches.cs index d9cd3f9..e3957f9 100644 --- a/BetterJunimos/Patches/JunimoHutPatches.cs +++ b/BetterJunimos/Patches/JunimoHutPatches.cs @@ -40,7 +40,7 @@ public static bool Prefix(JunimoHut __instance, ref bool __result) { private static bool SearchAroundHut(JunimoHut hut) { var id = Util.GetHutIdFromHut(hut); var radius = Util.CurrentWorkingRadius; - GameLocation farm = Game1.currentLocation; + GameLocation farm = hut.GetParentLocation(); // SearchHutGrid manages hut.lastKnownCropLocation and Util.Abilities.lastKnownCropLocations var foundWork = SearchHutGrid(hut, radius, farm, id); @@ -131,54 +131,65 @@ internal class ReplaceJunimoHutupdateWhenFarmNotCurrentLocation { // This is to prevent the update function from running, other than base.Update() // Capture sendOutTimer and use to stop execution - public static void Prefix(JunimoHut __instance, ref int ___junimoSendOutTimer, out int __state) { + public static bool Prefix(JunimoHut __instance, GameTime time, ref int ___junimoSendOutTimer, out int __state) { __state = ___junimoSendOutTimer; ___junimoSendOutTimer = 0; - } - public static void Postfix(JunimoHut __instance, GameTime time, ref int ___junimoSendOutTimer, int __state) - { - BetterJunimos.SMonitor.Log($"ReplaceJunimoHutupdateWhenFarmNotCurrentLocation: postfix starts v1"); - if (__state <= 0) return; - if (!Context.IsMainPlayer) return; - BetterJunimos.SMonitor.Log($"ReplaceJunimoHutupdateWhenFarmNotCurrentLocation: postfix starts"); + if (__state <= 0) return true; + if (!Context.IsMainPlayer) return true; + //BetterJunimos.SMonitor.Log($"ReplaceJunimoHutupdateWhenFarmNotCurrentLocation: postfix starts", LogLevel.Debug); ___junimoSendOutTimer = __state - time.ElapsedGameTime.Milliseconds; - __instance.shouldSendOutJunimos.Value = true; + //__instance.shouldSendOutJunimos.Value = true; // Don't work on farmEvent days // Base game work on event days // if (Game1.farmEvent != null) // return; // Winter - if (Game1.IsWinter && !Util.Progression.CanWorkInWinter) { - return; + if (__instance.GetParentLocation().IsWinterHere() && !Util.Progression.CanWorkInWinter) { + return true; } // Rain - if (Game1.isRaining && !Util.Progression.CanWorkInRain){ - BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: rain"); - return; + if (__instance.GetParentLocation().IsRainingHere() && !Util.Progression.CanWorkInRain){ + //BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: rain"); + return true; } // Currently sending out a junimo if (___junimoSendOutTimer > 0) { - BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} - ReplaceJunimoHutUpdate: sending"); - return; + //BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} - ReplaceJunimoHutUpdate: sending"); + return true; } // Already enough junimos if (__instance.myJunimos.Count >= Util.Progression.MaxJunimosUnlocked){ - BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} Already {__instance.myJunimos.Count} Junimos, limit is {Util.Progression.MaxJunimosUnlocked}"); - return; + //BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} Already {__instance.myJunimos.Count} Junimos, limit is {Util.Progression.MaxJunimosUnlocked}"); + return true; } // Nothing to do if (!__instance.areThereMatureCropsWithinRadius()) { - BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} No work for Junimos to do, not spawning another"); - return; + //BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} No work for Junimos to do, not spawning another", LogLevel.Debug); + return true; } - // BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: spawning"); + //BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} ReplaceJunimoHutUpdate: spawning"); Util.SpawnJunimoAtHut(__instance); // BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: postfix ends"); ___junimoSendOutTimer = 1000; + return true; } } + /* Update + * + * To allow more junimos, allow working + */ + [HarmonyPriority(Priority.VeryHigh)] + internal class ReplaceJunimoHutdayUpdate + { + public static void Postfix(JunimoHut __instance, int dayOfMonth) + { + //BetterJunimos.SMonitor.Log($"ReplaceJunimoHutdayUpdate: postfix starts", LogLevel.Debug); + __instance.shouldSendOutJunimos.Value = true; + } + } + /* Update * * To allow more junimos, allow working in rain @@ -201,15 +212,15 @@ public static void Postfix(JunimoHut __instance, GameTime time, ref int ___junim ___junimoSendOutTimer = __state - time.ElapsedGameTime.Milliseconds; // Don't work on farmEvent days - if (Game1.farmEvent != null) - return; + // if (Game1.farmEvent != null) + // return; // Winter - if (Game1.IsWinter && !Util.Progression.CanWorkInWinter) { + if (__instance.GetParentLocation().IsWinterHere() && !Util.Progression.CanWorkInWinter) { return; } // Rain - if (Game1.isRaining && !Util.Progression.CanWorkInRain){ - BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: rain"); + if (__instance.GetParentLocation().IsRainingHere() && !Util.Progression.CanWorkInRain){ + //BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: rain"); return; } // Currently sending out a junimo @@ -284,13 +295,13 @@ public static bool Prefix(int timeElapsed, JunimoHut __instance, ref int ___juni __instance.myJunimos[index].pokeToHarvest(); } - if (Game1.timeOfDay is >= 2000 and < 2400 && (!Game1.IsWinter && Game1.random.NextDouble() < 0.2)) + if (Game1.timeOfDay is >= 2000 and < 2400 && !__instance.GetParentLocation().IsWinterHere() && Game1.random.NextDouble() < 0.2) { __instance.wasLit.Value = true; } else { - if (Game1.timeOfDay != 2400 || Game1.IsWinter) + if (Game1.timeOfDay != 2400 || __instance.GetParentLocation().IsWinterHere()) return false; __instance.wasLit.Value = false; }