private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, List <string> backstoryCategories, FactionDef factionType)
        {
            AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.tmpBackstories.Clear();
            BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategories, AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.tmpBackstories);
            IEnumerable <Backstory> source = from bs in AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.tmpBackstories.TakeRandom(20)
                                             where slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)
                                             select bs;

            if (AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.funcA == null)
            {
                AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.funcA = new Func <Backstory, float>(AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.BackstorySelectionWeight);
            }
            if (!source.TryRandomElementByWeight(AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.funcA, out backstory))
            {
                Log.Error(string.Concat(new object[]
                {
                    "No shuffled ",
                    slot,
                    " found for ",
                    pawn.ToStringSafe <Pawn>(),
                    " of ",
                    factionType.ToStringSafe <FactionDef>(),
                    ". Defaulting."
                }), false);
                backstory = (from kvp in BackstoryDatabase.allBackstories
                             where kvp.Value.slot == slot
                             select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
            }
            AM_PawnBioAndNameGenerator_GiveShuffledBioTo_AdultAge_Patch.tmpBackstories.Clear();
        }
コード例 #2
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);
 }
        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);
        }