Skip to content

Commit

Permalink
Merge pull request #61 from Miguel-Thewolf/junimo_always_on
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkfalcon authored Jun 6, 2024
2 parents d58d9b3 + bd1a8ad commit b15d311
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 11 deletions.
5 changes: 4 additions & 1 deletion BetterJunimos/BetterJunimos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ 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));
replacements.Add("performTenMinuteAction", junimoHutType, typeof(ReplaceJunimoTimerNumber));

Expand Down Expand Up @@ -254,7 +256,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
Expand Down
5 changes: 4 additions & 1 deletion BetterJunimos/Patches/JunimoHarvesterPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
86 changes: 77 additions & 9 deletions BetterJunimos/Patches/JunimoHutPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -122,6 +122,74 @@ 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 bool Prefix(JunimoHut __instance, GameTime time, ref int ___junimoSendOutTimer, out int __state) {
__state = ___junimoSendOutTimer;
___junimoSendOutTimer = 0;
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;
// Don't work on farmEvent days
// Base game work on event days
// if (Game1.farmEvent != null)
// return;
// Winter
if (__instance.GetParentLocation().IsWinterHere() && !Util.Progression.CanWorkInWinter) {
return true;
}
// Rain
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 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 true;
}
// Nothing to do
if (!__instance.areThereMatureCropsWithinRadius()) {
//BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} No work for Junimos to do, not spawning another", LogLevel.Debug);
return true;
}
//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
Expand All @@ -142,17 +210,17 @@ 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;
// 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
Expand Down Expand Up @@ -227,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;
}
Expand Down

0 comments on commit b15d311

Please sign in to comment.