Esempio n. 1
0
        public void GrowTree()
        {
            SFarmer player = Game1.player;
            int     x      = (int)player.GetToolLocation().X / Game1.tileSize;
            int     y      = (int)player.GetToolLocation().Y / Game1.tileSize;
            Vector2 index  = new Vector2(x, y);

            if (player.currentLocation.terrainFeatures.ContainsKey(index))
            {
                TerrainFeature terrainFeature = player.currentLocation.terrainFeatures[index];
                if (terrainFeature is Tree tree)
                {
                    if (!tree.stump)
                    {
                        tree.growthStage = 5;
                    }
                }
                else if (terrainFeature is FruitTree fruitTree)
                {
                    if (!fruitTree.stump)
                    {
                        fruitTree.growthStage     = 5;
                        fruitTree.daysUntilMature = 0;
                    }
                }
            }
        }
Esempio n. 2
0
        //public Rectangle getNetZone(Farmer who)
        //{

        //}

        public override bool beginUsing(GameLocation location, int x, int y, StardewValley.Farmer who)
        {
            inUse = true;
            Log.info("beginging hte use");
            Rectangle rectangle = new Rectangle((int)who.GetToolLocation(false).X, (int)who.GetToolLocation(false).Y, 64, 64);

            CritterLocations checkLocation = new CritterLocations(location);
            List <Critter>   critters      = new List <Critter>();

            critters = checkLocation.getAllActiveCritters();

            if (!caughtBug)
            {
                if (critters.Count > 0)
                {
                    foreach (Critter critter in critters)
                    {
                        if (checkCatch(critter, rectangle))
                        {
                            break;
                        }
                    }
                }
            }


            return(base.beginUsing(location, x, y, who));
        }
Esempio n. 3
0
 public virtual void draw(SpriteBatch b)
 {
     if (lastUser != null && lastUser.toolPower > 0 && lastUser.canReleaseTool)
     {
         foreach (Vector2 v in tilesAffected(lastUser.GetToolLocation() / 64f, lastUser.toolPower, lastUser))
         {
             b.Draw(Game1.mouseCursors, Game1.GlobalToLocal(new Vector2((int)v.X * 64, (int)v.Y * 64)), new Rectangle(194, 388, 16, 16), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 0.01f);
         }
     }
 }
        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._animal.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.OnNewBehavior();
                    _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(() => {
                        AnimalHusbandryModEntry.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);
        }
Esempio n. 5
0
        public static bool beginUsing(MilkPail __instance, GameLocation location, int x, int y, StardewValley.Farmer who, ref bool __result)
        {
            if (!IsInseminationSyringe(__instance))
            {
                return(true);
            }

            string inseminationSyringeId = __instance.modData[InseminationSyringeKey];

            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.DisablePregnancy)
            {
                if (location is Farm)
                {
                    foreach (FarmAnimal farmAnimal in (location as Farm).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[inseminationSyringeId] = farmAnimal;
                            break;
                        }
                    }
                }
                else if (location is AnimalHouse)
                {
                    foreach (FarmAnimal farmAnimal in (location as AnimalHouse).animals.Values)
                    {
                        if (farmAnimal.GetBoundingBox().Intersects(rectangle))
                        {
                            Animals[inseminationSyringeId] = farmAnimal;
                            break;
                        }
                    }
                }
            }

            Animals.TryGetValue(inseminationSyringeId, out FarmAnimal animal);
            if (animal != null)
            {
                string dialogue = "";
                if (__instance.attachments[0] == null)
                {
                    Game1.showRedMessage(DataLoader.i18n.Get("Tool.InseminationSyringe.Empty"));
                    Animals[inseminationSyringeId] = null;
                }
                else if (AnimalExtension.GetAnimalFromType(animal.type.Value) == null)
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = animal.displayName });
                }
                else if (IsEggAnimal(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.EggAnimal", new { animalName = animal.displayName });
                }
                else if (!((ImpregnatableAnimalItem)DataLoader.AnimalData.GetAnimalItem(animal)).MinimumDaysUtillBirth.HasValue)
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = animal.displayName });
                }
                else if (animal.isBaby())
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.TooYoung", new { animalName = animal.displayName });
                }
                else if (PregnancyController.IsAnimalPregnant(animal))
                {
                    int daysUntilBirth = animal.GetDaysUntilBirth().Value;
                    if (daysUntilBirth > 1)
                    {
                        dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.AlreadyPregnant", new { animalName = animal.displayName, numberOfDays = daysUntilBirth });
                    }
                    else
                    {
                        dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.ReadyForBirth", new { animalName = animal.displayName });
                    }
                }
                else if (!CheckCorrectProduct(animal, __instance.attachments[0]))
                {
                    var    data        = DataLoader.Helper.Content.Load <Dictionary <int, string> >(@"Data\ObjectInformation.xnb", ContentSource.GameContent);
                    string produceName = data[animal.defaultProduceIndex.Value].Split('/')[4];
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CorrectItem", new { itemName = produceName });
                }
                else if (PregnancyController.CheckBuildingLimit(animal))
                {
                    dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.BuildingLimit", new { buildingType = animal.displayHouse });
                }
                else
                {
                    animal.doEmote(16, true);
                    if (who != null && Game1.player.Equals(who))
                    {
                        if (animal.sound.Value != null)
                        {
                            ICue animalSound = Game1.soundBank.GetCue(animal.sound.Value);
                            animalSound.Play();
                        }

                        DelayedAction.playSoundAfterDelay("fishingRodBend", 300, location);
                        DelayedAction.playSoundAfterDelay("fishingRodBend", 1200, location);
                    }
                    animal.pauseTimer = 1500;
                }
                if (dialogue.Length > 0)
                {
                    if (who != null && Game1.player.Equals(who))
                    {
                        DelayedAction.showDialogueAfterDelay(dialogue, 150);
                    }
                    Animals[inseminationSyringeId] = null;
                }
            }

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

            if (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;

            __result = true;
            return(false);
        }
        private void checkForToolAction(object sender, EventArgs e)
        {
            SFarmer player = Game1.player;

            if (player.usingTool)
            {
                toolPower = player.toolPower;
                if (hasCaluclatedRestore == true)
                {
                    return;
                }

                hasCaluclatedRestore = true;
                Tool    currentTool  = player.CurrentTool;
                Vector2 toolLocation = player.GetToolLocation() / Game1.tileSize;
                toolLocation.X = (int)Math.Floor(toolLocation.X);
                toolLocation.Y = (int)Math.Floor(toolLocation.Y);
                var toolLocationX = (int)toolLocation.X;
                var toolLocationY = (int)toolLocation.Y;

                if (currentTool is Hoe)
                {
                    // Check if you can even dig
                    if (Game1.currentLocation.doesTileHaveProperty(toolLocationX, toolLocationY, "Diggable", "Back") == null)
                    {
                        return;
                    }

                    // Check if already dug
                    if (Game1.currentLocation.isTileHoeDirt(toolLocation) == false)
                    {
                        return;
                    }

                    restoreAmount = 2 + ( float )player.FarmingLevel * 0.1f;
                }

                if (currentTool is Axe)
                {
                    // Check for trees
                    if (Game1.currentLocation.terrainFeatures.ContainsKey(toolLocation) &&
                        Game1.currentLocation.terrainFeatures[toolLocation] is Tree)
                    {
                        return;
                    }

                    // Check for twigs or weeds
                    if (Game1.currentLocation.objects.ContainsKey(toolLocation) && (Game1.currentLocation.objects[toolLocation].name == "Twig" || Game1.currentLocation.objects[toolLocation].name == "Weeds"))
                    {
                        return;
                    }

                    // Check for advanced tree stumps
                    if (Game1.currentLocation is Farm)
                    {
                        var toolHitBounds = new Rectangle(toolLocationX * Game1.tileSize, toolLocationY * Game1.tileSize, Game1.tileSize, Game1.tileSize);
                        foreach (var item in (Game1.currentLocation as Farm).resourceClumps)
                        {
                            if (item.getBoundingBox(item.tile).Contains(toolHitBounds))
                            {
                                return;
                            }
                        }
                    }

                    restoreAmount = 2 + ( float )player.ForagingLevel * 0.1f;
                }

                if (currentTool is Pickaxe)
                {
                    if (Game1.currentLocation.objects.ContainsKey(toolLocation))
                    {
                        StardewValley.Object groundObject = Game1.currentLocation.objects[toolLocation];

                        // Check if stone or boulder
                        if (groundObject.name.Contains("Stone") || groundObject.name.Contains("Boulder"))
                        {
                            return;
                        }

                        // Check if crafting object
                        if (groundObject.type.Equals("Crafting") && groundObject.fragility != 2)
                        {
                            return;
                        }
                    }

                    // Check if removing hoedirt
                    if ((Game1.currentLocation.doesTileHaveProperty(toolLocationX, toolLocationY, "Diggable", "Back") == null))
                    {
                        return;
                    }

                    restoreAmount = 2 + ( float )player.miningLevel * 0.1f;
                }

                if (currentTool is WateringCan)
                {
                    // Check if watering hoedirt
                    if ((Game1.currentLocation.isTileHoeDirt(toolLocation) == true))
                    {
                        return;
                    }

                    restoreAmount = 2 + ( float )player.farmingLevel * 0.1f;
                }

                if (currentTool is FishingRod)
                {
                    // Check for water
                    if (Game1.currentLocation.doesTileHaveProperty(toolLocationX, toolLocationY, "Water", "Back") != null && Game1.currentLocation.doesTileHaveProperty(toolLocationX, toolLocationY, "NoFishing", "Back") == null && Game1.currentLocation.getTileIndexAt(toolLocationX, toolLocationY, "Buildings") == -1 || Game1.currentLocation.doesTileHaveProperty(toolLocationX, toolLocationY, "Water", "Buildings") != null)
                    {
                        return;
                    }

                    restoreAmount = 2 + ( float )(8.0 - ( double )player.FishingLevel * 0.100000001490116);
                }
            }
            else if (toolPower == 0 && restoreAmount > 0)
            {
                Game1.player.stamina += restoreAmount;

                toolPower            = -1;
                restoreAmount        = -1;
                hasCaluclatedRestore = false;
            }
            else if (hasCaluclatedRestore)
            {
                hasCaluclatedRestore = false;
            }
        }
