public static void Postfix(JunimoHarvester __instance, ref NetGuid ___netHome) { var hut = Util.GetHutFromId(___netHome.Value); var radius = Util.CurrentWorkingRadius; var retry = 0; do { var endPoint = __instance.currentLocation.IsGreenhouse ? EndPointInGreenhouse(__instance) : EndPointInFarm(hut, radius); // BetterJunimos.SMonitor.Log($"PatchPathfindToRandomSpotAroundHut: " + // $"#{__instance.whichJunimoFromThisHut} " + // $"in {__instance.currentLocation.Name} " + // $"from [{__instance.getTileX()} {__instance.getTileX()}] " + // $"to [{endPoint.X} {endPoint.Y}]", // LogLevel.Debug); // BetterJunimos.SMonitor.Log( // $"PatchPathfindToRandomSpotAroundHut: #{__instance.whichJunimoFromThisHut} current location is {__instance.currentLocation.Name}", // LogLevel.Trace); // BetterJunimos.SMonitor.Log( // $"PatchPathfindToRandomSpotAroundHut: #{__instance.whichJunimoFromThisHut} want to path to [{endPoint.X} {endPoint.Y}]", // LogLevel.Trace); __instance.controller = new PathFindController( __instance, __instance.currentLocation, endPoint, -1, __instance.reachFirstDestinationFromHut, 100); retry++; } while (retry <= 5 && __instance.controller?.pathToEndPoint == null); if (__instance.controller == null) { // BetterJunimos.SMonitor.Log( // $"PatchPathfindToRandomSpotAroundHut: #{__instance.whichJunimoFromThisHut} controller is null, will be despawned", // LogLevel.Trace); } else if (__instance.controller?.pathToEndPoint == null) { // BetterJunimos.SMonitor.Log( // $"PatchPathfindToRandomSpotAroundHut: #{__instance.whichJunimoFromThisHut} controller.pathToEndPoint is null, will be despawned", // LogLevel.Trace); } else { // BetterJunimos.SMonitor.Log( // $"PatchPathfindToRandomSpotAroundHut: #{__instance.whichJunimoFromThisHut} has a path", // LogLevel.Trace); } }
public static void Postfix(JunimoHarvester __instance, ref NetGuid ___netHome) { JunimoHut hut = Util.GetHutFromId(___netHome.Value); int radius = Util.MaxRadius; int retry = 0; do { __instance.controller = new PathFindController(__instance, __instance.currentLocation, Utility.Vector2ToPoint( new Vector2((float)(hut.tileX.Value + 1 + Game1.random.Next(-radius, radius + 1)), (float)(hut.tileY.Value + 1 + Game1.random.Next(-radius, radius + 1)))), -1, new PathFindController.endBehavior(__instance.reachFirstDestinationFromHut), 100); retry++; } while (retry <= 5 && (__instance.controller == null || __instance.controller.pathToEndPoint == null)); }
public static bool Prefix(JunimoHarvester __instance, ref int ___harvestTimer, ref NetGuid ___netHome) { if (!Context.IsMainPlayer) { return(true); } var id = ___netHome.Value; var pos = __instance.getTileLocation(); // if (__instance.currentLocation.IsGreenhouse) { // BetterJunimos.SMonitor.Log($"PatchTryToHarvestHere: #{__instance.whichJunimoFromThisHut} looking in {__instance.currentLocation.Name} at [{pos.X} {pos.Y}]", LogLevel.Trace); // } int time; var junimoAbility = Util.Abilities.IdentifyJunimoAbility(__instance.currentLocation, pos, id); if (junimoAbility != null) { // if (__instance.currentLocation.IsGreenhouse) { // BetterJunimos.SMonitor.Log( // $"PatchTryToHarvestHere: #{__instance.whichJunimoFromThisHut} performing {junimoAbility.AbilityName()} at {__instance.currentLocation.Name} [{pos.X} {pos.Y}]", // LogLevel.Trace); // } if (junimoAbility is HarvestBushesAbility) { // Use the update() harvesting time = 2000; } else if (!Util.Abilities.PerformAction(junimoAbility, id, __instance.currentLocation, pos, __instance)) { // didn't succeed, move on time = 0; // add failed action to ability cooldowns Util.Abilities.ActionFailed(__instance.currentLocation, junimoAbility, pos); } else { // succeeded, shake if (junimoAbility is HarvestCropsAbility) { time = 2000; } else if (BetterJunimos.Config.JunimoImprovements.WorkRidiculouslyFast) { time = 20; } else { time = Util.Progression.WorkFaster ? 300 : 998; } // BetterJunimos.SMonitor.Log($"PatchTryToHarvestHere performing {junimoAbility.AbilityName()} time {time}]", LogLevel.Trace); } } else { // nothing to do, wait a moment time = Util.Progression.WorkFaster ? 5 : 200; __instance.pokeToHarvest(); } ___harvestTimer = time; return(false); }
public static bool Prefix(JunimoHarvester __instance, ref NetGuid ___netHome, ref NetEvent1Field <int, NetInt> ___netAnimationEvent) { if (!Context.IsMainPlayer) { return(true); } var hut = Util.GetHutFromId(___netHome.Value); var quittingTime = Util.Progression.CanWorkInEvenings ? 2400 : 1900; // BetterJunimos.SMonitor.Log($"PatchPathfindDoWork: Junimo {__instance.whichJunimoFromThisHut} in {__instance.currentLocation.Name} looking for work", LogLevel.Debug); if (Game1.timeOfDay > quittingTime) { // bedtime, all Junimos return to huts and/or despawn Util.Progression.PromptForCanWorkInEvenings(); if (__instance.controller != null) { return(false); } if (__instance.currentLocation is Farm) { __instance.returnToJunimoHut(__instance.currentLocation); } else { // can't walk back to the hut from here, just despawn __instance.junimoReachedHut(__instance, __instance.currentLocation); // BetterJunimos.SMonitor.Log($"PatchPathfindDoWork: despawning due end of day", LogLevel.Trace); } } // Prevent working when not paid else if (BetterJunimos.Config.JunimoPayment.WorkForWages && !Util.Payments.WereJunimosPaidToday) { if (Game1.random.NextDouble() < 0.02 && __instance.currentLocation.IsFarm) { __instance.pathfindToRandomSpotAroundHut(); } else { // go on strike ___netAnimationEvent.Fire(7); } } else if (hut.noHarvest.Value || (Game1.random.NextDouble() < 0.035 && !BetterJunimos.Config.JunimoImprovements.WorkRidiculouslyFast)) { // Hut has nothing to harvest // TODO: fix for greenhouse // BetterJunimos.SMonitor.Log($"PatchPathfindDoWork: {__instance.whichJunimoFromThisHut} hut noHarvest {hut.noHarvest.Value}", LogLevel.Debug); __instance.pathfindToRandomSpotAroundHut(); } else { // walk to work? __instance.controller = new PathFindController( __instance, __instance.currentLocation, __instance.foundCropEndFunction, -1, false, __instance.reachFirstDestinationFromHut, 100, Point.Zero); var radius = Util.CurrentWorkingRadius; var outsideRadius = __instance.controller.pathToEndPoint is not null && hut.tileX is not null && hut.tileY is not null && __instance.currentLocation is not null && __instance.currentLocation.IsFarm && ( Math.Abs(__instance.controller.pathToEndPoint.Last().X - hut.tileX.Value - 1) > radius || Math.Abs(__instance.controller.pathToEndPoint.Last().Y - hut.tileY.Value - 1) > radius ); if (__instance.controller.pathToEndPoint != null && !outsideRadius) { // Junimo has somewhere to be, let it happen // BetterJunimos.SMonitor.Log($"PatchPathfindDoWork: {__instance.whichJunimoFromThisHut} has more work", LogLevel.Debug); ___netAnimationEvent.Fire(0); } else { // Junimo has no path, or path endpoint is outside the hut radius Util.Abilities.lastKnownCropLocations.TryGetValue((hut, __instance.currentLocation), out var lkc); // BetterJunimos.SMonitor.Log($"PatchPathfindDoWork: {__instance.whichJunimoFromThisHut} needs work", LogLevel.Debug); // BetterJunimos.SMonitor.Log($"PatchPathfindDoWork: #{__instance.whichJunimoFromThisHut} " + // $"has no path, trying to find more work to do, " + // $"lkc: {__instance.currentLocation.Name} [{lkc.X} {lkc.Y}]", // LogLevel.Trace); if (Game1.random.NextDouble() < 0.5 && !lkc.Equals(Point.Zero)) { // hut has some work to do, send Junimo there __instance.controller = new PathFindController( __instance, __instance.currentLocation, lkc, -1, __instance.reachFirstDestinationFromHut, 100); if (__instance.controller.pathToEndPoint is null) { // BetterJunimos.SMonitor.Log($"PatchPathfindDoWork: {__instance.whichJunimoFromThisHut} can't get to work at {lkc}", LogLevel.Debug); // BetterJunimos.SMonitor.Log($"PatchPathfindDoWork: #{__instance.whichJunimoFromThisHut} " + // $"attempted to path " + // $"from {__instance.getTileX()} {__instance.getTileY()} " + // $"to {__instance.currentLocation} {lkc.X} {lkc.Y}, " + // $"no path to endpoint", // LogLevel.Trace); } } else if (Game1.random.NextDouble() < 0.25) { // BetterJunimos.SMonitor.Log($"PatchPathfindDoWork: {__instance.whichJunimoFromThisHut} being sent home", LogLevel.Debug); // unlucky, send Junimo home ___netAnimationEvent.Fire(0); if (__instance.currentLocation is Farm) { __instance.returnToJunimoHut(__instance.currentLocation); } else if (__instance.currentLocation.IsGreenhouse) { returnToGreenhouseDoor(__instance, __instance.currentLocation); } else { // can't walk back to the hut from here, just despawn __instance.junimoReachedHut(__instance, __instance.currentLocation); } } else { // move Junimo randomly // BetterJunimos.SMonitor.Log($"PatchPathfindDoWork: {__instance.whichJunimoFromThisHut} going for a walk", LogLevel.Debug); __instance.pathfindToRandomSpotAroundHut(); } } } return(false); }
public static bool Prefix(JunimoHarvester __instance, ref PathNode currentNode, ref NetGuid ___netHome, ref bool __result) { __result = Util.Abilities.IsActionable(__instance.currentLocation, new Vector2(currentNode.x, currentNode.y), ___netHome.Value); return(false); }
public static bool Prefix(JunimoHarvester __instance, ref int ___harvestTimer, ref NetGuid ___netHome) { Guid id = ___netHome.Value; Vector2 pos = __instance.getTileLocation(); int time; IJunimoAbility junimoAbility = Util.Abilities.IdentifyJunimoAbility(pos, id); if (junimoAbility != null) { // Use the update() harvesting if (junimoAbility is HarvestCropsAbility || junimoAbility is HarvestBushesAbility) { time = 2000; } else if (!Util.Abilities.PerformAction(junimoAbility, id, pos, __instance)) { // didn't succeed, move on time = 0; } else { // succeeded, shake time = Util.Progression.WorkFaster ? 300 : 998; } } else { // nothing to do, wait a moment time = Util.Progression.WorkFaster ? 5 : 200; __instance.pokeToHarvest(); } ___harvestTimer = time; return(false); }
public static bool Prefix(JunimoHarvester __instance, ref NetGuid ___netHome, ref NetEvent1Field <int, NetInt> ___netAnimationEvent) { JunimoHut hut = Util.GetHutFromId(___netHome.Value); int time = Util.Progression.CanWorkInEvenings ? 2400 : 1900; if (Game1.timeOfDay > time) { Util.Progression.PromptForCanWorkInEvenings(); if (__instance.controller != null) { return(false); } __instance.returnToJunimoHut(__instance.currentLocation); } // Prevent working when not paid else if (Util.Config.JunimoPayment.WorkForWages && !Util.Payments.WereJunimosPaidToday) { if (Game1.random.NextDouble() < 0.02) { __instance.pathfindToRandomSpotAroundHut(); } else { // go on strike ___netAnimationEvent.Fire(7); } } else if (Game1.random.NextDouble() < 0.035 || hut.noHarvest.Value) { __instance.pathfindToRandomSpotAroundHut(); } else { __instance.controller = new PathFindController(__instance, __instance.currentLocation, new PathFindController.isAtEnd(__instance.foundCropEndFunction), -1, false, new PathFindController.endBehavior(__instance.reachFirstDestinationFromHut), 100, Point.Zero); int radius = Util.MaxRadius; if (__instance.controller.pathToEndPoint == null || Math.Abs(__instance.controller.pathToEndPoint.Last().X - hut.tileX.Value - 1) > radius || Math.Abs(__instance.controller.pathToEndPoint.Last().Y - hut.tileY.Value - 1) > radius) { if (Game1.random.NextDouble() < 0.5 && !hut.lastKnownCropLocation.Equals(Point.Zero)) { __instance.controller = new PathFindController(__instance, __instance.currentLocation, hut.lastKnownCropLocation, -1, new PathFindController.endBehavior(__instance.reachFirstDestinationFromHut), 100); } else if (Game1.random.NextDouble() < 0.25) { ___netAnimationEvent.Fire(0); __instance.returnToJunimoHut(__instance.currentLocation); } else { __instance.pathfindToRandomSpotAroundHut(); } } else { ___netAnimationEvent.Fire(0); } } return(false); }
public static Guid GetHutIdFromJunimo(JunimoHarvester junimo) { NetGuid netHome = Reflection.GetField <NetGuid>(junimo, "netHome").GetValue(); return(netHome.Value); }