Exemple #1
0
        /// <summary>The method to call before <see cref="FarmAnimal.behaviors"/>.</summary>
        public static bool Before_Behaviors(FarmAnimal __instance, GameTime time, GameLocation location, ref bool __result)
        {
            if (__instance.home == null)
            {
                __result = false;
                return(false);
            }
            if (__instance.isEating.Value)
            {
                if (__instance.home != null && __instance.home.getRectForAnimalDoor().Intersects(__instance.GetBoundingBox()))
                {
                    FarmAnimal.behaviorAfterFindingGrassPatch(__instance, location);
                    __instance.isEating.Value = false;
                    __instance.Halt();
                    __result = false;
                    return(false);
                }
                if (__instance.buildingTypeILiveIn.Contains("Barn"))
                {
                    __instance.Sprite.Animate(time, 16, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 20)
                    {
                        __instance.isEating.Value      = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }
                else
                {
                    __instance.Sprite.Animate(time, 24, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 28)
                    {
                        __instance.isEating.Value      = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }
                __result = true;
                return(false);
            }
            if (!Game1.IsClient)
            {
                if (__instance.controller != null)
                {
                    __result = true;
                    return(false);
                }
                if (location.IsOutdoors && __instance.fullness.Value < 195 && (Game1.random.NextDouble() < 0.002 && FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick))
                {
                    ++FarmAnimal.NumPathfindingThisTick;
                    __instance.controller = new PathFindController(__instance, location, FarmAnimal.grassEndPointFunction, -1, false, FarmAnimal.behaviorAfterFindingGrassPatch, 200, Point.Zero);
                }
                if (Game1.timeOfDay >= 1700 && location.IsOutdoors && (__instance.controller == null && Game1.random.NextDouble() < 0.002))
                {
                    if (location.farmers.Count == 0)
                    {
                        (location as Farm).animals.Remove(__instance.myID.Value);
                        (__instance.home.indoors.Value as AnimalHouse).animals.Add(__instance.myID.Value, __instance);
                        __instance.setRandomPosition(__instance.home.indoors.Value);
                        __instance.faceDirection(Game1.random.Next(4));
                        __instance.controller = null;
                        __result = true;
                        return(false);
                    }
                    if (FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick)
                    {
                        ++FarmAnimal.NumPathfindingThisTick;
                        __instance.controller = new PathFindController(__instance, location, PathFindController.isAtEndPoint, 0, false, null, 200, new Point(__instance.home.tileX.Value + __instance.home.animalDoor.X, __instance.home.tileY.Value + __instance.home.animalDoor.Y));
                    }
                }
                if (location.IsOutdoors && !Game1.isRaining && (!Game1.currentSeason.Equals("winter") && __instance.currentProduce.Value != -1) && (__instance.age.Value >= __instance.ageWhenMature.Value && __instance.type.Value.Contains("Pig") && Game1.random.NextDouble() < 0.0002))
                {
                    Rectangle boundingBox = __instance.GetBoundingBox();
                    for (int corner = 0; corner < 4; ++corner)
                    {
                        Vector2 cornersOfThisRectangle = Utility.getCornersOfThisRectangle(ref boundingBox, corner);
                        Vector2 key = new Vector2((int)(cornersOfThisRectangle.X / 64.0), (int)(cornersOfThisRectangle.Y / 64.0));
                        if (location.terrainFeatures.ContainsKey(key) || location.objects.ContainsKey(key))
                        {
                            __result = false;
                            return(false);
                        }
                    }
                    if (Game1.player.currentLocation.Equals(location))
                    {
                        DelayedAction.playSoundAfterDelay("dirtyHit", 450);
                        DelayedAction.playSoundAfterDelay("dirtyHit", 900);
                        DelayedAction.playSoundAfterDelay("dirtyHit", 1350);
                    }
                    if (location.Equals(Game1.currentLocation))
                    {
                        var findTruffleDelegate = (AnimatedSprite.endOfAnimationBehavior)Delegate.CreateDelegate(typeof(AnimatedSprite.endOfAnimationBehavior), Mod.Instance.Helper.Reflection.GetMethod(__instance, "findTruffle").MethodInfo);

                        switch (__instance.FacingDirection)
                        {
                        case 0:
                            __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                            {
                                new(9, 250),
                                new(11, 250),
                                new(9, 250),
                                new(11, 250),
                                new(9, 250),
                                new(11, 250, false, false, findTruffleDelegate)
                            });
                            break;
Exemple #2
0
        /// <summary>The prefix for the Behaviors method.</summary>
        /// <param name="time">The GameTime object that contains time data about the game's frame time.</param>
        /// <param name="location">The current location of the <see cref="FarmAnimal"/> being patched.</param>
        /// <param name="__result">The return value of the original Bahaviors method.</param>
        /// <param name="__instance">The current <see cref="FarmAnimal"/> instance being patched.</param>
        /// <returns>False meaning the original method won't get ran.</returns>
        public static bool BehaviorsPrefix(GameTime time, GameLocation location, ref bool __result, FarmAnimal __instance)
        {
            // ensure animal has a house
            if (__instance.home == null)
            {
                __result = false;
                return(false);
            }

            // get isEating memeber
            var isEating = (NetBool)typeof(FarmAnimal).GetField("isEating", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);

            if (isEating)
            {
                if (__instance.home != null && __instance.home.getRectForAnimalDoor().Intersects(__instance.GetBoundingBox()))
                {
                    FarmAnimal.behaviorAfterFindingGrassPatch(__instance, location);
                    isEating.Value = false;
                    __instance.Halt();
                    __result = false;
                    return(false);
                }

                // sort out animation
                if (__instance.buildingTypeILiveIn.Contains("Barn"))
                {
                    __instance.Sprite.Animate(time, 16, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 20)
                    {
                        isEating.Value                 = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }
                else
                {
                    __instance.Sprite.Animate(time, 24, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 28)
                    {
                        isEating.Value                 = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }

                // set isEating member
                typeof(FarmAnimal).GetField("isEating", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, isEating);

                __result = true;
                return(false);
            }

            // only let the main behavior code be ran by the host
            if (Game1.IsClient)
            {
                __result = false;
                return(false);
            }

            // ensure animal isn't currently on a path
            if (__instance.controller != null)
            {
                __result = true;
                return(false);
            }

            // make animal go to grass if it's hungry
            if (location.IsOutdoors && __instance.fullness < 195 && (Game1.random.NextDouble() < 0.002 && FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick))
            {
                FarmAnimal.NumPathfindingThisTick++;
                __instance.controller = new PathFindController(__instance, location, new PathFindController.isAtEnd(FarmAnimal.grassEndPointFunction), -1, false, new PathFindController.endBehavior(FarmAnimal.behaviorAfterFindingGrassPatch), 200, Point.Zero, true);
            }

            // teleport the animals inside at night
            if (Game1.timeOfDay >= 1700 && location.IsOutdoors && (__instance.controller == null && Game1.random.NextDouble() < 0.002))
            {
                if (location.farmers.Count == 0)
                {
                    (location as Farm).animals.Remove(__instance.myID);
                    (__instance.home.indoors.Value as AnimalHouse).animals.Add(__instance.myID, __instance);
                    __instance.setRandomPosition(__instance.home.indoors);
                    __instance.faceDirection(Game1.random.Next(4));
                    __instance.controller = null;

                    __result = true;
                    return(false);
                }

                if (FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick)
                {
                    ++FarmAnimal.NumPathfindingThisTick;
                    __instance.controller = new PathFindController(__instance, location, new PathFindController.isAtEnd(PathFindController.isAtEndPoint), 0, false, null, 200, new Point(__instance.home.tileX + __instance.home.animalDoor.X, __instance.home.tileY + __instance.home.animalDoor.Y), true);
                }
            }

            // check if animal can forage for produce
            if (location.IsOutdoors && !Game1.isRaining && __instance.currentProduce != -1 && !__instance.isBaby() && Game1.random.NextDouble() < 0.0002)
            {
                // check if animal has produce that can be foraged
                var subType = ModEntry.Instance.Api.GetAnimalSubTypeByName(__instance.type);
                if (subType != null)
                {
                    // get the forage items count
                    var productCount = subType.Produce?.AllSeasons?.Products.Where(product => product.HarvestType == HarvestType.Forage).Select(product => product.Id).Count() ?? 0;
                    switch (Game1.currentSeason)
                    {
                    case "spring":
                    {
                        productCount += subType.Produce?.Spring?.Products.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        productCount += subType.Produce?.Spring?.DeluxeProducts.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        break;
                    }

                    case "summer":
                    {
                        productCount = subType.Produce?.Spring?.Products.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        productCount = subType.Produce?.Spring?.DeluxeProducts.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        break;
                    }

                    case "fall":
                    {
                        productCount = subType.Produce?.Spring?.Products.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        productCount = subType.Produce?.Spring?.DeluxeProducts.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        break;
                    }

                    case "winter":
                    {
                        productCount = subType.Produce?.Spring?.Products.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        productCount = subType.Produce?.Spring?.DeluxeProducts.Where(produce => produce.HarvestType == HarvestType.Forage).Select(produce => produce.Id).Count() ?? 0;
                        break;
                    }
                    }

                    // ensure there is a valid product for the animal
                    if (productCount == 0)
                    {
                        __result = false;
                        return(false);
                    }
                }

                // amke sure the place is blank for spawning the foraged item
                var boundingBox = __instance.GetBoundingBox();
                for (int corner = 0; corner < 4; ++corner)
                {
                    var cornersOfThisRectangle = Utility.getCornersOfThisRectangle(ref boundingBox, corner);
                    var position = new Vector2(cornersOfThisRectangle.X / 64f, cornersOfThisRectangle.Y / 64f);
                    if (location.terrainFeatures.ContainsKey(position) || location.objects.ContainsKey(position))
                    {
                        __result = false;
                        return(false);
                    }
                }

                // play forage sounds
                if (Game1.player.currentLocation.Equals(location))
                {
                    DelayedAction.playSoundAfterDelay("dirtyHit", 450, null, -1);
                    DelayedAction.playSoundAfterDelay("dirtyHit", 900, null, -1);
                    DelayedAction.playSoundAfterDelay("dirtyHit", 1350, null, -1);
                }

                // animate the animal is the player is there
                var findTruffle = typeof(FarmAnimal).GetMethod("findTruffle", BindingFlags.NonPublic | BindingFlags.Instance);
                if (location.Equals(Game1.currentLocation))
                {
                    switch (__instance.FacingDirection)
                    {
                    case 0:
                        __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(9, 250),
                            new FarmerSprite.AnimationFrame(11, 250),
                            new FarmerSprite.AnimationFrame(9, 250),
                            new FarmerSprite.AnimationFrame(11, 250),
                            new FarmerSprite.AnimationFrame(9, 250),
                            new FarmerSprite.AnimationFrame(11, 250, false, false, new AnimatedSprite.endOfAnimationBehavior((farmer) => { findTruffle.Invoke(__instance, new object[] { farmer }); }), false)
                        });
                        break;

                    case 1:
                        __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(5, 250),
                            new FarmerSprite.AnimationFrame(7, 250),
                            new FarmerSprite.AnimationFrame(5, 250),
                            new FarmerSprite.AnimationFrame(7, 250),
                            new FarmerSprite.AnimationFrame(5, 250),
                            new FarmerSprite.AnimationFrame(7, 250, false, false, new AnimatedSprite.endOfAnimationBehavior((farmer) => { findTruffle.Invoke(__instance, new object[] { farmer }); }), false)
                        });
                        break;

                    case 2:
                        __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(1, 250),
                            new FarmerSprite.AnimationFrame(3, 250),
                            new FarmerSprite.AnimationFrame(1, 250),
                            new FarmerSprite.AnimationFrame(3, 250),
                            new FarmerSprite.AnimationFrame(1, 250),
                            new FarmerSprite.AnimationFrame(3, 250, false, false, new AnimatedSprite.endOfAnimationBehavior((farmer) => { findTruffle.Invoke(__instance, new object[] { farmer }); }), false)
                        });
                        break;

                    case 3:
                        __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                        {
                            new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                            new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                            new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                            new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                            new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                            new FarmerSprite.AnimationFrame(7, 250, false, true, new AnimatedSprite.endOfAnimationBehavior((farmer) => { findTruffle.Invoke(__instance, new object[] { farmer }); }), false)
                        });
                        break;
                    }

                    __instance.Sprite.loop = false;
                }
                else
                {
                    findTruffle.Invoke(__instance, new object[] { Game1.player });
                }
            }

            __result = false;
            return(false);
        }
            private bool behaviors(GameTime time, GameLocation location)
            {
                if (this.home == null)
                {
                    return(false);
                }
                if (this.isEating)
                {
                    if (this.home != null && this.home.getRectForAnimalDoor().Intersects(this.GetBoundingBox()))
                    {
                        FarmAnimal.behaviorAfterFindingGrassPatch((Character)this, location);
                        this.isEating = false;
                        this.Halt();
                        return(false);
                    }
                    if (this.buildingTypeILiveIn.Contains("Barn"))
                    {
                        this.sprite.Animate(time, 16, 4, 100f);
                        if (this.sprite.CurrentFrame >= 20)
                        {
                            this.isEating            = false;
                            this.sprite.loop         = true;
                            this.sprite.CurrentFrame = 0;
                            this.faceDirection(2);
                        }
                    }
                    else
                    {
                        this.sprite.Animate(time, 24, 4, 100f);
                        if (this.sprite.CurrentFrame >= 28)
                        {
                            this.isEating            = false;
                            this.sprite.loop         = true;
                            this.sprite.CurrentFrame = 0;
                            this.faceDirection(2);
                        }
                    }
                    return(true);
                }
                if (!Game1.IsClient)
                {
                    if (this.controller != null)
                    {
                        return(true);
                    }
                    if (location.IsOutdoors && (int)this.fullness < 195 && Game1.random.NextDouble() < 0.002)
                    {
                        this.controller = new PathFindController((Character)this, location, new PathFindController.isAtEnd(FarmAnimal.grassEndPointFunction), -1, false, new PathFindController.endBehavior(FarmAnimal.behaviorAfterFindingGrassPatch), 200, Point.Zero);
                    }
                    if (Game1.timeOfDay >= 1700 && location.IsOutdoors && (this.controller == null && Game1.random.NextDouble() < 0.002))
                    {
                        this.controller = new PathFindController((Character)this, location, new PathFindController.isAtEnd(PathFindController.isAtEndPoint), 0, false, (PathFindController.endBehavior)null, 200, new Point(this.home.tileX + this.home.animalDoor.X, this.home.tileY + this.home.animalDoor.Y));
                        if (location.getFarmersCount() == 0)
                        {
                            ((AnimalHouse)this.home.indoors).animals.Add(this.myID, this);
                            this.setRandomPosition(this.home.indoors);
                            this.faceDirection(Game1.random.Next(4));
                            this.controller = (PathFindController)null;
                            (location as Farm).animals.Remove(this.myID);
                            return(true);
                        }
                    }
                    if (location.IsOutdoors && !Game1.isRaining && (!Game1.currentSeason.Equals("winter") && this.currentProduce != -1) && (this.age >= (int)this.ageWhenMature && this.type.Contains("Pig") && Game1.random.NextDouble() < 0.0002))
                    {
                        Microsoft.Xna.Framework.Rectangle boundingBox = this.GetBoundingBox();
                        for (int corner = 0; corner < 4; ++corner)
                        {
                            Vector2 cornersOfThisRectangle = Utility.getCornersOfThisRectangle(ref boundingBox, corner);
                            Vector2 key = new Vector2((float)(int)((double)cornersOfThisRectangle.X / (double)Game1.tileSize), (float)(int)((double)cornersOfThisRectangle.Y / (double)Game1.tileSize));
                            if (location.terrainFeatures.ContainsKey(key) || location.objects.ContainsKey(key))
                            {
                                return(false);
                            }
                        }
                        if (Game1.player.currentLocation.Equals((object)location))
                        {
                            DelayedAction.playSoundAfterDelay("dirtyHit", 450);
                            DelayedAction.playSoundAfterDelay("dirtyHit", 900);
                            DelayedAction.playSoundAfterDelay("dirtyHit", 1350);
                        }
                        if (location.Equals((object)Game1.currentLocation))
                        {
                            switch (this.FacingDirection)
                            {
                            case 0:
                                this.sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                                {
                                    new FarmerSprite.AnimationFrame(9, 250),
                                    new FarmerSprite.AnimationFrame(11, 250),
                                    new FarmerSprite.AnimationFrame(9, 250),
                                    new FarmerSprite.AnimationFrame(11, 250),
                                    new FarmerSprite.AnimationFrame(9, 250),
                                    new FarmerSprite.AnimationFrame(11, 250, false, false, new AnimatedSprite.endOfAnimationBehavior(this.findTruffle), false)
                                });
                                break;

                            case 1:
                                this.sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                                {
                                    new FarmerSprite.AnimationFrame(5, 250),
                                    new FarmerSprite.AnimationFrame(7, 250),
                                    new FarmerSprite.AnimationFrame(5, 250),
                                    new FarmerSprite.AnimationFrame(7, 250),
                                    new FarmerSprite.AnimationFrame(5, 250),
                                    new FarmerSprite.AnimationFrame(7, 250, false, false, new AnimatedSprite.endOfAnimationBehavior(this.findTruffle), false)
                                });
                                break;

                            case 2:
                                this.sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                                {
                                    new FarmerSprite.AnimationFrame(1, 250),
                                    new FarmerSprite.AnimationFrame(3, 250),
                                    new FarmerSprite.AnimationFrame(1, 250),
                                    new FarmerSprite.AnimationFrame(3, 250),
                                    new FarmerSprite.AnimationFrame(1, 250),
                                    new FarmerSprite.AnimationFrame(3, 250, false, false, new AnimatedSprite.endOfAnimationBehavior(this.findTruffle), false)
                                });
                                break;

                            case 3:
                                this.sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                                {
                                    new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                    new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                    new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                    new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                    new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                    new FarmerSprite.AnimationFrame(7, 250, false, true, new AnimatedSprite.endOfAnimationBehavior(this.findTruffle), false)
                                });
                                break;
                            }
                            this.sprite.loop = false;
                        }
                        else
                        {
                            this.findTruffle(Game1.player);
                        }
                    }
                }
                return(false);
            }
