Пример #1
0
        protected override void Generate(ItemCollectionGeneratorParams parms, List <Thing> outThings)
        {
            int?      count                     = parms.count;
            int       count2                    = (!count.HasValue) ? Rand.RangeInclusive(3, 6) : count.Value;
            float?    totalNutrition            = parms.totalNutrition;
            float     totalValue                = (!totalNutrition.HasValue) ? Rand.Range(5f, 10f) : totalNutrition.Value;
            TechLevel?techLevel                 = parms.techLevel;
            TechLevel techLevel2                = (!techLevel.HasValue) ? TechLevel.Spacer : techLevel.Value;
            bool?     nonHumanEdibleFoodAllowed = parms.nonHumanEdibleFoodAllowed;
            bool      flag = nonHumanEdibleFoodAllowed.HasValue && parms.nonHumanEdibleFoodAllowed.Value;
            IEnumerable <ThingDef> arg_FC_0;

            if (flag)
            {
                arg_FC_0 = ItemCollectionGenerator_Food.food;
            }
            else
            {
                arg_FC_0 = from x in ItemCollectionGenerator_Food.food
                           where x.ingestible.HumanEdible
                           select x;
            }
            IEnumerable <ThingDef> enumerable = arg_FC_0;

            if (!flag)
            {
                enumerable = from x in enumerable
                             where x.ingestible.preferability > FoodPreferability.NeverForNutrition
                             select x;
            }
            FoodPreferability?minPreferability = parms.minPreferability;

            if (minPreferability.HasValue)
            {
                enumerable = from x in enumerable
                             where x.ingestible.preferability >= parms.minPreferability.Value
                             select x;
            }
            if (!enumerable.Any <ThingDef>())
            {
                return;
            }
            int numMeats = (from x in enumerable
                            where x.IsMeat
                            select x).Count <ThingDef>();
            int numLeathers = (from x in enumerable
                               where x.IsLeather
                               select x).Count <ThingDef>();
            Func <ThingDef, float> weightSelector = (ThingDef x) => ItemCollectionGeneratorUtility.AdjustedSelectionWeight(x, numMeats, numLeathers);
            List <ThingStuffPair>  list           = ItemCollectionGeneratorByTotalValueUtility.GenerateDefsWithPossibleTotalValue(count2, totalValue, enumerable, techLevel2, (Thing x) => x.def.ingestible.nutrition, (ThingStuffPair x) => x.thing.ingestible.nutrition, (ThingStuffPair x) => x.thing.ingestible.nutrition * (float)x.thing.stackLimit, weightSelector, 100);

            for (int i = 0; i < list.Count; i++)
            {
                outThings.Add(ThingMaker.MakeThing(list[i].thing, list[i].stuff));
            }
            ItemCollectionGeneratorByTotalValueUtility.IncreaseStackCountsToTotalValue(outThings, totalValue, (Thing x) => x.def.ingestible.nutrition);
        }
Пример #2
0
        protected override void Generate(ItemCollectionGeneratorParams parms, List <Thing> outThings)
        {
            TechLevel?techLevel               = parms.techLevel;
            TechLevel techLevel2              = (!techLevel.HasValue) ? TechLevel.Spacer : techLevel.Value;
            int?      count                   = parms.count;
            int       num                     = (!count.HasValue) ? Rand.RangeInclusive(5, 10) : count.Value;
            float?    totalMarketValue        = parms.totalMarketValue;
            IEnumerable <ThingDef> enumerable = this.AllowedDefs(parms);

            if (parms.extraAllowedDefs != null)
            {
                enumerable = enumerable.Concat(parms.extraAllowedDefs);
            }
            if (enumerable.Any())
            {
                if (totalMarketValue.HasValue)
                {
                    List <ThingStuffPair> list = ItemCollectionGeneratorByTotalValueUtility.GenerateDefsWithPossibleTotalValue(num, totalMarketValue.Value, enumerable, techLevel2, (Thing x) => x.MarketValue, this.GetMinValue, this.GetMaxValue, null, 100);
                    for (int i = 0; i < list.Count; i++)
                    {
                        ThingStuffPair thingStuffPair  = list[i];
                        ThingDef       thing           = thingStuffPair.thing;
                        ThingStuffPair thingStuffPair2 = list[i];
                        outThings.Add(ThingMaker.MakeThing(thing, thingStuffPair2.stuff));
                    }
                    ItemCollectionGeneratorByTotalValueUtility.IncreaseStackCountsToTotalValue(outThings, totalMarketValue.Value, (Thing x) => x.MarketValue);
                }
                else
                {
                    for (int j = 0; j < num; j++)
                    {
                        ThingDef thingDef = enumerable.RandomElement();
                        outThings.Add(ThingMaker.MakeThing(thingDef, GenStuff.RandomStuffFor(thingDef)));
                    }
                }
                ItemCollectionGeneratorUtility.AssignRandomBaseGenItemQuality(outThings);
            }
        }