public static void Post(ref Pawn pawn, PawnGenerationRequest request) { var hediffGiverSet = pawn?.def?.race?.hediffGiverSets; if (hediffGiverSet == null) { return; } foreach (var item in hediffGiverSet) { var hediffGivers = item.hediffGivers; if (hediffGivers == null) { return; } if (hediffGivers.Any(y => y is HediffGiver_StartWithHediff)) { foreach (var hdg in hediffGivers.Where(x => x is HediffGiver_StartWithHediff)) { HediffGiver_StartWithHediff hediffGiver_StartWith = (HediffGiver_StartWithHediff)hdg; hediffGiver_StartWith.GiveHediff(pawn); } } } }
public static void GeneratePawn_ForceFactionTraits_Postfix(ref Pawn __result) { if (__result != null) { if (__result.Faction != null && __result.RaceProps.Humanlike) { if (__result.Faction.def.HasModExtension <FactionDefExtension>()) { if (__result.Faction.def.GetModExtension <FactionDefExtension>() is FactionDefExtension Forced) { if (__result.RaceProps.Humanlike) { foreach (FactionTraitEntry item in Forced.ForcedTraits) { if (!__result.story.traits.HasTrait(item.def)) { int maxTraits; if (MoreTraitSlotsUtil.TryGetMaxTraitSlots(out int max)) { maxTraits = max; } else { maxTraits = 4; } if (Rand.Chance(item.Chance)) { if (__result.story.traits.allTraits.Count >= maxTraits) { if (!item.replaceiffull) { return; } __result.story.traits.allTraits.Remove(__result.story.traits.allTraits.RandomElement()); } Trait trait = new Trait(item.def, item.degree); __result.story.traits.GainTrait(trait); } } } } foreach (HediffGiverSetDef item in Forced.hediffGivers) { foreach (var hdg in item.hediffGivers.Where(x => x is HediffGiver_StartWithHediff)) { HediffGiver_StartWithHediff hediffGiver_StartWith = (HediffGiver_StartWithHediff)hdg; if (__result.health.hediffSet.GetNotMissingParts().Any(x => hediffGiver_StartWith.partsToAffect.Contains(x.def))) { hediffGiver_StartWith.GiveHediff(__result); } } } } } } } }
public static void Postfix(ref Pawn pawn, ref PawnGenerationRequest request) { if (pawn != null) { if (pawn.Faction != null && pawn.RaceProps.Humanlike) { if (pawn.story.childhood == null) { pawn.story.childhood = BackstoryDatabase.RandomBackstory(BackstorySlot.Childhood); PawnBioAndNameGenerator.GiveAppropriateBioAndNameTo(pawn, request.FixedLastName, pawn.Faction.def); if (pawn.story.adulthood == null) { pawn.story.adulthood = BackstoryDatabase.RandomBackstory(BackstorySlot.Adulthood); PawnBioAndNameGenerator.GiveAppropriateBioAndNameTo(pawn, request.FixedLastName, pawn.Faction.def); } // log.message(string.Format("reroll {0} : {1}({2}) : {3} : {4} : {5}", pawn.NameShortColored, pawn.KindLabel, pawn.kindDef.defName, pawn.story.childhood, pawn.story.adulthood, pawn.Faction)); } if (pawn.Faction.def.HasModExtension <FactionDefExtension>()) { if (pawn.Faction.def.GetModExtensionFast <FactionDefExtension>() is FactionDefExtension Forced && Forced != null) { if (pawn.RaceProps.Humanlike) { foreach (FactionTraitEntry item in Forced.ForcedTraits) { // log.message(string.Format("{0} : {1}", pawn.NameShortColored, item.def.LabelCap)); if (!pawn.story.traits.HasTrait(item.def)) { int maxTraits; if (MoreTraitSlotsUtil.TryGetMaxTraitSlots(out int max)) { maxTraits = max; } else { maxTraits = 4; } Rand.PushState(); bool act = Rand.Chance(item.Chance); Rand.PopState(); if (act) { if (pawn.story.traits.allTraits.Count >= maxTraits) { if (!item.replaceiffull) { return; } pawn.story.traits.allTraits.Remove(pawn.story.traits.allTraits.RandomElement()); } Trait trait = new Trait(item.def, item.degree); pawn.story.traits.GainTrait(trait); } } } } foreach (HediffGiverSetDef item in Forced.hediffGivers) { foreach (var hdg in item.hediffGivers.Where(x => x is HediffGiver_StartWithHediff)) { HediffGiver_StartWithHediff hediffGiver_StartWith = (HediffGiver_StartWithHediff)hdg; if (pawn.health.hediffSet.GetNotMissingParts().Any(x => hediffGiver_StartWith.partsToAffect.Contains(x.def))) { hediffGiver_StartWith.GiveHediff(pawn); } } } } } } } }