コード例 #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);
     }
 }
コード例 #2
0
ファイル: ModEntry.cs プロジェクト: somnomania/smapi-mod-dump
        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;
                                }
                            }
                        }
                    }
                }
            }
        }