private void RerollTraits(Pawn pawn, List <Trait> traits)
        {
            for (var i = traits.Count - 1; i >= 0; i--)
            {
                traits.Remove(traits[i]);
            }

            for (var i = 0; i < 3; i++)
            {
                DefDatabase <TraitDef> .AllDefs.TryRandomElement(out var traitDef);

                var num   = PawnGenerator.RandomTraitDegree(traitDef);
                var trait = new Trait(traitDef, num);
                if (traits.Contains(trait))
                {
                    i--;
                }
                else
                {
                    traits.Add(trait);
                }
            }

            string text = "Atlas_TraitReroll".Translate(pawn.Name.ToStringShort).AdjustedFor(pawn);

            string label = "LetterLabelAtlas_TraitReroll".Translate();

            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.NeutralEvent, pawn);
        }
        private static void GiveRandomTraitsTo(Pawn pawn)
        {
            if (pawn.story == null)
            {
                return;
            }

            int num = Rand.RangeInclusive(2, 3);

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

                if (!pawn.story.traits.HasTrait(newTraitDef))
                {
                    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.story.OneOfWorkTypesIsDisabled(newTraitDef.requiredWorkTypes))
                        {
                            if (!pawn.story.WorkTagIsDisabled(newTraitDef.requiredWorkTags))
                            {
                                Trait trait = new Trait(newTraitDef);
                                trait.degree = PawnGenerator.RandomTraitDegree(trait.def);
                                if (pawn.mindState.breaker.HardBreakThreshold + trait.OffsetOfStat(StatDefOf.MentalBreakThreshold) <= 40f)
                                {
                                    pawn.story.traits.GainTrait(trait);
                                }
                            }
                        }
                    }
                }
            }
        }
        private void RerollTraits(Pawn pawn, List <Trait> traits)
        {
            for (int i = traits.Count - 1; i >= 0; i--)
            {
                traits.Remove(traits[i]);
            }

            HashSet <Trait> traitsToAdd = new HashSet <Trait>(3);

            for (int i = 0; i < 3; i++)
            {
                DefDatabase <TraitDef> .AllDefs.TryRandomElement <TraitDef>(out TraitDef traitDef);

                int   num   = PawnGenerator.RandomTraitDegree(traitDef);
                Trait trait = new Trait(traitDef, num, false);
                if (traits.Contains(trait) || traitsToAdd.Contains(trait))
                {
                    i--;
                }
                else
                {
                    traitsToAdd.Add(trait);
                }
            }

            traits.AddRange(traitsToAdd);

            string text = "Atlas_TraitReroll".Translate(pawn.Name.ToStringShort).AdjustedFor(pawn);

            string label = "LetterLabelAtlas_TraitReroll".Translate();

            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.NeutralEvent, pawn, null);
        }
Beispiel #4
0
        public override void TryExecute()
        {
            trait = new Trait(traitDef, PawnGenerator.RandomTraitDegree(traitDef));
            pawn.story.traits.GainTrait(trait);
            viewer.TakeViewerCoins(storeIncident.cost);
            viewer.CalculateNewKarma(storeIncident.karmaType, storeIncident.cost);
            VariablesHelpers.SendPurchaseMessage($"{viewer.username} has purchased " + trait.LabelCap + " for " + pawn.Name + ".", separateChannel);
            string text = $"@{viewer.username} just added the trait " + traitDef.LabelCap + " to " + pawn.Name + ".";

            Current.Game.letterStack.ReceiveLetter("Trait", text, LetterDefOf.PositiveEvent, pawn);
        }
Beispiel #5
0
        public void ExposeData()
        {
            Scribe_Defs.Look <TraitDef>(ref this.def, "def");
            Scribe_Values.Look <int>(ref this.degree, "degree", 0, false);
            Scribe_Values.Look <bool>(ref this.scenForced, "scenForced", false, false);
            if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs && this.def == null)
            {
                this.def = DefDatabase <TraitDef> .GetRandom();

                this.degree = PawnGenerator.RandomTraitDegree(this.def);
            }
        }
        public void ReplaceVanillaTraits()
        {
            if (parent is Pawn pawn)
            {
                CompIndividuality comp = pawn.TryGetComp <CompIndividuality>();
                if (comp != null && pawn?.story?.traits != null && (pawn.story.traits.HasTrait(TraitDefOf.Gay) || pawn.story.traits.HasTrait(TraitDefOf.Bisexual) || pawn.story.traits.HasTrait(TraitDefOf.Asexual) || pawn.story.traits.HasTrait(TraitDefOf.PsychicSensitivity)))
                {
                    if (pawn.story.traits.HasTrait(TraitDefOf.Gay))
                    {
                        comp.sexuality = Sexuality.Gay;
                    }
                    else if (pawn.story.traits.HasTrait(TraitDefOf.Bisexual))
                    {
                        comp.sexuality = Sexuality.Bisexual;
                    }
                    else if (pawn.story.traits.HasTrait(TraitDefOf.Asexual))
                    {
                        comp.sexuality = Sexuality.Asexual;
                    }
                    if (pawn.story.traits.HasTrait(TraitDefOf.PsychicSensitivity))
                    {
                        switch (pawn.story.traits.GetTrait(TraitDefOf.PsychicSensitivity).Degree)
                        {
                        case -2: comp.PsychicFactor = -1f; break;

                        case -1: comp.PsychicFactor = -0.4f; break;

                        case 1: comp.PsychicFactor = 0.4f; break;

                        case 2: comp.PsychicFactor = 0.8f; break;
                        }
                    }
                    if (!SyrIndividuality.RomanceDisabled)
                    {
                        pawn.story.traits.allTraits.RemoveAll(t => t.def == TraitDefOf.Bisexual || t.def == TraitDefOf.Asexual || t.def == TraitDefOf.Gay || t.def == TraitDefOf.PsychicSensitivity);
                        IEnumerable <TraitDef> allTraitDefs   = DefDatabase <TraitDef> .AllDefsListForReading;
                        Func <TraitDef, float> weightSelector = (TraitDef tr) => tr.GetGenderSpecificCommonality(pawn.gender);
                        TraitDef newTraitDef = allTraitDefs.RandomElementByWeight(weightSelector);
                        if (!pawn.story.traits.HasTrait(newTraitDef) && (pawn.Faction == null || Faction.OfPlayerSilentFail == null || !pawn.Faction.HostileTo(Faction.OfPlayer) || newTraitDef.allowOnHostileSpawn) &&
                            !pawn.story.traits.allTraits.Any((Trait tr) => newTraitDef.ConflictsWith(tr)) && (newTraitDef.requiredWorkTypes == null ||
                                                                                                              !pawn.OneOfWorkTypesIsDisabled(newTraitDef.requiredWorkTypes)) && !pawn.WorkTagIsDisabled(newTraitDef.requiredWorkTags))
                        {
                            int degree = PawnGenerator.RandomTraitDegree(newTraitDef);
                            if (pawn.story.childhood == null || !pawn.story.childhood.DisallowsTrait(newTraitDef, degree) && (pawn.story.adulthood == null || !pawn.story.adulthood.DisallowsTrait(newTraitDef, degree)))
                            {
                                Trait trait = new Trait(newTraitDef, degree, false);
                                pawn.story.traits.GainTrait(trait);
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public void ExposeData()
        {
            Scribe_Defs.Look(ref def, "def");
            Scribe_Values.Look(ref degree, "degree", 0);
            Scribe_Values.Look(ref scenForced, "scenForced", defaultValue: false);
            if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs && def == null)
            {
                def = DefDatabase <TraitDef> .GetRandom();

                degree = PawnGenerator.RandomTraitDegree(def);
            }
        }
Beispiel #8
0
        public new void ExposeData()
        {
            base.ExposeData();
            Scribe_Defs.LookDef <SoulTraitDef>(ref this.SDef, "SDef");
            //           Scribe_Collections.LookList<ThoughtDef>(ref this.NullifiedThoughtsInt, "NullifiedThoughtsInt", LookMode.Deep, new object[0]);
            Scribe_Values.LookValue <int>(ref this.degree, "degree", 0, false);
            Scribe_Deep.LookDeep <SoulTraitDegreeData>(ref this.CurrentSData, "CurrentSData", null, false);

            if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs && this.def == null)
            {
                this.def = DefDatabase <SoulTraitDef> .GetRandom();

                this.degree = PawnGenerator.RandomTraitDegree(this.SDef);
            }
        }
Beispiel #9
0
        public static void SetPawnTraits(Pawn pawn, int num)
        {
            pawn.story.traits.allTraits.Clear();
            while (pawn.story.traits.allTraits.Count < num)
            {
                TraitDef newTraitDef = DefDatabase <TraitDef> .GetRandom();

                if (!pawn.story.traits.HasTrait(newTraitDef))
                {
                    if (newTraitDef.conflictingTraits == null || !Contains(pawn, newTraitDef.conflictingTraits))
                    {
                        Trait trait = new Trait(newTraitDef);
                        trait.degree = PawnGenerator.RandomTraitDegree(trait.def);

                        if (pawn.mindState.breaker.HardBreakThreshold + trait.OffsetOfStat(StatDefOf.MentalBreakThreshold) <= 40f)
                        {
                            pawn.story.traits.GainTrait(trait);
                        }
                    }
                }
            }
        }
Beispiel #10
0
        //Patch for Caravan/Worldmap death
        //TBF

        //Patch death messages
        //TBF

        //Change Appearance, Traits and memories of pawns
        static void Regenerate(Pawn __instance)
        {
            // Health State Changes ----------------------------------------------------------------------------------------------------------

            //Resurrect the __instance
            ResurrectionUtility.Resurrect(__instance);

            //Remove all bad hediffs
            foreach (Hediff h in __instance.health.hediffSet.GetHediffs <Hediff>())
            {
                if (h.def.isBad)
                {
                    __instance.health.RemoveHediff(h);
                }
            }

            //Add resurrection sickness
            __instance.health.AddHediff(HediffDef.Named("ResurrectionSickness"));

            //Remove current RegenHediff and add the next
            BodyPartRecord heart = __instance.health.hediffSet.GetNotMissingParts().First(bpr => bpr.def == BodyPartDefOf.Heart);

            HediffDef Regen1Def  = HediffDef.Named("Regeneration01");
            HediffDef Regen2Def  = HediffDef.Named("Regeneration02");
            HediffDef Regen3Def  = HediffDef.Named("Regeneration03");
            HediffDef Regen4Def  = HediffDef.Named("Regeneration04");
            HediffDef Regen5Def  = HediffDef.Named("Regeneration05");
            HediffDef Regen6Def  = HediffDef.Named("Regeneration06");
            HediffDef Regen7Def  = HediffDef.Named("Regeneration07");
            HediffDef Regen8Def  = HediffDef.Named("Regeneration08");
            HediffDef Regen9Def  = HediffDef.Named("Regeneration09");
            HediffDef Regen10Def = HediffDef.Named("Regeneration10");
            HediffDef Regen11Def = HediffDef.Named("Regeneration11");
            HediffDef Regen12Def = HediffDef.Named("Regeneration12");
            HediffDef Regen13Def = HediffDef.Named("Regeneration13");

            if (__instance.health.hediffSet.HasHediff(Regen1Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen1Def)); __instance.health.AddHediff(Regen2Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen2Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen2Def)); __instance.health.AddHediff(Regen3Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen3Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen3Def)); __instance.health.AddHediff(Regen4Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen4Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen4Def)); __instance.health.AddHediff(Regen5Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen5Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen5Def)); __instance.health.AddHediff(Regen6Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen6Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen6Def)); __instance.health.AddHediff(Regen7Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen7Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen7Def)); __instance.health.AddHediff(Regen8Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen8Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen8Def)); __instance.health.AddHediff(Regen9Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen9Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen9Def)); __instance.health.AddHediff(Regen10Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen10Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen10Def)); __instance.health.AddHediff(Regen11Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen11Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen11Def)); __instance.health.AddHediff(Regen12Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen12Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen12Def)); __instance.health.AddHediff(Regen13Def, heart);
            }

            // Visual Changes ----------------------------------------------------------------------------------------------------------

            //Gender
            __instance.gender = GenderSwap(__instance.gender);

            //Skintone
            __instance.story.melanin = 0.01f * Rand.Range(10, 200);

            //Head
            var graphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(__instance.gender, __instance.story.SkinColor, __instance.story.crownType).GraphicPath;

            Traverse.Create(__instance.story).Field("headGraphicPath").SetValue(graphicPath);

            //Hair
            __instance.story.hairDef   = PawnHairChooser.RandomHairDefFor(__instance, FactionDefOf.PlayerColony);
            __instance.story.hairColor = HairColor();

            //Body
            __instance.story.bodyType = BodySwap(__instance.gender);

            //Redraw the __instance to trigger the above affects
            __instance.Drawer.renderer.graphics.nakedGraphic = null;

            // Bio Changes ----------------------------------------------------------------------------------------------------------

            //randomise traits
            __instance.story.traits.allTraits.Clear();
            int i    = 0;
            int rInt = Rand.RangeInclusive(1, 3);

            while (i < rInt)
            {
                TraitDef random = DefDatabase <TraitDef> .GetRandom();

                Trait trait = new Trait(random, PawnGenerator.RandomTraitDegree(random), false);
                __instance.story.traits.GainTrait(trait);
                Trait trait2 = new Trait(random, PawnGenerator.RandomTraitDegree(random), false);
                __instance.story.traits.GainTrait(trait2);
                i++;
            }

            //Add Memory
            __instance.needs.mood.thoughts.memories.TryGainMemory(RegenerationThoughtDefs.RecentlyRegenerated, null);

            //Add debuff thought to all related colonists
            foreach (Pawn p in __instance.relations.RelatedPawns)
            {
                //Log.Warning("related to: " + p.Name);
                try
                {
                    if (!p.health.Dead)
                    {
                        p.needs.mood.thoughts.memories.TryGainMemory(RegenerationThoughtDefs.KnownColonistRegeneratedSocial, __instance);
                        p.needs.mood.thoughts.memories.TryGainMemory(RegenerationThoughtDefs.KnownColonistRegenerated);
                    }
                }
                catch
                {
                    Log.Warning("Couldn't add social debuff to " + p.Name);
                }
            }

            // Visual effects -------------------------------------------------------------------------------------------------------

            //Glow effect (ugly approach, look at cleaning this up)
            MoteMaker.ThrowAirPuffUp(__instance.DrawPos, __instance.Map);
            MoteMaker.ThrowFireGlow(__instance.Position, __instance.Map, 3f);
            MoteMaker.ThrowFireGlow(__instance.Position, __instance.Map, 3f);
            MoteMaker.ThrowFireGlow(__instance.Position, __instance.Map, 3f);
            MoteMaker.ThrowFireGlow(__instance.Position, __instance.Map, 3f);
            MoteMaker.ThrowFireGlow(__instance.Position, __instance.Map, 3f);
        }
Beispiel #11
0
        private static void GiveRandomTraits(Pawn pawn, bool allowGay)
        {
            if (pawn.story == null)
            {
                return;
            }
            if (pawn.story.childhood.forcedTraits != null)
            {
                List <TraitEntry> forcedTraits = pawn.story.childhood.forcedTraits;
                for (int i = 0; i < forcedTraits.Count; i++)
                {
                    TraitEntry traitEntry = forcedTraits[i];
                    if (traitEntry.def == null)
                    {
                        Log.Error("Null forced trait def on " + pawn.story.childhood);
                    }
                    else if (!pawn.story.traits.HasTrait(traitEntry.def))
                    {
                        pawn.story.traits.GainTrait(new Trait(traitEntry.def, traitEntry.degree));
                    }
                }
            }
            if (pawn.story.adulthood.forcedTraits != null)
            {
                List <TraitEntry> forcedTraits2 = pawn.story.adulthood.forcedTraits;
                for (int j = 0; j < forcedTraits2.Count; j++)
                {
                    TraitEntry traitEntry2 = forcedTraits2[j];
                    if (traitEntry2.def == null)
                    {
                        Log.Error("Null forced trait def on " + pawn.story.adulthood);
                    }
                    else if (!pawn.story.traits.HasTrait(traitEntry2.def))
                    {
                        pawn.story.traits.GainTrait(new Trait(traitEntry2.def, traitEntry2.degree));
                    }
                }
            }
            int num = Rand.RangeInclusive(2, 3);

            if (allowGay && (LovePartnerRelationUtility.HasAnyLovePartnerOfTheSameGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheSameGender(pawn)))
            {
                Trait trait = new Trait(TraitDefOf.Gay, PawnGenerator.RandomTraitDegree(TraitDefOf.Gay));
                pawn.story.traits.GainTrait(trait);
            }
            while (pawn.story.traits.allTraits.Count < num)
            {
                TraitDef newTraitDef = DefDatabase <TraitDef> .AllDefsListForReading.RandomElementByWeight((TraitDef tr) => tr.GetGenderSpecificCommonality(pawn));

                if (!pawn.story.traits.HasTrait(newTraitDef))
                {
                    if (newTraitDef == TraitDefOf.Gay)
                    {
                        if (!allowGay)
                        {
                            continue;
                        }
                        if (LovePartnerRelationUtility.HasAnyLovePartnerOfTheOppositeGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheOppositeGender(pawn))
                        {
                            continue;
                        }
                    }
                    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.story.OneOfWorkTypesIsDisabled(newTraitDef.requiredWorkTypes))
                        {
                            if (!pawn.story.WorkTagIsDisabled(newTraitDef.requiredWorkTags))
                            {
                                int degree = PawnGenerator.RandomTraitDegree(newTraitDef);
                                if (!pawn.story.childhood.DisallowsTrait(newTraitDef, degree) && !pawn.story.adulthood.DisallowsTrait(newTraitDef, degree))
                                {
                                    Trait trait2 = new Trait(newTraitDef, degree);
                                    if (pawn.mindState == null || pawn.mindState.mentalBreaker == null || pawn.mindState.mentalBreaker.BreakThresholdExtreme + trait2.OffsetOfStat(StatDefOf.MentalBreakThreshold) <= 40f)
                                    {
                                        pawn.story.traits.GainTrait(trait2);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #12
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);
        }