private void process()
        {
            if (!create)
            {
                NPCMonitor.destroyAnimal(animalId);
                return;
            }

            FarmAnimal a = null;

            try
            {
                a = Util.deserialize <FarmAnimal>(animalStr);
            }
            catch (Exception e)
            {
                Log.Async("Exception deserializing farm animal: " + e);
            }

            NPCMonitor.addAnimal(location, a);
            a.reload();
        }
        /*********
        ** Private methods
        *********/
        /// <summary>Get a short explanation for the animal's current mod.</summary>
        /// <param name="animal">The farm animal.</param>
        private string GetMoodReason(FarmAnimal animal)
        {
            List <string> factors = new List <string>();

            // winter without heat
            if (Game1.IsWinter && Game1.currentLocation.numberOfObjectsWithName(Constant.ItemNames.Heater) <= 0)
            {
                factors.Add(this.Translate(L10n.Animal.ComplaintsNoHeater));
            }

            // mood
            switch (animal.moodMessage.Value)
            {
            case FarmAnimal.newHome:
                factors.Add(this.Translate(L10n.Animal.ComplaintsNewHome));
                break;

            case FarmAnimal.hungry:
                factors.Add(this.Translate(L10n.Animal.ComplaintsHungry));
                break;

            case FarmAnimal.disturbedByDog:
                factors.Add(this.Translate(L10n.Animal.ComplaintsWildAnimalAttack));
                break;

            case FarmAnimal.leftOutAtNight:
                factors.Add(this.Translate(L10n.Animal.ComplaintsLeftOut));
                break;
            }

            // not pet
            if (!animal.wasPet.Value)
            {
                factors.Add(this.Translate(L10n.Animal.ComplaintsNotPetted));
            }

            // return factors
            return(string.Join(", ", factors));
        }
        /*********
        ** Private methods
        *********/
        /// <summary>Get a short explanation for the animal's current mod.</summary>
        /// <param name="animal">The farm animal.</param>
        private string GetMoodReason(FarmAnimal animal)
        {
            List <string> factors = new List <string>();

            // winter without heat
            if (Game1.IsWinter && Game1.currentLocation.numberOfObjectsWithName(Constant.ItemNames.Heater) <= 0)
            {
                factors.Add("no heater in winter");
            }

            // mood
            switch (animal.moodMessage)
            {
            case FarmAnimal.newHome:
                factors.Add("moved into new home");
                break;

            case FarmAnimal.hungry:
                factors.Add("wasn't fed yesterday");
                break;

            case FarmAnimal.disturbedByDog:
                factors.Add($"was disturbed by {Game1.player.getPetName()}");
                break;

            case FarmAnimal.leftOutAtNight:
                factors.Add("was left outside last night");
                break;
            }

            // not pet
            if (!animal.wasPet)
            {
                factors.Add("hasn't been petted today");
            }

            // return factors
            return(string.Join(", ", factors));
        }
        /// <summary>Patch to adjust Breeder animal sell price.</summary>
        private static bool FarmAnimalGetSellPricePrefix(ref FarmAnimal __instance, ref int __result)
        {
            double adjustedFriendship;

            try
            {
                var owner = Game1.getFarmer(__instance.ownerID.Value);
                if (!Utility.SpecificPlayerHasProfession("Breeder", owner))
                {
                    return(true);                                                                        // run original logic
                }
                adjustedFriendship = Utility.GetProducerAdjustedFriendship(__instance);
            }
            catch (Exception ex)
            {
                Monitor.Log($"Failed in {nameof(FarmAnimalGetSellPricePrefix)}:\n{ex}");
                return(true);                // default to original logic
            }

            __result = (int)(__instance.price.Value * adjustedFriendship);
            return(false);            // don't run original logic
        }
        private static bool BeforeDraw(FarmAnimal __instance, SpriteBatch b)
        {
            if (ClickToMoveManager.GetOrCreate(Game1.currentLocation).TargetFarmAnimal == __instance)
            {
                b.Draw(
                    Game1.mouseCursors,
                    Game1.GlobalToLocal(
                        Game1.viewport,
                        new Vector2(
                            (int)__instance.Position.X + (__instance.Sprite.getWidth() * 4 / 2) - 32,
                            (int)__instance.Position.Y + (__instance.Sprite.getHeight() * 4 / 2) - 24)),
                    new Rectangle(194, 388, 16, 16),
                    Color.White,
                    0f,
                    Vector2.Zero,
                    4f,
                    SpriteEffects.None,
                    0.01f);
            }

            return(true);
        }
