Ejemplo n.º 1
0
        public static void setUpShopOwner_Postfix(string who, ref StardewValley.Menus.ShopMenu __instance)
        {
            try
            {
                if ("Traveler".Equals(who) || //traveler's shop (default)
                    ("TravelerNightMarket").Equals(who)) //traveler's shop (night market)
                {
                    NPC suki = new NPC();
                    suki.Portrait             = Game1.content.Load <Texture2D>("Portraits\\Suki");
                    __instance.portraitPerson = suki;
                }
                else if (Game1.dayOfMonth == 8 && Game1.currentSeason == "winter" && Game1.player.currentLocation.NameOrUniqueName == "Temp") //ice festival shop
                {
                    NPC suki = new NPC();
                    suki.Portrait             = Game1.content.Load <Texture2D>("Portraits\\Suki_IceFestival");
                    __instance.portraitPerson = suki;

                    //imitate skipped code from the original method, adding a dialogue window beneath the portrait
                    string ppDialogue = Game1.content.LoadString("Strings\\StringsFromCSFiles:ShopMenu.cs.11457");
                    __instance.potraitPersonDialogue = Game1.parseText(ppDialogue, Game1.dialogueFont, 304);
                }
            }
            catch (Exception ex)
            {
                modInstance.Monitor.LogOnce($"Harmony patch \"{nameof(setUpShopOwner_Postfix)}\" has encountered an error and may not function correctly:\n{ex.ToString()}", LogLevel.Error);
            }
        }
