public override void ResolveReferences()
        {
            base.ResolveReferences();

            if (!this.addToDatabase) return;
            if (BackstoryDatabase.allBackstories.ContainsKey(this.UniqueSaveKey())) return;

            Backstory b = new Backstory();
            if (!this.title.NullOrEmpty())
                b.title = this.title;
            else
            {
                CCL_Log.Error(defName + " backstory has empty title. Skipping...", "Backstories");
                return;
            }
            if (!titleShort.NullOrEmpty())
                b.titleShort = titleShort;
            else
                b.titleShort = b.title;

            if (!baseDescription.NullOrEmpty())
                b.baseDesc = baseDescription;
            else
            {
                CCL_Log.Message(defName + " backstory has empty description.", "Backstories");
                b.baseDesc = "Empty.";
            }

            b.bodyTypeGlobal        = bodyTypeGlobal;
            b.bodyTypeMale          = bodyTypeMale;
            b.bodyTypeFemale        = bodyTypeFemale;

            b.slot = slot;

            b.shuffleable = shuffleable;
            if (spawnCategories.NullOrEmpty())
            {
                CCL_Log.Error(defName + " backstory doesn't have any spawn categories defined. Skipping...", "Backstories");
                return;
            }
            else
                b.spawnCategories = spawnCategories;

            if (workAllows.Count > 0)
            {
                foreach (WorkTags current in Enum.GetValues(typeof(WorkTags)))
                {
                    if (!workAllows.Contains(current))
                    {
                        b.workDisables |= current;
                    }
                }
            }
            else if (workDisables.Count > 0)
            {
                foreach (var tag in workDisables)
                {
                    b.workDisables |= tag;
                }
            }
            else
            {
                b.workDisables = WorkTags.None;
            }
            b.skillGains = skillGains.ToDictionary(i => i.defName, i => i.amount);

            b.ResolveReferences();
            b.PostLoad();
            b.uniqueSaveKey = this.UniqueSaveKey();

            bool flag = false;
            foreach (var s in b.ConfigErrors(false))
            {
                if (!flag)
                {
                    flag = true;
                    CCL_Log.Error("Errors in custom backstory with defName: " + defName + ", backstory will be skipped.", "Backstories");
                }
                CCL_Log.Error(defName + " error: " + s, "Backstories");
            }
            if (!flag)
            {
                BackstoryDatabase.AddBackstory(b);
                //CCL_Log.Message("Added " + this.UniqueSaveKey() + " backstory", "Backstories");
            }
        }
        private void AddBackstories(bool report)
        {
            if (Config.debugRemoveAllVanillaBackstories)
            {
                BackstoryDatabase.Clear();
            }

            int num = 0;
            foreach (var def in DefDatabase<BackstoryDef>.AllDefs)
            {
                if (!def.addToDatabase) continue;
                if (BackstoryDatabase.allBackstories.ContainsKey(def.UniqueSaveKeyFor())) continue;

                Backstory b = new Backstory();
                if (!def.title.NullOrEmpty())
                    b.title = def.title;
                else
                {
                    Log.Error(def.defName + " backstory has empty title. Skipping...");
                    continue;
                }
                if (!def.titleShort.NullOrEmpty())
                    b.titleShort = def.titleShort;
                else
                    b.titleShort = b.title;
                b.baseDesc = def.baseDescription;
                b.bodyTypeGlobal = def.bodyTypeGlobal;
                b.bodyTypeMale = def.bodyTypeMale;
                b.bodyTypeFemale = def.bodyTypeFemale;
                b.slot = def.slot;
                b.shuffleable = def.shuffleable;
                b.spawnCategories = def.spawnCategories;
                if (def.workAllows.Count > 0)
                {
                    foreach (WorkTags current in Enum.GetValues(typeof(WorkTags)))
                    {
                        if (!def.workAllows.Contains(current))
                        {
                            b.workDisables |= current;
                        }
                    }
                }
                else if (def.workDisables.Count > 0)
                {
                    foreach (var tag in def.workDisables)
                    {
                        b.workDisables |= tag;
                    }
                }
                else
                {
                    b.workDisables = WorkTags.None;
                }
                b.skillGains = def.skillGains.ToDictionary(i => i.defName, i => i.amount);
                b.ResolveReferences();
                b.PostLoad();
                b.uniqueSaveKey = def.UniqueSaveKeyFor();
                bool flag = false;
                foreach (var s in b.ConfigErrors(false))
                {
                    if (!flag)
                    {
                        flag = true;
                        Log.Error("Backstories! backstory errors in custom backstory with defName: " + def.defName + ", backstory will be skipped");
                    }
                    Log.Error(def.defName + " error: " + s);
                }
                if (!flag)
                {
                    BackstoryDatabase.AddBackstory(b);
                    num++;
                }
            }
            if (num > 0 && report)
                Log.Warning("BackstoriesCore added " + num.ToString() + " custom backstories.");
        }
