Ejemplo n.º 1
0
 internal static bool AttemptPlanting(Vector2 grabTile, GameLocation location, Farmer who = null)
 {
     if (CaveCarrotSeed.canPlaceHere(location, grabTile))
     {
         try
         {
             location.terrainFeatures.Remove(grabTile);
             int  X                  = (int)grabTile.X;
             int  Y                  = (int)grabTile.Y;
             int  seedIndex          = CaveCarrotSeed.getIndex();
             bool isReallyGreenhouse = location.isGreenhouse.Value;
             location.isGreenhouse.Value = true;
             HoeDirt dirtPatch = new HoeDirt(0, location);
             location.terrainFeatures.Add(grabTile, (TerrainFeature)dirtPatch);
             bool planted2 = dirtPatch.plant(seedIndex, X, Y, Game1.player, false, location);
             location.isGreenhouse.Value = isReallyGreenhouse;
             return(true);
         } catch
         {
             return(false);
         }
     }
     else
     {
         if (!IsValidLocation(location))
         {
             Game1.showRedMessage("This plant would not thrive here.");
         }
         return(false);
     }
 }
Ejemplo n.º 2
0
        public static int getIndex()
        {
            if (CaveCarrotSeed.itemIndex == -1)
            {
                CaveCarrotSeed.setIndex();
            }

            return(CaveCarrotSeed.itemIndex);
        }
        public void Edit <T>(IAssetData asset)
        {
            VoidshroomSpore.setIndex(); //get an item index for voidshroom spores if one isn't already set.
            CaveCarrotSeed.setIndex();
            CaveCarrot.setIndex();
            CaveCarrot.setCropIndex();
            if (asset.AssetNameEquals("Maps\\springobjects"))
            {
                IAssetDataForImage editor    = asset.AsImage();
                Texture2D          data      = editor.Data;
                Texture2D          texture2D = new Texture2D(Game1.graphics.GraphicsDevice, data.Width, Math.Max(data.Height, 4096));
                editor.ReplaceWith(texture2D);
                editor.PatchImage(data, new Rectangle?(), new Rectangle?(), PatchMode.Replace);
                try
                {
                    editor.PatchImage(TextureSet.voidShroomSpore, new Rectangle?(), new Rectangle?(this.objectRect(VoidshroomSpore.getIndex())), PatchMode.Replace);
                    editor.PatchImage(TextureSet.caveCarrotSeed, new Rectangle?(), new Rectangle?(this.objectRect(CaveCarrotSeed.getIndex())), PatchMode.Replace);
                }
                catch (Exception)
                {
                }
            }
            else if (asset.AssetNameEquals("Data\\ObjectInformation"))
            {
                IAssetDataForDictionary <int, string> editor = asset.AsDictionary <int, string>();

                IDictionary <int, string> data = editor.Data;
                if (!data.ContainsKey(VoidshroomSpore.getIndex()))
                {
                    int    voidShroomSporeIndex = VoidshroomSpore.getIndex();
                    String voidShroomSpore      = VoidshroomSpore.getObjectData();
                    this.log("Add voidshroom spore object data: " + voidShroomSporeIndex + ": " + voidShroomSpore);
                    data.Add(voidShroomSporeIndex, voidShroomSpore);
                }

                if (!data.ContainsKey(CaveCarrotSeed.getIndex()))
                {
                    int    caveCarrotSeedIndex = CaveCarrotSeed.getIndex();
                    String caveCarrotObject    = CaveCarrotSeed.getObjectData();
                    this.log("Add cave carrot seed object data: " + caveCarrotSeedIndex + ": " + caveCarrotObject);
                    data.Add(caveCarrotSeedIndex, caveCarrotObject);
                }

                if (!data.ContainsKey(CaveCarrotFlower.getIndex()))
                {
                    int    caveCarrotFlowerIndex  = CaveCarrotFlower.getIndex();
                    String caveCarrotFlowerObject = CaveCarrotFlower.getObjectData();
                    this.log("Add cave carrot flower 'seed' data: " + caveCarrotFlowerIndex + ": " + caveCarrotFlowerObject);
                    data.Add(caveCarrotFlowerIndex, caveCarrotFlowerObject);
                }
            }
            else if (asset.AssetNameEquals("Data\\Crops"))
            {
                IAssetDataForDictionary <int, string> editor = asset.AsDictionary <int, string>();
                IDictionary <int, string>             data   = editor.Data;

                int seedIndex = CaveCarrot.getIndex();
                this.log("seedIndex is: " + seedIndex);
                if (!data.ContainsKey(seedIndex))
                {
                    String cropData = CaveCarrot.getCropData();
                    this.monitor.Log("Loading crop data: " + cropData);
                    data.Add(CaveCarrot.getIndex(), cropData);
                }

                int caveCarrotFlowerIndex = CaveCarrotFlower.getIndex();
                this.log("seedIndex is: " + caveCarrotFlowerIndex);
                if (!data.ContainsKey(caveCarrotFlowerIndex))
                {
                    String cropData = CaveCarrotFlower.getCropData();
                    this.monitor.Log("Loading crop data: " + cropData);
                    data.Add(caveCarrotFlowerIndex, cropData);
                }
            }
            else if (asset.AssetNameEquals("TileSheets\\crops"))
            {
                IAssetDataForImage editor    = asset.AsImage();
                Texture2D          data      = editor.Data;
                Texture2D          texture2D = new Texture2D(Game1.graphics.GraphicsDevice, data.Width, Math.Max(data.Height, 4096));
                editor.ReplaceWith(texture2D);
                editor.PatchImage(data, new Rectangle?(), new Rectangle?(), PatchMode.Replace);
                try
                {
                    int index = CaveCarrot.getCropIndex();
                    this.monitor.Log("Loading cave carrot crop texture.  Crop index: " + index);
                    editor.PatchImage(TextureSet.caveCarrotCrop, new Rectangle?(), new Rectangle?(this.cropRect(index)), PatchMode.Replace);

                    index = CaveCarrotFlower.getCropIndex();
                    this.monitor.Log("Loading cave carrot flower crop texture.  Crop index: " + index);
                    editor.PatchImage(TextureSet.caveCarrotFlowerCrop, new Rectangle?(), new Rectangle?(this.cropRect(index)), PatchMode.Replace);
                }
                catch (Exception)
                {
                }
            }
        }
Ejemplo n.º 4
0
 private bool isModItem(Item currentItem)
 {
     return(currentItem != null && (currentItem.ParentSheetIndex == VoidshroomSpore.getIndex() || currentItem.ParentSheetIndex == CaveCarrotSeed.getIndex()));
 }
Ejemplo n.º 5
0
 private bool isModCrop(Crop crop)
 {
     return(crop.netSeedIndex.Value == CaveCarrotSeed.getIndex() || crop.netSeedIndex.Value == CaveCarrotFlower.getIndex());
 }
Ejemplo n.º 6
0
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            if (isGameReady())
            {
                Item    currentItem = Game1.player.CurrentItem;
                Vector2 tile        = e.Cursor.GrabTile;
                if (e.Button.IsActionButton() || e.Button.IsUseToolButton())
                {
                    GameLocation location = Game1.currentLocation;

                    if (location.terrainFeatures.ContainsKey(tile) && location.terrainFeatures[tile] is HoeDirt)
                    {
                        HoeDirt dirtPatch = location.terrainFeatures[tile] as HoeDirt;
                        if (dirtPatch.crop != null && this.isModCrop(dirtPatch.crop))
                        {
                            int X = (int)tile.X;
                            int Y = (int)tile.Y;
                            if (e.Button.IsActionButton())
                            {
                                dirtPatch.performUseAction(tile, location);
                            }
                            else if (e.Button.IsUseToolButton())
                            {
                                Tool tool = Game1.player.CurrentItem as Tool;
                                dirtPatch.performToolAction(tool, 0, tile, location);
                                dirtPatch.performUseAction(tile, location);
                            }

                            if (dirtPatch.crop == null)
                            {
                                location.terrainFeatures.Remove(tile);
                                return;
                            }
                        }
                    }

                    if (e.Button.IsActionButton())
                    {
                        if (currentItem != null && (this.isModItem(currentItem) || PlantableCaveCarrot.IsValidLocation(location)))
                        {
                            if (currentItem.ParentSheetIndex.Equals(CaveCarrot.HARVEST_INDEX))
                            {
                                this.Monitor.Log("Attempt to plant a cave carrot flower at " + tile.ToString());
                                bool planted = PlantableCaveCarrot.AttemptPlanting(tile, location);
                                if (planted)
                                {
                                    Game1.player.reduceActiveItemByOne();
                                    this.Helper.Input.Suppress(e.Button);
                                    return;
                                }
                            }
                            else if (currentItem.ParentSheetIndex.Equals(VoidshroomSpore.getIndex()))
                            {
                                this.Monitor.Log("Attempt to plant a new voidshroom tree at " + e.Cursor.GrabTile.ToString());
                                bool planted = VoidshroomSpore.AttemptPlanting(tile, Game1.currentLocation);
                                if (planted)
                                {
                                    Game1.player.reduceActiveItemByOne();
                                    return;
                                }
                            }
                            else if (currentItem.ParentSheetIndex.Equals(CaveCarrotSeed.getIndex()))
                            {
                                this.Monitor.Log("Attempt to plant a cave carrot at " + e.Cursor.GrabTile.ToString());
                                bool planted = CaveCarrotSeed.AttemptPlanting(tile, Game1.currentLocation, Game1.player);
                                if (planted)
                                {
                                    Game1.player.reduceActiveItemByOne();
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }