Beispiel #1
0
 public static void TryGenerateWeaponFor(Pawn pawn)
 {
     workingWeapons.Clear();
     if (pawn.kindDef.weaponTags != null && pawn.kindDef.weaponTags.Count != 0 && pawn.RaceProps.ToolUser && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) && (pawn.story == null || !pawn.story.WorkTagIsDisabled(WorkTags.Violent)))
     {
         float randomInRange = pawn.kindDef.weaponMoney.RandomInRange;
         for (int i = 0; i < allWeaponPairs.Count; i++)
         {
             ThingStuffPair w2 = allWeaponPairs[i];
             if (!(w2.Price > randomInRange) && (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Any((string tag) => w2.thing.weaponTags.Contains(tag))) && (!(w2.thing.generateAllowChance < 1f) || Rand.ChanceSeeded(w2.thing.generateAllowChance, pawn.thingIDNumber ^ w2.thing.shortHash ^ 0x1B3B648)))
             {
                 workingWeapons.Add(w2);
             }
         }
         if (workingWeapons.Count != 0)
         {
             pawn.equipment.DestroyAllEquipment();
             if (workingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out ThingStuffPair result))
             {
                 ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(result.thing, result.stuff);
                 PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn);
                 pawn.equipment.AddEquipment(thingWithComps);
             }
             workingWeapons.Clear();
         }
     }
 }
Beispiel #2
0
 public void GiveToPawn(Pawn pawn)
 {
     for (int i = 0; i < aps.Count; i++)
     {
         ThingStuffPair thingStuffPair  = aps[i];
         ThingDef       thing           = thingStuffPair.thing;
         ThingStuffPair thingStuffPair2 = aps[i];
         Apparel        apparel         = (Apparel)ThingMaker.MakeThing(thing, thingStuffPair2.stuff);
         PawnGenerator.PostProcessGeneratedGear(apparel, pawn);
         if (ApparelUtility.HasPartsToWear(pawn, apparel.def))
         {
             pawn.apparel.Wear(apparel, dropReplacedApparel: false);
         }
     }
     for (int j = 0; j < aps.Count; j++)
     {
         for (int k = 0; k < aps.Count; k++)
         {
             if (j != k)
             {
                 ThingStuffPair thingStuffPair3 = aps[j];
                 ThingDef       thing2          = thingStuffPair3.thing;
                 ThingStuffPair thingStuffPair4 = aps[k];
                 if (!ApparelUtility.CanWearTogether(thing2, thingStuffPair4.thing, pawn.RaceProps.body))
                 {
                     Log.Error(pawn + " generated with apparel that cannot be worn together: " + aps[j] + ", " + aps[k]);
                     return;
                 }
             }
         }
     }
 }
Beispiel #3
0
        public static void TryGenerateWeaponFor(Pawn pawn, PawnGenerationRequest request)
        {
            workingWeapons.Clear();
            if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0 || !pawn.RaceProps.ToolUser || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || pawn.WorkTagIsDisabled(WorkTags.Violent))
            {
                return;
            }
            float randomInRange = pawn.kindDef.weaponMoney.RandomInRange;

            for (int i = 0; i < allWeaponPairs.Count; i++)
            {
                ThingStuffPair w2 = allWeaponPairs[i];
                if (!(w2.Price > randomInRange) && (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Any((string tag) => w2.thing.weaponTags.Contains(tag))) && (!(w2.thing.generateAllowChance < 1f) || Rand.ChanceSeeded(w2.thing.generateAllowChance, pawn.thingIDNumber ^ w2.thing.shortHash ^ 0x1B3B648)))
                {
                    workingWeapons.Add(w2);
                }
            }
            if (workingWeapons.Count == 0)
            {
                return;
            }
            pawn.equipment.DestroyAllEquipment();
            if (workingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out var result))
            {
                ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(result.thing, result.stuff);
                PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn);
                float num = ((request.BiocodeWeaponChance > 0f) ? request.BiocodeWeaponChance : pawn.kindDef.biocodeWeaponChance);
                if (Rand.Value < num)
                {
                    thingWithComps.TryGetComp <CompBiocodableWeapon>()?.CodeFor(pawn);
                }
                pawn.equipment.AddEquipment(thingWithComps);
            }
            workingWeapons.Clear();
        }
Beispiel #4
0
            public bool CoatButNoShirt()
            {
                bool flag  = false;
                bool flag2 = false;

                for (int i = 0; i < aps.Count; i++)
                {
                    ThingStuffPair thingStuffPair = aps[i];
                    if (thingStuffPair.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso))
                    {
                        int num = 0;
                        while (true)
                        {
                            int            num2            = num;
                            ThingStuffPair thingStuffPair2 = aps[i];
                            if (num2 >= thingStuffPair2.thing.apparel.layers.Count)
                            {
                                break;
                            }
                            ThingStuffPair  thingStuffPair3 = aps[i];
                            ApparelLayerDef apparelLayerDef = thingStuffPair3.thing.apparel.layers[num];
                            if (apparelLayerDef == ApparelLayerDefOf.OnSkin)
                            {
                                flag2 = true;
                            }
                            if (apparelLayerDef == ApparelLayerDefOf.Shell || apparelLayerDef == ApparelLayerDefOf.Middle)
                            {
                                flag = true;
                            }
                            num++;
                        }
                    }
                }
                return(flag && !flag2);
            }
 public static void TryGenerateWeaponFor(Pawn pawn)
 {
     PawnWeaponGenerator.workingWeapons.Clear();
     if (pawn.kindDef.weaponTags != null && pawn.kindDef.weaponTags.Count != 0 && pawn.RaceProps.ToolUser && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) && (pawn.story == null || !pawn.story.WorkTagIsDisabled(WorkTags.Violent)))
     {
         float randomInRange = pawn.kindDef.weaponMoney.RandomInRange;
         for (int i = 0; i < PawnWeaponGenerator.allWeaponPairs.Count; i++)
         {
             ThingStuffPair w2 = PawnWeaponGenerator.allWeaponPairs[i];
             if (!(w2.Price > randomInRange) && pawn.kindDef.weaponTags.Any((string tag) => w2.thing.weaponTags.Contains(tag)) && (!(w2.thing.generateAllowChance < 1.0) || !(Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) > w2.thing.generateAllowChance)))
             {
                 PawnWeaponGenerator.workingWeapons.Add(w2);
             }
         }
         if (PawnWeaponGenerator.workingWeapons.Count != 0)
         {
             pawn.equipment.DestroyAllEquipment(DestroyMode.Vanish);
             ThingStuffPair thingStuffPair = default(ThingStuffPair);
             if (((IEnumerable <ThingStuffPair>)PawnWeaponGenerator.workingWeapons).TryRandomElementByWeight <ThingStuffPair>((Func <ThingStuffPair, float>)((ThingStuffPair w) => w.Commonality * w.Price), out thingStuffPair))
             {
                 ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff);
                 PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn);
                 pawn.equipment.AddEquipment(thingWithComps);
             }
             PawnWeaponGenerator.workingWeapons.Clear();
         }
     }
 }
        public static void Reset()
        {
            Predicate <ThingDef> isWeapon = (ThingDef td) => td.equipmentType == EquipmentType.Primary && !td.weaponTags.NullOrEmpty <string>();

            PawnWeaponGenerator.allWeaponPairs = ThingStuffPair.AllWith(isWeapon);
            using (IEnumerator <ThingDef> enumerator = (from td in DefDatabase <ThingDef> .AllDefs
                                                        where isWeapon(td)
                                                        select td).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ThingDef thingDef = enumerator.Current;
                    float    num      = (from pa in PawnWeaponGenerator.allWeaponPairs
                                         where pa.thing == thingDef
                                         select pa).Sum((ThingStuffPair pa) => pa.Commonality);
                    float num2 = thingDef.generateCommonality / num;
                    if (num2 != 1f)
                    {
                        for (int i = 0; i < PawnWeaponGenerator.allWeaponPairs.Count; i++)
                        {
                            ThingStuffPair thingStuffPair = PawnWeaponGenerator.allWeaponPairs[i];
                            if (thingStuffPair.thing == thingDef)
                            {
                                PawnWeaponGenerator.allWeaponPairs[i] = new ThingStuffPair(thingStuffPair.thing, thingStuffPair.stuff, thingStuffPair.commonalityMultiplier * num2);
                            }
                        }
                    }
                }
            }
        }
        public static bool TryGetRandomThingWhichCanWeighNoMoreThan(IEnumerable <ThingDef> candidates, TechLevel stuffTechLevel, float maxMass, QualityGenerator?qualityGenerator, out ThingStuffPair thingStuffPair)
        {
            if (!candidates.Where((ThingDef x) => PossibleToWeighNoMoreThan(x, maxMass, GenStuff.AllowedStuffsFor(x, stuffTechLevel))).TryRandomElement(out var thingDef))
            {
                thingStuffPair = default(ThingStuffPair);
                return(false);
            }
            ThingDef result;

            if (thingDef.MadeFromStuff)
            {
                if (!(from x in GenStuff.AllowedStuffsFor(thingDef, stuffTechLevel)
                      where thingDef.GetStatValueAbstract(StatDefOf.Mass, x) <= maxMass && !IsDerpAndDisallowed(thingDef, x, qualityGenerator)
                      select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out result))
                {
                    thingStuffPair = default(ThingStuffPair);
                    return(false);
                }
            }
            else
            {
                result = null;
            }
            thingStuffPair = new ThingStuffPair(thingDef, result);
            return(true);
        }
