Пример #1
0
        private void tsMetamagicAddEnhancement_Click(object sender, EventArgs e)
        {
            if (treMetamagic.SelectedNode.Level != 0)
                return;

            int intGrade = 0;
            foreach (InitiationGrade objGrade in _objCharacter.InitiationGrades)
            {
                if (objGrade.InternalId == treMetamagic.SelectedNode.Tag.ToString())
                {
                    intGrade = objGrade.Grade;
                    break;
                }
            }
            frmSelectArt frmPickArt = new frmSelectArt(_objCharacter);
            frmPickArt.WindowMode = frmSelectArt.Mode.Enhancement;
            frmPickArt.ShowDialog(this);

            // Make sure a value was selected.
            if (frmPickArt.DialogResult == DialogResult.Cancel)
                return;

            string strEnhancement = frmPickArt.SelectedItem;

            XmlDocument objXmlDocument = new XmlDocument();
            XmlNode objXmlArt;

            TreeNode objNode = new TreeNode();
            Enhancement objEnhancement = new Enhancement(_objCharacter);
            Improvement.ImprovementSource objSource;

            objXmlDocument = XmlManager.Instance.Load("powers.xml");
            objXmlArt = objXmlDocument.SelectSingleNode("/chummer/enhancements/enhancement[name = \"" + strEnhancement + "\"]");
            objSource = Improvement.ImprovementSource.Initiation;

            // Find the associated Power
            string strPower = objXmlArt["power"].InnerText.ToString();

            objEnhancement.Create(objXmlArt, _objCharacter, objNode, objSource);
            objEnhancement.Grade = intGrade;
            objNode.ContextMenuStrip = cmsInitiationNotes;
            if (objEnhancement.InternalId == Guid.Empty.ToString())
                return;

            Power objPower = new Power(_objCharacter);
            bool blnPowerFound = false;
            foreach (Power objExistingPower in _objCharacter.Powers)
            {
                if (objExistingPower.Name == strPower)
                {
                    objPower = objExistingPower;
                    objPower.Enhancements.Add(objEnhancement);
                    blnPowerFound = true;
                    break;
                }
            }

            if (!blnPowerFound)
            {
                // Add it to the character instead
                _objCharacter.Enhancements.Add(objEnhancement);
            }

            treMetamagic.SelectedNode.Nodes.Add(objNode);
            treMetamagic.SelectedNode.Expand();

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Пример #2
0
        private void tsMetamagicAddEnhancement_Click(object sender, EventArgs e)
        {
            bool blnPayWithKarma = false;
            string strType = "";

            if (treMetamagic.SelectedNode.Level != 0)
                return;

            int intGrade = 0;
            foreach (InitiationGrade objGrade in _objCharacter.InitiationGrades)
            {
                if (objGrade.InternalId == treMetamagic.SelectedNode.Tag.ToString())
                {
                    intGrade = objGrade.Grade;
                    break;
                }
            }

            blnPayWithKarma = true;
            if (blnPayWithKarma && _objCharacter.Karma < _objOptions.KarmaSpell)
            {
                // Make sure the Karma expense would not put them over the limit.
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseSpend").Replace("{0}", LanguageManager.Instance.GetString("String_Enhancement")).Replace("{1}", _objOptions.KarmaSpell.ToString())))
                return;

            frmSelectArt frmPickArt = new frmSelectArt(_objCharacter);
            frmPickArt.WindowMode = frmSelectArt.Mode.Enhancement;
            frmPickArt.ShowDialog(this);

            // Make sure a value was selected.
            if (frmPickArt.DialogResult == DialogResult.Cancel)
                return;

            string strEnhancement = frmPickArt.SelectedItem;

            XmlDocument objXmlDocument = new XmlDocument();
            XmlNode objXmlArt;

            TreeNode objNode = new TreeNode();
            Enhancement objEnhancement = new Enhancement(_objCharacter);
            Improvement.ImprovementSource objSource;

            objXmlDocument = XmlManager.Instance.Load("powers.xml");
            objXmlArt = objXmlDocument.SelectSingleNode("/chummer/enhancements/enhancement[name = \"" + strEnhancement + "\"]");
            objSource = Improvement.ImprovementSource.Initiation;

            // Find the associated Power
            string strPower = objXmlArt["power"].InnerText.ToString();

            objEnhancement.Create(objXmlArt, _objCharacter, objNode, objSource);
            objEnhancement.Grade = intGrade;
            objNode.ContextMenuStrip = cmsInitiationNotes;
            if (objEnhancement.InternalId == Guid.Empty.ToString())
                return;

            Power objPower = new Power(_objCharacter);
            bool blnPowerFound = false;
            foreach (Power objExistingPower in _objCharacter.Powers)
            {
                if (objExistingPower.Name == strPower)
                {
                    objPower = objExistingPower;
                    objPower.Enhancements.Add(objEnhancement);
                    blnPowerFound = true;
                    break;
                }
            }

            if (!blnPowerFound)
            {
                // Add it to the character instead
                _objCharacter.Enhancements.Add(objEnhancement);
            }

            if (blnPayWithKarma)
            {
                // Create the Expense Log Entry.
                ExpenseLogEntry objEntry = new ExpenseLogEntry();
                objEntry.Create(_objOptions.KarmaEnhancement * -1, strType + " " + frmPickArt.SelectedItem, ExpenseType.Karma, DateTime.Now);
                _objCharacter.ExpenseEntries.Add(objEntry);

                ExpenseUndo objUndo = new ExpenseUndo();
                objUndo.CreateKarma(KarmaExpenseType.AddSpell, objEnhancement.InternalId);
                objEntry.Undo = objUndo;

                // Adjust the character's Karma total.
                _objCharacter.Karma -= _objOptions.KarmaEnhancement;
            }

            treMetamagic.SelectedNode.Nodes.Add(objNode);
            treMetamagic.SelectedNode.Expand();

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }