Beispiel #1
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 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;
                }