Beispiel #8
0
 public void Add(ThingStuffPair pair)
 {
     aps.Add(pair);
     ApparelUtility.GenerateLayerGroupPairs(body, pair.thing, delegate(ApparelUtility.LayerGroupPair lgp)
     {
         lgps.Add(lgp);
     });
 }
Beispiel #9
0
        private static bool CanUsePair(ThingStuffPair pair, Pawn pawn, float moneyLeft, bool allowHeadgear, int fixedSeed)
        {
            bool result;

            if (pair.Price > moneyLeft)
            {
                result = false;
            }
            else if (!allowHeadgear && PawnApparelGenerator.IsHeadgear(pair.thing))
            {
                result = false;
            }
            else if (pair.stuff != null && pawn.Faction != null && !pawn.Faction.def.CanUseStuffForApparel(pair.stuff))
            {
                result = false;
            }
            else if (PawnApparelGenerator.workingSet.PairOverlapsAnything(pair))
            {
                result = false;
            }
            else
            {
                if (!pawn.kindDef.apparelTags.NullOrEmpty <string>())
                {
                    bool flag = false;
                    for (int i = 0; i < pawn.kindDef.apparelTags.Count; i++)
                    {
                        for (int j = 0; j < pair.thing.apparel.tags.Count; j++)
                        {
                            if (pawn.kindDef.apparelTags[i] == pair.thing.apparel.tags[j])
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag)
                        {
                            break;
                        }
                    }
                    if (!flag)
                    {
                        return(false);
                    }
                }
                if (pair.thing.generateAllowChance < 1f)
                {
                    if (!Rand.ChanceSeeded(pair.thing.generateAllowChance, fixedSeed ^ (int)pair.thing.shortHash ^ 64128343))
                    {
                        return(false);
                    }
                }
                result = true;
            }
            return(result);
        }
Beispiel #10
0
            public bool PairOverlapsAnything(ThingStuffPair pair)
            {
                bool conflicts = false;

                ApparelUtility.GenerateLayerGroupPairs(body, pair.thing, delegate(ApparelUtility.LayerGroupPair lgp)
                {
                    conflicts |= lgps.Contains(lgp);
                });
                return(conflicts);
            }
        private static void GenerateWorkingPossibleApparelSetFor(Pawn pawn, float money, List <ThingStuffPair> apparelCandidates)
        {
            workingSet.Reset(pawn.RaceProps.body, pawn.def);
            float           num        = money;
            List <ThingDef> reqApparel = pawn.kindDef.apparelRequired;

            if (reqApparel != null)
            {
                int j;
                for (j = 0; j < reqApparel.Count; j++)
                {
                    ThingStuffPair pair = allApparelPairs.Where((ThingStuffPair pa) => pa.thing == reqApparel[j] && CanUseStuff(pawn, pa)).RandomElementByWeight((ThingStuffPair pa) => pa.Commonality);
                    workingSet.Add(pair);
                    num -= pair.Price;
                }
            }
            List <SpecificApparelRequirement> att = pawn.kindDef.specificApparelRequirements;

            if (att != null)
            {
                int i;
                for (i = 0; i < att.Count; i++)
                {
                    if ((!att[i].RequiredTag.NullOrEmpty() || !att[i].AlternateTagChoices.NullOrEmpty()) && allApparelPairs.Where((ThingStuffPair pa) => ApparelRequirementTagsMatch(att[i], pa.thing) && ApparelRequirementHandlesThing(att[i], pa.thing) && CanUseStuff(pawn, pa) && pa.thing.apparel.CorrectGenderForWearing(pawn.gender) && !workingSet.PairOverlapsAnything(pa)).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality, out ThingStuffPair result))
                    {
                        workingSet.Add(result);
                        num -= result.Price;
                    }
                }
            }
            usableApparel.Clear();
            for (int k = 0; k < apparelCandidates.Count; k++)
            {
                if (!workingSet.PairOverlapsAnything(apparelCandidates[k]))
                {
                    usableApparel.Add(apparelCandidates[k]);
                }
            }
            ThingStuffPair result2;

            while ((!(Rand.Value < 0.1f) || !(money < 9999999f)) && usableApparel.Where((ThingStuffPair pa) => CanUseStuff(pawn, pa)).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality, out result2))
            {
                workingSet.Add(result2);
                num -= result2.Price;
                for (int num2 = usableApparel.Count - 1; num2 >= 0; num2--)
                {
                    if (usableApparel[num2].Price > num || workingSet.PairOverlapsAnything(usableApparel[num2]))
                    {
                        usableApparel.RemoveAt(num2);
                    }
                }
            }
        }
 private static bool CanUsePair(ThingStuffPair pair, Pawn pawn, float moneyLeft, bool allowHeadgear, int fixedSeed)
 {
     if (pair.Price > moneyLeft)
     {
         return(false);
     }
     if (!allowHeadgear && IsHeadgear(pair.thing))
     {
         return(false);
     }
     if (!pair.thing.apparel.CorrectGenderForWearing(pawn.gender))
     {
         return(false);
     }
     if (!pawn.kindDef.apparelTags.NullOrEmpty())
     {
         bool flag = false;
         for (int i = 0; i < pawn.kindDef.apparelTags.Count; i++)
         {
             for (int j = 0; j < pair.thing.apparel.tags.Count; j++)
             {
                 if (pawn.kindDef.apparelTags[i] == pair.thing.apparel.tags[j])
                 {
                     flag = true;
                     break;
                 }
             }
             if (flag)
             {
                 break;
             }
         }
         if (!flag)
         {
             return(false);
         }
     }
     if (!pawn.kindDef.apparelDisallowTags.NullOrEmpty())
     {
         for (int k = 0; k < pawn.kindDef.apparelDisallowTags.Count; k++)
         {
             if (pair.thing.apparel.tags.Contains(pawn.kindDef.apparelDisallowTags[k]))
             {
                 return(false);
             }
         }
     }
     if (pair.thing.generateAllowChance < 1f && !Rand.ChanceSeeded(pair.thing.generateAllowChance, fixedSeed ^ pair.thing.shortHash ^ 0x3D28557))
     {
         return(false);
     }
     return(true);
 }
Beispiel #13
0
 public bool Covers(BodyPartGroupDef bp)
 {
     for (int i = 0; i < aps.Count; i++)
     {
         ThingStuffPair thingStuffPair = aps[i];
         if (thingStuffPair.thing.apparel.bodyPartGroups.Contains(bp))
         {
             return(true);
         }
     }
     return(false);
 }
            private float GetReplacedInsulationCold(ThingStuffPair newAp)
            {
                float num = 0f;

                for (int i = 0; i < aps.Count; i++)
                {
                    if (!ApparelUtility.CanWearTogether(aps[i].thing, newAp.thing, body))
                    {
                        num += aps[i].InsulationCold;
                    }
                }
                return(num);
            }
Beispiel #15
0
 public void Add(ThingStuffPair pair)
 {
     aps.Add(pair);
     for (int i = 0; i < pair.thing.apparel.layers.Count; i++)
     {
         ApparelLayerDef    layer = pair.thing.apparel.layers[i];
         BodyPartGroupDef[] interferingBodyPartGroups = pair.thing.apparel.GetInterferingBodyPartGroups(body);
         for (int j = 0; j < interferingBodyPartGroups.Length; j++)
         {
             lgps.Add(new ApparelUtility.LayerGroupPair(layer, interferingBodyPartGroups[j]));
         }
     }
 }
        public static void TryGenerateWeaponFor(Pawn pawn)
        {
            PawnWeaponGenerator.workingWeapons.Clear();
            if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0)
            {
                return;
            }
            if (!pawn.RaceProps.ToolUser)
            {
                return;
            }
            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                return;
            }
            if (pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent))
            {
                return;
            }
            float randomInRange = pawn.kindDef.weaponMoney.RandomInRange;

            for (int i = 0; i < PawnWeaponGenerator.allWeaponPairs.Count; i++)
            {
                ThingStuffPair w = PawnWeaponGenerator.allWeaponPairs[i];
                if (w.Price <= randomInRange)
                {
                    if (pawn.kindDef.weaponTags.Any((string tag) => w.thing.weaponTags.Contains(tag)))
                    {
                        if (w.thing.generateAllowChance >= 1f || Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) <= w.thing.generateAllowChance)
                        {
                            PawnWeaponGenerator.workingWeapons.Add(w);
                        }
                    }
                }
            }
            if (PawnWeaponGenerator.workingWeapons.Count == 0)
            {
                return;
            }
            pawn.equipment.DestroyAllEquipment(DestroyMode.Vanish);
            ThingStuffPair thingStuffPair;

            if (PawnWeaponGenerator.workingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out thingStuffPair))
            {
                ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff);
                PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn);
                pawn.equipment.AddEquipment(thingWithComps);
            }
            PawnWeaponGenerator.workingWeapons.Clear();
        }
Beispiel #17
0
        public static float CheapestNonDerpPriceFor(ThingDef weaponDef)
        {
            float num = 9999999f;

            for (int i = 0; i < allWeaponPairs.Count; i++)
            {
                ThingStuffPair thingStuffPair = allWeaponPairs[i];
                if (thingStuffPair.thing == weaponDef && !IsDerpWeapon(thingStuffPair.thing, thingStuffPair.stuff) && thingStuffPair.Price < num)
                {
                    num = thingStuffPair.Price;
                }
            }
            return(num);
        }
        internal static void LogHeadwearApparelPairs()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Listing all entries in allApparelPairs of headwear");
            foreach (ThingStuffPair item in from pa in PawnApparelGenerator.allApparelPairs
                     where PawnApparelGenerator.IsHeadwear(pa.thing)
                     orderby pa.thing.defName
                     select pa)
            {
                ThingStuffPair current = item;
                stringBuilder.AppendLine(current + "  - " + current.commonalityMultiplier);
            }
            Log.Message(stringBuilder.ToString());
        }
Beispiel #19
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> enumerable = (!flag) ? (from x in ItemCollectionGenerator_Food.food
                                                           where x.ingestible.HumanEdible
                                                           select x) : ItemCollectionGenerator_Food.food;

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

            if (minPreferability.HasValue)
            {
                enumerable = from x in enumerable
                             where (int)x.ingestible.preferability >= (int)parms.minPreferability.Value
                             select x;
            }
            if (enumerable.Any())
            {
                int numMeats = (from x in enumerable
                                where x.IsMeat
                                select x).Count();
                int numLeathers = (from x in enumerable
                                   where x.IsLeather
                                   select x).Count();
                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++)
                {
                    ThingStuffPair thingStuffPair  = list[i];
                    ThingDef       thing           = thingStuffPair.thing;
                    ThingStuffPair thingStuffPair2 = list[i];
                    outThings.Add(ThingMaker.MakeThing(thing, thingStuffPair2.stuff));
                }
                ItemCollectionGeneratorByTotalValueUtility.IncreaseStackCountsToTotalValue(outThings, totalValue, (Thing x) => x.def.ingestible.nutrition);
            }
        }
                internal bool <> m__0(ThingStuffPair pa)
                {
                    if (pa.Price > PawnApparelGenerator.freeWarmParkaMaxPrice)
                    {
                        return(false);
                    }
                    if (pa.InsulationCold <= 0f)
                    {
                        return(false);
                    }
                    if (!pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso))
                    {
                        return(false);
                    }
                    float replacedInsulationCold = this.$this.GetReplacedInsulationCold(pa);

                    return(replacedInsulationCold < pa.InsulationCold);
                }
