Esempio n. 1
0
        public static bool beginUsing(Axe __instance, GameLocation location, int x, int y, StardewValley.Farmer who, ref bool __result)
        {
            if (!IsMeatCleaver(__instance))
            {
                return(true);
            }

            string meatCleaverId = __instance.modData[MeatCleaverKey];

            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 && who != null && Game1.player.Equals(who))
            {
                if (location is Farm farm)
                {
                    foreach (FarmAnimal farmAnimal in farm.animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            if (TempAnimals.ContainsKey(meatCleaverId) && farmAnimal == TempAnimals[meatCleaverId])
                            {
                                Animals[meatCleaverId] = farmAnimal;
                            }
                            else
                            {
                                TempAnimals[meatCleaverId] = farmAnimal;
                                if (who != null && Game1.player.Equals(who))
                                {
                                    ICue 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 animalHouse)
                {
                    foreach (FarmAnimal farmAnimal in animalHouse.animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            if (TempAnimals.ContainsKey(meatCleaverId) && farmAnimal == TempAnimals[meatCleaverId])
                            {
                                Animals[meatCleaverId] = farmAnimal;
                            }
                            else
                            {
                                TempAnimals[meatCleaverId] = farmAnimal;
                                if (who != null && Game1.player.Equals(who))
                                {
                                    ICue 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;
                        }
                    }
                }
            }

            __instance.Update(who.facingDirection, 0, who);
            if (TempAnimals.TryGetValue(meatCleaverId, out FarmAnimal tempAnimal) && tempAnimal != null && tempAnimal.age.Value < (int)tempAnimal.ageWhenMature.Value)
            {
                if (who != null && Game1.player.Equals(who))
                {
                    string dialogue = DataLoader.i18n.Get("Tool.MeatCleaver.TooYoung" + Suffix, new { animalName = tempAnimal.displayName });
                    DelayedAction.showDialogueAfterDelay(dialogue, 150);
                }
                TempAnimals[meatCleaverId] = null;
            }
            who.EndUsingTool();
            __result = true;
            return(false);
        }
        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);
        }
Esempio n. 3
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);
        }