示例#1
0
        /// <summary>
        /// Deals with progression.xml.
        /// </summary>
        public static void GetSkills()
        {
            List <SkillData> skillList = SkillData.skillList;
            XmlDocument      document  = new XmlDocument();

            document.Load(Config.GetSetting("gameRoot") + "\\Data\\Config\\progression.xml");

            XmlNode progressionNode = document.DocumentElement;

            XmlNode playerNode = progressionNode.SelectSingleNode("player");

            SkillData.maxPlayerLevel   = int.Parse(playerNode.Attributes["max_level"].Value);
            SkillData.expToPlayerLevel = int.Parse(playerNode.Attributes["exp_to_level"].Value);

            XmlNode skillsNode = progressionNode.SelectSingleNode("skills");

            SkillData.maxLevelDefault   = int.Parse(skillsNode.Attributes["max_level"].Value);
            SkillData.expToLevelDefault = int.Parse(skillsNode.Attributes["exp_to_level"].Value);

            foreach (XmlNode skillNode in skillsNode.ChildNodes)
            {
                SkillData skillData = new SkillData();

                if (skillNode.Name.Equals("player_skill"))
                {
                    skillData.type = SkillType.PlayerSkill;
                }
                else if (skillNode.Name.Equals("action_skill"))
                {
                    skillData.type = SkillType.ActionSkill;
                }
                else if (skillNode.Name.Equals("perk"))
                {
                    skillData.type = SkillType.Perk;
                }
                else if (skillNode.Name.Equals("crafting_skill"))
                {
                    skillData.type = SkillType.CraftingSkill;
                }
                else
                {
                    continue;
                }

                skillData.name = skillNode.Attributes["name"].Value;

                XmlAttribute iconAttr = skillNode.Attributes["icon"];
                if (iconAttr != null)
                {
                    string iconName = "ui_game_symbol_" + iconAttr.Value;
                    if (IconData.itemIconDictionary != null)
                    {
                        IconData.uiIconDictionary.TryGetValue(iconName, out skillData.iconData);
                    }
                }

                XmlAttribute maxLevelAttr = skillNode.Attributes["max_level"];
                if (maxLevelAttr != null)
                {
                    skillData.maxLevel = int.Parse(maxLevelAttr.Value);
                }
                else
                {
                    skillData.maxLevel = SkillData.maxLevelDefault;
                }

                XmlAttribute expToLevelAttr = skillNode.Attributes["exp_to_level"];
                if (expToLevelAttr != null)
                {
                    skillData.expToLevel = int.Parse(expToLevelAttr.Value);
                }
                else if (skillData.type == SkillType.Perk)
                {
                    skillData.expToLevel = 0;
                }
                else
                {
                    skillData.expToLevel = SkillData.expToLevelDefault;
                }

                skillData.requirements = new List <Requirement>();
                skillData.recipes      = new List <RecipeData>();

                for (int i = 0; i < skillNode.ChildNodes.Count; i++)
                {
                    if (skillNode.ChildNodes[i].Name.Equals("requirement"))
                    {
                        XmlNode requirementNode = skillNode.ChildNodes[i];

                        XmlAttribute thisPerkLevelAttr       = requirementNode.Attributes["perk_level"];
                        XmlAttribute requiredSkillNameAttr   = requirementNode.Attributes["required_skill_name"];
                        XmlAttribute requiredSkillLevelAttr  = requirementNode.Attributes["required_skill_level"];
                        XmlAttribute requiredPlayerLevelAttr = requirementNode.Attributes["required_player_level"];

                        if (thisPerkLevelAttr == null)
                        {
                            thisPerkLevelAttr = requirementNode.Attributes["skill_level"];
                        }

                        int    perkLevel = int.Parse(thisPerkLevelAttr.Value);
                        string requiredSkillName;
                        int    requiredSkillLevel;

                        if (requiredSkillNameAttr != null)
                        {
                            requiredSkillName  = requiredSkillNameAttr.Value;
                            requiredSkillLevel = int.Parse(requiredSkillLevelAttr.Value);
                        }
                        else
                        {
                            requiredSkillName  = "Player Level";
                            requiredSkillLevel = int.Parse(requiredPlayerLevelAttr.Value);
                        }

                        skillData.requirements.Add(new Requirement(perkLevel, requiredSkillName, requiredSkillLevel));
                    }
                    else if (skillNode.ChildNodes[i].Name.Equals("recipe"))
                    {
                        XmlNode recipeNode = skillNode.ChildNodes[i];

                        XmlAttribute recipeNameAttr        = recipeNode.Attributes["name"];
                        XmlAttribute recipeUnlockLevelAttr = recipeNode.Attributes["unlock_level"];

                        RecipeData skillsRecipe = RecipeData.GetRecipeDataByName(recipeNameAttr.Value);
                        if (skillsRecipe == null)
                        {
                            skillsRecipe = new RecipeData(recipeNameAttr.Value, false);
                            RecipeData.recipeList.Add(skillsRecipe);
                        }

                        if (skillsRecipe.skillUnlockConditions == null)
                        {
                            skillsRecipe.skillUnlockConditions = new Dictionary <SkillData, int>();
                        }

                        if (!skillsRecipe.skillUnlockConditions.ContainsKey(skillData))
                        {
                            skillsRecipe.skillUnlockConditions.Add(skillData, int.Parse(recipeUnlockLevelAttr.Value));
                        }

                        skillData.recipes.Add(skillsRecipe);
                    }
                }

                skillList.Add(skillData);
            }
        }