Esempio n. 1
0
        /// <summary>
        /// Initialize the ItemStock, doing error checking on the quality, and setting the price to the store price
        /// if none is given specifically for this stock.
        /// Creates the builder
        /// </summary>
        /// <param name="shopName"></param>
        /// <param name="price"></param>
        /// <param name="defaultSellPriceMultiplier"></param>
        /// <param name="priceMultiplierWhen"></param>
        internal void Initialize(string shopName, int price, double defaultSellPriceMultiplier, Dictionary <double, string[]> priceMultiplierWhen)
        {
            ShopName = shopName;
            DefaultSellPriceMultiplier = defaultSellPriceMultiplier;
            PriceMultiplierWhen        = priceMultiplierWhen;

            if (Quality < 0 || Quality == 3 || Quality > 4)
            {
                Quality = 0;
                ModEntry.monitor.Log("Item quality can only be 0,1,2, or 4. Defaulting to 0", LogLevel.Warn);
            }

            CurrencyObjectId = ItemsUtil.GetIndexByName(StockItemCurrency);

            //sets price to the store price if no stock price is given
            if (StockPrice == -1)
            {
                StockPrice = price;
            }
            this._priceMultiplierWhen = priceMultiplierWhen;

            if (IsRecipe)
            {
                Stock = 1;
            }

            _builder = new ItemBuilder(this);
        }
        private static void EditShopStock(string shopName, ref Dictionary <ISalable, int[]> __result)
        {
            if (ShopManager.VanillaShops.ContainsKey(shopName))
            {
                var customStock = ShopManager.VanillaShops[shopName].ItemPriceAndStock;
                ItemsUtil.RemoveSoldOutItems(customStock);
                if (ShopManager.VanillaShops[shopName].ReplaceInsteadOfAdd)
                {
                    __result = customStock;
                }
                else
                {
                    foreach (var key in customStock.Keys)
                    {
                        if (__result.ContainsKey(key))
                        {
                            return;
                        }
                    }

                    if (ShopManager.VanillaShops[shopName].AddStockAboveVanilla)
                    {
                        __result = customStock.Concat(__result).ToDictionary(x => x.Key, x => x.Value);
                    }
                    else
                    {
                        __result = __result.Concat(customStock).ToDictionary(x => x.Key, x => x.Value);
                    }
                }
            }
        }
        internal void CheckItems()
        {
            MarketDay.Log("Checking progression data", LogLevel.Debug);
            if (Levels.Count == 0)
            {
                MarketDay.Log($"    No levels loaded", LogLevel.Error);
            }
            foreach (var level in Levels)
            {
                foreach (var prizeLevel in level.Prizes)
                {
                    var name = prizeLevel.Object;

                    var item = ItemsUtil.GetIndexByName(name);
                    if (item == -1)
                    {
                        MarketDay.Log($"    Could not get index for object: {name}", LogLevel.Warn);
                    }

                    if (name is "Wine" or "Jelly" or "Juice" or "Pickle" or "Roe" or "Aged Roe")
                    {
                        var preservedGoods = prizeLevel.Flavor;
                        var item1          = ItemsUtil.GetIndexByName(preservedGoods);
                        if (item1 == -1)
                        {
                            MarketDay.Log($"    Could not get index for flavor: {preservedGoods}", LogLevel.Warn);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// On a save loaded, store the language for translation purposes. Done on save loaded in
        /// case it's changed between saves
        ///
        /// Also retrieve all object informations. This is done on save loaded because that's
        /// when JA adds custom items
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e)
        {
            Translations.UpdateSelectedLanguage();
            ShopManager.UpdateTranslations();

            ItemsUtil.UpdateObjectInfoSource();
            ShopManager.InitializeItemStocks();

            ItemsUtil.RegisterItemsToRemove();
        }
Esempio n. 5
0
        /// <summary>
        /// Resets the items of this item stock, with condition checks and randomization
        /// </summary>
        /// <returns></returns>
        public Dictionary <ISalable, int[]> Update()
        {
            if (When != null && !APIs.Conditions.CheckConditions(When))
            {
                return(null);                       //did not pass conditions
            }
            if (!ItemsUtil.CheckItemType(ItemType)) //check that itemtype is valid
            {
                ModEntry.monitor.Log($"\t\"{ItemType}\" is not a valid ItemType. No items from this stock will be added."
                                     , LogLevel.Warn);
                return(null);
            }

            _itemPriceAndStock = new Dictionary <ISalable, int[]>();
            _builder.SetItemPriceAndStock(_itemPriceAndStock);

            double pricemultiplier = 1;

            if (_priceMultiplierWhen != null)
            {
                foreach (KeyValuePair <double, string[]> kvp in _priceMultiplierWhen)
                {
                    if (APIs.Conditions.CheckConditions(kvp.Value))
                    {
                        pricemultiplier = kvp.Key;
                        break;
                    }
                }
            }

            if (ItemType != "Seed")
            {
                AddById(pricemultiplier);
                AddByName(pricemultiplier);
            }
            else
            {
                if (ItemIDs != null)
                {
                    ModEntry.monitor.Log(
                        "ItemType of \"Seed\" is a special itemtype used for parsing Seeds from JA Pack crops and trees and does not support input via ID. If adding seeds via ID, please use the ItemType \"Object\" instead to directly sell the seeds/saplings");
                }
                if (ItemNames != null)
                {
                    ModEntry.monitor.Log(
                        "ItemType of \"Seed\" is a special itemtype used for parsing Seeds from JA Pack crops and trees and does not support input via Name. If adding seeds via Name, please use the ItemType \"Object\" instead to directly sell the seeds/saplings");
                }
            }

            AddByJAPack(pricemultiplier);

            ItemsUtil.RandomizeStock(_itemPriceAndStock, MaxNumItemsSoldInItemStock);
            return(_itemPriceAndStock);
        }
Esempio n. 6
0
        /// <summary>
        /// Takes an item name, and adds that item to the stock
        /// </summary>
        /// <param name="itemName">name of the item</param>
        /// <param name="priceMultiplier"></param>
        /// <returns></returns>
        public bool AddItemToStock(string itemName, double priceMultiplier = 1)
        {
            int id = ItemsUtil.GetIndexByName(itemName, _itemStock.ItemType);

            if (id < 0)
            {
                ModEntry.monitor.Log($"{_itemStock.ItemType} named \"{itemName}\" could not be added to the Shop {_itemStock.ShopName}", LogLevel.Trace);
                return(false);
            }

            return(AddItemToStock(id, priceMultiplier));
        }
Esempio n. 7
0
        private void JsonAssets_AddedItemsToShop(object sender, System.EventArgs e)
        {
            //make sure we only remove all objects if we camew from a vanilla store
            //this stops us from removing all packs from custom TMXL or STF stores
            if (!JustOpenedVanilla)
            {
                return;
            }

            if (Game1.activeClickableMenu is ShopMenu shop)
            {
                shop.setItemPriceAndStock(ItemsUtil.RemoveSpecifiedJAPacks(shop.itemPriceAndStock));
            }

            JustOpenedVanilla = false;
        }
        //public Type Type { get; set; }
        #endregion Properties.


        public IEnumerable <object> ExecOrder(IEnumerable <object> enumerable)
        {
            object comparer(object x) => ItemsUtil.GetValueByPath(x, PropertyName);     // Comparer

            if (Order == SortingOrder.None)
            {
                return(enumerable);
            }
            else if (Order == SortingOrder.Descendant)
            {
                return(enumerable.OrderByDescending(comparer));
            }
            else
            {
                return(enumerable.OrderBy(comparer));
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Takes an item id, and adds that item to the stock
        /// </summary>
        /// <param name="itemId">the id of the item</param>
        /// <param name="priceMultiplier"></param>
        /// <returns></returns>
        public bool AddItemToStock(int itemId, double priceMultiplier = 1)
        {
            if (ModEntry.VerboseLogging)
            {
                ModEntry.monitor.Log($"Adding item ID {itemId} to {_itemStock.ShopName}", LogLevel.Debug);
            }

            if (itemId < 0)
            {
                ModEntry.monitor.Log($"{_itemStock.ItemType} of ID {itemId} could not be added to the Shop {_itemStock.ShopName}", LogLevel.Trace);
                return(false);
            }

            if (_itemStock.ItemType == "Seed" && _itemStock.FilterSeedsBySeason)
            {
                if (!ItemsUtil.IsInSeasonCrop(itemId))
                {
                    return(false);
                }
            }

            var item = CreateItem(itemId);

            if (item == null)
            {
                return(false);
            }

            if (_itemStock.IsRecipe)
            {
                if (!ItemsUtil.RecipesList.Contains(item.Name))
                {
                    ModEntry.monitor.Log($"{item.Name} is not a valid recipe and won't be added.", LogLevel.Trace);
                    return(false);
                }
            }

            var priceStockCurrency = GetPriceStockAndCurrency(item, priceMultiplier);

            _itemPriceAndStock.Add(item, priceStockCurrency);

            return(true);
        }
Esempio n. 10
0
        /// <summary>
        /// Refreshes the stock of all items, doing condition checking and randomization
        /// </summary>
        public void Update()
        {
            ItemPriceAndStock = new Dictionary <ISalable, int[]>();
            ModEntry.monitor.Log($"Updating {_shopName}");

            foreach (ItemStock stock in _itemStocks)
            {
                var priceAndStock = stock.Update();
                //null is returned if conhditions aren't met, skip adding this stock
                if (priceAndStock == null)
                {
                    continue;
                }

                Add(priceAndStock);
            }

            //randomly reduces the stock of the whole store down to maxNumItemsSoldInStore
            ItemsUtil.RandomizeStock(ItemPriceAndStock, _maxNumItemsSoldInStore);
        }
Esempio n. 11
0
        /// <summary>
        /// Resets the items of this item stock, with condition checks and randomization
        /// </summary>
        /// <returns></returns>
        public Dictionary <ISalable, int[]> Update()
        {
            if (When != null && !APIs.Conditions.CheckConditions(When))
            {
                return(null);                       //did not pass conditions
            }
            if (!ItemsUtil.CheckItemType(ItemType)) //check that itemtype is valid
            {
                ModEntry.monitor.Log($"\t\"{ItemType}\" is not a valid ItemType. No items from this stock will be added."
                                     , LogLevel.Warn);
                return(null);
            }

            _itemPriceAndStock = new Dictionary <ISalable, int[]>();
            _builder.SetItemPriceAndStock(_itemPriceAndStock);

            double pricemultiplier = 1;

            if (_priceMultiplierWhen != null)
            {
                foreach (KeyValuePair <double, string[]> kvp in _priceMultiplierWhen)
                {
                    if (APIs.Conditions.CheckConditions(kvp.Value))
                    {
                        pricemultiplier = kvp.Key;
                        break;
                    }
                }
            }

            AddById(pricemultiplier);
            AddByName(pricemultiplier);
            AddByJAPack(pricemultiplier);

            ItemsUtil.RandomizeStock(_itemPriceAndStock, MaxNumItemsSoldInItemStock);
            return(_itemPriceAndStock);
        }
Esempio n. 12
0
        /// <summary>
        /// Add all items from the JA Packs listed in the JAPacks section
        /// </summary>
        private void AddByJAPack(double pricemultiplier)
        {
            if (JAPacks == null)
            {
                return;
            }

            if (APIs.JsonAssets == null)
            {
                return;
            }

            foreach (var JAPack in JAPacks)
            {
                ModEntry.monitor.Log($"Adding all {ItemType}s from {JAPack}", LogLevel.Debug);

                if (ItemType == "Seed")
                {
                    var crops = APIs.JsonAssets.GetAllCropsFromContentPack(JAPack);
                    var trees = APIs.JsonAssets.GetAllFruitTreesFromContentPack(JAPack);


                    if (crops != null)
                    {
                        foreach (string crop in crops)
                        {
                            if (ExcludeFromJAPacks != null && ExcludeFromJAPacks.Contains(crop))
                            {
                                continue;
                            }
                            int id = ItemsUtil.GetSeedId(crop);
                            if (id > 0)
                            {
                                _builder.AddItemToStock(id, pricemultiplier);
                            }
                        }
                    }

                    if (trees != null)
                    {
                        foreach (string tree in trees)
                        {
                            if (ExcludeFromJAPacks != null && ExcludeFromJAPacks.Contains(tree))
                            {
                                continue;
                            }
                            int id = ItemsUtil.GetSaplingId(tree);
                            if (id > 0)
                            {
                                _builder.AddItemToStock(id, pricemultiplier);
                            }
                        }
                    }

                    continue; //skip the rest of the loop so we don't also add the none-seed version
                }

                var packs = GetJaItems(JAPack);
                if (packs == null)
                {
                    ModEntry.monitor.Log($"No {ItemType} from {JAPack} could be found", LogLevel.Trace);
                    continue;
                }

                foreach (string itemName in packs)
                {
                    if (ExcludeFromJAPacks != null && ExcludeFromJAPacks.Contains(itemName))
                    {
                        continue;
                    }
                    _builder.AddItemToStock(itemName, pricemultiplier);
                }
            }
        }
        /// <summary>
        /// Saves each shop as long as its has a unique name
        /// </summary>
        /// <param name="data"></param>
        /// <param name="contentPack"></param>
        public static void RegisterShops(ContentPack data, IContentPack contentPack)
        {
            ItemsUtil.RegisterPacksToRemove(data.RemovePacksFromVanilla, data.RemovePackRecipesFromVanilla, data.RemoveItemsFromVanilla);

            if (data.Shops != null)
            {
                foreach (ItemShop shopPack in data.Shops)
                {
                    if (ItemShops.ContainsKey(shopPack.ShopName))
                    {
                        ModEntry.monitor.Log($"{contentPack.Manifest.Name} is trying to add a Shop \"{shopPack.ShopName}\"," +
                                             $" but a shop of this name has already been added. " +
                                             $"It will not be added.", LogLevel.Warn);
                        continue;
                    }
                    shopPack.ContentPack = contentPack;
                    ItemShops.Add(shopPack.ShopName, shopPack);
                }
            }

            if (data.AnimalShops != null)
            {
                foreach (AnimalShop animalShopPack in data.AnimalShops)
                {
                    if (AnimalShops.ContainsKey(animalShopPack.ShopName))
                    {
                        ModEntry.monitor.Log($"{contentPack.Manifest.Name} is trying to add an AnimalShop \"{animalShopPack.ShopName}\"," +
                                             $" but a shop of this name has already been added. " +
                                             $"It will not be added.", LogLevel.Warn);
                        continue;
                    }
                    AnimalShops.Add(animalShopPack.ShopName, animalShopPack);
                }
            }

            if (data.VanillaShops != null)
            {
                foreach (var vanillaShopPack in data.VanillaShops)
                {
                    if (!VanillaShopNames.Contains(vanillaShopPack.ShopName))
                    {
                        ModEntry.monitor.Log($"{contentPack.Manifest.Name}" +
                                             $" is trying to edit nonexistent vanilla store" +
                                             $" \"{vanillaShopPack.ShopName}\"", LogLevel.Warn);
                        continue;
                    }

                    if (VanillaShops.ContainsKey(vanillaShopPack.ShopName))
                    {
                        VanillaShops[vanillaShopPack.ShopName].StockManagers.Add(new ItemPriceAndStockManager(vanillaShopPack));

                        if (vanillaShopPack.ReplaceInsteadOfAdd)
                        {
                            VanillaShops[vanillaShopPack.ShopName].ReplaceInsteadOfAdd = true;
                        }

                        if (vanillaShopPack.AddStockAboveVanilla)
                        {
                            VanillaShops[vanillaShopPack.ShopName].AddStockAboveVanilla = true;
                        }
                    }
                    else
                    {
                        vanillaShopPack.Initialize();
                        vanillaShopPack.StockManagers.Add(new ItemPriceAndStockManager(vanillaShopPack));
                        VanillaShops.Add(vanillaShopPack.ShopName, vanillaShopPack);
                    }
                }
            }
        }