コード例 #1
0
ファイル: frmCreate.cs プロジェクト: cormanater/chummer5a
        private void tsAddArmorMod_Click(object sender, EventArgs e)
        {
            // Make sure a parent item is selected, then open the Select Accessory window.
            try
            {
                if (treArmor.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectArmor"), LanguageManager.Instance.GetString("MessageTitle_SelectArmor"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectArmor"), LanguageManager.Instance.GetString("MessageTitle_SelectArmor"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (treArmor.SelectedNode.Level > 1)
                treArmor.SelectedNode = treArmor.SelectedNode.Parent;

            // Locate the Armor that is selected in the tree.
            Armor objArmor = _objFunctions.FindArmor(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor);

            // Open the Armor XML file and locate the selected Armor.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml");

            XmlNode objXmlArmor = objXmlDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objArmor.Name + "\"]");

            frmSelectArmorMod frmPickArmorMod = new frmSelectArmorMod(_objCharacter);
            frmPickArmorMod.ArmorCost = objArmor.Cost;
            frmPickArmorMod.AllowedCategories = objArmor.Category + "," + objArmor.Name;
            frmPickArmorMod.CapacityDisplayStyle = objArmor.CapacityDisplayStyle;
            if (objXmlArmor.InnerXml.Contains("<addmodcategory>"))
                frmPickArmorMod.AllowedCategories += "," + objXmlArmor["addmodcategory"].InnerText;

            frmPickArmorMod.ShowDialog(this);

            if (frmPickArmorMod.DialogResult == DialogResult.Cancel)
                return;

            // Locate the selected piece.
            objXmlArmor = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + frmPickArmorMod.SelectedArmorMod + "\"]");

            TreeNode objNode = new TreeNode();
            ArmorMod objMod = new ArmorMod(_objCharacter);
            List<Weapon> lstWeapons = new List<Weapon>();
            List<TreeNode> lstWeaponNodes = new List<TreeNode>();
            int intRating = 0;
            if (Convert.ToInt32(objXmlArmor["maxrating"].InnerText) > 1)
                intRating = frmPickArmorMod.SelectedRating;

            objMod.Create(objXmlArmor, objNode, intRating, lstWeapons, lstWeaponNodes);
            objMod.Parent = objArmor;
            objNode.ContextMenuStrip = cmsArmorMod;
            if (objMod.InternalId == Guid.Empty.ToString())
                return;

            objArmor.ArmorMods.Add(objMod);

            treArmor.SelectedNode.Nodes.Add(objNode);
            treArmor.SelectedNode.Expand();
            treArmor.SelectedNode = objNode;

            // Add any Weapons created by the Mod.
            foreach (Weapon objWeapon in lstWeapons)
                _objCharacter.Weapons.Add(objWeapon);

            foreach (TreeNode objWeaponNode in lstWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }

            UpdateCharacterInfo();
            RefreshSelectedArmor();

            if (frmPickArmorMod.AddAgain)
                tsAddArmorMod_Click(sender, e);
        }
コード例 #2
0
ファイル: frmCareer.cs プロジェクト: Althalusdlg/chummer5a
        private void tsAddArmorMod_Click(object sender, EventArgs e)
        {
            // Make sure a parent item is selected, then open the Select Accessory window.
            try
            {
                if (treArmor.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectArmor"), LanguageManager.Instance.GetString("MessageTitle_SelectArmor"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectArmor"), LanguageManager.Instance.GetString("MessageTitle_SelectArmor"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (treArmor.SelectedNode.Level > 1)
                treArmor.SelectedNode = treArmor.SelectedNode.Parent;

            // Locate the Armor that is selected in the tree.
            Armor objArmor = _objFunctions.FindArmor(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor);

            // Open the Armor XML file and locate the selected Armor.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml");

            XmlNode objXmlArmor = objXmlDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objArmor.Name + "\"]");

            frmSelectArmorMod frmPickArmorMod = new frmSelectArmorMod(_objCharacter, true);
            frmPickArmorMod.ArmorCost = objArmor.Cost;
            frmPickArmorMod.AllowedCategories = objArmor.Category + "," + objArmor.Name;
            frmPickArmorMod.CapacityDisplayStyle = objArmor.CapacityDisplayStyle;
            if (objXmlArmor.InnerXml.Contains("<addmodcategory>"))
                frmPickArmorMod.AllowedCategories += "," + objXmlArmor["addmodcategory"].InnerText;

            frmPickArmorMod.ShowDialog(this);

            if (frmPickArmorMod.DialogResult == DialogResult.Cancel)
                return;

            // Locate the selected piece.
            objXmlArmor = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + frmPickArmorMod.SelectedArmorMod + "\"]");

            TreeNode objNode = new TreeNode();
            ArmorMod objMod = new ArmorMod(_objCharacter);
            List<Weapon> lstWeapons = new List<Weapon>();
            List<TreeNode> lstWeaponNodes = new List<TreeNode>();
            int intRating = 0;
            if (Convert.ToInt32(objXmlArmor["maxrating"].InnerText) > 1)
                intRating = frmPickArmorMod.SelectedRating;

            objMod.Create(objXmlArmor, objNode, intRating, lstWeapons, lstWeaponNodes);
            objMod.Parent = objArmor;
            objNode.ContextMenuStrip = cmsArmorMod;
            if (objMod.InternalId == Guid.Empty.ToString())
                return;

            // Check the item's Cost and make sure the character can afford it.
            int intOriginalCost = objArmor.TotalCost;
            objArmor.ArmorMods.Add(objMod);

            // Do not allow the user to add a new piece of Armor if its Capacity has been reached.
            if (_objOptions.EnforceCapacity && objArmor.CapacityRemaining < 0)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                objArmor.ArmorMods.Remove(objMod);
                if (frmPickArmorMod.AddAgain)
                    tsAddArmorMod_Click(sender, e);
                return;
            }

            int intCost = objArmor.TotalCost - intOriginalCost;
            // Apply a markup if applicable.
            if (frmPickArmorMod.Markup != 0)
            {
                double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo);
                dblCost *= 1 + (Convert.ToDouble(frmPickArmorMod.Markup, GlobalOptions.Instance.CultureInfo) / 100.0);
                intCost = Convert.ToInt32(dblCost);
            }

            // Multiply the cost if applicable.
            if (objMod.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost)
                intCost *= _objOptions.RestrictedCostMultiplier;
            if (objMod.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailForbidden")) && _objOptions.MultiplyForbiddenCost)
                intCost *= _objOptions.ForbiddenCostMultiplier;

            if (!frmPickArmorMod.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    objArmor.ArmorMods.Remove(objMod);
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    // Remove the Improvements created by the Armor Mod.
                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.ArmorMod, objMod.InternalId);
                    if (frmPickArmorMod.AddAgain)
                        tsAddArmorMod_Click(sender, e);

                    return;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseArmorMod") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddArmorMod, objMod.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            treArmor.SelectedNode.Nodes.Add(objNode);
            treArmor.SelectedNode.Expand();
            treArmor.SelectedNode = objNode;

            // Add any Weapons created by the Mod.
            foreach (Weapon objWeapon in lstWeapons)
                _objCharacter.Weapons.Add(objWeapon);

            foreach (TreeNode objWeaponNode in lstWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }

            UpdateCharacterInfo();
            RefreshSelectedArmor();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickArmorMod.AddAgain)
                tsAddArmorMod_Click(sender, e);
        }