Beispiel #1
0
 private static void Postfix(Pawn pawn, WorkGiver __instance, ref bool __result)
 {
     if (!__result && !RaceAddonTools.CheckWorkGiver(pawn.def, __instance.def))
     {
         __result = true;
     }
 }
Beispiel #2
0
        private static bool Prefix(Pawn pawn, BodyPartGroupDef bodyPartGroupDef, ref Apparel __result)
        {
            Room room = pawn.GetRoom(RegionType.Set_Passable);

            if (room.isPrisonCell)
            {
                foreach (IntVec3 current in room.Cells)
                {
                    List <Thing> thingList = current.GetThingList(pawn.Map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        if (thingList[i] is Apparel apparel &&
                            RaceAddonTools.CheckApparel(pawn, apparel.def) &&
                            apparel.def.apparel.bodyPartGroups.Contains(bodyPartGroupDef) &&
                            pawn.CanReserve(apparel, 1, -1, null, false) && !apparel.IsBurning() &&
                            ApparelUtility.HasPartsToWear(pawn, apparel.def))
                        {
                            __result = apparel;
                            return(false);
                        }
                    }
                }
            }
            __result = null;
            return(false);
        }
Beispiel #3
0
 private static void Postfix(Pawn p, ref bool __result)
 {
     if (!__result && p.kindDef is RaceAddonPawnKindDef pkd && RaceAddonTools.IsWildMan(pkd))
     {
         __result = true;
     }
 }
 private static void Postfix(Pawn pawn, ThoughtDef def, ref bool __result)
 {
     if (!RaceAddonTools.CheckMood(pawn.def, def))
     {
         __result = false;
     }
 }
Beispiel #5
0
 private static void Postfix(ThingDef t, RaceProperties __instance, ref bool __result)
 {
     if (__result && __instance.Humanlike && DefDatabase <ThingDef> .AllDefsListForReading.First((ThingDef x) => x.race == __instance) is ThingDef thingDef)
     {
         __result = RaceAddonTools.CheckFood(thingDef, t);
     }
 }
 private static void Postfix(Pawn p, RecipeDef ___recipe, ref bool __result)
 {
     if (__result && !RaceAddonTools.CheckRecipe(p.def, ___recipe))
     {
         __result = false;
         JobFailReason.Is("RaceAddonRestriction_FloatMenu".Translate(), null);
     }
 }
Beispiel #7
0
 private static void Postfix(Pawn pawn, Thing t, ref Job __result)
 {
     if (__result != null && !RaceAddonTools.CheckAnimal(pawn.def, t.def))
     {
         __result = null;
         JobFailReason.Is("RaceAddonRestriction_FloatMenu".Translate(), null);
     }
 }
Beispiel #8
0
 private static void Postfix(Pawn pawn, IntVec3 c, ref bool __result)
 {
     if (__result)
     {
         ThingDef plant = c.GetPlant(map: pawn.Map).def;
         __result = RaceAddonTools.CheckPlant(pawn.def, plant);
     }
 }
Beispiel #9
0
 private static void Postfix(IPlantToGrowSettable settable, Pawn pawn, ref bool __result)
 {
     if (__result)
     {
         ThingDef plant = WorkGiver_Grower.CalculateWantedPlantDef((settable as Zone_Growing)?.Cells[0] ?? ((Thing)settable).Position, pawn.Map);
         __result = RaceAddonTools.CheckPlant(pawn.def, plant);
     }
 }
Beispiel #10
0
 private static bool Prefix(Pawn pawn, Apparel ap, ref float __result)
 {
     if (!RaceAddonTools.CheckApparel(pawn, ap.def))
     {
         __result = -100f;
         return(false);
     }
     return(true);
 }
Beispiel #11
0
 private static FloatMenuOption Check(FloatMenuOption menu, ThingDef plantDef)
 {
     if (!PawnsFinder.AllMaps_FreeColonistsSpawned.Any((Pawn x) => RaceAddonTools.CheckPlant(x.def, plantDef)))
     {
         menu.Label    = plantDef.LabelCap + " (" + "RaceAddonRestriction_FloatMenu".Translate() + ")";
         menu.Disabled = true;
     }
     return(menu);
 }
 private static bool Prefix(Pawn pawn, ref List <ThingStuffPair> ___allWeaponPairs)
 {
     if (savedAllWeaponPairs == null)
     {
         savedAllWeaponPairs = ___allWeaponPairs.ListFullCopy();
     }
     ___allWeaponPairs = savedAllWeaponPairs.FindAll((ThingStuffPair x) => RaceAddonTools.CheckWeapon(pawn, x.thing));
     return(true);
 }
 private static void Postfix(ref Designator d, ref bool __result)
 {
     if (__result && d is Designator_Build target && target.PlacingDef is ThingDef def && RaceAddonTools.BuildingRestrictions.Contains(def))
     {
         if (!PawnsFinder.AllMaps_FreeColonistsSpawned.Any((Pawn x) => RaceAddonTools.CheckBuilding(x.def, def)))
         {
             d.disabled       = true;
             d.disabledReason = "RaceAddonRestriction_Designator".Translate();
         }
     }
 }
 private static void Postfix(Pawn pawn, ref bool __result)
 {
     if (!__result)
     {
         ResearchProjectDef project = Find.ResearchManager.currentProj;
         if (!RaceAddonTools.CheckResearch(pawn.def, project))
         {
             __result = true;
         }
     }
 }
 private static void Postfix(Thing t, Pawn p, ref bool __result)
 {
     if (__result && t.def.entityDefToBuild is ThingDef def)
     {
         if (!RaceAddonTools.CheckBuilding(p.def, def))
         {
             __result = false;
             JobFailReason.Is("RaceAddonRestriction_FloatMenu".Translate(), null);
         }
     }
 }
 private static void Postfix(BuildableDef buildable, ref Command __result)
 {
     if (__result != null && buildable is ThingDef def)
     {
         if (!PawnsFinder.AllMaps_FreeColonistsSpawned.Any((Pawn x) => RaceAddonTools.CheckBuilding(x.def, def)))
         {
             __result.disabled       = true;
             __result.disabledReason = "RaceAddonRestriction_Designator".Translate();
         }
     }
 }
Beispiel #17
0
        private static void Postfix(Pawn pawn, Apparel ap, ref float __result)
        {
            if (__result < 0f)
            {
                return;
            }

            if (!RaceAddonTools.CheckApparel(pawn, ap.def))
            {
                __result = -50f;
            }
        }
 private static void Postfix(RecipeDef recipe)
 {
     if (!Find.CurrentMap.mapPawns.FreeColonists.Any((Pawn x) => RaceAddonTools.CheckRecipe(x.def, recipe)))
     {
         string text = "RaceAddonRestriction_Recipe".Translate(recipe.LabelCap);
         text += "\n\n";
         foreach (RaceAddonThingDef thingDef in RaceAddonTools.AllRaceAddonThingDefs.FindAll(x => RaceAddonTools.CheckRecipe(x, recipe)))
         {
             text += thingDef.label + "\n";
         }
         Find.WindowStack.Add(new Dialog_MessageBox(text, null, null, null, null, null, false, null, null));
     }
 }
 private static void NoRaceWarning(ResearchProjectDef def)
 {
     if (!PawnsFinder.AllMaps_FreeColonistsSpawned.Any((Pawn x) => RaceAddonTools.CheckResearch(x.def, def)))
     {
         string text = "RaceAddonRestriction_Research".Translate(def.label);
         text += "\n\n";
         foreach (var thingDef in RaceAddonTools.AllRaceAddonThingDefs.FindAll(x => RaceAddonTools.CheckResearch(x, def)))
         {
             text += thingDef.label + "\n";
         }
         Find.WindowStack.Add(new Dialog_MessageBox(text, null, null, null, null, null, false, null, null));
     }
 }
 private static void Postfix(Pawn pawn, LocalTargetInfo target, ref FloatMenuOption __result)
 {
     if (pawn != null && target.Thing != null)
     {
         var thing = target.Thing;
         if (thing is Apparel apparel && !RaceAddonTools.CheckApparel(pawn, apparel.def) && __result.Label == "ForceWear".Translate(apparel.LabelShort, apparel))
         {
             __result = new FloatMenuOption("CannotWear".Translate(apparel.Label, apparel) + " (" + "RaceAddonRestriction_FloatMenu".Translate() + ")", null);
         }
         if (thing.TryGetComp <CompEquippable>() != null && !RaceAddonTools.CheckWeapon(pawn, thing.def) && __result.Label.Contains("Equip".Translate(thing.LabelShort)))
         {
             __result = new FloatMenuOption("CannotEquip".Translate(thing.LabelShort) + " (" + "RaceAddonRestriction_FloatMenu".Translate() + ")", null);
         }
     }
 }
 private static bool Prefix(Pawn p, ref Thing ___draggedItem, ref bool ___droppedDraggedItem)
 {
     ___droppedDraggedItem = false;
     if (___draggedItem.def.IsApparel && !RaceAddonTools.CheckApparel(p, ___draggedItem.def))
     {
         Messages.Message("RaceAddonRestriction_Caravan".Translate(p.LabelShort), p, MessageTypeDefOf.RejectInput, false);
         ___draggedItem = null;
         return(false);
     }
     if (___draggedItem.def.IsWeapon && !RaceAddonTools.CheckWeapon(p, ___draggedItem.def))
     {
         Messages.Message("RaceAddonRestriction_Caravan".Translate(p.LabelShort), p, MessageTypeDefOf.RejectInput, false);
         ___draggedItem = null;
         return(false);
     }
     return(true);
 }