Beispiel #21
0
        private static void GenerateWorkingPossibleApparelSetFor(Pawn pawn, float money, bool headwearAllowed)
        {
            workingSet.Reset(pawn.RaceProps.body, pawn.def);
            float           num        = money;
            List <ThingDef> reqApparel = pawn.kindDef.apparelRequired;

            if (reqApparel != null)
            {
                int i;
                for (i = 0; i < reqApparel.Count; i++)
                {
                    ThingStuffPair pair = (from pa in allApparelPairs
                                           where pa.thing == reqApparel[i]
                                           select pa).RandomElementByWeight((ThingStuffPair pa) => pa.Commonality);
                    workingSet.Add(pair);
                    num -= pair.Price;
                }
            }
            int @int = Rand.Int;

            while (!(Rand.Value < 0.1f))
            {
                usableApparel.Clear();
                for (int j = 0; j < allApparelPairs.Count; j++)
                {
                    ThingStuffPair thingStuffPair = allApparelPairs[j];
                    if (CanUsePair(thingStuffPair, pawn, num, headwearAllowed, @int))
                    {
                        usableApparel.Add(thingStuffPair);
                    }
                }
                ThingStuffPair result;
                bool           flag = usableApparel.TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality, out result);
                usableApparel.Clear();
                if (!flag)
                {
                    break;
                }
                workingSet.Add(result);
                num -= result.Price;
            }
        }
Beispiel #22
0
 public bool PairOverlapsAnything(ThingStuffPair pair)
 {
     if (!lgps.Any())
     {
         return(false);
     }
     for (int i = 0; i < pair.thing.apparel.layers.Count; i++)
     {
         ApparelLayerDef    layer = pair.thing.apparel.layers[i];
         BodyPartGroupDef[] interferingBodyPartGroups = pair.thing.apparel.GetInterferingBodyPartGroups(body);
         for (int j = 0; j < interferingBodyPartGroups.Length; j++)
         {
             if (lgps.Contains(new ApparelUtility.LayerGroupPair(layer, interferingBodyPartGroups[j])))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        private static bool CanUseStuff(Pawn pawn, ThingStuffPair pair)
        {
            List <SpecificApparelRequirement> specificApparelRequirements = pawn.kindDef.specificApparelRequirements;

            if (specificApparelRequirements != null)
            {
                for (int i = 0; i < specificApparelRequirements.Count; i++)
                {
                    if (!ApparelRequirementCanUseStuff(specificApparelRequirements[i], pair))
                    {
                        return(false);
                    }
                }
            }
            if (pair.stuff != null && pawn.Faction != null && !pawn.Faction.def.CanUseStuffForApparel(pair.stuff))
            {
                return(false);
            }
            return(true);
        }
Beispiel #24
0
        public static void Reset()
        {
            Predicate <ThingDef> isWeapon = (ThingDef td) => td.equipmentType == EquipmentType.Primary && !td.weaponTags.NullOrEmpty();

            allWeaponPairs = ThingStuffPair.AllWith(isWeapon);
            foreach (ThingDef thingDef in DefDatabase <ThingDef> .AllDefs.Where((ThingDef td) => isWeapon(td)))
            {
                float num  = allWeaponPairs.Where((ThingStuffPair pa) => pa.thing == thingDef).Sum((ThingStuffPair pa) => pa.Commonality);
                float num2 = thingDef.generateCommonality / num;
                if (num2 != 1f)
                {
                    for (int i = 0; i < allWeaponPairs.Count; i++)
                    {
                        ThingStuffPair thingStuffPair = allWeaponPairs[i];
                        if (thingStuffPair.thing == thingDef)
                        {
                            allWeaponPairs[i] = new ThingStuffPair(thingStuffPair.thing, thingStuffPair.stuff, thingStuffPair.commonalityMultiplier * num2);
                        }
                    }
                }
            }
        }
        public static void MakeTablePairsByThing(List <ThingStuffPair> pairList)
        {
            DefMap <ThingDef, float> totalCommMult = new DefMap <ThingDef, float>();
            DefMap <ThingDef, float> totalComm     = new DefMap <ThingDef, float>();
            DefMap <ThingDef, int>   pairCount     = new DefMap <ThingDef, int>();

            foreach (ThingStuffPair pair in pairList)
            {
                ThingStuffPair           current = pair;
                ThingDef                 thing;
                DefMap <ThingDef, float> defMap;
                (defMap = totalCommMult)[thing = current.thing] = defMap[thing] + current.commonalityMultiplier;
                ThingDef thing2;
                (defMap = totalComm)[thing2 = current.thing] = defMap[thing2] + current.Commonality;
                DefMap <ThingDef, int> defMap2;
                ThingDef thing3;
                (defMap2 = pairCount)[thing3 = current.thing] = defMap2[thing3] + 1;
            }
            DebugTables.MakeTablesDialog(from d in DefDatabase <ThingDef> .AllDefs
                                         where pairList.Any((ThingStuffPair pa) => pa.thing == d)
                                         select d, new TableDataGetter <ThingDef>("thing", (ThingDef t) => t.defName), new TableDataGetter <ThingDef>("pair count", (ThingDef t) => pairCount[t].ToString()), new TableDataGetter <ThingDef>("total commonality multiplier ", (ThingDef t) => totalCommMult[t].ToString("F4")), new TableDataGetter <ThingDef>("total commonality", (ThingDef t) => totalComm[t].ToString("F4")), new TableDataGetter <ThingDef>("def-commonality", (ThingDef t) => t.generateCommonality.ToString("F4")));
        }
Beispiel #26
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);
            }
        }
        public static void Reset()
        {
            Predicate <ThingDef> isWeapon = (ThingDef td) => td.equipmentType == EquipmentType.Primary && td.canBeSpawningInventory && !td.weaponTags.NullOrEmpty();

            PawnWeaponGenerator.allWeaponPairs = ThingStuffPair.AllWith(isWeapon);
            foreach (ThingDef item in from td in DefDatabase <ThingDef> .AllDefs
                     where isWeapon(td)
                     select td)
            {
                float num  = PawnWeaponGenerator.allWeaponPairs.Where((ThingStuffPair pa) => pa.thing == item).Sum((ThingStuffPair pa) => pa.Commonality);
                float num2 = item.generateCommonality / num;
                if (num2 != 1.0)
                {
                    for (int i = 0; i < PawnWeaponGenerator.allWeaponPairs.Count; i++)
                    {
                        ThingStuffPair thingStuffPair = PawnWeaponGenerator.allWeaponPairs[i];
                        if (thingStuffPair.thing == item)
                        {
                            PawnWeaponGenerator.allWeaponPairs[i] = new ThingStuffPair(thingStuffPair.thing, thingStuffPair.stuff, thingStuffPair.commonalityMultiplier * num2);
                        }
                    }
                }
            }
        }
 public static void Reset()
 {
     allApparelPairs       = ThingStuffPair.AllWith((ThingDef td) => td.IsApparel);
     freeWarmParkaMaxPrice = (int)(StatDefOf.MarketValue.Worker.GetValueAbstract(ThingDefOf.Apparel_Parka, ThingDefOf.Cloth) * 1.3f);
     freeWarmHatMaxPrice   = (int)(StatDefOf.MarketValue.Worker.GetValueAbstract(ThingDefOf.Apparel_Tuque, ThingDefOf.Cloth) * 1.3f);
 }
 private static bool ApparelRequirementCanUseStuff(SpecificApparelRequirement req, ThingStuffPair pair)
 {
     if (req.Stuff == null)
     {
         return(true);
     }
     if (!ApparelRequirementHandlesThing(req, pair.thing))
     {
         return(true);
     }
     if (pair.stuff != null)
     {
         return(req.Stuff == pair.stuff);
     }
     return(false);
 }
        public static void GenerateStartingApparelFor(Pawn pawn, PawnGenerationRequest request)
        {
            if (!pawn.RaceProps.ToolUser || !pawn.RaceProps.IsFlesh)
            {
                return;
            }
            pawn.apparel.DestroyAll();
            float        randomInRange = pawn.kindDef.apparelMoney.RandomInRange;
            float        mapTemperature;
            NeededWarmth neededWarmth  = ApparelWarmthNeededNow(pawn, request, out mapTemperature);
            bool         allowHeadgear = Rand.Value < pawn.kindDef.apparelAllowHeadgearChance;

            debugSb = null;
            if (DebugViewSettings.logApparelGeneration)
            {
                debugSb = new StringBuilder();
                debugSb.AppendLine("Generating apparel for " + pawn);
                debugSb.AppendLine("Money: " + randomInRange.ToString("F0"));
                debugSb.AppendLine("Needed warmth: " + neededWarmth);
                debugSb.AppendLine("Headgear allowed: " + allowHeadgear.ToString());
            }
            int @int = Rand.Int;

            tmpApparelCandidates.Clear();
            for (int i = 0; i < allApparelPairs.Count; i++)
            {
                ThingStuffPair thingStuffPair = allApparelPairs[i];
                if (CanUsePair(thingStuffPair, pawn, randomInRange, allowHeadgear, @int))
                {
                    tmpApparelCandidates.Add(thingStuffPair);
                }
            }
            if (randomInRange < 0.001f)
            {
                GenerateWorkingPossibleApparelSetFor(pawn, randomInRange, tmpApparelCandidates);
            }
            else
            {
                int num = 0;
                while (true)
                {
                    GenerateWorkingPossibleApparelSetFor(pawn, randomInRange, tmpApparelCandidates);
                    if (DebugViewSettings.logApparelGeneration)
                    {
                        debugSb.Append(num.ToString().PadRight(5) + "Trying: " + workingSet.ToString());
                    }
                    if (num < 10 && Rand.Value < 0.85f && randomInRange < 9999999f)
                    {
                        float num2       = Rand.Range(0.45f, 0.8f);
                        float totalPrice = workingSet.TotalPrice;
                        if (totalPrice < randomInRange * num2)
                        {
                            if (DebugViewSettings.logApparelGeneration)
                            {
                                debugSb.AppendLine(" -- Failed: Spent $" + totalPrice.ToString("F0") + ", < " + (num2 * 100f).ToString("F0") + "% of money.");
                            }
                            goto IL_037d;
                        }
                    }
                    if (num < 20 && Rand.Value < 0.97f && !workingSet.Covers(BodyPartGroupDefOf.Torso))
                    {
                        if (DebugViewSettings.logApparelGeneration)
                        {
                            debugSb.AppendLine(" -- Failed: Does not cover torso.");
                        }
                    }
                    else if (num < 30 && Rand.Value < 0.8f && workingSet.CoatButNoShirt())
                    {
                        if (DebugViewSettings.logApparelGeneration)
                        {
                            debugSb.AppendLine(" -- Failed: Coat but no shirt.");
                        }
                    }
                    else
                    {
                        if (num < 50)
                        {
                            bool mustBeSafe = num < 17;
                            if (!workingSet.SatisfiesNeededWarmth(neededWarmth, mustBeSafe, mapTemperature))
                            {
                                if (DebugViewSettings.logApparelGeneration)
                                {
                                    debugSb.AppendLine(" -- Failed: Wrong warmth.");
                                }
                                goto IL_037d;
                            }
                        }
                        if (num >= 80 || !workingSet.IsNaked(pawn.gender))
                        {
                            break;
                        }
                        if (DebugViewSettings.logApparelGeneration)
                        {
                            debugSb.AppendLine(" -- Failed: Naked.");
                        }
                    }
                    goto IL_037d;
IL_037d:
                    num++;
                }
                if (DebugViewSettings.logApparelGeneration)
                {
                    debugSb.Append(" -- Approved! Total price: $" + workingSet.TotalPrice.ToString("F0") + ", TotalInsulationCold: " + workingSet.TotalInsulationCold);
                }
            }
            if ((!pawn.kindDef.apparelIgnoreSeasons || request.ForceAddFreeWarmLayerIfNeeded) && !workingSet.SatisfiesNeededWarmth(neededWarmth, mustBeSafe: true, mapTemperature))
            {
                workingSet.AddFreeWarmthAsNeeded(neededWarmth, mapTemperature);
            }
            if (DebugViewSettings.logApparelGeneration)
            {
                Log.Message(debugSb.ToString());
            }
            workingSet.GiveToPawn(pawn);
            workingSet.Reset(null, null);
            if (pawn.kindDef.apparelColor != Color.white)
            {
                List <Apparel> wornApparel = pawn.apparel.WornApparel;
                for (int j = 0; j < wornApparel.Count; j++)
                {
                    wornApparel[j].SetColor(pawn.kindDef.apparelColor, reportFailure: false);
                }
            }
            List <SpecificApparelRequirement> specificApparelRequirements = pawn.kindDef.specificApparelRequirements;

            if (specificApparelRequirements != null)
            {
                foreach (SpecificApparelRequirement item in specificApparelRequirements.Where((SpecificApparelRequirement x) => x.Color != default(Color)))
                {
                    List <Apparel> wornApparel2 = pawn.apparel.WornApparel;
                    for (int k = 0; k < wornApparel2.Count; k++)
                    {
                        if (ApparelRequirementHandlesThing(item, wornApparel2[k].def))
                        {
                            wornApparel2[k].SetColor(item.Color, reportFailure: false);
                        }
                    }
                }
            }
            foreach (Apparel item2 in pawn.apparel.WornApparel)
            {
                CompBiocodable compBiocodable = item2.TryGetComp <CompBiocodable>();
                if (compBiocodable != null && Rand.Chance(request.BiocodeApparelChance))
                {
                    compBiocodable.CodeFor(pawn);
                }
            }
        }