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)
            {
                this._animal.doEmote(20, true);

                if (!DataLoader.ModConfig.DisableFriendshipInscreseWithTreats)
                {
                    double professionAjust = 1.0;
                    if (!_animal.isCoopDweller() && who.professions.Contains(3) || _animal.isCoopDweller() && who.professions.Contains(2))
                    {
                        professionAjust += DataLoader.ModConfig.PercentualAjustOnFriendshipInscreaseFromProfessions;
                    }
                    this._animal.friendshipTowardFarmer.Value = Math.Min(1000, this._animal.friendshipTowardFarmer.Value + (int)Math.Ceiling(professionAjust * this.attachments[0].Price * (1.0 + this.attachments[0].Quality * 0.25) / (this._animal.price.Value / 1000.0)));
                }
                if (!DataLoader.ModConfig.DisableMoodInscreseWithTreats)
                {
                    this._animal.happiness.Value = byte.MaxValue;
                }

                if (DataLoader.ModConfig.EnableTreatsCountAsAnimalFeed)
                {
                    this._animal.fullness.Value = byte.MaxValue;
                }

                TreatsController.FeedAnimalTreat(this._animal, this.attachments[0]);

                if (this.attachments[0].Category == StardewValley.Object.MilkCategory)
                {
                    this._animal.age.Value = Math.Min(this._animal.ageWhenMature.Value - 1, this._animal.age.Value + 1);
                }

                --this.attachments[0].Stack;
                if (this.attachments[0].Stack <= 0)
                {
                    Game1.showGlobalMessage(DataLoader.i18n.Get("Tool.FeedingBasket.ItemConsumed", new { itemName = this.attachments[0].DisplayName }));
                    this.attachments[0] = (StardewValley.Object)null;
                }
            }
            else if (this._pet != null)
            {
                this._pet.doEmote(20, true);

                if (!DataLoader.ModConfig.DisableFriendshipInscreseWithTreats)
                {
                    this._pet.friendshipTowardFarmer = Math.Min(Pet.maxFriendship, this._pet.friendshipTowardFarmer + 6);
                }
                TreatsController.FeedPetTreat(this.attachments[0]);

                --this.attachments[0].Stack;
                if (this.attachments[0].Stack <= 0)
                {
                    Game1.showGlobalMessage(DataLoader.i18n.Get("Tool.FeedingBasket.ItemConsumed", new { itemName = this.attachments[0].DisplayName }));
                    this.attachments[0] = (StardewValley.Object)null;
                }
            }
            this._animal = null;
            this._pet    = 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();
        }
        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);

            // Added this because for some wierd reason the current value appears subtracted by 5 the first time the tool is used.
            this.CurrentParentTileIndex = InitialParentTileIndex;

            if (Context.IsMainPlayer && !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.attachments[0] == null)
                {
                    Game1.showRedMessage(DataLoader.i18n.Get("Tool.FeedingBasket.Empty"));
                    this._animal = null;
                }
                else if (!TreatsController.CanReceiveTreat(this._animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.NotLikeTreat", new { itemName = this.attachments[0].DisplayName });
                }
                else if (!TreatsController.IsLikedTreat(this._animal, this.attachments[0].ParentSheetIndex) && !TreatsController.IsLikedTreat(this._animal, this.attachments[0].Category))
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.NotLikeTreat", new  { itemName = this.attachments[0].DisplayName });
                }
                else if (this.attachments[0].Category == StardewValley.Object.MilkCategory && !this._animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.OnlyBabiesCanEatMilk");
                }
                else if (!TreatsController.IsReadyForTreat(this._animal))
                {
                    if (TreatsController.GetTreatItem(this._animal)?.MinimumDaysBetweenTreats == 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.AlreadyAteTreatToday", new { animalName = this._pet.displayName });
                    }
                    else
                    {
                        int daysUntilNextTreat = TreatsController.DaysUntilNextTreat(this._animal);
                        if (daysUntilNextTreat > 1)
                        {
                            dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatInDays", new { animalName = this._animal.displayName, numberOfDays = daysUntilNextTreat });
                        }
                        else if (daysUntilNextTreat == 1)
                        {
                            dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatTomorrow", new { animalName = this._animal.displayName });
                        }
                    }
                }
                else
                {
                    this._animal.pauseTimer = 1000;
                }


                if (dialogue.Length > 0)
                {
                    DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    this._animal = null;
                }
            }
            if (this._pet != null)
            {
                string dialogue = "";
                if (this.attachments[0] == null)
                {
                    Game1.showRedMessage(DataLoader.i18n.Get("Tool.FeedingBasket.Empty"));
                    this._pet = null;
                }
                else if (!TreatsController.IsLikedTreatPet(this.attachments[0].ParentSheetIndex) && !TreatsController.IsLikedTreatPet(this.attachments[0].Category))
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.NotLikeTreat", new { itemName = this.attachments[0].DisplayName });
                }
                else if (!TreatsController.IsReadyForTreatPet())
                {
                    int daysUntilNextTreat = TreatsController.DaysUntilNextTreatPet();

                    if (DataLoader.AnimalData.Pet.MinimumDaysBetweenTreats == 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.AlreadyAteTreatToday", new { animalName = this._pet.displayName });
                    }
                    else if (daysUntilNextTreat > 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatInDays", new { animalName = this._pet.displayName, numberOfDays = daysUntilNextTreat });
                    }
                    else if (daysUntilNextTreat == 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatTomorrow", new { animalName = this._pet.displayName });
                    }
                }
                else
                {
                    _pet.Halt();
                    _pet.CurrentBehavior = 0;
                    _pet.initiateCurrentBehavior();
                    _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, 900, false, false, new AnimatedSprite.endOfAnimationBehavior(StardewValley.Farmer.useTool), true)
                    });
                    break;

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

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

                case 3:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(58, 900, 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;

            if (this._animal != null || this._pet != null)
            {
                Rectangle boundingBox;
                if (this._animal != null)
                {
                    boundingBox = this._animal.GetBoundingBox();
                }
                else
                {
                    boundingBox = this._pet.GetBoundingBox();
                }

                double numX = boundingBox.Center.X;
                double numY = boundingBox.Center.Y;

                Vector2 vectorBasket = new Vector2((float)numX - 32, (float)numY);
                Vector2 vectorFood   = new Vector2((float)numX - 24, (float)numY - 10);
                var     foodScale    = Game1.pixelZoom * 0.75f;

                Multiplayer multiplayer = DataLoader.Helper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();

                TemporaryAnimatedSprite basketSprite = new TemporaryAnimatedSprite(Game1.toolSpriteSheetName,
                                                                                   Game1.getSourceRectForStandardTileSheet(Game1.toolSpriteSheet, this.CurrentParentTileIndex, 16, 16),
                                                                                   750.0f, 1, 1, vectorBasket, false, false, ((float)boundingBox.Bottom + 0.1f) / 10000f, 0.0f,
                                                                                   Color.White, Game1.pixelZoom, 0.0f, 0.0f, 0.0f)
                {
                    delayBeforeAnimationStart = 100
                };
                multiplayer.broadcastSprites(who.currentLocation, new TemporaryAnimatedSprite[1] {
                    basketSprite
                });
                TemporaryAnimatedSprite foodSprite = new TemporaryAnimatedSprite(Game1.objectSpriteSheetName,
                                                                                 Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, this.attachments[0].ParentSheetIndex,
                                                                                                                         16, 16), 500.0f, 1, 1, vectorFood, false, false, ((float)boundingBox.Bottom + 0.2f) / 10000f, 0.0f,
                                                                                 Color.White, foodScale, 0.0f, 0.0f, 0.0f)
                {
                    delayBeforeAnimationStart = 100
                };
                multiplayer.broadcastSprites(who.currentLocation, new TemporaryAnimatedSprite[1] {
                    foodSprite
                });

                for (int index = 0; index < 8; ++index)
                {
                    Rectangle standardTileSheet = Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet,
                                                                                          this.attachments[0].ParentSheetIndex, 16, 16);
                    standardTileSheet.X += 8;
                    standardTileSheet.Y += 8;

                    standardTileSheet.Width  = Game1.pixelZoom;
                    standardTileSheet.Height = Game1.pixelZoom;
                    TemporaryAnimatedSprite temporaryAnimatedSprite2 =
                        new TemporaryAnimatedSprite(Game1.objectSpriteSheetName, standardTileSheet, 400f, 1, 0,
                                                    vectorFood + new Vector2(12, 12), false, false,
                                                    ((float)boundingBox.Bottom + 0.2f) / 10000f, 0.0f, Color.White, (float)foodScale, 0.0f,
                                                    0.0f, 0.0f, false)
                    {
                        motion       = new Vector2((float)Game1.random.Next(-30, 31) / 10f, (float)Game1.random.Next(-6, -3)),
                        acceleration = new Vector2(0.0f, 0.5f),
                        delayBeforeAnimationStart = 600
                    };
                    multiplayer.broadcastSprites(who.currentLocation, new TemporaryAnimatedSprite[1] {
                        temporaryAnimatedSprite2
                    });
                }

                if (this._animal != null)
                {
                    Game1.delayedActions.Add(new DelayedAction(300, new DelayedAction.delayedBehavior(() => {
                        AnimalHusbandryModEntery.ModHelper.Reflection.GetField <NetBool>(this._animal, "isEating").GetValue().Value = true;
                        this._animal.Sprite.loop = false;
                    })));
                }
                else if (this._pet != null)
                {
                    _pet.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(18, 300),
                        new FarmerSprite.AnimationFrame(17, 100),
                        new FarmerSprite.AnimationFrame(16, 100),
                        new FarmerSprite.AnimationFrame(0, 100),
                        new FarmerSprite.AnimationFrame(16, 100),
                        new FarmerSprite.AnimationFrame(17, 100),
                        new FarmerSprite.AnimationFrame(18, 300)
                    });
                    _pet.Sprite.loop = false;
                }
                DelayedAction.playSoundAfterDelay("eat", 600);
            }

            return(true);
        }
Beispiel #3
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 (Context.IsMainPlayer && !DataLoader.ModConfig.DisableAnimalContest)
            {
                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;
                        }
                    }
                }
            }

            string dialogue = "";

            if (this._animal != null)
            {
                if (this._animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.CantBeBaby");
                }
                else if (AnimalContestController.HasParticipated(this._animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.HasAlreadyParticipatedContest", new { animalName = this._animal.displayName });
                }
                else if (AnimalContestController.IsParticipant(this._animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.IsAlreadyParticipant", new { animalName = this._animal.displayName });
                }
                else if (AnimalContestController.GetNextContestParticipantId() is long nextContestParticipantId)
                {
                    string participantName = nextContestParticipantId != AnimalData.PetId
                        ? AnimalContestController.GetAnimal(nextContestParticipantId).displayName
                        : Game1.player.getPetName();
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.AnotherParticipantAlready", new { participantName });
                }
                else
                {
                    this._animal.doEmote(8, true);
                    this._animal.makeSound();
                    this._animal.pauseTimer = 200;
                }
            }
            if (this._pet != null)
            {
                if (AnimalContestController.IsParticipantPet())
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.IsAlreadyParticipant",
                                                   new { animalName = this._pet.displayName });
                }
                else if (AnimalContestController.GetNextContestParticipantId() is long nextContestParticipantId)
                {
                    string participantName = nextContestParticipantId != AnimalData.PetId
                        ? AnimalContestController.GetAnimal(nextContestParticipantId).displayName
                        : Game1.player.getPetName();
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.AnotherParticipantAlready", new { participantName });
                }
                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;
                this._animal = 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 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 (Context.IsMainPlayer && !DataLoader.ModConfig.DisablePregnancy)
            {
                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;
                        }
                    }
                }
            }

            if (this._animal != null)
            {
                string dialogue = "";
                if (this.attachments[0] == null)
                {
                    Game1.showRedMessage(DataLoader.i18n.Get("Tool.InseminationSyringe.Empty"));
                    this._animal = null;
                }
                else if (AnimalExtension.GetAnimalFromType(this._animal.type.Value) == null)
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = this._animal.displayName });
                }
                else if (IsEggAnimal(this._animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.EggAnimal", new { animalName = this._animal.displayName });
                }
                else if (!((ImpregnatableAnimalItem)DataLoader.AnimalData.GetAnimalItem(this._animal)).MinimumDaysUtillBirth.HasValue)
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = this._animal.displayName });
                }
                else if (this._animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.TooYoung", new { animalName = this._animal.displayName });
                }
                else if (PregnancyController.IsAnimalPregnant(this._animal.myID.Value))
                {
                    int daysUtillBirth = PregnancyController.GetPregnancyItem(this._animal.myID.Value).DaysUntilBirth;
                    if (daysUtillBirth > 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.AlreadyPregnant", new { animalName = this._animal.displayName, numberOfDays = daysUtillBirth });
                    }
                    else
                    {
                        dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.ReadyForBirth", new { animalName = this._animal.displayName });
                    }
                }
                else if (!CheckCorrectProduct(this._animal, this.attachments[0]))
                {
                    var    data        = DataLoader.Helper.Content.Load <Dictionary <int, string> >(@"Data\ObjectInformation.xnb", ContentSource.GameContent);
                    string produceName = data[this._animal.defaultProduceIndex.Value].Split('/')[4];
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CorrectItem", new { itemName = produceName });
                }
                else if (PregnancyController.CheckBuildingLimit(this._animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.BuildingLimit", new { buildingType = this._animal.displayHouse });
                }
                else
                {
                    this._animal.doEmote(16, true);
                    if (this._animal.sound.Value != null)
                    {
                        ICue animalSound = Game1.soundBank.GetCue(this._animal.sound.Value);
                        animalSound.Play();
                    }
                    DelayedAction.playSoundAfterDelay("fishingRodBend", 300);
                    DelayedAction.playSoundAfterDelay("fishingRodBend", 1200);
                    this._animal.pauseTimer = 1500;
                }
                if (dialogue.Length > 0)
                {
                    DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    this._animal = null;
                }
            }



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

            if (this._animal != null)
            {
                who.FarmerSprite.animateOnce(287 + who.FacingDirection, 50f, 4);
            }
            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 static bool beginUsing(MilkPail __instance, GameLocation location, int x, int y, StardewValley.Farmer who, ref bool __result)
        {
            if (!IsFeedingBasket(__instance))
            {
                return(true);
            }

            string feedingBasketId = __instance.modData[FeedingBasketKey];

            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);

            // Added this because for some wierd reason the current value appears subtracted by 5 the first time the tool is used.
            __instance.CurrentParentTileIndex = InitialParentTileIndex;

            if (!DataLoader.ModConfig.DisableTreats)
            {
                if (location is Farm farm)
                {
                    foreach (FarmAnimal farmAnimal in farm.animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[feedingBasketId] = farmAnimal;
                            break;
                        }
                    }
                    if (!Animals.ContainsKey(feedingBasketId) || Animals[feedingBasketId] == null)
                    {
                        foreach (Pet localPet in farm.characters.Where(i => i is Pet))
                        {
                            if (localPet.GetBoundingBox().Intersects(rectangle))
                            {
                                Pets[feedingBasketId] = localPet;
                                break;
                            }
                        }
                    }
                }
                else if (location is AnimalHouse animalHouse)
                {
                    foreach (FarmAnimal farmAnimal in animalHouse.animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[feedingBasketId] = farmAnimal;
                            break;
                        }
                    }
                }
                else if (location is FarmHouse)
                {
                    foreach (Pet localPet in location.characters.Where(i => i is Pet))
                    {
                        if (localPet.GetBoundingBox().Intersects(rectangle))
                        {
                            Pets[feedingBasketId] = localPet;
                            break;
                        }
                    }
                }
            }

            Animals.TryGetValue(feedingBasketId, out FarmAnimal animal);
            if (animal != null)
            {
                string dialogue = "";
                if (__instance.attachments[0] == null)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        Game1.showRedMessage(DataLoader.i18n.Get("Tool.FeedingBasket.Empty"));
                    }
                    Animals[feedingBasketId] = animal = null;
                }
                else if (!TreatsController.CanReceiveTreat(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.NotLikeTreat", new { itemName = __instance.attachments[0].DisplayName });
                }
                else if (!TreatsController.IsLikedTreat(animal, __instance.attachments[0]))
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.NotLikeTreat", new { itemName = __instance.attachments[0].DisplayName });
                }
                else if (__instance.attachments[0].Category == SObject.MilkCategory && !animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.OnlyBabiesCanEatMilk");
                }
                else if (!TreatsController.IsReadyForTreat(animal))
                {
                    if (TreatsController.GetTreatItem(animal)?.MinimumDaysBetweenTreats == 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.AlreadyAteTreatToday", new { animalName = animal.displayName });
                    }
                    else
                    {
                        int daysUntilNextTreat = TreatsController.DaysUntilNextTreat(animal);
                        if (daysUntilNextTreat > 1)
                        {
                            dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatInDays", new { animalName = animal.displayName, numberOfDays = daysUntilNextTreat });
                        }
                        else if (daysUntilNextTreat == 1)
                        {
                            dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatTomorrow", new { animalName = animal.displayName });
                        }
                    }
                }
                else
                {
                    animal.pauseTimer = 1000;
                }


                if (dialogue.Length > 0)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    }
                    Animals[feedingBasketId] = animal = null;
                }
            }
            Pets.TryGetValue(feedingBasketId, out Pet pet);
            if (pet != null)
            {
                string dialogue = "";
                if (__instance.attachments[0] == null)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        Game1.showRedMessage(DataLoader.i18n.Get("Tool.FeedingBasket.Empty"));
                    }
                    Pets[feedingBasketId] = pet = null;
                }
                else if (!TreatsController.IsLikedTreat(pet, __instance.attachments[0]))
                {
                    dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.NotLikeTreat", new { itemName = __instance.attachments[0].DisplayName });
                }
                else if (!TreatsController.IsReadyForTreat(pet))
                {
                    int daysUntilNextTreat = TreatsController.DaysUntilNextTreat(pet);

                    if (DataLoader.AnimalData.Pet.MinimumDaysBetweenTreats == 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.AlreadyAteTreatToday", new { animalName = pet.displayName });
                    }
                    else if (daysUntilNextTreat > 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatInDays", new { animalName = pet.displayName, numberOfDays = daysUntilNextTreat });
                    }
                    else if (daysUntilNextTreat == 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.FeedingBasket.WantsTreatTomorrow", new { animalName = pet.displayName });
                    }
                }
                else
                {
                    pet.Halt();
                    pet.FacingDirection = 2;
                    pet.CurrentBehavior = 2;
                    DataLoader.Helper.Reflection.GetField <int>(pet, "_currentBehavior").SetValue(2);
                    pet.Halt();
                    pet.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(18, 200)
                    });
                    pet.Sprite.loop = true;
                }

                if (dialogue.Length > 0)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    }
                    Pets[feedingBasketId] = pet = null;
                }
            }

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

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

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

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

                case 3:
                    who.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[1] {
                        new FarmerSprite.AnimationFrame(58, 900, 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;

            if (animal != null || pet != null)
            {
                Rectangle boundingBox;
                boundingBox = animal != null?animal.GetBoundingBox() : pet.GetBoundingBox();

                double numX = boundingBox.Center.X;
                double numY = boundingBox.Center.Y;

                Vector2 vectorBasket = new Vector2((float)numX - 32, (float)numY);
                Vector2 vectorFood   = new Vector2((float)numX - 24, (float)numY - 10);
                var     foodScale    = Game1.pixelZoom * 0.75f;

                TemporaryAnimatedSprite basketSprite = new TemporaryAnimatedSprite(Game1.toolSpriteSheetName,
                                                                                   Game1.getSourceRectForStandardTileSheet(Game1.toolSpriteSheet, __instance.CurrentParentTileIndex, 16, 16),
                                                                                   750.0f, 1, 1, vectorBasket, false, false, ((float)boundingBox.Bottom + 0.1f) / 10000f, 0.0f,
                                                                                   Color.White, Game1.pixelZoom, 0.0f, 0.0f, 0.0f)
                {
                    delayBeforeAnimationStart = 100
                };
                location.temporarySprites.Add(basketSprite);
                TemporaryAnimatedSprite foodSprite = new TemporaryAnimatedSprite(Game1.objectSpriteSheetName,
                                                                                 Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, __instance.attachments[0].ParentSheetIndex,
                                                                                                                         16, 16), 500.0f, 1, 1, vectorFood, false, false, ((float)boundingBox.Bottom + 0.2f) / 10000f, 0.0f,
                                                                                 Color.White, foodScale, 0.0f, 0.0f, 0.0f)
                {
                    delayBeforeAnimationStart = 100
                };
                location.temporarySprites.Add(foodSprite);

                for (int index = 0; index < 8; ++index)
                {
                    Rectangle standardTileSheet = Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet,
                                                                                          __instance.attachments[0].ParentSheetIndex, 16, 16);
                    standardTileSheet.X += 8;
                    standardTileSheet.Y += 8;

                    standardTileSheet.Width  = Game1.pixelZoom;
                    standardTileSheet.Height = Game1.pixelZoom;
                    TemporaryAnimatedSprite temporaryAnimatedSprite2 =
                        new TemporaryAnimatedSprite(Game1.objectSpriteSheetName, standardTileSheet, 400f, 1, 0,
                                                    vectorFood + new Vector2(12, 12), false, false,
                                                    ((float)boundingBox.Bottom + 0.2f) / 10000f, 0.0f, Color.White, (float)foodScale, 0.0f,
                                                    0.0f, 0.0f, false)
                    {
                        motion       = new Vector2((float)Game1.random.Next(-30, 31) / 10f, (float)Game1.random.Next(-6, -3)),
                        acceleration = new Vector2(0.0f, 0.5f),
                        delayBeforeAnimationStart = 600
                    };
                    location.temporarySprites.Add(temporaryAnimatedSprite2);
                }

                if (animal != null)
                {
                    FarmAnimal tempAnimal = animal;
                    Game1.delayedActions.Add(new DelayedAction(300, new DelayedAction.delayedBehavior(() => {
                        if (tempAnimal.buildingTypeILiveIn.Contains("Barn"))
                        {
                            tempAnimal.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                            {
                                new FarmerSprite.AnimationFrame(16, 100),
                                new FarmerSprite.AnimationFrame(17, 100),
                                new FarmerSprite.AnimationFrame(18, 100),
                                new FarmerSprite.AnimationFrame(19, 100),
                                new FarmerSprite.AnimationFrame(19, 100, secondaryArm: false, flip: false, (f) =>
                                {
                                    tempAnimal.doEmote(20, true);
                                    tempAnimal.Sprite.CurrentAnimation = null;
                                    tempAnimal.Sprite.loop             = true;
                                    tempAnimal.Sprite.currentFrame     = 0;
                                    tempAnimal.faceDirection(2);
                                })
                            });
                        }
                        else
                        {
                            tempAnimal.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
                            {
                                new FarmerSprite.AnimationFrame(24, 100),
                                new FarmerSprite.AnimationFrame(25, 100),
                                new FarmerSprite.AnimationFrame(26, 100),
                                new FarmerSprite.AnimationFrame(27, 100),
                                new FarmerSprite.AnimationFrame(27, 100, secondaryArm: false, flip: false, (f) =>
                                {
                                    tempAnimal.doEmote(20, true);
                                    tempAnimal.Sprite.CurrentAnimation = null;
                                    tempAnimal.Sprite.loop             = true;
                                    tempAnimal.Sprite.currentFrame     = 0;
                                    tempAnimal.faceDirection(2);
                                })
                            });
                        }
                        tempAnimal.Sprite.loop = false;
                    })));
                }
                else if (pet != null)
                {
                    pet.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>()
                    {
                        new FarmerSprite.AnimationFrame(18, 300),
                        new FarmerSprite.AnimationFrame(17, 100),
                        new FarmerSprite.AnimationFrame(16, 100),
                        new FarmerSprite.AnimationFrame(0, 100),
                        new FarmerSprite.AnimationFrame(16, 100),
                        new FarmerSprite.AnimationFrame(17, 100, secondaryArm: false, flip: false, (f) => pet.doEmote(20, true), true),
                        new FarmerSprite.AnimationFrame(18, 300, false, false, pet.hold, true)
                    });
                    pet.Sprite.loop = false;
                }
                if (who != null && Game1.player.Equals(who))
                {
                    DelayedAction.playSoundAfterDelay("eat", 600, location);
                }
            }
            __result = true;
            return(false);
        }
        public static bool DoFunction(MilkPail __instance, GameLocation location, int x, int y, int power, StardewValley.Farmer who)
        {
            if (!IsFeedingBasket(__instance))
            {
                return(true);
            }

            string feedingBasketId = __instance.modData[FeedingBasketKey];

            BaseToolDoFunction(__instance, location, x, y, power, who);
            __instance.CurrentParentTileIndex    = InitialParentTileIndex;
            __instance.indexOfMenuItemView.Value = IndexOfMenuItemView;

            Animals.TryGetValue(feedingBasketId, out FarmAnimal animal);
            if (animal != null)
            {
                if (!DataLoader.ModConfig.DisableFriendshipInscreseWithTreats)
                {
                    double professionAjust = 1.0;
                    if (!animal.isCoopDweller() && who.professions.Contains(3) || animal.isCoopDweller() && who.professions.Contains(2))
                    {
                        professionAjust += DataLoader.ModConfig.PercentualAjustOnFriendshipInscreaseFromProfessions;
                    }
                    animal.friendshipTowardFarmer.Value = Math.Min(1000, animal.friendshipTowardFarmer.Value + (int)Math.Ceiling(professionAjust * __instance.attachments[0].Price * (1.0 + __instance.attachments[0].Quality * 0.25) / (animal.price.Value / 1000.0)));
                }
                if (!DataLoader.ModConfig.DisableMoodInscreseWithTreats)
                {
                    animal.happiness.Value = byte.MaxValue;
                }

                if (DataLoader.ModConfig.EnableTreatsCountAsAnimalFeed)
                {
                    animal.fullness.Value = byte.MaxValue;
                }

                TreatsController.FeedAnimalTreat(animal, __instance.attachments[0]);

                if (__instance.attachments[0].Category == SObject.MilkCategory)
                {
                    animal.age.Value = Math.Min(animal.ageWhenMature.Value - 1, animal.age.Value + 1);
                }

                --__instance.attachments[0].Stack;
                if (__instance.attachments[0].Stack <= 0)
                {
                    Game1.showGlobalMessage(DataLoader.i18n.Get("Tool.FeedingBasket.ItemConsumed", new { itemName = __instance.attachments[0].DisplayName }));
                    __instance.attachments[0] = null;
                }
            }
            if (Pets.TryGetValue(feedingBasketId, out Pet pet) && pet != null)
            {
                if (!DataLoader.ModConfig.DisableFriendshipInscreseWithTreats)
                {
                    pet.friendshipTowardFarmer.Value = Math.Min(Pet.maxFriendship, pet.friendshipTowardFarmer.Value + 6);
                }
                TreatsController.FeedAnimalTreat(pet, __instance.attachments[0]);

                --__instance.attachments[0].Stack;
                if (__instance.attachments[0].Stack <= 0)
                {
                    Game1.showGlobalMessage(DataLoader.i18n.Get("Tool.FeedingBasket.ItemConsumed", new { itemName = __instance.attachments[0].DisplayName }));
                    __instance.attachments[0] = null;
                }
            }
            Animals[feedingBasketId] = (FarmAnimal)null;
            Pets[feedingBasketId]    = (Pet)null;

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

            DataLoader.Helper.Reflection.GetMethod(__instance, "finish").Invoke();

            return(false);
        }
        public static bool beginUsing(MilkPail __instance, GameLocation location, int x, int y, StardewValley.Farmer who, ref bool __result)
        {
            if (!IsParticipantRibbon(__instance))
            {
                return(true);
            }

            string participantRibbonId = __instance.modData[ParticipantRibbonKey];

            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.DisableAnimalContest)
            {
                if (location is Farm farm)
                {
                    foreach (FarmAnimal farmAnimal in farm.animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[participantRibbonId] = farmAnimal;
                            break;
                        }
                    }
                    if (!Animals.ContainsKey(participantRibbonId) || Animals[participantRibbonId] == null)
                    {
                        foreach (Pet localPet in farm.characters.Where(i => i is Pet))
                        {
                            if (localPet.GetBoundingBox().Intersects(rectangle))
                            {
                                Pets[participantRibbonId] = localPet;
                                break;
                            }
                        }
                    }
                }
                else if (location is AnimalHouse animalHouse)
                {
                    foreach (FarmAnimal farmAnimal in animalHouse.animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[participantRibbonId] = farmAnimal;
                            break;
                        }
                    }
                }
                else if (location is FarmHouse)
                {
                    foreach (Pet localPet in location.characters.Where(i => i is Pet))
                    {
                        if (localPet.GetBoundingBox().Intersects(rectangle))
                        {
                            Pets[participantRibbonId] = localPet;
                            break;
                        }
                    }
                }
            }

            string dialogue = "";

            Animals.TryGetValue(participantRibbonId, out FarmAnimal animal);
            if (animal != null)
            {
                if (animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.CantBeBaby");
                }
                else if (AnimalContestController.HasParticipated(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.HasAlreadyParticipatedContest", new { animalName = animal.displayName });
                }
                else if (AnimalContestController.IsNextParticipant(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.IsAlreadyParticipant", new { animalName = animal.displayName });
                }
                else if (AnimalContestController.GetNextContestParticipant() is Character participant)
                {
                    string participantName = participant.displayName;
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.AnotherParticipantAlready", new { participantName });
                }
                else
                {
                    animal.doEmote(8, true);
                    if (who != null && Game1.player.Equals(who))
                    {
                        animal.makeSound();
                    }
                    animal.pauseTimer = 200;
                }
            }
            Pets.TryGetValue(participantRibbonId, out Pet pet);
            if (pet != null)
            {
                if (AnimalContestController.IsNextParticipant(pet))
                {
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.IsAlreadyParticipant",
                                                   new { animalName = pet.displayName });
                }
                else if (AnimalContestController.GetNextContestParticipant() is Character character)
                {
                    string participantName = character.displayName;
                    dialogue = DataLoader.i18n.Get("Tool.ParticipantRibbon.AnotherParticipantAlready", new { participantName });
                }
                else
                {
                    pet.doEmote(8, true);
                    if (who != null && Game1.player.Equals(who))
                    {
                        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)
            {
                if (who != null && Game1.player.Equals(who))
                {
                    DelayedAction.showDialogueAfterDelay(dialogue, 150);
                }

                Pets[participantRibbonId]    = pet = null;
                Animals[participantRibbonId] = animal = null;
            }

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

            if (animal != null || 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;

            __result = true;
            return(false);
        }
Beispiel #8
0
        private static void fixCommand(Event @event, string[] array)
        {
            // We only want to do things the game would have done to farmers
            // So stuff affecting the NPCs or anything else was removed

            // More stuff from Event
            Dictionary <string, Vector3> actorPositionsAfterMove = (Dictionary <string, Vector3>)Util.GetInstanceField(typeof(Event), @event, "actorPositionsAfterMove");

            if (array[0].Equals("showFrame"))
            {
                if (array.Count <string>() > 2 && !array[2].Equals("flip") && !array[1].Contains("farmer"))
                {
                }
                else
                {
                    SFarmer farmer = getFarmerFromFarmerNumberString(array[1]);
                    //if (farmer == Game1.player) return;
                    if (array.Count <string>() == 2)
                    {
                        farmer = Game1.player;
                    }
                    if (farmer != null)
                    {
                        if (array.Count <string>() > 2)
                        {
                            array[1] = array[2];
                        }
                        List <FarmerSprite.AnimationFrame> list = new List <FarmerSprite.AnimationFrame>();
                        list.Add(new FarmerSprite.AnimationFrame(Convert.ToInt32(array[1]), 100, false, array.Count <string>() > 2, null, false));
                        farmer.FarmerSprite.setCurrentAnimation(list.ToArray());
                        farmer.FarmerSprite.loopThisAnimation       = true;
                        farmer.FarmerSprite.PauseForSingleAnimation = true;
                        farmer.sprite.CurrentFrame = Convert.ToInt32(array[1]);
                    }
                }
            }
            else if (array[0].Equals("animate"))
            {
                int  milliseconds = Convert.ToInt32(array[4]);
                bool flip         = array[2].Equals("true");
                bool flag2        = array[3].Equals("true");
                List <FarmerSprite.AnimationFrame> list2 = new List <FarmerSprite.AnimationFrame>();
                for (int n = 5; n < array.Count <string>(); n++)
                {
                    list2.Add(new FarmerSprite.AnimationFrame(Convert.ToInt32(array[n]), milliseconds, false, flip, null, false));
                }
                if (array[1].Contains("farmer"))
                {
                    SFarmer farmerFromFarmerNumberString6 = getFarmerFromFarmerNumberString(array[1]);
                    //if (farmerFromFarmerNumberString6 == Game1.player) return;
                    if (farmerFromFarmerNumberString6 != null)
                    {
                        farmerFromFarmerNumberString6.FarmerSprite.setCurrentAnimation(list2.ToArray());
                        farmerFromFarmerNumberString6.FarmerSprite.loopThisAnimation       = flag2;
                        farmerFromFarmerNumberString6.FarmerSprite.PauseForSingleAnimation = true;
                    }
                }
                else
                {
                }
            }
            else if (array[0].Equals("stopAnimation"))
            {
                if (array[1].Contains("farmer"))
                {
                    SFarmer farmerFromFarmerNumberString7 = getFarmerFromFarmerNumberString(array[1]);
                    //if (farmerFromFarmerNumberString7 == Game1.player) return;
                    if (farmerFromFarmerNumberString7 != null)
                    {
                        farmerFromFarmerNumberString7.completelyStopAnimatingOrDoingAction();
                        farmerFromFarmerNumberString7.Halt();
                        farmerFromFarmerNumberString7.FarmerSprite.currentAnimation = null;
                        int num12 = farmerFromFarmerNumberString7.facingDirection;
                        switch (num12)
                        {
                        case 0:
                            farmerFromFarmerNumberString7.FarmerSprite.setCurrentSingleFrame(12, 32000, false, false);
                            break;

                        case 1:
                            farmerFromFarmerNumberString7.FarmerSprite.setCurrentSingleFrame(6, 32000, false, false);
                            break;

                        case 2:
                            farmerFromFarmerNumberString7.FarmerSprite.setCurrentSingleFrame(0, 32000, false, false);
                            break;

                        case 3:
                            farmerFromFarmerNumberString7.FarmerSprite.setCurrentSingleFrame(6, 32000, false, true);
                            break;
                        }
                    }
                }
                else
                {
                }
            }
            else if (array[0].Equals("positionOffset"))
            {
                if (array[1].Contains("farmer"))
                {
                    SFarmer farmerFromFarmerNumberString8 = getFarmerFromFarmerNumberString(array[1]);
                    //if (farmerFromFarmerNumberString8 == Game1.player) return;
                    if (farmerFromFarmerNumberString8 != null)
                    {
                        SFarmer expr_46E6_cp_0 = farmerFromFarmerNumberString8;
                        expr_46E6_cp_0.position.X = expr_46E6_cp_0.position.X + (float)Convert.ToInt32(array[2]);
                        SFarmer expr_4702_cp_0 = farmerFromFarmerNumberString8;
                        expr_4702_cp_0.position.Y = expr_4702_cp_0.position.Y + (float)Convert.ToInt32(array[3]);
                    }
                }
                else
                {
                }
            }
            else if (array[0].Equals("move"))
            {
                int num3 = 1;
                while (num3 < array.Count <string>() && array.Count <string>() - num3 >= 3)
                {
                    if (array[num3].Contains("farmer") && !actorPositionsAfterMove.ContainsKey(array[num3]))
                    {
                        SFarmer farmerFromFarmerNumberString2 = Utility.getFarmerFromFarmerNumberString(array[num3]);
                        //if (farmerFromFarmerNumberString2 == Game1.player) { num3 += 4; continue; }
                        if (farmerFromFarmerNumberString2 != null)
                        {
                            farmerFromFarmerNumberString2.canOnlyWalk = false;
                            farmerFromFarmerNumberString2.setRunning(false, true);
                            farmerFromFarmerNumberString2.canOnlyWalk = true;
                            farmerFromFarmerNumberString2.convertEventMotionCommandToMovement(new Vector2((float)Convert.ToInt32(array[num3 + 1]), (float)Convert.ToInt32(array[num3 + 2])));
                            actorPositionsAfterMove.Add(array[num3], @event.getPositionAfterMove(Game1.player, Convert.ToInt32(array[num3 + 1]), Convert.ToInt32(array[num3 + 2]), Convert.ToInt32(array[num3 + 3])));
                        }
                    }
                    else
                    {
                    }
                    num3 += 4;
                }
                if (array.Last <string>().Equals("true"))
                {
                }
                if (!array.Last <string>().Equals("false"))
                {
                }
                if (array.Count <string>() == 2 && actorPositionsAfterMove.Count == 0)
                {
                }
            }
            else if (array[0].Equals("emote"))
            {
                bool flag = array.Count <string>() > 3;
                if (array[1].Contains("farmer"))
                {
                    SFarmer farmerFromFarmerNumberString3 = getFarmerFromFarmerNumberString(array[1]);
                    //if (farmerFromFarmerNumberString3 == Game1.player) return;
                    if (farmerFromFarmerNumberString3 != null)
                    {
                        Game1.player.doEmote(Convert.ToInt32(array[2]), !flag);
                    }
                }
                else
                {
                }
            }
            else if (array[0].Equals("faceDirection"))
            {
                if (array[1].Contains("farmer"))
                {
                    SFarmer farmerFromFarmerNumberString4 = getFarmerFromFarmerNumberString(array[1]);
                    //if (farmerFromFarmerNumberString4 == Game1.player) return;
                    if (farmerFromFarmerNumberString4 != null)
                    {
                        farmerFromFarmerNumberString4.FarmerSprite.StopAnimation();
                        farmerFromFarmerNumberString4.completelyStopAnimatingOrDoingAction();
                        farmerFromFarmerNumberString4.faceDirection(Convert.ToInt32(array[2]));
                        farmerFromFarmerNumberString4.FarmerSprite.StopAnimation();
                    }
                }
                else if (array[1].Contains("spouse"))
                {
                }
                else
                {
                }
                if (array.Length == 3 && Game1.pauseTime <= 0f)
                {
                }
                if (array.Length > 3)
                {
                }
            }
            else if (array[0].Equals("warp"))
            {
                if (array[1].Contains("farmer"))
                {
                    SFarmer farmerFromFarmerNumberString5 = getFarmerFromFarmerNumberString(array[1]);
                    //if (farmerFromFarmerNumberString5 == Game1.player) return;
                    if (farmerFromFarmerNumberString5 != null)
                    {
                        farmerFromFarmerNumberString5.position.X = (float)(Convert.ToInt32(array[2]) * Game1.tileSize);
                        farmerFromFarmerNumberString5.position.Y = (float)(Convert.ToInt32(array[3]) * Game1.tileSize);
                        if (Game1.IsClient)
                        {
                            farmerFromFarmerNumberString5.remotePosition = new Vector2(farmerFromFarmerNumberString5.position.X, farmerFromFarmerNumberString5.position.Y);
                        }
                    }
                }
                else if (array[1].Contains("spouse"))
                {
                }
                else
                {
                }
                if (array.Count <string>() > 4)
                {
                }
            }
            if (array[0].Equals("proceedPosition"))
            {/*
              * try
              * {
              *     if (!this.getCharacterByName(array[1]).isMoving() || (this.npcControllers != null && this.npcControllers.Count<NPCController>() == 0))
              *     {
              *         this.getCharacterByName(array[1]).Halt();
              *         this.CurrentCommand++;
              *     }
              *     goto IL_4406;
              * }*/
             // TODO: Fix this^ later
            }
        }
Beispiel #9
0
        public virtual bool beginUsing(GameLocation location, int x, int y, Farmer who)
        {
            lastUser = who;
            if (!instantUse)
            {
                who.Halt();
                Update(who.FacingDirection, 0, who);
                if ((!(this is FishingRod) && (int)upgradeLevel <= 0 && !(this is MeleeWeapon)) || this is Pickaxe)
                {
                    who.EndUsingTool();
                    return(true);
                }
            }
            if (Name.Equals("Wand"))
            {
                if (((Wand)this).charged)
                {
                    Game1.toolAnimationDone(who);
                    who.canReleaseTool = false;
                    if (!who.IsLocalPlayer || !Game1.fadeToBlack)
                    {
                        who.CanMove   = true;
                        who.UsingTool = false;
                    }
                }
                else
                {
                    if (who.IsLocalPlayer)
                    {
                        Game1.drawObjectDialogue(Game1.parseText(Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3180")));
                    }
                    who.UsingTool      = false;
                    who.canReleaseTool = false;
                }
            }
            else if ((bool)instantUse)
            {
                Game1.toolAnimationDone(who);
                who.canReleaseTool = false;
                who.UsingTool      = false;
            }
            else if (Name.Equals("Seeds"))
            {
                switch (who.FacingDirection)
                {
                case 0:
                    who.Sprite.currentFrame = 208;
                    Update(0, 0, who);
                    break;

                case 1:
                    who.Sprite.currentFrame = 204;
                    Update(1, 0, who);
                    break;

                case 2:
                    who.Sprite.currentFrame = 200;
                    Update(2, 0, who);
                    break;

                case 3:
                    who.Sprite.currentFrame = 212;
                    Update(3, 0, who);
                    break;
                }
            }
            else if (this is WateringCan && location.CanRefillWateringCanOnTile((int)who.GetToolLocation().X / 64, (int)who.GetToolLocation().Y / 64))
            {
                switch (who.FacingDirection)
                {
                case 2:
                    ((FarmerSprite)who.Sprite).animateOnce(166, 250f, 2);
                    Update(2, 1, who);
                    break;

                case 1:
                    ((FarmerSprite)who.Sprite).animateOnce(174, 250f, 2);
                    Update(1, 0, who);
                    break;

                case 0:
                    ((FarmerSprite)who.Sprite).animateOnce(182, 250f, 2);
                    Update(0, 1, who);
                    break;

                case 3:
                    ((FarmerSprite)who.Sprite).animateOnce(190, 250f, 2);
                    Update(3, 0, who);
                    break;
                }
                who.canReleaseTool = false;
            }
            else if (this is WateringCan && ((WateringCan)this).WaterLeft <= 0)
            {
                Game1.toolAnimationDone(who);
                who.CanMove        = true;
                who.canReleaseTool = false;
            }
            else if (this is WateringCan)
            {
                who.jitterStrength = 0.25f;
                switch (who.FacingDirection)
                {
                case 0:
                    who.FarmerSprite.setCurrentFrame(180);
                    Update(0, 0, who);
                    break;

                case 1:
                    who.FarmerSprite.setCurrentFrame(172);
                    Update(1, 0, who);
                    break;

                case 2:
                    who.FarmerSprite.setCurrentFrame(164);
                    Update(2, 0, who);
                    break;

                case 3:
                    who.FarmerSprite.setCurrentFrame(188);
                    Update(3, 0, who);
                    break;
                }
            }
            else if (this is FishingRod)
            {
                switch (who.FacingDirection)
                {
                case 0:
                    ((FarmerSprite)who.Sprite).animateOnce(295, 35f, 8, FishingRod.endOfAnimationBehavior);
                    Update(0, 0, who);
                    break;

                case 1:
                    ((FarmerSprite)who.Sprite).animateOnce(296, 35f, 8, FishingRod.endOfAnimationBehavior);
                    Update(1, 0, who);
                    break;

                case 2:
                    ((FarmerSprite)who.Sprite).animateOnce(297, 35f, 8, FishingRod.endOfAnimationBehavior);
                    Update(2, 0, who);
                    break;

                case 3:
                    ((FarmerSprite)who.Sprite).animateOnce(298, 35f, 8, FishingRod.endOfAnimationBehavior);
                    Update(3, 0, who);
                    break;
                }
                who.canReleaseTool = false;
            }
            else if (this is MeleeWeapon)
            {
                ((MeleeWeapon)this).setFarmerAnimating(who);
            }
            else
            {
                switch (who.FacingDirection)
                {
                case 0:
                    who.FarmerSprite.setCurrentFrame(176);
                    Update(0, 0, who);
                    break;

                case 1:
                    who.FarmerSprite.setCurrentFrame(168);
                    Update(1, 0, who);
                    break;

                case 2:
                    who.FarmerSprite.setCurrentFrame(160);
                    Update(2, 0, who);
                    break;

                case 3:
                    who.FarmerSprite.setCurrentFrame(184);
                    Update(3, 0, who);
                    break;
                }
            }
            return(false);
        }