コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }