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 override void updateWhenNotCurrentLocation(Building currentBuilding, GameTime time, GameLocation environment) { NetEvent1Field <int, NetInt> makeThoseMoves = (NetEvent1Field <int, NetInt>)Memory.instance.Helper.Reflection.GetField <NetEvent1Field <int, NetInt> >(this, "doFarmerPushEvent"); makeThoseMoves.Poll(); //this.doFarmerPushEvent.Poll(); if (!Game1.shouldTimePass()) { return; } update(time, environment, myID, false); if (!Game1.IsMasterGame) { return; } if (currentBuilding != null && Game1.random.NextDouble() < 0.002 && currentBuilding.animalDoorOpen && Game1.timeOfDay < 1630 && !Game1.isRaining && !Game1.currentSeason.Equals("winter") && environment.getFarmersCount() == 0) { Farm farm = (Farm)Game1.getLocationFromName("Farm"); if (farm.isCollidingPosition(new XNARectangle((currentBuilding.tileX + currentBuilding.animalDoor.X) * 64 + 2, (currentBuilding.tileY + currentBuilding.animalDoor.Y) * 64 + 2, (this.isCoopDweller() ? 64 : 128) - 4, 60), Game1.viewport, false, 0, false, this, false, false, false) || farm.isCollidingPosition(new XNARectangle((currentBuilding.tileX + currentBuilding.animalDoor.X) * 64 + 2, (currentBuilding.tileY + currentBuilding.animalDoor.Y + 1) * 64 + 2, (this.isCoopDweller() ? 64 : 128) - 4, 60), Game1.viewport, false, 0, false, this, false, false, false)) { return; } if (farm.animals.ContainsKey(this.myID)) { for (int i = farm.animals.Count() - 1; i >= 0; i--) { if (farm.animals.Pairs.ElementAt(i).Key.Equals(this.myID)) { farm.animals.Remove(this.myID); break; } } } (currentBuilding.indoors.Value as AnimalHouse).animals.Remove(this.myID); farm.animals.Add(this.myID, this); this.faceDirection(2); this.SetMovingDown(true); base.Position = new Vector2((float)currentBuilding.getRectForAnimalDoor().X, (float)((currentBuilding.tileY + currentBuilding.animalDoor.Y) * 64 - (this.Sprite.getHeight() * 4 - this.GetBoundingBox().Height) + 32)); this.controller = new PathFindController(this, farm, new PathFindController.isAtEnd(FarmAnimal.grassEndPointFunction), Game1.random.Next(4), false, new PathFindController.endBehavior(FarmAnimal.behaviorAfterFindingGrassPatch), 200, Point.Zero); if (this.controller == null || this.controller.pathToEndPoint == null || this.controller.pathToEndPoint.Count < 3) { this.SetMovingDown(true); this.controller = null; } else { this.faceDirection(2); base.Position = new Vector2((float)(this.controller.pathToEndPoint.Peek().X * 64), (float)(this.controller.pathToEndPoint.Peek().Y * 64 - (this.Sprite.getHeight() * 4 - this.GetBoundingBox().Height) + 16)); if (!this.isCoopDweller()) { this.position.X -= 32f; } } this.noWarpTimer = 3000; NetInt currentOccupants = currentBuilding.currentOccupants; int value = currentOccupants.Value; currentOccupants.Value = value - 1; if (Utility.isOnScreen(base.getTileLocationPoint(), 192, farm)) { farm.localSound("sandyStep"); } if (environment.isTileOccupiedByFarmer(base.getTileLocation()) != null) { environment.isTileOccupiedByFarmer(base.getTileLocation()).temporaryImpassableTile = this.GetBoundingBox(); } } Memory.instance.Helper.Reflection.GetMethod(this, "behaviors").Invoke(time, environment); //this.behaviors(time, environment); //base.updateWhenNotCurrentLocation(currentBuilding, time, environment); }
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); }