From e2d608eeefca7f7d38a27a3385a379ec24a6a4f7 Mon Sep 17 00:00:00 2001 From: hawkfalcon Date: Sun, 26 Aug 2018 23:47:41 -0700 Subject: [PATCH] Work in Winter and Evenings, fix nre --- BetterJunimos/ModConfig.cs | 2 ++ BetterJunimos/Patches/JunimoHarvesterPatches.cs | 2 +- BetterJunimos/Patches/JunimoHutPatches.cs | 7 +++++-- BetterJunimos/Utils/JunimoAbilities.cs | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/BetterJunimos/ModConfig.cs b/BetterJunimos/ModConfig.cs index 86d6e8b..f2d242f 100644 --- a/BetterJunimos/ModConfig.cs +++ b/BetterJunimos/ModConfig.cs @@ -24,6 +24,8 @@ internal class HutSettings { public JunimoImprovement JunimoImprovements { get; set; } = new JunimoImprovement(); internal class JunimoImprovement { public bool CanWorkInRain { get; set; } = true; + public bool CanWorkInWinter { get; set; } = false; + public bool CanWorkInEvenings { get; set; } = false; public bool WorkFaster { get; set; } = false; public bool AvoidHarvestingFlowers { get; set; } = true; } diff --git a/BetterJunimos/Patches/JunimoHarvesterPatches.cs b/BetterJunimos/Patches/JunimoHarvesterPatches.cs index 769359a..18398ff 100644 --- a/BetterJunimos/Patches/JunimoHarvesterPatches.cs +++ b/BetterJunimos/Patches/JunimoHarvesterPatches.cs @@ -109,7 +109,7 @@ public class PatchPathfindDoWork { public static bool Prefix(JunimoHarvester __instance) { JunimoHut hut = Util.GetHutFromId(Util.GetHutIdFromJunimo(__instance)); - if (Game1.timeOfDay > 1900) { + if (Game1.timeOfDay > 1900 && !Util.Config.JunimoImprovements.CanWorkInEvenings) { if (__instance.controller != null) return false; __instance.returnToJunimoHut(__instance.currentLocation); diff --git a/BetterJunimos/Patches/JunimoHutPatches.cs b/BetterJunimos/Patches/JunimoHutPatches.cs index 8e31080..355fe54 100644 --- a/BetterJunimos/Patches/JunimoHutPatches.cs +++ b/BetterJunimos/Patches/JunimoHutPatches.cs @@ -65,7 +65,10 @@ public static void Postfix(JunimoHut __instance, GameTime time, int __state) { // from Update junimoSendOutTimer.SetValue(sendOutTimer - time.ElapsedGameTime.Milliseconds); if (sendOutTimer > 0 || __instance.myJunimos.Count() >= Util.Config.JunimoHuts.MaxJunimos || - Game1.IsWinter || !__instance.areThereMatureCropsWithinRadius() || Game1.farmEvent != null) + !__instance.areThereMatureCropsWithinRadius() || Game1.farmEvent != null) + return; + // Winter + if (Game1.IsWinter && !Util.Config.JunimoImprovements.CanWorkInWinter) return; // Rain if (Game1.isRaining && !Util.Config.JunimoImprovements.CanWorkInRain) @@ -85,7 +88,7 @@ public static void Postfix(JunimoHut __instance, GameTime time, int __state) { internal class ReplaceJunimoHutNumber { public static bool Prefix(JunimoHut __instance, ref int __result) { for (int index = 0; index < Util.Config.JunimoHuts.MaxJunimos; ++index) { - if (index >= __instance.myJunimos.Count()) { + if (index >= __instance.myJunimos.Count()) { __result = index; return false; } diff --git a/BetterJunimos/Utils/JunimoAbilities.cs b/BetterJunimos/Utils/JunimoAbilities.cs index baf7f11..95b42d5 100644 --- a/BetterJunimos/Utils/JunimoAbilities.cs +++ b/BetterJunimos/Utils/JunimoAbilities.cs @@ -169,6 +169,7 @@ private bool UseItemAbility(Guid id, Vector2 pos, int itemCategory, Func chest = hut.output.Value.items; Item foundItem = chest.FirstOrDefault(item => item.Category == itemCategory); + if (foundItem == null) return false; bool success = useItem(pos, foundItem.ParentSheetIndex); if (success) { Util.ReduceItemCount(chest, foundItem);