예제 #1
0
 public static void LoadAllBios()
 {
     foreach (PawnBio item in DirectXmlLoader.LoadXmlDataInResourcesFolder <PawnBio>("Backstories/Solid"))
     {
         item.name.ResolveMissingPieces();
         if (item.childhood == null || item.adulthood == null)
         {
             PawnNameDatabaseSolid.AddPlayerContentName(item.name, item.gender);
         }
         else
         {
             item.PostLoad();
             item.ResolveReferences();
             foreach (string item2 in item.ConfigErrors())
             {
                 Log.Error(item2);
             }
             allBios.Add(item);
             item.childhood.shuffleable = false;
             item.childhood.slot        = BackstorySlot.Childhood;
             item.adulthood.shuffleable = false;
             item.adulthood.slot        = BackstorySlot.Adulthood;
             BackstoryDatabase.AddBackstory(item.childhood);
             BackstoryDatabase.AddBackstory(item.adulthood);
         }
     }
 }
예제 #2
0
        public void ExposeData()
        {
            string text = (this.childhood == null) ? null : this.childhood.identifier;

            Scribe_Values.Look <string>(ref text, "childhood", null, false);
            if (Scribe.mode == LoadSaveMode.LoadingVars && !text.NullOrEmpty() && !BackstoryDatabase.TryGetWithIdentifier(text, out this.childhood, true))
            {
                Log.Error("Couldn't load child backstory with identifier " + text + ". Giving random.", false);
                this.childhood = BackstoryDatabase.RandomBackstory(BackstorySlot.Childhood);
            }
            string text2 = (this.adulthood == null) ? null : this.adulthood.identifier;

            Scribe_Values.Look <string>(ref text2, "adulthood", null, false);
            if (Scribe.mode == LoadSaveMode.LoadingVars && !text2.NullOrEmpty() && !BackstoryDatabase.TryGetWithIdentifier(text2, out this.adulthood, true))
            {
                Log.Error("Couldn't load adult backstory with identifier " + text2 + ". Giving random.", false);
                this.adulthood = BackstoryDatabase.RandomBackstory(BackstorySlot.Adulthood);
            }
            Scribe_Defs.Look <BodyTypeDef>(ref this.bodyType, "bodyType");
            Scribe_Values.Look <CrownType>(ref this.crownType, "crownType", CrownType.Undefined, false);
            Scribe_Values.Look <string>(ref this.headGraphicPath, "headGraphicPath", null, false);
            Scribe_Defs.Look <HairDef>(ref this.hairDef, "hairDef");
            Scribe_Values.Look <Color>(ref this.hairColor, "hairColor", default(Color), false);
            Scribe_Values.Look <float>(ref this.melanin, "melanin", 0f, false);
            Scribe_Deep.Look <TraitSet>(ref this.traits, "traits", new object[]
            {
                this.pawn
            });
            Scribe_Values.Look <string>(ref this.title, "title", null, false);
            if (Scribe.mode == LoadSaveMode.PostLoadInit && this.hairDef == null)
            {
                this.hairDef = DefDatabase <HairDef> .AllDefs.RandomElement <HairDef>();
            }
        }
        private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, List <string> backstoryCategories, FactionDef factionType)
        {
            PawnBioAndNameGenerator.tmpBackstories.Clear();
            BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategories, PawnBioAndNameGenerator.tmpBackstories);
            IEnumerable <Backstory> source = from bs in PawnBioAndNameGenerator.tmpBackstories.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;
            }
            PawnBioAndNameGenerator.tmpBackstories.Clear();
        }
예제 #4
0
 public static void ReloadAllBackstories()
 {
     foreach (Backstory current in DirectXmlLoader.LoadXmlDataInResourcesFolder <Backstory>("Backstories/Shuffled"))
     {
         current.PostLoad();
         current.ResolveReferences();
         foreach (string current2 in current.ConfigErrors(false))
         {
             Log.Error(current.Title + ": " + current2);
         }
         BackstoryDatabase.AddBackstory(current);
     }
     SolidBioDatabase.LoadAllBios();
 }
예제 #5
0
 public static void ReloadAllBackstories()
 {
     foreach (Backstory item in DirectXmlLoader.LoadXmlDataInResourcesFolder <Backstory>("Backstories/Shuffled"))
     {
         item.PostLoad();
         item.ResolveReferences();
         foreach (string item2 in item.ConfigErrors(false))
         {
             Log.Error(item.Title + ": " + item2);
         }
         BackstoryDatabase.AddBackstory(item);
     }
     SolidBioDatabase.LoadAllBios();
 }
 public static void ReloadAllBackstories()
 {
     foreach (Backstory backstory in DirectXmlLoader.LoadXmlDataInResourcesFolder <Backstory>("Backstories/Shuffled"))
     {
         backstory.PostLoad();
         backstory.ResolveReferences();
         foreach (string str in backstory.ConfigErrors(false))
         {
             Log.Error(backstory.title + ": " + str, false);
         }
         BackstoryDatabase.AddBackstory(backstory);
     }
     SolidBioDatabase.LoadAllBios();
 }
        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;
            }
        }
예제 #8
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();
 }
예제 #9
0
        public void ExposeData()
        {
            string value = ((childhood != null) ? childhood.identifier : null);

            Scribe_Values.Look(ref value, "childhood");
            if (Scribe.mode == LoadSaveMode.LoadingVars && !value.NullOrEmpty() && !BackstoryDatabase.TryGetWithIdentifier(value, out childhood))
            {
                Log.Error("Couldn't load child backstory with identifier " + value + ". Giving random.");
                childhood = BackstoryDatabase.RandomBackstory(BackstorySlot.Childhood);
            }
            string value2 = ((adulthood != null) ? adulthood.identifier : null);

            Scribe_Values.Look(ref value2, "adulthood");
            if (Scribe.mode == LoadSaveMode.LoadingVars && !value2.NullOrEmpty() && !BackstoryDatabase.TryGetWithIdentifier(value2, out adulthood))
            {
                Log.Error("Couldn't load adult backstory with identifier " + value2 + ". Giving random.");
                adulthood = BackstoryDatabase.RandomBackstory(BackstorySlot.Adulthood);
            }
            Scribe_Defs.Look(ref bodyType, "bodyType");
            Scribe_Values.Look(ref crownType, "crownType", CrownType.Undefined);
            Scribe_Values.Look(ref headGraphicPath, "headGraphicPath");
            Scribe_Defs.Look(ref hairDef, "hairDef");
            Scribe_Values.Look(ref hairColor, "hairColor");
            Scribe_Values.Look(ref melanin, "melanin", 0f);
            Scribe_Deep.Look(ref traits, "traits", pawn);
            Scribe_Values.Look(ref title, "title");
            Scribe_Values.Look(ref birthLastName, "birthLastName");
            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                if (birthLastName == null && pawn.Name is NameTriple)
                {
                    birthLastName = ((NameTriple)pawn.Name).Last;
                }
                if (hairDef == null)
                {
                    hairDef = DefDatabase <HairDef> .AllDefs.RandomElement();
                }
            }
        }
예제 #10
0
        public static string GetIdentifierClosestMatch(string identifier, bool closestMatchWarning = true)
        {
            if (BackstoryDatabase.allBackstories.ContainsKey(identifier))
            {
                return(identifier);
            }
            string b = BackstoryDatabase.StripNumericSuffix(identifier);

            foreach (KeyValuePair <string, Backstory> current in BackstoryDatabase.allBackstories)
            {
                Backstory value = current.Value;
                if (BackstoryDatabase.StripNumericSuffix(value.identifier) == b)
                {
                    if (closestMatchWarning)
                    {
                        Log.Warning("Couldn't find exact match for backstory " + identifier + ", using closest match " + value.identifier, false);
                    }
                    return(value.identifier);
                }
            }
            Log.Warning("Couldn't find exact match for backstory " + identifier + ", or any close match.", false);
            return(identifier);
        }
예제 #11
0
 public static bool TryGetWithIdentifier(string identifier, out Backstory bs, bool closestMatchWarning = true)
 {
     identifier = BackstoryDatabase.GetIdentifierClosestMatch(identifier, closestMatchWarning);
     return(BackstoryDatabase.allBackstories.TryGetValue(identifier, out bs));
 }