Exemple #6
0
        public override bool beginUsing(GameLocation location, int x, int y, Farmer who)
        {
            x = (int)who.GetToolLocation().X;
            y = (int)who.GetToolLocation().Y;
            Rectangle r = new Rectangle(x - 32, y - 32, 64, 64);

            if (location is Farm)
            {
                animal = Utility.GetBestHarvestableFarmAnimal((location as Farm).animals.Values, this, r);
            }
            else if (location is AnimalHouse)
            {
                animal = Utility.GetBestHarvestableFarmAnimal((location as AnimalHouse).animals.Values, this, r);
            }
            who.Halt();
            int g = who.FarmerSprite.CurrentFrame;

            who.FarmerSprite.animateOnce(283 + who.FacingDirection, 50f, 4);
            who.FarmerSprite.oldFrame = g;
            who.UsingTool             = true;
            who.CanMove = false;
            return(true);
        }
        public static bool Prefix(ref FarmAnimal __instance)
        {
            if (!Config.HasAnimal(__instance.type.Value))
            {
                return(true);
            }
            UpdateOrInsert(ref __instance);

            CurrentDrops.DefaultDrop = __instance.defaultProduceIndex.Value;
            CurrentDrops.DeluxeDrop  = __instance.deluxeProduceIndex.Value;
            CurrentDrops.IsAltered   = true;

            CurrentDrops.NewDrop = Config.GetMainDropForAnimal(__instance.type.Value);
            __instance.defaultProduceIndex.Value = CurrentDrops.NewDrop;
            __instance.deluxeProduceIndex.Value  = -1;

            if (RegisterGameEvents.IsModLoaded("Paritee.BetterFarmAnimalVariety"))
            {
                __instance.pushAccumulator = 1;
            }

            return(true);
        }
Exemple #8
0
        public static void NewHatchedAnimalPrefix(AnimalHouse __instance, ref string name, ref string __state)
        {
            if (__instance.getBuilding() is Coop)
            {
                foreach (StardewValley.Object @object in __instance.objects.Values)
                {
                    if ((bool)((NetFieldBase <bool, NetBool>)@object.bigCraftable) && @object.Name.Contains("Incubator") && (@object.heldObject.Value != null && (int)((NetFieldBase <int, NetIntDelta>)@object.minutesUntilReady) <= 0) && !__instance.isFull())
                    {
                        FarmAnimal farmAnimal = ModEntry.BirthAnimal(__instance, @object.heldObject.Value.ParentSheetIndex);

                        if (farmAnimal != null)
                        {
                            farmAnimal.Name          = name;
                            farmAnimal.displayName   = name;
                            @object.heldObject.Value = (StardewValley.Object)null;
                            @object.ParentSheetIndex = 101;
                            __state = farmAnimal.type;
                        }
                        break;
                    }
                }
            }
        }
Exemple #9
0
        /****
        ** Helpers
        ****/
        /// <summary>Push the target in front of the player.</summary>
        private void Push()
        {
            ITarget target = this.TargetFactory.GetTarget(Game1.currentLocation);

            if (target != null)
            {
                switch (target.Type)
                {
                case TargetType.Horse:
                case TargetType.Junimo:
                case TargetType.Monster:
                case TargetType.Pet:
                case TargetType.Villager:
                    NPC npc = target.GetValue <NPC>();
                    this.Monitor.Log("NPC: " + npc.Name);
                    npc.Position += this.GetPushVector(target, npc.Name);
                    break;

                case TargetType.FarmAnimal:
                    FarmAnimal animal = target.GetValue <FarmAnimal>();
                    this.Monitor.Log("Animal: " + animal.Name);
                    animal.Position += this.GetPushVector(target, animal.Name);
                    break;

                case TargetType.Farmer:
                    Farmer farmer = target.GetValue <Farmer>();
                    this.Monitor.Log("Farmer: " + farmer.Name);
                    farmer.Position += this.GetPushVector(target, farmer.Name);
                    break;

                default:
                    StardewValley.Object obj = target.GetValue <StardewValley.Object>();
                    this.Monitor.Log("Unpushable object: " + obj.Name);
                    break;
                }
            }
        }