示例#3
0
        public override void ResolveReferences()
        {
            base.ResolveReferences();

            WorkTags workDisables = WorkTags.None;

            if (this.workDisables != null)
            {
                this.workDisables.ForEach(x => workDisables |= x);
            }

            WorkTags requiredWorkTags = WorkTags.None;

            if (this.requiredWorkTags != null)
            {
                this.requiredWorkTags.ForEach(x => requiredWorkTags |= x);
            }

            List <TraitEntry> forcedTraits = new List <TraitEntry>();

            if (this.forcedTraits != null)
            {
                this.forcedTraits.ForEach(x => forcedTraits.Add(new TraitEntry(x.traitDef, x.degree)));
            }

            List <TraitEntry> disallowedTraits = new List <TraitEntry>();

            if (this.disallowedTraits != null)
            {
                this.disallowedTraits.ForEach(x => disallowedTraits.Add(new TraitEntry(x.traitDef, x.degree)));
            }

            Dictionary <SkillDef, int> skillGainsResolved = new Dictionary <SkillDef, int>();

            if (skillGains != null)
            {
                skillGains.ForEach(x => skillGainsResolved.Add(x.skill, x.xp));
            }

            backstory = new Backstory
            {
                identifier = defName,

                slot            = slot,
                title           = backstoryTitle,
                titleShort      = backstoryTitleShort,
                baseDesc        = backstoryDescription,
                spawnCategories = spawnCategories,

                workDisables       = workDisables,
                requiredWorkTags   = requiredWorkTags,
                forcedTraits       = forcedTraits,
                disallowedTraits   = disallowedTraits,
                skillGainsResolved = skillGainsResolved
            };
            Traverse.Create(backstory).Field("bodyTypeMaleResolved").SetValue(BodyTypeDefOf.Male);
            Traverse.Create(backstory).Field("bodyTypeFemaleResolved").SetValue(BodyTypeDefOf.Female);
            backstory.ResolveReferences();
            backstory.PostLoad();

            IEnumerable <string> errors;

            if (!(errors = backstory.ConfigErrors(false)).Any())
            {
                BackstoryDatabase.AddBackstory(backstory);
            }
            else
            {
                Log.Error("====================================================================================================");
                Log.Error("[Garam, Race Addon] BackstoryDef has errors : " + defName + string.Join("\n", errors.ToArray()));
                Log.Error("====================================================================================================");
            }
        }
示例#4
0
        public override void ResolveReferences()
        {
            base.ResolveReferences();

            if (!this.addToDatabase)
            {
                return;
            }
            if (BackstoryDatabase.allBackstories.ContainsKey(this.UniqueSaveKey()))
            {
                return;
            }

            Backstory b = new Backstory();

            if (!this.title.NullOrEmpty())
            {
                b.SetTitle(this.title);
            }
            else
            {
                return;
            }
            if (!titleShort.NullOrEmpty())
            {
                b.SetTitleShort(titleShort);
            }
            else
            {
                b.SetTitleShort(b.Title);
            }

            if (!baseDescription.NullOrEmpty())
            {
                b.baseDesc = baseDescription;
            }
            else
            {
                b.baseDesc = "Empty.";
            }

            b.bodyTypeGlobal = bodyTypeGlobal;
            b.bodyTypeMale   = bodyTypeMale;
            b.bodyTypeFemale = bodyTypeFemale;

            b.slot = slot;

            b.shuffleable = shuffleable;
            if (spawnCategories.NullOrEmpty())
            {
                return;
            }
            else
            {
                b.spawnCategories = spawnCategories;
            }

            if (workAllows.Count > 0)
            {
                foreach (WorkTags current in Enum.GetValues(typeof(WorkTags)))
                {
                    if (!workAllows.Contains(current))
                    {
                        b.workDisables |= current;
                    }
                }
            }
            else if (workDisables.Count > 0)
            {
                foreach (var tag in workDisables)
                {
                    b.workDisables |= tag;
                }
            }
            else
            {
                b.workDisables = WorkTags.None;
            }
            b.skillGains = skillGains.ToDictionary(i => i.defName, i => i.amount);

            if (forcedTraits.Count > 0)
            {
                b.forcedTraits = new List <TraitEntry>();
                foreach (var trait in forcedTraits)
                {
                    var newTrait = new TraitEntry(trait.def, trait.degree);
                    b.forcedTraits.Add(newTrait);
                }
            }

            if (disallowedTraits.Count > 0)
            {
                b.disallowedTraits = new List <TraitEntry>();
                foreach (var trait in disallowedTraits)
                {
                    var newTrait = new TraitEntry(trait.def, trait.degree);
                    b.disallowedTraits.Add(newTrait);
                }
            }

            b.ResolveReferences();
            b.PostLoad();

            bool flag = false;

            foreach (var s in b.ConfigErrors(false))
            {
                if (!flag)
                {
                    flag = true;
                }
            }
            if (!flag)
            {
                BackstoryDatabase.AddBackstory(b);
                //CCL_Log.Message("Added " + this.UniqueSaveKey() + " backstory", "Backstories");
            }
        }
        public override void ResolveReferences()
        {
            base.ResolveReferences();
            if (!this.addToDatabase)
            {
                return;
            }
            if (BackstoryDatabase.allBackstories.ContainsKey(this.saveKeyIdentifier))
            {
                return;
            }
            Backstory backstory = new Backstory();

            if (GenText.NullOrEmpty(this.title))
            {
                return;
            }
            backstory.SetTitle(this.title, this.title);
            if (!GenText.NullOrEmpty(this.titleShort))
            {
                backstory.SetTitleShort(this.titleShort, this.titleShort);
            }
            else
            {
                backstory.SetTitleShort(backstory.title, backstory.title);
            }
            if (!GenText.NullOrEmpty(this.baseDescription))
            {
                backstory.baseDesc = this.baseDescription;
            }
            else
            {
                backstory.baseDesc = "Empty.";
            }
            Traverse.Create(backstory).Field("bodyTypeGlobal").SetValue(this.bodyTypeGlobal);
            Traverse.Create(backstory).Field("bodyTypeMale").SetValue(this.bodyTypeMale);
            Traverse.Create(backstory).Field("bodyTypeFemale").SetValue(this.bodyTypeFemale);
            backstory.slot        = this.slot;
            backstory.shuffleable = this.shuffleable;
            if (GenList.NullOrEmpty <string>(this.spawnCategories))
            {
                return;
            }
            backstory.spawnCategories = this.spawnCategories;
            if (this.workDisables.Count > 0)
            {
                using (List <WorkTags> .Enumerator enumerator2 = this.workDisables.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        WorkTags workTags2 = enumerator2.Current;
                        backstory.workDisables |= workTags2;
                    }
                    goto IL_1E9;
                }
            }
            backstory.workDisables = 0;
IL_1E9:
            backstory.ResolveReferences();
            backstory.PostLoad();
            backstory.identifier = this.saveKeyIdentifier;
            bool flag = false;

            foreach (string text in backstory.ConfigErrors(false))
            {
                if (!flag)
                {
                    flag = true;
                }
            }
            if (!flag)
            {
                BackstoryDatabase.AddBackstory(backstory);
            }
        }
示例#6
0
        public override void ResolveReferences()
        {
            base.ResolveReferences();
            if (!this.addToDatabase)
            {
                return;
            }
            if (BackstoryDatabase.allBackstories.ContainsKey(this.UniqueSaveKey()))
            {
                Log.Error("Backstory Error (" + this.defName + "): Duplicate defName.");
                return;
            }
            Backstory b = new Backstory();

            if (!this.title.NullOrEmpty())
            {
                b.SetTitle(this.title, this.title);
            }
            else
            {
                return;
            }
            if (!titleShort.NullOrEmpty())
            {
                b.SetTitleShort(titleShort, titleShort);
            }
            else
            {
                b.SetTitleShort(b.title, b.title);
            }
            if (!baseDesc.NullOrEmpty())
            {
                b.baseDesc = baseDesc;
            }
            else
            {
                b.baseDesc = "Empty.";
            }
            bool bodyTypeSet = false;

            if (!string.IsNullOrEmpty(bodyTypeGlobal))
            {
                bodyTypeSet = SetGlobalBodyType(b, bodyTypeGlobal);
            }
            if (!bodyTypeSet)
            {
                if (!SetMaleBodyType(b, bodyTypeMale))
                {
                    SetMaleBodyType(b, "Male");
                }
                if (!SetFemaleBodyType(b, bodyTypeFemale))
                {
                    SetFemaleBodyType(b, "Female");
                }
            }
            b.slot        = slot;
            b.shuffleable = shuffleable;
            if (spawnCategories.NullOrEmpty())
            {
                return;
            }
            else
            {
                b.spawnCategories = spawnCategories;
            }
            if (workAllows.Count > 0)
            {
                foreach (WorkTags current in Enum.GetValues(typeof(WorkTags)))
                {
                    if (!workAllows.Contains(current))
                    {
                        b.workDisables |= current;
                    }
                }
            }
            else if (workDisables.Count > 0)
            {
                foreach (var tag in workDisables)
                {
                    b.workDisables |= tag;
                }
            }
            else
            {
                b.workDisables = WorkTags.None;
            }
            if (requiredWorkTags.Count > 0)
            {
                foreach (var tag in requiredWorkTags)
                {
                    b.requiredWorkTags |= tag;
                }
            }
            else
            {
                b.requiredWorkTags = WorkTags.None;
            }
            Dictionary <SkillDef, int> skillDefs = new Dictionary <SkillDef, int>();

            foreach (BackstoryDefSkillListItem skillGain in this.skillGains)
            {
                SkillDef named = DefDatabase <SkillDef> .GetNamed(skillGain.key, false);

                if (named == null)
                {
                    Log.Error(string.Concat(new string[] { "Tribal Raiders: Unable to find SkillDef of [", skillGain.key, "] for Backstory.Title [", b.title, "]" }), false);
                    continue;
                }
                skillDefs.Add(named, skillGain.@value);
            }
            b.skillGainsResolved = skillDefs;
            Dictionary <string, int> fTraitList = forcedTraits.ToDictionary(i => i.key, i => i.value);

            if (fTraitList.Count > 0)
            {
                b.forcedTraits = new List <TraitEntry>();
                foreach (KeyValuePair <string, int> trait in fTraitList)
                {
                    b.forcedTraits.Add(new TraitEntry(TraitDef.Named(trait.Key), trait.Value));
                }
            }
            Dictionary <string, int> dTraitList = disallowedTraits.ToDictionary(i => i.key, i => i.value);

            if (dTraitList.Count > 0)
            {
                b.disallowedTraits = new List <TraitEntry>();
                foreach (KeyValuePair <string, int> trait in dTraitList)
                {
                    b.disallowedTraits.Add(new TraitEntry(TraitDef.Named(trait.Key), trait.Value));
                }
            }
            b.ResolveReferences();
            b.PostLoad();
            b.identifier = this.UniqueSaveKey();
            bool flag2 = false;

            foreach (var s in b.ConfigErrors(false))
            {
                Log.Error("Backstory Error (" + b.identifier + "): " + s);
                if (!flag2)
                {
                    flag2 = true;
                }
            }
            if (!flag2)
            {
                BackstoryDatabase.allBackstories.Add(b.identifier, b);
            }
        }
