/// <summary>The method to call before <see cref="FarmAnimal.updateWhenCurrentLocation"/>.</summary> private static bool Before_UpdateWhenCurrentLocation(FarmAnimal __instance, GameTime time, GameLocation location, ref bool __result) { if (!Game1.shouldTimePass()) { return(false); } if (__instance.health.Value <= 0) { return(true); } Mod.Instance.Helper.Reflection.GetField <NetEvent0>(__instance, "doBuildingPokeEvent").GetValue().Poll(); if (__instance.hitGlowTimer > 0) { __instance.hitGlowTimer -= time.ElapsedGameTime.Milliseconds; } if (__instance.Sprite.CurrentAnimation != null) { if (__instance.Sprite.animateOnce(time)) { __instance.Sprite.CurrentAnimation = null; } return(false); } __instance.update(time, location, __instance.myID.Value, false); if (Game1.IsMasterGame && Mod.Instance.Helper.Reflection.GetMethod(__instance, "behaviors").Invoke <bool>(time, location) || __instance.Sprite.CurrentAnimation != null) { return(false); } if (__instance.controller != null && __instance.controller.timerSinceLastCheckPoint > 10000) { __instance.controller = null; __instance.Halt(); } if (location is BuildableGameLocation && location is IAnimalLocation animalLocation && __instance.noWarpTimer <= 0) { Building building = __instance.home; if (building != null && Game1.IsMasterGame && building.getRectForAnimalDoor().Contains(__instance.GetBoundingBox().Center.X, __instance.GetBoundingBox().Top)) { if (Utility.isOnScreen(__instance.getTileLocationPoint(), 192, location)) { location.localSound("dwoop"); } animalLocation.Animals.Remove(__instance.myID.Value); (building.indoors.Value as AnimalHouse).animals[__instance.myID.Value] = __instance; __instance.setRandomPosition(building.indoors.Value); __instance.faceDirection(Game1.random.Next(4)); __instance.controller = null; return(true); } } __instance.noWarpTimer = Math.Max(0, __instance.noWarpTimer - time.ElapsedGameTime.Milliseconds); if (__instance.pauseTimer > 0) { __instance.pauseTimer -= time.ElapsedGameTime.Milliseconds; } if (Game1.timeOfDay >= 2000) { __instance.Sprite.currentFrame = __instance.buildingTypeILiveIn.Contains("Coop") ? 16 : 12; __instance.Sprite.UpdateSourceRect(); __instance.FacingDirection = 2; if (!__instance.isEmoting && Game1.random.NextDouble() < 0.002) { __instance.doEmote(24); } } else if (__instance.pauseTimer <= 0) { if (Game1.random.NextDouble() < 0.001 && __instance.age.Value >= __instance.ageWhenMature.Value && (Game1.gameMode == 3 && __instance.sound.Value != null) && Utility.isOnScreen(__instance.Position, 192)) { __instance.makeSound(); } if (!Game1.IsClient && Game1.random.NextDouble() < 0.007 && __instance.uniqueFrameAccumulator == -1) { int direction = Game1.random.Next(5); if (direction != (__instance.FacingDirection + 2) % 4) { if (direction < 4) { int facingDirection = __instance.FacingDirection; __instance.faceDirection(direction); if (!location.IsOutdoors && location.isCollidingPosition(__instance.nextPosition(direction), Game1.viewport, __instance)) { __instance.faceDirection(facingDirection); return(false); } } switch (direction) { case 0: __instance.SetMovingUp(true); break; case 1: __instance.SetMovingRight(true); break; case 2: __instance.SetMovingDown(true); break; case 3: __instance.SetMovingLeft(true); break; default: __instance.Halt(); __instance.Sprite.StopAnimation(); break; } } else if (__instance.noWarpTimer <= 0) { __instance.Halt(); __instance.Sprite.StopAnimation(); } } if (!Game1.IsClient && __instance.isMoving() && (Game1.random.NextDouble() < 0.014 && __instance.uniqueFrameAccumulator == -1)) { __instance.Halt(); __instance.Sprite.StopAnimation(); if (Game1.random.NextDouble() < 0.75) { __instance.uniqueFrameAccumulator = 0; if (__instance.buildingTypeILiveIn.Contains("Coop")) { switch (__instance.FacingDirection) { case 0: __instance.Sprite.currentFrame = 20; break; case 1: __instance.Sprite.currentFrame = 18; break; case 2: __instance.Sprite.currentFrame = 16; break; case 3: __instance.Sprite.currentFrame = 22; break; } } else if (__instance.buildingTypeILiveIn.Contains("Barn")) { switch (__instance.FacingDirection) { case 0: __instance.Sprite.currentFrame = 15; break; case 1: __instance.Sprite.currentFrame = 14; break; case 2: __instance.Sprite.currentFrame = 13; break; case 3: __instance.Sprite.currentFrame = 14; break; } } } __instance.Sprite.UpdateSourceRect(); } if (__instance.uniqueFrameAccumulator != -1 && !Game1.IsClient) { __instance.uniqueFrameAccumulator += time.ElapsedGameTime.Milliseconds; if (__instance.uniqueFrameAccumulator > 500) { if (__instance.buildingTypeILiveIn.Contains("Coop")) { __instance.Sprite.currentFrame = __instance.Sprite.currentFrame + 1 - __instance.Sprite.currentFrame % 2 * 2; } else if (__instance.Sprite.currentFrame > 12) { __instance.Sprite.currentFrame = (__instance.Sprite.currentFrame - 13) * 4; } else { switch (__instance.FacingDirection) { case 0: __instance.Sprite.currentFrame = 15; break; case 1: __instance.Sprite.currentFrame = 14; break; case 2: __instance.Sprite.currentFrame = 13; break; case 3: __instance.Sprite.currentFrame = 14; break; } } __instance.uniqueFrameAccumulator = 0; if (Game1.random.NextDouble() < 0.4) { __instance.uniqueFrameAccumulator = -1; } } } else if (!Game1.IsClient) { __instance.MovePosition(time, Game1.viewport, location); } } return(false); }