Ejemplo n.º 1
0
        // Rebuild the list of Spirits/Sprites based on the character's selected Tradition/Stream.
        public void RebuildSpiritList(Tradition objTradition)
        {
            if (objTradition == null)
            {
                return;
            }
            string strCurrentValue = cboSpiritName.SelectedValue?.ToString() ?? _objSpirit.Name;

            XmlDocument objXmlDocument = _objSpirit.EntityType == SpiritType.Spirit ? XmlManager.Load("traditions.xml") : XmlManager.Load("streams.xml");

            HashSet <string> lstLimitCategories = new HashSet <string>();

            foreach (Improvement improvement in _objSpirit.CharacterObject.Improvements.Where(x => x.ImproveType == Improvement.ImprovementType.LimitSpiritCategory && x.Enabled))
            {
                lstLimitCategories.Add(improvement.ImprovedName);
            }

            List <ListItem> lstCritters = new List <ListItem>();

            if (objTradition.IsCustomTradition)
            {
                string strSpiritCombat       = objTradition.SpiritCombat;
                string strSpiritDetection    = objTradition.SpiritDetection;
                string strSpiritHealth       = objTradition.SpiritHealth;
                string strSpiritIllusion     = objTradition.SpiritIllusion;
                string strSpiritManipulation = objTradition.SpiritManipulation;

                if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritCombat)) && !string.IsNullOrWhiteSpace(strSpiritCombat))
                {
                    XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritCombat + "\"]");
                    lstCritters.Add(new ListItem(strSpiritCombat, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritCombat));
                }

                if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritDetection)) && !string.IsNullOrWhiteSpace(strSpiritDetection))
                {
                    XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritDetection + "\"]");
                    lstCritters.Add(new ListItem(strSpiritDetection, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritDetection));
                }

                if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritHealth)) && !string.IsNullOrWhiteSpace(strSpiritHealth))
                {
                    XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritHealth + "\"]");
                    lstCritters.Add(new ListItem(strSpiritHealth, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritHealth));
                }

                if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritIllusion)) && !string.IsNullOrWhiteSpace(strSpiritIllusion))
                {
                    XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritIllusion + "\"]");
                    lstCritters.Add(new ListItem(strSpiritIllusion, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritIllusion));
                }

                if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritManipulation)) && !string.IsNullOrWhiteSpace(strSpiritManipulation))
                {
                    XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritManipulation + "\"]");
                    lstCritters.Add(new ListItem(strSpiritManipulation, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritManipulation));
                }
            }
            else
            {
                if (objTradition.GetNode()?.SelectSingleNode("spirits/spirit[. = \"All\"]") != null)
                {
                    if (lstLimitCategories.Count == 0)
                    {
                        using (XmlNodeList xmlSpiritList = objXmlDocument.SelectNodes("/chummer/spirits/spirit"))
                            if (xmlSpiritList != null)
                            {
                                foreach (XmlNode objXmlCritterNode in xmlSpiritList)
                                {
                                    string strSpiritName = objXmlCritterNode["name"]?.InnerText;
                                    lstCritters.Add(new ListItem(strSpiritName, objXmlCritterNode["translate"]?.InnerText ?? strSpiritName));
                                }
                            }
                    }
                    else
                    {
                        foreach (string strSpiritName in lstLimitCategories)
                        {
                            XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritName + "\"]");
                            lstCritters.Add(new ListItem(strSpiritName, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritName));
                        }
                    }
                }
                else
                {
                    using (XmlNodeList xmlSpiritList = objTradition.GetNode()?.SelectSingleNode("spirits")?.ChildNodes)
                        if (xmlSpiritList != null)
                        {
                            foreach (XmlNode objXmlSpirit in xmlSpiritList)
                            {
                                string strSpiritName = objXmlSpirit.InnerText;
                                if (lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritName))
                                {
                                    XmlNode objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + strSpiritName + "\"]");
                                    lstCritters.Add(new ListItem(strSpiritName, objXmlCritterNode?["translate"]?.InnerText ?? strSpiritName));
                                }
                            }
                        }
                }
            }

            if (_objSpirit.CharacterObject.RESEnabled)
            {
                // Add any additional Sprites the character has Access to through improvements.
                lstCritters.AddRange(from objImprovement in _objSpirit.CharacterObject.Improvements
                                     .Where(imp => imp.ImproveType == Improvement.ImprovementType.AddSprite && imp.Enabled)
                                     let objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + objImprovement.ImprovedName + "\"]")
                                                             select new ListItem(objImprovement.ImprovedName, objXmlCritterNode?["translate"]?.InnerText ?? objImprovement.ImprovedName));
            }
            if (_objSpirit.CharacterObject.MAGEnabled)
            {
                // Add any additional Spirits the character has Access to through improvements.
                lstCritters.AddRange(from objImprovement in _objSpirit.CharacterObject.Improvements
                                     .Where(imp => imp.ImproveType == Improvement.ImprovementType.AddSpirit && imp.Enabled)
                                     let objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = \"" + objImprovement.ImprovedName + "\"]")
                                                             select new ListItem(objImprovement.ImprovedName, objXmlCritterNode?["translate"]?.InnerText ?? objImprovement.ImprovedName));
            }

            cboSpiritName.BeginUpdate();
            cboSpiritName.DisplayMember = "Name";
            cboSpiritName.ValueMember   = "Value";
            cboSpiritName.DataSource    = lstCritters;

            // Set the control back to its original value.
            cboSpiritName.SelectedValue = strCurrentValue;
            cboSpiritName.EndUpdate();
        }
Ejemplo n.º 2
0
        // Rebuild the list of Spirits/Sprites based on the character's selected Tradition/Stream.
        public void RebuildSpiritList(Tradition objTradition)
        {
            if (objTradition == null)
            {
                return;
            }
            string strCurrentValue = cboSpiritName.SelectedValue?.ToString() ?? _objSpirit.Name;

            XPathNavigator objXmlDocument = _objSpirit.CharacterObject.LoadDataXPath(_objSpirit.EntityType == SpiritType.Spirit
                    ? "traditions.xml"
                    : "streams.xml");

            HashSet <string> lstLimitCategories = new HashSet <string>();

            foreach (Improvement objImprovement in _objSpirit.CharacterObject.Improvements)
            {
                if (objImprovement.ImproveType == Improvement.ImprovementType.LimitSpiritCategory && objImprovement.Enabled)
                {
                    lstLimitCategories.Add(objImprovement.ImprovedName);
                }
            }

            List <ListItem> lstCritters = new List <ListItem>(30);

            if (objTradition.IsCustomTradition)
            {
                string strSpiritCombat       = objTradition.SpiritCombat;
                string strSpiritDetection    = objTradition.SpiritDetection;
                string strSpiritHealth       = objTradition.SpiritHealth;
                string strSpiritIllusion     = objTradition.SpiritIllusion;
                string strSpiritManipulation = objTradition.SpiritManipulation;

                if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritCombat)) && !string.IsNullOrWhiteSpace(strSpiritCombat))
                {
                    XPathNavigator objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = " + strSpiritCombat.CleanXPath() + "]");
                    lstCritters.Add(new ListItem(strSpiritCombat, objXmlCritterNode?.SelectSingleNode("translate")?.Value ?? strSpiritCombat));
                }

                if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritDetection)) && !string.IsNullOrWhiteSpace(strSpiritDetection))
                {
                    XPathNavigator objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = " + strSpiritDetection.CleanXPath() + "]");
                    lstCritters.Add(new ListItem(strSpiritDetection, objXmlCritterNode?.SelectSingleNode("translate")?.Value ?? strSpiritDetection));
                }

                if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritHealth)) && !string.IsNullOrWhiteSpace(strSpiritHealth))
                {
                    XPathNavigator objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = " + strSpiritHealth.CleanXPath() + "]");
                    lstCritters.Add(new ListItem(strSpiritHealth, objXmlCritterNode?.SelectSingleNode("translate")?.Value ?? strSpiritHealth));
                }

                if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritIllusion)) && !string.IsNullOrWhiteSpace(strSpiritIllusion))
                {
                    XPathNavigator objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = " + strSpiritIllusion.CleanXPath() + "]");
                    lstCritters.Add(new ListItem(strSpiritIllusion, objXmlCritterNode?.SelectSingleNode("translate")?.Value ?? strSpiritIllusion));
                }

                if ((lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritManipulation)) && !string.IsNullOrWhiteSpace(strSpiritManipulation))
                {
                    XPathNavigator objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = " + strSpiritManipulation.CleanXPath() + "]");
                    lstCritters.Add(new ListItem(strSpiritManipulation, objXmlCritterNode?.SelectSingleNode("translate")?.Value ?? strSpiritManipulation));
                }
            }
            else
            {
                if (objTradition.GetNode()?.SelectSingleNode("spirits/spirit[. = \"All\"]") != null)
                {
                    if (lstLimitCategories.Count == 0)
                    {
                        foreach (XmlNode objXmlCritterNode in objXmlDocument.Select("/chummer/spirits/spirit"))
                        {
                            string strSpiritName = objXmlCritterNode["name"]?.InnerText;
                            lstCritters.Add(new ListItem(strSpiritName, objXmlCritterNode["translate"]?.InnerText ?? strSpiritName));
                        }
                    }
                    else
                    {
                        foreach (string strSpiritName in lstLimitCategories)
                        {
                            XPathNavigator objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = " + strSpiritName.CleanXPath() + "]");
                            lstCritters.Add(new ListItem(strSpiritName, objXmlCritterNode?.SelectSingleNode("translate")?.Value ?? strSpiritName));
                        }
                    }
                }
                else
                {
                    using (XmlNodeList xmlSpiritList = objTradition.GetNode()?.SelectSingleNode("spirits")?.ChildNodes)
                    {
                        if (xmlSpiritList != null)
                        {
                            foreach (XmlNode objXmlSpirit in xmlSpiritList)
                            {
                                string strSpiritName = objXmlSpirit.InnerText;
                                if (lstLimitCategories.Count == 0 || lstLimitCategories.Contains(strSpiritName))
                                {
                                    XPathNavigator objXmlCritterNode = objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = " + strSpiritName.CleanXPath() + "]");
                                    lstCritters.Add(new ListItem(strSpiritName, objXmlCritterNode?.SelectSingleNode("translate")?.Value ?? strSpiritName));
                                }
                            }
                        }
                    }
                }
            }

            if (_objSpirit.CharacterObject.MAGEnabled || _objSpirit.CharacterObject.RESEnabled)
            {
                // Add any additional Spirits and Sprites the character has Access to through improvements.
                foreach (Improvement objImprovement in _objSpirit.CharacterObject.Improvements)
                {
                    if (((objImprovement.ImproveType == Improvement.ImprovementType.AddSpirit && _objSpirit.CharacterObject.MAGEnabled) ||
                         (objImprovement.ImproveType == Improvement.ImprovementType.AddSprite && _objSpirit.CharacterObject.RESEnabled)) &&
                        !string.IsNullOrEmpty(objImprovement.ImprovedName) && objImprovement.Enabled)
                    {
                        lstCritters.Add(new ListItem(objImprovement.ImprovedName,
                                                     objXmlDocument.SelectSingleNode("/chummer/spirits/spirit[name = " + objImprovement.ImprovedName.CleanXPath() + "]/translate")?.Value
                                                     ?? objImprovement.ImprovedName));
                    }
                }
            }

            cboSpiritName.BeginUpdate();
            cboSpiritName.DataSource    = null;
            cboSpiritName.DataSource    = lstCritters;
            cboSpiritName.DisplayMember = nameof(ListItem.Name);
            cboSpiritName.ValueMember   = nameof(ListItem.Value);

            // Set the control back to its original value.
            cboSpiritName.SelectedValue = strCurrentValue;
            cboSpiritName.EndUpdate();
        }