Beispiel #22
0
 private static bool Prefix(ref PawnGenerationRequest request)
 {
     if (!request.Newborn)
     {
         request = new PawnGenerationRequest(RaceAddonTools.RandomPawnKindDefFromRaceAddonPawnKindDef(request.KindDef), request.Faction,
                                             request.Context, request.Tile, request.ForceGenerateNewPawn, request.Newborn,
                                             request.AllowDead, request.AllowDowned, request.CanGeneratePawnRelations,
                                             request.MustBeCapableOfViolence, request.ColonistRelationChanceFactor, request.ForceAddFreeWarmLayerIfNeeded,
                                             request.AllowGay, request.AllowFood, request.AllowAddictions, request.Inhabitant,
                                             request.CertainlyBeenInCryptosleep, request.ForceRedressWorldPawnIfFormerColonist, request.WorldPawnFactionDoesntMatter,
                                             request.BiocodeWeaponChance, request.ExtraPawnForExtraRelationChance, request.RelationWithExtraPawnChanceFactor,
                                             request.ValidatorPreGear, request.ValidatorPostGear, request.ForcedTraits,
                                             request.ProhibitedTraits, request.MinChanceToRedressWorldPawn, request.FixedBiologicalAge,
                                             request.FixedChronologicalAge, request.FixedGender, request.FixedMelanin, request.FixedLastName,
                                             request.FixedBirthName, request.FixedTitle);
     }
     return(true);
 }
Beispiel #23
0
 private static bool Prefix(Pawn ___pawn, Hediff hediff)
 {
     if (!RaceAddonTools.CheckHediff(___pawn.def, hediff.def))
     {
         return(false);
     }
     if (___pawn.def is RaceAddonThingDef thingDef)
     {
         if (thingDef.raceAddonSettings.hediffSetting.replacedHediffs != null)
         {
             var replacedHediff = thingDef.raceAddonSettings.hediffSetting.replacedHediffs.Find(x => x.originalHediffDef == hediff.def);
             if (replacedHediff != null)
             {
                 hediff.def = replacedHediff.replacedHediffDef;
             }
         }
     }
     return(true);
 }
Beispiel #24
0
        private static void Postfix(ref Pawn __result, ref PawnGenerationRequest request)
        {
            RaceAddonComp racomp = null;

            if (__result.def is RaceAddonThingDef thingDef)
            {
                // get backstorydef
                SimpleBackstoryDef simpleBackstoryDef = null;
                foreach (var backstory in __result.story.AllBackstories)
                {
                    if (DefDatabase <SimpleBackstoryDef> .AllDefsListForReading.Find(x => x.defName == backstory.identifier) is var def && def != null)
                    {
                        simpleBackstoryDef = def;
                    }
                }

                // make default setting
                racomp = __result.GetComp <RaceAddonComp>();

                float maleChance = (simpleBackstoryDef != null && simpleBackstoryDef.maleChance >= 0) ? simpleBackstoryDef.maleChance : thingDef.raceAddonSettings.basicSetting.maleChance;
                __result.gender = GetGender(maleChance, request.FixedGender);
                var gender = __result.gender;

                __result.Name = PawnBioAndNameGenerator.GeneratePawnName(__result, NameStyle.Full, request.FixedLastName);

                racomp.drawSize = RaceAddonTools.GetPawnDrawSize(__result, thingDef);
                var drawSize = thingDef.raceAddonSettings.graphicSetting.drawSize[racomp.drawSize];

                AppearanceDef appearanceDef = null;
                var           list          = (simpleBackstoryDef != null && simpleBackstoryDef.raceAppearances != null) ? simpleBackstoryDef.raceAppearances : thingDef.raceAddonSettings.graphicSetting.raceAppearances;
                if (drawSize.apparanceOverwrite.FindAll(x => x.gender == Gender.None || x.gender == gender) is var list2 && list2.Count > 0)
                {
                    appearanceDef = list2.RandomElementByWeight(x => x.weight).appearanceDef;
                }
                else if (list.FindAll(x => x.gender == Gender.None || x.gender == gender) is var list3 && list3.Count > 0)
                {
                    appearanceDef = list3.RandomElementByWeight(x => x.weight).appearanceDef;
                }
 public override void CompTickRare()
 {
     base.CompTickRare();
     if (Pawn != null && Pawn.Spawned)
     {
         // resolve draw size
         var newDrawSize = RaceAddonTools.GetPawnDrawSize(Pawn, ThingDef);
         if (drawSize != newDrawSize)
         {
             drawSize = newDrawSize;
             if (ThingDef.raceAddonSettings.graphicSetting.drawSize[drawSize].apparanceOverwrite.FindAll(x => x.gender == Gender.None || x.gender == Pawn.gender) is var overwrite && overwrite.Count > 0)
             {
                 var appearanceDef = overwrite.RandomElementByWeight(x => x.weight).appearanceDef;
                 HarmonyPathces_PawnGenerator_GeneratePawn.GenerateAppearance(Pawn, appearanceDef);
                 Pawn.Drawer.renderer.graphics.ResolveAllGraphics();
             }
             else
             {
                 var appearanceDef = ThingDef.raceAddonSettings.graphicSetting.raceAppearances.FindAll(x => x.gender == Gender.None || x.gender == Pawn.gender).RandomElementByWeight(x => x.weight).appearanceDef;
                 HarmonyPathces_PawnGenerator_GeneratePawn.GenerateAppearance(Pawn, appearanceDef);
                 Pawn.Drawer.renderer.graphics.ResolveAllGraphics();
             }
             if (Pawn.IsColonist)
             {
                 Find.LetterStack.ReceiveLetter("RaceAddon_GrowUp_Label".Translate(Pawn.Name.ToStringShort), "RaceAddon_GrowUp_String".Translate(), LetterDefOf.PositiveEvent);
             }
         }
         foreach (var apparel in Pawn.apparel.WornApparel)
         {
             if (!RaceAddonTools.CheckApparel(Pawn, apparel.def))
             {
                 Pawn.apparel.TryDrop(apparel);
             }
         }
         HarmonyPatches_ResolveApparelGraphics.ResolveAddonDraw(this, ThingDef, AllAddonGraphicSets, null);
     }
Beispiel #26
0
 private static void Postfix(Pawn pawn, PawnKindDef ___pawnKind, ref bool __result)
 {
     if (__result == false && ___pawnKind == PawnKindDefOf.WildMan && pawn.kindDef is RaceAddonPawnKindDef pkd && RaceAddonTools.IsWildMan(pkd))
     {
         __result = true;
     }
 }
Beispiel #27
0
 private static void Postfix(Pawn p, ref TraderCaravanRole __result)
 {
     if (__result == TraderCaravanRole.Guard && p.kindDef is RaceAddonPawnKindDef pkd && RaceAddonTools.IsSlave(pkd))
     {
         __result = TraderCaravanRole.Chattel;
     }
 }
Beispiel #28
0
        private static bool Prefix(PawnGraphicSet __instance)
        {
            if (__instance.pawn.def is RaceAddonThingDef thingDef)
            {
                Pawn          pawn   = __instance.pawn;
                RaceAddonComp racomp = pawn.GetComp <RaceAddonComp>();
                racomp.drawSize = RaceAddonTools.GetPawnDrawSize(pawn, thingDef);
                var drawSize = thingDef.raceAddonSettings.graphicSetting.drawSize[racomp.drawSize];
                // cleaning
                __instance.ClearCache();

                // resolve mesh set
                racomp.bodyMeshSet      = new GraphicMeshSet(1.5f * drawSize.bodySize.x, 1.5f * drawSize.bodySize.y);
                racomp.headMeshSet      = new GraphicMeshSet(1.5f * drawSize.headSize.x, 1.5f * drawSize.headSize.y);
                racomp.equipmentMeshSet = new GraphicMeshSet(drawSize.equipmentSize.x, drawSize.equipmentSize.y);

                // resolve body
                var bodyDef = racomp.savedBodyData.def;
                __instance.pawn.story.bodyType = bodyDef.bodyTypeDef;
                __instance.nakedGraphic        = GraphicDatabase.Get <Graphic_Multi>
                                                     (GetBodyNormalPath(bodyDef), bodyDef.shaderType.Shader, Vector2.one, pawn.story.SkinColor, racomp.savedSkinData.color2);
                __instance.rottingGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                (GetBodyNormalPath(bodyDef), bodyDef.shaderType.Shader, Vector2.one, racomp.savedSkinData.rottingColor);
                __instance.dessicatedGraphic = GraphicDatabase.Get <Graphic_Multi>(GetBodySkullPath(bodyDef), ShaderDatabase.Cutout);

                // resolve head
                var headDef = racomp.savedHeadData.def;
                __instance.pawn.story.crownType = headDef.crownType;
                __instance.headGraphic          = GraphicDatabase.Get <Graphic_Multi>
                                                      (headDef.replacedHeadPath, headDef.shaderType.Shader, Vector2.one, pawn.story.SkinColor, racomp.savedSkinData.color2);
                __instance.desiccatedHeadGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                       (headDef.replacedHeadPath, headDef.shaderType.Shader, Vector2.one, racomp.savedSkinData.rottingColor);
                __instance.skullGraphic = GraphicDatabase.Get <Graphic_Multi>
                                              (headDef.replacedSkullPath, headDef.shaderType.Shader, Vector2.one, Color.white);

                // resolve stump
                __instance.headStumpGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                  (headDef.replacedStumpPath, headDef.shaderType.Shader, Vector2.one, pawn.story.SkinColor, racomp.savedSkinData.color2);
                __instance.desiccatedHeadStumpGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                            (headDef.replacedStumpPath, headDef.shaderType.Shader, Vector2.one, racomp.savedSkinData.rottingColor);

                // resolve hair
                HairDef hairDef = pawn.story.hairDef;
                if (hairDef is ImprovedHairDef advancedHairDef)
                {
                    __instance.hairGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                 (advancedHairDef.texPath, advancedHairDef.shaderType.Shader, Vector2.one, pawn.story.hairColor, racomp.savedHairData.color2);
                    if (advancedHairDef.lowerPath != null)
                    {
                        racomp.improvedHairGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                         (advancedHairDef.lowerPath, advancedHairDef.shaderType.Shader, Vector2.one, pawn.story.hairColor, racomp.savedHairData.color2);
                    }
                }
                else
                {
                    __instance.hairGraphic = GraphicDatabase.Get <Graphic_Multi>
                                                 (hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, pawn.story.hairColor);
                    racomp.improvedHairGraphic = null;
                }

                // resolve upper face
                if (racomp.savedFaceData != null && racomp.savedFaceData.upperDef != null)
                {
                    var upperFaceDef = racomp.savedFaceData.upperDef;
                    racomp.upperFaceGraphicSet = new FaceGraphicSet(pawn, racomp.savedFaceData, upperFaceDef, racomp);
                    racomp.upperFaceGraphicSet.ResolveAllGraphics();
                }

                // resolve lower face
                if (racomp.savedFaceData != null && racomp.savedFaceData.lowerDef != null)
                {
                    var lowerFaceDef = racomp.savedFaceData.lowerDef;
                    racomp.lowerFaceGraphicSet = new FaceGraphicSet(pawn, racomp.savedFaceData, lowerFaceDef, racomp);
                    racomp.lowerFaceGraphicSet.ResolveAllGraphics();
                }

                // resolve addons
                if (racomp.savedAddonDatas != null)
                {
                    racomp.bodyAddonGraphicSets = null;
                    racomp.headAddonGraphicSets = null;
                    foreach (var data in racomp.savedAddonDatas)
                    {
                        if (data.def.drawingToBody)
                        {
                            if (racomp.bodyAddonGraphicSets == null)
                            {
                                racomp.bodyAddonGraphicSets = new List <AddonGraphicSet>();
                            }
                            var set = new AddonGraphicSet(data);
                            set.ResolveAllGraphics(racomp.savedSkinData.rottingColor, pawn.health.hediffSet);
                            racomp.bodyAddonGraphicSets.Add(set);
                        }
                        else
                        {
                            if (racomp.headAddonGraphicSets == null)
                            {
                                racomp.headAddonGraphicSets = new List <AddonGraphicSet>();
                            }
                            var set = new AddonGraphicSet(data);
                            set.ResolveAllGraphics(racomp.savedSkinData.rottingColor, pawn.health.hediffSet);
                            racomp.headAddonGraphicSets.Add(set);
                        }
                    }
                }

                if (!pawn.Dead)
                {
                    // resolve eye blinker
                    if (thingDef.raceAddonSettings.graphicSetting.eyeBlink)
                    {
                        racomp.eyeBlinker = new EyeBlinker();
                        racomp.eyeBlinker.Check(pawn.needs.mood.CurLevel);
                    }

                    // resolve head rotator
                    if (thingDef.raceAddonSettings.graphicSetting.headAnimation)
                    {
                        racomp.headRotator = new HeadRotator();
                        racomp.headRotator.Check();
                    }

                    // resolve head targeter
                    if (thingDef.raceAddonSettings.graphicSetting.headTargeting)
                    {
                        racomp.headTargeter = new HeadTargeter(__instance.pawn);
                        racomp.headTargeter.Check();
                    }
                }

                // resolve apparel
                __instance.ResolveApparelGraphics();

                return(false);
            }
            return(true);
        }
Beispiel #29
0
        private static bool Prefix(Pawn pawn, PawnGenerationRequest request)
        {
            if (pawn.story == null)
            {
                return(false);
            }

            RaceAddonThingDef thingDef = pawn.def as RaceAddonThingDef;

            foreach (var backstory in pawn.story.AllBackstories)
            {
                List <TraitEntry> forcedTraits = backstory.forcedTraits;
                if (forcedTraits != null)
                {
                    foreach (var traitEntry in forcedTraits)
                    {
                        if (traitEntry.def == null)
                        {
                            Log.Error("Null forced trait def on " + pawn.story.childhood, false);
                        }
                        else if (!pawn.story.traits.HasTrait(traitEntry.def) && RaceAddonTools.CheckTrait(pawn.def, traitEntry))
                        {
                            pawn.story.traits.GainTrait(new Trait(traitEntry.def, traitEntry.degree, false));
                        }
                    }
                }
            }
            if (thingDef != null)
            {
                foreach (var set in thingDef.raceAddonSettings.traitSetting.forcedTraits)
                {
                    if (Rand.Chance(set.chance))
                    {
                        if (set.traitDef == null)
                        {
                            Log.Error("Null forced trait def on " + thingDef.defName, false);
                        }
                        else if (!pawn.story.traits.HasTrait(set.traitDef) && RaceAddonTools.CheckTrait(pawn.def, set.traitDef, set.degree))
                        {
                            pawn.story.traits.GainTrait(new Trait(set.traitDef, set.degree, false));
                        }
                    }
                }
            }

            int traitCount = 0;

            if (thingDef != null)
            {
                traitCount = thingDef.raceAddonSettings.traitSetting.traitCount.RandomInRange;
            }
            else
            {
                traitCount = Rand.RangeInclusive(2, 3);
            }

            if (request.AllowGay && (LovePartnerRelationUtility.HasAnyLovePartnerOfTheSameGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheSameGender(pawn)))
            {
                Trait trait = new Trait(TraitDefOf.Gay, PawnGenerator.RandomTraitDegree(TraitDefOf.Gay), false);
                if (RaceAddonTools.CheckTrait(pawn.def, trait))
                {
                    pawn.story.traits.GainTrait(trait);
                }
            }

            while (pawn.story.traits.allTraits.Count < traitCount)
            {
                TraitDef newTraitDef = DefDatabase <TraitDef> .AllDefsListForReading.RandomElementByWeight((TraitDef tr) => tr.GetGenderSpecificCommonality(pawn.gender));

                int degree = PawnGenerator.RandomTraitDegree(newTraitDef);

                if (!pawn.story.traits.HasTrait(newTraitDef) && RaceAddonTools.CheckTrait(pawn.def, newTraitDef, degree))
                {
                    if (newTraitDef == TraitDefOf.Gay)
                    {
                        if (!request.AllowGay)
                        {
                            continue;
                        }
                        if (LovePartnerRelationUtility.HasAnyLovePartnerOfTheOppositeGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheOppositeGender(pawn))
                        {
                            continue;
                        }
                    }
                    if (request.Faction == null || Faction.OfPlayerSilentFail == null || !request.Faction.HostileTo(Faction.OfPlayer) || newTraitDef.allowOnHostileSpawn)
                    {
                        if (!pawn.story.traits.allTraits.Any((Trait tr) => newTraitDef.ConflictsWith(tr)) && (newTraitDef.conflictingTraits == null || !newTraitDef.conflictingTraits.Any((TraitDef tr) => pawn.story.traits.HasTrait(tr))))
                        {
                            if (newTraitDef.requiredWorkTypes == null || !pawn.OneOfWorkTypesIsDisabled(newTraitDef.requiredWorkTypes))
                            {
                                if (!pawn.WorkTagIsDisabled(newTraitDef.requiredWorkTags))
                                {
                                    if (!pawn.story.childhood.DisallowsTrait(newTraitDef, degree) && (pawn.story.adulthood == null || !pawn.story.adulthood.DisallowsTrait(newTraitDef, degree)))
                                    {
                                        Trait trait2 = new Trait(newTraitDef, degree, false);
                                        if (pawn.mindState != null && pawn.mindState.mentalBreaker != null)
                                        {
                                            float num2 = pawn.mindState.mentalBreaker.BreakThresholdExtreme;
                                            num2 += trait2.OffsetOfStat(StatDefOf.MentalBreakThreshold);
                                            num2 *= trait2.MultiplierOfStat(StatDefOf.MentalBreakThreshold);
                                            if (num2 > 0.4f)
                                            {
                                                continue;
                                            }
                                        }
                                        pawn.story.traits.GainTrait(trait2);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }