public void CheckAgeSetting() { var thingDef = pawn.def as RaceAddonThingDef; var newAgeSetting = thingDef.raceAddonSettings.ageSettings.GetPresent(pawn); if (presentAgeSetting != newAgeSetting) { presentAgeSetting = newAgeSetting; AppearanceDef appearanceDef = presentAgeSetting.appearances?.GetAppearanceDef(pawn, true); if (appearanceDef != null && !presentAgeSetting.keepAppearance) { RaceAddon.SetAppearance(pawn, racomp, thingDef, appearanceDef); } racomp.raceAddonGraphicSet = new RaceAddonGraphicSet(pawn, racomp); pawn.Drawer.renderer.graphics.ResolveAllGraphics(); if (pawn.IsColonist) { Find.LetterStack.ReceiveLetter("RaceAddon_GrowUp_Label".Translate(pawn.Name.ToStringShort), "RaceAddon_GrowUp_String".Translate(), LetterDefOf.PositiveEvent); } /* * if (presentAgeSetting.ageBackstory != null && thingDef.raceAddonSettings.ageSettings[thingDef.raceAddonSettings.ageSettings.IndexOf(presentAgeSetting) - 1].ageBackstory.Backstory == pawn.story.childhood) * { * pawn.story.childhood = presentAgeSetting.ageBackstory.Backstory; * * if (presentAgeSetting.ageBackstory.skillGains.Count > 0) * { * foreach (SkillGain skillGain in presentAgeSetting.ageBackstory.skillGains) * { * pawn.skills.Learn(skillGain.skill, skillGain.xp, true); * pawn.skills.skills.ForEach(x => x.Level += x.def == skillGain.skill ? skillGain.xp : 0); * } * } * if (presentAgeSetting.ageBackstory.forcedHediffs.Count > 0) * { * foreach (var set in presentAgeSetting.ageBackstory.forcedHediffs) * { * Hediff hediff = HediffMaker.MakeHediff(set.hediffDef, pawn, set.targetPart.GetBodyPartRecord(pawn.def.race.body)); * hediff.Severity = set.severity; * pawn.health.AddHediff(hediff); * } * } * * pawn.workSettings = new Pawn_WorkSettings(pawn); * pawn.workSettings.EnableAndInitialize(); * } */ } }
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 static bool RaceAddonGenerator(Pawn pawn, ref PawnGenerationRequest request) { if (pawn.def is RaceAddonThingDef thingDef) { FactionDef factionDef; if (request.Faction != null) { factionDef = request.Faction.def; } else if (Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction_NewTemp(out Faction faction, false, true, TechLevel.Undefined)) { factionDef = faction.def; } else { factionDef = Faction.OfAncients.def; } // Race Addon Comp var racomp = pawn.GetComp <RaceAddonComp>(); // Backstory /* * if (request.Newborn && factionDef == Find.FactionManager.OfPlayer.def && thingDef.raceAddonSettings.ageSettings[0].ageBackstory != null) * { * pawn.story.childhood = thingDef.raceAddonSettings.ageSettings[0].ageBackstory.Backstory; * } */ GiveAppropriateBioAndNameTo.cachedNewborn = request.Newborn; PawnBioAndNameGenerator.GiveAppropriateBioAndNameTo(pawn, request.FixedLastName, factionDef); GiveAppropriateBioAndNameTo.cachedNewborn = false; SimpleBackstoryDef backstoryDef = null; foreach (var backstory in pawn.story.AllBackstories) { backstoryDef = backstory.GetDef(); if (backstoryDef != null) { // set age bool flag1 = false; bool flag2 = false; if (backstoryDef.bioAgeRange.Average >= 0) { request.FixedBiologicalAge = backstoryDef.bioAgeRange.RandomInRange; flag1 = true; } if (backstoryDef.chronoAgeRange.Average >= 0) { request.FixedChronologicalAge = flag1 ? request.FixedBiologicalAge + backstoryDef.chronoAgeRange.RandomInRange : pawn.ageTracker.AgeBiologicalYearsFloat + backstoryDef.chronoAgeRange.RandomInRange; flag2 = true; } if (flag1 || flag2) { AccessTools.Method(typeof(PawnGenerator), "GenerateRandomAge").Invoke(null, new object[] { pawn, request }); } // set gender if (backstoryDef.maleChance >= 0f) { pawn.gender = Rand.Chance(backstoryDef.maleChance) ? Gender.Male : Gender.Female; request.FixedGender = pawn.gender; } else { pawn.gender = Rand.Chance(thingDef.raceAddonSettings.basicSetting.maleChance) ? Gender.Male : Gender.Female; request.FixedGender = pawn.gender; } } } // Fix Name pawn.Name = PawnBioAndNameGenerator.GeneratePawnName(pawn, NameStyle.Full, request.FixedLastName); // Choose AppearanceDef AppearanceDef appearanceDef = null; if (backstoryDef?.appearances?.GetAppearanceDef(pawn) is var def && def != null) { appearanceDef = def; }