示例#7
0
        public override void ResolveReferences()
        {
            if (BackstoryDatabase.allBackstories.ContainsKey(this.saveKeyIdentifier))
            {
                Log.Error(this.defName + " contains a saveKeyIdentifier value " + saveKeyIdentifier + " which is used already. It won't be added as a def. Make sure that the identifier is unique.");
                return;
            }

            Backstory backstory = new Backstory();

            if (this.forcedTraits?.Any() ?? false)
            {
                backstory.forcedTraits = new List <TraitEntry>();
                foreach (var trait in this.forcedTraits.Where(x => Rand.RangeInclusive(0, 100) < x.chance))
                {
                    backstory.forcedTraits.Add(new TraitEntry(trait.defName, trait.degree));
                }
            }

            if (this.disallowedTraits?.Any() ?? false)
            {
                backstory.disallowedTraits = new List <TraitEntry>();
                foreach (var trait in this.disallowedTraits.Where(x => Rand.RangeInclusive(0, 100) < x.chance))
                {
                    backstory.disallowedTraits.Add(new TraitEntry(trait.defName, trait.degree));
                }
            }

            backstory.SetTitle(this.title, this.title);
            if (!GenText.NullOrEmpty(this.titleShort))
            {
                backstory.SetTitleShort(this.titleShort, this.titleShort);
            }
            else
            {
                backstory.SetTitleShort(backstory.title, backstory.title);
            }
            if (!GenText.NullOrEmpty(this.baseDescription))
            {
                backstory.baseDesc = this.baseDescription;
            }

            Traverse.Create(backstory).Field("bodyTypeGlobal").SetValue(this.bodyTypeGlobal);
            Traverse.Create(backstory).Field("bodyTypeMale").SetValue(this.bodyTypeMale);
            Traverse.Create(backstory).Field("bodyTypeFemale").SetValue(this.bodyTypeFemale);
            if (skillGains?.Any() ?? false)
            {
                var skillGainsDict = skillGains.ToDictionary(x => x.skill.defName, y => y.minLevel);
                Traverse.Create(backstory).Field("skillGains").SetValue(skillGainsDict);
            }

            backstory.slot            = this.slot;
            backstory.shuffleable     = this.shuffleable;
            backstory.spawnCategories = this.spawnCategories;

            if (this.workDisables.Any())
            {
                foreach (var workTag in this.workDisables)
                {
                    backstory.workDisables |= workTag;
                }
            }
            else
            {
                backstory.workDisables = WorkTags.None;
            }

            backstory.PostLoad();
            backstory.ResolveReferences();
            backstory.identifier = this.saveKeyIdentifier;

            if (!backstory.ConfigErrors(true).Any())
            {
                BackstoryDatabase.AddBackstory(backstory);
            }
            else
            {
                foreach (var err in backstory.ConfigErrors(true))
                {
                    Log.Error(backstory + " - " + err);
                }
            }
        }
        public override void ResolveReferences()
        {
            base.ResolveReferences();
            if (!this.addToDatabase)
            {
                return;
            }
            if (BackstoryDatabase.allBackstories.ContainsKey(this.UniqueSaveKey()))
            {
                Log.Error("Backstory Error (" + this.defName + "): Duplicate defName.");
                return;
            }
            Backstory b = new Backstory();

            if (!string.IsNullOrEmpty(this.title) || !string.IsNullOrEmpty(this.titleFemale))
            {
                b.SetTitle((string.IsNullOrEmpty(this.title) ? this.titleFemale : this.title), (string.IsNullOrEmpty(this.titleFemale) ? this.title : this.titleFemale));
            }
            else
            {
                return;
            }
            if (!string.IsNullOrEmpty(titleShort) || !string.IsNullOrEmpty(titleShortFemale))
            {
                b.SetTitleShort((string.IsNullOrEmpty(this.titleShort) ? this.titleShortFemale : this.titleShort), (string.IsNullOrEmpty(this.titleShortFemale) ? this.titleShort : this.titleShortFemale));
            }
            else
            {
                b.SetTitleShort((string.IsNullOrEmpty(this.title) ? this.titleFemale : this.title), (string.IsNullOrEmpty(this.titleFemale) ? this.title : this.titleFemale));
            }
            if (!baseDesc.NullOrEmpty())
            {
                b.baseDesc = baseDesc;
            }
            else
            {
                b.baseDesc = "Empty.";
            }
            bool bodyTypeSet = false;

            if (!string.IsNullOrEmpty(bodyTypeGlobal))
            {
                bodyTypeSet = SetGlobalBodyType(b, bodyTypeGlobal);
            }
            if (!bodyTypeSet)
            {
                if (!SetMaleBodyType(b, bodyTypeMale))
                {
                    SetMaleBodyType(b, "Male");
                }
                if (!SetFemaleBodyType(b, bodyTypeFemale))
                {
                    SetFemaleBodyType(b, "Female");
                }
            }
            b.slot        = slot;
            b.shuffleable = shuffleable;
            if (spawnCategories.NullOrEmpty())
            {
                return;
            }
            else
            {
                for (int i = 0; i < spawnCategories.Count; i++)
                {
                    if (Util.Categories.Contains(spawnCategories[i]))
                    {
                        spawnCategories[i] = "REB" + spawnCategories[i];
                    }
                }
            }
            b.spawnCategories = spawnCategories;
            if (workAllows.Count > 0)
            {
                foreach (WorkTags current in Enum.GetValues(typeof(WorkTags)))
                {
                    if (!workAllows.Contains(current))
                    {
                        b.workDisables |= current;
                    }
                }
            }
            else if (workDisables.Count > 0)
            {
                foreach (var tag in workDisables)
                {
                    b.workDisables |= tag;
                }
            }
            else
            {
                b.workDisables = WorkTags.None;
            }
            if (requiredWorkTags.Count > 0)
            {
                foreach (var tag in requiredWorkTags)
                {
                    b.requiredWorkTags |= tag;
                }
            }
            else
            {
                b.requiredWorkTags = WorkTags.None;
            }
            Dictionary <SkillDef, int> d = new Dictionary <SkillDef, int>();

            foreach (BackstoryDefSkillListItem i in skillGains)
            {
                SkillDef def = DefDatabase <SkillDef> .GetNamed(i.key, false);

                if (def == null)
                {
                    if (i.key.Equals("Growing"))
                    {
                        Log.Message("Editable Backstories: Converting SkillDef of [" + i.key + "] to [" + SkillDefOf.Plants.ToString() + "] for Backstory.Title [" + b.title + "]");
                        def = SkillDefOf.Plants;
                    }
                    else
                    {
                        Log.Error("Editable Backstories: Unable to find SkillDef of [" + i.key + "] for Backstory.Title [" + b.title + "]");
                    }
                }
                if (def != null)
                {
                    d.Add(def, i.value);
                }
            }
            b.skillGainsResolved = d;
            Dictionary <string, int> fTraitList = forcedTraits.ToDictionary(i => i.key, i => i.value);

            if (fTraitList.Count > 0)
            {
                b.forcedTraits = new List <TraitEntry>();
                foreach (KeyValuePair <string, int> trait in fTraitList)
                {
                    b.forcedTraits.Add(new TraitEntry(TraitDef.Named(trait.Key), trait.Value));
                }
            }
            Dictionary <string, int> dTraitList = disallowedTraits.ToDictionary(i => i.key, i => i.value);

            if (dTraitList.Count > 0)
            {
                b.disallowedTraits = new List <TraitEntry>();
                foreach (KeyValuePair <string, int> trait in dTraitList)
                {
                    b.disallowedTraits.Add(new TraitEntry(TraitDef.Named(trait.Key), trait.Value));
                }
            }
            b.ResolveReferences();
            b.PostLoad();
            b.identifier = this.UniqueSaveKey();
            bool skip = false;

            foreach (var s in b.ConfigErrors(false))
            {
                Log.Error("Backstory Error (" + b.identifier + "): " + s);
                skip = true;
            }
            if (!skip)
            {
                if (b.slot.Equals(BackstorySlot.Adulthood))
                {
                    if (b.shuffleable.Equals(true))
                    {
                        REB_Initializer.adultCount++;
                    }
                    else
                    {
                        REB_Initializer.adultNSCount++;
                    }
                }
                if (b.slot.Equals(BackstorySlot.Childhood))
                {
                    if (b.shuffleable.Equals(true))
                    {
                        REB_Initializer.childCount++;
                    }
                    else
                    {
                        REB_Initializer.childNSCount++;
                    }
                }
                BackstoryDatabase.allBackstories[b.identifier] = b;
            }
        }
示例#9
0
        public override void ResolveReferences()
        {
            base.ResolveReferences();


            if (!this.addToDatabase || BackstoryDatabase.allBackstories.ContainsKey(this.defName) || this.title.NullOrEmpty() || this.spawnCategories.NullOrEmpty())
            {
                return;
            }

            Backstory b = new Backstory()
            {
                baseDesc         = this.baseDescription.NullOrEmpty() ? "Empty." : this.baseDescription,
                bodyTypeGlobal   = this.bodyTypeGlobal,
                bodyTypeFemale   = this.bodyTypeFemale,
                bodyTypeMale     = this.bodyTypeMale,
                slot             = this.slot,
                shuffleable      = this.shuffleable,
                spawnCategories  = this.spawnCategories,
                skillGains       = this.skillGains.ToDictionary(i => i.defName, i => i.amount),
                forcedTraits     = this.forcedTraits.NullOrEmpty() ? null : this.forcedTraits.Where(trait => Rand.Range(0, 100) < trait.chance).ToList().ConvertAll(trait => new TraitEntry(TraitDef.Named(trait.defname), trait.degree)),
                disallowedTraits = this.disallowedTraits.NullOrEmpty() ? null : this.disallowedTraits.Where(trait => Rand.Range(0, 100) < trait.chance).ToList().ConvertAll(trait => new TraitEntry(TraitDef.Named(trait.defname), trait.degree)),
                workDisables     = this.workAllows.NullOrEmpty() ? this.workDisables.NullOrEmpty() ? WorkTags.None : ((Func <WorkTags>) delegate
                {
                    WorkTags wt = WorkTags.None;
                    this.workDisables.ForEach(tag => wt |= tag);
                    return(wt);
                })() : ((Func <WorkTags>) delegate
                {
                    WorkTags wt = WorkTags.None;
                    Enum.GetValues(typeof(WorkTags)).Cast <WorkTags>().ToList().ForEach(tag => { if (this.workAllows.Contains(tag))
                                                                                                 {
                                                                                                     wt |= tag;
                                                                                                 }
                                                                                        });
                    return(wt);
                })(),
                identifier = this.defName
            };

            b.SetTitle(this.title);
            if (!this.titleShort.NullOrEmpty())
            {
                b.SetTitleShort(this.titleShort);
            }
            else
            {
                b.SetTitleShort(b.Title);
            }

            b.ResolveReferences();
            b.PostLoad();

            b.identifier = this.defName;

            IEnumerable <string> errors;

            if (!(errors = b.ConfigErrors(false)).Any())
            {
                BackstoryDatabase.AddBackstory(b);
            }
            else
            {
                Log.Error(this.defName + " has errors: " + string.Join("\n", errors.ToArray()));
            }
        }
