public static bool GiveShuffledBioTo_AdultAge_Prefix(Pawn pawn, FactionDef factionType, string requiredLastName, ref List <BackstoryCategoryFilter> backstoryCategories)
        {
            if (pawn != null)
            {
                return(true);
            }
            if (!pawn.RaceProps.Humanlike)
            {
                return(true);
            }
            bool ext = pawn.kindDef.HasModExtension <BackstoryExtension>();

            if (ext)
            {
                BackstoryCategoryFilter backstoryCategoryFilter = backstoryCategories.RandomElementByWeight((BackstoryCategoryFilter c) => c.commonality);
                backstoryCategories.Clear();
                backstoryCategories.Add(backstoryCategoryFilter);
            }
            if (pawn.ageTracker.AgeBiologicalYears < 20 && pawn.def.modContentPack.PackageIdPlayerFacing.Contains("AdMech"))
            {
                bool act = pawn.RaceProps.lifeStageAges.Any(x => x.def.reproductive);
                if (act)
                {
                    GiveShuffledBioTo(pawn, factionType, requiredLastName, backstoryCategories);
                    return(false);
                }
            }
            if (backstoryCategories.NullOrEmpty())
            {
                Log.Warning(string.Format("{0} backstoryCategories null", pawn.NameShortColored));
            }
            return(true);
        }
Esempio n. 2
0
    public static bool Prefix_GiveShuffledBioTo_Orkoid(Pawn pawn, FactionDef factionType, string requiredLastName, ref List <BackstoryCategoryFilter> backstoryCategories)
    {
        if (pawn == null)
        {
            return(true);
        }
        if (!pawn.RaceProps.Humanlike)
        {
            return(true);
        }
        if (pawn.ageTracker == null || pawn.health == null || pawn.story == null || pawn.RaceProps.FleshType != OGOrkThingDefOf.OG_Flesh_Orkoid)
        {
            return(true);
        }
        bool ext = pawn.kindDef.HasModExtension <BackstoryExtension>();

        if (ext)
        {
            BackstoryCategoryFilter backstoryCategoryFilter = backstoryCategories.RandomElementByWeight((BackstoryCategoryFilter c) => c.commonality);
            backstoryCategories.Clear();
            backstoryCategories.Add(backstoryCategoryFilter);
            //    Log.Message(pawn.LabelShortCap + " BackstoryExtension using "+ backstoryCategoryFilter.categories.ToCommaList());
        }
        else
        {
            //    Log.Message(pawn.LabelShortCap + " No BackstoryExtension");
        }
        if (pawn.health.hediffSet.hediffs.Any(x => x.def.defName.Contains("TM_") && (x.def.defName.Contains("Undead") || x.def.defName.Contains("Lich"))))
        {
            return(true);
        }
        if ((pawn.ageTracker.AgeBiologicalYears < 20 && (pawn.def.defName.StartsWith("OG_") || pawn.kindDef.defName.StartsWith("OG_"))) || ext)
        {
            //    Log.Message(string.Format("AdMech mod pawn: {0} {1} {2}",pawn.NameShortColored, pawn.kindDef, pawn.def.modContentPack.PackageIdPlayerFacing));
            bool act = pawn.RaceProps.lifeStageAges.Any(x => x.def.reproductive);
            if (act)
            {
                if (pawn.ageTracker.AgeBiologicalYears > pawn.RaceProps.lifeStageAges.First(x => x.def.reproductive).minAge)
                {
                    FillBackstorySlotShuffled(pawn, BackstorySlot.Childhood, ref pawn.story.childhood, pawn.story.adulthood, backstoryCategories, factionType);
                    if (pawn.ageTracker.AgeBiologicalYearsFloat >= pawn.RaceProps.lifeStageAges.First(x => x.def.reproductive).minAge)
                    {
                        FillBackstorySlotShuffled(pawn, BackstorySlot.Adulthood, ref pawn.story.adulthood, pawn.story.childhood, backstoryCategories, factionType);
                    }
                    pawn.Name = PawnBioAndNameGenerator.GeneratePawnName(pawn, NameStyle.Full, requiredLastName);
                    return(false);
                }
            }
        }
        return(true);
    }
Esempio n. 3
0
 public static bool FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, Backstory backstoryOtherSlot, List <BackstoryCategoryFilter> backstoryCategories, FactionDef factionType)
 {
     if (pawn.def.defName.StartsWith("OG_"))
     {
         //    Log.Message(pawn.NameShortColored + " is " +pawn.def + " in " + pawn.Faction);
         BackstoryCategoryFilter backstoryCategoryFilter = backstoryCategories.RandomElementByWeight((BackstoryCategoryFilter c) => c.commonality);
         if (backstoryCategoryFilter == null)
         {
             //    Log.Message(pawn.def + " in " + pawn.Faction + " backstoryCategoryFilter == null");
             backstoryCategoryFilter = FallbackCategoryGroup;
             //    Log.Message(pawn.def + " in " + pawn.Faction + " backstoryCategoryFilter == " + backstoryCategoryFilter);
         }
         List <string> lista = new List <string>();
         foreach (BackstoryCategoryFilter filter in backstoryCategories)
         {
             foreach (string str in filter.categories)
             {
                 if (!lista.Contains(str))
                 {
                     lista.Add(str);
                 }
             }
         }
         if (!(from bs in BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategoryFilter).TakeRandom(20)
               where slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)
               select bs).TryRandomElementByWeight(new Func <Backstory, float>(BackstorySelectionWeight), out backstory))
         {
             //    Log.Message(string.Format("backstoryCategories: {0}, used backstoryCategoryFilter: {1}", lista.ToCommaList(), backstoryCategoryFilter.categories.ToCommaList()));
             Log.Error(string.Concat(new object[]
                 {
                     "No shuffled ",
                     slot,
                     " found for ",
                     pawn.ToStringSafe <Pawn>(),
                     " of ",
                     factionType.ToStringSafe <FactionDef>(),
                     ". Choosing random."
                 }), false);
             backstory = (from kvp in BackstoryDatabase.allBackstories
                          where kvp.Value.slot == slot
                          select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
         }
         return(false);
     }
     return(true);
 }
Esempio n. 4
0
        public static void Postfix(Pawn pawn, FactionDef faction, ref List <BackstoryCategoryFilter> __result)
        {
            if (faction.defName != "TribalRaiders")
            {
                return;
            }

            var strs = new List <BackstoryCategoryFilter>();
            var backstoryCategoryFilter = new BackstoryCategoryFilter {
                categories = new List <string> {
                    "TribalRaider"
                }
            };

            strs.Add(backstoryCategoryFilter);
            __result = strs;
        }
        public static bool TryGetRandomUnusedSolidBioFor(List <BackstoryCategoryFilter> backstoryCategories, PawnKindDef kind, Gender gender, string requiredLastName, out PawnBio result)
        {
            // Pick a random category filter.
            BackstoryCategoryFilter categoryFilter = backstoryCategories.RandomElementByWeight((c) => {
                return(c.commonality);
            });

            // Settle for a default category filter if none was chosen.
            if (categoryFilter == null)
            {
                categoryFilter = Reflection.PawnBioAndNameGenerator.GetFallbackCategoryGroup();
            }
            // Choose a weighted bio.
            return((from bio in SolidBioDatabase.allBios.TakeRandom(20)
                    where Reflection.PawnBioAndNameGenerator.IsBioUseable(bio, categoryFilter, kind, gender, requiredLastName)
                    select bio).TryRandomElementByWeight(new Func <PawnBio, float>(Reflection.PawnBioAndNameGenerator.BioSelectionWeight), out result));
        }
        public static void Prefix(Pawn pawn, FactionDef factionType, ref List <BackstoryCategoryFilter> backstoryCategories)
        {
            BackstoryExtension Ext = pawn.kindDef.GetModExtensionFast <BackstoryExtension>();

            if (Ext != null)
            {
                List <BackstoryCategoryFilter> Categories = new List <BackstoryCategoryFilter>();
                if (Ext.AdultUseChildCatergory)
                {
                    BackstoryCategoryFilter filter = backstoryCategories.RandomElementByWeight(x => x.commonality);
                    if (filter != null)
                    {
                        //    Log.Message(pawn + " of "+ factionType + " using "+filter.categories.ToCommaList());
                        Categories.Add(filter);
                        backstoryCategories = Categories;
                    }
                }
            }
        }
        // Token: 0x060040BF RID: 16575 RVA: 0x00159374 File Offset: 0x00157574
        public static List <BackstoryCategoryFilter> GetBackstoryCategoryFiltersFor(Pawn pawn, FactionDef faction)
        {
            if (!pawn.kindDef.backstoryFiltersOverride.NullOrEmpty <BackstoryCategoryFilter>())
            {
                return(pawn.kindDef.backstoryFiltersOverride);
            }
            List <BackstoryCategoryFilter> list = new List <BackstoryCategoryFilter>();

            if (pawn.kindDef.backstoryFilters != null)
            {
                list.AddRange(pawn.kindDef.backstoryFilters);
            }
            if (faction != null && !faction.backstoryFilters.NullOrEmpty <BackstoryCategoryFilter>())
            {
                for (int i = 0; i < faction.backstoryFilters.Count; i++)
                {
                    BackstoryCategoryFilter item = faction.backstoryFilters[i];
                    if (!list.Contains(item))
                    {
                        list.Add(item);
                    }
                }
            }
            if (!list.NullOrEmpty <BackstoryCategoryFilter>())
            {
                return(list);
            }
            Log.ErrorOnce(string.Concat(new object[]
            {
                "PawnKind ",
                pawn.kindDef,
                " generating with factionDef ",
                faction,
                ": no backstoryCategories in either."
            }), 1871521, false);
            return(new List <BackstoryCategoryFilter>
            {
                PawnBioAndNameGenerator_FillBackstorySlotShuffled_Controller_Patch.FallbackCategoryGroup
            });
        }
Esempio n. 8
0
        // EVERY RELEASE:
        // Evaluate to make sure the logic in PawnBioAndNameGenerator.GetBackstoryCategoryFiltersFor() has not changed in a way
        // that invalidates this rewrite. This is a modified version of that method but with the first argument a PawnKindDef
        // instead of a Pawn and with logging removed.
        private List <BackstoryCategoryFilter> GetBackstoryCategoryFiltersFor(PawnKindDef kindDef, FactionDef faction)
        {
            if (!kindDef.backstoryFiltersOverride.NullOrEmpty <BackstoryCategoryFilter>())
            {
                return(kindDef.backstoryFiltersOverride);
            }
            List <BackstoryCategoryFilter> list = new List <BackstoryCategoryFilter>();

            if (kindDef.backstoryFilters != null)
            {
                list.AddRange(kindDef.backstoryFilters);
            }
            if (faction != null && !faction.backstoryFilters.NullOrEmpty <BackstoryCategoryFilter>())
            {
                for (int i = 0; i < faction.backstoryFilters.Count; i++)
                {
                    BackstoryCategoryFilter item = faction.backstoryFilters[i];
                    if (!list.Contains(item))
                    {
                        list.Add(item);
                    }
                }
            }
            if (!list.NullOrEmpty <BackstoryCategoryFilter>())
            {
                return(list);
            }
            return(new List <BackstoryCategoryFilter> {
                new BackstoryCategoryFilter {
                    categories = new List <string> {
                        "Civil"
                    },
                    commonality = 1f
                }
            });
        }
        public static bool FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, Backstory backstoryOtherSlot, List <BackstoryCategoryFilter> backstoryCategories, FactionDef factionType)
        {
            bool act = pawn.def.modContentPack != null && pawn.def.modContentPack.Name.Contains("Adeptus Mechanicus");

            if (act || pawn.def.defName.StartsWith("OG_") || pawn.kindDef.defName.StartsWith("OG_") || pawn.kindDef.defName.Contains("_OG_"))
            {
                BackstoryCategoryFilter backstoryCategoryFilter = backstoryCategories.RandomElementByWeight((BackstoryCategoryFilter c) => c.commonality);
                if (backstoryCategoryFilter == null)
                {
                    backstoryCategoryFilter = PawnBioAndNameGenerator_FillBackstorySlotShuffled_Controller_Patch.FallbackCategoryGroup;
                }
                List <string> lista = new List <string>();
                foreach (BackstoryCategoryFilter filter in backstoryCategories)
                {
                    foreach (string str in filter.categories)
                    {
                        if (!lista.Contains(str))
                        {
                            lista.Add(str);
                        }
                    }
                }
                if (!(from bs in BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategoryFilter).TakeRandom(20)
                      where slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)
                      select bs).TryRandomElementByWeight(new Func <Backstory, float>(PawnBioAndNameGenerator_FillBackstorySlotShuffled_Controller_Patch.BackstorySelectionWeight), out backstory))
                {
                    Log.Warning(string.Concat(new object[]
                    {
                        "low number of backstories ",
                        slot,
                        " categories used ",
                        backstoryCategoryFilter.categories.ToCommaList(),
                        " found for ",
                        pawn.ToStringSafe <Pawn>(),
                        " of ",
                        factionType.ToStringSafe <FactionDef>(),
                        ". trying random."
                    }));
                    if (!BackstoryDatabase.allBackstories.Where(bs => backstoryCategoryFilter.categories.Any(cat => bs.Value.spawnCategories.Contains(cat)) && bs.Value.slot == slot && (slot != BackstorySlot.Adulthood || !bs.Value.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables))).TryRandomElementByWeight <KeyValuePair <string, Backstory> >(new Func <KeyValuePair <string, Backstory>, float>(PawnBioAndNameGenerator_FillBackstorySlotShuffled_Controller_Patch.BackstorySelectionWeight), out KeyValuePair <string, Backstory> b))
                    {
                        Log.Error(string.Concat(new object[]
                        {
                            "No shuffled ",
                            slot,
                            " categories used ",
                            backstoryCategoryFilter.categories.ToCommaList(),
                            " found for ",
                            pawn.ToStringSafe <Pawn>(),
                            " of ",
                            factionType.ToStringSafe <FactionDef>(),
                            ". Choosing random."
                        }), false);
                        backstory = (from kvp in BackstoryDatabase.allBackstories
                                     where kvp.Value.slot == slot
                                     select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
                    }
                    else
                    {
                        backstory = b.Value;
                    }
                }
                return(false);
            }
            return(true);
        }
Esempio n. 10
0
 public static bool IsBioUseable(PawnBio bio, BackstoryCategoryFilter categoryFilter, PawnKindDef kind, Gender gender, string requiredLastName)
 {
     return((bool)ReflectionCache.Instance.PawnBioAndNameGenerator_IsBioUseable.Invoke(null,
                                                                                       new object[] { bio, categoryFilter, kind, gender, requiredLastName }
                                                                                       ));
 }