Ejemplo n.º 1
0
        public static void TryCloseItemGrabMenu(ItemGrabMenu menu)
        {
            if (!menu.areAllItemsTaken() || menu.heldItem != null)
            {
                return;
            }

            if (menu.shippingBin || ShippingEstimationInfoBox.IsCaShippingBinMenu(menu))
            {
                //It's a shipping bin.
                return;
            }

            if (menu.context is Event && GetEssential(menu))
            {
                // You should not emergency close in events (it may stop the dialogue).
                return;
            }

            switch (menu.source)
            {
            case ItemGrabMenu.source_chest:
            case ItemGrabMenu.source_none when menu.context == null:
                return;     // It's a chest.
            }

            menu.exitThisMenu();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Determine whether the menu should be closed or not on an error
 /// </summary>
 /// <param name="menu">the inventory to check</param>
 /// <param name="msg">Added to the error message</param>
 private void HandleItemGrabMenuError(ItemGrabMenu menu, string msg)
 {
     log.Info($"There was an error getting all menu items - {msg}");
     if (config.pauseTreasureOnError)
     {
         log.Trace("Pausing collection until resolved.");
     }
     else
     {
         log.Info("Option pauseTreasureOnError is false, continuing with loss of treasure");
         menu.exitThisMenu(true);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Update mod state.  Try to keep processing quick here.
        /// </summary>
        public void OnUpdate()
        {
            if (!(Game1.player.CurrentTool is FishingRod))
            {
                return;
            }

            FishingRod currentTool = Game1.player.CurrentTool as FishingRod;

            // Could set up a state machine to track this, but for now just check either in the minigame or not.
            if (Game1.activeClickableMenu is BobberBar && currentTool.isFishing)
            {
                PlayFishMinigame();
            }
            else
            {
                // Do everything else the mod does outside of the fishing game.
                // If this is the first time out of the fishing game, clear the data.
                if (this.inFishingMenu)
                {
                    log.Silly("Left Fishing minigame, clearing memory");
                    this.UnloadSVReflectionObjects();
                    this.inFishingMenu            = false;
                    IsButtonDownHack.simulateDown = false;
                }

                // This might be where a state machine might help, as an extra check, (e.g can't set power if you're not done casting, etc...)
                // but the SV tool API seems to give us enough data to have a go at it just checking conditionals.

                // Sequential steps to automate fishing
                if (config.autoCast && ShouldDoAutoCast(currentTool))
                {
                    log.Trace("Attempting to cast for the user");
                    currentTool.beginUsing(Game1.currentLocation,
                                           Game1.player.getStandingX(),
                                           Game1.player.getStandingY(),
                                           Game1.player);
                }

                if (config.maxCastPower && ShouldSetCastingPower(currentTool))
                {
                    log.Trace("Modifying cast to max cast power");
                    // Apparently for max to be registered it needs to be > 1.0, but anything over increases the
                    // power bar past the UI, so make it a small number.  Also, 1.001F is too small.
                    currentTool.castingPower = 1.01F;
                }

                if (config.quickHook && ShouldSetQuickHook(currentTool))
                {
                    log.Trace("Modifying cast so fish will bite quickly.");
                    // Game uses fishingBiteAccumulator as the value that gets modified so we should only modify that one
                    // and let the game increase it and handle logic as they become equal.  Change the gap if it doesn't
                    // generate a quick hit quick enough.
                    currentTool.fishingBiteAccumulator = currentTool.timeUntilFishingBite - fishingBiteAccumulatorGap;
                }

                if (config.autoHook && ShouldDoAutoHook(currentTool))
                {
                    log.Trace("Executing hook function for FishingRod");
                    currentTool.DoFunction(Game1.currentLocation,
                                           Game1.player.getStandingX(),
                                           Game1.player.getStandingY(),
                                           (int)currentTool.castingPower,
                                           Game1.player);
                }

                // Click away the catched fish.  The conditionals are ordered here in a way
                // the check for the popup happens before the config check so the code can
                // always check the treasure chest.  See the variable doneCaughtFish for more
                // info.
                if (ShouldDoDismissCaughtPopup(currentTool))
                {
                    log.Trace("Tool is sitting at caught fish popup");
                    doneCaughtFish = true;

                    if (config.autoFinish && config.HarmonyLoad)
                    {
                        log.Trace("Closing popup with Harmony");
                        ClickAtAllHack.simulateClick = true;
                    }
                }
                else
                {
                    if (ClickAtAllHack.simulateClick)
                    {
                        log.Trace("Turning off Harmony injection for caught fish popup");
                        ClickAtAllHack.simulateClick = false;
                    }
                }

                // Deal with any treasure that has popped up
                if (ShouldDoProcessTreasure(currentTool) && doneCaughtFish)
                {
                    log.Trace("Found treasure after the caught fish popup");
                    doneCaughtFish = false;
                    if (config.autoFinish)
                    {
                        log.Trace("Acquiring treasure");
                        ItemGrabMenu m = Game1.activeClickableMenu as ItemGrabMenu;
                        if (m.ItemsToGrabMenu != null && m.ItemsToGrabMenu.actualInventory != null)
                        {
                            if (AcquireTreasure(m.ItemsToGrabMenu.actualInventory))
                            {
                                m.exitThisMenu(true);
                            }
                            else
                            {
                                HandleItemGrabMenuError(m, "might be full inventory");
                            }
                        }
                        else
                        {
                            HandleItemGrabMenuError(m, "treasure chest is open, but inventory is null");
                        }
                    }
                }
            }
        }