Example #1
0
 internal static bool AttemptPlanting(Vector2 grabTile, GameLocation location, Farmer who = null)
 {
     if (PlantableCaveCarrot.canPlaceHere(location, grabTile))
     {
         try
         {
             location.terrainFeatures.Remove(grabTile);
             int  X                  = (int)grabTile.X;
             int  Y                  = (int)grabTile.Y;
             int  seedIndex          = CaveCarrotFlower.getIndex();
             bool isReallyGreenhouse = location.isGreenhouse.Value;
             location.isGreenhouse.Value = true;
             HoeDirt dirtPatch = new HoeDirt(0, location);
             location.terrainFeatures.Add(grabTile, (TerrainFeature)dirtPatch);
             dirtPatch.plant(seedIndex, X, Y, Game1.player, false, location);
             location.isGreenhouse.Value = isReallyGreenhouse;
             return(true);
         } catch (Exception e)
         {
             ModEntry.GetMonitor().Log(e.InnerException.Message);
             return(false);
         }
     }
     else
     {
         if (!IsValidLocation(location))
         {
             Game1.showRedMessage("This plant would not thrive here.");
         }
         return(false);
     }
 }
Example #2
0
        private void ItemAction()
        {
            if (Game1.player.CurrentItem == null)
            {
                return;
            }

            if (Game1.player.CurrentItem.getCategoryName().ToLower() == "seed" || Game1.player.CurrentItem.getCategoryName().ToLower() == "fertilizer")
            {
                List <Vector2> affectedTileGrid = MakeVector2TileGrid(Game1.player.getTileLocation(), ModConfig.ItemRadius);

                foreach (Vector2 tile in affectedTileGrid)
                {
                    TerrainFeature terrainTile;
                    if (Game1.currentLocation.terrainFeatures.TryGetValue(tile, out terrainTile))
                    {
                        if (Game1.currentLocation.terrainFeatures[tile] is HoeDirt)
                        {
                            HoeDirt hoedirtTile = (HoeDirt)Game1.currentLocation.terrainFeatures[tile];

                            if (Game1.player.CurrentItem.getCategoryName().ToLower() == "seed")
                            {
                                if (hoedirtTile.crop != null)
                                {
                                    continue;
                                }
                                if (hoedirtTile.plant(Game1.player.CurrentItem.parentSheetIndex, (int)tile.X, (int)tile.Y, Game1.player))
                                {
                                    Game1.player.CurrentItem.Stack -= 1;
                                    if (Game1.player.CurrentItem.Stack <= 0)
                                    {
                                        Game1.player.removeItemFromInventory(Game1.player.CurrentItem);
                                        return;
                                    }
                                }
                            }
                            if (Game1.player.CurrentItem.getCategoryName().ToLower() == "fertilizer")
                            {
                                if (hoedirtTile.fertilizer != 0)
                                {
                                    continue;
                                }
                                hoedirtTile.fertilizer          = Game1.player.CurrentItem.parentSheetIndex;
                                Game1.player.CurrentItem.Stack -= 1;
                                if (Game1.player.CurrentItem.Stack <= 0)
                                {
                                    Game1.player.removeItemFromInventory(Game1.player.CurrentItem);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #3
0
 private void FertilizeSoil(Vector2 tile, HoeDirt dirt)
 {
     if (dirt.fertilizer.Value == 0 && Grabber.NearbyChests.Any((chest) => chest.Fertilizers.Any()))
     {
         var fertilizer = Grabber.NextFertilizer;
         if (fertilizer != null &&
             dirt.canPlantThisSeedHere(fertilizer.Item.ParentSheetIndex, (int)tile.X, (int)tile.Y, true) &&
             dirt.plant(fertilizer.Item.ParentSheetIndex, (int)tile.X, (int)tile.Y, Game1.player, true, Grabber.Location))
         {
             fertilizer.UseItem();
         }
     }
 }
Example #4
0
        private void PlantSeed(Vector2 tile, HoeDirt dirt)
        {
            var seed = Grabber.NextSeed;

            if (seed != null)
            {
                //Utilities.Monitor.Log($"  {Grabber.InstanceName} attempting to seed with: {seed.Item.ParentSheetIndex} {dirt.canPlantThisSeedHere(seed.Item.ParentSheetIndex, (int)tile.X, (int)tile.Y)}", StardewModdingAPI.LogLevel.Trace);
                if (dirt.canPlantThisSeedHere(seed.Item.ParentSheetIndex, (int)tile.X, (int)tile.Y) &&
                    dirt.plant(seed.Item.ParentSheetIndex, (int)tile.X, (int)tile.Y, Game1.player, false, Grabber.Location))
                {
                    seed.UseItem();
                }
            }
        }
        private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            // place fully grown crops to test harvesting capabilities
            if (e.KeyPressed == Keys.B)
            {
                if (Game1.player.ActiveObject == null || (Game1.player.ActiveObject != null && Game1.player.ActiveObject.category != StardewValley.Object.SeedsCategory))
                {
                    Game1.showRedMessage("Please select a seed as your active object.");
                    return;
                }
                else
                {
                    int seedIndex = Game1.player.ActiveObject.parentSheetIndex;

                    for (int tileX = 0; tileX < Game1.currentLocation.map.Layers[0].LayerWidth; ++tileX)
                    {
                        for (int tileY = 0; tileY < Game1.currentLocation.map.Layers[0].LayerHeight; ++tileY)
                        {
                            if (Game1.currentLocation.doesTileHaveProperty(tileX, tileY, "Diggable", "Back") != null)
                            {
                                Vector2 key = new Vector2(tileX, tileY);
                                Game1.currentLocation.makeHoeDirt(key);

                                if (Game1.currentLocation.terrainFeatures.ContainsKey(key))
                                {
                                    HoeDirt dirt = Game1.currentLocation.terrainFeatures[key] as HoeDirt;
                                    if (dirt != null /* && dirt.canPlantThisSeedHere(seedIndex, tileX, tileY)*/)
                                    {
                                        dirt.plant(seedIndex, tileX, tileY, Game1.player);
                                        dirt.crop.growCompletely();
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (e.KeyPressed == Keys.Z)
            {
                this.Monitor.Log($"Your location: ({Game1.player.getTileLocationPoint()})");
            }
        }
Example #6
0
        private void AttemptSowSeed(int seedIndex, HoeDirt hoeDirt, Vector2 tile)
        {
            // -74 == Object.SeedsCategory
            Item seedItem = chest.items.FirstOrDefault(i => i != null && i.Category == -74 && i.ParentSheetIndex == seedIndex);

            if (seedItem != null)
            {
                // Remove one seed from the stack, or the whole item if it is the last seed of the stack
                seedItem.Stack -= 1;

                if (seedItem.Stack == 0)
                {
                    chest.items.Remove(seedItem);
                }

                // Plant the seed on the ground
                //hoeDirt.crop = new Crop(seedIndex, (int)tile.X, (int)tile.Y);
                hoeDirt.plant(seedIndex, (int)tile.X, (int)tile.Y, Game1.MasterPlayer, false, hoeDirt.currentLocation);
            }
        }
Example #7
0
        public void doMagic(bool playedToday)
        {
            if (!playedToday)
            {
                List <Vector2> tiles      = Utility.getAdjacentTileLocations(Game1.player.getTileLocation());
                Vector2        playerTile = Game1.player.getTileLocation();
                tiles.Add(playerTile);
                tiles.Add(playerTile + new Vector2(1f, 1f));
                tiles.Add(playerTile + new Vector2(-1f, -1f));
                tiles.Add(playerTile + new Vector2(1f, -1f));
                tiles.Add(playerTile + new Vector2(-1f, 1f));

                foreach (Vector2 tile in tiles)
                {
                    if (Game1.currentLocation.terrainFeatures.ContainsKey(tile) && Game1.currentLocation.terrainFeatures[tile] is HoeDirt)
                    {
                        HoeDirt hd = (HoeDirt)Game1.currentLocation.terrainFeatures[tile];
                        if (hd.crop == null)
                        {
                            int seeds = 770;

                            if (Game1.IsWinter)
                            {
                                seeds = 498;
                            }

                            hd.plant(seeds, (int)tile.X, (int)tile.Y, Game1.player, false, Game1.currentLocation);

                            if (hd.crop != null)
                            {
                                hd.crop.newDay(1, 0, (int)tile.X, (int)tile.Y, Game1.currentLocation);
                                Game1.playSound("leafrustle");
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, SFarmer player, Tool tool, Item item, GameLocation location)
        {
            if (item == null || item.Stack <= 0)
            {
                return(false);
            }

            // get dirt
            HoeDirt dirt = tileFeature as HoeDirt;

            if (dirt == null || dirt.crop != null)
            {
                return(false);
            }

            // sow seeds
            bool sowed = dirt.plant(item.parentSheetIndex, (int)tile.X, (int)tile.Y, player);

            if (sowed)
            {
                this.ConsumeItem(player, item);
            }
            return(sowed);
        }
Example #9
0
        public override void DoFunction(GameLocation location, int x, int y, int power, Farmer who)
        {
            this.Refresh_Tools();
            Tool tool;
            IDictionary <string, object> properties = this.Get_Properties(x, y);
            string toolName = "";
            int    xtile    = (int)x / Game1.tileSize;
            int    ytile    = (int)y / Game1.tileSize;

            toolName = (string)properties["string_useTool"];
            if (toolName == null)
            {
                if ((bool)properties["bool_canPlant"])
                {
                    try
                    {
                        if (Game1.player.CurrentItem != null)
                        {
                            HoeDirt dirt = (HoeDirt)properties["hoedirt_dirt"];
                            if (Game1.player.CurrentItem.Category == StardewValley.Object.SeedsCategory)
                            {
                                dirt.plant(Game1.player.CurrentItem.parentSheetIndex.Get(), xtile, ytile, Game1.player, false, Game1.currentLocation);
                                Game1.player.consumeObject(Game1.player.CurrentItem.parentSheetIndex.Get(), 1);
                            }
                            else if (Game1.player.CurrentItem.Category == StardewValley.Object.fertilizerCategory)
                            {
                                dirt.plant(Game1.player.CurrentItem.parentSheetIndex.Get(), xtile, ytile, Game1.player, true, Game1.currentLocation);
                                Game1.player.consumeObject(Game1.player.CurrentItem.parentSheetIndex.Get(), 1);
                            }
                        }
                        else
                        {
                            location.checkAction(new Location(xtile, ytile), Game1.viewport, Game1.player);
                        }
                    }
                    catch (System.Collections.Generic.KeyNotFoundException)
                    {
                        Game1.addHUDMessage(new HUDMessage($"{Game1.player.CurrentItem} {Game1.player.CurrentItem.parentSheetIndex.Get()} 201"));
                        return;
                    }
                }
                return;
            }
            try
            {
                tool = this.attachedTools[toolName];
            }
            catch (System.Collections.Generic.KeyNotFoundException)
            {
                if (toolName == "grab")
                {
                    location.checkAction(new Location(xtile, ytile), Game1.viewport, Game1.player);
                }
                else
                {
                    Game1.addHUDMessage(new HUDMessage($"{toolName} not found"));
                }
                return;
            }
            if (toolName == "melee")
            {
                //TODO this doesn't land at the right location
                //this.scythe.DoDamage(Game1.currentLocation, x, y, 0, power, who);
                return;
            }
            else
            {
                tool.DoFunction(location, x, y, power, who);
                return;
            }
        }