示例#10
0
        public override void ResolveReferences()
        {
            base.ResolveReferences();

            if (!this.addToDatabase)
            {
                return;
            }
            if (BackstoryDatabase.allBackstories.ContainsKey(this.UniqueSaveKey()))
            {
                return;
            }

            Backstory b = new Backstory();

            if (!this.title.NullOrEmpty())
            {
                b.SetTitle(this.title, this.title);
            }
            else
            {
                return;
            }
            if (!titleShort.NullOrEmpty())
            {
                b.SetTitleShort(titleShort, titleShort);
            }
            else
            {
                b.SetTitleShort(b.title, b.title);
            }

            if (!baseDescription.NullOrEmpty())
            {
                b.baseDesc = baseDescription;
            }
            else
            {
                b.baseDesc = "Empty.";
            }

            // [B19] These are now private variables.
            Traverse.Create(b).Field("bodyTypeGlobal").SetValue(bodyTypeGlobal);
            Traverse.Create(b).Field("bodyTypeMale").SetValue(bodyTypeMale);
            Traverse.Create(b).Field("bodyTypeFemale").SetValue(bodyTypeFemale);

            b.slot = slot;

            b.shuffleable = shuffleable;
            if (spawnCategories.NullOrEmpty())
            {
                return;
            }
            else
            {
                b.spawnCategories = spawnCategories;
            }

            if (workAllows.Count > 0)
            {
                foreach (WorkTags current in Enum.GetValues(typeof(WorkTags)))
                {
                    if (!workAllows.Contains(current))
                    {
                        b.workDisables |= current;
                    }
                }
            }
            else if (workDisables.Count > 0)
            {
                foreach (var tag in workDisables)
                {
                    b.workDisables |= tag;
                }
            }
            else
            {
                b.workDisables = WorkTags.None;
            }
            Dictionary <string, int> skGains = skillGains.ToDictionary(i => i.defName, i => i.amount);

            foreach (KeyValuePair <string, int> current in skGains)
            {
                b.skillGainsResolved.Add(DefDatabase <SkillDef> .GetNamed(current.Key, true), current.Value);
            }

            if (forcedTraits.Count > 0)
            {
                b.forcedTraits = new List <TraitEntry>();
                foreach (var trait in forcedTraits)
                {
                    var newTrait = new TraitEntry(trait.def, trait.degree);
                    b.forcedTraits.Add(newTrait);
                }
            }

            if (disallowedTraits.Count > 0)
            {
                b.disallowedTraits = new List <TraitEntry>();
                foreach (var trait in disallowedTraits)
                {
                    var newTrait = new TraitEntry(trait.def, trait.degree);
                    b.disallowedTraits.Add(newTrait);
                }
            }

            b.ResolveReferences();
            b.PostLoad();
            b.identifier = this.UniqueSaveKey();

            bool flag = false;

            foreach (var s in b.ConfigErrors(false))
            {
                if (!flag)
                {
                    flag = true;
                }
            }
            if (!flag)
            {
                BackstoryDatabase.AddBackstory(b);
                //Log.Message("Added " + this.UniqueSaveKey() + " backstory");
                //CCL_Log.Message("Added " + this.UniqueSaveKey() + " backstory", "Backstories");
            }
        }