/// <summary>
        /// Locate a Weapon Accessory within the character's Vehicles.
        /// </summary>
        /// <param name="strGuid">InternalId of the Weapon Accessory to find.</param>
        /// <param name="lstVehicles">List of Vehicles to search.</param>
        public static WeaponAccessory FindVehicleWeaponAccessory(this IEnumerable <Vehicle> lstVehicles, string strGuid)
        {
            if (!string.IsNullOrWhiteSpace(strGuid) && !strGuid.IsEmptyGuid())
            {
                foreach (Vehicle objVehicle in lstVehicles)
                {
                    WeaponAccessory objReturn = objVehicle.Weapons.FindWeaponAccessory(strGuid);
                    if (objReturn != null)
                    {
                        return(objReturn);
                    }

                    foreach (WeaponMount objMod in objVehicle.WeaponMounts)
                    {
                        objReturn = objMod.Weapons.FindWeaponAccessory(strGuid);
                        if (objReturn != null)
                        {
                            return(objReturn);
                        }
                    }

                    foreach (VehicleMod objMod in objVehicle.Mods)
                    {
                        objReturn = objMod.Weapons.FindWeaponAccessory(strGuid);
                        if (objReturn != null)
                        {
                            return(objReturn);
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        public void CreateAllWeaponAccessoriesTest()
        {
            // Create a new Human character.
            Character objCharacter = new Character();

            objCharacter.LoadMetatype(Guid.Parse("e28e7075-f635-4c02-937c-e4fc61c51602"));

            TreeNode objNode = new TreeNode();

            XmlDocument objXmlDocument = XmlManager.Instance.Load("weapons.xml");

            foreach (XmlNode objXmlNode in objXmlDocument.SelectNodes("/chummer/accessories/accessory"))
            {
                WeaponAccessory objAccessory = new WeaponAccessory(objCharacter);
                objAccessory.Create(objXmlNode, objNode, "Barrel");
            }
        }
Exemplo n.º 3
0
        private void tsWeaponAddAccessory_Click(object sender, EventArgs e)
        {
            // Make sure a parent item is selected, then open the Select Accessory window.
            try
            {
                if (treWeapons.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectWeaponAccessory"), LanguageManager.Instance.GetString("MessageTitle_SelectWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectWeaponAccessory"), LanguageManager.Instance.GetString("MessageTitle_SelectWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Locate the Weapon that is selected in the Tree.
            Weapon objWeapon = (Weapon)_objFunctions.FindEquipment(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, typeof(Weapon));

            // Accessories cannot be added to Cyberweapons.
            if (objWeapon.Category.StartsWith("Cyberware"))
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CyberweaponNoAccessory"), LanguageManager.Instance.GetString("MessageTitle_CyberweaponNoAccessory"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

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

            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + objWeapon.ExternalId + "\"]");

            frmSelectWeaponAccessory frmPickWeaponAccessory = new frmSelectWeaponAccessory(_objCharacter);

            if (objXmlWeapon == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Make sure the Weapon allows Accessories to be added to it.
            if (!Convert.ToBoolean(objXmlWeapon["allowaccessory"].InnerText))
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                XmlNodeList objXmlMountList = objXmlWeapon.SelectNodes("accessorymounts/mount");
                string strMounts = "";
                foreach (XmlNode objXmlMount in objXmlMountList)
                    strMounts += objXmlMount.InnerText + "/";

                frmPickWeaponAccessory.AllowedMounts = strMounts;
            }

            frmPickWeaponAccessory.WeaponCost = objWeapon.Cost;
            frmPickWeaponAccessory.AccessoryMultiplier = objWeapon.AccessoryMultiplier;
            frmPickWeaponAccessory.ShowDialog();

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

            // Locate the selected piece.
            objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + frmPickWeaponAccessory.SelectedAccessory + "\"]");

            TreeNode objNode = new TreeNode();
            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
            objAccessory.Create(objXmlWeapon, objNode, frmPickWeaponAccessory.SelectedMount);
            objAccessory.Parent = objWeapon;
            objWeapon.WeaponAccessories.Add(objAccessory);

            objNode.ContextMenuStrip = cmsWeaponAccessory;
            treWeapons.SelectedNode.Nodes.Add(objNode);
            treWeapons.SelectedNode.Expand();

            UpdateCharacterInfo();
            RefreshSelectedWeapon();

            if (frmPickWeaponAccessory.AddAgain)
                tsWeaponAddAccessory_Click(sender, e);
        }
        /// <summary>
        /// Locate a piece of Gear within the character's Vehicles.
        /// </summary>
        /// <param name="strGuid">InternalId of the Gear to find.</param>
        /// <param name="lstVehicles">List of Vehicles to search.</param>
        /// <param name="objFoundVehicle">Vehicle that the Gear was found in.</param>
        /// <param name="objFoundWeaponAccessory">Weapon Accessory that the Gear was found in.</param>
        /// <param name="objFoundCyberware">Cyberware that the Gear was found in.</param>
        public static Gear FindVehicleGear(this IEnumerable <Vehicle> lstVehicles, string strGuid, out Vehicle objFoundVehicle, out WeaponAccessory objFoundWeaponAccessory, out Cyberware objFoundCyberware)
        {
            if (!string.IsNullOrEmpty(strGuid) && !strGuid.IsEmptyGuid())
            {
                foreach (Vehicle objVehicle in lstVehicles)
                {
                    Gear objReturn = objVehicle.Gear.DeepFindById(strGuid);
                    if (!string.IsNullOrEmpty(objReturn?.Name))
                    {
                        objFoundVehicle         = objVehicle;
                        objFoundWeaponAccessory = null;
                        objFoundCyberware       = null;
                        return(objReturn);
                    }

                    // Look for any Gear that might be attached to this Vehicle through Weapon Accessories or Cyberware.
                    foreach (VehicleMod objMod in objVehicle.Mods)
                    {
                        // Weapon Accessories.
                        objReturn = objMod.Weapons.FindWeaponGear(strGuid, out WeaponAccessory objAccessory);

                        if (!string.IsNullOrEmpty(objReturn?.Name))
                        {
                            objFoundVehicle         = objVehicle;
                            objFoundWeaponAccessory = objAccessory;
                            objFoundCyberware       = null;
                            return(objReturn);
                        }

                        // Cyberware.
                        objReturn = objMod.Cyberware.FindCyberwareGear(strGuid, out Cyberware objCyberware);

                        if (!string.IsNullOrEmpty(objReturn?.Name))
                        {
                            objFoundVehicle         = objVehicle;
                            objFoundWeaponAccessory = null;
                            objFoundCyberware       = objCyberware;
                            return(objReturn);
                        }
                    }
                }
            }

            objFoundVehicle         = null;
            objFoundWeaponAccessory = null;
            objFoundCyberware       = null;
            return(null);
        }
Exemplo n.º 5
0
        private void tsWeaponAddAccessory_Click(object sender, EventArgs e)
        {
            // Make sure a parent item is selected, then open the Select Accessory window.
            try
            {
                if (treWeapons.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectWeaponAccessory"), LanguageManager.Instance.GetString("MessageTitle_SelectWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectWeaponAccessory"), LanguageManager.Instance.GetString("MessageTitle_SelectWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Locate the Weapon that is selected in the Tree.
            Weapon objWeapon = _objFunctions.FindWeapon(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);

            // Accessories cannot be added to Cyberweapons.
            if (objWeapon.Cyberware)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CyberweaponNoAccessory"), LanguageManager.Instance.GetString("MessageTitle_CyberweaponNoAccessory"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

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

            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objWeapon.Name + "\"]");

            frmSelectWeaponAccessory frmPickWeaponAccessory = new frmSelectWeaponAccessory(_objCharacter);

            if (objXmlWeapon == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotFindWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

			// Make sure the Weapon allows Accessories to be added to it.
			bool blnAllowAccessories = false;
			if (objXmlWeapon["allowaccessory"] != null)
			{
				blnAllowAccessories = Convert.ToBoolean(objXmlWeapon["allowaccessory"].InnerText);
			}
            if (!blnAllowAccessories)
			{
				MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
				return;
			}
			else
			{
				XmlNodeList objXmlMountList = objXmlWeapon.SelectNodes("accessorymounts/mount");
				string strMounts = "";
				foreach (XmlNode objXmlMount in objXmlMountList)
				{
					bool blnFound = false;
					foreach (WeaponAccessory objMod in objWeapon.WeaponAccessories)
					{
						if (objMod.Mount == objXmlMount.InnerText)
						{
							blnFound = true;
						}
					}
					if (!blnFound)
					{
						strMounts += objXmlMount.InnerText + "/";
					}
				}

				// Remove the trailing /
				if (strMounts != "" && strMounts.Contains('/'))
					strMounts = strMounts.Substring(0, strMounts.Length - 1);

				frmPickWeaponAccessory.AllowedMounts = strMounts;
			}

			frmPickWeaponAccessory.WeaponCost = objWeapon.Cost;
			frmPickWeaponAccessory.AccessoryMultiplier = objWeapon.AccessoryMultiplier;
			frmPickWeaponAccessory.ShowDialog();

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

			// Locate the selected piece.
			objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + frmPickWeaponAccessory.SelectedAccessory + "\"]");

            TreeNode objNode = new TreeNode();
            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
            objAccessory.Create(objXmlWeapon, objNode, frmPickWeaponAccessory.SelectedMount,Convert.ToInt32(frmPickWeaponAccessory.SelectedRating));
            objAccessory.Parent = objWeapon;

            if (objAccessory.Cost.StartsWith("Variable"))
            {
                int intMin = 0;
                int intMax = 0;
                string strCost = objAccessory.Cost.Replace("Variable(", string.Empty).Replace(")", string.Empty);
                if (strCost.Contains("-"))
                {
                    string[] strValues = strCost.Split('-');
                    intMin = Convert.ToInt32(strValues[0]);
                    intMax = Convert.ToInt32(strValues[1]);
                }
                else
                    intMin = Convert.ToInt32(strCost.Replace("+", string.Empty));

                if (intMin != 0 || intMax != 0)
                {
                    frmSelectNumber frmPickNumber = new frmSelectNumber();
                    if (intMax == 0)
                        intMax = 1000000;
                    frmPickNumber.Minimum = intMin;
                    frmPickNumber.Maximum = intMax;
                    frmPickNumber.Description = LanguageManager.Instance.GetString("String_SelectVariableCost").Replace("{0}", objAccessory.DisplayNameShort);
                    frmPickNumber.AllowCancel = false;
                    frmPickNumber.ShowDialog();
                    objAccessory.Cost = frmPickNumber.SelectedValue.ToString();
                }
            }

            objWeapon.WeaponAccessories.Add(objAccessory);

            objNode.ContextMenuStrip = cmsWeaponAccessory;
            treWeapons.SelectedNode.Nodes.Add(objNode);
            treWeapons.SelectedNode.Expand();

            UpdateCharacterInfo();
            RefreshSelectedWeapon();

            if (frmPickWeaponAccessory.AddAgain)
                tsWeaponAddAccessory_Click(sender, e);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Enable/Disable the Paste Menu and ToolStrip items as appropriate.
        /// </summary>
        private void RefreshPasteStatus()
        {
            bool blnPasteEnabled = false;
            bool blnCopyEnabled = false;

            if (tabCharacterTabs.SelectedTab == tabStreetGear)
            {
                // Lifestyle Tab.
                if (tabStreetGearTabs.SelectedTab == tabLifestyle)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Lifestyle)
                        blnPasteEnabled = true;

                    try
                    {
                        foreach (Lifestyle objLifestyle in _objCharacter.Lifestyles)
                        {
                            if (objLifestyle.InternalId == treLifestyles.SelectedNode.Tag.ToString())
                            {
                                blnCopyEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                }

                // Armor Tab.
                if (tabStreetGearTabs.SelectedTab == tabArmor)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Armor)
                        blnPasteEnabled = true;
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                    {
                        // Gear can only be pasted into Armor, not Armor Mods.
                        try
                        {
                            foreach (Armor objArmor in _objCharacter.Armor)
                            {
                                if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString())
                                {
                                    blnPasteEnabled = true;
                                    break;
                                }
                            }
                        }
                        catch
                        {
                        }
                    }

                    try
                    {
                        foreach (Armor objArmor in _objCharacter.Armor)
                        {
                            if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString())
                            {
                                blnCopyEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        Armor objArmor = new Armor(_objCharacter);
                        Gear objGear = _objFunctions.FindArmorGear(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor, out objArmor);
                        if (objGear != null)
                            blnCopyEnabled = true;
                    }
                    catch
                    {
                    }
                }

                // Weapons Tab.
                if (tabStreetGearTabs.SelectedTab == tabWeapons)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Weapon)
                        blnPasteEnabled = true;
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                    {
                        // Check if the copied Gear can be pasted into the selected Weapon Accessory.
                        Gear objGear = new Gear(_objCharacter);
                        XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear");
                        if (objXmlNode != null)
                        {
                            switch (objXmlNode["category"].InnerText)
                            {
                                case "Commlinks":
                                case "Cyberdecks":
                                case "Rigger Command Consoles":
                                    Commlink objCommlink = new Commlink(_objCharacter);
                                    objCommlink.Load(objXmlNode, true);
                                    objGear = objCommlink;
                                    break;
                                default:
                                    Gear objNewGear = new Gear(_objCharacter);
                                    objNewGear.Load(objXmlNode, true);
                                    objGear = objNewGear;
                                    break;
                            }

                            objGear.Parent = null;

                            // Make sure that a Weapon Accessory is selected and that it allows Gear of the item's Category.
                            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                            try
                            {
                                foreach (Weapon objCharacterWeapon in _objCharacter.Weapons)
                                {
                                    foreach (WeaponAccessory objWeaponAccessory in objCharacterWeapon.WeaponAccessories)
                                    {
                                        if (objWeaponAccessory.InternalId == treWeapons.SelectedNode.Tag.ToString())
                                        {
                                            objAccessory = objWeaponAccessory;
                                            break;
                                        }
                                    }
                                }
                                if (objAccessory.AllowGear != null)
                                {
                                    foreach (XmlNode objAllowed in objAccessory.AllowGear.SelectNodes("gearcategory"))
                                    {
                                        if (objAllowed.InnerText == objGear.Category)
                                        {
                                            blnPasteEnabled = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }

                    try
                    {
                        foreach (Weapon objWeapon in _objCharacter.Weapons)
                        {
                            if (objWeapon.InternalId == treWeapons.SelectedNode.Tag.ToString())
                            {
                                blnCopyEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                        Gear objGear = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objAccessory);
                        if (objGear != null)
                            blnCopyEnabled = true;
                    }
                    catch
                    {
                    }
                }

                // Gear Tab.
                if (tabStreetGearTabs.SelectedTab == tabGear)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                        blnPasteEnabled = true;

                    try
                    {
                        Gear objGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);
                        if (objGear != null)
                            blnCopyEnabled = true;
                    }
                    catch
                    {
                    }
                }
            }

            // Vehicles Tab.
            if (tabCharacterTabs.SelectedTab == tabVehicles)
            {
                if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Vehicle)
                    blnPasteEnabled = true;
                if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                {
                    // Gear can only be pasted into Vehicles and Vehicle Gear.
                    try
                    {
                        foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                        {
                            if (objVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                blnPasteEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        Vehicle objVehicle = new Vehicle(_objCharacter);
                        Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle);
                        if (objGear != null)
                            blnPasteEnabled = true;
                    }
                    catch
                    {
                    }
                }
                if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Weapon)
                {
                    // Weapons can only be pasted into Vehicle Mods that allow them (Weapon Mounts and Mechanical Arms).
                    try
                    {
                        VehicleMod objMod = new VehicleMod(_objCharacter);
                        foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                        {
                            foreach (VehicleMod objVehicleMod in objVehicle.Mods)
                            {
                                if (objVehicleMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    if (objVehicleMod.Name.StartsWith("Weapon Mount") || objVehicleMod.Name.StartsWith("Heavy Weapon Mount") || objVehicleMod.Name.StartsWith("Mechanical Arm"))
                                    {
                                        blnPasteEnabled = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }

                try
                {
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        if (objVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString())
                        {
                            blnCopyEnabled = true;
                            break;
                        }
                    }
                }
                catch
                {
                }
                try
                {
                    Vehicle objVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle);
                    if (objGear != null)
                        blnCopyEnabled = true;
                }
                catch
                {
                }
                try
                {
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                if (objWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    blnCopyEnabled = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            mnuEditPaste.Enabled = blnPasteEnabled;
            tsbPaste.Enabled = blnPasteEnabled;
            mnuEditCopy.Enabled = blnCopyEnabled;
            tsbCopy.Enabled = blnCopyEnabled;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Refresh the information for the currently displayed Weapon.
        /// </summary>
        public void RefreshSelectedWeapon()
        {
            lblWeaponDeviceRating.Text = "";
            lblWeaponAttack.Text = "";
            lblWeaponSleaze.Text = "";
            lblWeaponDataProcessing.Text = "";
            lblWeaponFirewall.Text = "";

            bool blnClear = false;
            try
            {
                if (treWeapons.SelectedNode.Level == 0)
                    blnClear = true;
            }
            catch
            {
                blnClear = true;
            }
            if (blnClear)
            {
                lblWeaponName.Text = "";
                lblWeaponCategory.Text = "";
                lblWeaponAvail.Text = "";
                lblWeaponCost.Text = "";
                lblWeaponAccuracy.Text = "";
                lblWeaponConceal.Text = "";
                lblWeaponDamage.Text = "";
                lblWeaponRC.Text = "";
                lblWeaponAP.Text = "";
                lblWeaponReach.Text = "";
                lblWeaponMode.Text = "";
                lblWeaponAmmo.Text = "";
				lblWeaponRating.Text = "";
				lblWeaponSource.Text = "";
                tipTooltip.SetToolTip(lblWeaponSource, null);
                chkWeaponAccessoryInstalled.Enabled = false;
                chkIncludedInWeapon.Enabled = false;
                chkIncludedInWeapon.Checked = false;

                // Hide Weapon Ranges.
                lblWeaponRangeShort.Text = "";
                lblWeaponRangeMedium.Text = "";
                lblWeaponRangeLong.Text = "";
                lblWeaponRangeExtreme.Text = "";
                return;
            }

            lblWeaponDicePool.Text = "";
            tipTooltip.SetToolTip(lblWeaponDicePool, "");

            // Locate the selected Weapon.
            if (treWeapons.SelectedNode.Level == 1)
            {
                Weapon objWeapon = _objFunctions.FindWeapon(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);
                if (objWeapon == null)
                    return;

                // If this is a Cyberweapon, grab the STR of the limb.
                int intUseSTR = 0;
                if (objWeapon.Cyberware)
                {
                    foreach (Cyberware objCyberware in _objCharacter.Cyberware)
                    {
                        foreach (Cyberware objPlugin in objCyberware.Children)
                        {
                            if (objPlugin.WeaponID == objWeapon.InternalId)
                            {
                                intUseSTR = objCyberware.TotalStrength;
                                break;
                            }
                        }
                    }
                }

                _blnSkipRefresh = true;
                lblWeaponName.Text = objWeapon.DisplayNameShort;
                lblWeaponCategory.Text = objWeapon.DisplayCategory;
                string strBook = _objOptions.LanguageBookShort(objWeapon.Source);
                string strPage = objWeapon.Page;
                lblWeaponSource.Text = strBook + " " + strPage;
                tipTooltip.SetToolTip(lblWeaponSource, _objOptions.LanguageBookLong(objWeapon.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objWeapon.Page);
                chkWeaponAccessoryInstalled.Enabled = false;
                chkIncludedInWeapon.Enabled = false;
                chkIncludedInWeapon.Checked = false;
                chkWeaponBlackMarketDiscount.Checked = objWeapon.DiscountCost;

                // Show the Weapon Ranges.
                lblWeaponRangeShort.Text = objWeapon.RangeShort;
                lblWeaponRangeMedium.Text = objWeapon.RangeMedium;
                lblWeaponRangeLong.Text = objWeapon.RangeLong;
                lblWeaponRangeExtreme.Text = objWeapon.RangeExtreme;
                _blnSkipRefresh = false;

                lblWeaponAvail.Text = objWeapon.TotalAvail;
                lblWeaponCost.Text = String.Format("{0:###,###,##0¥}", objWeapon.TotalCost);
                lblWeaponConceal.Text = objWeapon.CalculatedConcealability();
                lblWeaponDamage.Text = objWeapon.CalculatedDamage(intUseSTR);
                lblWeaponAccuracy.Text = objWeapon.TotalAccuracy.ToString();
                lblWeaponRC.Text = objWeapon.TotalRC;
                lblWeaponAP.Text = objWeapon.TotalAP;
                lblWeaponReach.Text = objWeapon.TotalReach.ToString();
                lblWeaponMode.Text = objWeapon.CalculatedMode;
                lblWeaponAmmo.Text = objWeapon.CalculatedAmmo();
				lblWeaponRating.Text = "";
				lblWeaponSlots.Text = "6 (" + objWeapon.SlotsRemaining.ToString() + " " + LanguageManager.Instance.GetString("String_Remaining") + ")";
                lblWeaponDicePool.Text = objWeapon.DicePool;
                tipTooltip.SetToolTip(lblWeaponDicePool, objWeapon.DicePoolTooltip);
                tipTooltip.SetToolTip(lblWeaponRC, objWeapon.RCToolTip);

                UpdateCharacterInfo();
            }
            else
            {
                // See if this is an Underbarrel Weapon.
                bool blnUnderbarrel = false;
                Weapon objWeapon = _objFunctions.FindWeapon(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);
                if (objWeapon != null)
                {
                    if (objWeapon.IsUnderbarrelWeapon)
                        blnUnderbarrel = true;
                }

                if (blnUnderbarrel)
                {
                    _blnSkipRefresh = true;
                    lblWeaponName.Text = objWeapon.DisplayNameShort;
                    lblWeaponCategory.Text = objWeapon.DisplayCategory;
                    string strBook = _objOptions.LanguageBookShort(objWeapon.Source);
                    string strPage = objWeapon.Page;
                    lblWeaponSource.Text = strBook + " " + strPage;
                    tipTooltip.SetToolTip(lblWeaponSource, _objOptions.LanguageBookLong(objWeapon.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objWeapon.Page);
                    chkWeaponAccessoryInstalled.Enabled = true;
                    chkWeaponAccessoryInstalled.Checked = objWeapon.Installed;
                    chkIncludedInWeapon.Enabled = false;
                    chkIncludedInWeapon.Checked = objWeapon.IncludedInWeapon;
                    chkWeaponBlackMarketDiscount.Checked = objWeapon.DiscountCost;

                    // Show the Weapon Ranges.
                    lblWeaponRangeShort.Text = objWeapon.RangeShort;
                    lblWeaponRangeMedium.Text = objWeapon.RangeMedium;
                    lblWeaponRangeLong.Text = objWeapon.RangeLong;
                    lblWeaponRangeExtreme.Text = objWeapon.RangeExtreme;
                    _blnSkipRefresh = false;

                    lblWeaponAvail.Text = objWeapon.TotalAvail;
                    lblWeaponCost.Text = String.Format("{0:###,###,##0¥}", objWeapon.TotalCost);
                    lblWeaponConceal.Text = "+4";
                    lblWeaponDamage.Text = objWeapon.CalculatedDamage();
                    lblWeaponAccuracy.Text = objWeapon.TotalAccuracy.ToString();
                    lblWeaponRC.Text = objWeapon.TotalRC;
                    lblWeaponAP.Text = objWeapon.TotalAP;
                    lblWeaponReach.Text = objWeapon.TotalReach.ToString();
                    lblWeaponMode.Text = objWeapon.CalculatedMode;
                    lblWeaponAmmo.Text = objWeapon.CalculatedAmmo();
					lblWeaponRating.Text = "";
					lblWeaponSlots.Text = "6 (" + objWeapon.SlotsRemaining.ToString() + " " + LanguageManager.Instance.GetString("String_Remaining") + ")";
                    lblWeaponDicePool.Text = objWeapon.DicePool;
                    tipTooltip.SetToolTip(lblWeaponDicePool, objWeapon.DicePoolTooltip);

                    UpdateCharacterInfo();
                }
                else
                {
                    bool blnAccessory = false;
                    Weapon objSelectedWeapon = new Weapon(_objCharacter);
                    WeaponAccessory objSelectedAccessory = _objFunctions.FindWeaponAccessory(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);
                    if (objSelectedAccessory != null)
                    {
                        blnAccessory = true;
                        objSelectedWeapon = objSelectedAccessory.Parent;
                    }

                    if (blnAccessory)
                    {
                        lblWeaponName.Text = objSelectedAccessory.DisplayNameShort;
                        lblWeaponCategory.Text = LanguageManager.Instance.GetString("String_WeaponAccessory");
                        lblWeaponAvail.Text = objSelectedAccessory.TotalAvail;
                        lblWeaponCost.Text = String.Format("{0:###,###,##0¥}", Convert.ToInt32(objSelectedAccessory.TotalCost));
                        lblWeaponConceal.Text = objSelectedAccessory.Concealability.ToString();
                        lblWeaponDamage.Text = "";
                        lblWeaponAccuracy.Text = objSelectedAccessory.Accuracy.ToString();
                        lblWeaponRC.Text = objSelectedAccessory.RC;
                        lblWeaponAP.Text = "";
                        lblWeaponReach.Text = "";
                        lblWeaponMode.Text = "";
                        lblWeaponAmmo.Text = "";
						lblWeaponRating.Text = objSelectedAccessory.Rating.ToString();

                        string[] strMounts = objSelectedAccessory.Mount.Split('/');
                        string strMount = "";
                        foreach (string strCurrentMount in strMounts)
                        {
                            if (strCurrentMount != "")
                                strMount += LanguageManager.Instance.GetString("String_Mount" + strCurrentMount) + "/";
                        }
                        // Remove the trailing /
                        if (strMount != "" && strMount.Contains('/'))
                            strMount = strMount.Substring(0, strMount.Length - 1);

                        lblWeaponSlots.Text = strMount;
                        string strBook = _objOptions.LanguageBookShort(objSelectedAccessory.Source);
                        string strPage = objSelectedAccessory.Page;
                        lblWeaponSource.Text = strBook + " " + strPage;
                        tipTooltip.SetToolTip(lblWeaponSource, _objOptions.BookFromCode(objSelectedAccessory.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objSelectedAccessory.Page);
                        chkWeaponAccessoryInstalled.Enabled = true;
                        chkWeaponAccessoryInstalled.Checked = objSelectedAccessory.Installed;
                        chkIncludedInWeapon.Enabled = _objOptions.AllowEditPartOfBaseWeapon;
                        chkIncludedInWeapon.Checked = objSelectedAccessory.IncludedInWeapon;
                        chkWeaponBlackMarketDiscount.Checked = objSelectedAccessory.DiscountCost;
                        UpdateCharacterInfo();
                    }
                    else
                    {
                        bool blnMod = false;
                        WeaponMod objSelectedMod = _objFunctions.FindWeaponMod(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);
                        if (objSelectedMod != null)
                        {
                            blnMod = true;
                            objSelectedWeapon = objSelectedMod.Parent;
                        }

                        if (blnMod)
                        {
                            lblWeaponName.Text = objSelectedMod.DisplayNameShort;
                            lblWeaponCategory.Text = LanguageManager.Instance.GetString("String_WeaponModification");
                            lblWeaponAvail.Text = objSelectedMod.TotalAvail;
                            lblWeaponCost.Text = String.Format("{0:###,###,##0¥}", Convert.ToInt32(objSelectedMod.TotalCost));
                            lblWeaponConceal.Text = objSelectedMod.Concealability.ToString();
                            lblWeaponDamage.Text = "";
                            lblWeaponRC.Text = objSelectedMod.RC;
                            lblWeaponAP.Text = "";
                            lblWeaponAccuracy.Text = "";
                            lblWeaponReach.Text = "";
                            lblWeaponMode.Text = "";
                            lblWeaponAmmo.Text = "";
							lblWeaponRating.Text = "";
							lblWeaponSlots.Text = objSelectedMod.Slots.ToString();
                            string strBook = _objOptions.LanguageBookShort(objSelectedMod.Source);
                            string strPage = objSelectedMod.Page;
                            lblWeaponSource.Text = strBook + " " + strPage;
                            tipTooltip.SetToolTip(lblWeaponSource, _objOptions.BookFromCode(objSelectedMod.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objSelectedMod.Page);
                            chkWeaponAccessoryInstalled.Enabled = true;
                            chkWeaponAccessoryInstalled.Checked = objSelectedMod.Installed;
                            chkIncludedInWeapon.Enabled = _objOptions.AllowEditPartOfBaseWeapon;
                            chkIncludedInWeapon.Checked = objSelectedMod.IncludedInWeapon;
                            chkWeaponBlackMarketDiscount.Checked = objSelectedMod.DiscountCost;
                            UpdateCharacterInfo();
                        }
                        else
                        {
                            // Find the selected Gear.
                            _blnSkipRefresh = true;
                            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                            Gear objGear = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objAccessory);
                            lblWeaponName.Text = objGear.DisplayNameShort;
                            lblWeaponCategory.Text = objGear.DisplayCategory;
                            lblWeaponAvail.Text = objGear.TotalAvail(true);
                            lblWeaponCost.Text = String.Format("{0:###,###,##0¥}", objGear.TotalCost);
                            lblWeaponConceal.Text = "";
                            lblWeaponDamage.Text = "";
                            lblWeaponRC.Text = "";
                            lblWeaponAP.Text = "";
                            lblWeaponAccuracy.Text = "";
                            lblWeaponReach.Text = "";
                            lblWeaponMode.Text = "";
                            lblWeaponAmmo.Text = "";
                            lblWeaponSlots.Text = "";
							lblWeaponRating.Text = "";
							string strBook = _objOptions.LanguageBookShort(objGear.Source);
                            string strPage = objGear.Page;
                            lblWeaponSource.Text = strBook + " " + strPage;
                            tipTooltip.SetToolTip(lblWeaponSource, _objOptions.BookFromCode(objGear.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objGear.Page);
                            chkWeaponAccessoryInstalled.Enabled = true;
                            chkWeaponAccessoryInstalled.Checked = objGear.Equipped;
                            chkIncludedInWeapon.Enabled = false;
                            chkIncludedInWeapon.Checked = false;
                            chkWeaponBlackMarketDiscount.Checked = objGear.DiscountCost;
                            _blnSkipRefresh = false;

                            if (objGear.GetType() == typeof(Commlink))
                            {
                                Commlink objCommlink = (Commlink)objGear;
                                lblWeaponDeviceRating.Text = objCommlink.DeviceRating.ToString();
                                lblWeaponAttack.Text = objCommlink.Attack.ToString();
                                lblWeaponSleaze.Text = objCommlink.Sleaze.ToString();
                                lblWeaponDataProcessing.Text = objCommlink.DataProcessing.ToString();
                                lblWeaponFirewall.Text = objCommlink.Firewall.ToString();
                            }
                        }
                    }

                    // Show the Weapon Ranges.
                    lblWeaponRangeShort.Text = objSelectedWeapon.RangeShort;
                    lblWeaponRangeMedium.Text = objSelectedWeapon.RangeMedium;
                    lblWeaponRangeLong.Text = objSelectedWeapon.RangeLong;
                    lblWeaponRangeExtreme.Text = objSelectedWeapon.RangeExtreme;
                }
            }
        }
Exemplo n.º 8
0
        private void lstAccessory_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Retireve the information for the selected Accessory.
            XmlNode objXmlAccessory = _objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + lstAccessory.SelectedValue + "\"]");

            TreeNode        objTreeNode  = new TreeNode();
            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);

            objAccessory.Create(objXmlAccessory, objTreeNode, "Barrel");

            lblRC.Text = objAccessory.RC;

            string[] strMounts = objXmlAccessory["mount"].InnerText.Split('/');
            string   strMount  = "";

            foreach (string strCurrentMount in strMounts)
            {
                if (strCurrentMount != "")
                {
                    strMount += LanguageManager.Instance.GetString("String_Mount" + strCurrentMount) + "/";
                }
            }
            // Remove the trailing /
            if (strMount != "" && strMount.Contains('/'))
            {
                strMount = strMount.Substring(0, strMount.Length - 1);
            }

            lblMount.Tag  = objXmlAccessory["mount"].InnerText;
            lblMount.Text = strMount;
            lblAvail.Text = objAccessory.TotalAvail;

            // If a Weapon Cost has been provided, create a dummy parent so that its cost can be considered.
            if (_intWeaponCost != 0)
            {
                Weapon objWeapon = new Weapon(_objCharacter);
                objWeapon.Cost      = _intWeaponCost;
                objAccessory.Parent = objWeapon;
            }

            int intCost = objAccessory.TotalCost;

            if (chkFreeItem.Checked)
            {
                intCost = 0;
            }

            // Apply any markup.
            double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo);

            dblCost *= 1 + (Convert.ToDouble(nudMarkup.Value, GlobalOptions.Instance.CultureInfo) / 100.0);
            intCost  = Convert.ToInt32(dblCost);

            lblCost.Text = String.Format("{0:###,###,##0¥}", intCost);

            lblTest.Text = _objCharacter.AvailTest(intCost, lblAvail.Text);

            string strBook = _objCharacter.Options.LanguageBookShort(objAccessory.Source);
            string strPage = objAccessory.Page;

            lblSource.Text = strBook + " " + strPage;

            tipTooltip.SetToolTip(lblSource, _objCharacter.Options.LanguageBookLong(objAccessory.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + strPage);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Locate a piece of Gear within the character's Weapons.
        /// </summary>
        /// <param name="strGuid">InternalId of the Gear to find.</param>
        /// <param name="lstWeapons">List of Weapons to search.</param>
        /// <param name="objFoundAccessory">WeaponAccessory that the Gear was found in.</param>
        public Gear FindWeaponGear(string strGuid, List<Weapon> lstWeapons, out WeaponAccessory objFoundAccessory)
        {
            Gear objReturn = new Gear(_objCharacter);
            foreach (Weapon objWeapon in lstWeapons)
            {
                foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                {
                    objReturn = FindGear(strGuid, objAccessory.Gear);

                    if (objReturn != null)
                    {
                        if (objReturn.InternalId != Guid.Empty.ToString() && objReturn.Name != "")
                        {
                            objFoundAccessory = objAccessory;
                            return objReturn;
                        }
                    }
                }

                if (objWeapon.UnderbarrelWeapons.Count > 0)
                {
                    objReturn = FindWeaponGear(strGuid, objWeapon.UnderbarrelWeapons, out objFoundAccessory);

                    if (objReturn != null)
                    {
                        if (objReturn.InternalId != Guid.Empty.ToString() && objReturn.Name != "")
                            return objReturn;
                    }
                }
            }

            objFoundAccessory = null;
            return objReturn;
        }
Exemplo n.º 10
0
        private void TestWeapons()
        {
            Character   objCharacter   = new Character();
            XmlDocument objXmlDocument = XmlManager.Load("weapons.xml");

            pgbProgress.Minimum  = 0;
            pgbProgress.Value    = 0;
            pgbProgress.Maximum  = objXmlDocument.SelectNodes("/chummer/weapons/weapon").Count;
            pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/accessories/accessory").Count;
            pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/mods/mod").Count;

            // Weapons.
            foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/weapons/weapon"))
            {
                pgbProgress.Value++;
                Application.DoEvents();
                try
                {
                    Weapon objTemp = new Weapon(objCharacter);
                    objTemp.Create(objXmlGear, null);
                    try
                    {
                        decimal objValue = objTemp.TotalCost;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\r\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalAP(GlobalOptions.Language);
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAP\r\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language);
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\r\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalRC;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalRC\r\n";
                    }
                    try
                    {
                        int objValue = objTemp.TotalReach;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalReach\r\n";
                    }
                    try
                    {
                        string objValue = objTemp.CalculatedAmmo(GlobalOptions.CultureInfo, GlobalOptions.Language);
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedAmmo\r\n";
                    }
                    try
                    {
                        string objValue = objTemp.CalculatedConcealability(GlobalOptions.CultureInfo);
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedConcealability\r\n";
                    }
                    try
                    {
                        string objValue = objTemp.CalculatedDamage(GlobalOptions.CultureInfo, GlobalOptions.Language);
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedDamage\r\n";
                    }
                }
                catch
                {
                    txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n";
                }
            }

            // Weapon Accessories.
            foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/accessories/accessory"))
            {
                pgbProgress.Value++;
                Application.DoEvents();
                try
                {
                    WeaponAccessory objTemp = new WeaponAccessory(objCharacter);
                    objTemp.Create(objXmlGear, new Tuple <string, string>(string.Empty, string.Empty), 0);
                    try
                    {
                        decimal objValue = objTemp.TotalCost;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCost\r\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalAvail(GlobalOptions.CultureInfo, GlobalOptions.Language);
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\r\n";
                    }
                }
                catch
                {
                    txtOutput.Text += objXmlGear["name"].InnerText + " general failure\r\n";
                }
            }

            objCharacter.DeleteCharacter();
        }
Exemplo n.º 11
0
        private void TestWeapons()
        {
            Character objCharacter = new Character();
            XmlDocument objXmlDocument = XmlManager.Instance.Load("weapons.xml");
            pgbProgress.Minimum = 0;
            pgbProgress.Value = 0;
            pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/weapons/weapon").Count;
            pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/accessories/accessory").Count;
            pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/mods/mod").Count;

            // Weapons.
            foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/weapons/weapon"))
            {
                pgbProgress.Value++;
                Application.DoEvents();
                try
                {
                    TreeNode objTempNode = new TreeNode();
                    Weapon objTemp = new Weapon(objCharacter);
                    objTemp.Create(objXmlGear, objCharacter, objTempNode, null, null, null);
                    try
                    {
                        int objValue = objTemp.TotalCost;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalAP;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAP\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalAvail;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalRC;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalRC\n";
                    }
                    try
                    {
                        int objValue = objTemp.TotalReach;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalReach\n";
                    }
                    try
                    {
                        string objValue = objTemp.CalculatedAmmo();
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedAmmo\n";
                    }
                    try
                    {
                        string objValue = objTemp.CalculatedConcealability();
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedConcealability\n";
                    }
                    try
                    {
                        string objValue = objTemp.CalculatedDamage();
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedDamage\n";
                    }
                }
                catch
                {
                    txtOutput.Text += objXmlGear["name"].InnerText + " general failure\n";
                }
            }

            // Weapon Accessories.
            foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/accessories/accessory"))
            {
                pgbProgress.Value++;
                Application.DoEvents();
                try
                {
                    TreeNode objTempNode = new TreeNode();
                    WeaponAccessory objTemp = new WeaponAccessory(objCharacter);
                    objTemp.Create(objXmlGear, objTempNode, "");
                    try
                    {
                        int objValue = objTemp.TotalCost;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCost\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalAvail;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\n";
                    }
                }
                catch
                {
                    txtOutput.Text += objXmlGear["name"].InnerText + " general failure\n";
                }
            }

            // Weapon Mods.
            foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/mods/mod"))
            {
                pgbProgress.Value++;
                Application.DoEvents();
                try
                {
                    TreeNode objTempNode = new TreeNode();
                    WeaponMod objTemp = new WeaponMod(objCharacter);
                    objTemp.Create(objXmlGear, objTempNode);
                    try
                    {
                        int objValue = objTemp.TotalCost;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCost\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalAvail;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\n";
                    }
                }
                catch
                {
                    txtOutput.Text += objXmlGear["name"].InnerText + " general failure\n";
                }
            }
        }
Exemplo n.º 12
0
		private void cboWeaponGearFirewall_SelectedIndexChanged(object sender, EventArgs e)
		{
			WeaponAccessory objSelectedWeapon = new WeaponAccessory(_objCharacter);
			Gear objGear = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objSelectedWeapon);
			if (objGear.GetType() == typeof(Commlink))
			{
				Commlink objCommlink = (Commlink)objGear;
				List<string> objASDF = new List<string>() { "0", "1", "2", "3" };

				objASDF.Remove(cboWeaponGearAttack.SelectedIndex.ToString());
				objASDF.Remove(cboWeaponGearSleaze.SelectedIndex.ToString());
				objASDF.Remove(cboWeaponGearDataProcessing.SelectedIndex.ToString());
				objASDF.Remove(cboWeaponGearFirewall.SelectedIndex.ToString());
				if (objASDF.Count == 0)
					return;

				string strMissing = objASDF[0].ToString();

				// Find the combo with the same value as this one and change it to the missing value.
				_blnLoading = true;
				if (cboWeaponGearSleaze.SelectedIndex == cboWeaponGearFirewall.SelectedIndex)
				{
					cboWeaponGearSleaze.SelectedIndex = Convert.ToInt32(strMissing);
					objCommlink.Sleaze = Convert.ToInt32(cboWeaponGearSleaze.SelectedValue);
				}

				if (cboWeaponGearDataProcessing.SelectedIndex == cboWeaponGearFirewall.SelectedIndex)
				{
					cboWeaponGearDataProcessing.SelectedIndex = Convert.ToInt32(strMissing);
					objCommlink.DataProcessing = Convert.ToInt32(cboWeaponGearDataProcessing.SelectedValue);
				}

				if (cboWeaponGearAttack.SelectedIndex == cboWeaponGearFirewall.SelectedIndex)
				{
					cboWeaponGearAttack.SelectedIndex = Convert.ToInt32(strMissing);
					objCommlink.Attack = Convert.ToInt32(cboWeaponGearAttack.SelectedValue);
				}
				_blnLoading = false;
				objCommlink.Firewall = Convert.ToInt32(cboWeaponGearFirewall.SelectedValue);
			}
			else
			{
				return;
			}
		}
Exemplo n.º 13
0
        private void lstAccessory_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Retireve the information for the selected Accessory.
            XmlNode objXmlAccessory = _objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + lstAccessory.SelectedValue + "\"]");

            TreeNode objTreeNode = new TreeNode();
            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
            objAccessory.Create(objXmlAccessory, objTreeNode, "Barrel");

            lblRC.Text = objAccessory.RC;

            string[] strMounts = objXmlAccessory["mount"].InnerText.Split('/');
            string strMount = "";
            foreach (string strCurrentMount in strMounts)
            {
                if (strCurrentMount != "")
                    strMount += LanguageManager.Instance.GetString("String_Mount" + strCurrentMount) + "/";
            }
            // Remove the trailing /
            if (strMount != "" && strMount.Contains('/'))
                strMount = strMount.Substring(0, strMount.Length - 1);

            lblMount.Tag = objXmlAccessory["mount"].InnerText;
            lblMount.Text = strMount;
            lblAvail.Text = objAccessory.TotalAvail;

            // If a Weapon Cost has been provided, create a dummy parent so that its cost can be considered.
            if (_intWeaponCost != 0)
            {
                Weapon objWeapon = new Weapon(_objCharacter);
                objWeapon.Cost = _intWeaponCost;
                objAccessory.Parent = objWeapon;
            }

            int intCost = objAccessory.TotalCost;
            if (chkFreeItem.Checked)
                intCost = 0;

            // Apply any markup.
            double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo);
            dblCost *= 1 + (Convert.ToDouble(nudMarkup.Value, GlobalOptions.Instance.CultureInfo) / 100.0);
            intCost = Convert.ToInt32(dblCost);

            lblCost.Text = String.Format("{0:###,###,##0¥}", intCost);

            lblTest.Text = _objCharacter.AvailTest(intCost, lblAvail.Text);

            string strBook = _objCharacter.Options.LanguageBookShort(objAccessory.Source);
            string strPage = objAccessory.Page;
            lblSource.Text = strBook + " " + strPage;

            tipTooltip.SetToolTip(lblSource, _objCharacter.Options.LanguageBookLong(objAccessory.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + strPage);
        }
        /// <summary>
        /// Locate a piece of Gear within the character's Weapons.
        /// </summary>
        /// <param name="strGuid">InternalId of the Gear to find.</param>
        /// <param name="lstWeapons">List of Weapons to search.</param>
        /// <param name="objFoundAccessory">WeaponAccessory that the Gear was found in.</param>
        public static Gear FindWeaponGear(this IEnumerable <Weapon> lstWeapons, string strGuid, out WeaponAccessory objFoundAccessory)
        {
            if (!string.IsNullOrWhiteSpace(strGuid) && !strGuid.IsEmptyGuid())
            {
                foreach (Weapon objWeapon in lstWeapons.DeepWhere(x => x.Children, x => x.WeaponAccessories.Any(y => y.Gear.Count > 0)))
                {
                    foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                    {
                        Gear objReturn = objAccessory.Gear.DeepFindById(strGuid);

                        if (objReturn != null)
                        {
                            objFoundAccessory = objAccessory;
                            return(objReturn);
                        }
                    }
                }
            }

            objFoundAccessory = null;
            return(null);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Locate a Weapon Accessory within the character's Vehicles.
        /// </summary>
        /// <param name="strGuid">InternalId of the Weapon Accessory to find.</param>
        /// <param name="lstVehicles">List of Vehicles to search.</param>
        public WeaponAccessory FindVehicleWeaponAccessory(string strGuid, List<Vehicle> lstVehicles)
        {
            WeaponAccessory objReturn = new WeaponAccessory(_objCharacter);
            foreach (Vehicle objVehicle in lstVehicles)
            {
                objReturn = FindWeaponAccessory(strGuid, objVehicle.Weapons);
                if (objReturn != null)
                    return objReturn;

                foreach (VehicleMod objMod in objVehicle.Mods)
                {
                    objReturn = FindWeaponAccessory(strGuid, objMod.Weapons);
                    if (objReturn != null)
                        return objReturn;
                }
            }

            return null;
        }
Exemplo n.º 16
0
        private void tsWeaponAccessoryGearMenuAddAsPlugin_Click(object sender, EventArgs e)
        {
            // Locate the Vehicle Sensor Gear.
            bool blnFound = false;
            WeaponAccessory objFoundAccessory = new WeaponAccessory(_objCharacter);
            Gear objSensor = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objFoundAccessory);
            if (objSensor != null)
                blnFound = true;

            // Make sure the Gear was found.
            if (!blnFound)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_ModifyVehicleGear"), LanguageManager.Instance.GetString("MessageTitle_SelectGear"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");

            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSensor.Name + "\" and category = \"" + objSensor.Category + "\"]");

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true);
            //frmPickGear.ShowNegativeCapacityOnly = true;

            if (objXmlGear.InnerXml.Contains("<addoncategory>"))
            {
                string strCategories = "";
                foreach (XmlNode objXmlCategory in objXmlGear.SelectNodes("addoncategory"))
                    strCategories += objXmlCategory.InnerText + ",";
                // Remove the trailing comma.
                strCategories = strCategories.Substring(0, strCategories.Length - 1);
                frmPickGear.AddCategory(strCategories);
            }

            if (frmPickGear.AllowedCategories != "")
                frmPickGear.AllowedCategories += objSensor.Category + ",";

            frmPickGear.ShowDialog(this);

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

            // Open the Gear XML file and locate the selected piece.
            objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            Gear objGear = new Gear(_objCharacter);

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlink":
                case "Commlink Upgrade":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objCommlink.DisplayName;

                    objGear = objCommlink;
                    break;
                case "Commlink Operating System":
                case "Commlink Operating System Upgrade":
                    OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter);
                    objOperatingSystem.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objOperatingSystem.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objOperatingSystem.DisplayName;

                    objGear = objOperatingSystem;
                    break;
                default:
                    Gear objNewGear = new Gear(_objCharacter);
                    objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objNewGear.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objNewGear.DisplayName;

                    objGear = objNewGear;
                    break;
            }

            if (objGear.InternalId == Guid.Empty.ToString())
                return;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objGear.Cost = (Convert.ToDouble(objGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objGear.Cost != "")
                    objGear.Cost = "(" + objGear.Cost + ") * 0.1";
                if (objGear.Cost3 != "")
                    objGear.Cost3 = "(" + objGear.Cost3 + ") * 0.1";
                if (objGear.Cost6 != "")
                    objGear.Cost6 = "(" + objGear.Cost6 + ") * 0.1";
                if (objGear.Cost10 != "")
                    objGear.Cost10 = "(" + objGear.Cost10 + ") * 0.1";
                if (objGear.Extra == "")
                    objGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objGear.Cost = "0";
                objGear.Cost3 = "0";
                objGear.Cost6 = "0";
                objGear.Cost10 = "0";
            }

            objNode.Text = objGear.DisplayName;

            int intCost = objGear.TotalCost;

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

            // Check the item's Cost and make sure the character can afford it.
            if (!frmPickGear.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    _objFunctions.DeleteGear(objGear, treWeapons, _objImprovementManager);
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (frmPickGear.AddAgain)
                        tsVehicleSensorAddAsPlugin_Click(sender, e);

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

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddWeaponGear, objGear.InternalId, frmPickGear.SelectedQty);
                    objExpense.Undo = objUndo;
                }
            }

            objNode.ContextMenuStrip = cmsCyberwareGear;

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

            objGear.Parent = objSensor;
            objSensor.Children.Add(objGear);

            if (frmPickGear.AddAgain)
                tsWeaponAccessoryGearMenuAddAsPlugin_Click(sender, e);

            UpdateCharacterInfo();
            RefreshSelectedWeapon();
        }
Exemplo n.º 17
0
        /// <summary>
        /// Locate a WeaponAccessory within the character's Weapons.
        /// </summary>
        /// <param name="strGuid">InternalId of the WeaponAccessory to find.</param>
        /// <param name="lstWeapons">List of Weapons to search.</param>
        public WeaponAccessory FindWeaponAccessory(string strGuid, List<Weapon> lstWeapons)
        {
            WeaponAccessory objReturn = new WeaponAccessory(_objCharacter);
            foreach (Weapon objWeapon in lstWeapons)
            {
                foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                {
                    if (objAccessory.InternalId == strGuid)
                        return objAccessory;
                }

                // Look within Underbarrel Weapons.
                objReturn = FindWeaponAccessory(strGuid, objWeapon.UnderbarrelWeapons);
                if (objReturn != null)
                    return objReturn;
            }

            return null;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Refresh the information for the currently displayed Weapon.
        /// </summary>
        public void RefreshSelectedWeapon()
        {
            lblWeaponDeviceRating.Text = "";
            lblWeaponAttack.Text = "";
            lblWeaponSleaze.Text = "";
            lblWeaponDataProcessing.Text = "";
            lblWeaponFirewall.Text = "";

            bool blnClear = false;
            try
            {
                if (treWeapons.SelectedNode.Level == 0)
                    blnClear = true;
            }
            catch
            {
                blnClear = true;
            }
            if (blnClear)
            {
                lblWeaponName.Text = "";
                lblWeaponCategory.Text = "";
                lblWeaponAvail.Text = "";
                lblWeaponCost.Text = "";
                lblWeaponConceal.Text = "";
                lblWeaponAccuracy.Text = "";
                lblWeaponDamage.Text = "";
                lblWeaponRC.Text = "";
                lblWeaponAP.Text = "";
                lblWeaponReach.Text = "";
                lblWeaponMode.Text = "";
                lblWeaponAmmo.Text = "";
                lblWeaponSource.Text = "";
                cboWeaponAmmo.Enabled = false;
                tipTooltip.SetToolTip(lblWeaponSource, null);
                chkWeaponAccessoryInstalled.Enabled = false;
                chkIncludedInWeapon.Enabled = false;
                chkIncludedInWeapon.Checked = false;

                // Disable the fire button.
                cmdFireWeapon.Enabled = false;
                cmdReloadWeapon.Enabled = false;
                cmdWeaponBuyAmmo.Enabled = false;
                cboWeaponAmmo.Enabled = false;

                // Hide Weapon Ranges.
                lblWeaponRangeShort.Text = "";
                lblWeaponRangeMedium.Text = "";
                lblWeaponRangeLong.Text = "";
                lblWeaponRangeExtreme.Text = "";
                return;
            }

            lblWeaponDicePool.Text = "";
            tipTooltip.SetToolTip(lblWeaponDicePool, "");
            cmdWeaponMoveToVehicle.Enabled = false;

            // Locate the selected Weapon.
            if (treWeapons.SelectedNode.Level == 1)
            {
                Weapon objWeapon = _objFunctions.FindWeapon(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);
                if (objWeapon == null)
                    return;

                _blnSkipRefresh = true;
                lblWeaponName.Text = objWeapon.DisplayNameShort;
                lblWeaponCategory.Text = objWeapon.DisplayCategory;
                string strBook = _objOptions.LanguageBookShort(objWeapon.Source);
                string strPage = objWeapon.Page;
                lblWeaponSource.Text = strBook + " " + strPage;
                tipTooltip.SetToolTip(lblWeaponSource, _objOptions.LanguageBookLong(objWeapon.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objWeapon.Page);
                chkWeaponAccessoryInstalled.Enabled = false;
                chkIncludedInWeapon.Enabled = false;
                chkIncludedInWeapon.Checked = false;

                // Do not allow Cyberware of Gear Weapons to be moved.
                if (!objWeapon.Cyberware && objWeapon.Category != "Gear")
                {
                    if (_objCharacter.Vehicles.Count > 0)
                        cmdWeaponMoveToVehicle.Enabled = true;
                    else
                        cmdWeaponMoveToVehicle.Enabled = false;
                }

                // Enable the fire button if the Weapon is Ranged.
                if (objWeapon.WeaponType == "Ranged" || (objWeapon.WeaponType == "Melee" && objWeapon.Ammo != "0"))
                {
                    cmdFireWeapon.Enabled = true;
                    cmdReloadWeapon.Enabled = true;
                    cmdWeaponBuyAmmo.Enabled = true;
                    lblWeaponAmmoRemaining.Text = objWeapon.AmmoRemaining.ToString();
                    //lblWeaponAmmoType.Text = "External Source";

                    cmsAmmoSingleShot.Enabled = objWeapon.AllowMode(LanguageManager.Instance.GetString("String_ModeSingleShot")) || objWeapon.AllowMode(LanguageManager.Instance.GetString("String_ModeSemiAutomatic"));
                    cmsAmmoShortBurst.Enabled = objWeapon.AllowMode(LanguageManager.Instance.GetString("String_ModeBurstFire")) || objWeapon.AllowMode(LanguageManager.Instance.GetString("String_ModeFullAutomatic"));
                    cmsAmmoLongBurst.Enabled = objWeapon.AllowMode(LanguageManager.Instance.GetString("String_ModeFullAutomatic"));
                    cmsAmmoFullBurst.Enabled = objWeapon.AllowMode(LanguageManager.Instance.GetString("String_ModeFullAutomatic"));
                    cmsAmmoSuppressiveFire.Enabled = objWeapon.AllowMode(LanguageManager.Instance.GetString("String_ModeFullAutomatic"));

                    // Melee Weapons with Ammo are considered to be Single Shot.
                    if (objWeapon.WeaponType == "Melee" && objWeapon.Ammo != "0")
                        cmsAmmoSingleShot.Enabled = true;

                    if (cmsAmmoFullBurst.Enabled)
                        cmsAmmoFullBurst.Text = LanguageManager.Instance.GetString("String_FullBurst").Replace("{0}", objWeapon.FullBurst.ToString());
                    if (cmsAmmoSuppressiveFire.Enabled)
                        cmsAmmoSuppressiveFire.Text = LanguageManager.Instance.GetString("String_SuppressiveFire").Replace("{0}", objWeapon.Suppressive.ToString());

                    List<ListItem> lstAmmo = new List<ListItem>();
                    int intCurrentSlot = objWeapon.ActiveAmmoSlot;
                    for (int i = 1; i <= objWeapon.AmmoSlots; i++)
                    {
                        Gear objGear = new Gear(_objCharacter);
                        ListItem objAmmo = new ListItem();
                        objWeapon.ActiveAmmoSlot = i;
                        objGear = _objFunctions.FindGear(objWeapon.AmmoLoaded, _objCharacter.Gear);
                        objAmmo.Value = i.ToString();

                        string strPlugins = "";
                        if (objGear != null)
                        {
                            foreach (Gear objChild in objGear.Children)
                            {
                                strPlugins += objChild.DisplayNameShort + ", ";
                            }
                        }
                        // Remove the trailing comma.
                        if (strPlugins != "")
                            strPlugins = strPlugins.Substring(0, strPlugins.Length - 2);

                        if (objGear == null)
                        {
                            if (objWeapon.AmmoRemaining == 0)
                                objAmmo.Name = LanguageManager.Instance.GetString("String_SlotNumber").Replace("{0}", i.ToString()) + " " + LanguageManager.Instance.GetString("String_Empty");
                            else
                                objAmmo.Name = LanguageManager.Instance.GetString("String_SlotNumber").Replace("{0}", i.ToString()) + " " + LanguageManager.Instance.GetString("String_ExternalSource");
                        }
                        else
                            objAmmo.Name = LanguageManager.Instance.GetString("String_SlotNumber").Replace("{0}", i.ToString()) + " " + objGear.DisplayNameShort;
                        if (strPlugins != "")
                            objAmmo.Name += " [" + strPlugins + "]";
                        lstAmmo.Add(objAmmo);
                    }
                    _blnSkipRefresh = true;
                    objWeapon.ActiveAmmoSlot = intCurrentSlot;
                    cboWeaponAmmo.Enabled = true;
                    cboWeaponAmmo.ValueMember = "Value";
                    cboWeaponAmmo.DisplayMember = "Name";
                    cboWeaponAmmo.DataSource = lstAmmo;
                    cboWeaponAmmo.SelectedValue = objWeapon.ActiveAmmoSlot.ToString();
                    if (cboWeaponAmmo.SelectedIndex == -1)
                        cboWeaponAmmo.SelectedIndex = 0;
                    _blnSkipRefresh = false;
                }
                else
                {
                    cmdFireWeapon.Enabled = false;
                    cmdReloadWeapon.Enabled = false;
                    cmdWeaponBuyAmmo.Enabled = false;
                    lblWeaponAmmoRemaining.Text = "";
                    cboWeaponAmmo.Enabled = false;
                }

                // If this is a Cyberweapon, grab the STR of the limb.
                int intUseSTR = 0;
                if (objWeapon.Cyberware)
                {
                    foreach (Cyberware objCyberware in _objCharacter.Cyberware)
                    {
                        foreach (Cyberware objPlugin in objCyberware.Children)
                        {
                            if (objPlugin.WeaponID == objWeapon.InternalId)
                            {
                                intUseSTR = objCyberware.TotalStrength;
                                break;
                            }
                        }
                    }
                }

                // Show the Weapon Ranges.
                lblWeaponRangeShort.Text = objWeapon.RangeShort;
                lblWeaponRangeMedium.Text = objWeapon.RangeMedium;
                lblWeaponRangeLong.Text = objWeapon.RangeLong;
                lblWeaponRangeExtreme.Text = objWeapon.RangeExtreme;

                _blnSkipRefresh = false;

                lblWeaponAvail.Text = objWeapon.TotalAvail;
                lblWeaponCost.Text = String.Format("{0:###,###,##0¥}", objWeapon.TotalCost);
                lblWeaponConceal.Text = objWeapon.CalculatedConcealability();
                lblWeaponDamage.Text = objWeapon.CalculatedDamage(intUseSTR);
                lblWeaponAccuracy.Text = objWeapon.TotalAccuracy.ToString();
                lblWeaponRC.Text = objWeapon.TotalRC;
                lblWeaponAP.Text = objWeapon.TotalAP;
                lblWeaponReach.Text = objWeapon.TotalReach.ToString();
                lblWeaponMode.Text = objWeapon.CalculatedMode;
                lblWeaponAmmo.Text = objWeapon.CalculatedAmmo();
                lblWeaponSlots.Text = "6 (" + objWeapon.SlotsRemaining.ToString() + " " + LanguageManager.Instance.GetString("String_Remaining") + ")";
                lblWeaponDicePool.Text = objWeapon.DicePool;
                tipTooltip.SetToolTip(lblWeaponDicePool, objWeapon.DicePoolTooltip);
                tipTooltip.SetToolTip(lblWeaponRC, objWeapon.RCToolTip);

                UpdateCharacterInfo();
            }
            else
            {
                // See if this is an Underbarrel Weapon.
                bool blnUnderbarrel = false;
                Weapon objWeapon = new Weapon(_objCharacter);
                foreach (Weapon objCharacterWeapon in _objCharacter.Weapons)
                {
                    if (objCharacterWeapon.UnderbarrelWeapons.Count > 0)
                    {
                        foreach (Weapon objUnderbarrelWeapon in objCharacterWeapon.UnderbarrelWeapons)
                        {
                            if (objUnderbarrelWeapon.InternalId == treWeapons.SelectedNode.Tag.ToString())
                            {
                                objWeapon = objUnderbarrelWeapon;
                                blnUnderbarrel = true;
                                break;
                            }
                        }
                    }
                }

                if (blnUnderbarrel)
                {
                    cmdFireWeapon.Enabled = true;
                    cmdReloadWeapon.Enabled = true;
                    cmdWeaponBuyAmmo.Enabled = true;

                    lblWeaponAvail.Text = objWeapon.TotalAvail;
                    lblWeaponCost.Text = String.Format("{0:###,###,##0¥}", objWeapon.TotalCost);
                    lblWeaponConceal.Text = "+4";
                    lblWeaponDamage.Text = objWeapon.CalculatedDamage();
                    lblWeaponRC.Text = objWeapon.TotalRC;
                    lblWeaponAccuracy.Text = objWeapon.TotalAccuracy.ToString();
                    lblWeaponAP.Text = objWeapon.TotalAP;
                    lblWeaponReach.Text = objWeapon.TotalReach.ToString();
                    lblWeaponMode.Text = objWeapon.CalculatedMode;
                    lblWeaponAmmo.Text = objWeapon.CalculatedAmmo();
                    lblWeaponSlots.Text = "6 (" + objWeapon.SlotsRemaining.ToString() + " " + LanguageManager.Instance.GetString("String_Remaining") + ")";
                    lblWeaponDicePool.Text = objWeapon.DicePool;
                    tipTooltip.SetToolTip(lblWeaponDicePool, objWeapon.DicePoolTooltip);
                    UpdateCharacterInfo();

                    cmsAmmoSingleShot.Enabled = objWeapon.AllowMode("SS") || objWeapon.AllowMode("SA");
                    cmsAmmoShortBurst.Enabled = objWeapon.AllowMode("BF") || objWeapon.AllowMode("FA");
                    cmsAmmoLongBurst.Enabled = objWeapon.AllowMode("FA");
                    cmsAmmoFullBurst.Enabled = objWeapon.AllowMode("FA");
                    cmsAmmoSuppressiveFire.Enabled = objWeapon.AllowMode("FA");

                    // Melee Weapons with Ammo are considered to be Single Shot.
                    if (objWeapon.WeaponType == "Melee" && objWeapon.Ammo != "0")
                        cmsAmmoSingleShot.Enabled = true;

                    if (cmsAmmoFullBurst.Enabled)
                        cmsAmmoFullBurst.Text = LanguageManager.Instance.GetString("String_FullBurst").Replace("{0}", objWeapon.FullBurst.ToString());
                    if (cmsAmmoSuppressiveFire.Enabled)
                        cmsAmmoSuppressiveFire.Text = LanguageManager.Instance.GetString("String_SuppressiveFire").Replace("{0}", objWeapon.Suppressive.ToString());

                    List<ListItem> lstAmmo = new List<ListItem>();
                    int intCurrentSlot = objWeapon.ActiveAmmoSlot;
                    for (int i = 1; i <= objWeapon.AmmoSlots; i++)
                    {
                        Gear objGear = new Gear(_objCharacter);
                        ListItem objAmmo = new ListItem();
                        objWeapon.ActiveAmmoSlot = i;
                        objGear = _objFunctions.FindGear(objWeapon.AmmoLoaded, _objCharacter.Gear);
                        objAmmo.Value = i.ToString();

                        string strPlugins = "";
                        if (objGear != null)
                        {
                            foreach (Gear objChild in objGear.Children)
                            {
                                strPlugins += objChild.DisplayNameShort + ", ";
                            }
                        }
                        // Remove the trailing comma.
                        if (strPlugins != string.Empty)
                            strPlugins = strPlugins.Substring(0, strPlugins.Length - 2);

                        if (objGear == null)
                            objAmmo.Name = LanguageManager.Instance.GetString("String_SlotNumber").Replace("{0}", i.ToString()) + " " + LanguageManager.Instance.GetString("String_Empty");
                        else
                            objAmmo.Name = LanguageManager.Instance.GetString("String_SlotNumber").Replace("{0}", i.ToString()) + " " + objGear.DisplayNameShort;
                        if (strPlugins != "")
                            objAmmo.Name += " [" + strPlugins + "]";
                        lstAmmo.Add(objAmmo);
                    }
                    _blnSkipRefresh = true;
                    chkWeaponAccessoryInstalled.Enabled = true;
                    chkWeaponAccessoryInstalled.Checked = objWeapon.Installed;
                    chkIncludedInWeapon.Enabled = false;
                    chkIncludedInWeapon.Checked = objWeapon.IncludedInWeapon;
                    objWeapon.ActiveAmmoSlot = intCurrentSlot;
                    cboWeaponAmmo.Enabled = true;
                    cboWeaponAmmo.ValueMember = "Value";
                    cboWeaponAmmo.DisplayMember = "Name";
                    cboWeaponAmmo.DataSource = lstAmmo;
                    cboWeaponAmmo.SelectedValue = objWeapon.ActiveAmmoSlot.ToString();
                    if (cboWeaponAmmo.SelectedIndex == -1)
                        cboWeaponAmmo.SelectedIndex = 0;

                    // Show the Weapon Ranges.
                    lblWeaponAmmoRemaining.Text = objWeapon.AmmoRemaining.ToString();
                    lblWeaponRangeShort.Text = objWeapon.RangeShort;
                    lblWeaponRangeMedium.Text = objWeapon.RangeMedium;
                    lblWeaponRangeLong.Text = objWeapon.RangeLong;
                    lblWeaponRangeExtreme.Text = objWeapon.RangeExtreme;

                    _blnSkipRefresh = false;
                }
                else
                {
                    cmdFireWeapon.Enabled = false;
                    cmdReloadWeapon.Enabled = false;
                    cmdWeaponBuyAmmo.Enabled = false;
                    cboWeaponAmmo.Enabled = false;

                    bool blnAccessory = false;
                    Weapon objSelectedWeapon = new Weapon(_objCharacter);
                    WeaponAccessory objSelectedAccessory = _objFunctions.FindWeaponAccessory(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);
                    if (objSelectedAccessory != null)
                    {
                        blnAccessory = true;
                        objSelectedWeapon = objSelectedAccessory.Parent;
                    }

                    if (blnAccessory)
                    {
                        lblWeaponName.Text = objSelectedAccessory.DisplayNameShort;
                        lblWeaponCategory.Text = LanguageManager.Instance.GetString("String_WeaponAccessory");
                        lblWeaponAvail.Text = objSelectedAccessory.TotalAvail;
                        lblWeaponAccuracy.Text = objWeapon.TotalAccuracy.ToString();
                        lblWeaponCost.Text = String.Format("{0:###,###,##0¥}", Convert.ToInt32(objSelectedAccessory.TotalCost));
                        lblWeaponConceal.Text = objSelectedAccessory.Concealability.ToString();
                        lblWeaponDamage.Text = "";
                        lblWeaponRC.Text = objSelectedAccessory.RC;
                        lblWeaponAP.Text = "";
                        lblWeaponReach.Text = "";
                        lblWeaponMode.Text = "";
                        lblWeaponAmmo.Text = "";

                        string[] strMounts = objSelectedAccessory.Mount.Split('/');
                        string strMount = "";
                        foreach (string strCurrentMount in strMounts)
                        {
                            if (strCurrentMount != "")
                                strMount += LanguageManager.Instance.GetString("String_Mount" + strCurrentMount) + "/";
                        }
                        // Remove the trailing /
                        if (strMount != "" && strMount.Contains('/'))
                            strMount = strMount.Substring(0, strMount.Length - 1);

                        lblWeaponSlots.Text = strMount;
                        string strBook = _objOptions.LanguageBookShort(objSelectedAccessory.Source);
                        string strPage = objSelectedAccessory.Page;
                        lblWeaponSource.Text = strBook + " " + strPage;
                        tipTooltip.SetToolTip(lblWeaponSource, _objOptions.LanguageBookLong(objSelectedAccessory.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objSelectedAccessory.Page);
                        chkWeaponAccessoryInstalled.Enabled = true;
                        chkWeaponAccessoryInstalled.Checked = objSelectedAccessory.Installed;
                        chkIncludedInWeapon.Enabled = _objOptions.AllowEditPartOfBaseWeapon;
                        chkIncludedInWeapon.Checked = objSelectedAccessory.IncludedInWeapon;
                    }
                    else
                    {
                        bool blnMod = false;
                        WeaponMod objSelectedMod = _objFunctions.FindWeaponMod(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);
                        if (objSelectedMod != null)
                        {
                            blnMod = true;
                            objSelectedWeapon = objSelectedMod.Parent;
                        }

                        if (blnMod)
                        {
                            lblWeaponName.Text = objSelectedMod.DisplayNameShort;
                            lblWeaponCategory.Text = LanguageManager.Instance.GetString("String_WeaponModification");
                            lblWeaponAvail.Text = objSelectedMod.TotalAvail;
                            lblWeaponCost.Text = String.Format("{0:###,###,##0¥}", Convert.ToInt32(objSelectedMod.TotalCost));
                            lblWeaponConceal.Text = objSelectedMod.Concealability.ToString();
                            lblWeaponAccuracy.Text = objWeapon.TotalAccuracy.ToString();
                            lblWeaponDamage.Text = "";
                            lblWeaponRC.Text = objSelectedMod.RC;
                            lblWeaponAP.Text = "";
                            lblWeaponReach.Text = "";
                            lblWeaponMode.Text = "";
                            lblWeaponAmmo.Text = "";
                            lblWeaponSlots.Text = objSelectedMod.Slots.ToString();
                            string strBook = _objOptions.LanguageBookShort(objSelectedMod.Source);
                            string strPage = objSelectedMod.Page;
                            lblWeaponSource.Text = strBook + " " + strPage;
                            tipTooltip.SetToolTip(lblWeaponSource, _objOptions.LanguageBookLong(objSelectedMod.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objSelectedMod.Page);
                            chkWeaponAccessoryInstalled.Enabled = true;
                            chkWeaponAccessoryInstalled.Checked = objSelectedMod.Installed;
                            chkIncludedInWeapon.Enabled = _objOptions.AllowEditPartOfBaseWeapon;
                            chkIncludedInWeapon.Checked = objSelectedMod.IncludedInWeapon;
                        }
                        else
                        {
                            // Find the selected Gear.
                            _blnSkipRefresh = true;
                            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                            Gear objGear = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objAccessory);
                            lblWeaponName.Text = objGear.DisplayNameShort;
                            lblWeaponCategory.Text = objGear.DisplayCategory;
                            lblWeaponAvail.Text = objGear.TotalAvail(true);
                            lblWeaponCost.Text = String.Format("{0:###,###,##0¥}", objGear.TotalCost);
                            lblWeaponAccuracy.Text = objWeapon.TotalAccuracy.ToString();
                            lblWeaponConceal.Text = "";
                            lblWeaponDamage.Text = "";
                            lblWeaponRC.Text = "";
                            lblWeaponAP.Text = "";
                            lblWeaponReach.Text = "";
                            lblWeaponMode.Text = "";
                            lblWeaponAmmo.Text = "";
                            lblWeaponSlots.Text = "";
                            string strBook = _objOptions.LanguageBookShort(objGear.Source);
                            string strPage = objGear.Page;
                            lblWeaponSource.Text = strBook + " " + strPage;
                            tipTooltip.SetToolTip(lblWeaponSource, _objOptions.BookFromCode(objGear.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objGear.Page);
                            chkWeaponAccessoryInstalled.Enabled = true;
                            chkWeaponAccessoryInstalled.Checked = objGear.Equipped;
                            chkIncludedInWeapon.Enabled = false;
                            chkIncludedInWeapon.Checked = false;
                            _blnSkipRefresh = true;

                            if (objGear.GetType() == typeof(Commlink))
                            {
                                Commlink objCommlink = (Commlink)objGear;
                                lblWeaponDeviceRating.Text = objCommlink.DeviceRating.ToString();
                                lblWeaponAttack.Text = objCommlink.Attack.ToString();
                                lblWeaponSleaze.Text = objCommlink.Sleaze.ToString();
                                lblWeaponDataProcessing.Text = objCommlink.DataProcessing.ToString();
                                lblWeaponFirewall.Text = objCommlink.Firewall.ToString();
                            }
                        }
                    }

                    // Show the Weapon Ranges.
                    lblWeaponRangeShort.Text = objSelectedWeapon.RangeShort;
                    lblWeaponRangeMedium.Text = objSelectedWeapon.RangeMedium;
                    lblWeaponRangeLong.Text = objSelectedWeapon.RangeLong;
                    lblWeaponRangeExtreme.Text = objSelectedWeapon.RangeExtreme;
                }
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Locate a piece of Gear within the character's Vehicles.
        /// </summary>
        /// <param name="strGuid">InternalId of the Gear to find.</param>
        /// <param name="lstVehicles">List of Vehicles to search.</param>
        /// <param name="objFoundVehicle">Vehicle that the Gear was found in.</param>
        public Gear FindVehicleGear(string strGuid, List<Vehicle> lstVehicles, out Vehicle objFoundVehicle)
        {
            Gear objReturn = new Gear(_objCharacter);
            foreach (Vehicle objVehicle in lstVehicles)
            {
                objReturn = FindGear(strGuid, objVehicle.Gear);

                if (objReturn != null)
                {
                    if (objReturn.InternalId != Guid.Empty.ToString() && objReturn.Name != "")
                    {
                        objFoundVehicle = objVehicle;
                        return objReturn;
                    }
                }

                // Look for any Gear that might be attached to this Vehicle through Weapon Accessories or Cyberware.
                foreach (VehicleMod objMod in objVehicle.Mods)
                {
                    // Weapon Accessories.
                    WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                    objReturn = FindWeaponGear(strGuid, objMod.Weapons, out objAccessory);

                    if (objReturn != null)
                    {
                        if (objReturn.InternalId != Guid.Empty.ToString() && objReturn.Name != "")
                        {
                            objFoundVehicle = objVehicle;
                            return objReturn;
                        }
                    }

                    // Cyberware.
                    Cyberware objCyberware = new Cyberware(_objCharacter);
                    objReturn = FindCyberwareGear(strGuid, objMod.Cyberware, out objCyberware);

                    if (objReturn != null)
                    {
                        if (objReturn.InternalId != Guid.Empty.ToString() && objReturn.Name != "")
                        {
                            objFoundVehicle = objVehicle;
                            return objReturn;
                        }
                    }
                }
            }

            objFoundVehicle = null;
            objReturn = null;
            return objReturn;
        }
Exemplo n.º 20
0
        private void tsUndoNuyenExpense_Click(object sender, EventArgs e)
        {
            ListViewItem objItem = new ListViewItem();

            try
            {
                objItem = lstNuyen.SelectedItems[0];
            }
            catch
            {
                return;
            }

            CommonFunctions objCommon = new CommonFunctions(_objCharacter);

            ExpenseLogEntry objEntry = new ExpenseLogEntry();
            objItem = lstNuyen.SelectedItems[0];

            // Find the selected Nuyen Expense.
            foreach (ExpenseLogEntry objCharacterEntry in _objCharacter.ExpenseEntries)
            {
                if (objCharacterEntry.InternalId == objItem.SubItems[3].Text)
                {
                    objEntry = objCharacterEntry;
                    break;
                }
            }

            if (objEntry.Undo == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_UndoNoHistory"), LanguageManager.Instance.GetString("MessageTitle_NoUndoHistory"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else if (objEntry.Undo.KarmaType == KarmaExpenseType.ImproveInitiateGrade)
            {
                // Get the grade of the item we're undoing and make sure it's the highest grade
                int intMaxGrade = 0;
                foreach (InitiationGrade objGrade in _objCharacter.InitiationGrades)
                {
                    intMaxGrade = Math.Max(intMaxGrade, objGrade.Grade);
                }
                foreach (InitiationGrade objGrade in _objCharacter.InitiationGrades)
                {
                    if (objGrade.InternalId == objEntry.Undo.ObjectId)
                    {
                        if (objGrade.Grade < intMaxGrade)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_UndoNotHighestGrade"), LanguageManager.Instance.GetString("MessageTitle_NotHighestGrade"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        break;
                    }
                }
                if (MessageBox.Show(LanguageManager.Instance.GetString("Message_UndoExpense"), LanguageManager.Instance.GetString("MessageTitle_UndoExpense"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    return;
            }
            else
            {
                if (MessageBox.Show(LanguageManager.Instance.GetString("Message_UndoExpense"), LanguageManager.Instance.GetString("MessageTitle_UndoExpense"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    return;
            }

            switch (objEntry.Undo.NuyenType)
            {
                case NuyenExpenseType.AddCyberware:
                    // Locate the Cyberware that was added.
                    int intOldPenalty = 0;
                    int intNewPenalty = 0;
                    foreach (Cyberware objCyberware in _objCharacter.Cyberware)
                    {
                        if (objCyberware.InternalId == objEntry.Undo.ObjectId)
                        {
                            foreach (Cyberware objChild in objCyberware.Children)
                            {
                                // Remove the Improvements created by child items.
                                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Cyberware, objChild.InternalId);
                                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Bioware, objChild.InternalId);
                            }
                            // Remove the Improvements created by the item.
                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Cyberware, objCyberware.InternalId);
                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Bioware, objCyberware.InternalId);

                            // Determine the character's Essence penalty before removing the Cyberware.
                            intOldPenalty = _objCharacter.EssencePenalty;
                            // Remove the Cyberware.
                            _objCharacter.Cyberware.Remove(objCyberware);
                            // Determine the character's Essence penalty after removing the Cyberware.
                            intNewPenalty = _objCharacter.EssencePenalty;

                            // Restore the character's MAG/RES if they have it.
                            //if (!_objCharacter.OverrideSpecialAttributeEssenceLoss && !_objCharacter.OverrideSpecialAttributeEssenceLoss)
                            //{
                            //    if (intOldPenalty != intNewPenalty)
                            //    {
                            //        if (_objCharacter.MAGEnabled)
                            //            _objCharacter.MAG.Value += (intOldPenalty - intNewPenalty);
                            //        if (_objCharacter.RESEnabled)
                            //            _objCharacter.RES.Value += (intOldPenalty - intNewPenalty);
                            //    }
                            //}

                            // Remove the item from the Tree.
                            foreach (TreeNode objNode in treCyberware.Nodes[0].Nodes)
                            {
                                if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                {
                                    objNode.Remove();
                                    break;
                                }
                            }
                            foreach (TreeNode objNode in treCyberware.Nodes[1].Nodes)
                            {
                                if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                {
                                    objNode.Remove();
                                    break;
                                }
                            }

                            // Remove any Weapon that the Cyberware created.
                            if (objCyberware.WeaponID != Guid.Empty.ToString())
                            {
                                foreach (Weapon objWeapon in _objCharacter.Weapons)
                                {
                                    if (objWeapon.InternalId == objCyberware.WeaponID)
                                    {
                                        _objCharacter.Weapons.Remove(objWeapon);
                                        break;
                                    }
                                }

                                // Remove the TreeNode for the Weapon.
                                foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                {
                                    if (objWeaponNode.Tag.ToString() == objCyberware.WeaponID)
                                    {
                                        treWeapons.Nodes[0].Nodes.Remove(objWeaponNode);
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                        else
                        {
                            foreach (Cyberware objChild in objCyberware.Children)
                            {
                                if (objChild.InternalId == objEntry.Undo.ObjectId)
                                {
                                    // Remove the Improvements created by the item.
                                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Cyberware, objChild.InternalId);
                                    objCyberware.Children.Remove(objChild);

                                    // Remove the item from the Tree.
                                    foreach (TreeNode objNode in treCyberware.Nodes[0].Nodes)
                                    {
                                        foreach (TreeNode objChildNode in objNode.Nodes)
                                        {
                                            if (objChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                            {
                                                objChildNode.Remove();
                                                break;
                                            }
                                        }
                                    }
                                    foreach (TreeNode objNode in treCyberware.Nodes[1].Nodes)
                                    {
                                        foreach (TreeNode objChildNode in objNode.Nodes)
                                        {
                                            if (objChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                            {
                                                objNode.Remove();
                                                break;
                                            }
                                        }
                                    }
                                    break;
                                }

                                // Remove any Weapon that the Cyberware created.
                                if (objChild.WeaponID != Guid.Empty.ToString())
                                {
                                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                                    {
                                        if (objWeapon.InternalId == objChild.WeaponID)
                                        {
                                            _objCharacter.Weapons.Remove(objWeapon);
                                            break;
                                        }
                                    }

                                    // Remove the TreeNode for the Weapon.
                                    foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                    {
                                        if (objWeaponNode.Tag.ToString() == objChild.WeaponID)
                                        {
                                            treWeapons.Nodes[0].Nodes.Remove(objWeaponNode);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddGear:
                    // Locate the Gear that was added.
                    //If the gear was already deleted manually we will not be able to locate it here
                    Gear objGear = objCommon.FindGear(objEntry.Undo.ObjectId, _objCharacter.Gear);
                    if (objGear == null)
                        break;
                    objGear.Quantity -= objEntry.Undo.Qty;

                    if (objGear.Quantity <= 0)
                    {
                        if (objGear.Parent != null)
                            objGear.Parent.Children.Remove(objGear);
                        else
                            _objCharacter.Gear.Remove(objGear);

                        objCommon.DeleteGear(objGear, treWeapons, _objImprovementManager);
                        TreeNode objNode = objCommon.FindNode(objGear.InternalId, treGear);
                        objNode.Remove();
                    }
                    else
                    {
                        TreeNode objNode = objCommon.FindNode(objGear.InternalId, treGear);
                        objNode.Text = objGear.DisplayName;
                    }

                    _objController.PopulateFocusList(treFoci);
                    break;
                case NuyenExpenseType.AddVehicle:
                    // Locate the Vehicle that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        if (objVehicle.InternalId == objEntry.Undo.ObjectId)
                        {
                            // Remove the Vehicle.
                            _objCharacter.Vehicles.Remove(objVehicle);
                            foreach (TreeNode objNode in treVehicles.Nodes[0].Nodes)
                            {
                                if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                {
                                    objNode.Remove();
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleMod:
                    // Locate the Vehicle Mod that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            if (objMod.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Check for Improved Sensor bonus.
                                if (objMod.Bonus != null)
                                {
                                    if (objMod.Bonus["improvesensor"] != null)
                                    {
                                        ChangeVehicleSensor(objVehicle, false);
                                    }
                                }

                                // Remove the Vehicle Mod.
                                objVehicle.Mods.Remove(objMod);

                                // Remove the Vehicle Mod from the tree.
                                foreach (TreeNode objNode in treVehicles.Nodes[0].Nodes)
                                {
                                    foreach (TreeNode objChild in objNode.Nodes)
                                    {
                                        if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                        {
                                            objChild.Remove();
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleGear:
                    // Locate the Gear that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (Gear objVehicleGear in objVehicle.Gear)
                        {
                            if (objVehicleGear.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Deduct the Qty from the Gear.
                                objVehicleGear.Quantity -= objEntry.Undo.Qty;
                                foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                {
                                    foreach (TreeNode objNode in objVNode.Nodes)
                                    {
                                        if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                        {
                                            objNode.Text = objVehicleGear.DisplayName;
                                            // Remove the Node if its Qty has been reduced to 0.
                                            if (objVehicleGear.Quantity <= 0)
                                                objNode.Remove();
                                            break;
                                        }
                                    }
                                }

                                // Remove the Gear if its Qty has been reduced to 0.
                                if (objVehicleGear.Quantity <= 0)
                                {
                                    objVehicle.Gear.Remove(objVehicleGear);
                                }

                                break;
                            }
                            else
                            {
                                // Look in child items.
                                foreach (Gear objChild in objVehicleGear.Children)
                                {
                                    if (objChild.InternalId == objEntry.Undo.ObjectId)
                                    {
                                        // Deduct the Qty from the Gear.
                                        objChild.Quantity -= objEntry.Undo.Qty;
                                        foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                        {
                                            foreach (TreeNode objNode in objVNode.Nodes)
                                            {
                                                foreach (TreeNode objChildNode in objNode.Nodes)
                                                {
                                                    if (objChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                                    {
                                                        objChildNode.Text = objChild.DisplayName;
                                                        // Remove the Node if its Qty has been reduced to 0.
                                                        if (objChild.Quantity <= 0)
                                                        {
                                                            objChildNode.Remove();
                                                        }
                                                        break;
                                                    }
                                                }
                                            }
                                        }

                                        // Remove the Gear if its Qty has been reduce to 0.
                                        if (objChild.Quantity <= 0)
                                        {
                                            objVehicleGear.Children.Remove(objChild);
                                        }

                                        break;
                                    }
                                    else
                                    {
                                        foreach (Gear objSubChild in objChild.Children)
                                        {
                                            if (objSubChild.InternalId == objEntry.Undo.ObjectId)
                                            {
                                                // Deduct the Qty from the Gear.
                                                objSubChild.Quantity -= objEntry.Undo.Qty;
                                                foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                                {
                                                    foreach (TreeNode objNode in objVNode.Nodes)
                                                    {
                                                        foreach (TreeNode objChildNode in objNode.Nodes)
                                                        {
                                                            foreach (TreeNode objSubChildNode in objChildNode.Nodes)
                                                            {
                                                                if (objSubChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                                                {
                                                                    objSubChildNode.Text = objSubChild.DisplayName;
                                                                    // Remove the Node if its Qty has been reduced to 0.
                                                                    if (objSubChild.Quantity <= 0)
                                                                    {
                                                                        objSubChildNode.Remove();
                                                                    }
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                // Remove the Gear if its Qty has been reduce to 0.
                                                if (objSubChild.Quantity <= 0)
                                                {
                                                    objChild.Children.Remove(objSubChild);
                                                }

                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleWeapon:
                    // Locate the Weapon that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                if (objWeapon.InternalId == objEntry.Undo.ObjectId)
                                {
                                    // Remove the Weapon.
                                    objMod.Weapons.Remove(objWeapon);

                                    // Remove the Weapon from the Tree.
                                    foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                    {
                                        foreach (TreeNode objNode in objVNode.Nodes)
                                        {
                                            foreach (TreeNode objChild in objNode.Nodes)
                                            {
                                                if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                {
                                                    objChild.Remove();
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                                else
                                {
                                    if (objWeapon.UnderbarrelWeapons.Count > 0)
                                    {
                                        foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                        {
                                            if (objUnderbarrelWeapon.InternalId == objEntry.Undo.ObjectId)
                                            {
                                                // Remove the Underbarrel Weapon.
                                                objWeapon.UnderbarrelWeapons.Remove(objUnderbarrelWeapon);

                                                // Remove the Underbarrel Weapon from the Tree.
                                                foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                                {
                                                    foreach (TreeNode objNode in objVNode.Nodes)
                                                    {
                                                        foreach (TreeNode objChild in objNode.Nodes)
                                                        {
                                                            foreach (TreeNode objSubChild in objChild.Nodes)
                                                            {
                                                                if (objSubChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                                {
                                                                    objSubChild.Remove();
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleWeaponAccessory:
                    // Locate the Weapon Accessory that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                                {
                                    if (objAccessory.InternalId == objEntry.Undo.ObjectId)
                                    {
                                        // Remove the Weapon Accessory.
                                        objWeapon.WeaponAccessories.Remove(objAccessory);

                                        // Remove the Weapon Accessory from the Tree.
                                        foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                        {
                                            foreach (TreeNode objNode in objVNode.Nodes)
                                            {
                                                foreach (TreeNode objWNode in objNode.Nodes)
                                                {
                                                    foreach (TreeNode objChild in objWNode.Nodes)
                                                    {
                                                        if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                        {
                                                            objChild.Remove();
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                }
                                if (objWeapon.UnderbarrelWeapons.Count > 0)
                                {
                                    foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                    {
                                        foreach (WeaponAccessory objAccessory in objUnderbarrelWeapon.WeaponAccessories)
                                        {
                                            if (objAccessory.InternalId == objEntry.Undo.ObjectId)
                                            {
                                                // Remove the Weapon Accessory.
                                                objUnderbarrelWeapon.WeaponAccessories.Remove(objAccessory);

                                                // Remove the Weapon Accessory from the Tree.
                                                foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                                {
                                                    foreach (TreeNode objNode in objVNode.Nodes)
                                                    {
                                                        foreach (TreeNode objWNode in objNode.Nodes)
                                                        {
                                                            foreach (TreeNode objChild in objWNode.Nodes)
                                                            {
                                                                foreach (TreeNode objSubChild in objChild.Nodes)
                                                                {
                                                                    if (objSubChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                                    {
                                                                        objSubChild.Remove();
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleWeaponMod:
                    // Locate the Weapon Mod that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                foreach (WeaponMod objWMod in objWeapon.WeaponMods)
                                {
                                    if (objMod.InternalId == objEntry.Undo.ObjectId)
                                    {
                                        // Remove the Weapon Mod.
                                        objWeapon.WeaponMods.Remove(objWMod);

                                        // Remove the Weapon Mod from the Tree.
                                        foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                        {
                                            foreach (TreeNode objNode in objVNode.Nodes)
                                            {
                                                foreach (TreeNode objWNode in objNode.Nodes)
                                                {
                                                    foreach (TreeNode objChild in objWNode.Nodes)
                                                    {
                                                        if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                        {
                                                            objChild.Remove();
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                }
                                if (objWeapon.UnderbarrelWeapons.Count > 0)
                                {
                                    foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                    {
                                        foreach (WeaponMod objWMod in objUnderbarrelWeapon.WeaponMods)
                                        {
                                            if (objWMod.InternalId == objEntry.Undo.ObjectId)
                                            {
                                                // Remove the Weapon Mod.
                                                objUnderbarrelWeapon.WeaponMods.Remove(objWMod);

                                                // Remove the Weapon Mod from the Tree.
                                                foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                                {
                                                    foreach (TreeNode objNode in objVNode.Nodes)
                                                    {
                                                        foreach (TreeNode objWNode in objNode.Nodes)
                                                        {
                                                            foreach (TreeNode objChild in objWNode.Nodes)
                                                            {
                                                                foreach (TreeNode objSubChild in objChild.Nodes)
                                                                {
                                                                    if (objSubChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                                    {
                                                                        objSubChild.Remove();
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddArmor:
                    // Locate the Armor that was added.
                    Armor objArmor = objCommon.FindArmor(objEntry.Undo.ObjectId, _objCharacter.Armor);

                    if (objArmor != null)
                    {
                        // Remove the Improvements for any child items.
                        foreach (ArmorMod objMod in objArmor.ArmorMods)
                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.ArmorMod, objMod.InternalId);

                        // Remove the Improvements for the Armor.
                        _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Armor, objArmor.InternalId);

                        // Remove the Armor from the character.
                        _objCharacter.Armor.Remove(objArmor);

                        // Remove the Armor from the Tree.
                        TreeNode objArmorNode = objCommon.FindNode(objEntry.Undo.ObjectId, treArmor);
                        objArmorNode.Remove();
                    }

                    break;
                case NuyenExpenseType.AddArmorMod:
                    // Locate the Armor Mod that was added.
                    foreach (Armor objFoundArmor in _objCharacter.Armor)
                    {
                        foreach (ArmorMod objMod in objFoundArmor.ArmorMods)
                        {
                            if (objMod.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Remove the Improtements for the Armor Mod.
                                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.ArmorMod, objMod.InternalId);

                                // Remove the Armor Mod from the Armor.
                                objFoundArmor.ArmorMods.Remove(objMod);

                                // Remove the Cyberweapon created by the Mod if applicable.
                                if (objMod.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() == objMod.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 == objMod.WeaponID)
                                            objRemoveWeapon = objWeapon;
                                    }
                                    _objCharacter.Weapons.Remove(objRemoveWeapon);
                                }

                                // Remove the Armor Mod from the Tree.
                                TreeNode objNode = objCommon.FindNode(objMod.InternalId, treArmor.Nodes[0]);
                                objNode.Remove();
                                break;
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddWeapon:
                    // Locate the Weapon that was added.
                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                    {
                        if (objWeapon.InternalId == objEntry.Undo.ObjectId)
                        {
                            // Remove the Weapn from the character.
                            _objCharacter.Weapons.Remove(objWeapon);

                            // Remove the Weapon from the Tree.
                            foreach (TreeNode objNode in treWeapons.Nodes[0].Nodes)
                            {
                                if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                {
                                    objNode.Remove();
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    break;
                case NuyenExpenseType.AddWeaponAccessory:
                    // Locate the Weapon Accessory that was added.
                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                    {
                        foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                        {
                            if (objAccessory.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Remove the Weapon Accessory.
                                objWeapon.WeaponAccessories.Remove(objAccessory);

                                // Remove the Weapon Accessory from the tree.
                                foreach (TreeNode objNode in treWeapons.Nodes[0].Nodes)
                                {
                                    foreach (TreeNode objChild in objNode.Nodes)
                                    {
                                        if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                        {
                                            objChild.Remove();
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddWeaponMod:
                    // Locate the Weapon Mod that was added.
                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                    {
                        foreach (WeaponMod objMod in objWeapon.WeaponMods)
                        {
                            if (objMod.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Remove the Weapon Mod.
                                objWeapon.WeaponMods.Remove(objMod);

                                // Remove the Weapon Mod from the tree.
                                foreach (TreeNode objNode in treWeapons.Nodes[0].Nodes)
                                {
                                    foreach (TreeNode objChild in objNode.Nodes)
                                    {
                                        if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                        {
                                            objChild.Remove();
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.IncreaseLifestyle:
                    // Locate the Lifestyle that was increased.
                    foreach (Lifestyle objLifestyle in _objCharacter.Lifestyles)
                    {
                        if (objLifestyle.Name == objEntry.Undo.ObjectId)
                        {
                            objLifestyle.Months--;
                            RefreshSelectedLifestyle();
                            break;
                        }
                    }
                    break;
                case NuyenExpenseType.AddArmorGear:
                    // Locate the Armor Gear that was added.
                    foreach (Armor objFoundArmor in _objCharacter.Armor)
                    {
                        foreach (Gear objArmorGear in objFoundArmor.Gear)
                        {
                            if (objArmorGear.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Deduct the Qty from the Gear.
                                objArmorGear.Quantity -= objEntry.Undo.Qty;
                                foreach (TreeNode objArmorNode in treArmor.Nodes[0].Nodes)
                                {
                                    foreach (TreeNode objNode in objArmorNode.Nodes)
                                    {
                                        if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                        {
                                            objNode.Text = objArmorGear.DisplayName;
                                            // Remove the Node if its Qty has been reduced to 0.
                                            if (objArmorGear.Quantity <= 0)
                                                objNode.Remove();
                                            break;
                                        }
                                    }
                                }

                                // Remove the Gear if its Qty has been reduced to 0.
                                if (objArmorGear.Quantity <= 0)
                                {
                                    // Remove any Improvements created by the Gear.
                                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objArmorGear.InternalId);
                                    objFoundArmor.Gear.Remove(objArmorGear);

                                    // Remove any Weapons created by the Gear.
                                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                                    {
                                        if (objWeapon.InternalId == objArmorGear.WeaponID)
                                        {
                                            _objCharacter.Weapons.Remove(objWeapon);
                                            foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                            {
                                                if (objWeaponNode.Tag.ToString() == objArmorGear.WeaponID)
                                                {
                                                    objWeaponNode.Remove();
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }

                                break;
                            }
                            else
                            {
                                // Look in child items.
                                foreach (Gear objChild in objArmorGear.Children)
                                {
                                    if (objChild.InternalId == objEntry.Undo.ObjectId)
                                    {
                                        // Deduct the Qty from the Gear.
                                        objChild.Quantity -= objEntry.Undo.Qty;
                                        foreach (TreeNode objArmorNode in treArmor.Nodes[0].Nodes)
                                        {
                                            foreach (TreeNode objNode in objArmorNode.Nodes)
                                            {
                                                foreach (TreeNode objChildNode in objNode.Nodes)
                                                {
                                                    if (objChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                                    {
                                                        objChildNode.Text = objChild.DisplayName;
                                                        // Remove the Node if its Qty has been reduced to 0.
                                                        if (objChild.Quantity <= 0)
                                                        {
                                                            objChildNode.Remove();

                                                            // Remove any Weapons created by the Gear.
                                                            foreach (Weapon objWeapon in _objCharacter.Weapons)
                                                            {
                                                                if (objWeapon.InternalId == objChild.WeaponID)
                                                                {
                                                                    _objCharacter.Weapons.Remove(objWeapon);
                                                                    foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                                                    {
                                                                        if (objWeaponNode.Tag.ToString() == objChild.WeaponID)
                                                                        {
                                                                            objWeaponNode.Remove();
                                                                            break;
                                                                        }
                                                                    }
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                        break;
                                                    }
                                                }
                                            }
                                        }

                                        // Remove the Gear if its Qty has been reduce to 0.
                                        if (objChild.Quantity <= 0)
                                        {
                                            // Remove any Improvements created by the Gear.
                                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objChild.InternalId);
                                            objArmorGear.Children.Remove(objChild);
                                        }

                                        break;
                                    }
                                    else
                                    {
                                        foreach (Gear objSubChild in objChild.Children)
                                        {
                                            if (objSubChild.InternalId == objEntry.Undo.ObjectId)
                                            {
                                                // Deduct the Qty from the Gear.
                                                objSubChild.Quantity -= objEntry.Undo.Qty;
                                                foreach (TreeNode objArmorNode in treArmor.Nodes[0].Nodes)
                                                {
                                                    foreach (TreeNode objNode in objArmorNode.Nodes)
                                                    {
                                                        foreach (TreeNode objChildNode in objNode.Nodes)
                                                        {
                                                            foreach (TreeNode objSubChildNode in objChildNode.Nodes)
                                                            {
                                                                if (objSubChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                                                {
                                                                    objSubChildNode.Text = objSubChild.DisplayName;
                                                                    // Remove the Node if its Qty has been reduced to 0.
                                                                    if (objSubChild.Quantity <= 0)
                                                                    {
                                                                        objSubChildNode.Remove();

                                                                        // Remove any Weapons created by the Gear.
                                                                        foreach (Weapon objWeapon in _objCharacter.Weapons)
                                                                        {
                                                                            if (objWeapon.InternalId == objSubChild.WeaponID)
                                                                            {
                                                                                _objCharacter.Weapons.Remove(objWeapon);
                                                                                foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                                                                {
                                                                                    if (objWeaponNode.Tag.ToString() == objSubChild.WeaponID)
                                                                                    {
                                                                                        objWeaponNode.Remove();
                                                                                        break;
                                                                                    }
                                                                                }
                                                                                break;
                                                                            }
                                                                        }
                                                                    }
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                // Remove the Gear if its Qty has been reduce to 0.
                                                if (objSubChild.Quantity <= 0)
                                                {
                                                    // Remove any Improvements created by the Gear.
                                                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objSubChild.InternalId);
                                                    objChild.Children.Remove(objSubChild);
                                                }

                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleModCyberware:
                    // Locate the Cyberware that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            foreach (Cyberware objCyberware in objMod.Cyberware)
                            {
                                if (objCyberware.InternalId == objEntry.Undo.ObjectId)
                                {
                                    // Remove the Cyberware.
                                    objMod.Cyberware.Remove(objCyberware);

                                    // Remove the Cyberware from the Tree.
                                    foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                    {
                                        foreach (TreeNode objNode in objVNode.Nodes)
                                        {
                                            foreach (TreeNode objChild in objNode.Nodes)
                                            {
                                                if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                {
                                                    objChild.Remove();
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddCyberwareGear:
                    // Locate the Gear that was added.
                    Cyberware objFoundCyberware = new Cyberware(_objCharacter);
                    Gear objFoundGear = _objFunctions.FindCyberwareGear(objEntry.Undo.ObjectId, _objCharacter.Cyberware, out objFoundCyberware);
                    _objFunctions.DeleteGear(objFoundGear, treWeapons, _objImprovementManager);
                    if (objFoundGear.Parent == null)
                        objFoundCyberware.Gear.Remove(objFoundGear);
                    else
                        objFoundGear.Parent.Children.Remove(objFoundGear);
                    TreeNode objFoundNode = _objFunctions.FindNode(objFoundGear.InternalId, treCyberware);
                    objFoundNode.Remove();
                    break;
                case NuyenExpenseType.AddWeaponGear:
                    // Locate the Gear that was added.
                    WeaponAccessory objFoundAccessory = new WeaponAccessory(_objCharacter);
                    Gear objFoundAccGear = _objFunctions.FindWeaponGear(objEntry.Undo.ObjectId, _objCharacter.Weapons, out objFoundAccessory);
                    _objFunctions.DeleteGear(objFoundAccGear, treWeapons, _objImprovementManager);
                    if (objFoundAccGear.Parent == null)
                        objFoundAccessory.Gear.Remove(objFoundAccGear);
                    else
                        objFoundAccGear.Parent.Children.Remove(objFoundAccGear);
                    TreeNode objFoundAccNode = _objFunctions.FindNode(objFoundAccGear.InternalId, treWeapons);
                    objFoundAccNode.Remove();
                    break;
                case NuyenExpenseType.ManualAdd:
                case NuyenExpenseType.ManualSubtract:
                    break;
            }
            // Refund the Nuyen amount and remove the Expense Entry.
            _objCharacter.Nuyen -= objEntry.Amount;
            _objCharacter.ExpenseEntries.Remove(objEntry);

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Exemplo n.º 21
0
        private void tsWeaponAccessoryGearMenuAddAsPlugin_Click(object sender, EventArgs e)
        {
            // Locate the Vehicle Sensor Gear.
            bool blnFound = false;
            WeaponAccessory objFoundAccessory = new WeaponAccessory(_objCharacter);
            Gear objSensor = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objFoundAccessory);
            if (objSensor != null)
                blnFound = true;

            // Make sure the Gear was found.
            if (!blnFound)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_ModifyVehicleGear"), LanguageManager.Instance.GetString("MessageTitle_SelectGear"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");

            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSensor.Name + "\" and category = \"" + objSensor.Category + "\"]");

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter);
            //frmPickGear.ShowNegativeCapacityOnly = true;

            if (objXmlGear.InnerXml.Contains("<addoncategory>"))
            {
                string strCategories = "";
                foreach (XmlNode objXmlCategory in objXmlGear.SelectNodes("addoncategory"))
                    strCategories += objXmlCategory.InnerText + ",";
                // Remove the trailing comma.
                strCategories = strCategories.Substring(0, strCategories.Length - 1);
                frmPickGear.AddCategory(strCategories);
            }

            if (frmPickGear.AllowedCategories != "")
                frmPickGear.AllowedCategories += objSensor.Category + ",";

            frmPickGear.ShowDialog(this);

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

            // Open the Gear XML file and locate the selected piece.
            objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            Gear objGear = new Gear(_objCharacter);

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlinks":
                case "Cyberdecks":
                case "Rigger Command Consoles":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objCommlink.DisplayName;

                    objGear = objCommlink;
                    break;
                default:
                    Gear objNewGear = new Gear(_objCharacter);
                    objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objNewGear.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objNewGear.DisplayName;

                    objGear = objNewGear;
                    break;
            }

            if (objGear.InternalId == Guid.Empty.ToString())
                return;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objGear.Cost = (Convert.ToDouble(objGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objGear.Cost != "")
                    objGear.Cost = "(" + objGear.Cost + ") * 0.1";
                if (objGear.Cost3 != "")
                    objGear.Cost3 = "(" + objGear.Cost3 + ") * 0.1";
                if (objGear.Cost6 != "")
                    objGear.Cost6 = "(" + objGear.Cost6 + ") * 0.1";
                if (objGear.Cost10 != "")
                    objGear.Cost10 = "(" + objGear.Cost10 + ") * 0.1";
                if (objGear.Extra == "")
                    objGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objGear.Cost = "0";
                objGear.Cost3 = "0";
                objGear.Cost6 = "0";
                objGear.Cost10 = "0";
            }

            objNode.Text = objGear.DisplayName;

            objNode.ContextMenuStrip = cmsWeaponAccessoryGear;

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

            objGear.Parent = objSensor;
            objSensor.Children.Add(objGear);

            if (frmPickGear.AddAgain)
                tsWeaponAccessoryGearMenuAddAsPlugin_Click(sender, e);

            UpdateCharacterInfo();
            RefreshSelectedWeapon();
        }
Exemplo n.º 22
0
        private void tsVehicleAddWeaponAccessory_Click(object sender, EventArgs e)
        {
            // Attempt to locate the selected VehicleWeapon.
            bool blnWeaponFound = false;
            Vehicle objFoundVehicle = new Vehicle(_objCharacter);
            Weapon objWeapon = _objFunctions.FindVehicleWeapon(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
            if (objWeapon != null)
                blnWeaponFound = true;

            if (!blnWeaponFound)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_VehicleWeaponAccessories"), LanguageManager.Instance.GetString("MessageTitle_VehicleWeaponAccessories"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

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

            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + treVehicles.SelectedNode.Text + "\"]");

            frmSelectWeaponAccessory frmPickWeaponAccessory = new frmSelectWeaponAccessory(_objCharacter, true);

            if (objXmlWeapon == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Make sure the Weapon allows Accessories to be added to it.
            if (!Convert.ToBoolean(objXmlWeapon["allowaccessory"].InnerText))
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                XmlNodeList objXmlMountList = objXmlWeapon.SelectNodes("accessorymounts/mount");
                string strMounts = "";
                foreach (XmlNode objXmlMount in objXmlMountList)
                {
                    // Run through the Weapon's currenct Accessories and filter out any used up Mount points.
                    bool blnFound = false;
                    foreach (WeaponAccessory objCurrentAccessory in objWeapon.WeaponAccessories)
                    {
                        if (objCurrentAccessory.Mount == objXmlMount.InnerText)
                            blnFound = true;
                    }
                    if (!blnFound)
                        strMounts += objXmlMount.InnerText + "/";
                }
                frmPickWeaponAccessory.AllowedMounts = strMounts;
            }

            frmPickWeaponAccessory.WeaponCost = objWeapon.Cost;
            frmPickWeaponAccessory.AccessoryMultiplier = objWeapon.AccessoryMultiplier;
            frmPickWeaponAccessory.ShowDialog();

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

            // Locate the selected piece.
            objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + frmPickWeaponAccessory.SelectedAccessory + "\"]");

            TreeNode objNode = new TreeNode();
            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
            objAccessory.Create(objXmlWeapon, objNode, frmPickWeaponAccessory.SelectedMount);
            objAccessory.Parent = objWeapon;

            // Check the item's Cost and make sure the character can afford it.
            int intOriginalCost = objWeapon.TotalCost;
            objWeapon.WeaponAccessories.Add(objAccessory);

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

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

            if (!frmPickWeaponAccessory.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    objWeapon.WeaponAccessories.Remove(objAccessory);
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (frmPickWeaponAccessory.AddAgain)
                        tsVehicleAddWeaponAccessory_Click(sender, e);

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

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddVehicleWeaponAccessory, objAccessory.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            objNode.ContextMenuStrip = cmsVehicleWeaponAccessory;
            treVehicles.SelectedNode.Nodes.Add(objNode);
            treVehicles.SelectedNode.Expand();

            if (frmPickWeaponAccessory.AddAgain)
                tsVehicleAddWeaponAccessory_Click(sender, e);

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Exemplo n.º 23
0
        /// <summary>
        /// Add a PACKS Kit to the character.
        /// </summary>
        public void AddPACKSKit()
        {
            frmSelectPACKSKit frmPickPACKSKit = new frmSelectPACKSKit(_objCharacter);
            frmPickPACKSKit.ShowDialog(this);

            bool blnCreateChildren = true;

            // If the form was canceled, don't do anything.
            if (frmPickPACKSKit.DialogResult == DialogResult.Cancel)
                return;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("packs.xml");

            // Do not create child items for Gear if the chosen Kit is in the Custom category since these items will contain the exact plugins desired.
            if (frmPickPACKSKit.SelectedCategory == "Custom")
                blnCreateChildren = false;

            XmlNode objXmlKit = objXmlDocument.SelectSingleNode("/chummer/packs/pack[name = \"" + frmPickPACKSKit.SelectedKit + "\" and category = \"" + frmPickPACKSKit.SelectedCategory + "\"]");
            // Update Qualities.
            if (objXmlKit["qualities"] != null)
            {
                XmlDocument objXmlQualityDocument = XmlManager.Instance.Load("qualities.xml");

                // Positive Qualities.
                foreach (XmlNode objXmlQuality in objXmlKit.SelectNodes("qualities/positive/quality"))
                {
                    XmlNode objXmlQualityNode = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQuality.InnerText + "\"]");

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

                    if (objXmlQuality.Attributes["select"] != null)
                        strForceValue = objXmlQuality.Attributes["select"].InnerText;

                    objQuality.Create(objXmlQualityNode, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes, strForceValue);
                    _objCharacter.Qualities.Add(objQuality);

                    treQualities.Nodes[0].Nodes.Add(objNode);
                    treQualities.Nodes[0].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();
                    }
                }

                // Negative Qualities.
                foreach (XmlNode objXmlQuality in objXmlKit.SelectNodes("qualities/negative/quality"))
                {
                    XmlNode objXmlQualityNode = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQuality.InnerText + "\"]");

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

                    if (objXmlQuality.Attributes["select"] != null)
                        strForceValue = objXmlQuality.Attributes["select"].InnerText;

                    objQuality.Create(objXmlQualityNode, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes, strForceValue);
                    _objCharacter.Qualities.Add(objQuality);

                    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();
                    }
                }
            }

            // Update Attributes.
            if (objXmlKit["attributes"] != null)
            {
                // Reset all Attributes back to 1 so we don't go over any BP limits.
                nudBOD.Value = nudBOD.Minimum;
                nudAGI.Value = nudAGI.Minimum;
                nudREA.Value = nudREA.Minimum;
                nudSTR.Value = nudSTR.Minimum;
                nudCHA.Value = nudCHA.Minimum;
                nudINT.Value = nudINT.Minimum;
                nudLOG.Value = nudLOG.Minimum;
                nudWIL.Value = nudWIL.Minimum;
                nudEDG.Value = nudEDG.Minimum;
                nudMAG.Value = nudMAG.Minimum;
                nudRES.Value = nudRES.Minimum;
                foreach (XmlNode objXmlAttribute in objXmlKit["attributes"])
                {
                    // The Attribute is calculated as given value - (6 - Metatype Maximum) so that each Metatype has the values from the file adjusted correctly.
                    switch (objXmlAttribute.Name)
                    {
                        case "bod":
                            nudBOD.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.BOD.MetatypeMaximum);
                            break;
                        case "agi":
                            nudAGI.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.AGI.MetatypeMaximum);
                            break;
                        case "rea":
                            nudREA.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.REA.MetatypeMaximum);
                            break;
                        case "str":
                            nudSTR.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.STR.MetatypeMaximum);
                            break;
                        case "cha":
                            nudCHA.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.CHA.MetatypeMaximum);
                            break;
                        case "int":
                            nudINT.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.INT.MetatypeMaximum);
                            break;
                        case "log":
                            nudLOG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.LOG.MetatypeMaximum);
                            break;
                        case "wil":
                            nudWIL.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.WIL.MetatypeMaximum);
                            break;
                        case "mag":
                            nudMAG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.MAG.MetatypeMaximum);
                            break;
                        case "res":
                            nudRES.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.RES.MetatypeMaximum);
                            break;
                        default:
                            nudEDG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.EDG.MetatypeMaximum);
                            break;
                    }
                }
            }

            // Update Skills.
            if (objXmlKit["skills"] != null)
            {
                // Active Skills.
                foreach (XmlNode objXmlSkill in objXmlKit.SelectNodes("skills/skill"))
                {
                    if (objXmlSkill["name"].InnerText.Contains("Exotic"))
                    {
                        int i = panActiveSkills.Controls.Count;
                        Skill objSkill = new Skill(_objCharacter);

                        SkillControl objSkillControl = new SkillControl(_objCharacter);
                        objSkillControl.SkillObject = objSkill;
                        objSkillControl.Width = 510;

                        // Attach an EventHandler for the RatingChanged and SpecializationChanged Events.
                        objSkillControl.RatingChanged += objActiveSkill_RatingChanged;
                        objSkillControl.SpecializationChanged += objSkill_SpecializationChanged;
                        objSkillControl.SkillName = objXmlSkill["name"].InnerText;

                        switch (objXmlSkill["name"].InnerText)
                        {
                            case "Exotic Ranged Weapon":
                            case "Exotic Melee Weapon":
                                objSkill.Attribute = "AGI";
                                objSkillControl.SkillCategory = "Combat Active";
                                objSkill.Default = true;
                                break;
                            default:
                                objSkill.Attribute = "REA";
                                objSkillControl.SkillCategory = "Vehicle Active";
                                objSkill.Default = false;
                                break;
                        }
                        objSkill.ExoticSkill = true;
                        _objCharacter.Skills.Add(objSkill);


						if (_objCharacter.IgnoreRules)
						{
							objSkillControl.SkillRatingMaximum = 12;
						}
						else
						{
							objSkillControl.SkillRatingMaximum = 6;
						}

						// Make sure it's not going above the maximum number.
						if (Convert.ToInt32(objXmlSkill["rating"].InnerText) > objSkillControl.SkillRatingMaximum)
                            objSkillControl.SkillRating = objSkillControl.SkillRatingMaximum;
                        else
                            objSkillControl.SkillRating = Convert.ToInt32(objXmlSkill["rating"].InnerText);

                        if (objXmlSkill["spec"] != null)
                            objSkillControl.SkillSpec = objXmlSkill["spec"].InnerText;
                        else
                            objSkillControl.SkillSpec = "";

                        // Set the SkillControl's Location since scrolling the Panel causes it to actually change the child Controls' Locations.
                        objSkillControl.Location = new Point(0, objSkillControl.Height * i + panActiveSkills.AutoScrollPosition.Y);
                        panActiveSkills.Controls.Add(objSkillControl);
                    }
                    else
                    {
                        // Find the correct Skill Control.
                        SkillControl objSkillControl = new SkillControl(_objCharacter);
                        foreach (SkillControl objControl in panActiveSkills.Controls)
                        {
                            if (objControl.SkillName == objXmlSkill["name"].InnerText)
                            {
                                objSkillControl = objControl;
                                break;
                            }
                        }

                        // Make sure it's not going above the maximum number.
                        if (Convert.ToInt32(objXmlSkill["rating"].InnerText) > objSkillControl.SkillRatingMaximum)
                            objSkillControl.SkillRating = objSkillControl.SkillRatingMaximum;
                        else
                            objSkillControl.SkillRating = Convert.ToInt32(objXmlSkill["rating"].InnerText);

                        if (objXmlSkill["spec"] != null)
                            objSkillControl.SkillSpec = objXmlSkill["spec"].InnerText;
                        else
                            objSkillControl.SkillSpec = "";
                    }
                }

                // Skill Groups.
                foreach (XmlNode objXmlGroup in objXmlKit.SelectNodes("skills/skillgroup"))
                {
                    // Find the correct SkillGroupControl.
                    SkillGroupControl objSkillGroupControl = new SkillGroupControl(_objCharacter.Options, _objCharacter);
                    foreach (SkillGroupControl objControl in panSkillGroups.Controls)
                    {
                        if (objControl.GroupName == objXmlGroup["name"].InnerText)
                        {
                            objSkillGroupControl = objControl;
                            break;
                        }
                    }

                    // Make sure it's not going above the maximum number.
                    if (Convert.ToInt32(objXmlGroup["base"].InnerText) > objSkillGroupControl.GroupRatingMaximum)
                    {
                        objSkillGroupControl.BaseRating = objSkillGroupControl.GroupRatingMaximum;
                        objSkillGroupControl.KarmaRating = 0;
                    }
                    else if (Convert.ToInt32(objXmlGroup["base"].InnerText) + Convert.ToInt32(objXmlGroup["karma"].InnerText) > objSkillGroupControl.GroupRatingMaximum)
                    {
                        objSkillGroupControl.BaseRating = Convert.ToInt32(objXmlGroup["base"].InnerText);
                        objSkillGroupControl.KarmaRating = objSkillGroupControl.GroupRatingMaximum - objSkillGroupControl.BaseRating;
                    }
                    else
                    {
                        objSkillGroupControl.BaseRating = Convert.ToInt32(objXmlGroup["base"].InnerText);
                        objSkillGroupControl.KarmaRating = Convert.ToInt32(objXmlGroup["karma"].InnerText);
                    }
                }
            }

            // Update Knowledge Skills.
            if (objXmlKit["knowledgeskills"] != null)
            {
                foreach (XmlNode objXmlSkill in objXmlKit.SelectNodes("knowledgeskills/skill"))
                {
                    int i = panKnowledgeSkills.Controls.Count;
                    Skill objSkill = new Skill(_objCharacter);
                    objSkill.Name = objXmlSkill["name"].InnerText;

                    SkillControl objSkillControl = new SkillControl(_objCharacter);
                    objSkillControl.SkillObject = objSkill;

                    // Attach an EventHandler for the RatingChanged and SpecializationChanged Events.
                    objSkillControl.RatingChanged += objKnowledgeSkill_RatingChanged;
                    objSkillControl.SpecializationChanged += objSkill_SpecializationChanged;
                    objSkillControl.DeleteSkill += objKnowledgeSkill_DeleteSkill;

                    objSkillControl.KnowledgeSkill = true;
                    objSkillControl.AllowDelete = true;

					if (_objCharacter.IgnoreRules)
					{
						objSkillControl.SkillRatingMaximum = 12;
					}
					else
					{
						objSkillControl.SkillRatingMaximum = 6;
					}
					// Set the SkillControl's Location since scrolling the Panel causes it to actually change the child Controls' Locations.
					objSkillControl.Location = new Point(0, objSkillControl.Height * i + panKnowledgeSkills.AutoScrollPosition.Y);
                    panKnowledgeSkills.Controls.Add(objSkillControl);

                    objSkillControl.SkillName = objXmlSkill["name"].InnerText;

                    // Make sure it's not going above the maximum number.
                    if (Convert.ToInt32(objXmlSkill["rating"].InnerText) > objSkillControl.SkillRatingMaximum)
                        objSkillControl.SkillRating = objSkillControl.SkillRatingMaximum;
                    else
                        objSkillControl.SkillRating = Convert.ToInt32(objXmlSkill["rating"].InnerText);

                    if (objXmlSkill["spec"] != null)
                        objSkillControl.SkillSpec = objXmlSkill["spec"].InnerText;
                    else
                        objSkillControl.SkillSpec = "";

                    if (objXmlSkill["category"] != null)
                        objSkillControl.SkillCategory = objXmlSkill["category"].InnerText;

                    _objCharacter.Skills.Add(objSkill);
                }
            }

            // Select a Martial Art.
            if (objXmlKit["selectmartialart"] != null)
            {
                string strForcedValue = "";
                int intRating = 1;
                if (objXmlKit["selectmartialart"].Attributes["select"] != null)
                    strForcedValue = objXmlKit["selectmartialart"].Attributes["select"].InnerText;
                if (objXmlKit["selectmartialart"].Attributes["rating"] != null)
                    intRating = Convert.ToInt32(objXmlKit["selectmartialart"].Attributes["rating"].InnerText);

                frmSelectMartialArt frmPickMartialArt = new frmSelectMartialArt(_objCharacter);
                frmPickMartialArt.ForcedValue = strForcedValue;
                frmPickMartialArt.ShowDialog(this);

                if (frmPickMartialArt.DialogResult != DialogResult.Cancel)
                {
                    // Open the Martial Arts XML file and locate the selected piece.
                    XmlDocument objXmlMartialArtDocument = XmlManager.Instance.Load("martialarts.xml");

                    XmlNode objXmlArt = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + frmPickMartialArt.SelectedMartialArt + "\"]");

                    TreeNode objNode = new TreeNode();
                    MartialArt objMartialArt = new MartialArt(_objCharacter);
                    objMartialArt.Create(objXmlArt, objNode, _objCharacter);
                    objMartialArt.Rating = intRating;
                    _objCharacter.MartialArts.Add(objMartialArt);

                    objNode.ContextMenuStrip = cmsMartialArts;

                    treMartialArts.Nodes[0].Nodes.Add(objNode);
                    treMartialArts.Nodes[0].Expand();

                    treMartialArts.SelectedNode = objNode;
                }
            }

            // Update Martial Arts.
            if (objXmlKit["martialarts"] != null)
            {
                // Open the Martial Arts XML file and locate the selected art.
                XmlDocument objXmlMartialArtDocument = XmlManager.Instance.Load("martialarts.xml");

                foreach (XmlNode objXmlArt in objXmlKit.SelectNodes("martialarts/martialart"))
                {
                    TreeNode objNode = new TreeNode();
                    MartialArt objArt = new MartialArt(_objCharacter);
                    XmlNode objXmlArtNode = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + objXmlArt["name"].InnerText + "\"]");
                    objArt.Create(objXmlArtNode, objNode, _objCharacter);
                    objArt.Rating = Convert.ToInt32(objXmlArt["rating"].InnerText);
                    _objCharacter.MartialArts.Add(objArt);

                    // Check for Advantages.
                    foreach (XmlNode objXmlAdvantage in objXmlArt.SelectNodes("techniques/technique"))
                    {
                        TreeNode objChildNode = new TreeNode();
                        MartialArtAdvantage objAdvantage = new MartialArtAdvantage(_objCharacter);
                        XmlNode objXmlAdvantageNode = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + objXmlArt["name"].InnerText + "\"]/techniques/technique[. = \"" + objXmlAdvantage.InnerText + "\"]");
                        objAdvantage.Create(objXmlAdvantageNode, _objCharacter, objChildNode);
                        objArt.Advantages.Add(objAdvantage);

                        objNode.Nodes.Add(objChildNode);
                        objNode.Expand();
                    }

                    treMartialArts.Nodes[0].Nodes.Add(objNode);
                    treMartialArts.Nodes[0].Expand();
                }
            }

            // Update Adept Powers.
            if (objXmlKit["powers"] != null)
            {
                // Open the Powers XML file and locate the selected power.
                XmlDocument objXmlPowerDocument = XmlManager.Instance.Load("powers.xml");

                foreach (XmlNode objXmlPower in objXmlKit.SelectNodes("powers/power"))
                {
                    XmlNode objXmlPowerNode = objXmlPowerDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower["name"].InnerText + "\"]");

                    int i = panPowers.Controls.Count;

                    Power objPower = new Power(_objCharacter);
                    _objCharacter.Powers.Add(objPower);

                    PowerControl objPowerControl = new PowerControl();
                    objPowerControl.PowerObject = objPower;

                    // Attach an EventHandler for the PowerRatingChanged Event.
                    objPowerControl.PowerRatingChanged += objPower_PowerRatingChanged;
                    objPowerControl.DeletePower += objPower_DeletePower;

                    objPowerControl.PowerName = objXmlPowerNode["name"].InnerText;
                    objPowerControl.PointsPerLevel = Convert.ToDecimal(objXmlPowerNode["points"].InnerText, GlobalOptions.Instance.CultureInfo);
                    objPowerControl.AdeptWayDiscount = Convert.ToDecimal(objXmlPowerNode["adeptway"].InnerText, GlobalOptions.Instance.CultureInfo);
                    if (objXmlPowerNode["levels"].InnerText == "no")
                    {
                        objPowerControl.LevelEnabled = false;
                    }
                    else
                    {
                        objPowerControl.LevelEnabled = true;
                        if (objXmlPowerNode["levels"].InnerText != "yes")
                            objPower.MaxLevels = Convert.ToInt32(objXmlPowerNode["levels"].InnerText);
                    }

                    objPower.Source = objXmlPowerNode["source"].InnerText;
                    objPower.Page = objXmlPowerNode["page"].InnerText;
                    if (objXmlPowerNode["doublecost"] != null)
                        objPower.DoubleCost = false;

                    if (objXmlPowerNode.InnerXml.Contains("bonus"))
                    {
                        objPower.Bonus = objXmlPowerNode["bonus"];

                        if (objXmlPower["name"].Attributes["select"] != null)
                            _objImprovementManager.ForcedValue = objXmlPower["name"].Attributes["select"].InnerText;

                        _objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Power, objPower.InternalId, objPower.Bonus, false, Convert.ToInt32(objPower.Rating), objPower.DisplayNameShort);
                        objPowerControl.Extra = _objImprovementManager.SelectedValue;
                    }

                    objPowerControl.Top = i * objPowerControl.Height;
                    panPowers.Controls.Add(objPowerControl);

                    // Set the Rating of the Power if applicable.
                    if (objXmlPower["rating"] != null)
                        objPowerControl.PowerLevel = Convert.ToInt32(objXmlPower["rating"].InnerText);
                }
            }

            // Update Complex Forms.
            if (objXmlKit["programs"] != null)
            {
                // Open the Programs XML file and locate the selected program.
                XmlDocument objXmlProgramDocument = XmlManager.Instance.Load("complexforms.xml");

                foreach (XmlNode objXmlProgram in objXmlKit.SelectNodes("complexforms/complexform"))
                {
                    XmlNode objXmlProgramNode = objXmlProgramDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + objXmlProgram["name"].InnerText + "\"]");

                    string strForceValue = "";
                    if (objXmlProgram.Attributes["select"] != null)
                        strForceValue = objXmlProgram.Attributes["select"].InnerText;

                    TreeNode objNode = new TreeNode();
                    ComplexForm objProgram = new ComplexForm(_objCharacter);
                    objProgram.Create(objXmlProgramNode, _objCharacter, objNode, strForceValue);

                    treComplexForms.Nodes[0].Nodes.Add(objNode);
                    treComplexForms.Nodes[0].Expand();

                    _objCharacter.ComplexForms.Add(objProgram);

                    treComplexForms.SortCustom();
                }
            }

            // Update Spells.
            if (objXmlKit["spells"] != null)
            {
                XmlDocument objXmlSpellDocument = XmlManager.Instance.Load("spells.xml");

                foreach (XmlNode objXmlSpell in objXmlKit.SelectNodes("spells/spell"))
                {
                    // Make sure the Spell has not already been added to the character.
                    bool blnFound = false;
                    foreach (TreeNode nodSpell in treSpells.Nodes[0].Nodes)
                    {
                        if (nodSpell.Text == objXmlSpell.InnerText)
                        {
                            blnFound = true;
                            break;
                        }
                    }

                    // The Spell is not in the list, so add it.
                    if (!blnFound)
                    {
                        string strForceValue = "";
                        if (objXmlSpell.Attributes["select"] != null)
                            strForceValue = objXmlSpell.Attributes["select"].InnerText;

                        XmlNode objXmlSpellNode = objXmlSpellDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + objXmlSpell.InnerText + "\"]");

                        Spell objSpell = new Spell(_objCharacter);
                        TreeNode objNode = new TreeNode();
                        objSpell.Create(objXmlSpellNode, _objCharacter, objNode, strForceValue);
                        objNode.ContextMenuStrip = cmsSpell;
                        _objCharacter.Spells.Add(objSpell);

                        switch (objSpell.Category)
                        {
                            case "Combat":
                                treSpells.Nodes[0].Nodes.Add(objNode);
                                treSpells.Nodes[0].Expand();
                                break;
                            case "Detection":
                                treSpells.Nodes[1].Nodes.Add(objNode);
                                treSpells.Nodes[1].Expand();
                                break;
                            case "Health":
                                treSpells.Nodes[2].Nodes.Add(objNode);
                                treSpells.Nodes[2].Expand();
                                break;
                            case "Illusion":
                                treSpells.Nodes[3].Nodes.Add(objNode);
                                treSpells.Nodes[3].Expand();
                                break;
                            case "Manipulation":
                                treSpells.Nodes[4].Nodes.Add(objNode);
                                treSpells.Nodes[4].Expand();
                                break;
                            case "Rituals":
                                int intNode = 5;
                                if (_objCharacter.AdeptEnabled && !_objCharacter.MagicianEnabled)
                                    intNode = 0;
                                treSpells.Nodes[intNode].Nodes.Add(objNode);
                                treSpells.Nodes[intNode].Expand();
                                break;
                        }

                        treSpells.SortCustom();
                    }
                }
            }

            // Update Spirits.
            if (objXmlKit["spirits"] != null)
            {
                foreach (XmlNode objXmlSpirit in objXmlKit.SelectNodes("spirits/spirit"))
                {
                    int i = panSpirits.Controls.Count;

                    Spirit objSpirit = new Spirit(_objCharacter);
                    _objCharacter.Spirits.Add(objSpirit);

                    SpiritControl objSpiritControl = new SpiritControl();
                    objSpiritControl.SpiritObject = objSpirit;
                    objSpiritControl.EntityType = SpiritType.Spirit;

                    // Attach an EventHandler for the ServicesOwedChanged Event.
                    objSpiritControl.ServicesOwedChanged += objSpirit_ServicesOwedChanged;
                    objSpiritControl.ForceChanged += objSpirit_ForceChanged;
                    objSpiritControl.BoundChanged += objSpirit_BoundChanged;
                    objSpiritControl.DeleteSpirit += objSpirit_DeleteSpirit;

                    objSpiritControl.Name = objXmlSpirit["name"].InnerText;
                    objSpiritControl.Force = Convert.ToInt32(objXmlSpirit["force"].InnerText);
                    objSpiritControl.ServicesOwed = Convert.ToInt32(objXmlSpirit["services"].InnerText);

                    objSpiritControl.Top = i * objSpiritControl.Height;
                    panSpirits.Controls.Add(objSpiritControl);
                }
            }

            // Update Lifestyles.
            if (objXmlKit["lifestyles"] != null)
            {
                XmlDocument objXmlLifestyleDocument = XmlManager.Instance.Load("lifestyles.xml");

                foreach (XmlNode objXmlLifestyle in objXmlKit.SelectNodes("lifestyles/lifestyle"))
                {
                    string strName = objXmlLifestyle["name"].InnerText;
                    int intMonths = Convert.ToInt32(objXmlLifestyle["months"].InnerText);

                    // Create the Lifestyle.
                    TreeNode objNode = new TreeNode();
                    Lifestyle objLifestyle = new Lifestyle(_objCharacter);

                    XmlNode objXmlLifestyleNode = objXmlLifestyleDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + strName + "\"]");
                    if (objXmlLifestyleNode != null)
                    {
                        // This is a standard Lifestyle, so just use the Create method.
                        objLifestyle.Create(objXmlLifestyleNode, objNode);
                        objLifestyle.Months = intMonths;
                    }
                    else
                    {
                        // This is an Advanced Lifestyle, so build it manually.
                        objLifestyle.Name = strName;
                        objLifestyle.Months = intMonths;
                        objLifestyle.Cost = Convert.ToInt32(objXmlLifestyle["cost"].InnerText);
                        objLifestyle.Dice = Convert.ToInt32(objXmlLifestyle["dice"].InnerText);
                        objLifestyle.Multiplier = Convert.ToInt32(objXmlLifestyle["multiplier"].InnerText);
                        objLifestyle.BaseLifestyle = objXmlLifestyle["baselifestyle"].InnerText;
                        objLifestyle.Source = "SR5";
                        objLifestyle.Page = "373";
                        objLifestyle.Comforts = Convert.ToInt32(objXmlLifestyle["comforts"].InnerText);
                        objLifestyle.ComfortsEntertainment = Convert.ToInt32(objXmlLifestyle["comfortsentertainment"].InnerText);
                        objLifestyle.Security = Convert.ToInt32(objXmlLifestyle["security"].InnerText);
                        objLifestyle.SecurityEntertainment = Convert.ToInt32(objXmlLifestyle["securityentertainment"].InnerText);
                        objLifestyle.Area = Convert.ToInt32(objXmlLifestyle["area"].InnerText);
                        objLifestyle.AreaEntertainment = Convert.ToInt32(objXmlLifestyle["areaentertainment"].InnerText);

                        foreach (LifestyleQuality objXmlQuality in objXmlLifestyle.SelectNodes("lifestylequalities/lifestylequality"))
                            objLifestyle.LifestyleQualities.Add(objXmlQuality);

                        objNode.Text = strName;
                    }

                    // Add the Lifestyle to the character and Lifestyle Tree.
                    if (objLifestyle.BaseLifestyle != "")
                        objNode.ContextMenuStrip = cmsAdvancedLifestyle;
                    else
                        objNode.ContextMenuStrip = cmsLifestyleNotes;
                    _objCharacter.Lifestyles.Add(objLifestyle);
                    treLifestyles.Nodes[0].Nodes.Add(objNode);
                    treLifestyles.Nodes[0].Expand();
                }
            }

            // Update NuyenBP.
            if (objXmlKit["nuyenbp"] != null)
            {
                int intAmount = Convert.ToInt32(objXmlKit["nuyenbp"].InnerText);
                //if (_objCharacter.BuildMethod == CharacterBuildMethod.Karma)
                //intAmount *= 2;

                // Make sure we don't go over the field's maximum which would throw an Exception.
                if (nudNuyen.Value + intAmount > nudNuyen.Maximum)
                    nudNuyen.Value = nudNuyen.Maximum;
                else
                    nudNuyen.Value += intAmount;
            }

            // Update Armor.
            if (objXmlKit["armors"] != null)
            {
                XmlDocument objXmlArmorDocument = XmlManager.Instance.Load("armor.xml");

                foreach (XmlNode objXmlArmor in objXmlKit.SelectNodes("armors/armor"))
                {
                    XmlNode objXmlArmorNode = objXmlArmorDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objXmlArmor["name"].InnerText + "\"]");

                    Armor objArmor = new Armor(_objCharacter);
                    TreeNode objNode = new TreeNode();
                    objArmor.Create(objXmlArmorNode, objNode, cmsArmorMod, Convert.ToInt32(objXmlArmor["rating"].InnerText), false, blnCreateChildren);
                    _objCharacter.Armor.Add(objArmor);

                    // Look for Armor Mods.
                    if (objXmlArmor["mods"] != null)
                    {
                        foreach (XmlNode objXmlMod in objXmlArmor.SelectNodes("mods/mod"))
                        {
                            List<Weapon> lstWeapons = new List<Weapon>();
                            List<TreeNode> lstWeaponNodes = new List<TreeNode>();
                            XmlNode objXmlModNode = objXmlArmorDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]");
                            ArmorMod objMod = new ArmorMod(_objCharacter);
                            TreeNode objModNode = new TreeNode();
                            int intRating = 0;
                            if (objXmlMod["rating"] != null)
                                intRating = Convert.ToInt32(objXmlMod["rating"].InnerText);
                            objMod.Create(objXmlModNode, objModNode, intRating, lstWeapons, lstWeaponNodes);
                            objModNode.ContextMenuStrip = cmsArmorMod;
                            objMod.Parent = objArmor;

                            objArmor.ArmorMods.Add(objMod);

                            objNode.Nodes.Add(objModNode);
                            objNode.Expand();

                            // 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();
                            }
                        }
                    }

                    XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");
                    foreach (XmlNode objXmlGear in objXmlArmor.SelectNodes("gears/gear"))
                        AddPACKSGear(objXmlGearDocument, objXmlGear, objNode, objArmor, cmsArmorGear, blnCreateChildren);

                    objNode.ContextMenuStrip = cmsArmor;
                    treArmor.Nodes[0].Nodes.Add(objNode);
                    treArmor.Nodes[0].Expand();
                }
            }

            // Update Weapons.
            if (objXmlKit["weapons"] != null)
            {
                XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml");

                pgbProgress.Visible = true;
                pgbProgress.Value = 0;
                pgbProgress.Maximum = objXmlKit.SelectNodes("weapons/weapon").Count;
                int i = 0;
                foreach (XmlNode objXmlWeapon in objXmlKit.SelectNodes("weapons/weapon"))
                {
                    i++;
                    pgbProgress.Value = i;
                    Application.DoEvents();

                    XmlNode objXmlWeaponNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["name"].InnerText + "\"]");

                    Weapon objWeapon = new Weapon(_objCharacter);
                    TreeNode objNode = new TreeNode();
                    objWeapon.Create(objXmlWeaponNode, _objCharacter, objNode, cmsWeapon, cmsWeaponAccessory, cmsWeaponMod, blnCreateChildren);
                    _objCharacter.Weapons.Add(objWeapon);

                    // Look for Weapon Accessories.
                    if (objXmlWeapon["accessories"] != null)
                    {
                        foreach (XmlNode objXmlAccessory in objXmlWeapon.SelectNodes("accessories/accessory"))
                        {
                            XmlNode objXmlAccessoryNode = objXmlWeaponDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + objXmlAccessory["name"].InnerText + "\"]");
                            WeaponAccessory objMod = new WeaponAccessory(_objCharacter);
                            TreeNode objModNode = new TreeNode();
                            string strMount = "";
							int intRating = 0;
                            if (objXmlAccessory["mount"] != null)
                                strMount = objXmlAccessory["mount"].InnerText;
                            objMod.Create(objXmlAccessoryNode, objModNode, strMount, intRating);
                            objModNode.ContextMenuStrip = cmsWeaponAccessory;
                            objMod.Parent = objWeapon;

                            objWeapon.WeaponAccessories.Add(objMod);

                            XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");
                            foreach (XmlNode objXmlGear in objXmlAccessory.SelectNodes("gears/gear"))
                                AddPACKSGear(objXmlGearDocument, objXmlGear, objModNode, objMod, cmsWeaponAccessoryGear, blnCreateChildren);

                            objNode.Nodes.Add(objModNode);
                            objNode.Expand();
                        }
                    }

                    // Look for Weapon Mods.
                    if (objXmlWeapon["mods"] != null)
                    {
                        foreach (XmlNode objXmlMod in objXmlWeapon.SelectNodes("mods/mod"))
                        {
                            XmlNode objXmlModNode = objXmlWeaponDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]");
                            WeaponMod objMod = new WeaponMod(_objCharacter);
                            TreeNode objModNode = new TreeNode();
                            objMod.Create(objXmlModNode, objModNode);
                            objModNode.ContextMenuStrip = cmsWeaponMod;
                            objMod.Parent = objWeapon;

                            objWeapon.WeaponMods.Add(objMod);

                            objNode.Nodes.Add(objModNode);
                            objNode.Expand();
                        }
                    }

                    // Look for an Underbarrel Weapon.
                    if (objXmlWeapon["underbarrel"] != null)
                    {
                        XmlNode objXmlUnderbarrelNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["underbarrel"].InnerText + "\"]");

                        Weapon objUnderbarrelWeapon = new Weapon(_objCharacter);
                        TreeNode objUnderbarrelNode = new TreeNode();
                        objUnderbarrelWeapon.Create(objXmlUnderbarrelNode, _objCharacter, objUnderbarrelNode, cmsWeapon, cmsWeaponAccessory, cmsWeaponMod, blnCreateChildren);
                        objWeapon.UnderbarrelWeapons.Add(objUnderbarrelWeapon);
                        objNode.Nodes.Add(objUnderbarrelNode);
                        objNode.Expand();
                    }

                    objNode.ContextMenuStrip = cmsWeapon;
                    treWeapons.Nodes[0].Nodes.Add(objNode);
                    treWeapons.Nodes[0].Expand();

                    Application.DoEvents();
                }
            }

            // Update Cyberware.
            if (objXmlKit["cyberwares"] != null)
            {
                XmlDocument objXmlCyberwareDocument = XmlManager.Instance.Load("cyberware.xml");
                XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");

                pgbProgress.Visible = true;
                pgbProgress.Value = 0;
                pgbProgress.Maximum = objXmlKit.SelectNodes("cyberwares/cyberware").Count;
                int i = 0;
                foreach (XmlNode objXmlCyberware in objXmlKit.SelectNodes("cyberwares/cyberware"))
                {
                    i++;
                    pgbProgress.Value = i;
                    Application.DoEvents();

                    List<Weapon> objWeapons = new List<Weapon>();
                    List<TreeNode> objWeaponNodes = new List<TreeNode>();
                    TreeNode objNode = new TreeNode();
                    Cyberware objCyberware = new Cyberware(_objCharacter);
                    Grade objGrade = objCyberware.ConvertToCyberwareGrade(objXmlCyberware["grade"].InnerText, Improvement.ImprovementSource.Cyberware);

                    int intRating = 0;
                    if (objXmlCyberware["rating"] != null)
                        intRating = Convert.ToInt32(objXmlCyberware["rating"].InnerText);

                    XmlNode objXmlCyberwareNode = objXmlCyberwareDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + objXmlCyberware["name"].InnerText + "\"]");
                    objCyberware.Create(objXmlCyberwareNode, _objCharacter, objGrade, Improvement.ImprovementSource.Cyberware, intRating, objNode, objWeapons, objWeaponNodes, true, blnCreateChildren);
                    _objCharacter.Cyberware.Add(objCyberware);

                    // Add any children.
                    if (objXmlCyberware["cyberwares"] != null)
                    {
                        foreach (XmlNode objXmlChild in objXmlCyberware.SelectNodes("cyberwares/cyberware"))
                        {
                            TreeNode objChildNode = new TreeNode();
                            Cyberware objChildCyberware = new Cyberware(_objCharacter);

                            int intChildRating = 0;
                            if (objXmlChild["rating"] != null)
                                intChildRating = Convert.ToInt32(objXmlChild["rating"].InnerText);

                            XmlNode objXmlChildNode = objXmlCyberwareDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + objXmlChild["name"].InnerText + "\"]");
                            objChildCyberware.Create(objXmlChildNode, _objCharacter, objGrade, Improvement.ImprovementSource.Cyberware, intChildRating, objChildNode, objWeapons, objWeaponNodes, true, blnCreateChildren);
                            objCyberware.Children.Add(objChildCyberware);
                            objChildNode.ContextMenuStrip = cmsCyberware;

                            foreach (XmlNode objXmlGear in objXmlChild.SelectNodes("gears/gear"))
                                AddPACKSGear(objXmlGearDocument, objXmlGear, objChildNode, objChildCyberware, cmsCyberwareGear, blnCreateChildren);

                            objNode.Nodes.Add(objChildNode);
                            objNode.Expand();
                        }
                    }

                    foreach (XmlNode objXmlGear in objXmlCyberware.SelectNodes("gears/gear"))
                        AddPACKSGear(objXmlGearDocument, objXmlGear, objNode, objCyberware, cmsCyberwareGear, blnCreateChildren);

                    objNode.ContextMenuStrip = cmsCyberware;
                    treCyberware.Nodes[0].Nodes.Add(objNode);
                    treCyberware.Nodes[0].Expand();

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

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

                    Application.DoEvents();
                }

                treCyberware.SortCustom();
            }

            // Update Bioware.
            if (objXmlKit["biowares"] != null)
            {
                XmlDocument objXmlBiowareDocument = XmlManager.Instance.Load("bioware.xml");

                pgbProgress.Visible = true;
                pgbProgress.Value = 0;
                pgbProgress.Maximum = objXmlKit.SelectNodes("biowares/bioware").Count;
                int i = 0;

                foreach (XmlNode objXmlBioware in objXmlKit.SelectNodes("biowares/bioware"))
                {
                    i++;
                    pgbProgress.Value = i;
                    Application.DoEvents();

                    List<Weapon> objWeapons = new List<Weapon>();
                    List<TreeNode> objWeaponNodes = new List<TreeNode>();
                    TreeNode objNode = new TreeNode();
                    Cyberware objCyberware = new Cyberware(_objCharacter);
                    Grade objGrade = objCyberware.ConvertToCyberwareGrade(objXmlBioware["grade"].InnerText, Improvement.ImprovementSource.Bioware);

                    int intRating = 0;
                    if (objXmlBioware["rating"] != null)
                        intRating = Convert.ToInt32(objXmlBioware["rating"].InnerText);

                    XmlNode objXmlBiowareNode = objXmlBiowareDocument.SelectSingleNode("/chummer/biowares/bioware[name = \"" + objXmlBioware["name"].InnerText + "\"]");
                    objCyberware.Create(objXmlBiowareNode, _objCharacter, objGrade, Improvement.ImprovementSource.Bioware, intRating, objNode, objWeapons, objWeaponNodes, true, blnCreateChildren);
                    _objCharacter.Cyberware.Add(objCyberware);

                    objNode.ContextMenuStrip = cmsBioware;
                    treCyberware.Nodes[1].Nodes.Add(objNode);
                    treCyberware.Nodes[1].Expand();

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

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

                    Application.DoEvents();
                }

                treCyberware.SortCustom();
            }

            // Update Gear.
            if (objXmlKit["gears"] != null)
            {
                XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");

                pgbProgress.Visible = true;
                pgbProgress.Value = 0;
                pgbProgress.Maximum = objXmlKit.SelectNodes("gears/gear").Count;
                int i = 0;

                foreach (XmlNode objXmlGear in objXmlKit.SelectNodes("gears/gear"))
                {
                    i++;
                    pgbProgress.Value = i;
                    Application.DoEvents();

                    AddPACKSGear(objXmlGearDocument, objXmlGear, treGear.Nodes[0], _objCharacter, cmsGear, blnCreateChildren);

                    Application.DoEvents();
                }
            }

            // Update Vehicles.
            if (objXmlKit["vehicles"] != null)
            {
                XmlDocument objXmlVehicleDocument = XmlManager.Instance.Load("vehicles.xml");

                pgbProgress.Visible = true;
                pgbProgress.Value = 0;
                pgbProgress.Maximum = objXmlKit.SelectNodes("vehicles/vehicle").Count;
                int i = 0;

                foreach (XmlNode objXmlVehicle in objXmlKit.SelectNodes("vehicles/vehicle"))
                {
                    i++;
                    pgbProgress.Value = i;
                    Application.DoEvents();

                    Gear objDefaultSensor = new Gear(_objCharacter);

                    TreeNode objNode = new TreeNode();
                    Vehicle objVehicle = new Vehicle(_objCharacter);

                    XmlNode objXmlVehicleNode = objXmlVehicleDocument.SelectSingleNode("/chummer/vehicles/vehicle[name = \"" + objXmlVehicle["name"].InnerText + "\"]");
                    objVehicle.Create(objXmlVehicleNode, objNode, cmsVehicle, cmsVehicleGear, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponMod, blnCreateChildren);
                    _objCharacter.Vehicles.Add(objVehicle);

                    // Grab the default Sensor that comes with the Vehicle.
                    foreach (Gear objSensorGear in objVehicle.Gear)
                    {
                        if (objSensorGear.Category == "Sensors" && objSensorGear.Cost == "0" && objSensorGear.Rating == 0)
                        {
                            objDefaultSensor = objSensorGear;
                            break;
                        }
                    }

                    // Add any Vehicle Mods.
                    if (objXmlVehicle["mods"] != null)
                    {
                        foreach (XmlNode objXmlMod in objXmlVehicle.SelectNodes("mods/mod"))
                        {
                            TreeNode objModNode = new TreeNode();
                            VehicleMod objMod = new VehicleMod(_objCharacter);

                            int intRating = 0;
                            if (objXmlMod["rating"] != null)
                                intRating = Convert.ToInt32(objXmlMod["rating"].InnerText);

                            XmlNode objXmlModNode = objXmlVehicleDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]");
                            objMod.Create(objXmlModNode, objModNode, intRating);
                            objVehicle.Mods.Add(objMod);

                            objNode.Nodes.Add(objModNode);
                            objNode.Expand();
                        }
                    }

                    // Add any Vehicle Gear.
                    if (objXmlVehicle["gears"] != null)
                    {
                        XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");

                        foreach (XmlNode objXmlGear in objXmlVehicle.SelectNodes("gears/gear"))
                        {
                            List<Weapon> objWeapons = new List<Weapon>();
                            List<TreeNode> objWeaponNodes = new List<TreeNode>();
                            TreeNode objGearNode = new TreeNode();
                            Gear objGear = new Gear(_objCharacter);
                            int intQty = 1;

                            int intRating = 0;
                            if (objXmlGear["rating"] != null)
                                intRating = Convert.ToInt32(objXmlGear["rating"].InnerText);
                            string strForceValue = "";
                            if (objXmlGear["name"].Attributes["select"] != null)
                                strForceValue = objXmlGear["name"].Attributes["select"].InnerText;
                            if (objXmlGear["qty"] != null)
                                intQty = Convert.ToInt32(objXmlGear["qty"].InnerText);

                            XmlNode objXmlGearNode = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear["name"].InnerText + "\"]");
                            objGear.Create(objXmlGearNode, _objCharacter, objGearNode, intRating, objWeapons, objWeaponNodes, strForceValue, false, false, false, blnCreateChildren, false);
                            objGear.Quantity = intQty;
                            objGearNode.Text = objGear.DisplayName;
                            objVehicle.Gear.Add(objGear);

                            // Look for child components.
                            if (objXmlGear["gears"] != null)
                            {
                                foreach (XmlNode objXmlChild in objXmlGear.SelectNodes("gears/gear"))
                                {
                                    AddPACKSGear(objXmlGearDocument, objXmlChild, objGearNode, objGear, cmsVehicleGear, blnCreateChildren);
                                }
                            }

                            objGearNode.Expand();
                            objGearNode.ContextMenuStrip = cmsVehicleGear;
                            objNode.Nodes.Add(objGearNode);
                            objNode.Expand();

                            // If this is a Sensor, it will replace the Vehicle's base sensor, so remove it.
                            if (objGear.Category == "Sensors" && objGear.Cost == "0" && objGear.Rating == 0)
                            {
                                objVehicle.Gear.Remove(objDefaultSensor);
                                foreach (TreeNode objSensorNode in objNode.Nodes)
                                {
                                    if (objSensorNode.Tag.ToString() == objDefaultSensor.InternalId)
                                    {
                                        objSensorNode.Remove();
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    // Add any Vehicle Weapons.
                    if (objXmlVehicle["weapons"] != null)
                    {
                        XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml");

                        foreach (XmlNode objXmlWeapon in objXmlVehicle.SelectNodes("weapons/weapon"))
                        {
                            TreeNode objWeaponNode = new TreeNode();
                            Weapon objWeapon = new Weapon(_objCharacter);

                            XmlNode objXmlWeaponNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["name"].InnerText + "\"]");
                            objWeapon.Create(objXmlWeaponNode, _objCharacter, objWeaponNode, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponMod, blnCreateChildren);
                            objWeapon.VehicleMounted = true;

                            // Find the first Weapon Mount in the Vehicle.
                            foreach (VehicleMod objMod in objVehicle.Mods)
                            {
                                if (objMod.Name.StartsWith("Weapon Mount") || objMod.Name.StartsWith("Heavy Weapon Mount"))
                                {
                                    objMod.Weapons.Add(objWeapon);
                                    foreach (TreeNode objModNode in objNode.Nodes)
                                    {
                                        if (objModNode.Tag.ToString() == objMod.InternalId)
                                        {
                                            objWeaponNode.ContextMenuStrip = cmsVehicleWeapon;
                                            objModNode.Nodes.Add(objWeaponNode);
                                            objModNode.Expand();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }

                            // Look for Weapon Accessories.
                            if (objXmlWeapon["accessories"] != null)
                            {
                                foreach (XmlNode objXmlAccessory in objXmlWeapon.SelectNodes("accessories/accessory"))
                                {
                                    XmlNode objXmlAccessoryNode = objXmlWeaponDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + objXmlAccessory["name"].InnerText + "\"]");
                                    WeaponAccessory objMod = new WeaponAccessory(_objCharacter);
                                    TreeNode objModNode = new TreeNode();
                                    string strMount = "";
									int intRating = 0;
									if (objXmlAccessory["mount"] != null)
                                        strMount = objXmlAccessory["mount"].InnerText;
                                    objMod.Create(objXmlAccessoryNode, objModNode, strMount,intRating);
                                    objModNode.ContextMenuStrip = cmsWeaponAccessory;
                                    objMod.Parent = objWeapon;

                                    objWeapon.WeaponAccessories.Add(objMod);

                                    objWeaponNode.Nodes.Add(objModNode);
                                    objWeaponNode.Expand();
                                }
                            }

                            // Look for Weapon Mods.
                            if (objXmlWeapon["mods"] != null)
                            {
                                foreach (XmlNode objXmlMod in objXmlWeapon.SelectNodes("mods/mod"))
                                {
                                    XmlNode objXmlModNode = objXmlWeaponDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]");
                                    WeaponMod objMod = new WeaponMod(_objCharacter);
                                    TreeNode objModNode = new TreeNode();
                                    objMod.Create(objXmlModNode, objModNode);
                                    objModNode.ContextMenuStrip = cmsVehicleWeaponMod;
                                    objMod.Parent = objWeapon;

                                    objWeapon.WeaponMods.Add(objMod);

                                    objWeaponNode.Nodes.Add(objModNode);
                                    objWeaponNode.Expand();
                                }
                            }
                        }
                    }

                    objNode.ContextMenuStrip = cmsVehicle;
                    treVehicles.Nodes[0].Nodes.Add(objNode);
                    treVehicles.Nodes[0].Expand();

                    Application.DoEvents();
                }
            }

            pgbProgress.Visible = false;

            if (frmPickPACKSKit.AddAgain)
                AddPACKSKit();

            PopulateGearList();
            UpdateCharacterInfo();
        }
Exemplo n.º 24
0
        private void tsWeaponAddAccessory_Click(object sender, EventArgs e)
        {
            // Make sure a parent item is selected, then open the Select Accessory window.
            try
            {
                if (treWeapons.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectWeaponAccessory"), LanguageManager.Instance.GetString("MessageTitle_SelectWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectWeaponAccessory"), LanguageManager.Instance.GetString("MessageTitle_SelectWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Locate the Weapon that is selected in the Tree.
            Weapon objWeapon = _objFunctions.FindWeapon(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);

            // Accessories cannot be added to Cyberweapons.
            if (objWeapon.Cyberware)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CyberweaponNoAccessory"), LanguageManager.Instance.GetString("MessageTitle_CyberweaponNoAccessory"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

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

            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objWeapon.Name + "\"]");

            frmSelectWeaponAccessory frmPickWeaponAccessory = new frmSelectWeaponAccessory(_objCharacter, true);

            if (objXmlWeapon == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Make sure the Weapon allows Accessories to be added to it.
            if (!Convert.ToBoolean(objXmlWeapon["allowaccessory"].InnerText))
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                XmlNodeList objXmlMountList = objXmlWeapon.SelectNodes("accessorymounts/mount");
                string strMounts = "";
                foreach (XmlNode objXmlMount in objXmlMountList)
                    strMounts += objXmlMount.InnerText + "/";

                frmPickWeaponAccessory.AllowedMounts = strMounts;
            }

            frmPickWeaponAccessory.WeaponCost = objWeapon.Cost;
            frmPickWeaponAccessory.AccessoryMultiplier = objWeapon.AccessoryMultiplier;
            frmPickWeaponAccessory.ShowDialog();

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

            // Locate the selected piece.
            objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + frmPickWeaponAccessory.SelectedAccessory + "\"]");

            TreeNode objNode = new TreeNode();
            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
            objAccessory.Create(objXmlWeapon, objNode, frmPickWeaponAccessory.SelectedMount);
            objAccessory.Parent = objWeapon;

            if (objAccessory.Cost.StartsWith("Variable"))
            {
                int intMin = 0;
                int intMax = 0;
                string strCost = objAccessory.Cost.Replace("Variable(", string.Empty).Replace(")", string.Empty);
                if (strCost.Contains("-"))
                {
                    string[] strValues = strCost.Split('-');
                    intMin = Convert.ToInt32(strValues[0]);
                    intMax = Convert.ToInt32(strValues[1]);
                }
                else
                    intMin = Convert.ToInt32(strCost.Replace("+", string.Empty));

                if (intMin != 0 || intMax != 0)
                {
                    frmSelectNumber frmPickNumber = new frmSelectNumber();
                    if (intMax == 0)
                        intMax = 1000000;
                    frmPickNumber.Minimum = intMin;
                    frmPickNumber.Maximum = intMax;
                    frmPickNumber.Description = LanguageManager.Instance.GetString("String_SelectVariableCost").Replace("{0}", objAccessory.DisplayNameShort);
                    frmPickNumber.AllowCancel = false;
                    frmPickNumber.ShowDialog();
                    objAccessory.Cost = frmPickNumber.SelectedValue.ToString();
                }
            }

            // Check the item's Cost and make sure the character can afford it.
            int intOriginalCost = objWeapon.TotalCost;
            objWeapon.WeaponAccessories.Add(objAccessory);

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

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

            if (!frmPickWeaponAccessory.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    objWeapon.WeaponAccessories.Remove(objAccessory);
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (frmPickWeaponAccessory.AddAgain)
                        tsWeaponAddAccessory_Click(sender, e);

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

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddWeaponAccessory, objAccessory.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            objNode.ContextMenuStrip = cmsWeaponAccessory;
            treWeapons.SelectedNode.Nodes.Add(objNode);
            treWeapons.SelectedNode.Expand();

            UpdateCharacterInfo();
            RefreshSelectedWeapon();

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickWeaponAccessory.AddAgain)
                tsWeaponAddAccessory_Click(sender, e);
        }
Exemplo n.º 25
0
        private void mnuEditCopy_Click(object sender, EventArgs e)
        {
            if (tabCharacterTabs.SelectedTab == tabStreetGear)
            {
                // Lifestyle Tab.
                if (tabStreetGearTabs.SelectedTab == tabLifestyle)
                {
                    try
                    {
                        // Copy the selected Lifestyle.
                        Lifestyle objCopyLifestyle = _objFunctions.FindLifestyle(treLifestyles.SelectedNode.Tag.ToString(), _objCharacter.Lifestyles);

                        if (objCopyLifestyle == null)
                            return;

                        MemoryStream objStream = new MemoryStream();
                        XmlTextWriter objWriter = new XmlTextWriter(objStream, System.Text.Encoding.Unicode);
                        objWriter.Formatting = Formatting.Indented;
                        objWriter.Indentation = 1;
                        objWriter.IndentChar = '\t';

                        objWriter.WriteStartDocument();

                        // </characters>
                        objWriter.WriteStartElement("character");

                        objCopyLifestyle.Save(objWriter);

                        // </characters>
                        objWriter.WriteEndElement();

                        // Finish the document and flush the Writer and Stream.
                        objWriter.WriteEndDocument();
                        objWriter.Flush();
                        objStream.Flush();

                        // Read the stream.
                        StreamReader objReader = new StreamReader(objStream);
                        objStream.Position = 0;
                        XmlDocument objCharacterXML = new XmlDocument();

                        // Put the stream into an XmlDocument.
                        string strXML = objReader.ReadToEnd();
                        objCharacterXML.LoadXml(strXML);

                        objWriter.Close();
                        objStream.Close();

                        GlobalOptions.Instance.Clipboard = objCharacterXML;
                        GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Lifestyle;
                        //Clipboard.SetText(objCharacterXML.OuterXml);
                    }
                    catch
                    {
                    }
                }

                // Armor Tab.
                if (tabStreetGearTabs.SelectedTab == tabArmor)
                {
                    try
                    {
                        // Copy the selected Armor.
                        Armor objCopyArmor = _objFunctions.FindArmor(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor);

                        if (objCopyArmor != null)
                        {
                            MemoryStream objStream = new MemoryStream();
                            XmlTextWriter objWriter = new XmlTextWriter(objStream, System.Text.Encoding.Unicode);
                            objWriter.Formatting = Formatting.Indented;
                            objWriter.Indentation = 1;
                            objWriter.IndentChar = '\t';

                            objWriter.WriteStartDocument();

                            // </characters>
                            objWriter.WriteStartElement("character");

                            objCopyArmor.Save(objWriter);

                            // </characters>
                            objWriter.WriteEndElement();

                            // Finish the document and flush the Writer and Stream.
                            objWriter.WriteEndDocument();
                            objWriter.Flush();
                            objStream.Flush();

                            // Read the stream.
                            StreamReader objReader = new StreamReader(objStream);
                            objStream.Position = 0;
                            XmlDocument objCharacterXML = new XmlDocument();

                            // Put the stream into an XmlDocument.
                            string strXML = objReader.ReadToEnd();
                            objCharacterXML.LoadXml(strXML);

                            objWriter.Close();
                            objStream.Close();

                            GlobalOptions.Instance.Clipboard = objCharacterXML;
                            GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Armor;

                            RefreshPasteStatus();
                            return;
                        }

                        // Attempt to copy Gear.
                        Gear objCopyGear = _objFunctions.FindArmorGear(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor, out objCopyArmor);

                        if (objCopyGear != null)
                        {
                            MemoryStream objStream = new MemoryStream();
                            XmlTextWriter objWriter = new XmlTextWriter(objStream, System.Text.Encoding.Unicode);
                            objWriter.Formatting = Formatting.Indented;
                            objWriter.Indentation = 1;
                            objWriter.IndentChar = '\t';

                            objWriter.WriteStartDocument();

                            // </characters>
                            objWriter.WriteStartElement("character");

                            if (objCopyGear.GetType() == typeof(Commlink))
                            {
                                Commlink objCommlink = (Commlink)objCopyGear;
                                objCommlink.Save(objWriter);
                                GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Commlink;
                            }
                            else
                            {
                                objCopyGear.Save(objWriter);
                                GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Gear;
                            }

                            if (objCopyGear.WeaponID != Guid.Empty.ToString())
                            {
                                // Copy any Weapon that comes with the Gear.
                                Weapon objCopyWeapon = _objFunctions.FindWeapon(objCopyGear.WeaponID, _objCharacter.Weapons);
                                objCopyWeapon.Save(objWriter);
                            }

                            // </characters>
                            objWriter.WriteEndElement();

                            // Finish the document and flush the Writer and Stream.
                            objWriter.WriteEndDocument();
                            objWriter.Flush();
                            objStream.Flush();

                            // Read the stream.
                            StreamReader objReader = new StreamReader(objStream);
                            objStream.Position = 0;
                            XmlDocument objCharacterXML = new XmlDocument();

                            // Put the stream into an XmlDocument.
                            string strXML = objReader.ReadToEnd();
                            objCharacterXML.LoadXml(strXML);

                            objWriter.Close();
                            objStream.Close();

                            GlobalOptions.Instance.Clipboard = objCharacterXML;

                            RefreshPasteStatus();
                            return;
                        }
                    }
                    catch
                    {
                    }
                }

                // Weapons Tab.
                if (tabStreetGearTabs.SelectedTab == tabWeapons)
                {
                    try
                    {
                        // Copy the selected Weapon.
                        Weapon objCopyWeapon = _objFunctions.FindWeapon(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);

                        if (objCopyWeapon != null)
                        {
                            // Do not let the user copy Gear or Cyberware Weapons.
                            if (objCopyWeapon.Category == "Gear" || objCopyWeapon.Cyberware)
                                return;

                            MemoryStream objStream = new MemoryStream();
                            XmlTextWriter objWriter = new XmlTextWriter(objStream, System.Text.Encoding.Unicode);
                            objWriter.Formatting = Formatting.Indented;
                            objWriter.Indentation = 1;
                            objWriter.IndentChar = '\t';

                            objWriter.WriteStartDocument();

                            // </characters>
                            objWriter.WriteStartElement("character");

                            objCopyWeapon.Save(objWriter);

                            // </characters>
                            objWriter.WriteEndElement();

                            // Finish the document and flush the Writer and Stream.
                            objWriter.WriteEndDocument();
                            objWriter.Flush();
                            objStream.Flush();

                            // Read the stream.
                            StreamReader objReader = new StreamReader(objStream);
                            objStream.Position = 0;
                            XmlDocument objCharacterXML = new XmlDocument();

                            // Put the stream into an XmlDocument.
                            string strXML = objReader.ReadToEnd();
                            objCharacterXML.LoadXml(strXML);

                            objWriter.Close();
                            objStream.Close();

                            GlobalOptions.Instance.Clipboard = objCharacterXML;
                            GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Weapon;

                            RefreshPasteStatus();
                            return;
                        }

                        WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                        Gear objCopyGear = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objAccessory);

                        if (objCopyGear != null)
                        {
                            MemoryStream objStream = new MemoryStream();
                            XmlTextWriter objWriter = new XmlTextWriter(objStream, System.Text.Encoding.Unicode);
                            objWriter.Formatting = Formatting.Indented;
                            objWriter.Indentation = 1;
                            objWriter.IndentChar = '\t';

                            objWriter.WriteStartDocument();

                            // </characters>
                            objWriter.WriteStartElement("character");

                            if (objCopyGear.GetType() == typeof(Commlink))
                            {
                                Commlink objCommlink = (Commlink)objCopyGear;
                                objCommlink.Save(objWriter);
                                GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Commlink;
                            }
                            else
                            {
                                objCopyGear.Save(objWriter);
                                GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Gear;
                            }

                            if (objCopyGear.WeaponID != Guid.Empty.ToString())
                            {
                                // Copy any Weapon that comes with the Gear.
                                Weapon objCopyGearWeapon = _objFunctions.FindWeapon(objCopyGear.WeaponID, _objCharacter.Weapons);
                                objCopyGearWeapon.Save(objWriter);
                            }

                            // </characters>
                            objWriter.WriteEndElement();

                            // Finish the document and flush the Writer and Stream.
                            objWriter.WriteEndDocument();
                            objWriter.Flush();
                            objStream.Flush();

                            // Read the stream.
                            StreamReader objReader = new StreamReader(objStream);
                            objStream.Position = 0;
                            XmlDocument objCharacterXML = new XmlDocument();

                            // Put the stream into an XmlDocument.
                            string strXML = objReader.ReadToEnd();
                            objCharacterXML.LoadXml(strXML);

                            objWriter.Close();
                            objStream.Close();

                            GlobalOptions.Instance.Clipboard = objCharacterXML;

                            RefreshPasteStatus();
                            return;
                        }
                    }
                    catch
                    {
                    }
                }

                // Gear Tab.
                if (tabStreetGearTabs.SelectedTab == tabGear)
                {
                    try
                    {
                        // Copy the selected Gear.
                        Gear objCopyGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);

                        if (objCopyGear == null)
                            return;

                        MemoryStream objStream = new MemoryStream();
                        XmlTextWriter objWriter = new XmlTextWriter(objStream, System.Text.Encoding.Unicode);
                        objWriter.Formatting = Formatting.Indented;
                        objWriter.Indentation = 1;
                        objWriter.IndentChar = '\t';

                        objWriter.WriteStartDocument();

                        // </characters>
                        objWriter.WriteStartElement("character");

                        if (objCopyGear.GetType() == typeof(Commlink))
                        {
                            Commlink objCommlink = (Commlink)objCopyGear;
                            objCommlink.Save(objWriter);
                            GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Commlink;
                        }
                        else
                        {
                            objCopyGear.Save(objWriter);
                            GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Gear;
                        }

                        if (objCopyGear.WeaponID != Guid.Empty.ToString())
                        {
                            // Copy any Weapon that comes with the Gear.
                            Weapon objCopyWeapon = _objFunctions.FindWeapon(objCopyGear.WeaponID, _objCharacter.Weapons);
                            objCopyWeapon.Save(objWriter);
                        }

                        // </characters>
                        objWriter.WriteEndElement();

                        // Finish the document and flush the Writer and Stream.
                        objWriter.WriteEndDocument();
                        objWriter.Flush();
                        objStream.Flush();

                        // Read the stream.
                        StreamReader objReader = new StreamReader(objStream);
                        objStream.Position = 0;
                        XmlDocument objCharacterXML = new XmlDocument();

                        // Put the stream into an XmlDocument.
                        string strXML = objReader.ReadToEnd();
                        objCharacterXML.LoadXml(strXML);

                        objWriter.Close();
                        objStream.Close();

                        GlobalOptions.Instance.Clipboard = objCharacterXML;
                        //Clipboard.SetText(objCharacterXML.OuterXml);
                    }
                    catch
                    {
                    }
                }
            }

            // Vehicles Tab.
            if (tabCharacterTabs.SelectedTab == tabVehicles)
            {
                try
                {
                    if (treVehicles.SelectedNode.Level == 1)
                    {
                        // Copy the selected Vehicle.
                        Vehicle objCopyVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles);

                        MemoryStream objStream = new MemoryStream();
                        XmlTextWriter objWriter = new XmlTextWriter(objStream, System.Text.Encoding.Unicode);
                        objWriter.Formatting = Formatting.Indented;
                        objWriter.Indentation = 1;
                        objWriter.IndentChar = '\t';

                        objWriter.WriteStartDocument();

                        // </characters>
                        objWriter.WriteStartElement("character");

                        objCopyVehicle.Save(objWriter);

                        // </characters>
                        objWriter.WriteEndElement();

                        // Finish the document and flush the Writer and Stream.
                        objWriter.WriteEndDocument();
                        objWriter.Flush();
                        objStream.Flush();

                        // Read the stream.
                        StreamReader objReader = new StreamReader(objStream);
                        objStream.Position = 0;
                        XmlDocument objCharacterXML = new XmlDocument();

                        // Put the stream into an XmlDocument.
                        string strXML = objReader.ReadToEnd();
                        objCharacterXML.LoadXml(strXML);

                        objWriter.Close();
                        objStream.Close();

                        GlobalOptions.Instance.Clipboard = objCharacterXML;
                        GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Vehicle;
                        //Clipboard.SetText(objCharacterXML.OuterXml);
                    }
                    else
                    {
                        Vehicle objVehicle = new Vehicle(_objCharacter);
                        Gear objCopyGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle);

                        if (objCopyGear != null)
                        {
                            MemoryStream objStream = new MemoryStream();
                            XmlTextWriter objWriter = new XmlTextWriter(objStream, System.Text.Encoding.Unicode);
                            objWriter.Formatting = Formatting.Indented;
                            objWriter.Indentation = 1;
                            objWriter.IndentChar = '\t';

                            objWriter.WriteStartDocument();

                            // </characters>
                            objWriter.WriteStartElement("character");

                            if (objCopyGear.GetType() == typeof(Commlink))
                            {
                                Commlink objCommlink = (Commlink)objCopyGear;
                                objCommlink.Save(objWriter);
                                GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Commlink;
                            }
                            else
                            {
                                objCopyGear.Save(objWriter);
                                GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Gear;
                            }

                            if (objCopyGear.WeaponID != Guid.Empty.ToString())
                            {
                                // Copy any Weapon that comes with the Gear.
                                Weapon objCopyWeapon = _objFunctions.FindWeapon(objCopyGear.WeaponID, _objCharacter.Weapons);
                                objCopyWeapon.Save(objWriter);
                            }

                            // </characters>
                            objWriter.WriteEndElement();

                            // Finish the document and flush the Writer and Stream.
                            objWriter.WriteEndDocument();
                            objWriter.Flush();
                            objStream.Flush();

                            // Read the stream.
                            StreamReader objReader = new StreamReader(objStream);
                            objStream.Position = 0;
                            XmlDocument objCharacterXML = new XmlDocument();

                            // Put the stream into an XmlDocument.
                            string strXML = objReader.ReadToEnd();
                            objCharacterXML.LoadXml(strXML);

                            objWriter.Close();
                            objStream.Close();

                            GlobalOptions.Instance.Clipboard = objCharacterXML;

                            RefreshPasteStatus();
                            return;
                        }

                        foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                        {
                            foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                            {
                                Weapon objCopyWeapon = _objFunctions.FindWeapon(treVehicles.SelectedNode.Tag.ToString(), objMod.Weapons);
                                if (objCopyWeapon != null)
                                {
                                    // Do not let the user copy Gear or Cyberware Weapons.
                                    if (objCopyWeapon.Category == "Gear" || objCopyWeapon.Cyberware)
                                        return;

                                    MemoryStream objStream = new MemoryStream();
                                    XmlTextWriter objWriter = new XmlTextWriter(objStream, System.Text.Encoding.Unicode);
                                    objWriter.Formatting = Formatting.Indented;
                                    objWriter.Indentation = 1;
                                    objWriter.IndentChar = '\t';

                                    objWriter.WriteStartDocument();

                                    // </characters>
                                    objWriter.WriteStartElement("character");

                                    objCopyWeapon.Save(objWriter);

                                    // </characters>
                                    objWriter.WriteEndElement();

                                    // Finish the document and flush the Writer and Stream.
                                    objWriter.WriteEndDocument();
                                    objWriter.Flush();
                                    objStream.Flush();

                                    // Read the stream.
                                    StreamReader objReader = new StreamReader(objStream);
                                    objStream.Position = 0;
                                    XmlDocument objCharacterXML = new XmlDocument();

                                    // Put the stream into an XmlDocument.
                                    string strXML = objReader.ReadToEnd();
                                    objCharacterXML.LoadXml(strXML);

                                    objWriter.Close();
                                    objStream.Close();

                                    GlobalOptions.Instance.Clipboard = objCharacterXML;
                                    GlobalOptions.Instance.ClipboardContentType = ClipboardContentType.Weapon;

                                    RefreshPasteStatus();
                                    return;
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            RefreshPasteStatus();
        }
Exemplo n.º 26
0
        private void tsWeaponSell_Click(object sender, EventArgs e)
        {
            // Delete the selected Weapon.
            try
            {
                if (treWeapons.SelectedNode.Level == 1)
                {
                    Weapon objWeapon = new Weapon(_objCharacter);
                    // Locate the Weapon that is selected in the tree.
                    foreach (Weapon objCharacterWeapon in _objCharacter.Weapons)
                    {
                        if (objCharacterWeapon.InternalId == treWeapons.SelectedNode.Tag.ToString())
                        {
                            objWeapon = objCharacterWeapon;
                            break;
                        }
                    }

                    // Cyberweapons cannot be removed through here and must be done by removing the piece of Cyberware.
                    if (objWeapon.Cyberware)
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotRemoveCyberweapon"), LanguageManager.Instance.GetString("MessageTitle_CannotRemoveCyberweapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (objWeapon.Category == "Gear")
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotRemoveGearWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotRemoveGearWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (objWeapon.Category.StartsWith("Quality"))
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotRemoveQualityWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotRemoveQualityWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    frmSellItem frmSell = new frmSellItem();
                    frmSell.ShowDialog(this);

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

                    // Create the Expense Log Entry for the sale.
                    int intAmount = Convert.ToInt32(Convert.ToDouble(objWeapon.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldWeapon") + " " + objWeapon.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen += intAmount;

                    _objCharacter.Weapons.Remove(objWeapon);
                    treWeapons.SelectedNode.Remove();
                }
                else if (treWeapons.SelectedNode.Level > 1)
                {
                    Weapon objWeapon = new Weapon(_objCharacter);
                    // Locate the Weapon that is selected in the tree.
                    foreach (Weapon objCharacterWeapon in _objCharacter.Weapons)
                    {
                        if (objCharacterWeapon.InternalId == treWeapons.SelectedNode.Parent.Tag.ToString())
                        {
                            objWeapon = objCharacterWeapon;
                            break;
                        }
                    }

                    WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                    // Locate the Accessory that is selected in the tree.
                    foreach (WeaponAccessory objCharacterAccessory in objWeapon.WeaponAccessories)
                    {
                        if (objCharacterAccessory.InternalId == treWeapons.SelectedNode.Tag.ToString())
                        {
                            objAccessory = objCharacterAccessory;
                            break;
                        }
                    }

                    if (objAccessory.Name != "")
                    {
                        frmSellItem frmSell = new frmSellItem();
                        frmSell.ShowDialog(this);

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

                        // Record the Weapon's original cost.
                        int intOriginal = objWeapon.TotalCost;

                        objWeapon.WeaponAccessories.Remove(objAccessory);
                        treWeapons.SelectedNode.Remove();

                        int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objWeapon.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldWeaponAccessory") + " " + objAccessory.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Nuyen += intAmount;
                    }

                    WeaponMod objMod = new WeaponMod(_objCharacter);
                    // Locate the Mod that is selected in the tree.
                    foreach (WeaponMod objCharacterMod in objWeapon.WeaponMods)
                    {
                        if (objCharacterMod.InternalId == treWeapons.SelectedNode.Tag.ToString())
                        {
                            objMod = objCharacterMod;
                            break;
                        }
                    }

                    if (objMod.Name != "")
                    {
                        frmSellItem frmSell = new frmSellItem();
                        frmSell.ShowDialog(this);

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

                        // Record the Weapon's original cost.
                        int intOriginal = objWeapon.TotalCost;

                        objWeapon.WeaponMods.Remove(objMod);
                        treWeapons.SelectedNode.Remove();

                        int intAmount = Convert.ToInt32(Convert.ToDouble(intOriginal - objWeapon.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldWeaponMod") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Nuyen += intAmount;
                    }
                    else
                    {
                        frmSellItem frmSell = new frmSellItem();
                        frmSell.ShowDialog(this);

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

                        // Find the selected Gear.
                        Gear objGear = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objAccessory);
                        _objFunctions.DeleteGear(objGear, treWeapons, _objImprovementManager);
                        if (objGear.Parent == null)
                            objAccessory.Gear.Remove(objGear);
                        else
                            objGear.Parent.Children.Remove(objGear);
                        treWeapons.SelectedNode.Remove();

                        int intAmount = Convert.ToInt32(Convert.ToDouble(objGear.TotalCost, GlobalOptions.Instance.CultureInfo) * frmSell.SellPercent);
                        ExpenseLogEntry objExpense = new ExpenseLogEntry();
                        objExpense.Create(intAmount, LanguageManager.Instance.GetString("String_ExpenseSoldWeaponGear") + " " + objGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objExpense);
                        _objCharacter.Nuyen += intAmount;
                    }
                }
                UpdateCharacterInfo();
                RefreshSelectedWeapon();

                _blnIsDirty = true;
                UpdateWindowTitle();
            }
            catch
            {
            }
        }
Exemplo n.º 27
0
        private void tsVehicleAddWeaponAccessory_Click(object sender, EventArgs e)
        {
            // Attempt to locate the selected VehicleWeapon.
            bool blnWeaponFound = false;
            Vehicle objFoundVehicle = new Vehicle(_objCharacter);
            Weapon objWeapon = _objFunctions.FindVehicleWeapon(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
            if (objWeapon != null)
                blnWeaponFound = true;

            if (!blnWeaponFound)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_VehicleWeaponAccessories"), LanguageManager.Instance.GetString("MessageTitle_VehicleWeaponAccessories"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

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

            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + treVehicles.SelectedNode.Text + "\"]");

            frmSelectWeaponAccessory frmPickWeaponAccessory = new frmSelectWeaponAccessory(_objCharacter);

            if (objXmlWeapon == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Make sure the Weapon allows Accessories to be added to it.
            if (!Convert.ToBoolean(objXmlWeapon["allowaccessory"].InnerText))
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotModifyWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotModifyWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                XmlNodeList objXmlMountList = objXmlWeapon.SelectNodes("accessorymounts/mount");
                string strMounts = "";
                foreach (XmlNode objXmlMount in objXmlMountList)
                {
                    // Run through the Weapon's currenct Accessories and filter out any used up Mount points.
                    bool blnFound = false;
                    foreach (WeaponAccessory objCurrentAccessory in objWeapon.WeaponAccessories)
                    {
                        if (objCurrentAccessory.Mount == objXmlMount.InnerText)
                            blnFound = true;
                    }
                    if (!blnFound)
                        strMounts += objXmlMount.InnerText + "/";
                }
                frmPickWeaponAccessory.AllowedMounts = strMounts;
            }

            frmPickWeaponAccessory.WeaponCost = objWeapon.Cost;
            frmPickWeaponAccessory.AccessoryMultiplier = objWeapon.AccessoryMultiplier;
            frmPickWeaponAccessory.ShowDialog();

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

            // Locate the selected piece.
            objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + frmPickWeaponAccessory.SelectedAccessory + "\"]");

            TreeNode objNode = new TreeNode();
            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
            objAccessory.Create(objXmlWeapon, objNode, frmPickWeaponAccessory.SelectedMount, Convert.ToInt32(frmPickWeaponAccessory.SelectedRating));
			objAccessory.Parent = objWeapon;
            objWeapon.WeaponAccessories.Add(objAccessory);

            objNode.ContextMenuStrip = cmsVehicleWeaponAccessory;
            treVehicles.SelectedNode.Nodes.Add(objNode);
            treVehicles.SelectedNode.Expand();

            if (frmPickWeaponAccessory.AddAgain)
                tsVehicleAddWeaponAccessory_Click(sender, e);

            UpdateCharacterInfo();
        }
Exemplo n.º 28
0
        public void CreateAllWeaponAccessoriesTest()
        {
            // Create a new Human character.
            Character objCharacter = new Character();
            objCharacter.LoadMetatype(Guid.Parse("e28e7075-f635-4c02-937c-e4fc61c51602"));

            TreeNode objNode = new TreeNode();

            XmlDocument objXmlDocument = XmlManager.Instance.Load("weapons.xml");
            foreach (XmlNode objXmlNode in objXmlDocument.SelectNodes("/chummer/accessories/accessory"))
            {
                WeaponAccessory objAccessory = new WeaponAccessory(objCharacter);
                objAccessory.Create(objXmlNode, objNode, "Barrel");
            }
        }