Esempio n. 7
0
        private static bool DoToolFunction(GameLocation location, StardewValley.Farmer who, Tool tool, int x, int y)
        {
            bool    performedAction = false;
            Vector2 index           = new Vector2(x, y);
            Vector2 vector2         = new Vector2((float)(x + 0.5), (float)(y + 0.5));

            if (tool is MeleeWeapon && tool.Name.ToLower().Contains("scythe"))
            {
                var snapshotPlayerExperience = Game1.player.experiencePoints;
                if (location.objects[index] != null)
                {
                    StardewValley.Object hitObject = location.objects[index];
                    if (hitObject.name.Contains("Weed") && hitObject.performToolAction(tool, location))
                    {
                        if (hitObject.type == "Crafting" && hitObject.fragility != 2)
                        {
                            location.debris.Add(new Debris(hitObject.bigCraftable ? -hitObject.parentSheetIndex : hitObject.parentSheetIndex, index, index));
                        }
                        hitObject.performRemoveAction(index, location);
                        location.objects.Remove(index);
                        performedAction = true;
                    }
                }
                else if (location.terrainFeatures.ContainsKey(index) && location.terrainFeatures[index].performToolAction(tool, 0, index, (GameLocation)null))
                {
                    location.terrainFeatures.Remove(index);
                    performedAction = true;
                }
                RestorePlayerExperience(snapshotPlayerExperience);
            }
            else if (tool is Axe)
            {
                var       snapshotPlayerExperience = Game1.player.experiencePoints;
                Rectangle rectangle = new Rectangle(x * Game1.tileSize, y * Game1.tileSize, Game1.tileSize, Game1.tileSize);
                location.performToolAction(tool, x, y);
                if (location.terrainFeatures.ContainsKey(index) && location.terrainFeatures[index].performToolAction(tool, 0, index, (GameLocation)null))
                {
                    location.terrainFeatures.Remove(index);
                    performedAction = true;
                }
                Rectangle boundingBox;
                if (location.largeTerrainFeatures != null)
                {
                    for (int index2 = location.largeTerrainFeatures.Count - 1; index2 >= 0; --index2)
                    {
                        boundingBox = location.largeTerrainFeatures[index2].getBoundingBox();
                        if (boundingBox.Intersects(rectangle) && location.largeTerrainFeatures[index2].performToolAction(tool, 0, index, (GameLocation)null))
                        {
                            location.largeTerrainFeatures.RemoveAt(index2);
                        }
                    }
                }
                if (location.terrainFeatures.ContainsKey(index) && location.terrainFeatures[index] is Tree)
                {
                    if (!(location.terrainFeatures[index] as Tree).stump || EquivalentExchange.IsShiftKeyPressed())
                    {
                        performedAction = true;
                    }
                }
                if (!location.Objects.ContainsKey(index) || location.Objects[index].Type == null || !location.Objects[index].performToolAction(tool, location))
                {
                    return(performedAction);
                }
                if (location.Objects[index].type.Equals("Crafting") && location.Objects[index].fragility != 2)
                {
                    var    debris1     = location.debris;
                    int    objectIndex = location.Objects[index].bigCraftable ? -location.Objects[index].ParentSheetIndex : location.Objects[index].ParentSheetIndex;
                    Debris debris2     = new Debris(objectIndex, index, index);
                    debris1.Add(debris2);
                }
                location.Objects[index].performRemoveAction(index, location);
                location.Objects.Remove(index);
                performedAction = true;
                RestorePlayerExperience(snapshotPlayerExperience);
            }
            else if (tool is Pickaxe)
            {
                var snapshotPlayerExperience = Game1.player.experiencePoints;
                int power = who.toolPower;
                if (location.performToolAction(tool, x, y))
                {
                    return(true);
                }
                StardewValley.Object objectHit = (StardewValley.Object)null;
                location.Objects.TryGetValue(index, out objectHit);
                if (objectHit == null)
                {
                    if (location.terrainFeatures.ContainsKey(index) && location.terrainFeatures[index].performToolAction(tool, 0, index, (GameLocation)null))
                    {
                        location.terrainFeatures.Remove(index);
                        performedAction = true;
                    }
                }

                if (objectHit != null)
                {
                    if (objectHit.Name.Equals("Stone"))
                    {
                        Game1.playSound("hammer");
                        if (objectHit.minutesUntilReady > 0)
                        {
                            int num3 = Math.Max(1, tool.upgradeLevel + 1);
                            objectHit.minutesUntilReady.Set(objectHit.minutesUntilReady - num3);
                            objectHit.shakeTimer = 200;
                            if (objectHit.minutesUntilReady > 0)
                            {
                                Game1.createRadialDebris(Game1.currentLocation, 14, x, y, Game1.random.Next(2, 5), false, -1, false, -1);
                                return(performedAction);
                            }
                        }
                        if (objectHit.ParentSheetIndex < 200 && !Game1.objectInformation.ContainsKey(objectHit.ParentSheetIndex + 1))
                        {
                            location.TemporarySprites.Add(new TemporaryAnimatedSprite(objectHit.ParentSheetIndex + 1, 300f, 1, 2, new Vector2((float)(x) * Game1.tileSize, (float)(y) * Game1.tileSize), true, objectHit.flipped)
                            {
                                alphaFade = 0.01f
                            });
                        }
                        else
                        {
                            location.TemporarySprites.Add(new TemporaryAnimatedSprite(47, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize)), Color.Gray, 10, false, 80f, 0, -1, -1f, -1, 0));
                        }
                        Game1.createRadialDebris(location, 14, x, y, Game1.random.Next(2, 5), false, -1, false, -1);
                        location.TemporarySprites.Add(new TemporaryAnimatedSprite(46, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize)), Color.White, 10, false, 80f, 0, -1, -1f, -1, 0)
                        {
                            motion       = new Vector2(0.0f, -0.6f),
                            acceleration = new Vector2(0.0f, 1f / 500f),
                            alphaFade    = 0.015f
                        });
                        if (!location.Name.StartsWith("UndergroundMine"))
                        {
                            if (objectHit.parentSheetIndex == 343 || objectHit.parentSheetIndex == 450)
                            {
                                Random random = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 2 + x * 2000 + y);
                                if (random.NextDouble() < 0.035 && Game1.stats.DaysPlayed > 1U)
                                {
                                    Game1.createObjectDebris(535 + (Game1.stats.DaysPlayed <= 60U || random.NextDouble() >= 0.2 ? (Game1.stats.DaysPlayed <= 120U || random.NextDouble() >= 0.2 ? 0 : 2) : 1), x, y, tool.getLastFarmerToUse().uniqueMultiplayerID);
                                }
                                if (random.NextDouble() < 0.035 * (who.professions.Contains(21) ? 2.0 : 1.0) && Game1.stats.DaysPlayed > 1U)
                                {
                                    Game1.createObjectDebris(382, x, y, tool.getLastFarmerToUse().uniqueMultiplayerID);
                                }
                                if (random.NextDouble() < 0.01 && Game1.stats.DaysPlayed > 1U)
                                {
                                    Game1.createObjectDebris(390, x, y, tool.getLastFarmerToUse().uniqueMultiplayerID);
                                }
                            }
                            location.breakStone(objectHit.parentSheetIndex, x, y, who, new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 2 + x * 4000 + y));
                        }
                        else
                        {
                            Game1.mine.checkStoneForItems(objectHit.ParentSheetIndex, x, y, who);
                        }
                        if (objectHit.minutesUntilReady > 0)
                        {
                            return(performedAction);
                        }
                        location.Objects.Remove(index);
                        Game1.playSound("stoneCrack");
                        performedAction = true;
                    }
                    else
                    {
                        if (!objectHit.performToolAction(tool, location))
                        {
                            return(performedAction);
                        }
                        objectHit.performRemoveAction(index, location);
                        if (objectHit.type.Equals("Crafting") && objectHit.fragility != 2)
                        {
                            var       debris1      = Game1.currentLocation.debris;
                            int       objectIndex  = objectHit.bigCraftable ? -objectHit.ParentSheetIndex : objectHit.ParentSheetIndex;
                            Vector2   toolLocation = who.GetToolLocation(false);
                            Rectangle boundingBox  = who.GetBoundingBox();
                            double    x1           = (double)boundingBox.Center.X;
                            boundingBox = who.GetBoundingBox();
                            double  y1             = (double)boundingBox.Center.Y;
                            Vector2 playerPosition = new Vector2((float)x1, (float)y1);
                            Debris  debris2        = new Debris(objectIndex, toolLocation, playerPosition);
                            debris1.Add(debris2);
                        }
                        Game1.currentLocation.Objects.Remove(index);
                        performedAction = true;
                    }
                    RestorePlayerExperience(snapshotPlayerExperience);
                }
                else
                {
                    Game1.playSound("woodyHit");
                    if (location.doesTileHaveProperty(x, y, "Diggable", "Back") == null)
                    {
                        return(false);
                    }
                    location.TemporarySprites.Add(new TemporaryAnimatedSprite(12, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize)), Color.White, 8, false, 80f, 0, -1, -1f, -1, 0)
                    {
                        alphaFade = 0.015f
                    });
                }
            }
            else if (tool is Hoe)
            {
                var snapshotPlayerExperience = Game1.player.experiencePoints;
                if (location.terrainFeatures.ContainsKey(index))
                {
                    if (location.terrainFeatures[index].performToolAction(tool, 0, index, (GameLocation)null))
                    {
                        location.terrainFeatures.Remove(index);
                        performedAction = true;
                    }
                }
                else
                {
                    if (location.objects.ContainsKey(index) && location.Objects[index].performToolAction(tool, location))
                    {
                        if (location.Objects[index].type.Equals("Crafting") && location.Objects[index].fragility != 2)
                        {
                            var     debris1      = location.debris;
                            int     objectIndex  = location.Objects[index].bigCraftable ? -location.Objects[index].ParentSheetIndex : location.Objects[index].ParentSheetIndex;
                            Vector2 toolLocation = who.GetToolLocation(false);
                            Microsoft.Xna.Framework.Rectangle boundingBox = who.GetBoundingBox();
                            double x1 = (double)boundingBox.Center.X;
                            boundingBox = who.GetBoundingBox();
                            double  y1             = (double)boundingBox.Center.Y;
                            Vector2 playerPosition = new Vector2((float)x1, (float)y1);
                            Debris  debris2        = new Debris(objectIndex, toolLocation, playerPosition);
                            debris1.Add(debris2);
                        }
                        location.Objects[index].performRemoveAction(index, location);
                        location.Objects.Remove(index);
                        performedAction = true;
                    }
                    if (location.doesTileHaveProperty((int)index.X, (int)index.Y, "Diggable", "Back") != null)
                    {
                        if (location.Name.Equals("UndergroundMine") && !location.isTileOccupied(index, ""))
                        {
                            location.terrainFeatures.Add(index, (TerrainFeature) new HoeDirt());
                            performedAction = true;
                            Game1.removeSquareDebrisFromTile((int)index.X, (int)index.Y);
                            location.checkForBuriedItem((int)index.X, (int)index.Y, false, false);
                            location.temporarySprites.Add(new TemporaryAnimatedSprite(12, new Vector2(vector2.X * (float)Game1.tileSize, vector2.Y * (float)Game1.tileSize), Color.White, 8, Game1.random.NextDouble() < 0.5, 50f, 0, -1, -1f, -1, 0));
                        }
                        else if (!location.isTileOccupied(index, "") && location.isTilePassable(new xTile.Dimensions.Location((int)index.X, (int)index.Y), Game1.viewport))
                        {
                            location.makeHoeDirt(index);
                            performedAction = true;
                            Game1.removeSquareDebrisFromTile((int)index.X, (int)index.Y);
                            location.temporarySprites.Add(new TemporaryAnimatedSprite(12, new Vector2(index.X * (float)Game1.tileSize, index.Y * (float)Game1.tileSize), Color.White, 8, Game1.random.NextDouble() < 0.5, 50f, 0, -1, -1f, -1, 0));
                            location.checkForBuriedItem((int)index.X, (int)index.Y, false, false);
                        }
                    }
                }
                RestorePlayerExperience(snapshotPlayerExperience);
            }
            return(performedAction);
        }
