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, 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(); }
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; } }