private void CheckPetAnimal(IAnimalLocation location, Farmer who)
 {
     foreach (KeyValuePair <long, FarmAnimal> kvp in location.Animals.Pairs)
     {
         FarmAnimal animal = kvp.Value;
         if (Parameters.AnimalType == AnimalType.Any || animal.GetAnimalType() == Parameters.AnimalType)
         {
             if (canPet(animal) && animal.GetCursorPetBoundingBox().Contains((int)who.position.X, (int)who.position.Y))
             {
                 animal.pet(who, false);
             }
         }
     }
 }
Esempio n. 2
0
 /*********
 ** Private methods
 *********/
 /// <summary>The method to call before <see cref="FarmAnimal.updateWhenNotCurrentLocation"/>.</summary>
 private static bool Before_UpdateWhenNotCurrentLocation(FarmAnimal __instance, Building currentBuilding, GameTime time, GameLocation environment)
 {
     Mod.Instance.Helper.Reflection.GetField <NetEvent1Field <int, NetInt> >(__instance, "doFarmerPushEvent").GetValue().Poll();
     Mod.Instance.Helper.Reflection.GetField <NetEvent0>(__instance, "doBuildingPokeEvent").GetValue().Poll();
     if (!Game1.shouldTimePass())
     {
         return(false);
     }
     __instance.update(time, environment, __instance.myID.Value, false);
     if (!Game1.IsMasterGame)
     {
         return(false);
     }
     if (currentBuilding != null && Game1.random.NextDouble() < 0.002 && (currentBuilding.animalDoorOpen.Value && Game1.timeOfDay < 1630) && (!Game1.isRaining && !Game1.currentSeason.Equals("winter") && environment.farmers.Count == 0))
     {
         GameLocation    locationFromName         = Mod.FindOutdoorsOf(currentBuilding);
         IAnimalLocation locationFromName_animals = (IAnimalLocation)locationFromName;
         if (locationFromName.isCollidingPosition(new Rectangle((currentBuilding.tileX.Value + currentBuilding.animalDoor.X) * 64 + 2, (currentBuilding.tileY.Value + currentBuilding.animalDoor.Y) * 64 + 2, (__instance.isCoopDweller() ? 64 : 128) - 4, 60), Game1.viewport, false, 0, false, __instance, false) || locationFromName.isCollidingPosition(new Rectangle((currentBuilding.tileX.Value + currentBuilding.animalDoor.X) * 64 + 2, (currentBuilding.tileY.Value + currentBuilding.animalDoor.Y + 1) * 64 + 2, (__instance.isCoopDweller() ? 64 : 128) - 4, 60), Game1.viewport, false, 0, false, __instance, false))
         {
             return(false);
         }
         if (locationFromName_animals.Animals.ContainsKey(__instance.myID.Value))
         {
             for (int index = locationFromName_animals.Animals.Count() - 1; index >= 0; --index)
             {
                 if (locationFromName_animals.Animals.Pairs.ElementAt(index).Key.Equals(__instance.myID.Value))
                 {
                     locationFromName_animals.Animals.Remove(__instance.myID.Value);
                     break;
                 }
             }
         }
         (currentBuilding.indoors.Value as AnimalHouse).animals.Remove(__instance.myID.Value);
         locationFromName_animals.Animals.Add(__instance.myID.Value, __instance);
         __instance.faceDirection(2);
         __instance.SetMovingDown(true);
         __instance.Position = new Vector2(currentBuilding.getRectForAnimalDoor().X, (currentBuilding.tileY.Value + currentBuilding.animalDoor.Y) * 64 - (__instance.Sprite.getHeight() * 4 - __instance.GetBoundingBox().Height) + 32);
         if (FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick)
         {
             ++FarmAnimal.NumPathfindingThisTick;
             __instance.controller = new PathFindController(__instance, locationFromName, FarmAnimal.grassEndPointFunction, Game1.random.Next(4), false, FarmAnimal.behaviorAfterFindingGrassPatch, 200, Point.Zero);
         }
         if (__instance.controller?.pathToEndPoint == null || __instance.controller.pathToEndPoint.Count < 3)
         {
             __instance.SetMovingDown(true);
             __instance.controller = null;
         }
         else
         {
             __instance.faceDirection(2);
             __instance.Position = new Vector2(__instance.controller.pathToEndPoint.Peek().X * 64, __instance.controller.pathToEndPoint.Peek().Y * 64 - (__instance.Sprite.getHeight() * 4 - __instance.GetBoundingBox().Height) + 16);
             if (!__instance.isCoopDweller())
             {
                 __instance.position.X -= 32f;
             }
         }
         __instance.noWarpTimer = 3000;
         --currentBuilding.currentOccupants.Value;
         if (Utility.isOnScreen(__instance.getTileLocationPoint(), 192, locationFromName))
         {
             locationFromName.localSound("sandyStep");
         }
         if (environment.isTileOccupiedByFarmer(__instance.getTileLocation()) != null)
         {
             environment.isTileOccupiedByFarmer(__instance.getTileLocation()).TemporaryPassableTiles.Add(__instance.GetBoundingBox());
         }
     }
     Mod.Instance.Helper.Reflection.GetMethod(__instance, "behaviors").Invoke(time, environment);
     return(false);
 }
 public static FarmAnimal GetSelectedAnimal(this IAnimalLocation location, Rectangle rectangle)
 {
     return(location.Animals.Values
            .FirstOrDefault(farmAnimal => farmAnimal.GetBoundingBox().Intersects(rectangle)));
 }