Exemple #1
0
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            if (isGameReady())
            {
                Item currentItem = Game1.player.CurrentItem;

                if (currentItem.ParentSheetIndex == VoidshroomSpore.getIndex() && e.Button.IsActionButton())
                {
                    this.Monitor.Log("Attempt to plant a new voidshroom tree at " + e.Cursor.GrabTile.ToString());
                    bool planted = VoidshroomSpore.AttemptPlanting(e.Cursor.GrabTile, Game1.currentLocation);
                    if (planted)
                    {
                        Game1.player.reduceActiveItemByOne();
                    }
                }
            }
        }
        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;
                                }
                            }
                        }
                    }
                }
            }
        }