Esempio n. 1
0
        /* GameEvents_OnUpdateTick
         * Triggers every time the menu changes.
         * Handles the setup of the SBobberBar, used to detect if the player is fishing.
         */
        private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
        {
            if (e.NewMenu is BobberBar bobberBarMenu)
            {
                this.Bobber = SBobberBar.ConstructFromBaseClass(bobberBarMenu);
            }

            // Player just caught a fish, but inventory is full
            if (e.NewMenu is ItemGrabMenu itemGrabMenu && e.PriorMenu is DialogueBox && FishItem.itemToAdd != null)
            {
                Item itemToChange = null;

                foreach (Item item in itemGrabMenu.ItemsToGrabMenu.actualInventory)
                {
                    // Item is a fish
                    if (item.Category == -4)
                    {
                        itemToChange = item;
                    }
                }

                if (itemToChange != null)
                {
                    itemGrabMenu.ItemsToGrabMenu.actualInventory.Remove(itemToChange);
                    itemGrabMenu.ItemsToGrabMenu.actualInventory.Add(FishItem.itemToAdd);
                }
            }
        }
Esempio n. 2
0
        /* GameEvents_OnUpdateTick
         * Triggers 60 times per second.
         * Use one of the methods here https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Events#Game for other time durations
         */
        private void GameEvents_OnUpdateTick(object sender, EventArgs e)
        {
            if (Game1.player.CurrentTool is FishingRod rod)
            {
                if (rod.fishCaught && !this.PlayerReceivedFish)
                {
                    // Prevents the mod from giving the player 1 fish per tick ;)
                    this.PlayerReceivedFish = true;

                    this.whichFish = this.Helper.Reflection.GetField <int>(rod, "whichFish").GetValue();

                    // construct a temporary fish item to figure out what the caught fish's name is
                    FishItem tempFish = new FishItem(this.whichFish);

                    if (tempFish.Category == -4)   // is a fish

                    // get the list of fish in the Population with that name
                    {
                        List <FishModel> fishOfType;
                        this.population.TryGetValue(tempFish.Name, out fishOfType);

                        // get a random fish of that type from the population
                        int       numFishOfType     = fishOfType.Count;
                        int       selectedFishIndex = ModEntry.rand.Next(0, numFishOfType);
                        FishModel selectedFish      = fishOfType[selectedFishIndex];

                        this.Helper.Reflection.GetField <int>(rod, "fishSize").SetValue((int)Math.Round(selectedFish.length));

                        // store a new custom fish item
                        Item customFish = (Item) new FishItem(this.whichFish, selectedFish);
                        FishItem.itemToAdd = customFish as FishItem;
                        this.FishCaught    = customFish;

                        // make sure the fish in the ocean will be regenerated at the end of the day
                        this.AllFishCaughtToday.Add(new Tuple <string, int>(selectedFish.name, selectedFish.uniqueID));

                        // Prompt the player to throw back the fish
                        this.PromptThrowBackFish(selectedFish.name, selectedFish.uniqueID);
                    }
                }
            }


            if (Game1.activeClickableMenu is BobberBar && this.Bobber != null)
            {
                SBobberBar bobber = this.Bobber;

                if (!this.BeganFishingGame)
                {
                    this.OnFishingBegin();
                    this.PlayerReceivedFish = false;
                    this.BeganFishingGame   = true;
                }
            }
            else if (this.EndedFishingGame)
            {
                this.OnFishingEnd();
                this.EndedFishingGame = false;
            }
            else if (this.BeganFishingGame)
            {
                {}

                this.EndedFishingGame = true;
                this.BeganFishingGame = false;
            }
        }