Exemple #4
0
        public static bool Prefix(FarmAnimal __instance, GameTime time, GameLocation location, ref bool __result)
        {
            NetBool isEating = Mod.instance.Helper.Reflection.GetField <NetBool>(__instance, "isEating").GetValue();

            if (__instance.home == null)
            {
                __result = false;
                return(false);
            }
            if (( bool )(NetFieldBase <bool, NetBool>)isEating)
            {
                if (__instance.home != null && __instance.home.getRectForAnimalDoor().Intersects(__instance.GetBoundingBox()))
                {
                    FarmAnimal.behaviorAfterFindingGrassPatch(( Character )__instance, location);
                    isEating.Value = false;
                    __instance.Halt();
                    __result = false;
                    return(false);
                }
                if (__instance.buildingTypeILiveIn.Contains("Barn"))
                {
                    __instance.Sprite.Animate(time, 16, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 20)
                    {
                        isEating.Value                 = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }
                else
                {
                    __instance.Sprite.Animate(time, 24, 4, 100f);
                    if (__instance.Sprite.currentFrame >= 28)
                    {
                        isEating.Value                 = false;
                        __instance.Sprite.loop         = true;
                        __instance.Sprite.currentFrame = 0;
                        __instance.faceDirection(2);
                    }
                }
                __result = true;
                return(false);
            }
            if (!Game1.IsClient)
            {
                if (__instance.controller != null)
                {
                    __result = true;
                    return(false);
                }
                if (location.IsOutdoors && ( byte )(NetFieldBase <byte, NetByte>)__instance.fullness < ( byte )195 && (Game1.random.NextDouble() < 0.002 && FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick))
                {
                    ++FarmAnimal.NumPathfindingThisTick;
                    __instance.controller = new PathFindController(( Character )__instance, location, new PathFindController.isAtEnd(FarmAnimal.grassEndPointFunction), -1, false, new PathFindController.endBehavior(FarmAnimal.behaviorAfterFindingGrassPatch), 200, Point.Zero, true);
                }
                if (Game1.timeOfDay >= 1700 && location.IsOutdoors && (__instance.controller == null && Game1.random.NextDouble() < 0.002))
                {
                    if (location.farmers.Count == 0)
                    {
                        (location as Farm).animals.Remove(( long )__instance.myID);
                        (__instance.home.indoors.Value as AnimalHouse).animals.Add(( long )__instance.myID, __instance);
                        __instance.setRandomPosition(( GameLocation )(NetFieldBase <GameLocation, NetRef <GameLocation> >)__instance.home.indoors);
                        __instance.faceDirection(Game1.random.Next(4));
                        __instance.controller = ( PathFindController )null;
                        __result = true;
                        return(false);
                    }
                    if (FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick)
                    {
                        ++FarmAnimal.NumPathfindingThisTick;
                        __instance.controller = new PathFindController(( Character )__instance, location, new PathFindController.isAtEnd(PathFindController.isAtEndPoint), 0, false, (PathFindController.endBehavior)null, 200, new Point(( int )(NetFieldBase <int, NetInt>)__instance.home.tileX + __instance.home.animalDoor.X, ( int )(NetFieldBase <int, NetInt>)__instance.home.tileY + __instance.home.animalDoor.Y), true);
                    }
                }
                if (location.IsOutdoors && !Game1.isRaining && (!Game1.currentSeason.Equals("winter") && ( int )(NetFieldBase <int, NetInt>)__instance.currentProduce != -1) && (( int )(NetFieldBase <int, NetInt>)__instance.age >= ( int )( byte )(NetFieldBase <byte, NetByte>)__instance.ageWhenMature && __instance.type.Value.Contains("Pig") && Game1.random.NextDouble() < 0.0002))
                {
                    Microsoft.Xna.Framework.Rectangle boundingBox = __instance.GetBoundingBox();
                    for (int corner = 0; corner < 4; ++corner)
                    {
                        Vector2 cornersOfThisRectangle = Utility.getCornersOfThisRectangle(ref boundingBox, corner);
                        Vector2 key = new Vector2((float)(int)((double)cornersOfThisRectangle.X / 64.0), (float)(int)((double)cornersOfThisRectangle.Y / 64.0));
                        if (location.terrainFeatures.ContainsKey(key) || location.objects.ContainsKey(key))
                        {
                            __result = false;
                            return(false);
                        }
                    }
                    if (Game1.player.currentLocation.Equals(location))
                    {
                        DelayedAction.playSoundAfterDelay("dirtyHit", 450, ( GameLocation )null, -1);
                        DelayedAction.playSoundAfterDelay("dirtyHit", 900, ( GameLocation )null, -1);
                        DelayedAction.playSoundAfterDelay("dirtyHit", 1350, ( GameLocation )null, -1);
                    }
                    if (location.Equals(Game1.currentLocation))
                    {
                        var findTruffleDelegate = (AnimatedSprite.endOfAnimationBehavior)Delegate.CreateDelegate(typeof(AnimatedSprite.endOfAnimationBehavior), Mod.instance.Helper.Reflection.GetMethod(__instance, "findTruffle").MethodInfo);

                        switch (__instance.FacingDirection)
                        {
                        case 0:
                            __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                            {
                                new FarmerSprite.AnimationFrame(9, 250),
                                new FarmerSprite.AnimationFrame(11, 250),
                                new FarmerSprite.AnimationFrame(9, 250),
                                new FarmerSprite.AnimationFrame(11, 250),
                                new FarmerSprite.AnimationFrame(9, 250),
                                new FarmerSprite.AnimationFrame(11, 250, false, false, findTruffleDelegate, false)
                            });
                            break;

                        case 1:
                            __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                            {
                                new FarmerSprite.AnimationFrame(5, 250),
                                new FarmerSprite.AnimationFrame(7, 250),
                                new FarmerSprite.AnimationFrame(5, 250),
                                new FarmerSprite.AnimationFrame(7, 250),
                                new FarmerSprite.AnimationFrame(5, 250),
                                new FarmerSprite.AnimationFrame(7, 250, false, false, findTruffleDelegate, false)
                            });
                            break;

                        case 2:
                            __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                            {
                                new FarmerSprite.AnimationFrame(1, 250),
                                new FarmerSprite.AnimationFrame(3, 250),
                                new FarmerSprite.AnimationFrame(1, 250),
                                new FarmerSprite.AnimationFrame(3, 250),
                                new FarmerSprite.AnimationFrame(1, 250),
                                new FarmerSprite.AnimationFrame(3, 250, false, false, findTruffleDelegate, false)
                            });
                            break;

                        case 3:
                            __instance.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                            {
                                new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                new FarmerSprite.AnimationFrame(7, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                new FarmerSprite.AnimationFrame(5, 250, false, true, (AnimatedSprite.endOfAnimationBehavior)null, false),
                                new FarmerSprite.AnimationFrame(7, 250, false, true, findTruffleDelegate, false)
                            });
                            break;
                        }
                        __instance.Sprite.loop = false;
                    }
                    else
                    {
                        Mod.instance.Helper.Reflection.GetMethod(__instance, "findTruffle").Invoke(Game1.player);
                    }
                }
            }
            __result = false;
            return(false);
        }