public static void ShuffleableBackstoryList(BackstorySlot slot, List <string> tags, List <Backstory> outBackstories)
 {
     outBackstories.Clear();
     if (tags.Count == 0)
     {
         return;
     }
     if (tags.Count == 1)
     {
         outBackstories.AddRange(BackstoryDatabase.ShuffleableBackstoryList(slot, tags[0]));
         return;
     }
     BackstoryDatabase.tmpUniqueBackstories.Clear();
     for (int i = 0; i < tags.Count; i++)
     {
         List <Backstory> list = BackstoryDatabase.ShuffleableBackstoryList(slot, tags[i]);
         for (int j = 0; j < list.Count; j++)
         {
             BackstoryDatabase.tmpUniqueBackstories.Add(list[j]);
         }
     }
     foreach (Backstory current in BackstoryDatabase.tmpUniqueBackstories)
     {
         outBackstories.Add(current);
     }
     BackstoryDatabase.tmpUniqueBackstories.Clear();
 }
Example #2
0
        private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, FactionDef factionType)
        {
            IEnumerable <Backstory> source = from bs in BackstoryDatabase.ShuffleableBackstoryList(slot, factionType.backstoryCategory).TakeRandom(20)
                                             where slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)
                                             select bs;

            if (PawnBioAndNameGenerator.< > f__mg$cache0 == null)
            {
                PawnBioAndNameGenerator.< > f__mg$cache0 = new Func <Backstory, float>(PawnBioAndNameGenerator.BackstorySelectionWeight);
            }
            if (!source.TryRandomElementByWeight(PawnBioAndNameGenerator.< > f__mg$cache0, 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;
            }
        }
        private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, Backstory backstoryOtherSlot, List <BackstoryCategoryFilter> backstoryCategories, FactionDef factionType)
        {
            BackstoryCategoryFilter backstoryCategoryFilter = backstoryCategories.RandomElementByWeight((BackstoryCategoryFilter c) => c.commonality);

            if (backstoryCategoryFilter == null)
            {
                backstoryCategoryFilter = FallbackCategoryGroup;
            }
            if (!(from bs in BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategoryFilter).TakeRandom(20)
                  where (slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)) ? true : false
                  select bs).TryRandomElementByWeight(BackstorySelectionWeight, out backstory))
            {
                Log.Error(string.Concat("No shuffled ", slot, " found for ", pawn.ToStringSafe(), " of ", factionType.ToStringSafe(), ". Choosing random."));
                backstory = BackstoryDatabase.allBackstories.Where((KeyValuePair <string, Backstory> kvp) => kvp.Value.slot == slot).RandomElement().Value;
            }
        }
Example #4
0
 private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, List <string> backstoryCategories, FactionDef factionType)
 {
     tmpBackstories.Clear();
     BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategories, tmpBackstories);
     if (!tmpBackstories.TakeRandom(20).Where(delegate(Backstory bs)
     {
         if (slot == BackstorySlot.Adulthood && bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables))
         {
             return(false);
         }
         return(true);
     }).TryRandomElementByWeight(BackstorySelectionWeight, out backstory))
     {
         Log.Error("No shuffled " + slot + " found for " + pawn.ToStringSafe() + " of " + factionType.ToStringSafe() + ". Defaulting.");
         backstory = (from kvp in BackstoryDatabase.allBackstories
                      where kvp.Value.slot == slot
                      select kvp).RandomElement().Value;
     }
     tmpBackstories.Clear();
 }