Ejemplo n.º 2
0
        /**
         * <summary>Modifies shop prices to account for current events.</summary>
         *
         * <param name="helper">The helper to use for reflection.</param>
         * <param name="menu">The menu to update.</param>
         */
        public void UpdateShopMenu(IModHelper helper, StardewValley.Menus.ShopMenu menu)
        {
            Dictionary <Item, int[]> shopItems = helper.Reflection.GetField <Dictionary <Item, int[]> >(menu, "itemPriceAndStock").GetValue();

            foreach (var evnt in this.currentEvents)
            {
                var itemID        = evnt.AffectedItem;
                var percent       = evnt.PercentChange;
                var matchingItems = shopItems.Keys.OfType <Object>().Where(o => o.parentSheetIndex == itemID);
                foreach (var item in matchingItems)
                {
                    shopItems[item][0] += (shopItems[item][0] * percent) / 100;
                }
            }
        }
        //Used to start the birthday
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            // Ignore if player hasn't loaded a save yet
            if (!Context.IsWorldReady)
            {
                return;
            }

            // If the B button is pressed (by the host)
            if (!bPressed && e.Button == SButton.B && Game1.player.IsMainPlayer)
            {
                this.Monitor.Log("Scheduled a celebration for tomorrow!", LogLevel.Info);
                Game1.addHUDMessage(new HUDMessage("Mail delivered!", 1));

                bPressed = true;

                // Send a message to the farmhand
                MyMessage message = new MyMessage();
                this.Helper.Multiplayer.SendMessage(message, "StartBirthdayEvent", modIDs: new[] { this.ModManifest.UniqueID });

                /*
                 * // In case they already have the birthday email, remove it
                 * if (Game1.player.mailReceived.Contains("WizardBirthdayMail"))
                 * {
                 *  Game1.player.mailReceived.Remove("WizardBirthdayMail");
                 * }
                 *
                 * //Create the letter
                 * Helper.Content.AssetEditors.Add(new BirthdayLetter());
                 *
                 * //Send the letter for tomorrow
                 * Game1.addMailForTomorrow("WizardBirthdayMail");
                 */

                //This will start the birthday in the next morning
                this.helper.Events.GameLoop.DayStarted += this.OnDayStarted;

                //Set the weather for tomorrow to sunny :D
                Game1.weatherForTomorrow = 4;
            }


            // On mouse click
            if (alreadyStarted && Game1.player.currentLocation.Name.Equals("Town") && (e.Button.IsActionButton() || e.Button.IsUseToolButton()) && Game1.overlayMenu == null && !Game1.player.IsMainPlayer)
            {
                ICursorPosition cursorPos = this.Helper.Input.GetCursorPosition();
                Vector2         pos       = cursorPos.GrabTile;

                // Check for shop
                // This is called when right clicking on Robin-Wizard
                if (pos == npcPosition && e.Button.IsActionButton())
                {
                    if (allRosesFound)
                    {
                        // Unhook music track change
                        helper.Events.Player.Warped -= OnPlayerWarped;

                        this.Monitor.Log("Click on Wizard", LogLevel.Info);

                        // Activate shop
                        shop = new StardewValley.Menus.ShopMenu(items, 0, null);

                        Game1.activeClickableMenu = shop;

                        //https://github.com/AdamMcIntosh/StawdewValley/blob/master/Menus/ShopMenu.cs
                    }
                    else
                    {
                        // Send a message
                        string message = "You have to find all 26 flowers before you can talk to the Wizard!";
                        Game1.activeClickableMenu = new StardewValley.Menus.DialogueBox(message);
                    }
                }

                // Check to pick roses
                if (!allRosesFound)
                {
                    // Check if a rose has been found
                    for (int i = 0; i < 26; i++)
                    {
                        if (pos == rosesPositions[i])
                        {
                            rosesFound[i] = true;
                            this.Monitor.Log($"Summer spangle {i} picked", LogLevel.Info);

                            // Spawn some butterflies
                            Random rnd = new Random();

                            for (int j = 0; j < 7; j++)
                            {
                                Butterfly b = new Butterfly(new Vector2((int)pos.X, (int)pos.Y));

                                Game1.getLocationFromName("Town").addCritter(b);
                            }
                        }
                    }

                    // Set to true when all the roses have been found
                    allRosesFound = CheckAllRosesPicked();

                    // Send a message
                    if (allRosesFound)
                    {
                        string message = "You have found all the flowers! ^Go talk to the Wizard!";
                        Game1.activeClickableMenu = new StardewValley.Menus.DialogueBox(message);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        //Used to start the birthday
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            // Ignore if player hasn't loaded a save yet
            if (!Context.IsWorldReady)
            {
                return;
            }

            // If the B button is pressed
            if (!bPressed && e.Button == SButton.B)
            {
                this.Monitor.Log("Tomorrow birthday :D", LogLevel.Info);

                bPressed = true;

                // In case they already have the birthday email, remove it
                if (Game1.player.mailReceived.Contains("Birthday"))
                {
                    Game1.player.mailReceived.Remove("Birthday");
                }

                //Create the letter
                Helper.Content.AssetEditors.Add(new BirthdayLetter());

                //Send the letter for tomorrow
                Game1.addMailForTomorrow("Birthday");

                //This will start the birthday in the next morning
                this.helper.Events.GameLoop.DayStarted += this.OnDayStarted;

                //Set the weather for tomorrow to sunny :D
                Game1.weatherForTomorrow = 4;
            }

            // On mouse click
            if (alreadyStarted && Game1.player.currentLocation.Name.Equals("Town") && (e.Button == SButton.MouseLeft || e.Button == SButton.MouseRight))
            {
                ICursorPosition cursorPos = this.Helper.Input.GetCursorPosition();
                Vector2         pos       = cursorPos.GrabTile;

                // Check for shop
                // This is called when right clicking on Robin
                if (pos == npcPosition && e.Button == SButton.MouseRight)
                {
                    if (allRosesFound)
                    {
                        this.Monitor.Log("Click on Robin", LogLevel.Info);

                        // Activate shop
                        shop = new StardewValley.Menus.ShopMenu(items, 0, null);

                        Game1.activeClickableMenu = shop;

                        //https://github.com/AdamMcIntosh/StawdewValley/blob/master/Menus/ShopMenu.cs
                    }
                    else
                    {
                        // Send a message
                        string message = "You have to find all the roses before you can talk to Robin!";
                        Game1.activeClickableMenu = new StardewValley.Menus.DialogueBox(message);
                    }
                }

                // Check to pick roses
                if (!allRosesFound)
                {
                    // Check if a rose has been found
                    for (int i = 0; i < 7; i++)
                    {
                        if (pos == rosesPositions[i])
                        {
                            rosesFound[i] = true;
                            this.Monitor.Log("Rose picked", LogLevel.Info);

                            // Spawn some butterflies
                            Random rnd = new Random();

                            for (int j = 0; j < 10; j++)
                            {
                                Butterfly b = new Butterfly(new Vector2((int)pos.X, (int)pos.Y));

                                Game1.getLocationFromName("Town").addCritter(b);
                            }
                        }
                    }

                    // Set to true when all the roses have been found
                    allRosesFound = CheckAllRosesPicked();

                    // Send a message
                    if (allRosesFound)
                    {
                        string message = "You have found all the roses! ^Go talk to Robin!";
                        Game1.activeClickableMenu = new StardewValley.Menus.DialogueBox(message);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void OnMenuChanged(object sender, MenuChangedEventArgs e)
        {
            if (e != null)
            {
                currentMenu = e.NewMenu;
                if (currentMenu != null)
                {
                    if (currentMenu is StardewValley.Menus.ShopMenu)
                    {
                        StardewValley.Menus.ShopMenu shopMenu = (StardewValley.Menus.ShopMenu)currentMenu;

                        if (shopMenu != null && shopMenu.portraitPerson != null && shopMenu.portraitPerson.Name == "Marnie")
                        {
                            IReflectedField <Dictionary <ISalable, int[]> > inventoryInformation = Helper.Reflection.GetField <Dictionary <ISalable, int[]> >(shopMenu, "itemPriceAndStock");
                            Dictionary <ISalable, int[]> itemPriceAndStock = null;
                            if (inventoryInformation != null)
                            {
                                itemPriceAndStock = inventoryInformation.GetValue();
                            }
                            IReflectedField <List <ISalable> > forSaleInformation = Helper.Reflection.GetField <List <ISalable> >(shopMenu, "forSale");
                            List <ISalable> forSale = null;
                            if (forSaleInformation != null)
                            {
                                forSale = forSaleInformation.GetValue();
                            }

                            if (forSale != null && itemPriceAndStock != null)
                            {
                                Item milk = new StardewValley.Object(184, config.numMilkToStock, false, -1, 0);
                                itemPriceAndStock.Add(milk, new[] { milk.salePrice() * 3, milk.Stack });
                                if (!forSale.Contains(milk))
                                {
                                    forSale.Add(milk);
                                }

                                List <Item> eggsToAdd = GetEggsOfTheDay();
                                if (eggsToAdd != null)
                                {
                                    foreach (Item eggToAdd in eggsToAdd)
                                    {
                                        itemPriceAndStock.Add(eggToAdd, new[] { eggToAdd.salePrice() * 5, eggToAdd.Stack });
                                        if (!forSale.Contains(eggToAdd))
                                        {
                                            forSale.Add(eggToAdd);
                                        }
                                    }
                                }

                                inventoryInformation.SetValue(itemPriceAndStock);
                                forSaleInformation.SetValue(forSale);
                            }
                        }
                    }
                    else if (currentMenu is StardewValley.Menus.DialogueBox)
                    {
                        StardewValley.Menus.DialogueBox dialogueBox = (StardewValley.Menus.DialogueBox)currentMenu;
                        if (eventText != "")
                        {
                            if (dialogueBox != null && dialogueBox.getCurrentString() == "??")
                            {
                                string eventTextClone = eventText;
                                Game1.drawObjectDialogue(eventTextClone);
                            }
                            eventText = "";
                        }
                    }
                }
            }
        }