Beispiel #1
0
 public ColonistConfiguration()
 {
     foreach (SkillDef current in DefDatabase <SkillDef> .AllDefsListForReading)
     {
         ConfigurationLine configurationLine = new ConfigurationLine()
         {
             skillName = current.label,
             skillId   = (int)current.index
         };
         this.config.Add(configurationLine);
     }
 }
Beispiel #2
0
        public bool CheckColonists()
        {
            List <SkillCheckRecord> list = new List <SkillCheckRecord>();
            int num = 0;

            checked {
                foreach (Pawn current in Find.GameInitData.startingPawns)
                {
                    using (List <SkillRecord> .Enumerator enumerator2 = current.skills.skills.GetEnumerator()) {
                        while (enumerator2.MoveNext())
                        {
                            SkillRecord      skill = enumerator2.Current;
                            SkillCheckRecord skillCheckRecord;
                            try {
                                skillCheckRecord = list.Find((SkillCheckRecord x) => x.skillId.Equals((int)skill.def.index));
                            }
                            catch {
                                skillCheckRecord = null;
                            }
                            if (skillCheckRecord != null)
                            {
                                if (skillCheckRecord.highestSkill < skill.Level && !skill.TotallyDisabled && (this.ColonistConfig[num].isUsing == enumIsUsing.Colony || this.ColonistConfig[num].isUsing == enumIsUsing.Locked))
                                {
                                    skillCheckRecord.highestSkill = skill.Level;
                                    skillCheckRecord.highestPawn  = current;
                                }
                            }
                            else
                            {
                                skillCheckRecord = new SkillCheckRecord()
                                {
                                    skillName = skill.def.skillLabel,
                                    skillId   = (int)skill.def.index
                                };
                                if (!skill.TotallyDisabled && (this.ColonistConfig[num].isUsing == enumIsUsing.Colony || this.ColonistConfig[num].isUsing == enumIsUsing.Locked))
                                {
                                    skillCheckRecord.highestSkill = skill.Level;
                                    skillCheckRecord.highestPawn  = current;
                                }
                                else
                                {
                                    skillCheckRecord.highestSkill = 0;
                                    skillCheckRecord.highestPawn  = null;
                                }
                                list.Add(skillCheckRecord);
                            }
                        }
                    }
                    num++;
                }
                bool result = true;
                this.warnings.Clear();
                using (List <SkillCheckRecord> .Enumerator enumerator3 = list.GetEnumerator()) {
                    while (enumerator3.MoveNext())
                    {
                        SkillCheckRecord  skill             = enumerator3.Current;
                        ConfigurationLine configurationLine = this.config.Find((ConfigurationLine x) => x.skillId == skill.skillId);
                        bool   useSkill        = configurationLine.useSkill;
                        int    minLevel        = configurationLine.minLevel;
                        int    highestSkill    = skill.highestSkill;
                        string highestPawnName = null;
                        Pawn   highestPawn     = skill.highestPawn;
                        if (highestPawn != null)
                        {
                            highestPawnName = highestPawn.NameStringShort;
                        }
                        if (useSkill && highestSkill < minLevel)
                        {
                            this.warnings.Add(new VerifyStartWarning(skill.skillName, skill.skillId, highestSkill, minLevel, false, highestPawnName, highestPawn));
                            result = false;
                        }
                        else
                        {
                            this.warnings.Add(new VerifyStartWarning(skill.skillName, skill.skillId, highestSkill, minLevel, true, highestPawnName, highestPawn));
                        }
                    }
                }
                if (this.bypass)
                {
                    result = true;
                }
                return(result);
            }
        }
Beispiel #3
0
        public void LoadSettings()
        {
            string filepath = GenFilePaths.ModsConfigFilePath.Replace("ModsConfig.xml", "VerifyStart.xml");

            if (File.Exists(filepath))
            {
                ConfigurationLine line = new ConfigurationLine();
                foreach (XElement element in XElement.Load(filepath).Elements())
                {
                    XElement skill     = element;
                    bool     flag      = false;
                    string   localName = skill.Name.LocalName;
                    switch (localName)
                    {
                    case "Shooting":
                    case "Melee":
                    case "Social":
                    case "Animals":
                    case "Medicine":
                    case "Cooking":
                    case "Construction":
                    case "Growing":
                    case "Mining":
                    case "Artistic":
                    case "Crafting":
                    case "Research":
                        line = Instance.Config.Find(x => x.skillName == skill.Name.LocalName);
                        if (line == null)
                        {
                            flag = true;
                            line = new ConfigurationLine();
                        }
                        line.skillName = skill.Name.LocalName;
                        line.useSkill  = Convert.ToBoolean(skill.Attribute("Use").Value);
                        line.minLevel  = int.Parse(skill.Value);
                        if (flag)
                        {
                            VerifyStart.Instance.Config.Add(line);
                            break;
                        }
                        break;

                    case "skill":
                        line = null;
                        if (skill.Attribute("id") == null)
                        {
                            line = Instance.Config.Find(x => x.skillName == skill.Attribute("name").Value);
                        }
                        else
                        {
                            line = Instance.Config.Find(x => x.skillId == int.Parse(skill.Attribute("id").Value));
                        }
                        if (line == null)
                        {
                            flag = true;
                            line = new ConfigurationLine();
                        }
                        line.skillName = skill.Attribute("name").Value;
                        if (skill.Attribute("id") == null)
                        {
                            SkillDef skillDef;
                            try {
                                skillDef = DefDatabase <SkillDef> .AllDefsListForReading.Find(x => x.skillLabel == line.skillName);
                            }
                            catch (NullReferenceException ex) {
                                Log.Error("Loading " + line.skillName + " from config file had no index.  Lookup of skill name in DefDatabase did not return an index either." + Environment.NewLine + ex.Message);
                                skillDef = null;
                            }
                            line.skillId = skillDef == null ? -1 : skillDef.index;
                        }
                        else
                        {
                            line.skillId = int.Parse(skill.Attribute("id").Value);
                        }
                        line.useSkill = Convert.ToBoolean(skill.Attribute("use").Value);
                        line.minLevel = int.Parse(skill.Value);
                        if (flag)
                        {
                            Instance.Config.Add(line);
                            break;
                        }
                        break;

                    default:
                        Log.Warning("Reading Verify Start settings found unknown setting name: " + localName);
                        break;
                    }
                }
            }
            else
            {
                foreach (ConfigurationLine configurationLine in this.Config)
                {
                    configurationLine.minLevel = 6;
                    configurationLine.useSkill = false;
                }
            }
        }