Esempio n. 1
0
        public void RegenerateStock()
        {
            TryDestroyStock();

            int   itemsCount = Comp.Props.CountRange.RandomInRange;
            float valueRange = Comp.Props.ValueRange.RandomInRange;

            ThingSetMaker_MarketValue maker = new ThingSetMaker_MarketValue();

            ThingSetMakerParams parms = default;

            parms.totalMarketValueRange = new FloatRange(valueRange, valueRange);
            parms.countRange            = new IntRange(itemsCount, itemsCount);

            parms.filter = DarkNetPriceUtils.GetThingFilter(def.AvaliableGoods);

            maker.fixedParams = parms;

            var items = maker.Generate();

            stock = new List <SellableItemWithModif>();

            foreach (var item in items)
            {
                int itemValue = (int)((item.MarketValue * Character.Greed) * GetPriceModificatorByTechLevel(item.def.techLevel));
                if (!DarkNetPriceUtils.TryMerge(item, stock))
                {
                    stock.Add(new SellableItemWithModif(item, itemValue, null));
                }
            }
        }
        public void RegenerateStock()
        {
            TryDestroyStock();

            ThingSetMaker_MarketValue maker = new ThingSetMaker_MarketValue();
            ThingSetMakerParams       parms = default;

            foreach (var cat in stock)
            {
                CategoryItemSetting <Tab> settings = Comp.Props.CategoryItemSettings.First(x => x.Tab == cat.Tab);

                if (cat.Items == null)
                {
                    cat.Items = new List <SellableItemWithModif>();
                }

                int   itemsCount = settings.CountRange.RandomInRange;
                float valueRange = settings.ValueRange.RandomInRange * itemsCount;

                parms.totalMarketValueRange = new FloatRange(valueRange, valueRange);
                parms.countRange            = new IntRange(itemsCount, itemsCount);

                ThingFilter filter = DarkNetPriceUtils.GetThingFilter(settings.Goods);
                if (filter.AllowedDefCount == 0)
                {
                    continue;
                }

                parms.filter = filter;

                maker.fixedParams = parms;

                var items = maker.Generate();

                foreach (var item in items)
                {
                    if (!DarkNetPriceUtils.TryMerge(item, cat.Items))
                    {
                        int marketValue = (int)((item.MarketValue * Character.Greed) * settings.PriceMultiplier);

                        var quality = item.TryGetComp <CompQuality>();
                        if (quality != null)
                        {
                            quality.SetQuality(QualityUtility.GenerateQualityRandomEqualChance(), ArtGenerationContext.Colony);
                            marketValue = (int)(marketValue * GetPriceMultiplierForQuality(quality.Quality));
                        }

                        SellableItemWithModif newItem = new SellableItemWithModif(item, marketValue, null);

                        cat.Items.Add(newItem);
                    }
                }
            }
        }