Ejemplo n.º 1
0
            public string GetAdjustedBaseCooldown(AbilityXmlInfo abilityDataEntry)
            {
                if (string.IsNullOrEmpty(abilityDataEntry.BaseCooldown))
                {
                    return(string.Empty);
                }
                if (string.IsNullOrEmpty(abilityDataEntry.CooldownChangeSkills))
                {
                    return(abilityDataEntry.BaseCooldown);
                }
                GameObject player = XRLCore.Core?.Game?.Player?.Body;

                if (player == null)
                {
                    return(abilityDataEntry.BaseCooldown);
                }
                int baseCooldown = int.Parse(abilityDataEntry.BaseCooldown);

                foreach (string entry in abilityDataEntry.CooldownChangeSkills.Split(','))
                {
                    string skill        = entry.Split(':')[0];
                    int    adjustAmount = int.Parse(entry.Split(':')[1]);
                    if (player.HasSkill(skill))
                    {
                        baseCooldown += adjustAmount;
                    }
                }
                return(baseCooldown.ToString());
            }
        public static Dictionary <string, List <AbilityXmlInfo> > LoadAbilityDataFile(string filePath)
        {
            Dictionary <string, List <AbilityXmlInfo> > ModCategorizedData = new Dictionary <string, List <AbilityXmlInfo> >();

            try
            {
                using (XmlTextReader stream = new XmlTextReader(filePath))
                {
                    stream.WhitespaceHandling = WhitespaceHandling.None;
                    while (stream.Read())
                    {
                        if (stream.Name == "abilityEntries")
                        {
                            while (stream.Read())
                            {
                                if (stream.Name == "category")
                                {
                                    string categoryName = stream.GetAttribute("Name");
                                    List <AbilityXmlInfo> categoryEntries = new List <AbilityXmlInfo>();
                                    while (stream.Read())
                                    {
                                        if (stream.Name == "abilityEntry")
                                        {
                                            AbilityXmlInfo thisEntry = new AbilityXmlInfo
                                            {
                                                Name                 = stream.GetAttribute("Name"),
                                                Class                = stream.GetAttribute("Class"),
                                                Command              = stream.GetAttribute("Command"),
                                                MutationName         = stream.GetAttribute("MutationName"),
                                                SkillName            = stream.GetAttribute("SkillName"),
                                                BaseCooldown         = stream.GetAttribute("BaseCooldown"),
                                                CustomDescription    = stream.GetAttribute("CustomDescription"),
                                                DeleteLines          = stream.GetAttribute("DeleteLines"),
                                                DeletePhrases        = stream.GetAttribute("DeletePhrases"),
                                                NoCooldownReduction  = stream.GetAttribute("NoCooldownReduction"),
                                                CooldownChangeSkills = stream.GetAttribute("CooldownChangeSkills")
                                            };
                                            categoryEntries.Add(thisEntry);
                                        }
                                        if (stream.NodeType == XmlNodeType.EndElement && (stream.Name == string.Empty || stream.Name == "category"))
                                        {
                                            break;
                                        }
                                    }
                                    if (categoryEntries.Count > 0)
                                    {
                                        if (ModCategorizedData.ContainsKey(categoryName))
                                        {
                                            ModCategorizedData[categoryName].AddRange(categoryEntries);
                                        }
                                        else
                                        {
                                            ModCategorizedData.Add(categoryName, categoryEntries);
                                        }
                                    }
                                }
                                if (stream.NodeType == XmlNodeType.EndElement && (stream.Name == string.Empty || stream.Name == "abilityEntries"))
                                {
                                    break;
                                }
                            }
                        }
                        if (stream.NodeType == XmlNodeType.EndElement && (stream.Name == string.Empty || stream.Name == "abilityEntries"))
                        {
                            break;
                        }
                    }
                    stream.Close();
                }
            }
            catch (Exception ex)
            {
                Log($"Error trying to load data from {Constants.AbilityDataFileName} ({ex})");
                ModCategorizedData.Clear();
            }
            return(ModCategorizedData);
        }