Exemplo n.º 1
0
        /// <summary>
        /// Create the shoplifting menu and determine what to do depending on the option pressed
        /// </summary>
        /// <param name="location">The current location instance</param>
        /// <param name="shopkeepers">A list of npcs that can ban the player if caught</param>
        /// <param name="shop">The shop the menu is for</param>
        /// <param name="maxstock">The max number of stock items to generate</param>
        /// <param name="maxquantity">The max quantity of each stock item to generate</param>
        /// <param name="islandvisit">Whether the owner is on the island, special menu case if true</param>
        /// <param name="bannable">Whether the player can be banned from the shop</param>
        public static void ShopliftingMenu(GameLocation location, string[] shopkeepers, string shop, int maxstock, int maxquantity, bool islandvisit = false, bool bannable = true)
        {
            // Check player hasn't reached daily shoplifting limit
            if (ModEntry.PerScreenShopliftCounter.Value >= config.MaxShopliftsPerDay)
            {
                // Player has reached limit, exit method after displaying dialogue box
                Game1.drawObjectDialogue(config.MaxShopliftsPerDay != 1
                        ? i18n.string_AlreadyShoplifted()
                        : i18n.string_AlreadyShoplifted_Single());
                return;
            }

            // Check player hasn't reached daily shoplifting limit for the shop
            else if (config.MaxShopliftsPerStore > 1 && ModEntry.PerScreenShopliftedShops.Value.ContainsKey(shop) == true && ModEntry.PerScreenShopliftedShops.Value[shop] >= config.MaxShopliftsPerStore)
            {
                // Player has reached limit, exit method after displaying dialogue box
                Game1.drawObjectDialogue(i18n.string_AlreadyShopliftedSameShop());
                return;
            }

            // Create option to steal
            location.createQuestionDialogue(i18n.string_Shoplift(), location.createYesNoResponses(), delegate(Farmer _, string answer)
            {
                // Player answered yes
                if (answer == "Yes")
                {
                    SeenShoplifting(location, Game1.player);

                    // Player is caught
                    if (ShouldBeCaught(shopkeepers, Game1.player, location) == true)
                    {
                        // After dialogue, apply penalties
                        Game1.afterDialogues = delegate
                        {
                            ShopliftingPenalties(location, bannable);
                        };

                        return;
                    }

                    // Set stolen to true so counters will increment
                    ModEntry.PerScreenStolen.Value = false;

                    // Not caught, generate stock for shoplifting, on purchase adjust counters
                    Game1.activeClickableMenu = new ShopMenu(ShopStock.generateRandomStock(maxstock, maxquantity, shop), 3, null, delegate
                    {
                        if (ModEntry.PerScreenStolen.Value == false)
                        {
                            // Increment times shoplifted by one
                            ModEntry.PerScreenShopliftCounter.Value++;
                        }

                        if (config.MaxShopliftsPerStore > 1 && ModEntry.PerScreenShopliftedShops.Value.ContainsKey(shop) == false)
                        {
                            // Add shop to list of shoplifted shops if needed
                            ModEntry.PerScreenShopliftedShops.Value.Add(shop, 1);
                        }

                        else if (ModEntry.PerScreenStolen.Value == false && config.MaxShopliftsPerStore > 1 && ModEntry.PerScreenShopliftedShops.Value.ContainsKey(shop) == true)
                        {
                            // Shop on shoplifted list, increment value by one
                            ModEntry.PerScreenShopliftedShops.Value[shop]++;
                        }

                        // Set stolen to false so counters won't increment on next purchase while in shoplifting window, will become true next time window opens so it can increment again
                        ModEntry.PerScreenStolen.Value = true;

                        return(false);
                    }, null, "");
                }

                else if (answer != "Yes" && islandvisit == true)
                {
                    switch (shop)
                    {
                    case "SeedShop":
                        Game1.activeClickableMenu = new ShopMenu((location as SeedShop).shopStock());
                        break;

                    case "Carpenters":
                        Game1.activeClickableMenu = new ShopMenu(Utility.getCarpenterStock());
                        break;

                    case "AnimalShop":
                        Game1.activeClickableMenu = new ShopMenu(Utility.getAnimalShopStock());
                        break;

                    case "Saloon":
                        Game1.activeClickableMenu = new ShopMenu(Utility.getSaloonStock(), 0, null, delegate(ISalable item, Farmer farmer, int amount)
                        {
                            Game1.player.team.synchronizedShopStock.OnItemPurchased(SynchronizedShopStock.SynchedShop.Saloon, item, amount);
                            return(false);
                        });
                        break;

                    default:
                        break;
                    }
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates a random list of stock for the given shop
        /// </summary>
        /// <param name="maxstock">The maximum number of different stock items to generate</param>
        /// <param name="maxquantity">The maximum quantity of each stock</param>
        /// <param name="which">The shop to generate stock for</param>
        /// <returns>The generated stock list</returns>
        public static Dictionary <ISalable, int[]> generateRandomStock(int maxstock, int maxquantity, string which)
        {
            GameLocation location = Game1.currentLocation;
            Dictionary <ISalable, int[]> stock = new Dictionary <ISalable, int[]>();
            HashSet <int> stockIndices         = new HashSet <int>();
            Random        random     = new Random((int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.DaysPlayed + ModEntry.PerScreenShopliftCounter.Value);
            int           stocklimit = random.Next(1, maxstock + 1);
            int           index;

            switch (which)
            {
            // Pierre's shop
            case "SeedShop":
                foreach (var shopstock in (location as SeedShop).shopStock())
                {
                    // Stops illegal stock being added, will result in an error item
                    if ((shopstock.Key as StardewValley.Object) == null || (shopstock.Key as Wallpaper) != null || (shopstock.Key as Furniture) != null || (shopstock.Key as StardewValley.Object).bigCraftable == true || (shopstock.Key as StardewValley.Object).IsRecipe == true || (shopstock.Key as Clothing) != null || (shopstock.Key as Ring) != null || (shopstock.Key as Boots) != null || (shopstock.Key as Hat) != null)
                    {
                        continue;
                    }

                    // Add object id to array
                    if ((shopstock.Key as StardewValley.Object) != null && (shopstock.Key as StardewValley.Object).bigCraftable == false)
                    {
                        index = (shopstock.Key as StardewValley.Object).parentSheetIndex;

                        CurrentStock.Add(index);
                    }
                }
                break;

            // Willy's shop
            case "FishShop":
                foreach (var shopstock in Utility.getFishShopStock(Game1.player))
                {
                    // Stops illegal stock being added, will result in an error item
                    if ((shopstock.Key as StardewValley.Object) == null || (shopstock.Key as Wallpaper) != null || (shopstock.Key as Furniture) != null || (shopstock.Key as StardewValley.Object).bigCraftable == true || (shopstock.Key as StardewValley.Object).IsRecipe == true || (shopstock.Key as Clothing) != null || (shopstock.Key as Ring) != null || (shopstock.Key as Boots) != null || (shopstock.Key as Hat) != null)
                    {
                        continue;
                    }

                    // Add object id to array
                    if ((shopstock.Key as StardewValley.Object) != null && (shopstock.Key as StardewValley.Object).bigCraftable == false)
                    {
                        index = (shopstock.Key as StardewValley.Object).parentSheetIndex;

                        CurrentStock.Add(index);
                    }
                }
                break;

            // Robin's shop
            case "Carpenters":
                foreach (var shopstock in Utility.getCarpenterStock())
                {
                    // Stops illegal stock being added, will result in an error item
                    if ((shopstock.Key as StardewValley.Object) == null || (shopstock.Key as Wallpaper) != null || (shopstock.Key as Furniture) != null || (shopstock.Key as StardewValley.Object).bigCraftable == true || (shopstock.Key as StardewValley.Object).IsRecipe == true || (shopstock.Key as Clothing) != null || (shopstock.Key as Ring) != null || (shopstock.Key as Boots) != null || (shopstock.Key as Hat) != null)
                    {
                        continue;
                    }

                    // Add object id to array
                    if ((shopstock.Key as StardewValley.Object) != null && (shopstock.Key as StardewValley.Object).bigCraftable == false)
                    {
                        index = (shopstock.Key as StardewValley.Object).parentSheetIndex;

                        CurrentStock.Add(index);
                    }
                }
                break;

            // Marnie's shop
            case "AnimalShop":
                foreach (var shopstock in Utility.getAnimalShopStock())
                {
                    // Stops illegal stock being added, will result in an error item
                    if ((shopstock.Key as StardewValley.Object) == null || (shopstock.Key as Wallpaper) != null || (shopstock.Key as Furniture) != null || (shopstock.Key as StardewValley.Object).bigCraftable == true || (shopstock.Key as StardewValley.Object).IsRecipe == true || (shopstock.Key as Clothing) != null || (shopstock.Key as Ring) != null || (shopstock.Key as Boots) != null || (shopstock.Key as Hat) != null)
                    {
                        continue;
                    }

                    // Add object id to array
                    if ((shopstock.Key as StardewValley.Object) != null && (shopstock.Key as StardewValley.Object).bigCraftable == false)
                    {
                        index = (shopstock.Key as StardewValley.Object).parentSheetIndex;

                        CurrentStock.Add(index);
                    }
                }
                break;

            // Clint's shop
            case "Blacksmith":
                foreach (var shopstock in Utility.getBlacksmithStock())
                {
                    // Stops illegal stock being added, will result in an error item
                    if ((shopstock.Key as StardewValley.Object) == null || (shopstock.Key as Wallpaper) != null || (shopstock.Key as Furniture) != null || (shopstock.Key as StardewValley.Object).bigCraftable == true || (shopstock.Key as StardewValley.Object).IsRecipe == true || (shopstock.Key as Clothing) != null || (shopstock.Key as Ring) != null || (shopstock.Key as Boots) != null || (shopstock.Key as Hat) != null)
                    {
                        continue;
                    }

                    // Add object id to array
                    if ((shopstock.Key as StardewValley.Object) != null && (shopstock.Key as StardewValley.Object).bigCraftable == false)
                    {
                        index = (shopstock.Key as StardewValley.Object).parentSheetIndex;

                        CurrentStock.Add(index);
                    }
                }
                break;

            // Gus' shop
            case "Saloon":
                foreach (var shopstock in Utility.getSaloonStock())
                {
                    // Stops illegal stock being added, will result in an error item
                    if ((shopstock.Key as StardewValley.Object) == null || (shopstock.Key as Wallpaper) != null || (shopstock.Key as Furniture) != null || (shopstock.Key as StardewValley.Object).bigCraftable == true || (shopstock.Key as StardewValley.Object).IsRecipe == true || (shopstock.Key as Clothing) != null || (shopstock.Key as Ring) != null || (shopstock.Key as Boots) != null || (shopstock.Key as Hat) != null)
                    {
                        continue;
                    }

                    // Add object id to array
                    if ((shopstock.Key as StardewValley.Object) != null && (shopstock.Key as StardewValley.Object).bigCraftable == false)
                    {
                        index = (shopstock.Key as StardewValley.Object).parentSheetIndex;

                        CurrentStock.Add(index);
                    }
                }
                break;

            // Harvey's shop
            case "HospitalShop":
                foreach (var shopstock in Utility.getHospitalStock())
                {
                    // Stops illegal stock being added, will result in an error item
                    if ((shopstock.Key as StardewValley.Object) == null || (shopstock.Key as Wallpaper) != null || (shopstock.Key as Furniture) != null || (shopstock.Key as StardewValley.Object).bigCraftable == true || (shopstock.Key as StardewValley.Object).IsRecipe == true || (shopstock.Key as Clothing) != null || (shopstock.Key as Ring) != null || (shopstock.Key as Boots) != null || (shopstock.Key as Hat) != null)
                    {
                        continue;
                    }

                    // Add object id to array
                    if ((shopstock.Key as StardewValley.Object) != null && (shopstock.Key as StardewValley.Object).bigCraftable == false)
                    {
                        index = (shopstock.Key as StardewValley.Object).parentSheetIndex;

                        CurrentStock.Add(index);
                    }
                }
                break;

            // Icecream Stand
            case "IceCreamStand":
                CurrentStock.Add(233);
                break;

            // Sandy's shop
            case "SandyShop":
                // Add object id to array
                CurrentStock.Add(802);
                CurrentStock.Add(478);
                CurrentStock.Add(486);
                CurrentStock.Add(494);

                switch (Game1.dayOfMonth % 7)
                {
                case 0:
                    CurrentStock.Add(233);
                    break;

                case 1:
                    CurrentStock.Add(88);
                    break;

                case 2:
                    CurrentStock.Add(90);
                    break;

                case 3:
                    CurrentStock.Add(749);
                    break;

                case 4:
                    CurrentStock.Add(466);
                    break;

                case 5:
                    CurrentStock.Add(340);
                    break;

                case 6:
                    CurrentStock.Add(371);
                    break;
                }
                break;

            default:
                CurrentStock.Add(340);
                break;
            }

            // Add generated stock to store from array
            for (int i = 0; i < stocklimit; i++)
            {
                int quantity = random.Next(1, maxquantity + 1);
                int item     = random.Next(0, CurrentStock.Count);

                ShopStock.addToStock(stock, stockIndices, new StardewValley.Object((int)CurrentStock[item], quantity), new int[2]
                {
                    0,
                    quantity
                });
            }

            // Clear stock array
            CurrentStock.Clear();

            return(stock);
        }