Exemple #10
0
        public override bool beginUsing(GameLocation location, int x, int y, Farmer who)
        {
            x = (int)who.GetToolLocation(false).X;
            y = (int)who.GetToolLocation(false).Y;
            Rectangle rectangle = new Rectangle(x - Game1.tileSize / 2, y - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize);

            if (location is Farm)
            {
                foreach (FarmAnimal farmAnimal in (location as Farm).animals.Values)
                {
                    if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                    {
                        this.animal = farmAnimal;
                        break;
                    }
                }
            }
            else if (location is AnimalHouse)
            {
                foreach (FarmAnimal farmAnimal in (location as AnimalHouse).animals.Values)
                {
                    if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                    {
                        this.animal = farmAnimal;
                        break;
                    }
                }
            }
            who.Halt();
            int currentFrame = who.FarmerSprite.currentFrame;

            who.FarmerSprite.animateOnce(283 + who.FacingDirection, 50f, 4);
            who.FarmerSprite.oldFrame = currentFrame;
            who.UsingTool             = true;
            who.CanMove = false;
            return(true);
        }
        public override void DoFunction(GameLocation location, int x, int y, int power, StardewValley.Farmer who)
        {
            this.lastUser = who;
            Game1.recentMultiplayerRandom  = new Random((int)(short)Game1.random.Next((int)short.MinValue, 32768));
            this.CurrentParentTileIndex    = InitialParentTileIndex;
            this.indexOfMenuItemView.Value = IndexOfMenuItemView;

            if (this._animal != null)
            {
                Animal?foundAnimal = AnimalExtension.GetAnimalFromType(this._animal.type.Value);
                who.Stamina -= ((float)4f - (float)who.FarmingLevel * 0.2f);
                int daysUtillBirth = (DataLoader.AnimalData.getAnimalItem((Animal)foundAnimal) as ImpregnatableAnimalItem).MinimumDaysUtillBirth;
                PregnancyController.AddPregancy(new PregnancyItem(this._animal.myID.Value, daysUtillBirth, this._animal.allowReproduction.Value));
                this._animal.allowReproduction.Value = false;
                --this.attachments[0].Stack;
                if (this.attachments[0].Stack <= 0)
                {
                    Game1.showGlobalMessage(DataLoader.i18n.Get("Tool.InseminationSyringe.ItemConsumed", new { itemName = this.attachments[0].DisplayName }));
                    this.attachments[0] = (StardewValley.Object)null;
                }
                this._animal = (FarmAnimal)null;
            }

            if (Game1.activeClickableMenu == null)
            {
                who.CanMove = true;
                who.completelyStopAnimatingOrDoingAction();
            }
            else
            {
                who.Halt();
            }
            who.UsingTool      = false;
            who.canReleaseTool = true;

            DataLoader.Helper.Reflection.GetMethod(this, "finish").Invoke();
        }
Exemple #12
0
        private static void addNewHatchedAnimal(string name)
        {
            try
            {
                Building   building   = parentAnimal.Value.home;
                FarmAnimal farmAnimal = new FarmAnimal(parentAnimal.Value.type.Value,
                                                       DataLoader.Helper.Multiplayer.GetNewID(),
                                                       parentAnimal.Value.ownerID.Value != 0
                        ? parentAnimal.Value.ownerID.Value
                        : (long)Game1.player.UniqueMultiplayerID)
                {
                    Name        = name,
                    displayName = name,
                    home        = building
                };
                farmAnimal.parentId.Value     = parentAnimal.Value.myID.Value;
                farmAnimal.homeLocation.Value = new Vector2((float)building.tileX.Value, (float)building.tileY.Value);
                farmAnimal.setRandomPosition(farmAnimal.home.indoors.Value);
                AnimalHouse animalHouse = (building.indoors.Value as AnimalHouse);
                animalHouse?.animals.Add(farmAnimal.myID.Value, farmAnimal);
                animalHouse?.animalsThatLiveHere.Add(farmAnimal.myID.Value);

                bool?allowReproductionBeforeInsemination = parentAnimal.Value.GetAllowReproductionBeforeInsemination();
                parentAnimal.Value.allowReproduction.Value = allowReproductionBeforeInsemination ?? parentAnimal.Value.allowReproduction.Value;
                RemovePregnancy(parentAnimal.Value);
            }
            catch (Exception e)
            {
                AnimalHusbandryModEntry.monitor.Log($"Error while adding born baby '{name}'. The birth will be skipped.", LogLevel.Error);
                AnimalHusbandryModEntry.monitor.Log($"Message from birth error above: {e.Message}");
            }
            finally
            {
                parentAnimal.Value = null;
                Game1.exitActiveMenu();
            }
        }
        public static bool AnimalBehaviorsExecutor(ref bool __result, ref FarmAnimal __instance, ref GameTime time, ref GameLocation location)
        {
            // return false if the animal's home is null
            if (__instance.home == null)
            {
                __result = false;
            }

            if (!Game1.IsClient)
            {
                if (__instance.controller != null)
                {
                    __result = true;
                }
                if (!__instance.isSwimming.Value && location.IsOutdoors && !ModData.FullAnimals.Contains(__instance) && __instance.controller == null && (Game1.random.NextDouble() < 0.005 && FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick) && ModEntry.Instance.Config.AnimalsCanDrinkOutside)
                {
                    // pathfind to the closest water tile
                    ++FarmAnimal.NumPathfindingThisTick;
                    __instance.controller = new PathFindController(__instance, location, WaterEndPointFunction, -1, false, BehaviorAfterFindingWater, 200, Point.Zero);
                }
            }

            return(true);
        }
        public static void DrawBubble(FarmAnimal animal)
        {
            if (animal == null)
            {
                return;
            }

            var bubblePosition = new Vector2(
                animal.Position.X + animal.Sprite.getWidth() / 2,
                animal.Position.Y - (Game1.tileSize * 4) / 3 + GetBubbleOffset());

            Game1.spriteBatch.Draw(Bubble,
                                   Game1.GlobalToLocal(Game1.viewport, bubblePosition),
                                   Color.White * 0.75f);

            var heartPosition = bubblePosition
                                + new Vector2(Bubble.Width / 2, Bubble.Height / 2)
                                - new Vector2(Heart.Width / 2, Heart.Height / 2)
                                - new Vector2(0, 4);

            Game1.spriteBatch.Draw(Heart,
                                   Game1.GlobalToLocal(Game1.viewport, heartPosition),
                                   new Color(255, 128, 128, 192));
        }
Exemple #15
0
        public static bool AnimalBehaviors(ref bool __result, ref FarmAnimal __instance, ref GameTime time, ref GameLocation location)
        {
            // return false if the animal's home is null
            if (__instance.home == null)
            {
                __result = false;
            }

            if (!Game1.IsClient)
            {
                if (__instance.controller != null)
                {
                    __result = true;
                }
                if (location.IsOutdoors && !ModData.FullAnimals.Contains(((Character)__instance).displayName) && __instance.controller == null && (Game1.random.NextDouble() < 0.001 && FarmAnimal.NumPathfindingThisTick < FarmAnimal.MaxPathfindingPerTick) && ModEntry.instance.Config.AnimalsCanDrinkOutside)
                {
                    // pathfind to the closest water tile
                    ++FarmAnimal.NumPathfindingThisTick;
                    __instance.controller = new PathFindController((Character)__instance, location, new PathFindController.isAtEnd(WaterEndPointFunction), -1, false, new PathFindController.endBehavior(BehaviorAfterFindingWater), 200, Point.Zero, true);
                }
            }

            return(true);
        }
Exemple #16
0
 public static void Prefix(FarmAnimal __instance)
 {
     if (!Config.EnableMod || __instance.modData.ContainsKey(sexKey))
     {
         return;
     }
     if (Game1.activeClickableMenu is PurchaseAnimalsMenu)
     {
         __instance.modData[sexKey] = currentSex + "";
     }
     else if (Game1.random.Next() < Config.IntersexChance)
     {
         __instance.modData[sexKey] = Sexes.Intersex + "";
     }
     else if (__instance.myID.Value % 2 == 0)
     {
         __instance.modData[sexKey] = Sexes.Male + "";
     }
     else
     {
         __instance.modData[sexKey] = Sexes.Male + "";
     }
     SMonitor.Log($"Set animal sex to {currentSex}");
 }
        public bool ShouldDieOfOldAge(FarmAnimal animal)
        {
            int age = animal.GetDaysOwned();

            var ages = GetMinAndMaxAnimalAgeInYears(animal);

            // convert years to days
            int minAge = ages.Item1 * 28 * 4;
            int maxAge = ages.Item2 * 28 * 4;

            if (age >= minAge)
            {
                double ran = Game1.random.NextDouble();

                double mappedValue = Map(age, minAge, maxAge, 0, 1);

                if (ran < mappedValue)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #18
0
 public static void AnimalDayUpdate(ref FarmAnimal __instance, ref GameLocation environtment)
 {
     if (!(__instance.home != null && !(__instance.home.indoors.Value as AnimalHouse).animals.ContainsKey(__instance.myID.Value) && environtment is Farm && !__instance.home.animalDoorOpen.Value))
     {
         if (__instance.home.nameOfIndoors.ToLower().Contains("coop"))
         {
             // checking whether CoopsWithWateredTrough contains the coop the animal lives in and whether it was able to drink outside or not
             if (ModData.CoopsWithWateredTrough.Contains(__instance.home.nameOfIndoors.ToLower()) || ModData.FullAnimals.Contains(((Character)__instance).displayName))
             {
                 // increasing friendship points if any of the conditions above is met
                 __instance.friendshipTowardFarmer.Value += Math.Abs(ModEntry.instance.Config.FriendshipPointsForWateredTrough);
             }
         }
         else if (__instance.home.nameOfIndoors.ToLower().Contains("barn"))
         {
             // checking whether BarnsWithWateredTrough contains the coop the animal lives in and whether it was able to drink outside or not
             if (ModData.BarnsWithWateredTrough.Contains(__instance.home.nameOfIndoors.ToLower()) || ModData.FullAnimals.Contains(((Character)__instance).displayName))
             {
                 // increasing friendship points if any of the conditions above is met
                 __instance.friendshipTowardFarmer.Value += Math.Abs(ModEntry.instance.Config.FriendshipPointsForWateredTrough);
             }
         }
     }
 }
Exemple #19
0
        public override bool beginUsing(GameLocation location, int x, int y, StardewValley.Farmer who)
        {
            x = (int)who.GetToolLocation(false).X;
            y = (int)who.GetToolLocation(false).Y;
            Rectangle rectangle = new Rectangle(x - Game1.tileSize / 2, y - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize);

            if (!DataLoader.ModConfig.DisableTreats)
            {
                if (location is Farm)
                {
                    foreach (FarmAnimal farmAnimal in (location as Farm).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            this._animal = farmAnimal;
                            break;
                        }
                    }
                    if (this._animal == null)
                    {
                        foreach (Pet pet in location.characters.Where(i => i is Pet))
                        {
                            if (pet.GetBoundingBox().Intersects(rectangle))
                            {
                                this._pet = pet;
                                break;
                            }
                        }
                    }
                }
                else if (location is AnimalHouse)
                {
                    foreach (FarmAnimal farmAnimal in (location as AnimalHouse).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            this._animal = farmAnimal;
                            break;
                        }
                    }
                }
                else if (location is FarmHouse)
                {
                    foreach (Pet pet in location.characters.Where(i => i is Pet))
                    {
                        if (pet.GetBoundingBox().Intersects(rectangle))
                        {
                            this._pet = pet;
                            break;
                        }
                    }
                }
            }

            if (this._animal != null)
            {
                string dialogue = "";
                if (this._animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.CantBeBaby", new { itemName = this.attachments[0].DisplayName });
                }
                else if (AnimalContestController.IsParticipant(this._animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.HasAlreadyParticipatedContest", new { itemName = this.attachments[0].DisplayName });
                }
                else
                {
                    this._animal.doEmote(8, true);
                    this._animal.makeSound();
                    this._animal.pauseTimer = 200;
                }


                if (dialogue.Length > 0)
                {
                    DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    this._animal = null;
                }
            }
            if (this._pet != null)
            {
                string dialogue = "";
                if (false)
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.PetCantCondition");
                }
                else
                {
                    this._pet.doEmote(8, true);
                    this._pet.playContentSound();
                    _pet.Halt();
                    _pet.CurrentBehavior = 0;
                    _pet.Halt();
                    _pet.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(18, 200)
                    });
                }


                if (dialogue.Length > 0)
                {
                    DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    this._pet = null;
                }
            }


            who.Halt();
            int currentFrame = who.FarmerSprite.currentFrame;

            if (this._animal != null || this._pet != null)
            {
                switch (who.FacingDirection)
                {
                case 0:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(62, 200, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;

                case 1:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(58, 200, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;

                case 2:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(54, 200, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;

                case 3:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(58, 200, false, true, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;
                }
            }
            else
            {
                who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                    new FarmerSprite.AnimationFrame(currentFrame, 0, false, who.FacingDirection == 3, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                });
            }
            who.FarmerSprite.oldFrame = currentFrame;
            who.UsingTool             = true;
            who.CanMove = false;


            return(true);
        }
        public void helperAction()
        {
            checkIfBuilding();
            if (this.targetChest != null)
            {
                if (this.offset == 40)
                {
                    StardewValley.Object fish = this.location.getFish(500, 774, 5, Game1.player, (double)15);
                    if (fish == null || fish.ParentSheetIndex <= 0)
                    {
                        fish = new StardewValley.Object(Game1.random.Next(167, 173), 1, false, -1, 0);
                    }
                    if (this.nearPlayer == true)
                    {
                        Game1.playSound("coin");
                    }
                    if (this.targetChest.items.Count < 36)
                    {
                        this.targetChest.addItem(fish);
                    }
                }

                if ((this.location is AnimalHouse) && this.location.name.Contains("Barn") && this.offset == 32)
                {
                    SerializableDictionary <long, FarmAnimal> animalDict = (this.location as AnimalHouse).animals;
                    List <FarmAnimal> animals = new List <FarmAnimal>();
                    foreach (long keyL in animalDict.Keys)
                    {
                        animals.Add(animalDict[keyL]);
                    }

                    if (animals.Count() > 0)
                    {
                        for (int i = 0; i < animals.Count(); i++)
                        {
                            FarmAnimal animal = animals[i];

                            if (animal != null && animal.currentProduce > 0 && (animal.age >= (int)animal.ageWhenMature) && this.targetChest.items.Count < 36)
                            {
                                StardewValley.Object product = new StardewValley.Object(Vector2.Zero, animal.currentProduce, (string)null, false, true, false, false);
                                product.quality = animal.produceQuality;

                                this.targetChest.addItem(product);

                                if (this.nearPlayer == true)
                                {
                                    Game1.playSound("coin");
                                }
                                animal.currentProduce = -1;
                                if (animal.showDifferentTextureWhenReadyForHarvest)
                                {
                                    animal.sprite.Texture = Game1.content.Load <Texture2D>("Animals\\Sheared" + animal.type);
                                }
                                Game1.player.gainExperience(0, 5);
                                break;
                            }
                        }
                    }
                }


                if (this.offset == 32)
                {
                    List <Vector2> pickTiles = new List <Vector2>();
                    SerializableDictionary <Vector2, StardewValley.Object> allobjects;

                    allobjects = this.location.objects;

                    pickTiles = new List <Vector2>();

                    Random rnd = new Random();


                    foreach (var keyV in allobjects.Keys)
                    {
                        if (allobjects[keyV].canBeShipped() && !allobjects[keyV].hasBeenInInventory && !allobjects[keyV].bigCraftable && allobjects[keyV].CanBeGrabbed && !allobjects[keyV].canBePlacedInWater() && allobjects[keyV].canBeGivenAsGift() && !allobjects[keyV].hasBeenPickedUpByFarmer && allobjects[keyV].salePrice() >= 1 && (allobjects[keyV].isForage(this.location) || allobjects[keyV].isAnimalProduct()))
                        {
                            pickTiles.Add(keyV);
                        }
                    }

                    int i = rnd.Next(pickTiles.Count());


                    if (this.targetChest.items.Count < 36 && pickTiles.Count() > 0)
                    {
                        if (this.nearPlayer == true)
                        {
                            Game1.playSound("coin");
                        }

                        this.targetChest.addItem(allobjects[pickTiles[i]]);
                        allobjects.Remove(pickTiles[i]);
                    }
                }
            }
        }
Exemple #21
0
 /// <summary>Get parsed data about the friendship between a player and NPC.</summary>
 /// <param name="player">The player.</param>
 /// <param name="animal">The farm animal.</param>
 /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
 public FriendshipModel GetFriendshipForAnimal(SFarmer player, FarmAnimal animal, Metadata metadata)
 {
     return(new FriendshipModel(animal.friendshipTowardFarmer.Value, metadata.Constants.AnimalFriendshipPointsPerLevel, metadata.Constants.AnimalFriendshipMaxPoints));
 }
Exemple #22
0
        /// <summary>Get a rectangle which roughly bounds the visible sprite relative the viewport.</summary>
        public override Rectangle GetSpriteArea()
        {
            FarmAnimal animal = (FarmAnimal)this.Value;

            return(this.GetSpriteArea(animal.GetBoundingBox(), animal.Sprite.SourceRect));
        }
 public static bool IsBlueChickenAvailableForPurchase(SDV.Farmer farmer)
 {
     return(FarmAnimal.RollBlueChickenChance(farmer));
 }
Exemple #24
0
 public PostFarmAnimalConstructedEvent(FarmAnimal farmAnimal)
 {
     FarmAnimal = farmAnimal;
 }
Exemple #25
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="obj">The underlying in-game object.</param>
 /// <param name="tilePosition">The object's tile position in the current location (if applicable).</param>
 public FarmAnimalTarget(FarmAnimal obj, Vector2?tilePosition = null)
     : base(TargetType.FarmAnimal, obj, tilePosition)
 {
 }
        public override bool beginUsing(GameLocation location, int x, int y, StardewValley.Farmer who)
        {
            x = (int)who.GetToolLocation(false).X;
            y = (int)who.GetToolLocation(false).Y;
            Rectangle rectangle = new Rectangle(x - Game1.tileSize / 2, y - Game1.tileSize / 2, Game1.tileSize,
                                                Game1.tileSize);

            if (!DataLoader.ModConfig.DisableMeat)
            {
                if (location is Farm)
                {
                    foreach (FarmAnimal farmAnimal in (location as Farm).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            if (farmAnimal == this._tempAnimal)
                            {
                                this._animal = farmAnimal;
                                break;
                            }
                            else
                            {
                                this._tempAnimal = farmAnimal;
                                Microsoft.Xna.Framework.Audio.Cue hurtSound;
                                if (!DataLoader.ModConfig.Softmode)
                                {
                                    if (farmAnimal.sound.Value != null)
                                    {
                                        hurtSound = Game1.soundBank.GetCue(farmAnimal.sound.Value);
                                        hurtSound.SetVariable("Pitch", 1800);
                                        hurtSound.Play();
                                    }
                                }
                                else
                                {
                                    hurtSound = Game1.soundBank.GetCue("toolCharge");
                                    hurtSound.SetVariable("Pitch", 5000f);
                                    hurtSound.Play();
                                }

                                break;
                            }
                        }
                    }
                }
                else if (location is AnimalHouse)
                {
                    foreach (FarmAnimal farmAnimal in (location as AnimalHouse).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            if (farmAnimal == this._tempAnimal)
                            {
                                this._animal = farmAnimal;
                                break;
                            }
                            else
                            {
                                this._tempAnimal = farmAnimal;

                                Microsoft.Xna.Framework.Audio.Cue hurtSound;
                                if (!DataLoader.ModConfig.Softmode)
                                {
                                    if (farmAnimal.sound.Value != null)
                                    {
                                        hurtSound = Game1.soundBank.GetCue(farmAnimal.sound.Value);
                                        hurtSound.SetVariable("Pitch", 1800);
                                        hurtSound.Play();
                                    }
                                }
                                else
                                {
                                    hurtSound = Game1.soundBank.GetCue("toolCharge");
                                    hurtSound.SetVariable("Pitch", 5000f);
                                    hurtSound.Play();
                                }


                                break;
                            }
                        }
                    }
                }
            }

            this.Update(who.facingDirection, 0, who);
            if (this._tempAnimal != null && this._tempAnimal.age.Value < (int)this._tempAnimal.ageWhenMature.Value)
            {
                string dialogue = DataLoader.i18n.Get("Tool.MeatCleaver.TooYoung" + _sufix, new { animalName = this._tempAnimal.displayName });
                DelayedAction.showDialogueAfterDelay(dialogue, 150);
                this._tempAnimal = null;
            }
            who.EndUsingTool();
            return(true);
        }
        public override void DoFunction(GameLocation location, int x, int y, int power, StardewValley.Farmer who)
        {
            base.DoFunction(location, x, y, power, who);
            who.Stamina -= ((float)4f - (float)who.FarmingLevel * 0.2f);
            if (this._animal != null && this._animal.type.Value == "Dinosaur" && DataLoader.ModConfig.DisableMeatFromDinosaur)
            {
                return;
            }

            if (this._animal != null && this._animal.age.Value >= (int)this._animal.ageWhenMature.Value)
            {
                (this._animal.home.indoors.Value as AnimalHouse)?.animalsThatLiveHere.Remove(this._animal.myID.Value);
                this._animal.health.Value = -1;
                int numClouds   = this._animal.frontBackSourceRect.Width / 2;
                int cloudSprite = !DataLoader.ModConfig.Softmode ? 5 : 10;
                for (int i = 0; i < numClouds; i++)
                {
                    int   nonRedness = Game1.random.Next(0, 80);
                    Color cloudColor = new Color(255, 255 - nonRedness, 255 - nonRedness);;

                    Game1.currentLocation.temporarySprites.Add
                    (
                        new TemporaryAnimatedSprite
                        (
                            cloudSprite
                            , this._animal.position + new Vector2(Game1.random.Next(-Game1.tileSize / 2, this._animal.frontBackSourceRect.Width * 3)
                                                                  , Game1.random.Next(-Game1.tileSize / 2, this._animal.frontBackSourceRect.Height * 3))
                            , cloudColor
                            , 8
                            , false,
                            Game1.random.NextDouble() < .5 ? 50 : Game1.random.Next(30, 200), 0, Game1.tileSize
                            , -1
                            , Game1.tileSize, Game1.random.NextDouble() < .5 ? 0 : Game1.random.Next(0, 600)
                        )
                    {
                        scale  = Game1.random.Next(2, 5) * .25f,
                        alpha  = Game1.random.Next(2, 5) * .25f,
                        motion = new Vector2(0, (float)-Game1.random.NextDouble())
                    }
                    );
                }
                Color animalColor;
                float alfaFade;
                if (!DataLoader.ModConfig.Softmode)
                {
                    animalColor = Color.LightPink;
                    alfaFade    = .025f;
                }
                else
                {
                    animalColor = Color.White;
                    alfaFade    = .050f;
                }
                Game1.currentLocation.temporarySprites.Add
                (
                    new TemporaryAnimatedSprite
                    (
                        this._animal.Sprite.textureName.Value
                        , this._animal.Sprite.SourceRect
                        , this._animal.position
                        , this._animal.FacingDirection == Game1.left
                        , alfaFade
                        , animalColor
                    )
                {
                    scale = 4f
                }
                );
                if (!DataLoader.ModConfig.Softmode)
                {
                    Game1.playSound("killAnimal");
                }
                else
                {
                    Microsoft.Xna.Framework.Audio.Cue warptSound = Game1.soundBank.GetCue("wand");
                    warptSound.SetVariable("Pitch", 1800);
                    warptSound.Play();
                }

                MeatController.ThrowItem(MeatController.CreateMeat(this._animal), this._animal);
                who.gainExperience(0, 5);
                this._animal     = (FarmAnimal)null;
                this._tempAnimal = (FarmAnimal)null;
            }
        }
Exemple #28
0
 public static bool IsReadyForTreat(FarmAnimal farmAnimal)
 {
     return(DaysUntilNextTreat(farmAnimal) <= 0);
 }
Exemple #29
0
 public static TreatItem GetTreatItem(FarmAnimal farmAnimal)
 {
     return(DataLoader.AnimalData.GetAnimalItem(farmAnimal) as TreatItem);
 }
Exemple #30
0
 public static void FeedAnimalTreat(FarmAnimal farmAnimal, Object treat)
 {
     FeedAnimalTreat(farmAnimal.myID.Value, treat);
 }