Beispiel #1
0
        public static void InsertTags()
        {
            IEnumerable <BackstorySettings> settings = DefDatabase <BackstorySettings> .AllDefs;
            IEnumerable <BackstoryTagItem>  items    = settings.SelectMany((BackstorySettings bs) => bs.backstoryTagInsertion);

            //     Log.Message("Checking " + items.Count() + " Backstroy Tags from " + settings.Count() + " BackstorySettings");
            foreach (BackstoryTagItem backstoryTagItem in items)
            {
                //    Log.Message("BackstorySettings for " + backstoryTagItem);
                using (List <string> .Enumerator enumerator2 = backstoryTagItem.backstories.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        Backstory backstory;
                        if (BackstoryDatabase.TryGetWithIdentifier(enumerator2.Current, out backstory, false))
                        {
                            backstory.spawnCategories.AddRange(backstoryTagItem.spawnCategories);
                            if (backstoryTagItem.debug)
                            {
                                Log.Message("Found Backstory with Identifer: " + enumerator2.Current + " Backstory: " + backstory.identifier + " spawnCategories: " + backstory.spawnCategories.ToCommaList());
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public static List <string> MissingBackstoryTranslations(LoadedLanguage lang)
        {
            List <KeyValuePair <string, Backstory> > list = BackstoryDatabase.allBackstories.ToList();
            List <string> list2 = new List <string>();
            string        modifiedIdentifier;
            KeyValuePair <string, Backstory> backstory;

            foreach (XElement item in BackstoryTranslationElements(lang.AllDirectories, null))
            {
                try
                {
                    string text = item.Name.ToString();
                    modifiedIdentifier = BackstoryDatabase.GetIdentifierClosestMatch(text, closestMatchWarning: false);
                    bool flag = list.Any((KeyValuePair <string, Backstory> x) => x.Key == modifiedIdentifier);
                    backstory = list.Find((KeyValuePair <string, Backstory> x) => x.Key == modifiedIdentifier);
                    if (flag)
                    {
                        list.RemoveAt(list.FindIndex((KeyValuePair <string, Backstory> x) => x.Key == backstory.Key));
                        string text2 = GetText(item, "title");
                        string text3 = GetText(item, "titleFemale");
                        string text4 = GetText(item, "titleShort");
                        string text5 = GetText(item, "titleShortFemale");
                        string text6 = GetText(item, "desc");
                        if (text2.NullOrEmpty())
                        {
                            list2.Add(text + ".title missing");
                        }
                        if (flag && !backstory.Value.titleFemale.NullOrEmpty() && text3.NullOrEmpty())
                        {
                            list2.Add(text + ".titleFemale missing");
                        }
                        if (text4.NullOrEmpty())
                        {
                            list2.Add(text + ".titleShort missing");
                        }
                        if (flag && !backstory.Value.titleShortFemale.NullOrEmpty() && text5.NullOrEmpty())
                        {
                            list2.Add(text + ".titleShortFemale missing");
                        }
                        if (text6.NullOrEmpty())
                        {
                            list2.Add(text + ".desc missing");
                        }
                    }
                    else
                    {
                        list2.Add("Translation doesn't correspond to any backstory: " + text);
                    }
                }
                catch (Exception ex)
                {
                    list2.Add(string.Concat("Exception reading ", item.Name, ": ", ex.Message));
                }
            }
            foreach (KeyValuePair <string, Backstory> item2 in list)
            {
                list2.Add("Missing backstory: " + item2.Key);
            }
            return(list2);
        }
Beispiel #3
0
        private static void SetBackstoryAndSkills(Pawn p)
        {
            if (BackstoryDatabase.TryGetWithIdentifier("ChildSpy47", out Backstory bs))
            {
                p.story.childhood = bs;
            }
            else
            {
                Log.Error("Tried to assign child backstory ChildSpy47, but not found");
            }
            if (BackstoryDatabase.TryGetWithIdentifier("ColonySettler53", out Backstory bstory))
            {
                p.story.adulthood = bstory;
            }
            else
            {
                Log.Error("Tried to assign child backstory ColonySettler53, but not found");
            }
            //Clear traits

            p.story.traits.allTraits = new List <Trait>();
            //Reset cache

            //ReflectionUtility.cachedDisabledWorkTypes.SetValue(p.story, null);
            //Reset cache for each skill

            for (int i = 0; i < p.skills.skills.Count; i++)
            {
                ReflectionUtility.cachedTotallyDisabled.SetValue(p.skills.skills[i], BoolUnknown.Unknown);
            }
        }
 static ConstructBackstories()
 {
     LongEventHandler.ExecuteWhenFinished(() =>
     {
         childhood = new Backstory()
         {
             title        = "Artificial Construct",
             titleShort   = "Construct",
             identifier   = "ConstructBackstoryC",
             workDisables = WorkTags.Social,
             slot         = BackstorySlot.Childhood,
             baseDesc     = ""
         };
         BackstoryDatabase.AddBackstory(childhood);
         adulthood = new Backstory()
         {
             title        = "Artificial Construct",
             titleShort   = "Construct",
             identifier   = "ConstructBackstoryA",
             workDisables = WorkTags.Social,
             slot         = BackstorySlot.Adulthood,
             baseDesc     = ""
         };
         BackstoryDatabase.AddBackstory(adulthood);
     });
 }
 static DroneBackstories()
 {
     LongEventHandler.ExecuteWhenFinished(() =>
     {
         childhood = new Backstory()
         {
             title        = "PRFDroneName".Translate(),
             titleShort   = "PRFDroneName".Translate(),
             identifier   = "PRFNoneBracketsC",
             workDisables = WorkTags.Social,
             slot         = BackstorySlot.Childhood,
             baseDesc     = "NoneBrackets".Translate()
         };
         BackstoryDatabase.AddBackstory(childhood);
         adulthood = new Backstory()
         {
             title        = "PRFDroneName".Translate(),
             titleShort   = "PRFDroneName".Translate(),
             identifier   = "PRFNoneBracketsA",
             workDisables = WorkTags.Social,
             slot         = BackstorySlot.Adulthood,
             baseDesc     = "NoneBrackets".Translate()
         };
         BackstoryDatabase.AddBackstory(adulthood);
     });
 }
Beispiel #6
0
 public override void ResolveReferences()
 {
     base.ResolveReferences();
     if (BackstoryDatabase.TryGetWithIdentifier(this.backstoryName, out Backstory bs))
     {
         bs.baseDesc = this.backstoryDescription;
     }
 }
Beispiel #7
0
        public Backstory GetFromDatabase()
        {
            Backstory bs = null;

            BackstoryDatabase.TryGetWithIdentifier(identifier, out bs, false);

            return(bs);
        }
        private static void CheckAllInjected()
        {
            // Thanks to all modders out there for providing help and support.
            // This is just for me.
            Backstory childMe = new Backstory
            {
                bodyTypeMale   = BodyType.Male,
                bodyTypeFemale = BodyType.Female,
                slot           = BackstorySlot.Childhood,
                baseDesc       =
                    "NAME never believed what was common sense and always doubted other people. HECAP later went on inflating toads with HIS sushi stick. It was there HE earned HIS nickname.",
                requiredWorkTags = WorkTags.Violent,
                shuffleable      = false
            };

            childMe.SetTitle("Lost child");
            childMe.SetTitleShort("Seeker");
            childMe.skillGains.Add("Shooting", 4);
            childMe.skillGains.Add("Medicine", 2);
            childMe.skillGains.Add("Social", 1);
            childMe.PostLoad();
            childMe.ResolveReferences();

            Backstory adultMale = new Backstory
            {
                bodyTypeMale   = BodyType.Male,
                bodyTypeFemale = BodyType.Female,
                slot           = BackstorySlot.Adulthood,
                baseDesc       =
                    "HECAP tells no one about his past. HECAP doesn't like doctors, thus HECAP prefers to tend his wounds himself.",
                shuffleable     = false,
                spawnCategories = new List <string>()
            };

            adultMale.spawnCategories.AddRange(new[] { "Civil", "Raider", "Slave", "Trader", "Traveler" });
            adultMale.SetTitle("Lone gunman");
            adultMale.SetTitleShort("Gunman");
            adultMale.skillGains.Add("Shooting", 4);
            adultMale.skillGains.Add("Medicine", 3);
            adultMale.skillGains.Add("Cooking", 2);
            adultMale.skillGains.Add("Social", 1);
            adultMale.PostLoad();
            adultMale.ResolveReferences();

            PawnBio me = new PawnBio
            {
                childhood = childMe,
                adulthood = adultMale,
                gender    = GenderPossibility.Male,
                name      = NameTriple.FromString("Gator 'Killface' Stinkwater")
            };

            me.PostLoad();
            SolidBioDatabase.allBios.Add(me);
            BackstoryDatabase.AddBackstory(childMe);

            BackstoryDatabase.AddBackstory(adultMale);
        }
        public Pawn GetNewPawn(Gender gender)
        {
            maleBodyTypeIndex   = 0;
            femaleBodyTypeIndex = 0;
            hairTypeIndex       = 0;
            femaleHeadTypeIndex = 0;
            maleHeadTypeIndex   = 0;
            Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(currentPawnKindDef, Faction.OfAncients, PawnGenerationContext.NonPlayer,
                                                                             -1, true, false, false, false, false, false, 0f, false, true, true, false, false, false, true, fixedGender: gender, fixedBiologicalAge: 20,
                                                                             fixedChronologicalAge: 20));

            pawn.story.childhood = null;
            pawn.story.adulthood = null;
            pawn.Name            = new NameSingle("AlteredCarbon.EmptySleeve".Translate());
            pawn?.equipment.DestroyAllEquipment();
            pawn?.inventory.DestroyAll();
            pawn.apparel.DestroyAll();
            RemoveAllTraits(pawn);
            if (pawn.playerSettings == null)
            {
                pawn.playerSettings = new Pawn_PlayerSettings(pawn);
            }
            pawn.playerSettings.medCare = MedicalCareCategory.Best;
            pawn.skills = new Pawn_SkillTracker(pawn);
            pawn.needs  = new Pawn_NeedsTracker(pawn);
            pawn.needs.mood.thoughts = new ThoughtHandler(pawn);
            pawn.timetable           = new Pawn_TimetableTracker(pawn);

            if (BackstoryDatabase.TryGetWithIdentifier("AC_VatGrown45", out Backstory bs))
            {
                pawn.story.childhood = bs;
            }

            if (pawn.needs?.mood?.thoughts?.memories?.Memories != null)
            {
                for (int num = pawn.needs.mood.thoughts.memories.Memories.Count - 1; num >= 0; num--)
                {
                    pawn.needs.mood.thoughts.memories.RemoveMemory(pawn.needs.mood.thoughts.memories.Memories[num]);
                }
            }
            RemoveAllHediffs(pawn);

            if (pawn.workSettings != null)
            {
                pawn.workSettings.EnableAndInitialize();
            }

            if (pawn.skills != null)
            {
                pawn.skills.Notify_SkillDisablesChanged();
            }
            if (!pawn.Dead && pawn.RaceProps.Humanlike)
            {
                pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
            }

            return(pawn);
        }
 public static void LoadAndInjectBackstoryData(IEnumerable <string> folderPaths, List <string> loadErrors)
 {
     foreach (XElement xelement in BackstoryTranslationUtility.BackstoryTranslationElements(folderPaths, loadErrors))
     {
         string text = "[unknown]";
         try
         {
             text = xelement.Name.ToString();
             string    value  = xelement.Element("title").Value;
             string    text2  = (xelement.Element("titleFemale") == null) ? null : xelement.Element("titleFemale").Value;
             string    value2 = xelement.Element("titleShort").Value;
             string    text3  = (xelement.Element("titleShortFemale") == null) ? null : xelement.Element("titleShortFemale").Value;
             string    value3 = xelement.Element("desc").Value;
             Backstory backstory;
             if (!BackstoryDatabase.TryGetWithIdentifier(text, out backstory, false))
             {
                 throw new Exception("Backstory not found matching identifier " + text);
             }
             if (value == backstory.title && text2 == backstory.titleFemale && value2 == backstory.titleShort && text3 == backstory.titleShortFemale && value3 == backstory.baseDesc)
             {
                 throw new Exception("Backstory translation exactly matches default data: " + text);
             }
             if (value != null)
             {
                 backstory.SetTitle(value, backstory.titleFemale);
             }
             if (text2 != null)
             {
                 backstory.SetTitle(backstory.title, text2);
             }
             if (value2 != null)
             {
                 backstory.SetTitleShort(value2, backstory.titleShortFemale);
             }
             if (text3 != null)
             {
                 backstory.SetTitleShort(backstory.titleShort, text3);
             }
             if (value3 != null)
             {
                 backstory.baseDesc = value3;
             }
         }
         catch (Exception ex)
         {
             loadErrors.Add(string.Concat(new object[]
             {
                 "Couldn't load backstory ",
                 text,
                 ": ",
                 ex,
                 "\nFull XML text:\n\n",
                 xelement.ToString()
             }));
         }
     }
 }
Beispiel #11
0
 public bool AddBackstory(string identifier)
 {
     if (BackstoryDatabase.TryGetWithIdentifier(identifier, out Backstory b, false))
     {
         backstories[b.identifier] = b;
         return(true);
     }
     return(false);
 }
 public static bool RemoveBackstory(string identifier)
 {
     if (BackstoryDatabase.TryGetWithIdentifier(identifier, out Backstory b, false))
     {
         Remove(b);
         return(true);
     }
     return(false);
 }
Beispiel #13
0
        private void BackCompatibleBackstory(XmlNode node)
        {
            string childValue = node?.FirstChild?.Value;

            if (childValue == null)
            {
                return;
            }

            foreach (var def in compatibilityDefs)
            {
                XmlNode destinationNode;
                string  prefix;
                string  newBackstory;

                if (def.TryGetBackstoryReplacement(childValue, out newBackstory))
                {
                    destinationNode = node;
                    prefix          = "";
                }
                else if (def.TryGetBackstoryOpposingReplacement(childValue, out newBackstory))
                {
                    var parentNode = node.ParentNode;

                    destinationNode = node.Name == "adulthood" ? parentNode["childhood"] : parentNode["adulthood"];
                    prefix          = "opposing";
                }
                else
                {
                    continue;
                }

                if (!BackstoryDatabase.TryGetWithIdentifier(newBackstory, out Backstory backstory))
                {
                    Log.Error($"Couldn't replace {prefix} backstory '{destinationNode.FirstChild.Value}' with identifier '{newBackstory}' - not found.");
                    continue;
                }
                Log.Message($"Replacing backstory {prefix} '{destinationNode.FirstChild.Value}' with '{newBackstory}'");

                destinationNode.FirstChild.Value = backstory.identifier;

                var    thingNode = node.ParentNode.ParentNode;
                string pawnID    = thingNode["id"]?.FirstChild?.Value;

                if (pawnID != null)
                {
                    pawnBackstoryToRefresh.Add($"Thing_{pawnID}");
                }
                else
                {
                    Log.Warning("pawnID is null");
                }
            }
        }
Beispiel #14
0
        public static void Inject()
        {
            Log.Message("Injecting backstories...");

            if (toSave == null || toSave.Count == 0)
            {
                Log.Message("No custom stories found...");
                return;
            }

            foreach (var story in toSave)
            {
                Backstory bStory = new Backstory()
                {
                    identifier         = story.identifier,
                    title              = story.title,
                    titleShort         = story.titleShort,
                    titleFemale        = story.titleFemale,
                    titleShortFemale   = story.titleShortFemale,
                    skillGainsResolved = story.skillGainsResolved,
                    baseDesc           = story.baseDesc,
                    workDisables       = story.workDisables,
                    requiredWorkTags   = story.requiredWorkTags,
                    forcedTraits       = new List <TraitEntry>(),
                    disallowedTraits   = new List <TraitEntry>()
                };
                if (story.traitData != null)
                {
                    foreach (var t in story.traitData)
                    {
                        if (t.status == 1)
                        {
                            bStory.forcedTraits.Add(new TraitEntry(t.traitDef, t.degreeInt));
                        }
                        if (t.status == 2)
                        {
                            bStory.disallowedTraits.Add(new TraitEntry(t.traitDef, t.degreeInt));
                        }
                    }
                }

                bStory.PostLoad();

                if (BackstoryDatabase.allBackstories.Keys.Contains(bStory.identifier))
                {
                    BackstoryDatabase.allBackstories.Remove(bStory.identifier);
                }

                BackstoryDatabase.AddBackstory(bStory);
            }

            Log.Message($"Loaded {toSave.Count} custom stories");
        }
 private static void <DoPlayLoad> m__0()
 {
     DeepProfiler.Start("Load backstories.");
     try
     {
         BackstoryDatabase.ReloadAllBackstories();
     }
     finally
     {
         DeepProfiler.End();
     }
 }
Beispiel #16
0
 public static void LoadAndInjectBackstoryData(IEnumerable <Tuple <VirtualDirectory, ModContentPack, string> > folderPaths, List <string> loadErrors)
 {
     foreach (XElement item in BackstoryTranslationElements(folderPaths, loadErrors))
     {
         string text = "[unknown]";
         try
         {
             text = item.Name.ToString();
             string text2 = GetText(item, "title");
             string text3 = GetText(item, "titleFemale");
             string text4 = GetText(item, "titleShort");
             string text5 = GetText(item, "titleShortFemale");
             string text6 = GetText(item, "desc");
             if (!BackstoryDatabase.TryGetWithIdentifier(text, out var bs, closestMatchWarning: false))
             {
                 throw new Exception("Backstory not found matching identifier " + text);
             }
             if (text2 == bs.title && text3 == bs.titleFemale && text4 == bs.titleShort && text5 == bs.titleShortFemale && text6 == bs.baseDesc)
             {
                 throw new Exception("Backstory translation exactly matches default data: " + text);
             }
             if (text2 != null)
             {
                 bs.SetTitle(text2, bs.titleFemale);
                 bs.titleTranslated = true;
             }
             if (text3 != null)
             {
                 bs.SetTitle(bs.title, text3);
                 bs.titleFemaleTranslated = true;
             }
             if (text4 != null)
             {
                 bs.SetTitleShort(text4, bs.titleShortFemale);
                 bs.titleShortTranslated = true;
             }
             if (text5 != null)
             {
                 bs.SetTitleShort(bs.titleShort, text5);
                 bs.titleShortFemaleTranslated = true;
             }
             if (text6 != null)
             {
                 bs.baseDesc       = text6;
                 bs.descTranslated = true;
             }
         }
         catch (Exception ex)
         {
             loadErrors.Add("Couldn't load backstory " + text + ": " + ex.Message + "\nFull XML text:\n\n" + item.ToString());
         }
     }
 }
        public static List <string> BackstoryTranslationsMatchingEnglish(LoadedLanguage lang)
        {
            List <string> list = new List <string>();

            foreach (XElement current in BackstoryTranslationUtility.BackstoryTranslationElements(lang.FolderPaths, null))
            {
                try
                {
                    string    text = current.Name.ToString();
                    Backstory backstory;
                    if (BackstoryDatabase.allBackstories.TryGetValue(BackstoryDatabase.GetIdentifierClosestMatch(text, true), out backstory))
                    {
                        string text2 = BackstoryTranslationUtility.GetText(current, "title");
                        string text3 = BackstoryTranslationUtility.GetText(current, "titleFemale");
                        string text4 = BackstoryTranslationUtility.GetText(current, "titleShort");
                        string text5 = BackstoryTranslationUtility.GetText(current, "titleShortFemale");
                        string text6 = BackstoryTranslationUtility.GetText(current, "desc");
                        if (!text2.NullOrEmpty() && text2 == backstory.untranslatedTitle)
                        {
                            list.Add(text + ".title '" + text2.Replace("\n", "\\n") + "'");
                        }
                        if (!text3.NullOrEmpty() && text3 == backstory.untranslatedTitleFemale)
                        {
                            list.Add(text + ".titleFemale '" + text3.Replace("\n", "\\n") + "'");
                        }
                        if (!text4.NullOrEmpty() && text4 == backstory.untranslatedTitleShort)
                        {
                            list.Add(text + ".titleShort '" + text4.Replace("\n", "\\n") + "'");
                        }
                        if (!text5.NullOrEmpty() && text5 == backstory.untranslatedTitleShortFemale)
                        {
                            list.Add(text + ".titleShortFemale '" + text5.Replace("\n", "\\n") + "'");
                        }
                        if (!text6.NullOrEmpty() && text6 == backstory.untranslatedDesc)
                        {
                            list.Add(text + ".desc '" + text6.Replace("\n", "\\n") + "'");
                        }
                    }
                }
                catch (Exception ex)
                {
                    list.Add(string.Concat(new object[]
                    {
                        "Exception reading ",
                        current.Name,
                        ": ",
                        ex.Message
                    }));
                }
            }
            return(list);
        }
Beispiel #18
0
 private static void ClearAllPlayData()
 {
     LanguageDatabase.Clear();
     LoadedModManager.ClearDestroy();
     foreach (Type genericParam in GenTypes.AllSubclasses(typeof(Def)))
     {
         GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), genericParam, "Clear");
     }
     ThingCategoryNodeDatabase.Clear();
     BackstoryDatabase.Clear();
     SolidBioDatabase.Clear();
     PlayDataLoader.loaded = false;
 }
Beispiel #19
0
 static RaceSettings()
 {
     foreach (BackstoryTagItem bt in DefDatabase <RaceSettings> .AllDefs.SelectMany(selector: rs => rs.backstoryTagInsertion))
     {
         foreach (string backstory in bt.backstories)
         {
             if (BackstoryDatabase.TryGetWithIdentifier(backstory, out Backstory bs))
             {
                 bs.spawnCategories.AddRange(bt.spawnCategories);
             }
         }
     }
 }
Beispiel #20
0
        private static bool AddBackstoryToDatabase(Backstory backstory)
        {
            bool keyFound = BackstoryDatabase.allBackstories.ContainsKey(backstory.identifier);

            //Log.Error("Adding Key:" + backstory.identifier + "// keyFound:" + keyFound.ToString());

            if (!keyFound)
            {
                BackstoryDatabase.AddBackstory(backstory);
            }

            return(!keyFound);
        }
 public override void Initialize(CompProperties props)
 {
     base.Initialize(props);
     this.childhoodStory = BackstoryDatabase.RandomBackstory(BackstorySlot.Childhood);
     this.adulthoodStory = BackstoryDatabase.RandomBackstory(BackstorySlot.Adulthood);
     if (Rand.Chance(0.5f))
     {
         memResetMode = MemResetMode.childhood;
     }
     else
     {
         memResetMode = MemResetMode.adulthood;
     }
 }
 public static void ClearAllPlayData()
 {
     LanguageDatabase.Clear();
     LoadedModManager.ClearDestroy();
     foreach (Type item in typeof(Def).AllSubclasses())
     {
         GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "Clear");
     }
     ThingCategoryNodeDatabase.Clear();
     BackstoryDatabase.Clear();
     SolidBioDatabase.Clear();
     Current.Game             = null;
     PlayDataLoader.loadedInt = false;
 }
 public static void LoadAndInjectBackstoryData(LoadedLanguage lang)
 {
     foreach (XElement current in BackstoryTranslationUtility.BackstoryTranslationElements(lang))
     {
         string text = "[unknown]";
         try
         {
             text = current.Name.ToString();
             string    value  = current.Element("title").Value;
             string    value2 = current.Element("titleShort").Value;
             string    value3 = current.Element("desc").Value;
             Backstory backstory;
             if (!BackstoryDatabase.TryGetWithIdentifier(text, out backstory))
             {
                 throw new Exception("Backstory not found matching identifier " + text);
             }
             if (value == backstory.Title && value2 == backstory.TitleShort && value3 == backstory.baseDesc)
             {
                 Log.Error("Backstory translation exactly matches default data: " + text);
             }
             else
             {
                 if (value != null)
                 {
                     backstory.SetTitle(value);
                 }
                 if (value2 != null)
                 {
                     backstory.SetTitleShort(value2);
                 }
                 if (value3 != null)
                 {
                     backstory.baseDesc = value3;
                 }
             }
         }
         catch (Exception ex)
         {
             Log.Warning(string.Concat(new object[]
             {
                 "Couldn't load backstory ",
                 text,
                 ": ",
                 ex,
                 "\nFull XML text:\n\n",
                 current.ToString()
             }));
         }
     }
 }
Beispiel #24
0
        private static void ClearAllPlayData()
        {
            LanguageDatabase.Clear();
            // A14 - ModContentPackManager was removed?
            LoadedModManager.ClearDestroy();
            foreach (Type genericParam in GenTypes.AllSubclasses(typeof(Def)))
            {
                GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), genericParam, "Clear");
            }
            ThingCategoryNodeDatabase.Clear();
            BackstoryDatabase.Clear();
            SolidBioDatabase.Clear();

            PlayDataLoader_loaded.SetValue(null, false);
        }
        private static void FixBackstory(Pawn pawn)
        {
            int tries = 100;

            while (pawn.story.BodyType != BodyType.Female && pawn.story.BodyType != BodyType.Thin)
            {
                //pawn.story.childhood = BackstoryDatabase.RandomBackstory(BackstorySlot.Childhood);
                pawn.story.adulthood = BackstoryDatabase.RandomBackstory(BackstorySlot.Adulthood);
                tries--;
                if (tries <= 0)
                {
                    Log.Error("Couldn't get backstory.");
                    break;
                }
            }
        }
        public override void ExposeData()
        {
            base.ExposeData();

            Scribe_Values.Look(ref sourceName, "sourceName");
            Scribe_Defs.Look(ref kindDef, "kindDef");

            string childhoodIdentifier = (backStoryChild == null) ? null : backStoryChild.identifier;

            Scribe_Values.Look(ref childhoodIdentifier, "backStoryChild");
            if (Scribe.mode == LoadSaveMode.LoadingVars && !childhoodIdentifier.NullOrEmpty())
            {
                if (!BackstoryDatabase.TryGetWithIdentifier(childhoodIdentifier, out backStoryChild, true))
                {
                    Log.Error("Couldn't load child backstory with identifier " + childhoodIdentifier + ". Giving random.", false);
                    backStoryChild = BackstoryDatabase.RandomBackstory(BackstorySlot.Childhood);
                }
            }

            string adulthoodIdentifier = (backStoryAdult == null) ? null : backStoryAdult.identifier;

            Scribe_Values.Look(ref adulthoodIdentifier, "backStoryAdult");
            if (Scribe.mode == LoadSaveMode.LoadingVars && !adulthoodIdentifier.NullOrEmpty())
            {
                if (!BackstoryDatabase.TryGetWithIdentifier(adulthoodIdentifier, out backStoryAdult, true))
                {
                    Log.Error("Couldn't load adult backstory with identifier " + adulthoodIdentifier + ". Giving random.", false);
                    backStoryAdult = BackstoryDatabase.RandomBackstory(BackstorySlot.Adulthood);
                }
            }

            Scribe_Collections.Look(ref skills, "skills", LookMode.Deep);
            Scribe_Values.Look(ref isAnimal, "isAnimal");
            Scribe_Deep.Look(ref trainingLearned, "trainingLearned");
            Scribe_Deep.Look(ref trainingSteps, "trainingSteps");
            Scribe_Collections.Look(ref hediffInfos, "hediffInfos", LookMode.Deep);

            if (Scribe.mode == LoadSaveMode.LoadingVars && hediffInfos != null)
            {
                //remove any hediffs where the def is missing. Most commonly occurs when a mod is removed from a save.
                int removed = hediffInfos.RemoveAll(h => h.def == null);
                if (removed > 0)
                {
                    QEEMod.TryLog("Removed " + removed + " null hediffs from hediffInfo list for " + sourceName + "'s brain template ");
                }
            }
        }
