Beispiel #1
0
        void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e)
        {
            Vector2 grabTile = e.Cursor.GrabTile;

            if (Game1.currentLocation != null && Game1.activeClickableMenu == null && e.Button.IsActionButton())
            {
                if (Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y) is Object obj && obj != null && obj.Name.Equals("Seed Maker"))
                {
                    if (obj.heldObject?.Value != null && obj.heldObject?.Value.Category == Object.SeedsCategory && obj.readyForHarvest && Game1.player.couldInventoryAcceptThisObject(obj.heldObject.Value.ParentSheetIndex, obj.heldObject.Value.Stack))
                    {
                        //Monitor.Log("Detected Seeds in Seed Maker", LogLevel.Alert);
                        //Cultivation.NewSeeds(obj.heldObject.Value.ParentSheetIndex); //TODO should be unneccessary now
                    }
                    else if (obj.heldObject?.Value == null && Game1.player.ActiveObject?.Category == Object.SeedsCategory)
                    {
                        if (Cultivation.GetCropItemFromSeeds(Game1.player.ActiveObject) is Object crop)
                        {
                            Game1.activeClickableMenu = new SeedsInfoMenu(Game1.player.ActiveObject, crop, false);
                        }
                    }
                }
                else if (Game1.currentLocation is Farm farm && farm.getBuildingAt(grabTile) is CompostingBin && Game1.player.ActiveObject?.Category == Object.SeedsCategory)
                {
                    if (Cultivation.GetCropItemFromSeeds(Game1.player.ActiveObject) is Object crop)
                    {
                        Game1.activeClickableMenu = new SeedsInfoMenu(Game1.player.ActiveObject, crop, true);
                    }
                }
Beispiel #2
0
        void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e)
        {
            Vector2 grabTile = e.Cursor.GrabTile;

            //Monitor.Log($"obj: {Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y)?.Name}");
            //Object obj2 = Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y);
            //Monitor.Log("1" + (obj2 is Object && obj2 != null));
            //Monitor.Log("2" + (e.Button.IsActionButton()));
            //Monitor.Log("3" + obj2.Name.Equals("Seed Maker"));
            //Monitor.Log("4" + (obj2.heldObject?.Value != null));
            //Monitor.Log("5" + obj2.heldObject.Value.CanBeGrabbed);
            if (Game1.currentLocation != null && Game1.activeClickableMenu == null && Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y) is Object obj && obj != null &&
                e.Button.IsActionButton() && obj.Name.Equals("Seed Maker"))
            {
                if (obj.heldObject?.Value != null && obj.heldObject?.Value.Category == Object.SeedsCategory && obj.readyForHarvest && Game1.player.couldInventoryAcceptThisObject(obj.heldObject.Value.ParentSheetIndex, obj.heldObject.Value.Stack))
                {
                    //Monitor.Log("Detected Seeds in Seed Maker", LogLevel.Alert);
                    Cultivation.NewSeeds(obj.heldObject.Value.ParentSheetIndex);
                }
                else if (obj.heldObject?.Value == null && Game1.player.ActiveObject?.Category == Object.SeedsCategory)
                {
                    if (Cultivation.GetCropItemFromSeeds(Game1.player.ActiveObject) is Object crop)
                    {
                        Game1.activeClickableMenu = new SeedsInfoMenu(Game1.player.ActiveObject, crop);
                    }
                }
            }

            /*if (e.Button.IsActionButton() && Game1.currentLocation is Farm farm && Game1.activeClickableMenu == null && Composting.IsComposter(farm.getBuildingAt(grabTile)))
             * {
             *  Game1.activeClickableMenu = new ComposterMenu();
             * }*/
        }
Beispiel #3
0
        private void onDigBug(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs args)
        {
            if (Game1.CurrentEvent != null)
            {
                return;
            }
            if (!args.Button.IsUseToolButton() || !(Game1.player.CurrentTool is StardewValley.Tools.Hoe))
            {
                return;
            }

            Vector2 tile = new Vector2((int)Game1.player.GetToolLocation(false).X / Game1.tileSize + 0.5f, (int)Game1.player.GetToolLocation(false).Y / Game1.tileSize + 0.5f);

            DisturbBug("", Game1.currentLocation, tile, "Back");
        }
Beispiel #4
0
        private void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e)
        {
            if (e.IsSuppressed())
            {
                return;                   //already eaten by someone else.
            }
            //check for Character or Action activation
            if (!Game1.eventUp)
            {
                if (e.Button.IsActionButton() || e.Button.IsUseToolButton())
                {
                    if (Context.IsPlayerFree)
                    {
                        //get the target tile
                        Vector2 vector = new Vector2(Game1.getOldMouseX() + Game1.viewport.X, Game1.getOldMouseY() + Game1.viewport.Y) / 64f;
                        if (Game1.mouseCursorTransparency == 0f || !Game1.wasMouseVisibleThisFrame || (!Game1.lastCursorMotionWasMouse && (Game1.player.ActiveObject == null || (!Game1.player.ActiveObject.isPlaceable() && Game1.player.ActiveObject.Category != -74))))
                        {
                            vector = Game1.player.GetGrabTile();
                            if (vector.Equals(Game1.player.getTileLocation()))
                            {
                                vector = Utility.getTranslatedVector2(vector, Game1.player.FacingDirection, 1f);
                            }
                        }
                        if (!Utility.tileWithinRadiusOfPlayer((int)vector.X, (int)vector.Y, 1, Game1.player))
                        {
                            vector = Game1.player.GetGrabTile();
                            if (vector.Equals(Game1.player.getTileLocation()) && Game1.isAnyGamePadButtonBeingPressed())
                            {
                                vector = Utility.getTranslatedVector2(vector, Game1.player.FacingDirection, 1f);
                            }
                        }

                        //check characters
                        NPC character = Game1.currentLocation.isCharacterAtTile(vector);
                        if (character != null)
                        {
                            var argsResult = Modworks.Events.NPCCheckActionEvent(Game1.player, character);
                            if (argsResult.Cancelled)
                            {
                                Helper.Input.Suppress(e.Button);
                            }
                        }
                        else
                        {
                            vector    = Utility.getTranslatedVector2(vector, Game1.player.FacingDirection, 0f);
                            vector.Y += 1;
                            character = Game1.currentLocation.isCharacterAtTile(vector);
                            if (character != null)
                            {
                                var argsResult = Modworks.Events.NPCCheckActionEvent(Game1.player, character);
                                if (argsResult.Cancelled)
                                {
                                    Helper.Input.Suppress(e.Button);
                                }
                            }
                            else
                            {
                                vector    = Game1.player.getTileLocation();
                                character = Game1.currentLocation.isCharacterAtTile(vector);
                                if (character != null)
                                {
                                    var argsResult = Modworks.Events.NPCCheckActionEvent(Game1.player, character);
                                    if (argsResult.Cancelled)
                                    {
                                        Helper.Input.Suppress(e.Button);
                                    }
                                }
                            }
                        }

                        //reset the target tile
                        vector = new Vector2(Game1.getOldMouseX() + Game1.viewport.X, Game1.getOldMouseY() + Game1.viewport.Y) / 64f;
                        if (Game1.mouseCursorTransparency == 0f || !Game1.wasMouseVisibleThisFrame || (!Game1.lastCursorMotionWasMouse && (Game1.player.ActiveObject == null || (!Game1.player.ActiveObject.isPlaceable() && Game1.player.ActiveObject.Category != -74))))
                        {
                            vector = Game1.player.GetGrabTile();
                            if (vector.Equals(Game1.player.getTileLocation()))
                            {
                                vector = Utility.getTranslatedVector2(vector, Game1.player.FacingDirection, 1f);
                            }
                        }
                        if (!Utility.tileWithinRadiusOfPlayer((int)vector.X, (int)vector.Y, 1, Game1.player))
                        {
                            vector = Game1.player.GetGrabTile();
                            if (vector.Equals(Game1.player.getTileLocation()) && Game1.isAnyGamePadButtonBeingPressed())
                            {
                                vector = Utility.getTranslatedVector2(vector, Game1.player.FacingDirection, 1f);
                            }
                        }

                        //check Actions in tiledata
                        string value = Game1.currentLocation.doesTileHaveProperty((int)vector.X, (int)vector.Y, "Action", "Buildings");
                        if (!string.IsNullOrWhiteSpace(value))
                        {
                            var argsResult = Modworks.Events.TileCheckActionEvent(Game1.player, Game1.currentLocation, vector, value);
                            if (argsResult.Cancelled)
                            {
                                Helper.Input.Suppress(e.Button);
                            }
                            else if (value.Split(' ')[0] == "Garbage" && DoTrashLoot(value))
                            {
                                Helper.Input.Suppress(e.Button);
                            }
                        }
                        else
                        {
                            vector    = Utility.getTranslatedVector2(vector, Game1.player.FacingDirection, 0f);
                            vector.Y += 1;
                            value     = Game1.currentLocation.doesTileHaveProperty((int)vector.X, (int)vector.Y, "Action", "Buildings");
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                var argsResult = Modworks.Events.TileCheckActionEvent(Game1.player, Game1.currentLocation, vector, value);
                                if (argsResult.Cancelled)
                                {
                                    Helper.Input.Suppress(e.Button);
                                }
                                else if (value.Split(' ')[0] == "Garbage" && DoTrashLoot(value))
                                {
                                    Helper.Input.Suppress(e.Button);
                                }
                            }
                            else
                            {
                                vector = Game1.player.getTileLocation();
                                value  = Game1.currentLocation.doesTileHaveProperty((int)vector.X, (int)vector.Y, "Action", "Buildings");
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    var argsResult = Modworks.Events.TileCheckActionEvent(Game1.player, Game1.currentLocation, vector, value);
                                    if (argsResult.Cancelled)
                                    {
                                        Helper.Input.Suppress(e.Button);
                                    }
                                    else if (value.Split(' ')[0] == "Garbage" && DoTrashLoot(value))
                                    {
                                        Helper.Input.Suppress(e.Button);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }