示例#1
0
        /**
         * Sells the crops, and adds them to the inventory if they are on the never-sell list.
         */
        private bool SellCrops(Farmer farmer, StardewValley.Object obj, ReplanterStats stats)
        {
            if (this.NeverSell(obj.ParentSheetIndex))
            {
                return(this.AddItemToInventory(obj, farmer, Game1.getFarm(), stats));
            }

            stats.RunningSellPrice += obj.sellToStorePrice();
            return(true);
        }
示例#2
0
        private void HandleSunflower(Farmer farmer, ReplanterStats stats, int quality, int tileX = 0, int tileY = 0)
        {
            if (this.SellAfterHarvest)
            {
                StardewValley.Object flower = new StardewValley.Object(421, 1, false, -1, quality);

                if (!this.SellCrops(farmer, flower, stats))
                {
                    // TODO: what to do if we can't sell the sunflower?
                }
            }
            else
            {
                StardewValley.Object flower = new StardewValley.Object(421, 1, false, -1, quality);

                if (!this.AddItemToInventory(flower, farmer, Game1.getFarm(), stats))
                {
                    Game1.createObjectDebris(421, tileX, tileY, -1, flower.Quality);

                    this.Monitor.Log("Sunflower was harvested, but couldn't add flower to inventory, you'll have to go pick it up.", LogLevel.Trace);
                }
            }
        }
示例#3
0
        /**
         * Attempts to add the crop to the farmer's inventory.  If the crop is on the always sell list, it is sold instead.
         */
        private bool AddItemToInventory(StardewValley.Object obj, Farmer farmer, Farm farm, ReplanterStats stats)
        {
            if (this.AlwaysSell(obj.ParentSheetIndex))
            {
                return(this.SellCrops(farmer, obj, stats));
            }

            bool wasAdded = false;

            if (farmer.couldInventoryAcceptThisItem(obj) && !this.BypassInventory)
            {
                farmer.addItemToInventory(obj);
                wasAdded = true;

                this.Monitor.Log("Was able to add item to inventory.", LogLevel.Trace);
            }
            else
            {
                StardewValley.Object chest;

                this.Chests.TryGetValue(obj.ParentSheetIndex, out ChestDef preferred);

                if (preferred != null)
                {
                    if (preferred.Location.Equals("house"))
                    {
                        FarmHouse house = (FarmHouse)Game1.getLocationFromName("FarmHouse");
                        house.objects.TryGetValue(preferred.Tile, out chest);
                    }
                    else
                    {
                        farm.objects.TryGetValue(preferred.Tile, out chest);
                    }

                    if (!(chest is Chest))
                    {
                        // Try getting the default chest.
                        farm.objects.TryGetValue(this.ChestCoords, out chest);
                    }
                }
                else
                {
                    farm.objects.TryGetValue(this.ChestCoords, out chest);
                }

                if (chest is Chest)
                {
                    Item i = ((Chest)chest).addItem(obj);
                    if (i == null)
                    {
                        wasAdded = true;
                    }
                    else
                    {
                        // If this condition was reached because bypassInventory was set, then try the inventory.
                        if (this.BypassInventory && farmer.couldInventoryAcceptThisItem(obj))
                        {
                            farmer.addItemToInventory(obj);
                            wasAdded = true;
                        }
                        else
                        {
                            this.Monitor.Log("Was NOT able to add items to chest.", LogLevel.Trace);
                        }
                    }
                }
                else
                {
                    this.Monitor.Log($"Did not find a chest at {(int)this.ChestCoords.X},{(int)this.ChestCoords.Y}", LogLevel.Trace);

                    // If bypassInventory is set to true, but there's no chest: try adding to the farmer's inventory.
                    if (this.BypassInventory)
                    {
                        this.Monitor.Log($"No chest at {(int)this.ChestCoords.X},{(int)this.ChestCoords.Y}, you should place a chest there, or set bypassInventory to \'false\'.", LogLevel.Trace);

                        if (farmer.couldInventoryAcceptThisItem(obj))
                        {
                            farmer.addItemToInventory(obj);
                            wasAdded = true;
                        }
                        else
                        {
                            this.Monitor.Log("Was NOT able to add item to inventory or a chest.  (No chest found, bypassInventory set to 'true')", LogLevel.Trace);
                        }
                    }
                    else
                    {
                        this.Monitor.Log("Was NOT able to add item to inventory or a chest.  (No chest found, bypassInventory set to 'false')", LogLevel.Trace);
                    }
                }
            }

            return(wasAdded);
        }
示例#4
0
        private void ShowMessage(ReplanterStats stats)
        {
            string message = "";

            if (this.Checker.ToLower() == "spouse")
            {
                if (Game1.player.isMarried())
                {
                    message += this.DialogueManager.PerformReplacement(this.Dialogue[1], stats, this.Config);
                }
                else
                {
                    message += this.DialogueManager.PerformReplacement(this.Dialogue[2], stats, this.Config);
                }

                if (((stats.RunningSeedCost + stats.FarmhandCost) > 0) && !this.Free)
                {
                    message += this.DialogueManager.PerformReplacement(this.Dialogue[3], stats, this.Config);
                }

                HUDMessage msg = new HUDMessage(message);
                Game1.addHUDMessage(msg);
            }
            else
            {
                NPC character = Game1.getCharacterFromName(this.Checker);
                if (character != null)
                {
                    message += this.DialogueManager.PerformReplacement(this.GetRandomMessage(this.Greetings), stats, this.Config);

                    if (stats.CropsHarvested > 0)
                    {
                        message += this.DialogueManager.PerformReplacement(this.Dialogue[4], stats, this.Config);
                    }
                    else
                    {
                        message += this.DialogueManager.PerformReplacement(this.Dialogue[7], stats, this.Config);
                    }

                    if ((stats.CropsHarvested != stats.TotalCrops) && !this.SellAfterHarvest)
                    {
                        message += this.DialogueManager.PerformReplacement(this.Dialogue[8], stats, this.Config);
                        message += this.DialogueManager.PerformReplacement(this.GetRandomMessage(this.InventoryMessages), stats, this.Config);
                    }

                    if (!this.Free && stats.CropsHarvested > 0)
                    {
                        message += this.DialogueManager.PerformReplacement(this.Dialogue[5], stats, this.Config);

                        if (stats.RunningSeedCost > 0)
                        {
                            message += this.DialogueManager.PerformReplacement(this.Dialogue[9], stats, this.Config);
                        }
                        else
                        {
                            message += ".";
                        }
                    }

                    if (this.SellAfterHarvest && stats.CropsHarvested > 0)
                    {
                        if (character.Name == "Pierre")
                        {
                            message += this.DialogueManager.PerformReplacement(this.Dialogue[10], stats, this.Config);
                        }
                        else
                        {
                            message += this.DialogueManager.PerformReplacement(this.Dialogue[11], stats, this.Config);
                        }
                    }

                    if (stats.CropsWatered > 0)
                    {
                        message += this.DialogueManager.PerformReplacement(this.Dialogue[12], stats, this.Config);
                    }

                    message += this.DialogueManager.PerformReplacement(this.GetRandomMessage(this.Smalltalk), stats, this.Config);
                    message += "#$e#";

                    character.CurrentDialogue.Push(new Dialogue(message, character));
                    Game1.drawDialogue(character);
                }
                else
                {
                    message += this.DialogueManager.PerformReplacement(this.Dialogue[13], stats, this.Config);
                    HUDMessage msg = new HUDMessage(message);
                    Game1.addHUDMessage(msg);
                }
            }
        }
示例#5
0
        private void PerformAction()
        {
            Farm   farm   = Game1.getFarm();
            Farmer farmer = Game1.player;

            ReplanterStats stats = new ReplanterStats();

            foreach (GameLocation location in Game1.locations)
            {
                if (!location.IsFarm && !location.Name.Contains("Greenhouse"))
                {
                    continue;
                }

                foreach (KeyValuePair <Vector2, TerrainFeature> feature in location.terrainFeatures.Pairs)
                {
                    if (feature.Value == null)
                    {
                        continue;
                    }

                    bool itemHarvested = true;
                    if (feature.Value is HoeDirt dirt)
                    {
                        if (dirt.crop != null)
                        {
                            Crop crop = dirt.crop;

                            if (this.WaterCrops && dirt.state.Value != 1)
                            {
                                dirt.state.Value = 1;
                                stats.CropsWatered++;
                            }

                            if (this.ClearDeadPlants && crop.dead.Value)
                            {
                                // TODO: store what kind of crop this was so we can replant.
                                dirt.destroyCrop(feature.Key, true, location);
                                stats.PlantsCleared++;

                                continue;
                            }

                            if (this.Ignore(crop.indexOfHarvest.Value))
                            {
                                continue;
                            }

                            if (crop.currentPhase.Value >= crop.phaseDays.Count - 1 && (!crop.fullyGrown.Value || crop.dayOfCurrentPhase.Value <= 0))
                            {
                                int seedCost = 0;
                                stats.TotalCrops++;

                                StardewValley.Object item = this.GetHarvestedCrop(dirt, crop, (int)feature.Key.X, (int)feature.Key.Y);

                                if (!this.Free)
                                {
                                    seedCost = (int)(this.CostOfSeed(crop.indexOfHarvest.Value) * ((100f - this.SeedDiscount) / 100f));
                                }

                                if (this.SellAfterHarvest)
                                {
                                    if (this.SellCrops(farmer, item, stats))
                                    {
                                        if (crop.indexOfHarvest.Value == 431)
                                        {
                                            this.HandleSunflower(farmer, stats, item.Quality);
                                        }
                                        itemHarvested = true;
                                    }
                                    else
                                    {
                                        itemHarvested = false;
                                    }
                                }
                                else
                                {
                                    if (this.AddItemToInventory(item, farmer, farm, stats))
                                    {
                                        itemHarvested = true;
                                        if (crop.indexOfHarvest.Value == 431)
                                        {
                                            this.HandleSunflower(farmer, stats, item.Quality, (int)feature.Key.X, (int)feature.Key.Y);
                                        }
                                    }
                                    else
                                    {
                                        itemHarvested = false;
                                    }
                                }

                                // Replanting
                                if (itemHarvested)
                                {
                                    stats.CropsHarvested++;

                                    if (this.ReplantCrop(crop, location))
                                    {
                                        if (crop.regrowAfterHarvest.Value == -1)
                                        {
                                            stats.RunningSeedCost += seedCost;
                                        }
                                    }
                                    else
                                    {
                                        if (crop.dead.Value)
                                        {
                                            // Store what kind of crop this is so you can replant.
                                            dirt.destroyCrop(feature.Key, true, location);
                                            stats.PlantsCleared++;
                                        }
                                    }

                                    // Add experience
                                    float experience = (float)(16.0 * Math.Log(0.018 * Convert.ToInt32(Game1.objectInformation[crop.indexOfHarvest.Value].Split('/')[1]) + 1.0, Math.E));
                                    Game1.player.gainExperience(0, (int)Math.Round(experience));
                                }
                            }
                        }
                    }
                    else if (feature.Value is FruitTree tree)
                    {
                        if (tree.fruitsOnTree.Value > 0)
                        {
                            int countFromThisTree = 0;

                            for (int i = 0; i < tree.fruitsOnTree.Value; i++)
                            {
                                stats.TotalCrops++;

                                StardewValley.Object fruit = this.GetHarvestedFruit(tree);

                                if (this.SellAfterHarvest)
                                {
                                    if (this.SellCrops(farmer, fruit, stats))
                                    {
                                        itemHarvested = true;
                                        countFromThisTree++;
                                    }
                                    else
                                    {
                                        itemHarvested = false;
                                    }
                                }
                                else
                                {
                                    if (this.AddItemToInventory(fruit, farmer, farm, stats))
                                    {
                                        itemHarvested = true;
                                        countFromThisTree++;
                                    }
                                    else
                                    {
                                        itemHarvested = false;
                                    }
                                }

                                if (itemHarvested)
                                {
                                    stats.CropsHarvested++;

                                    float experience = (float)(16.0 * Math.Log(0.018 * Convert.ToInt32(Game1.objectInformation[tree.indexOfFruit.Value].Split('/')[1]) + 1.0, Math.E));
                                    Game1.player.gainExperience(0, (int)Math.Round(experience));
                                }
                            }

                            tree.fruitsOnTree.Value -= countFromThisTree;
                        }
                    }
                    else if (feature.Value is Bush bush)
                    {
                        if (bush.size.Value == Bush.greenTeaBush && bush.inBloom(Game1.currentSeason, Game1.dayOfMonth) && bush.tileSheetOffset.Value != 0)
                        {
                            stats.TotalCrops++;

                            StardewValley.Object teaLeaf = this.GetHarvestedTeaLeaf(bush);

                            itemHarvested = this.SellAfterHarvest
                                ? this.SellCrops(farmer, teaLeaf, stats)
                                : this.AddItemToInventory(teaLeaf, farmer, farm, stats);

                            if (itemHarvested)
                            {
                                stats.CropsHarvested++;

                                float experience = (float)(16.0 * Math.Log(0.018 * Convert.ToInt32(Game1.objectInformation[teaLeaf.ParentSheetIndex].Split('/')[1]) + 1.0, Math.E));
                                Game1.player.gainExperience(0, (int)Math.Round(experience));
                            }
                        }
                    }
                }
            }

            if (stats.RunningSellPrice > 0)
            {
                farmer.Money = farmer.Money + stats.RunningSellPrice;
                this.Monitor.Log($"Sale price of your crops: {stats.RunningSellPrice}", LogLevel.Trace);
            }

            if (!this.Free)
            {
                farmer.Money = Math.Max(0, farmer.Money - stats.RunningSeedCost);
                this.Monitor.Log($"Total cost of new seeds: {stats.RunningSeedCost}", LogLevel.Trace);
            }

            if (!this.Free)
            {
                stats.FarmhandCost = (int)Math.Round(stats.CropsHarvested * this.CostPerHarvestedCrop);
                farmer.Money       = Math.Max(0, farmer.Money - stats.FarmhandCost);
                this.Monitor.Log($"Costs paid to farm hand: {stats.FarmhandCost}", LogLevel.Trace);
            }

            if (this.MessagesEnabled)
            {
                this.ShowMessage(stats);
            }
        }