Exemplo n.º 1
0
        private void cmdSwapQuality_Click(object sender, EventArgs e)
        {
            // Locate the selected Quality.
            try
            {
                if (treQualities.SelectedNode.Level == 0)
                    return;
            }
            catch
            {
                return;
            }

            Quality objQuality = _objFunctions.FindQuality(treQualities.SelectedNode.Tag.ToString(), _objCharacter.Qualities);

            // Qualities that come from a Metatype cannot be removed.
            if (objQuality.OriginSource == QualitySource.Metatype)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_MetavariantQualitySwap"), LanguageManager.Instance.GetString("MessageTitle_MetavariantQualitySwap"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectQuality frmPickQuality = new frmSelectQuality(_objCharacter);
            frmPickQuality.ForceCategory = objQuality.Type.ToString();
            frmPickQuality.IgnoreQuality = objQuality.Name;
            frmPickQuality.ShowDialog(this);

            // Don't do anything else if the form was canceled.
            if (frmPickQuality.DialogResult == DialogResult.Cancel)
                return;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("qualities.xml");
            XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + frmPickQuality.SelectedQuality + "\"]");

            TreeNode objNode = new TreeNode();
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Quality objNewQuality = new Quality(_objCharacter);

            objNewQuality.Create(objXmlQuality, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes);
            objNode.ContextMenuStrip = cmsQuality;
            if (objQuality.InternalId == Guid.Empty.ToString())
                return;

            bool blnAddItem = true;
            int intKarmaCost = (objNewQuality.BP - objQuality.BP) * _objOptions.KarmaQuality;

            // Make sure the character has enough Karma to pay for the Quality.
            if (objNewQuality.Type == QualityType.Positive)
            {
                if (intKarmaCost > _objCharacter.Karma)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    blnAddItem = false;
                }

                if (blnAddItem)
                {
                    if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_QualitySwap").Replace("{0}", objQuality.DisplayNameShort).Replace("{1}", objNewQuality.DisplayNameShort)))
                        blnAddItem = false;
                }

                if (blnAddItem)
                {
                    // Create the Karma expense.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseSwapPositiveQuality").Replace("{0}", objQuality.DisplayNameShort).Replace("{1}", objNewQuality.DisplayNameShort), ExpenseType.Karma, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Karma -= intKarmaCost;
                }
            }
            else
            {
                // This should only happen when a character is trading up to a less-costly Quality.
                if (intKarmaCost > 0)
                {
                    if (intKarmaCost > _objCharacter.Karma)
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        blnAddItem = false;
                    }

                    if (blnAddItem)
                    {
                        if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_QualitySwap").Replace("{0}", objQuality.Name).Replace("{1}", objNewQuality.Name)))
                            blnAddItem = false;
                    }

                    if (blnAddItem)
                    {
                        // Create the Karma expense.
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseSwapNegativeQuality").Replace("{0}", objQuality.DisplayNameShort).Replace("{1}", objNewQuality.DisplayNameShort), ExpenseType.Karma, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Karma -= intKarmaCost;
                    }
                }
            }

            if (blnAddItem)
            {
                // Add the Quality to the appropriate parent node.
                treQualities.SelectedNode.Remove();
                if (objNewQuality.Type == QualityType.Positive)
                {
                    treQualities.Nodes[0].Nodes.Add(objNode);
                    treQualities.Nodes[0].Expand();
                }
                else
                {
                    treQualities.Nodes[1].Nodes.Add(objNode);
                    treQualities.Nodes[1].Expand();
                }

                // Add any created Weapons to the character.
                foreach (Weapon objWeapon in objWeapons)
                    _objCharacter.Weapons.Add(objWeapon);

                // Create the Weapon Node if one exists.
                foreach (TreeNode objWeaponNode in objWeaponNodes)
                {
                    objWeaponNode.ContextMenuStrip = cmsWeapon;
                    treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                    treWeapons.Nodes[0].Expand();
                }

                // If the new Quality is linked to a Latent source, see if the Quality that is being swapped out is the same as the one the new Quality is linked to.
                // If so, set the character's OverrideSpecialAttributeEssenceLoss to true so that they always start with a Special Attribute value of 1.
                if (objXmlQuality["latentsource"] != null)
                {
                    if (objXmlQuality["latentsource"].InnerText == objQuality.Name)
                        _objCharacter.OverrideSpecialAttributeEssenceLoss = true;
                }

                // Add any additional Qualities that are forced on the character.
                if (objXmlQuality.SelectNodes("addqualities/addquality").Count > 0)
                {
                    foreach (XmlNode objXmlAddQuality in objXmlQuality.SelectNodes("addqualities/addquality"))
                    {
                        XmlNode objXmlSelectedQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlAddQuality.InnerText + "\"]");
                        string strForceValue = "";
                        if (objXmlAddQuality.Attributes["select"] != null)
                            strForceValue = objXmlAddQuality.Attributes["select"].InnerText;
                        bool blnAddQuality = true;

                        // Make sure the character does not yet have this Quality.
                        foreach (Quality objCharacterQuality in _objCharacter.Qualities)
                        {
                            if (objCharacterQuality.Name == objXmlAddQuality.InnerText && objCharacterQuality.Extra == strForceValue)
                            {
                                blnAddQuality = false;
                                break;
                            }
                        }

                        if (blnAddQuality)
                        {
                            TreeNode objAddQualityNode = new TreeNode();
                            List<Weapon> objAddWeapons = new List<Weapon>();
                            List<TreeNode> objAddWeaponNodes = new List<TreeNode>();
                            Quality objAddQuality = new Quality(_objCharacter);
                            objAddQuality.Create(objXmlSelectedQuality, _objCharacter, QualitySource.Selected, objAddQualityNode, objWeapons, objWeaponNodes, strForceValue);
                            objNode.Nodes.Add(objAddQualityNode);
                            objNode.Expand();
                            _objCharacter.Qualities.Add(objAddQuality);

                            // Add any created Weapons to the character.
                            foreach (Weapon objWeapon in objAddWeapons)
                                _objCharacter.Weapons.Add(objWeapon);

                            // Create the Weapon Node if one exists.
                            foreach (TreeNode objWeaponNode in objAddWeaponNodes)
                            {
                                objWeaponNode.ContextMenuStrip = cmsWeapon;
                                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                                treWeapons.Nodes[0].Expand();
                            }
                        }
                    }
                }

                // Remove any Improvements for the old Quality.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Quality, objQuality.InternalId);
                _objCharacter.Qualities.Remove(objQuality);

                // Remove any Weapons created by the old Quality if applicable.
                if (objQuality.WeaponID != Guid.Empty.ToString())
                {
                    // Remove the Weapon from the TreeView.
                    TreeNode objRemoveNode = new TreeNode();
                    foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                    {
                        if (objWeaponNode.Tag.ToString() == objQuality.WeaponID)
                            objRemoveNode = objWeaponNode;
                    }
                    treWeapons.Nodes.Remove(objRemoveNode);

                    // Remove the Weapon from the Character.
                    Weapon objRemoveWeapon = new Weapon(_objCharacter);
                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                    {
                        if (objWeapon.InternalId == objQuality.WeaponID)
                            objRemoveWeapon = objWeapon;
                    }
                    _objCharacter.Weapons.Remove(objRemoveWeapon);
                }

                // Add the new Quality to the character.
                _objCharacter.Qualities.Add(objNewQuality);
            }

            UpdateMentorSpirits();
            UpdateCharacterInfo();
            RefreshContacts();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Exemplo n.º 2
0
        private void cmdAddQuality_Click(object sender, EventArgs e)
        {
            frmSelectQuality frmPickQuality = new frmSelectQuality(_objCharacter);
            frmPickQuality.ShowDialog(this);

            // Don't do anything else if the form was canceled.
            if (frmPickQuality.DialogResult == DialogResult.Cancel)
                return;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("qualities.xml");
            XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + frmPickQuality.SelectedQuality + "\"]");
            TreeNode objNode = new TreeNode();
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Quality objQuality = new Quality(_objCharacter);

            objQuality.Create(objXmlQuality, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes);
            objNode.ContextMenuStrip = cmsQuality;
            if (objQuality.InternalId == Guid.Empty.ToString())
                return;

            if (frmPickQuality.FreeCost)
                objQuality.BP = 0;

            // If the item being checked would cause the limit of 25 BP spent on Positive Qualities to be exceed, do not let it be checked and display a message.
            string strAmount = "";
            int intMaxQualityAmount = 0;
            strAmount = _objCharacter.GameplayOptionQualityLimit.ToString() + " " + LanguageManager.Instance.GetString("String_Karma");
            intMaxQualityAmount = _objCharacter.GameplayOptionQualityLimit;

            // Make sure that adding the Quality would not cause the character to exceed their BP limits.
            int intBP = 0;
            bool blnAddItem = true;

            // Add the cost of the Quality that is being added.
            if (objQuality.ContributeToLimit)
                intBP += objQuality.BP;

            if (objQuality.Type == QualityType.Negative)
            {
                // Calculate the cost of the current Negative Qualities.
                foreach (Quality objCharacterQuality in _objCharacter.Qualities)
                {
                    if (objCharacterQuality.Type == QualityType.Negative && objCharacterQuality.ContributeToLimit)
                        intBP += objCharacterQuality.BP;
                }

                // Include the BP used by Enemies.
                if (lblEnemiesBP.Text.Contains(LanguageManager.Instance.GetString("String_BP")))
                    intBP += int.Parse(lblEnemiesBP.Text.Replace(LanguageManager.Instance.GetString("String_Karma"), ""));
                else
                    intBP += int.Parse(lblEnemiesBP.Text.Replace(" " + LanguageManager.Instance.GetString("String_Karma"), ""));

                // Include the amount from Free Negative Quality BP cost Improvements.
                intBP -= (_objImprovementManager.ValueOf(Improvement.ImprovementType.FreeNegativeQualities) * _objOptions.KarmaQuality);

                // Check if adding this Quality would put the character over their limit.
                if (!_objOptions.ExceedNegativeQualities)
                {
                    if (intBP < (intMaxQualityAmount * -1) && !_objCharacter.IgnoreRules)
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_NegativeQualityLimit").Replace("{0}", strAmount), LanguageManager.Instance.GetString("MessageTitle_NegativeQualityLimit"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        blnAddItem = false;
                    }
                    if (_objCharacter.MetatypeBP < 0)
                    {
                        if ((intBP + _objCharacter.MetatypeBP) < (intMaxQualityAmount * -1) && !_objCharacter.IgnoreRules)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_NegativeQualityAndMetatypeLimit").Replace("{0}", strAmount), LanguageManager.Instance.GetString("MessageTitle_NegativeQualityLimit"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            blnAddItem = false;
                        }
                    }
                    {

                    }
                }
            }
            else
            {
                // Calculate the cost of the current Positive Qualities.
                foreach (Quality objCharacterQuality in _objCharacter.Qualities)
                {
                    if (objCharacterQuality.Type == QualityType.Positive && objCharacterQuality.ContributeToLimit)
                        intBP += objCharacterQuality.BP;
                }
                if (_objCharacter.BuildMethod == CharacterBuildMethod.Karma)
                    intBP *= _objOptions.KarmaQuality;

                // Include the amount from Free Negative Quality BP cost Improvements.
                intBP -= (_objImprovementManager.ValueOf(Improvement.ImprovementType.FreePositiveQualities) * _objOptions.KarmaQuality);

                // Check if adding this Quality would put the character over their limit.
                if (!_objOptions.ExceedPositiveQualities)
                {
                    if (intBP > intMaxQualityAmount && !_objCharacter.IgnoreRules)
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_PositiveQualityLimit").Replace("{0}", strAmount), LanguageManager.Instance.GetString("MessageTitle_PositiveQualityLimit"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        blnAddItem = false;
                    }
                }
            }

            if (blnAddItem)
            {
                // Add the Quality to the appropriate parent node.
                if (objQuality.Type == QualityType.Positive)
                {
                    treQualities.Nodes[0].Nodes.Add(objNode);
                    treQualities.Nodes[0].Expand();
                }
                else
                {
                    treQualities.Nodes[1].Nodes.Add(objNode);
                    treQualities.Nodes[1].Expand();
                }
                _objCharacter.Qualities.Add(objQuality);

                // Add any created Weapons to the character.
                foreach (Weapon objWeapon in objWeapons)
                    _objCharacter.Weapons.Add(objWeapon);

                // Create the Weapon Node if one exists.
                foreach (TreeNode objWeaponNode in objWeaponNodes)
                {
                    objWeaponNode.ContextMenuStrip = cmsWeapon;
                    treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                    treWeapons.Nodes[0].Expand();
                }

                // Add any additional Qualities that are forced on the character.
                if (objXmlQuality.SelectNodes("addqualities/addquality").Count > 0)
                {
                    foreach (XmlNode objXmlAddQuality in objXmlQuality.SelectNodes("addqualities/addquality"))
                    {
                        XmlNode objXmlSelectedQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlAddQuality.InnerText + "\"]");
                        Quality objSubQuality = AddQuality(objXmlAddQuality, objXmlSelectedQuality, objWeapons, objWeaponNodes);
                        if (objSubQuality != null)
                            {
                            _objCharacter.Qualities.Add(objSubQuality);
                            }
                        }
                }

                // Add any Critter Powers that are gained through the Quality (Infected).
                if (objXmlQuality.SelectNodes("powers/power").Count > 0)
                {
                    objXmlDocument = XmlManager.Instance.Load("critterpowers.xml");
                    foreach (XmlNode objXmlPower in objXmlQuality.SelectNodes("powers/power"))
                    {
                        XmlNode objXmlCritterPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower.InnerText + "\"]");
                        TreeNode objPowerNode = new TreeNode();
                        CritterPower objPower = new CritterPower(_objCharacter);
                        string strForcedValue = "";
                        int intRating = 0;

                        if (objXmlPower.Attributes["rating"] != null)
                            intRating = Convert.ToInt32(objXmlPower.Attributes["rating"].InnerText);
                        if (objXmlPower.Attributes["select"] != null)
                            strForcedValue = objXmlPower.Attributes["select"].InnerText;

                        objPower.Create(objXmlCritterPower, _objCharacter, objPowerNode, intRating, strForcedValue);
                        _objCharacter.CritterPowers.Add(objPower);

                        if (objPower.Category != "Weakness")
                        {
                            treCritterPowers.Nodes[0].Nodes.Add(objPowerNode);
                            treCritterPowers.Nodes[0].Expand();
                        }
                        else
                        {
                            treCritterPowers.Nodes[1].Nodes.Add(objPowerNode);
                            treCritterPowers.Nodes[1].Expand();
                        }
                    }
                }
            }
            else
            {
                // If the Quality could not be added, remove the Improvements that were added during the Quality Creation process.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Quality, objQuality.InternalId);
            }

            // If the Quality is a mentor spirit, add any qualities particular to the mentor spirit.
            if (objQuality.Name == "Mentor Spirit")
            {
                XmlDocument objXmlMentors = XmlManager.Instance.Load("mentors.xml");
                XmlNode objXmlMentor = objXmlMentors.SelectSingleNode("/chummer/mentors/mentor[name = \"" + objQuality.Extra + "\"]");
                XmlNode objXmlAddQualities = objXmlMentor["addqualities"];

                // If there are additional qualities
                if (objXmlAddQualities != null)
                {
                    foreach (XmlNode objXmlAddQuality in objXmlAddQualities.ChildNodes)
                    {
                        XmlNode objXmlMentorQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlAddQuality.InnerText + "\"]");

                        TreeNode objMentorNode = new TreeNode();
                        List<Weapon> objMentorWeapons = new List<Weapon>();
                        List<TreeNode> objMentorWeaponNodes = new List<TreeNode>();
                        Quality objSpiritQuality = new Quality(_objCharacter);
                        string strExtra = "";
                        if (objXmlAddQuality.Attributes["select"] != null)
                        {
                            strExtra = objXmlAddQuality.Attributes["select"].InnerText.ToString();
                            objSpiritQuality.Create(objXmlMentorQuality, _objCharacter, QualitySource.Selected, objMentorNode, objMentorWeapons, objMentorWeaponNodes, strExtra);
                        }
                        else
                            objSpiritQuality.Create(objXmlMentorQuality, _objCharacter, QualitySource.Selected, objMentorNode, objMentorWeapons, objMentorWeaponNodes);

                        objSpiritQuality.BP = 0;

                        // Add the quality to the character
                        if (objSpiritQuality.Type == QualityType.Positive)
                        {
                            treQualities.Nodes[0].Nodes.Add(objMentorNode);
                            treQualities.Nodes[0].Expand();
                        }
                        else
                        {
                            treQualities.Nodes[1].Nodes.Add(objMentorNode);
                            treQualities.Nodes[1].Expand();
                        }
                        _objCharacter.Qualities.Add(objSpiritQuality);
                    }
                }
            }

            treQualities.SortCustom();
            UpdateMentorSpirits();
            UpdateCharacterInfo();
            RefreshMartialArts();
            RefreshPowers();
            RefreshContacts();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickQuality.AddAgain)
                cmdAddQuality_Click(sender, e);
        }
Exemplo n.º 3
0
        private void cmdAddQuality_Click(object sender, EventArgs e)
        {
            frmSelectQuality frmPickQuality = new frmSelectQuality(_objCharacter);
            frmPickQuality.ShowDialog(this);

            // Don't do anything else if the form was canceled.
            if (frmPickQuality.DialogResult == DialogResult.Cancel)
                return;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("qualities.xml");
            XmlNode objXmlQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + frmPickQuality.SelectedQuality + "\"]");

            TreeNode objNode = new TreeNode();
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Quality objQuality = new Quality(_objCharacter);

            objQuality.Create(objXmlQuality, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes);
            objNode.ContextMenuStrip = cmsQuality;
            if (objQuality.InternalId == Guid.Empty.ToString())
                return;

            if (frmPickQuality.FreeCost)
                objQuality.BP = 0;

            bool blnAddItem = true;
            int intKarmaCost = objQuality.BP * _objOptions.KarmaQuality;
            if (!_objCharacter.Options.DontDoubleQualities)
                intKarmaCost *= 2;

            // Make sure the character has enough Karma to pay for the Quality.
            if (objQuality.Type == QualityType.Positive)
            {
                if (intKarmaCost > _objCharacter.Karma)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    blnAddItem = false;
                }

                if (blnAddItem && !frmPickQuality.FreeCost && objQuality.ContributeToBP)
                {
                    if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSpend").Replace("{0}", objQuality.DisplayNameShort).Replace("{1}", intKarmaCost.ToString())))
                        blnAddItem = false;
                }

                if (blnAddItem && objQuality.ContributeToBP)
                {
                    // Create the Karma expense.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseAddPositiveQuality") + " " + objQuality.DisplayNameShort, ExpenseType.Karma, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Karma -= intKarmaCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateKarma(KarmaExpenseType.AddQuality, objQuality.InternalId);
                    objExpense.Undo = objUndo;
                }
            }
            else
            {
                if (MessageBox.Show(LanguageManager.Instance.GetString("Message_AddNegativeQuality"), LanguageManager.Instance.GetString("MessageTitle_AddNegativeQuality"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    blnAddItem = false;

                if (blnAddItem)
                {
                    // Create a Karma Expense for the Negative Quality.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(0, LanguageManager.Instance.GetString("String_ExpenseAddNegativeQuality") + " " + objQuality.DisplayNameShort, ExpenseType.Karma, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateKarma(KarmaExpenseType.AddQuality, objQuality.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            if (blnAddItem)
            {
                // Add the Quality to the appropriate parent node.
                if (objQuality.Type == QualityType.Positive)
                {
                    treQualities.Nodes[0].Nodes.Add(objNode);
                    treQualities.Nodes[0].Expand();
                }
                else
                {
                    treQualities.Nodes[1].Nodes.Add(objNode);
                    treQualities.Nodes[1].Expand();
                }
                _objCharacter.Qualities.Add(objQuality);

                // Add any created Weapons to the character.
                foreach (Weapon objWeapon in objWeapons)
                    _objCharacter.Weapons.Add(objWeapon);

                // Create the Weapon Node if one exists.
                foreach (TreeNode objWeaponNode in objWeaponNodes)
                {
                    objWeaponNode.ContextMenuStrip = cmsWeapon;
                    treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                    treWeapons.Nodes[0].Expand();
                }

                // Add any additional Qualities that are forced on the character.
                if (objXmlQuality.SelectNodes("addqualities/addquality").Count > 0)
                {
                    foreach (XmlNode objXmlAddQuality in objXmlQuality.SelectNodes("addqualities/addquality"))
                    {
                        XmlNode objXmlSelectedQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlAddQuality.InnerText + "\"]");
                        string strForceValue = "";
                        if (objXmlAddQuality.Attributes["select"] != null)
                            strForceValue = objXmlAddQuality.Attributes["select"].InnerText;
                        bool blnAddQuality = true;

                        // Make sure the character does not yet have this Quality.
                        foreach (Quality objCharacterQuality in _objCharacter.Qualities)
                        {
                            if (objCharacterQuality.Name == objXmlAddQuality.InnerText && objCharacterQuality.Extra == strForceValue)
                            {
                                blnAddQuality = false;
                                break;
                            }
                        }

                        if (blnAddQuality)
                        {
                            TreeNode objAddQualityNode = new TreeNode();
                            List<Weapon> objAddWeapons = new List<Weapon>();
                            List<TreeNode> objAddWeaponNodes = new List<TreeNode>();
                            Quality objAddQuality = new Quality(_objCharacter);
                            objAddQuality.Create(objXmlSelectedQuality, _objCharacter, QualitySource.Selected, objAddQualityNode, objAddWeapons, objAddWeaponNodes, strForceValue);
                            objNode.Nodes.Add(objAddQualityNode);
                            objNode.Expand();
                            _objCharacter.Qualities.Add(objAddQuality);

                            // Add any created Weapons to the character.
                            foreach (Weapon objWeapon in objAddWeapons)
                                _objCharacter.Weapons.Add(objWeapon);

                            // Create the Weapon Node if one exists.
                            foreach (TreeNode objWeaponNode in objAddWeaponNodes)
                            {
                                objWeaponNode.ContextMenuStrip = cmsWeapon;
                                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                                treWeapons.Nodes[0].Expand();
                            }
                        }
                    }
                }

                // Add any Critter Powers that are gained through the Quality (Infected).
                if (objXmlQuality.SelectNodes("powers/power").Count > 0)
                {
                    objXmlDocument = XmlManager.Instance.Load("critterpowers.xml");
                    foreach (XmlNode objXmlPower in objXmlQuality.SelectNodes("powers/power"))
                    {
                        XmlNode objXmlCritterPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower.InnerText + "\"]");
                        TreeNode objPowerNode = new TreeNode();
                        CritterPower objPower = new CritterPower(_objCharacter);
                        string strForcedValue = "";
                        int intRating = 0;

                        if (objXmlPower.Attributes["rating"] != null)
                            intRating = Convert.ToInt32(objXmlPower.Attributes["rating"].InnerText);
                        if (objXmlPower.Attributes["select"] != null)
                            strForcedValue = objXmlPower.Attributes["select"].InnerText;

                        objPower.Create(objXmlCritterPower, _objCharacter, objPowerNode, intRating, strForcedValue);
                        _objCharacter.CritterPowers.Add(objPower);

                        if (objPower.Category != "Weakness")
                        {
                            treCritterPowers.Nodes[0].Nodes.Add(objPowerNode);
                            treCritterPowers.Nodes[0].Expand();
                        }
                        else
                        {
                            treCritterPowers.Nodes[1].Nodes.Add(objPowerNode);
                            treCritterPowers.Nodes[1].Expand();
                        }
                    }
                }
            }
            else
            {
                // Remove the Improvements created by the Create method.
                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Quality, objQuality.InternalId);
            }

            // If the Quality is a mentor spirit, add any qualities particular to the mentor spirit.
            if (objQuality.Name == "Mentor Spirit")
            {
                XmlDocument objXmlMentors = XmlManager.Instance.Load("mentors.xml");
                XmlNode objXmlMentor = objXmlMentors.SelectSingleNode("/chummer/mentors/mentor[name = \"" + objQuality.Extra + "\"]");
                XmlNode objXmlAddQualities = objXmlMentor["addqualities"];

                // If there are additional qualities
                if (objXmlAddQualities != null)
                {
                    foreach (XmlNode objXmlAddQuality in objXmlAddQualities.ChildNodes)
                    {
                        XmlNode objXmlMentorQuality = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlAddQuality.InnerText + "\"]");

                        TreeNode objMentorNode = new TreeNode();
                        List<Weapon> objMentorWeapons = new List<Weapon>();
                        List<TreeNode> objMentorWeaponNodes = new List<TreeNode>();
                        Quality objSpiritQuality = new Quality(_objCharacter);
                        string strExtra = "";
                        if (objXmlAddQuality.Attributes["select"].InnerText.ToString().Length > 0)
                        {
                            strExtra = objXmlAddQuality.Attributes["select"].InnerText.ToString();
                            objSpiritQuality.Create(objXmlMentorQuality, _objCharacter, QualitySource.Selected, objMentorNode, objMentorWeapons, objMentorWeaponNodes, strExtra);
                        }
                        else
                            objSpiritQuality.Create(objXmlMentorQuality, _objCharacter, QualitySource.Selected, objMentorNode, objMentorWeapons, objMentorWeaponNodes);

                        objSpiritQuality.BP = 0;

                        // Add the quality to the character
                        if (objSpiritQuality.Type == QualityType.Positive)
                        {
                            treQualities.Nodes[0].Nodes.Add(objMentorNode);
                            treQualities.Nodes[0].Expand();
                        }
                        else
                        {
                            treQualities.Nodes[1].Nodes.Add(objMentorNode);
                            treQualities.Nodes[1].Expand();
                        }
                        _objCharacter.Qualities.Add(objSpiritQuality);
                    }
                }
            }

            _objFunctions.SortTree(treQualities);
            UpdateMentorSpirits();
            UpdateCharacterInfo();
            RefreshPowers();
            RefreshContacts();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickQuality.AddAgain)
                cmdAddQuality_Click(sender, e);
        }