protected const string MessageTraitLost = "TFFramework_MessageTraitLost"; // {0} lost trait {1} from {2}. protected override bool CheckPartWorker(Pawn pawn, object cause) { if (pawn.story?.traits == null) { return(false); } Trait realTrait = pawn.story.traits.GetTrait(trait); if (realTrait != null) { if (realTrait.Degree == realTrait.NearestPossibleDegreeTo(target, delta, operation)) { return(false); } } else { if ((conflicts == ConflictResolutionMode.Fail) && pawn.story.traits.allTraits.Any(t => trait.ConflictsWith(t))) { return(false); } } return(true); }
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); } } } } } } }
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); } } } } } }
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, AlienPawnGenerator.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 = AlienPawnGenerator.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); } } } } } } } }
private static void GenerateTraits(Pawn pawn, PawnGenerationRequest request) { 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, false)); } } } if (pawn.story.adulthood != null && 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, false)); } } } int num = Rand.RangeInclusive(2, 3); if (request.AllowGay && (LovePartnerRelationUtility.HasAnyLovePartnerOfTheSameGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheSameGender(pawn))) { Trait trait = new Trait(TraitDefOf.Gay, PawnGenerator.RandomTraitDegree(TraitDefOf.Gay), false); 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 (!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.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 == 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); } } } } } } } }
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); }
private static void GenerateTraits(Pawn pawn, PawnGenerationRequest request) { if (pawn.story == null) { return; } if (request.ForcedTraits != null) { foreach (TraitDef forcedTrait in request.ForcedTraits) { if (forcedTrait != null) { pawn.story.traits.GainTrait(new Trait(forcedTrait, 0, forced: true)); } } } 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 ((request.KindDef.disallowedTraits == null || !request.KindDef.disallowedTraits.Contains(traitEntry.def)) && !pawn.story.traits.HasTrait(traitEntry.def) && (request.ProhibitedTraits == null || !request.ProhibitedTraits.Contains(traitEntry.def))) { pawn.story.traits.GainTrait(new Trait(traitEntry.def, traitEntry.degree)); } } } if (pawn.story.adulthood != null && 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 ((request.KindDef.disallowedTraits == null || !request.KindDef.disallowedTraits.Contains(traitEntry2.def)) && !pawn.story.traits.HasTrait(traitEntry2.def) && (request.ProhibitedTraits == null || !request.ProhibitedTraits.Contains(traitEntry2.def))) { pawn.story.traits.GainTrait(new Trait(traitEntry2.def, traitEntry2.degree)); } } } int num = Rand.RangeInclusive(2, 3); if (request.AllowGay && (LovePartnerRelationUtility.HasAnyLovePartnerOfTheSameGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheSameGender(pawn))) { Trait trait = new Trait(TraitDefOf.Gay, 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.gender)); if (pawn.story.traits.HasTrait(newTraitDef) || (request.KindDef.disallowedTraits != null && request.KindDef.disallowedTraits.Contains(newTraitDef)) || (request.KindDef.requiredWorkTags != 0 && (newTraitDef.disabledWorkTags & request.KindDef.requiredWorkTags) != 0) || (newTraitDef == TraitDefOf.Gay && (!request.AllowGay || LovePartnerRelationUtility.HasAnyLovePartnerOfTheOppositeGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheOppositeGender(pawn))) || (request.ProhibitedTraits != null && request.ProhibitedTraits.Contains(newTraitDef)) || (request.Faction != null && Faction.OfPlayerSilentFail != null && request.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) || (newTraitDef.forcedPassions != null && pawn.workSettings != null && newTraitDef.forcedPassions.Any((SkillDef p) => p.IsDisabled(pawn.story.DisabledWorkTagsBackstoryAndTraits, pawn.GetDisabledWorkTypes(permanentOnly: true))))) { continue; } int degree = RandomTraitDegree(newTraitDef); if (!pawn.story.childhood.DisallowsTrait(newTraitDef, degree) && (pawn.story.adulthood == null || !pawn.story.adulthood.DisallowsTrait(newTraitDef, degree))) { Trait trait2 = new Trait(newTraitDef, degree); if (pawn.mindState == null || pawn.mindState.mentalBreaker == null || !((pawn.mindState.mentalBreaker.BreakThresholdMinor + trait2.OffsetOfStat(StatDefOf.MentalBreakThreshold)) * trait2.MultiplierOfStat(StatDefOf.MentalBreakThreshold) > 0.5f)) { pawn.story.traits.GainTrait(trait2); } } } }