コード例 #1
0
ファイル: frmCreate.cs プロジェクト: cormanater/chummer5a
        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);
        }
コード例 #2
0
ファイル: clsUnique.cs プロジェクト: Vanatrix/chummer5a
		/// <summary>
		/// Create a Quality from an XmlNode and return the TreeNodes for it.
		/// </summary>
		/// <param name="objXmlQuality">XmlNode to create the object from.</param>
		/// <param name="objCharacter">Character object the Quality will be added to.</param>
		/// <param name="objQualitySource">Source of the Quality.</param>
		/// <param name="objNode">TreeNode to populate a TreeView.</param>
		/// <param name="objWeapons">List of Weapons that should be added to the Character.</param>
		/// <param name="objWeaponNodes">List of TreeNodes to represent the Weapons added.</param>
		/// <param name="strForceValue">Force a value to be selected for the Quality.</param>
		public virtual void Create(XmlNode objXmlQuality, Character objCharacter, QualitySource objQualitySource, TreeNode objNode, List<Weapon> objWeapons, List<TreeNode> objWeaponNodes, string strForceValue = "")
		{
			_strName = objXmlQuality["name"].InnerText;
            if (objXmlQuality["metagenetic"] != null)
            {
                _strMetagenetic = objXmlQuality["metagenetic"].InnerText;
            }
			// Check for a Variable Cost.
			if (objXmlQuality["karma"].InnerText.StartsWith("Variable"))
			{
					int intMin = 0;
					int intMax = 0;
					string strCost = objXmlQuality["karma"].InnerText.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}", DisplayNameShort);
						frmPickNumber.AllowCancel = false;
						frmPickNumber.ShowDialog();
						_intBP = frmPickNumber.SelectedValue;
					}
			}
			else
			{ 
                _intBP = Convert.ToInt32(objXmlQuality["karma"].InnerText);
            }
            if (objXmlQuality["lp"] != null)
            {
                _intLP = Convert.ToInt32(objXmlQuality["lp"].InnerText);
            }
			_objQualityType = ConvertToQualityType(objXmlQuality["category"].InnerText);
			_objQualitySource = objQualitySource;
			if (objXmlQuality["print"] != null)
			{
				if (objXmlQuality["print"].InnerText == "no")
					_blnPrint = false;
			}
			if (objXmlQuality["implemented"] != null)
			{
				if (objXmlQuality["implemented"].InnerText == "False")
					_blnImplemented = false;
			}
			if (objXmlQuality["contributetolimit"] != null)
			{
				if (objXmlQuality["contributetolimit"].InnerText == "no")
					_blnContributeToLimit = false;
			}
			_strSource = objXmlQuality["source"].InnerText;
			_strPage = objXmlQuality["page"].InnerText;
			if (objXmlQuality["mutant"] != null)
				_strMutant = "yes";

			if (_objQualityType == QualityType.LifeModule)
			{
				objXmlQuality.TryGetField("stage", out _stage);
			}

            if(objXmlQuality["id"] != null)
                _qualiyGuid = Guid.Parse(objXmlQuality["id"].InnerText);

			if (GlobalOptions.Instance.Language != "en-us")
			{
				XmlDocument objXmlDocument = XmlManager.Instance.Load("qualities.xml");
				XmlNode objQualityNode = objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + _strName + "\"]");
				if (objQualityNode != null)
				{
					if (objQualityNode["translate"] != null)
						_strAltName = objQualityNode["translate"].InnerText;
					if (objQualityNode["altpage"] != null)
						_strAltPage = objQualityNode["altpage"].InnerText;
				}
			}

			// Add Weapons if applicable.
			if (objXmlQuality.InnerXml.Contains("<addweapon>"))
			{
				XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml");

				// More than one Weapon can be added, so loop through all occurrences.
				foreach (XmlNode objXmlAddWeapon in objXmlQuality.SelectNodes("addweapon"))
				{
					XmlNode objXmlWeapon = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlAddWeapon.InnerText + "\" and starts-with(category, \"Quality\")]");

					TreeNode objGearWeaponNode = new TreeNode();
					Weapon objGearWeapon = new Weapon(objCharacter);
					objGearWeapon.Create(objXmlWeapon, objCharacter, objGearWeaponNode, null, null, null);
					objGearWeaponNode.ForeColor = SystemColors.GrayText;
					objWeaponNodes.Add(objGearWeaponNode);
					objWeapons.Add(objGearWeapon);

					_guiWeaponID = Guid.Parse(objGearWeapon.InternalId);
				}
			}

			if (objXmlQuality.InnerXml.Contains("<naturalweapons>"))
            {
				foreach (XmlNode objXmlNaturalWeapon in objXmlQuality["naturalweapons"].SelectNodes("naturalweapon"))
				{
					TreeNode objGearWeaponNode = new TreeNode();
					Weapon objWeapon = new Weapon(_objCharacter);
					objWeapon.Name = objXmlNaturalWeapon["name"].InnerText;
					objWeapon.Category = LanguageManager.Instance.GetString("Tab_Critter");
					objWeapon.WeaponType = "Melee";
					objWeapon.Reach = Convert.ToInt32(objXmlNaturalWeapon["reach"].InnerText);
					objWeapon.Damage = objXmlNaturalWeapon["damage"].InnerText; ;
					objWeapon.AP = objXmlNaturalWeapon["ap"].InnerText; ;
					objWeapon.Mode = "0";
					objWeapon.RC = "0";
					objWeapon.Concealability = 0;
					objWeapon.Avail = "0";
					objWeapon.Cost = 0;
					objWeapon.UseSkill = objXmlNaturalWeapon["useskill"].InnerText;
					objWeapon.Source = objXmlNaturalWeapon["source"].InnerText;
					objWeapon.Page = objXmlNaturalWeapon["page"].InnerText;
					objGearWeaponNode.ForeColor = SystemColors.GrayText;
					objGearWeaponNode.Text = objWeapon.Name;
					objGearWeaponNode.Tag = objWeapon.InternalId;
					objWeaponNodes.Add(objGearWeaponNode);

					_objCharacter.Weapons.Add(objWeapon);
				}
			}

			// If the item grants a bonus, pass the information to the Improvement Manager.
			if (objXmlQuality.InnerXml.Contains("<bonus>"))
			{
				ImprovementManager objImprovementManager = new ImprovementManager(objCharacter);
				objImprovementManager.ForcedValue = strForceValue;
				if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Quality, _guiID.ToString(), objXmlQuality["bonus"], false, 1, DisplayNameShort))
				{
					_guiID = Guid.Empty;
					return;
				}
				if (objImprovementManager.SelectedValue != "")
				{
					_strExtra = objImprovementManager.SelectedValue;
					objNode.Text += " (" + objImprovementManager.SelectedValue + ")";
				}
			}

			// Metatype Qualities appear as grey text to show that they cannot be removed.
			if (objQualitySource == QualitySource.Metatype || objQualitySource == QualitySource.MetatypeRemovable)
				objNode.ForeColor = SystemColors.GrayText;

			objNode.Text = DisplayName;
			objNode.Tag = InternalId;
		}
コード例 #3
0
ファイル: frmCreate.cs プロジェクト: cormanater/chummer5a
        private void cmdDeleteVehicle_Click(object sender, EventArgs e)
        {
            // Delete the selected Vehicle.
            try
            {
                if (treVehicles.SelectedNode.Level == 0)
                    return;
            }
            catch
            {
                return;
            }

            if (treVehicles.SelectedNode.Level != 2)
            {
                if (!_objFunctions.ConfirmDelete(LanguageManager.Instance.GetString("Message_DeleteVehicle")))
                    return;
            }

            if (treVehicles.SelectedNode.Level == 1)
            {
                // Locate the Vehicle that is selected in the tree.
                Vehicle objVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles);

                // Remove any Gear Improvements from the character (primarily those provided by an Emotitoy).
                foreach (Gear objGear in objVehicle.Gear)
                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objGear.InternalId);

                _objCharacter.Vehicles.Remove(objVehicle);
                treVehicles.SelectedNode.Remove();
            }
            else if (treVehicles.SelectedNode.Level == 2)
            {
                bool blnFound = false;
                // Locate the VehicleMod that is selected in the tree.
                Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                VehicleMod objMod = _objFunctions.FindVehicleMod(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                if (objMod != null)
                {
                    blnFound = true;

                    if (!_objFunctions.ConfirmDelete(LanguageManager.Instance.GetString("Message_DeleteVehicle")))
                        return;

                    // Check for Improved Sensor bonus.
                    if (objMod.Bonus != null)
                    {
                        if (objMod.Bonus["improvesensor"] != null)
                        {
                            ChangeVehicleSensor(objFoundVehicle, false);
                        }
                    }

                    // If this is the Obsolete Mod, the user must select a percentage. This will create an Expense that costs X% of the Vehicle's base cost to remove the special Obsolete Mod.
                    if (objMod.Name == "Obsolete" || (objMod.Name == "Obsolescent" && _objOptions.AllowObsolescentUpgrade))
                    {
                        frmSelectNumber frmModPercent = new frmSelectNumber();
                        frmModPercent.Minimum = 0;
                        frmModPercent.Maximum = 1000;
                        frmModPercent.Description = LanguageManager.Instance.GetString("String_Retrofit");
                        frmModPercent.ShowDialog(this);

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

                        int intPercentage = frmModPercent.SelectedValue;
                        int intVehicleCost = Convert.ToInt32(objFoundVehicle.Cost);

                        // Make sure the character has enough Nuyen for the expense.
                        int intCost = Convert.ToInt32(Convert.ToDouble(intVehicleCost, GlobalOptions.Instance.CultureInfo) * (Convert.ToDouble(intPercentage, GlobalOptions.Instance.CultureInfo) / 100.0), GlobalOptions.Instance.CultureInfo);
                        VehicleMod objRetrofit = new VehicleMod(_objCharacter);

                        XmlDocument objVehiclesDoc = XmlManager.Instance.Load("vehicles.xml");
                        XmlNode objXmlNode = objVehiclesDoc.SelectSingleNode("/chummer/mods/mod[name = \"Retrofit\"]");
                        TreeNode objTreeNode = new TreeNode();
                        objRetrofit.Create(objXmlNode, objTreeNode, 0);
                        objRetrofit.Cost = intCost.ToString();
                        objFoundVehicle.Mods.Add(objRetrofit);
                        treVehicles.SelectedNode.Parent.Nodes.Add(objTreeNode);
                    }

                    objFoundVehicle.Mods.Remove(objMod);
                    treVehicles.SelectedNode.Remove();
                }

                if (!blnFound)
                {
                    // Locate the Sensor or Ammunition that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (Gear objGear in objCharacterVehicle.Gear)
                        {
                            if (objGear.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                if (!_objFunctions.ConfirmDelete(LanguageManager.Instance.GetString("Message_DeleteVehicle")))
                                    return;

                                // Remove the Gear Weapon created by the Gear if applicable.
                                if (objGear.WeaponID != Guid.Empty.ToString())
                                {
                                    // Remove the Weapon from the TreeView.
                                    foreach (TreeNode objWeaponNode in treVehicles.SelectedNode.Parent.Nodes)
                                    {
                                        if (objWeaponNode.Tag.ToString() == objGear.WeaponID)
                                        {
                                            treVehicles.SelectedNode.Parent.Nodes.Remove(objWeaponNode);
                                            break;
                                        }
                                    }

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

                                objCharacterVehicle.Gear.Remove(objGear);
                                treVehicles.SelectedNode.Remove();
                                blnFound = true;
                                break;
                            }
                        }
                    }
                }

                if (!blnFound)
                {
                    // Locate the Weapon that is selected in the tree.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (Weapon objWeapon in objCharacterVehicle.Weapons)
                        {
                            if (objWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                blnFound = true;
                                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotRemoveGearWeaponVehicle"), LanguageManager.Instance.GetString("MessageTitle_CannotRemoveGearWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                                break;
                            }
                        }
                    }
                }

                if (!blnFound)
                {
                    // This must be a Location, so find it.
                    TreeNode objVehicleNode = treVehicles.SelectedNode.Parent;
                    Vehicle objVehicle = _objFunctions.FindVehicle(objVehicleNode.Tag.ToString(), _objCharacter.Vehicles);

                    if (!_objFunctions.ConfirmDelete(LanguageManager.Instance.GetString("Message_DeleteVehicleLocation")))
                        return;

                    // Change the Location of the Gear.
                    foreach (Gear objGear in objVehicle.Gear)
                    {
                        if (objGear.Location == treVehicles.SelectedNode.Text)
                            objGear.Location = "";
                    }

                    // Move all of the child nodes in the current parent to the Vehicle.
                    List<TreeNode> lstMoveNodes = new List<TreeNode>();
                    foreach (TreeNode objNode in treVehicles.SelectedNode.Nodes)
                        lstMoveNodes.Add(objNode);

                    foreach (TreeNode objNode in lstMoveNodes)
                    {
                        treVehicles.SelectedNode.Nodes.Remove(objNode);
                        objVehicleNode.Nodes.Add(objNode);
                    }

                    // Remove the Location from the Vehicle, then remove the selected node.
                    objVehicle.Locations.Remove(treVehicles.SelectedNode.Text);
                    treVehicles.SelectedNode.Remove();
                }
            }
            else if (treVehicles.SelectedNode.Level == 3)
            {
                bool blnFound = false;
                // Locate the selected VehicleWeapon that is selected in the tree.
                foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                {
                    foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                    {
                        foreach (Weapon objWeapon in objMod.Weapons)
                        {
                            if (objWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                objMod.Weapons.Remove(objWeapon);
                                treVehicles.SelectedNode.Remove();
                                blnFound = true;
                                break;
                            }
                        }
                    }
                }

                if (!blnFound)
                {
                    // Locate the selected Sensor Plugin.
                    // Locate the Sensor that is selected in the tree.
                    Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                    if (objGear != null)
                    {
                        blnFound = true;
                        objGear.Parent.Children.Remove(objGear);
                        treVehicles.SelectedNode.Remove();

                        _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle);
                    }
                }

                if (!blnFound)
                {
                    // Locate the selected Cyberware.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                        {
                            foreach (Cyberware objCyberware in objMod.Cyberware)
                            {
                                if (objCyberware.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    // Remove the Cyberweapon created by the Cyberware if applicable.
                                    if (objCyberware.WeaponID != Guid.Empty.ToString())
                                    {
                                        // Remove the Weapon from the TreeView.
                                        TreeNode objRemoveNode = new TreeNode();
                                        foreach (TreeNode objWeaponNode in treVehicles.SelectedNode.Parent.Parent.Nodes)
                                        {
                                            if (objWeaponNode.Tag.ToString() == objCyberware.WeaponID)
                                                objRemoveNode = objWeaponNode;
                                        }
                                        treWeapons.Nodes.Remove(objRemoveNode);

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

                                    objMod.Cyberware.Remove(objCyberware);
                                    treVehicles.SelectedNode.Remove();
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else if (treVehicles.SelectedNode.Level == 4)
            {
                bool blnFound = false;
                // Locate the selected WeaponAccessory or VehicleWeaponMod that is selected in the tree.
                foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                {
                    foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                    {
                        foreach (Weapon objWeapon in objMod.Weapons)
                        {
                            foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                            {
                                if (objAccessory.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    objWeapon.WeaponAccessories.Remove(objAccessory);
                                    treVehicles.SelectedNode.Remove();
                                    blnFound = true;
                                    break;
                                }
                            }
                            if (!blnFound)
                            {
                                foreach (WeaponMod objWeaponMod in objWeapon.WeaponMods)
                                {
                                    if (objWeaponMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                    {
                                        objWeapon.WeaponMods.Remove(objWeaponMod);
                                        treVehicles.SelectedNode.Remove();
                                        blnFound = true;
                                        break;
                                    }
                                }
                            }
                            if (!blnFound)
                            {
                                // Remove the Underbarrel Weapon if the selected item it is one.
                                if (objWeapon.UnderbarrelWeapons.Count > 0)
                                {
                                    foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                    {
                                        if (objUnderbarrelWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                        {
                                            objWeapon.UnderbarrelWeapons.Remove(objUnderbarrelWeapon);
                                            treVehicles.SelectedNode.Remove();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (!blnFound)
                {
                    // Locate the selected Sensor Plugin.
                    // Locate the Sensor that is selected in the tree.
                    Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                    if (objGear != null)
                    {
                        blnFound = true;
                        objGear.Parent.Children.Remove(objGear);
                        treVehicles.SelectedNode.Remove();

                        _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle);
                    }
                }
            }
            else if (treVehicles.SelectedNode.Level == 5)
            {
                // Locate the selected WeaponAccessory or VehicleWeaponMod that is selected in the tree.
                bool blnFound = false;
                foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                {
                    foreach (VehicleMod objMod in objCharacterVehicle.Mods)
                    {
                        foreach (Weapon objWeapon in objMod.Weapons)
                        {
                            if (objWeapon.UnderbarrelWeapons.Count > 0)
                            {
                                foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                {
                                    foreach (WeaponAccessory objAccessory in objUnderbarrelWeapon.WeaponAccessories)
                                    {
                                        if (objAccessory.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                        {
                                            objUnderbarrelWeapon.WeaponAccessories.Remove(objAccessory);
                                            treVehicles.SelectedNode.Remove();
                                            blnFound = true;
                                            break;
                                        }
                                    }
                                    if (!blnFound)
                                    {
                                        foreach (WeaponMod objWeaponMod in objUnderbarrelWeapon.WeaponMods)
                                        {
                                            if (objWeaponMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                            {
                                                objUnderbarrelWeapon.WeaponMods.Remove(objWeaponMod);
                                                treVehicles.SelectedNode.Remove();
                                                blnFound = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (!blnFound)
                {
                    Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                    if (objGear != null)
                    {
                        blnFound = true;
                        objGear.Parent.Children.Remove(objGear);
                        treVehicles.SelectedNode.Remove();

                        _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle);
                    }
                }
            }
            else if (treVehicles.SelectedNode.Level > 5)
            {
                Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
                if (objGear != null)
                {
                    objGear.Parent.Children.Remove(objGear);
                    treVehicles.SelectedNode.Remove();

                    _objFunctions.DeleteVehicleGear(objGear, treVehicles, objFoundVehicle);
                }
            }

            UpdateCharacterInfo();
            RefreshSelectedVehicle();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
コード例 #4
0
ファイル: frmCareer.cs プロジェクト: Althalusdlg/chummer5a
        private void cmdQuickenSpell_Click(object sender, EventArgs e)
        {
            try
            {
                if (treSpells.SelectedNode.Level != 1)
                    return;
            }
            catch
            {
                return;
            }

            frmSelectNumber frmPickNumber = new frmSelectNumber();
            frmPickNumber.Description = LanguageManager.Instance.GetString("String_QuickeningKarma").Replace("{0}", treSpells.SelectedNode.Text);
            frmPickNumber.Minimum = 1;
            frmPickNumber.ShowDialog(this);

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

            // Make sure the character has enough Karma to improve the Attribute.
            int intKarmaCost = frmPickNumber.SelectedValue;
            if (intKarmaCost > _objCharacter.Karma)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!ConfirmKarmaExpense(LanguageManager.Instance.GetString("Message_ConfirmKarmaExpenseQuickeningMetamagic").Replace("{0}", intKarmaCost.ToString()).Replace("{1}", treSpells.SelectedNode.Text)))
                return;

            // Create the Karma expense.
            ExpenseLogEntry objExpense = new ExpenseLogEntry();
            objExpense.Create(intKarmaCost * -1, LanguageManager.Instance.GetString("String_ExpenseQuickenMetamagic") + " " + treSpells.SelectedNode.Text, ExpenseType.Karma, DateTime.Now);
            _objCharacter.ExpenseEntries.Add(objExpense);
            _objCharacter.Karma -= intKarmaCost;

            ExpenseUndo objUndo = new ExpenseUndo();
            objUndo.CreateKarma(KarmaExpenseType.QuickeningMetamagic, "");
            objExpense.Undo = objUndo;

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
コード例 #5
0
ファイル: frmCareer.cs プロジェクト: Althalusdlg/chummer5a
        private void cmdVehicleMoveToInventory_Click(object sender, EventArgs e)
        {
            // Locate the selected Weapon.
            bool blnFound = false;
            Weapon objWeapon = new Weapon(_objCharacter);
            Vehicle objVehicle = new Vehicle(_objCharacter);
            VehicleMod objMod = new VehicleMod(_objCharacter);

            foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
            {
                foreach (Weapon objVehicleWeapon in objCharacterVehicle.Weapons)
                {
                    if (objVehicleWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                    {
                        objWeapon = objVehicleWeapon;
                        objVehicle = objCharacterVehicle;
                        blnFound = true;
                        break;
                    }
                }
                foreach (VehicleMod objVehicleMod in objCharacterVehicle.Mods)
                {
                    foreach (Weapon objVehicleWeapon in objVehicleMod.Weapons)
                    {
                        if (objVehicleWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                        {
                            objWeapon = objVehicleWeapon;
                            objVehicle = objCharacterVehicle;
                            objMod = objVehicleMod;
                            blnFound = true;
                            break;
                        }
                    }
                }
            }

            if (blnFound){
                // Move the Weapons from the Vehicle Mod (or Vehicle) to the character.
                if (objMod.InternalId != Guid.Empty.ToString())
                    objMod.Weapons.Remove(objWeapon);
                else
                    objVehicle.Weapons.Remove(objWeapon);

                _objCharacter.Weapons.Add(objWeapon);

                TreeNode objNode = new TreeNode();
                objNode = treVehicles.SelectedNode;

                treVehicles.SelectedNode.Remove();
                treWeapons.Nodes[0].Nodes.Add(objNode);
                objWeapon.VehicleMounted = false;
                objNode.Expand();
            }
            else
            {
                // Locate the selected Gear.
                Vehicle objSelectedVehicle = new Vehicle(_objCharacter);
                Gear objSelectedGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objSelectedVehicle);

                int intMove = 0;
                if (objSelectedGear.Quantity == 1)
                    intMove = 1;
                else
                {
                    frmSelectNumber frmPickNumber = new frmSelectNumber();
                    frmPickNumber.Minimum = 1;
                    frmPickNumber.Maximum = objSelectedGear.Quantity;
                    frmPickNumber.Description = LanguageManager.Instance.GetString("String_MoveGear");
                    frmPickNumber.ShowDialog(this);

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

                    intMove = frmPickNumber.SelectedValue;
                }

                // See if the character already has a matching piece of Gear.
                bool blnMatch = false;
                Gear objFoundGear = new Gear(_objCharacter);
                foreach (Gear objCharacterGear in _objCharacter.Gear)
                {
                    if (objCharacterGear.Name == objSelectedGear.Name && objCharacterGear.Category == objSelectedGear.Category && objCharacterGear.Rating == objSelectedGear.Rating && objCharacterGear.Extra == objSelectedGear.Extra && objCharacterGear.GearName == objSelectedGear.GearName && objCharacterGear.Notes == objSelectedGear.Notes)
                    {
                        blnMatch = true;
                        objFoundGear = objCharacterGear;
                        if (objCharacterGear.Children.Count == objSelectedGear.Children.Count)
                        {
                            for (int i = 0; i <= objCharacterGear.Children.Count - 1; i++)
                            {
                                if (objCharacterGear.Children[i].Name != objSelectedGear.Children[i].Name || objCharacterGear.Children[i].Extra != objSelectedGear.Children[i].Extra || objCharacterGear.Children[i].Rating != objSelectedGear.Children[i].Rating)
                                {
                                    blnMatch = false;
                                    break;
                                }
                            }
                        }
                        else
                            blnMatch = false;
                    }
                }

                if (!blnMatch)
                {
                    // Create a new piece of Gear.
                    TreeNode objGearNode = new TreeNode();
                    List<Weapon> lstWeapons = new List<Weapon>();
                    List<TreeNode> lstWeaponNodes = new List<TreeNode>();
                    Gear objGear = new Gear(_objCharacter);
                    if (objSelectedGear.GetType() == typeof(Commlink))
                    {
                        Commlink objCommlink = new Commlink(_objCharacter);
                        objCommlink.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);
                        objGear = objCommlink;
                    }
                    else
                        objGear.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);

                    objGear.Parent = null;
                    objGear.Quantity = intMove;
                    objGearNode.Text = objGear.DisplayName;
                    objGearNode.ContextMenuStrip = cmsGear;

                    treGear.Nodes[0].Nodes.Add(objGearNode);
                    _objCharacter.Gear.Add(objGear);

                    // Create any Weapons that came with this Gear.
                    foreach (Weapon objGearWeapon in lstWeapons)
                        _objCharacter.Weapons.Add(objGearWeapon);

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

                    AddGearImprovements(objGear);
                    UpdateCharacterInfo();
                }
                else
                {
                    // Everything matches up, so just increase the quantity.
                    objFoundGear.Quantity += intMove;
                    foreach (TreeNode nodGear in treGear.Nodes[0].Nodes)
                    {
                        if (nodGear.Tag.ToString() == objFoundGear.InternalId)
                            nodGear.Text = objFoundGear.DisplayName;
                    }
                }

                // Update the selected item.
                objSelectedGear.Quantity -= intMove;
                if (objSelectedGear.Quantity == 0)
                {
                    // The quantity has reached 0, so remove it entirely.
                    treVehicles.SelectedNode.Remove();
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                        objCharacterVehicle.Gear.Remove(objSelectedGear);
                }
                else
                    treVehicles.SelectedNode.Text = objSelectedGear.DisplayName;
            }

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
コード例 #6
0
ファイル: frmCareer.cs プロジェクト: Althalusdlg/chummer5a
        private void cmdGearSplitQty_Click(object sender, EventArgs e)
        {
            // This can only be done with the first level of Nodes.
            try
            {
                if (treGear.SelectedNode.Level != 1)
                    return;
            }
            catch
            {
                return;
            }

            Gear objSelectedGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);

            // Cannot split a stack of 1 item.
            if (objSelectedGear.Quantity == 1)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotSplitGear"), LanguageManager.Instance.GetString("MessageTitle_CannotSplitGear"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            frmSelectNumber frmPickNumber = new frmSelectNumber();
            frmPickNumber.Minimum = 1;
            frmPickNumber.Maximum = objSelectedGear.Quantity - 1;
            frmPickNumber.Description = LanguageManager.Instance.GetString("String_SplitGear");
            frmPickNumber.ShowDialog(this);

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

            // Create a new piece of Gear.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");
            XmlNode objNode = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSelectedGear.Name + "\" and category = \"" + objSelectedGear.Category + "\"]");

            TreeNode objGearNode = new TreeNode();
            List<Weapon> lstWeapons = new List<Weapon>();
            List<TreeNode> lstWeaponNodes = new List<TreeNode>();
            Gear objGear = new Gear(_objCharacter);
            if (objSelectedGear.GetType() == typeof(Commlink))
            {
                Commlink objCommlink = new Commlink(_objCharacter);
                objCommlink.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);
                objGear = objCommlink;
            }
            else
                objGear.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);

            objGear.Quantity = frmPickNumber.SelectedValue;
            objGear.Equipped = objSelectedGear.Equipped;
            objGear.Location = objSelectedGear.Location;
            objGear.Notes = objSelectedGear.Notes;
            objGearNode.Text = objGear.DisplayName;
            objGearNode.ContextMenuStrip = treGear.SelectedNode.ContextMenuStrip;

            // Update the selected item.
            objSelectedGear.Quantity -= frmPickNumber.SelectedValue;
            treGear.SelectedNode.Text = objSelectedGear.DisplayName;

            treGear.SelectedNode.Parent.Nodes.Add(objGearNode);
            _objCharacter.Gear.Add(objGear);

            // Create any Weapons that came with this Gear.
            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();
            }

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
コード例 #7
0
ファイル: frmCareer.cs プロジェクト: Althalusdlg/chummer5a
        private void cmdGearMoveToVehicle_Click(object sender, EventArgs e)
        {
            frmSelectItem frmPickItem = new frmSelectItem();
            frmPickItem.Vehicles = _objCharacter.Vehicles;
            frmPickItem.ShowDialog(this);

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

            // Locate the selected Vehicle.
            Vehicle objVehicle = new Vehicle(_objCharacter);
            foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
            {
                if (objCharacterVehicle.InternalId == frmPickItem.SelectedItem)
                {
                    objVehicle = objCharacterVehicle;
                    break;
                }
            }

            Gear objSelectedGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);
            int intMove = 0;
            if (objSelectedGear.Quantity == 1)
                intMove = 1;
            else
            {
                frmSelectNumber frmPickNumber = new frmSelectNumber();
                frmPickNumber.Minimum = 1;
                frmPickNumber.Maximum = objSelectedGear.Quantity;
                frmPickNumber.Description = LanguageManager.Instance.GetString("String_MoveGear");
                frmPickNumber.ShowDialog(this);

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

                intMove = frmPickNumber.SelectedValue;
            }

            // See if the Vehicle already has a matching piece of Gear.
            bool blnMatch = false;
            Gear objFoundGear = new Gear(_objCharacter);
            foreach (Gear objVehicleGear in objVehicle.Gear)
            {
                if (objVehicleGear.Name == objSelectedGear.Name && objVehicleGear.Category == objSelectedGear.Category && objVehicleGear.Rating == objSelectedGear.Rating && objVehicleGear.Extra == objSelectedGear.Extra && objVehicleGear.GearName == objSelectedGear.GearName && objVehicleGear.Notes == objSelectedGear.Notes)
                {
                    blnMatch = true;
                    objFoundGear = objVehicleGear;
                    if (objVehicleGear.Children.Count == objSelectedGear.Children.Count)
                    {
                        for (int i = 0; i <= objVehicleGear.Children.Count - 1; i++)
                        {
                            if (objVehicleGear.Children[i].Name != objSelectedGear.Children[i].Name || objVehicleGear.Children[i].Extra != objSelectedGear.Children[i].Extra || objVehicleGear.Children[i].Rating != objSelectedGear.Children[i].Rating)
                            {
                                blnMatch = false;
                                break;
                            }
                        }
                    }
                    else
                        blnMatch = false;
                }
            }

            if (!blnMatch)
            {
                // Create a new piece of Gear.
                TreeNode objGearNode = new TreeNode();
                List<Weapon> lstWeapons = new List<Weapon>();
                List<TreeNode> lstWeaponNodes = new List<TreeNode>();
                Gear objGear = new Gear(_objCharacter);
                if (objSelectedGear.GetType() == typeof(Commlink))
                {
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);
                    objGear = objCommlink;
                }
                else
                    objGear.Copy(objSelectedGear, objGearNode, lstWeapons, lstWeaponNodes);

                objGear.Parent = null;
                objGear.Quantity = intMove;
                objGear.Location = string.Empty;
                objGearNode.Text = objGear.DisplayName;
                objGearNode.ContextMenuStrip = cmsVehicleGear;

                // Locate the Node for the selected Vehicle.
                TreeNode nodParent = new TreeNode();
                foreach (TreeNode nodNode in treVehicles.Nodes[0].Nodes)
                {
                    if (nodNode.Tag.ToString() == objVehicle.InternalId)
                    {
                        nodParent = nodNode;
                        break;
                    }
                }

                nodParent.Nodes.Add(objGearNode);
                objVehicle.Gear.Add(objGear);
            }
            else
            {
                // Everything matches up, so just increase the quantity.
                objFoundGear.Quantity += intMove;
                foreach (TreeNode nodVehicle in treVehicles.Nodes[0].Nodes)
                {
                    if (nodVehicle.Tag.ToString() == objVehicle.InternalId)
                    {
                        foreach (TreeNode nodGear in nodVehicle.Nodes)
                        {
                            if (nodGear.Tag.ToString() == objFoundGear.InternalId)
                                nodGear.Text = objFoundGear.DisplayName;
                        }
                    }
                }
            }

            // Update the selected item.
            objSelectedGear.Quantity -= intMove;
            if (objSelectedGear.Quantity == 0)
            {
                if (objSelectedGear.Parent != null)
                    objSelectedGear.Parent.Children.Remove(objSelectedGear);
                else
                    _objCharacter.Gear.Remove(objSelectedGear);
                _objFunctions.DeleteGear(objSelectedGear, treWeapons, _objImprovementManager);
                treGear.SelectedNode.Remove();
                UpdateCharacterInfo();
            }
            else
            {
                treGear.SelectedNode.Text = objSelectedGear.DisplayName;
            }

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
コード例 #8
0
ファイル: frmCareer.cs プロジェクト: Althalusdlg/chummer5a
        private void cmdGearMergeQty_Click(object sender, EventArgs e)
        {
            Gear objGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);
            List<Gear> lstGear = new List<Gear>();

            foreach (Gear objCharacterGear in _objCharacter.Gear)
            {
                bool blnMatch = false;
                // Matches must happen on Name, Category, Rating, and Extra, plus all plugins.
                if (objCharacterGear.Name == objGear.Name && objCharacterGear.Category == objGear.Category && objCharacterGear.Rating == objGear.Rating && objCharacterGear.Extra == objGear.Extra && objCharacterGear.InternalId != objGear.InternalId)
                {
                    blnMatch = true;
                    if (objCharacterGear.Children.Count == objGear.Children.Count)
                    {
                        for (int i = 0; i <= objCharacterGear.Children.Count - 1; i++)
                        {
                            if (objCharacterGear.Children[i].Name != objGear.Children[i].Name || objCharacterGear.Children[i].Extra != objGear.Children[i].Extra || objCharacterGear.Children[i].Rating != objGear.Children[i].Rating)
                            {
                                blnMatch = false;
                                break;
                            }
                        }
                    }
                    else
                        blnMatch = false;
                }

                if (blnMatch)
                    lstGear.Add(objCharacterGear);
            }

            // If there were no matches, don't try to merge anything.
            if (lstGear.Count == 0)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotMergeGear"), LanguageManager.Instance.GetString("MessageTitle_CannotMergeGear"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Show the Select Item window.
            frmSelectItem frmPickItem = new frmSelectItem();
            frmPickItem.Gear = lstGear;
            frmPickItem.ShowDialog(this);

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

            Gear objSelectedGear = _objFunctions.FindGear(frmPickItem.SelectedItem, _objCharacter.Gear);

            frmSelectNumber frmPickNumber = new frmSelectNumber();
            frmPickNumber.Minimum = 1;
            frmPickNumber.Maximum = objGear.Quantity;
            frmPickNumber.Description = LanguageManager.Instance.GetString("String_MergeGear");
            frmPickNumber.ShowDialog(this);

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

            // Increase the quantity for the selected item.
            objSelectedGear.Quantity += frmPickNumber.SelectedValue;
            // Located the item in the Tree and update its display information.
            foreach (TreeNode objParent in treGear.Nodes)
            {
                foreach (TreeNode objNode in objParent.Nodes)
                {
                    if (objNode.Tag.ToString() == objSelectedGear.InternalId)
                    {
                        objNode.Text = objSelectedGear.DisplayName;
                        break;
                    }
                }
            }

            // Reduce the quantity for the selected item.
            objGear.Quantity -= frmPickNumber.SelectedValue;
            // If the quantity has reached 0, delete the item and any Weapons it created.
            if (objGear.Quantity == 0)
            {
                // Remove the Gear Weapon created by the Gear if applicable.
                if (objGear.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() == objGear.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 == objGear.WeaponID)
                            objRemoveWeapon = objWeapon;
                    }
                    _objCharacter.Weapons.Remove(objRemoveWeapon);
                }

                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objGear.InternalId);

                // Remove the Gear from the character.
                _objCharacter.Gear.Remove(objGear);
                treGear.SelectedNode.Remove();
            }
            else
                treGear.SelectedNode.Text = objGear.DisplayName;

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
コード例 #9
0
ファイル: frmCareer.cs プロジェクト: Althalusdlg/chummer5a
        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);
        }
コード例 #10
0
ファイル: frmCareer.cs プロジェクト: Althalusdlg/chummer5a
        private void mnuSpecialCloningMachine_Click(object sender, EventArgs e)
        {
            frmSelectNumber frmPickNumber = new frmSelectNumber();
            frmPickNumber.Description = LanguageManager.Instance.GetString("String_CloningMachineNumber");
            frmPickNumber.Minimum = 1;
            frmPickNumber.ShowDialog(this);

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

            int intClones = 0;
            try
            {
                intClones = Convert.ToInt32(frmPickNumber.SelectedValue);
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CloningMachineNumberRequired"), LanguageManager.Instance.GetString("MessageTitle_CloningMachineNumberRequired"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            for (int i = 1; i <= intClones; i++)
                GlobalOptions.Instance.MainForm.LoadCharacter(_objCharacter.FileName, false, _objCharacter.Alias + " " + i.ToString(), true);
        }