Esempio n. 8
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 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);
        }
Esempio n. 10
0
        public virtual void endUsing(GameLocation location, Farmer who)
        {
            who.stopJittering();
            who.canReleaseTool = false;
            int addedAnimationMultiplayer = (!(who.Stamina <= 0f)) ? 1 : 2;

            if (Game1.isAnyGamePadButtonBeingPressed() || !who.IsLocalPlayer)
            {
                who.lastClick = who.GetToolLocation();
            }
            if (Name.Equals("Seeds"))
            {
                switch (who.FacingDirection)
                {
                case 2:
                    ((FarmerSprite)who.Sprite).animateOnce(200, 150f, 4);
                    break;

                case 1:
                    ((FarmerSprite)who.Sprite).animateOnce(204, 150f, 4);
                    break;

                case 0:
                    ((FarmerSprite)who.Sprite).animateOnce(208, 150f, 4);
                    break;

                case 3:
                    ((FarmerSprite)who.Sprite).animateOnce(212, 150f, 4);
                    break;
                }
            }
            else if (this is WateringCan)
            {
                if ((this as WateringCan).WaterLeft > 0)
                {
                    who.currentLocation.localSound("wateringCan");
                }
                switch (who.FacingDirection)
                {
                case 2:
                    ((FarmerSprite)who.Sprite).animateOnce(164, 125f * (float)addedAnimationMultiplayer, 3);
                    break;

                case 1:
                    ((FarmerSprite)who.Sprite).animateOnce(172, 125f * (float)addedAnimationMultiplayer, 3);
                    break;

                case 0:
                    ((FarmerSprite)who.Sprite).animateOnce(180, 125f * (float)addedAnimationMultiplayer, 3);
                    break;

                case 3:
                    ((FarmerSprite)who.Sprite).animateOnce(188, 125f * (float)addedAnimationMultiplayer, 3);
                    break;
                }
            }
            else if (this is FishingRod && who.IsLocalPlayer && Game1.activeClickableMenu == null)
            {
                if (!(this as FishingRod).hit)
                {
                    DoFunction(who.currentLocation, (int)who.lastClick.X, (int)who.lastClick.Y, 1, who);
                }
            }
            else if (!(this is MeleeWeapon) && !(this is Pan) && !(this is Shears) && !(this is MilkPail) && !(this is Slingshot))
            {
                who.FarmerSprite.nextOffset = 0;
                switch (who.FacingDirection)
                {
                case 0:
                    ((FarmerSprite)who.Sprite).animateOnce(176, 60f * (float)addedAnimationMultiplayer, 8);
                    break;

                case 1:
                    ((FarmerSprite)who.Sprite).animateOnce(168, 60f * (float)addedAnimationMultiplayer, 8);
                    break;

                case 2:
                    ((FarmerSprite)who.Sprite).animateOnce(160, 60f * (float)addedAnimationMultiplayer, 8);
                    break;

                case 3:
                    ((FarmerSprite)who.Sprite).animateOnce(184, 60f * (float)addedAnimationMultiplayer, 8);
                    break;
                }
            }
        }
Esempio n. 11
0
        /// <summary>Raised after the game state is updated (≈60 times per second).</summary>
        /// <param name="e">The event arguments.</param>
        /// <param name="reflection">Simplifies access to private game code.</param>
        public void OnUpdateTicked(UpdateTickedEventArgs e, IReflectionHelper reflection)
        {
            if (Game1.player?.currentLocation != null)
            {
                SFarmer player = Game1.player;

                // movement speed
                if (this.Config.IncreasedMovement && player.running)
                {
                    player.addedSpeed = this.Config.MoveSpeed;
                }
                else if (!this.Config.IncreasedMovement && player.addedSpeed == this.Config.MoveSpeed)
                {
                    player.addedSpeed = 0;
                }
                if (player.controller != null)
                {
                    player.addedSpeed = 0;
                }
                if (Game1.CurrentEvent == null)
                {
                    player.movementDirections.Clear();
                }

                // infinite health/stamina
                if (this.Config.InfiniteHealth)
                {
                    player.health = player.maxHealth;
                }
                if (this.Config.InfiniteStamina)
                {
                    player.stamina = player.MaxStamina;
                }

                // fishing cheats
                if (player.CurrentTool is FishingRod rod)
                {
                    BobberBar bobberMenu = Game1.activeClickableMenu as BobberBar;

                    // max cast power
                    if (this.Config.ThrowBobberMax && rod.isTimingCast)
                    {
                        rod.castingPower = 1.01f;
                    }

                    // durable tackles
                    if (this.Config.DurableTackles && rod.attachments[1] != null)
                    {
                        rod.attachments[1].uses.Value = 0;
                    }

                    // instant bite
                    if (this.Config.InstantBite && rod.isFishing && !rod.hit && rod.timeUntilFishingBite > 0)
                    {
                        rod.timeUntilFishingBite = 0;
                    }

                    // always treasure
                    if (this.Config.AlwaysTreasure && bobberMenu != null)
                    {
                        reflection.GetField <bool>(bobberMenu, "treasure").SetValue(true);
                    }

                    // instant catch
                    if (this.Config.InstantCatch && bobberMenu != null)
                    {
                        reflection.GetField <float>(bobberMenu, "distanceFromCatching").SetValue(1);
                        if (reflection.GetField <bool>(bobberMenu, "treasure").GetValue())
                        {
                            reflection.GetField <bool>(bobberMenu, "treasureCaught").SetValue(true);
                        }
                    }
                }

                // one-hit break
                if (this.Config.OneHitBreak && player.UsingTool && (player.CurrentTool is Axe || player.CurrentTool is Pickaxe))
                {
                    Vector2 tile = new Vector2((int)player.GetToolLocation().X / Game1.tileSize, (int)player.GetToolLocation().Y / Game1.tileSize);

                    if (player.CurrentTool is Pickaxe && player.currentLocation.objects.ContainsKey(tile))
                    {
                        SObject obj = player.currentLocation.Objects[tile];
                        if (obj != null && obj.name == "Stone")
                        {
                            obj.MinutesUntilReady = 0;
                        }
                    }

                    if (player.CurrentTool is Axe && player.currentLocation.terrainFeatures.ContainsKey(tile))
                    {
                        TerrainFeature obj = player.currentLocation.terrainFeatures[tile];
                        if (obj is Tree tree && tree.health.Value > 1)
                        {
                            tree.health.Value = 1;
                        }
                        else if (obj is FruitTree fruitTree && fruitTree.health.Value > 1)
                        {
                            fruitTree.health.Value = 1;
                        }
                    }

                    List <ResourceClump> resourceClumps = new List <ResourceClump>();
                    if (player.currentLocation is MineShaft mineShaft)
                    {
                        resourceClumps.AddRange(mineShaft.resourceClumps);
                    }

                    if (player.currentLocation is Farm farm)
                    {
                        resourceClumps.AddRange(farm.resourceClumps);
                    }

                    if (player.currentLocation is Forest forest)
                    {
                        resourceClumps.Add(forest.log);
                    }

                    if (player.currentLocation is Woods woods)
                    {
                        resourceClumps.AddRange(woods.stumps);
                    }

                    foreach (ResourceClump r in resourceClumps)
                    {
                        if (r == null)
                        {
                            continue;
                        }
                        if (r.getBoundingBox(r.tile.Value).Contains((int)player.GetToolLocation().X, (int)player.GetToolLocation().Y) && r.health.Value > 0)
                        {
                            r.health.Value = 0;
                        }
                    }
                }

                // infinite watering can
                if (this.Config.InfiniteWateringCan && player.CurrentTool is WateringCan can)
                {
                    can.WaterLeft = can.waterCanMax;
                }

                // unlimited gifts
                if (this.Config.AlwaysGiveGift)
                {
                    foreach (Friendship friendship in player.friendshipData.Values)
                    {
                        friendship.GiftsThisWeek = 0;
                        friendship.GiftsToday    = 0;
                    }
                }

                // one-hit kill
                if (this.Config.OneHitKill)
                {
                    foreach (Monster monster in player.currentLocation.characters.OfType <Monster>())
                    {
                        if (monster.Health > 1)
                        {
                            monster.Health = 1;
                        }
                    }
                }
            }
        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);
        }
        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 (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)
                    {
                        Cue 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);
        }
Esempio n. 14
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);
        }
        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. 16
0
        public override bool beginUsing(GameLocation location, int x, int y, StardewValley.Farmer who)
        {
            x = (int)who.GetToolLocation(false).X;
            y = (int)who.GetToolLocation(false).Y;
            Rectangle rectangle = new Rectangle(x - Game1.tileSize / 2, y - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize);

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

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


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


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


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

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

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

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

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


            return(true);
        }
Esempio n. 17
0
        public override void DoFunction(GameLocation location, int x, int y, int power, StardewValley.Farmer who)
        {
            this.lastUser = who;
            if (location.Name.Equals("UndergroundMine"))
            {
                power = 1;
            }
            who.Stamina -= (float)(2 * power) - (float)who.FarmingLevel * 0.1f;
            power        = who.toolPower;
            who.stopJittering();
            Game1.playSound("woodyHit");
            Vector2        vector2     = new Vector2((float)(x / Game1.tileSize), (float)(y / Game1.tileSize));
            List <Vector2> vector2List = IridiumTiles.AFTiles(vector2, power, who);

            foreach (Vector2 index in vector2List)
            {
                index.Equals(vector2);
                if (location.terrainFeatures.ContainsKey(index))
                {
                    //terrainfeatures.performToolAction apparently always returns false
                    if (location.terrainFeatures[index].performToolAction((Tool)this, 0, index, (GameLocation)null))
                    {
                        location.terrainFeatures.Remove(index);
                    }
                }
                else
                {
                    //Test of object[index].performToolAction
                    StardewValley.Object obj = null;
                    if (location.Objects.ContainsKey(index))
                    {
                        obj = location.Objects[index];
                    }
                    //if (location.objects.ContainsKey(index) && location.Objects[index].performToolAction((Tool)this))


                    if (location.objects.ContainsKey(index) && IridiumTiles.perfHoeAtion(this, obj))
                    {
                        if (location.Objects[index].type.Equals("Crafting") && location.Objects[index].fragility != 2)
                        {
                            List <Debris> debris1      = location.debris;
                            int           objectIndex  = location.Objects[index].bigCraftable ? -location.Objects[index].ParentSheetIndex : location.Objects[index].ParentSheetIndex;
                            Vector2       toolLocation = who.GetToolLocation(false);
                            Microsoft.Xna.Framework.Rectangle boundingBox = who.GetBoundingBox();
                            double x1 = (double)boundingBox.Center.X;
                            boundingBox = who.GetBoundingBox();
                            double  y1             = (double)boundingBox.Center.Y;
                            Vector2 playerPosition = new Vector2((float)x1, (float)y1);
                            Debris  debris2        = new Debris(objectIndex, toolLocation, playerPosition);
                            debris1.Add(debris2);
                        }
                        location.Objects[index].performRemoveAction(index, location);
                        location.Objects.Remove(index);
                    }
                    if (location.doesTileHaveProperty((int)index.X, (int)index.Y, "Diggable", "Back") != null)
                    {
                        if (location.Name.Equals("UndergroundMine") && !location.isTileOccupied(index, ""))
                        {
                            if (Game1.mine.mineLevel < 40 || Game1.mine.mineLevel >= 80)
                            {
                                location.terrainFeatures.Add(index, (TerrainFeature) new HoeDirt());
                                Game1.playSound("hoeHit");
                            }
                            else if (Game1.mine.mineLevel < 80)
                            {
                                location.terrainFeatures.Add(index, (TerrainFeature) new HoeDirt());
                                Game1.playSound("hoeHit");
                            }
                            Game1.removeSquareDebrisFromTile((int)index.X, (int)index.Y);
                            location.checkForBuriedItem((int)index.X, (int)index.Y, false, false);
                            location.temporarySprites.Add(new TemporaryAnimatedSprite(12, new Vector2(vector2.X * (float)Game1.tileSize, vector2.Y * (float)Game1.tileSize), Color.White, 8, Game1.random.NextDouble() < 0.5, 50f, 0, -1, -1f, -1, 0));
                            if (vector2List.Count > 2)
                            {
                                location.temporarySprites.Add(new TemporaryAnimatedSprite(6, new Vector2(index.X * (float)Game1.tileSize, index.Y * (float)Game1.tileSize), Color.White, 8, Game1.random.NextDouble() < 0.5, Vector2.Distance(vector2, index) * 30f, 0, -1, -1f, -1, 0));
                            }
                        }
                        else if (!location.isTileOccupied(index, "") && location.isTilePassable(new Location((int)index.X, (int)index.Y), Game1.viewport))
                        {
                            location.makeHoeDirt(index);
                            Game1.playSound("hoeHit");
                            Game1.removeSquareDebrisFromTile((int)index.X, (int)index.Y);
                            location.temporarySprites.Add(new TemporaryAnimatedSprite(12, new Vector2(index.X * (float)Game1.tileSize, index.Y * (float)Game1.tileSize), Color.White, 8, Game1.random.NextDouble() < 0.5, 50f, 0, -1, -1f, -1, 0));
                            if (vector2List.Count > 2)
                            {
                                location.temporarySprites.Add(new TemporaryAnimatedSprite(6, new Vector2(index.X * (float)Game1.tileSize, index.Y * (float)Game1.tileSize), Color.White, 8, Game1.random.NextDouble() < 0.5, Vector2.Distance(vector2, index) * 30f, 0, -1, -1f, -1, 0));
                            }
                            location.checkForBuriedItem((int)index.X, (int)index.Y, false, false);
                        }
                        ++Game1.stats.DirtHoed;
                    }
                }
            }
        }