Beispiel #27
0
        public override void ResolveReferences()
        {
            Dictionary <SkillDef, int> skills = new Dictionary <SkillDef, int>();

            base.ResolveReferences();
            foreach (skillGains skillGains in this.skillGains)
            {
                if (!skills.ContainsKey(skillGains.skill))
                {
                    skills.Add(skillGains.skill, skillGains.amount);
                }
            }
            foreach (traitList traitItem in forcedTraits)
            {
                traitsToForce.Add(new TraitEntry(traitItem.def, traitItem.degree));
            }
            this.story = new Backstory
            {
                slot               = this.backstorySlot,
                title              = this.title,
                titleFemale        = this.femaleTitle,
                titleShort         = this.shortTitle,
                titleShortFemale   = this.shortFemaleTitle,
                identifier         = this.defName,
                baseDesc           = this.storyDesc,
                spawnCategories    = this.spawnInCategories,
                skillGainsResolved = skills,
                forcedTraits       = this.traitsToForce,
                disallowedTraits   = this.traitsToDisable,

                workDisables = ((Func <WorkTags>) delegate {
                    WorkTags work = WorkTags.None;
                    Enum.GetValues(typeof(WorkTags)).Cast <WorkTags>().Where(tag =>
                                                                             ((!enabledWorkTypes.NullOrEmpty() && !enabledWorkTypes.Contains(tag)) ||
                                                                              disabledWorkTypes.Contains(tag)) &&
                                                                             (!(disabledWorkTypes.Contains(WorkTags.AllWork)) && !(tag == WorkTags.AllWork))
                                                                             ).ToList().ForEach(tag => work |= tag);
                    return(work);
                })(),
                shuffleable = this.shuffable
            };


            BackstoryDatabase.AddBackstory(story);
            //Log.Message("created story: " + this.defName);
        }
Beispiel #28
0
        public bool Initialize()
        {
            if (!BackstoryDatabase.TryGetWithIdentifier(this.identifier, out this.backstory, false))
            {
                Log.Warning("Unable to load backstory " + this.identifier);
                return(false);
            }

            Util.InitializeDefStat(this.bodyTypeGlobal);
            Util.InitializeDefStat(this.bodyTypeFemale);
            Util.InitializeDefStat(this.bodyTypeMale);

            this.skillGains?.ForEach(v => v.Initialize());
            this.forcedTraits?.ForEach(v => v.Initialize());
            this.disallowedTraits?.ForEach(v => v.Initialize());
            return(true);
        }
Beispiel #29
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);
 }
Beispiel #30
0
        Pawn GenerateGordon(Pawn animal)
        {
            PawnKindDef kind = PawnKindDefOf.Colonist; //TODO get these randomly ;
            Faction     faction = Faction.OfPlayer;
            bool        useFirst = Rand.Bool;
            string      firstName, lastName;

            firstName = lastName = null;
            if (useFirst)
            {
                firstName = "Gordon";
            }
            else
            {
                lastName = "Ramsey";
            }



            float convertedAge = Mathf.Max(TransformerUtility.ConvertAge(animal, ThingDefOf.Human.race), 17);
            float chronoAge    = animal.ageTracker.AgeChronologicalYears * convertedAge / animal.ageTracker.AgeBiologicalYears;
            var   local        = new PawnGenerationRequest(kind, faction, PawnGenerationContext.NonPlayer, -1,
                                                           fixedChronologicalAge: chronoAge,
                                                           fixedBiologicalAge: convertedAge, fixedBirthName: firstName,
                                                           fixedLastName: lastName, fixedGender: Gender.Male, forcedTraits: ForcedTraits)
            {
                ForcedTraits = ForcedTraits, ValidatorPreGear = GordenValidator
            };


            Pawn lPawn = PawnGenerator.GeneratePawn(local);



            if (!BackstoryDatabase.TryGetWithIdentifier("chef", out Backstory back))
            {
            }
            else
            {
                lPawn.story.adulthood = back;
            }

            AssignMutations(lPawn);
            return(lPawn);
        }