Пример #1
0
        public static TaleData_Thing GenerateRandom()
        {
            ThingDef thingDef = DefDatabase <ThingDef> .AllDefs.Where(delegate(ThingDef d)
            {
                bool arg_36_0;
                if (d.comps != null)
                {
                    arg_36_0 = d.comps.Any((CompProperties cp) => cp.compClass == typeof(CompArt));
                }
                else
                {
                    arg_36_0 = false;
                }
                return(arg_36_0);
            }).RandomElement <ThingDef>();

            ThingDef             thingDef2   = GenStuff.RandomStuffFor(thingDef);
            Thing                thing       = ThingMaker.MakeThing(thingDef, thingDef2);
            ArtGenerationContext source      = (Rand.Value >= 0.5f) ? ArtGenerationContext.Outsider : ArtGenerationContext.Colony;
            CompQuality          compQuality = thing.TryGetComp <CompQuality>();

            if (compQuality != null && compQuality.Quality < thing.TryGetComp <CompArt>().Props.minQualityForArtistic)
            {
                compQuality.SetQuality(thing.TryGetComp <CompArt>().Props.minQualityForArtistic, source);
            }
            thing.TryGetComp <CompArt>().InitializeArt(source);
            return(TaleData_Thing.GenerateFrom(thing));
        }
Пример #2
0
        public static ThingDef DefaultStuffFor(ThingDef td)
        {
            if (!td.MadeFromStuff)
            {
                return(null);
            }
            if (ThingDefOf.WoodLog.stuffProps.CanMake(td))
            {
                return(ThingDefOf.WoodLog);
            }
            if (ThingDefOf.Steel.stuffProps.CanMake(td))
            {
                return(ThingDefOf.Steel);
            }
            if (ThingDefOf.Cloth.stuffProps.CanMake(td))
            {
                return(ThingDefOf.Cloth);
            }
            ThingDef leatherDef = ThingDefOf.Cow.race.leatherDef;

            if (leatherDef.stuffProps.CanMake(td))
            {
                return(leatherDef);
            }
            if (ThingDefOf.BlocksGranite.stuffProps.CanMake(td))
            {
                return(ThingDefOf.BlocksGranite);
            }
            if (ThingDefOf.Plasteel.stuffProps.CanMake(td))
            {
                return(ThingDefOf.Plasteel);
            }
            return(GenStuff.RandomStuffFor(td));
        }
Пример #3
0
 public override void Randomize()
 {
     this.thingDef = this.PossibleThingDefs().RandomElement <ThingDef>();
     this.stuff    = GenStuff.RandomStuffFor(this.thingDef);
     if (this.thingDef.statBases.StatListContains(StatDefOf.MarketValue))
     {
         float num = (float)Rand.Range(200, 2000);
         float statValueAbstract = this.thingDef.GetStatValueAbstract(StatDefOf.MarketValue, this.stuff);
         this.count = Mathf.CeilToInt(num / statValueAbstract);
     }
     else
     {
         this.count = Rand.RangeInclusive(1, 100);
     }
 }
Пример #4
0
        public static TaleData_Thing GenerateRandom()
        {
            ThingDef obj = DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.comps != null && d.comps.Any((CompProperties cp) => cp.compClass == typeof(CompArt))).RandomElement();

            ThingDef             thingDef    = GenStuff.RandomStuffFor(obj);
            Thing                thing       = ThingMaker.MakeThing(obj, thingDef);
            ArtGenerationContext source      = (Rand.Value < 0.5f) ? ArtGenerationContext.Colony : ArtGenerationContext.Outsider;
            CompQuality          compQuality = thing.TryGetComp <CompQuality>();

            if (compQuality != null && (int)compQuality.Quality < (int)thing.TryGetComp <CompArt>().Props.minQualityForArtistic)
            {
                compQuality.SetQuality(thing.TryGetComp <CompArt>().Props.minQualityForArtistic, source);
            }
            thing.TryGetComp <CompArt>().InitializeArt(source);
            return(GenerateFrom(thing));
        }
        public static TaleData_Thing GenerateRandom()
        {
            ThingDef thingDef = (from d in DefDatabase <ThingDef> .AllDefs
                                 where d.comps != null && d.comps.Any((CompProperties cp) => cp.compClass == typeof(CompArt))
                                 select d).RandomElement();
            ThingDef             thingDef2   = GenStuff.RandomStuffFor(thingDef);
            Thing                thing       = ThingMaker.MakeThing(thingDef, thingDef2);
            ArtGenerationContext source      = (ArtGenerationContext)((Rand.Value < 0.5) ? 1 : 0);
            CompQuality          compQuality = thing.TryGetComp <CompQuality>();

            if (compQuality != null && (int)compQuality.Quality < (int)thing.TryGetComp <CompArt>().Props.minQualityForArtistic)
            {
                compQuality.SetQuality(thing.TryGetComp <CompArt>().Props.minQualityForArtistic, source);
            }
            thing.TryGetComp <CompArt>().InitializeArt(source);
            return(TaleData_Thing.GenerateFrom(thing));
        }
Пример #6
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);
            }
        }
        private Thing GenerateReward(float value, TechLevel techLevel, Predicate <ThingDef> validator = null)
        {
            if (Rand.Chance(0.5f) && (validator == null || validator(ThingDefOf.Silver)))
            {
                Thing thing = ThingMaker.MakeThing(ThingDefOf.Silver, null);
                thing.stackCount = ThingUtility.RoundedResourceStackCount(Mathf.Max(GenMath.RoundRandom(value), 1));
                return(thing);
            }
            ThingDef thingDef = default(ThingDef);

            if (Rand.Chance(0.35f) && (from x in ItemCollectionGeneratorUtility.allGeneratableItems
                                       where x.itemGeneratorTags != null && x.itemGeneratorTags.Contains(ItemCollectionGeneratorUtility.SpecialRewardTag) && (validator == null || validator(x)) && Mathf.Abs((float)(1.0 - x.BaseMarketValue / value)) <= 0.34999999403953552
                                       select x).TryRandomElement <ThingDef>(out thingDef))
            {
                Thing       thing2      = ThingMaker.MakeThing(thingDef, GenStuff.RandomStuffFor(thingDef));
                CompQuality compQuality = thing2.TryGetComp <CompQuality>();
                if (compQuality != null)
                {
                    compQuality.SetQuality(QualityUtility.RandomBaseGenItemQuality(), ArtGenerationContext.Outsider);
                }
                return(thing2);
            }
            if (Rand.Chance(0.13f))
            {
                float    minExpensiveMineableResourceMarketValue = ThingDefOf.Uranium.BaseMarketValue;
                ThingDef thingDef2 = default(ThingDef);
                if ((from x in ItemCollectionGenerator_Meteorite.mineables
                     where x.building.isResourceRock && x.building.mineableThing.BaseMarketValue >= minExpensiveMineableResourceMarketValue && (validator == null || validator(x.building.mineableThing))
                     select x).TryRandomElement <ThingDef>(out thingDef2))
                {
                    float    num           = (float)(value * 0.89999997615814209);
                    ThingDef mineableThing = thingDef2.building.mineableThing;
                    Thing    thing3        = ThingMaker.MakeThing(mineableThing, null);
                    thing3.stackCount = Mathf.Max(GenMath.RoundRandom(num / mineableThing.BaseMarketValue), 1);
                    return(thing3);
                }
            }
            Option option2 = (from option in ItemCollectionGeneratorUtility.allGeneratableItems.Select(delegate(ThingDef td)
            {
                if ((int)td.techLevel > (int)techLevel)
                {
                    return(null);
                }
                if (td.itemGeneratorTags != null && td.itemGeneratorTags.Contains(ItemCollectionGeneratorUtility.SpecialRewardTag))
                {
                    return(null);
                }
                if (!td.IsWithinCategory(ThingCategoryDefOf.Apparel) && !td.IsWithinCategory(ThingCategoryDefOf.Weapons) && !td.IsWithinCategory(ThingCategoryDefOf.Art) && (td.building == null || !td.Minifiable) && (td.tradeTags == null || !td.tradeTags.Contains("Exotic")))
                {
                    return(null);
                }
                if (validator != null && !validator(td))
                {
                    return(null);
                }
                ThingDef stuff = null;
                if (td.MadeFromStuff && !GenStuff.TryRandomStuffByCommonalityFor(td, out stuff, techLevel))
                {
                    return(null);
                }
                Option option3 = new Option();
                option3.thingDef = td;
                option3.quality = ((!td.HasComp(typeof(CompQuality))) ? QualityCategory.Normal : QualityUtility.RandomQuality());
                option3.stuff = stuff;
                return(option3);
            })
                              where option != null
                              select option).MinBy(delegate(Option option)
            {
                float value2 = StatDefOf.MarketValue.Worker.GetValue(StatRequest.For(option.thingDef, option.stuff, option.quality), true);
                return(Mathf.Abs(value - value2));
            });
            Thing       thing4       = ThingMaker.MakeThing(option2.thingDef, option2.stuff);
            CompQuality compQuality2 = thing4.TryGetComp <CompQuality>();

            if (compQuality2 != null)
            {
                compQuality2.SetQuality(option2.quality, ArtGenerationContext.Outsider);
            }
            return(thing4);
        }