/// <summary> /// Add a piece of Gear that was found in a PACKS Kit. /// </summary> /// <param name="objXmlGearDocument">XmlDocument that contains the Gear.</param> /// <param name="objXmlGear">XmlNode of the Gear to add.</param> /// <param name="objParent">TreeNode to attach the created items to.</param> /// <param name="objParentObject">Object to associate the newly-created items with.</param> /// <param name="cmsContextMenu">ContextMenuStrip to assign to the TreeNodes created.</param> /// <param name="blnCreateChildren">Whether or not the default plugins for the Gear should be created.</param> private void AddPACKSGear(XmlDocument objXmlGearDocument, XmlNode objXmlGear, TreeNode objParent, Object objParentObject, ContextMenuStrip cmsContextMenu, bool blnCreateChildren) { int intRating = 0; if (objXmlGear["rating"] != null) intRating = Convert.ToInt32(objXmlGear["rating"].InnerText); int intQty = 1; if (objXmlGear["qty"] != null) intQty = Convert.ToInt32(objXmlGear["qty"].InnerText); XmlNode objXmlGearNode; objXmlGearNode = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + objXmlGear["id"].InnerText + "\"]"); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); TreeNode objNode = new TreeNode(); string strForceValue = ""; if (objXmlGear["name"].Attributes["select"] != null) strForceValue = objXmlGear["name"].Attributes["select"].InnerText; Gear objNewGear = new Gear(_objCharacter); switch (objXmlGearNode["category"].InnerText) { case "Commlink": case "Commlink Upgrade": Commlink objCommlink = new Commlink(_objCharacter); objCommlink.Create(objXmlGearNode, _objCharacter, objNode, intRating, true, blnCreateChildren); objCommlink.Quantity = intQty; objNewGear = objCommlink; break; case "Commlink Operating System": case "Commlink Operating System Upgrade": OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter); objOperatingSystem.Create(objXmlGearNode, _objCharacter, objNode, intRating, true, blnCreateChildren); objOperatingSystem.Quantity = intQty; objNewGear = objOperatingSystem; break; default: Gear objGear = new Gear(_objCharacter); objGear.Create(objXmlGearNode, _objCharacter, objNode, intRating, objWeapons, objWeaponNodes, strForceValue, false, false, true, blnCreateChildren); objGear.Quantity = intQty; objNode.Text = objGear.DisplayName; objNewGear = objGear; break; } if (objParentObject.GetType() == typeof(Character)) ((Character)objParentObject).Gear.Add(objNewGear); if (objParentObject.GetType() == typeof(Gear) || objParentObject.GetType() == typeof(Commlink) || objParentObject.GetType() == typeof(OperatingSystem)) { ((Gear)objParentObject).Gears.Add(objNewGear); objNewGear.Parent = (Gear)objParentObject; } if (objParentObject.GetType() == typeof(Armor)) ((Armor)objParentObject).Gears.Add(objNewGear); if (objParentObject.GetType() == typeof(WeaponAccessory)) ((WeaponAccessory)objParentObject).Gears.Add(objNewGear); if (objParentObject.GetType() == typeof(Cyberware)) ((Cyberware)objParentObject).Gears.Add(objNewGear); // Look for child components. if (objXmlGear["gears"] != null) { foreach (XmlNode objXmlChild in objXmlGear.SelectNodes("gears/gear")) { AddPACKSGear(objXmlGearDocument, objXmlChild, objNode, objNewGear, cmsContextMenu, blnCreateChildren); } } objParent.Nodes.Add(objNode); objParent.Expand(); objNode.ContextMenuStrip = cmsContextMenu; objNode.Text = objNewGear.DisplayName; // 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(); } }
private void tsWeaponAccessoryAddGear_Click(object sender, EventArgs e) { WeaponAccessory objAccessory = (WeaponAccessory)_objFunctions.FindEquipment(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, typeof(WeaponAccessory)); // Make sure the Weapon Accessory is allowed to accept Gear. if (objAccessory.AllowGear == null) { MessageBox.Show(LanguageManager.Instance.GetString("Message_WeaponGear"), LanguageManager.Instance.GetString("MessageTitle_CyberwareGear"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, false); string strCategories = ""; foreach (XmlNode objXmlCategory in objAccessory.AllowGear) strCategories += objXmlCategory.InnerText + ","; frmPickGear.AllowedCategories = strCategories; frmPickGear.ShowDialog(this); if (frmPickGear.DialogResult == DialogResult.Cancel) return; TreeNode objNode = new TreeNode(); // Open the Gear XML file and locate the selected piece. XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + frmPickGear.SelectedGear + "\"]"); // Create the new piece of Gear. List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); Gear objNewGear = 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; try { _blnSkipRefresh = true; nudGearQty.Increment = objCommlink.CostFor; //nudGearQty.Minimum = nudGearQty.Increment; _blnSkipRefresh = false; } catch { } objNode.Text = objCommlink.DisplayName; objNewGear = 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; try { _blnSkipRefresh = true; nudGearQty.Increment = objOperatingSystem.CostFor; //nudGearQty.Minimum = nudGearQty.Increment; _blnSkipRefresh = false; } catch { } objNode.Text = objOperatingSystem.DisplayName; objNewGear = objOperatingSystem; break; default: Gear objGear = new Gear(_objCharacter); objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic); objGear.Quantity = frmPickGear.SelectedQty; try { _blnSkipRefresh = true; nudGearQty.Increment = objGear.CostFor; //nudGearQty.Minimum = nudGearQty.Increment; _blnSkipRefresh = false; } catch { } objNode.Text = objGear.DisplayName; objNewGear = objGear; break; } if (objNewGear.InternalId == Guid.Empty.ToString()) return; // Reduce the cost for Do It Yourself components. if (frmPickGear.DoItYourself) objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString(); // Reduce the cost to 10% for Hacked programs. if (frmPickGear.Hacked) { if (objNewGear.Cost != "") objNewGear.Cost = "(" + objNewGear.Cost + ") * 0.1"; if (objNewGear.Cost3 != "") objNewGear.Cost3 = "(" + objNewGear.Cost3 + ") * 0.1"; if (objNewGear.Cost6 != "") objNewGear.Cost6 = "(" + objNewGear.Cost6 + ") * 0.1"; if (objNewGear.Cost10 != "") objNewGear.Cost10 = "(" + objNewGear.Cost10 + ") * 0.1"; if (objNewGear.Extra == "") objNewGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked"); else objNewGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked"); } // If the item was marked as free, change its cost. if (frmPickGear.FreeCost) { objNewGear.Cost = "0"; objNewGear.Cost3 = "0"; objNewGear.Cost6 = "0"; objNewGear.Cost10 = "0"; } // Create any Weapons that came with this 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(); } objAccessory.Gears.Add(objNewGear); objNode.ContextMenuStrip = cmsWeaponAccessoryGear; treWeapons.SelectedNode.Nodes.Add(objNode); treWeapons.SelectedNode.Expand(); UpdateCharacterInfo(); if (frmPickGear.AddAgain) tsWeaponAccessoryAddGear_Click(sender, e); _blnIsDirty = true; UpdateWindowTitle(); }
private void tsWeaponAccessoryGearMenuAddAsPlugin_Click(object sender, EventArgs e) { // Locate the Vehicle Sensor Gear. bool blnFound = false; WeaponAccessory objFoundAccessory = new WeaponAccessory(_objCharacter); Gear objSensor = (Gear)_objFunctions.FindEquipment(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, typeof(Gear)); if (objSensor != null) blnFound = true; if (objSensor.Parent != null) objFoundAccessory = (WeaponAccessory)objSensor.Parent; // 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[id = \"" + objSensor.ExternalId + "\"]"); frmSelectGear frmPickGear = new frmSelectGear(_objCharacter); //frmPickGear.ShowNegativeCapacityOnly = true; if (objXmlGear["addoncategory"] != null) { 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[id = \"" + frmPickGear.SelectedGear + "\"]"); // 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; objNode.ContextMenuStrip = cmsWeaponAccessoryGear; treWeapons.SelectedNode.Nodes.Add(objNode); treWeapons.SelectedNode.Expand(); objGear.Parent = objSensor; objSensor.Gears.Add(objGear); if (frmPickGear.AddAgain) tsWeaponAccessoryGearMenuAddAsPlugin_Click(sender, e); UpdateCharacterInfo(); RefreshSelectedWeapon(); }
/// <summary> /// Select a piece of Gear to be added to the character. /// </summary> private bool PickGear() { bool blnNullParent = false; Gear objSelectedGear = (Gear)_objFunctions.FindEquipment(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear, typeof(Gear)); if (objSelectedGear == null) { objSelectedGear = new Gear(_objCharacter); blnNullParent = true; } // Open the Gear XML file and locate the selected Gear. XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + objSelectedGear.ExternalId + "\"]"); bool blnFakeCareerMode = false; if (_objCharacter.Metatype == "A.I." || _objCharacter.MetatypeCategory == "Technocritters" || _objCharacter.MetatypeCategory == "Protosapients") blnFakeCareerMode = true; frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, blnFakeCareerMode, objSelectedGear.ChildAvailModifier, objSelectedGear.ChildCostMultiplier); try { if (treGear.SelectedNode.Level > 0) { if (objXmlGear["addoncategory"] != null) { 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 += objSelectedGear.Category + ","; // If the Gear has a Capacity with no brackets (meaning it grants Capacity), show only Subsystems (those that conume Capacity). if (!objSelectedGear.Capacity.Contains('[')) frmPickGear.MaximumCapacity = objSelectedGear.CapacityRemaining; if (objSelectedGear.Category == "Commlink") { Commlink objCommlink = (Commlink)objSelectedGear; frmPickGear.CommlinkResponse = objCommlink.Response; frmPickGear.CommlinkSignal = objCommlink.Signal; frmPickGear.CommlinkFirewall = objCommlink.Firewall; frmPickGear.CommlinkSystem = objCommlink.System; } if (objSelectedGear.Category == "Commlink Operating System") { OperatingSystem objOS = (OperatingSystem)objSelectedGear; frmPickGear.CommlinkFirewall = objOS.Firewall; frmPickGear.CommlinkSystem = objOS.System; } } } catch { } frmPickGear.ShowDialog(this); // Make sure the dialogue window was not canceled. if (frmPickGear.DialogResult == DialogResult.Cancel) return false; TreeNode objNode = new TreeNode(); // Open the Cyberware XML file and locate the selected piece. objXmlDocument = XmlManager.Instance.Load("gear.xml"); objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + frmPickGear.SelectedGear + "\"]"); // Create the new piece of Gear. List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); Gear objNewGear = 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; try { _blnSkipRefresh = true; nudGearQty.Increment = objCommlink.CostFor; //nudGearQty.Minimum = nudGearQty.Increment; _blnSkipRefresh = false; } catch { } objNode.Text = objCommlink.DisplayName; // If a Commlink has just been added, see if the character already has one. If not, make it the active Commlink. if (_objFunctions.FindCharacterCommlinks(_objCharacter.Gear).Count == 0 && frmPickGear.SelectedCategory == "Commlink") objCommlink.IsActive = true; objNewGear = 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; try { _blnSkipRefresh = true; nudGearQty.Increment = objOperatingSystem.CostFor; //nudGearQty.Minimum = nudGearQty.Increment; _blnSkipRefresh = false; } catch { } objNode.Text = objOperatingSystem.DisplayName; objNewGear = objOperatingSystem; break; default: Gear objGear = new Gear(_objCharacter); objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic); objGear.Quantity = frmPickGear.SelectedQty; try { _blnSkipRefresh = true; nudGearQty.Increment = objGear.CostFor; //nudGearQty.Minimum = nudGearQty.Increment; _blnSkipRefresh = false; } catch { } objNode.Text = objGear.DisplayName; objNewGear = objGear; break; } if (objNewGear.InternalId == Guid.Empty.ToString()) return false; // Reduce the cost for Do It Yourself components. if (frmPickGear.DoItYourself) objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString(); // Reduce the cost to 10% for Hacked programs. if (frmPickGear.Hacked) { if (objNewGear.Cost != "") objNewGear.Cost = "(" + objNewGear.Cost + ") * 0.1"; if (objNewGear.Cost3 != "") objNewGear.Cost3 = "(" + objNewGear.Cost3 + ") * 0.1"; if (objNewGear.Cost6 != "") objNewGear.Cost6 = "(" + objNewGear.Cost6 + ") * 0.1"; if (objNewGear.Cost10 != "") objNewGear.Cost10 = "(" + objNewGear.Cost10 + ") * 0.1"; if (objNewGear.Extra == "") objNewGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked"); else objNewGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked"); } // If the item was marked as free, change its cost. if (frmPickGear.FreeCost) { objNewGear.Cost = "0"; objNewGear.Cost3 = "0"; objNewGear.Cost6 = "0"; objNewGear.Cost10 = "0"; } // Create any Weapons that came with this 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(); } objNewGear.Parent = objSelectedGear; if (blnNullParent) objNewGear.Parent = null; try { if (treGear.SelectedNode.Level > 0) { objNode.ContextMenuStrip = cmsGear; treGear.SelectedNode.Nodes.Add(objNode); treGear.SelectedNode.Expand(); objSelectedGear.Gears.Add(objNewGear); } else { objNode.ContextMenuStrip = cmsGear; treGear.Nodes[0].Nodes.Add(objNode); treGear.Nodes[0].Expand(); _objCharacter.Gear.Add(objNewGear); } } catch { treGear.Nodes[0].Nodes.Add(objNode); treGear.Nodes[0].Expand(); _objCharacter.Gear.Add(objNewGear); } // Select the node that was just added. if (objNode.Level < 2) treGear.SelectedNode = objNode; UpdateCharacterInfo(); RefreshSelectedGear(); _blnIsDirty = true; UpdateWindowTitle(); return frmPickGear.AddAgain; }
private void tsVehicleAddGear_Click(object sender, EventArgs e) { // Make sure a parent items is selected, then open the Select Gear window. try { if (treVehicles.SelectedNode.Level == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (treVehicles.SelectedNode.Level > 1) treVehicles.SelectedNode = treVehicles.SelectedNode.Parent; // Locate the selected Vehicle. Vehicle objSelectedVehicle = (Vehicle)_objFunctions.FindEquipment(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, typeof(Vehicle)); frmSelectGear frmPickGear = new frmSelectGear(_objCharacter); frmPickGear.ShowPositiveCapacityOnly = true; frmPickGear.ShowDialog(this); if (frmPickGear.DialogResult == DialogResult.Cancel) return; // Open the Gear XML file and locate the selected piece. XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + frmPickGear.SelectedGear + "\"]"); // 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, false); objCommlink.Quantity = frmPickGear.SelectedQty; objGear = objCommlink; break; case "Commlink Operating System": case "Commlink Operating System Upgrade": OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter); objOperatingSystem.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, false); objOperatingSystem.Quantity = frmPickGear.SelectedQty; objGear = objOperatingSystem; break; default: Gear objNewGear = new Gear(_objCharacter); objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, false, true, frmPickGear.Aerodynamic); objNewGear.Quantity = frmPickGear.SelectedQty; 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"; } objGear.Quantity = frmPickGear.SelectedQty; objNode.Text = objGear.DisplayName; try { nudVehicleRating.Increment = objGear.CostFor; nudVehicleRating.Minimum = nudGearQty.Increment; } catch { } // Change the cost of the Sensor itself to 0. if (frmPickGear.SelectedCategory == "Sensors") { objGear.Cost = "0"; objGear.Cost3 = "0"; objGear.Cost6 = "0"; objGear.Cost10 = "0"; } objNode.ContextMenuStrip = cmsVehicleGear; bool blnMatchFound = false; // If this is Ammunition, see if the character already has it on them. if (objGear.Category == "Ammunition") { foreach (Gear objVehicleGear in objSelectedVehicle.Gears) { if (objVehicleGear.Name == objGear.Name && objVehicleGear.Category == objGear.Category && objVehicleGear.Rating == objGear.Rating && objVehicleGear.Extra == objGear.Extra) { // A match was found, so increase the quantity instead. objVehicleGear.Quantity += objGear.Quantity; blnMatchFound = true; foreach (TreeNode objGearNode in treVehicles.SelectedNode.Nodes) { if (objVehicleGear.InternalId == objGearNode.Tag.ToString()) { objGearNode.Text = objVehicleGear.DisplayName; break; } } break; } } } if (!blnMatchFound) { treVehicles.SelectedNode.Nodes.Add(objNode); treVehicles.SelectedNode.Expand(); // Add the Gear to the Vehicle. objSelectedVehicle.Gears.Add(objGear); } if (frmPickGear.AddAgain) tsVehicleAddGear_Click(sender, e); UpdateCharacterInfo(); RefreshSelectedVehicle(); }
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(); }
/// <summary> /// Select a piece of Gear and add it to a piece of Armor. /// </summary> /// <param name="blnShowArmorCapacityOnly">Whether or not only items that consume capacity should be shown.</param> private bool PickArmorGear(bool blnShowArmorCapacityOnly = false) { bool blnNullParent = true; Gear objSelectedGear = new Gear(_objCharacter); Armor objSelectedArmor = new Armor(_objCharacter); foreach (Armor objArmor in _objCharacter.Armor) { if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString()) objSelectedArmor = objArmor; } if (treArmor.SelectedNode.Level > 1) { objSelectedGear = (Gear)_objFunctions.FindEquipment(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor, typeof(Gear)); if (objSelectedGear != null) blnNullParent = false; if (objSelectedGear.Parent != null) objSelectedArmor = (Armor)objSelectedGear.Parent; } // Open the Gear XML file and locate the selected Gear. XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + objSelectedGear.ExternalId + "\"]"); bool blnFakeCareerMode = false; if (_objCharacter.Metatype == "A.I." || _objCharacter.MetatypeCategory == "Technocritters" || _objCharacter.MetatypeCategory == "Protosapients") blnFakeCareerMode = true; frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, blnFakeCareerMode); frmPickGear.ShowArmorCapacityOnly = blnShowArmorCapacityOnly; frmPickGear.CapacityDisplayStyle = objSelectedArmor.CapacityDisplayStyle; try { if (treArmor.SelectedNode.Level > 1) { if (objXmlGear["addoncategory"] != null) { 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 += objSelectedGear.Category + ","; // If the Gear has a Capacity with no brackets (meaning it grants Capacity), show only Subsystems (those that conume Capacity). if (!objSelectedGear.Capacity.Contains('[')) frmPickGear.MaximumCapacity = objSelectedGear.CapacityRemaining; if (objSelectedGear.Category == "Commlink") { Commlink objCommlink = (Commlink)objSelectedGear; frmPickGear.CommlinkResponse = objCommlink.Response; frmPickGear.CommlinkSignal = objCommlink.Signal; frmPickGear.CommlinkFirewall = objCommlink.Firewall; frmPickGear.CommlinkSystem = objCommlink.System; } } else if (treArmor.SelectedNode.Level == 1) { // Open the Armor XML file and locate the selected Gear. objXmlDocument = XmlManager.Instance.Load("armor.xml"); objXmlGear = objXmlDocument.SelectSingleNode("/chummer/armors/armor[id = \"" + objSelectedArmor.ExternalId + "\"]"); if (objXmlGear["addoncategory"] != null) { 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); } } } catch { } frmPickGear.ShowDialog(this); // Make sure the dialogue window was not canceled. if (frmPickGear.DialogResult == DialogResult.Cancel) return false; TreeNode objNode = new TreeNode(); // Open the Cyberware XML file and locate the selected piece. objXmlDocument = XmlManager.Instance.Load("gear.xml"); objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + frmPickGear.SelectedGear + "\"]"); // Create the new piece of Gear. List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); Gear objNewGear = 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; try { nudGearQty.Increment = objCommlink.CostFor; //nudGearQty.Minimum = nudGearQty.Increment; } catch { } objNewGear = 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; try { nudGearQty.Increment = objOperatingSystem.CostFor; //nudGearQty.Minimum = nudGearQty.Increment; } catch { } objNewGear = objOperatingSystem; break; default: Gear objGear = new Gear(_objCharacter); objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", false, false, true, true, frmPickGear.Aerodynamic); objGear.Quantity = frmPickGear.SelectedQty; try { nudGearQty.Increment = objGear.CostFor; //nudGearQty.Minimum = nudGearQty.Increment; } catch { } objNewGear = objGear; break; } if (objNewGear.InternalId == Guid.Empty.ToString()) return false; if (!blnNullParent) objNewGear.Parent = objSelectedGear; // Reduce the cost for Do It Yourself components. if (frmPickGear.DoItYourself) objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString(); // If the item was marked as free, change its cost. if (frmPickGear.FreeCost) { objNewGear.Cost = "0"; objNewGear.Cost3 = "0"; objNewGear.Cost6 = "0"; objNewGear.Cost10 = "0"; } // Create any Weapons that came with this 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(); } bool blnMatchFound = false; // If this is Ammunition, see if the character already has it on them. if (objNewGear.Category == "Ammunition") { foreach (Gear objCharacterGear in _objCharacter.Gear) { if (objCharacterGear.Name == objNewGear.Name && objCharacterGear.Category == objNewGear.Category && objCharacterGear.Rating == objNewGear.Rating && objCharacterGear.Extra == objNewGear.Extra) { // A match was found, so increase the quantity instead. objCharacterGear.Quantity += objNewGear.Quantity; blnMatchFound = true; foreach (TreeNode objGearNode in treGear.Nodes[0].Nodes) { if (objCharacterGear.InternalId == objGearNode.Tag.ToString()) { objGearNode.Text = objCharacterGear.DisplayName; treGear.SelectedNode = objGearNode; break; } } break; } } } // Add the Gear. if (!blnMatchFound) { if (objSelectedGear.Name == string.Empty) { objNode.ContextMenuStrip = cmsArmorGear; treArmor.SelectedNode.Nodes.Add(objNode); treArmor.SelectedNode.Expand(); objSelectedArmor.Gears.Add(objNewGear); } else { objNode.ContextMenuStrip = cmsArmorGear; treArmor.SelectedNode.Nodes.Add(objNode); treArmor.SelectedNode.Expand(); objSelectedGear.Gears.Add(objNewGear); } // Select the node that was just added. treGear.SelectedNode = objNode; } UpdateCharacterInfo(); RefreshSelectedArmor(); _blnIsDirty = true; UpdateWindowTitle(); return frmPickGear.AddAgain; }
private void tsVehicleAddGear_Click(object sender, EventArgs e) { // Make sure a parent items is selected, then open the Select Gear window. try { if (treVehicles.SelectedNode.Level == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (treVehicles.SelectedNode.Level > 1) treVehicles.SelectedNode = treVehicles.SelectedNode.Parent; // Locate the selected Vehicle. Vehicle objSelectedVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles); frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true); frmPickGear.ShowPositiveCapacityOnly = true; frmPickGear.ShowDialog(this); if (frmPickGear.DialogResult == DialogResult.Cancel) return; // Open the Gear XML file and locate the selected piece. XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); XmlNode 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, false); objCommlink.Quantity = frmPickGear.SelectedQty; objGear = objCommlink; break; case "Commlink Operating System": case "Commlink Operating System Upgrade": OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter); objOperatingSystem.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, false); objOperatingSystem.Quantity = frmPickGear.SelectedQty; objGear = objOperatingSystem; break; default: Gear objNewGear = new Gear(_objCharacter); objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, false, true, frmPickGear.Aerodynamic); objNewGear.Quantity = frmPickGear.SelectedQty; 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"; } objGear.Quantity = frmPickGear.SelectedQty; objNode.Text = objGear.DisplayName; // Change the cost of the Sensor itself to 0. if (frmPickGear.SelectedCategory == "Sensors") { objGear.Cost = "0"; objGear.Cost3 = "0"; objGear.Cost6 = "0"; objGear.Cost10 = "0"; } 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) { MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information); if (frmPickGear.AddAgain) tsVehicleAddGear_Click(sender, e); return; } else { // Create the Expense Log Entry. ExpenseLogEntry objExpense = new ExpenseLogEntry(); objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseVehicleGear") + " " + objGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now); _objCharacter.ExpenseEntries.Add(objExpense); _objCharacter.Nuyen -= intCost; ExpenseUndo objUndo = new ExpenseUndo(); objUndo.CreateNuyen(NuyenExpenseType.AddVehicleGear, objGear.InternalId, 1); objExpense.Undo = objUndo; } } objNode.ContextMenuStrip = cmsVehicleGear; bool blnMatchFound = false; // If this is Ammunition, see if the character already has it on them. if (objGear.Category == "Ammunition") { foreach (Gear objVehicleGear in objSelectedVehicle.Gear) { if (objVehicleGear.Name == objGear.Name && objVehicleGear.Category == objGear.Category && objVehicleGear.Rating == objGear.Rating && objVehicleGear.Extra == objGear.Extra) { // A match was found, so increase the quantity instead. objVehicleGear.Quantity += objGear.Quantity; blnMatchFound = true; foreach (TreeNode objGearNode in treVehicles.SelectedNode.Nodes) { if (objVehicleGear.InternalId == objGearNode.Tag.ToString()) { objGearNode.Text = objVehicleGear.DisplayName; break; } } break; } } } if (!blnMatchFound) { treVehicles.SelectedNode.Nodes.Add(objNode); treVehicles.SelectedNode.Expand(); // Add the Gear to the Vehicle. objSelectedVehicle.Gear.Add(objGear); } if (frmPickGear.AddAgain) tsVehicleAddGear_Click(sender, e); UpdateCharacterInfo(); RefreshSelectedVehicle(); _blnIsDirty = true; UpdateWindowTitle(); }
private void tsCyberwareAddGear_Click(object sender, EventArgs e) { // Make sure a parent items is selected, then open the Select Gear window. try { if (treCyberware.SelectedNode.Level == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectCyberware"), LanguageManager.Instance.GetString("MessageTitle_SelectCyberware"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectCyberware"), LanguageManager.Instance.GetString("MessageTitle_SelectCyberware"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Cyberware objCyberware = new Cyberware(_objCharacter); foreach (Cyberware objCharacterCyberware in _objCharacter.Cyberware) { if (objCharacterCyberware.InternalId == treCyberware.SelectedNode.Tag.ToString()) { objCyberware = objCharacterCyberware; break; } foreach (Cyberware objChild in objCharacterCyberware.Children) { if (objChild.InternalId == treCyberware.SelectedNode.Tag.ToString()) { objCyberware = objChild; break; } } } // Make sure the Cyberware is allowed to accept Gear. if (objCyberware.AllowGear == null) { MessageBox.Show(LanguageManager.Instance.GetString("Message_CyberwareGear"), LanguageManager.Instance.GetString("MessageTitle_CyberwareGear"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true); string strCategories = ""; foreach (XmlNode objXmlCategory in objCyberware.AllowGear) strCategories += objXmlCategory.InnerText + ","; frmPickGear.AllowedCategories = strCategories; frmPickGear.ShowDialog(this); if (frmPickGear.DialogResult == DialogResult.Cancel) return; TreeNode objNode = new TreeNode(); // Open the Gear XML file and locate the selected piece. XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); XmlNode 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>(); Gear objNewGear = 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; objNewGear = 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; objNewGear = objOperatingSystem; break; default: Gear objGear = new Gear(_objCharacter); objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic); objGear.Quantity = frmPickGear.SelectedQty; objNode.Text = objGear.DisplayName; objNewGear = objGear; break; } if (objNewGear.InternalId == Guid.Empty.ToString()) return; // Reduce the cost for Do It Yourself components. if (frmPickGear.DoItYourself) objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString(); // Reduce the cost to 10% for Hacked programs. if (frmPickGear.Hacked) { if (objNewGear.Cost != "") objNewGear.Cost = "(" + objNewGear.Cost + ") * 0.1"; if (objNewGear.Cost3 != "") objNewGear.Cost3 = "(" + objNewGear.Cost3 + ") * 0.1"; if (objNewGear.Cost6 != "") objNewGear.Cost6 = "(" + objNewGear.Cost6 + ") * 0.1"; if (objNewGear.Cost10 != "") objNewGear.Cost10 = "(" + objNewGear.Cost10 + ") * 0.1"; if (objNewGear.Extra == "") objNewGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked"); else objNewGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked"); } // If the item was marked as free, change its cost. if (frmPickGear.FreeCost) { objNewGear.Cost = "0"; objNewGear.Cost3 = "0"; objNewGear.Cost6 = "0"; objNewGear.Cost10 = "0"; } int intCost = objNewGear.TotalCost; // Multiply the cost if applicable. if (objNewGear.TotalAvail().EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost) intCost *= _objOptions.RestrictedCostMultiplier; if (objNewGear.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(objNewGear, treWeapons, _objImprovementManager); MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information); if (frmPickGear.AddAgain) tsCyberwareAddGear_Click(sender, e); return; } else { // Create the Expense Log Entry. ExpenseLogEntry objExpense = new ExpenseLogEntry(); objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseCyberwearGear") + " " + objNewGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now); _objCharacter.ExpenseEntries.Add(objExpense); _objCharacter.Nuyen -= intCost; ExpenseUndo objUndo = new ExpenseUndo(); objUndo.CreateNuyen(NuyenExpenseType.AddCyberwareGear, objNewGear.InternalId, 1); objExpense.Undo = objUndo; } } // Create any Weapons that came with this 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(); } objCyberware.Gear.Add(objNewGear); objNode.ContextMenuStrip = cmsCyberwareGear; treCyberware.SelectedNode.Nodes.Add(objNode); treCyberware.SelectedNode.Expand(); UpdateCharacterInfo(); if (frmPickGear.AddAgain) tsCyberwareAddGear_Click(sender, e); _blnIsDirty = true; UpdateWindowTitle(); }
/// <summary> /// Select a piece of Gear to be added to the character. /// </summary> /// <param name="blnAmmoOnly">Whether or not only Ammunition should be shown in the window.</param> /// <param name="objStackGear">Whether or not the selected item should stack with a matching item on the character.</param> /// <param name="strForceItemValue">Force the user to select an item with the passed name..</param> private bool PickGear(bool blnAmmoOnly = false, Gear objStackGear = null, string strForceItemValue = "") { bool blnNullParent = false; Gear objSelectedGear = new Gear(_objCharacter); if (treGear.SelectedNode != null) objSelectedGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear); if (objSelectedGear == null) { objSelectedGear = new Gear(_objCharacter); blnNullParent = true; } ExpenseUndo objUndo = new ExpenseUndo(); // Open the Gear XML file and locate the selected Gear. XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSelectedGear.Name + "\" and category = \"" + objSelectedGear.Category + "\"]"); frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true, objSelectedGear.ChildAvailModifier, objSelectedGear.ChildCostMultiplier); try { if (treGear.SelectedNode.Level > 0) { 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 += objSelectedGear.Category + ","; // If the Gear has a Capacity with no brackets (meaning it grants Capacity), show only Subsystems (those that conume Capacity). if (!objSelectedGear.Capacity.Contains('[')) { frmPickGear.MaximumCapacity = objSelectedGear.CapacityRemaining; // Do not allow the user to add a new piece of Gear if its Capacity has been reached. if (_objOptions.EnforceCapacity && objSelectedGear.CapacityRemaining < 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } } if (objSelectedGear.Category == "Commlink") { Commlink objCommlink = (Commlink)objSelectedGear; frmPickGear.CommlinkResponse = objCommlink.Response; frmPickGear.CommlinkSignal = objCommlink.Signal; frmPickGear.CommlinkFirewall = objCommlink.Firewall; frmPickGear.CommlinkSystem = objCommlink.System; // If a Commlink has just been added, see if the character already has one. If not, make it the active Commlink. if (_objFunctions.FindCharacterCommlinks(_objCharacter.Gear).Count == 0) objCommlink.IsActive = true; } if (objSelectedGear.Category == "Commlink Operating System") { OperatingSystem objOS = (OperatingSystem)objSelectedGear; frmPickGear.CommlinkFirewall = objOS.Firewall; frmPickGear.CommlinkSystem = objOS.System; } } } catch { } if (blnAmmoOnly) { frmPickGear.AllowedCategories = "Ammunition"; frmPickGear.SelectedGear = objSelectedGear.Name; } frmPickGear.ShowDialog(this); // Make sure the dialogue window was not canceled. if (frmPickGear.DialogResult == DialogResult.Cancel) return false; TreeNode objNode = new TreeNode(); // Open the Cyberware XML file and locate the selected piece. objXmlDocument = XmlManager.Instance.Load("gear.xml"); objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]"); // Create the new piece of Gear. Gear objNewGear = new Gear(_objCharacter); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); 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; objNewGear = 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; objNewGear = objOperatingSystem; break; default: string strForceValue = ""; if (blnAmmoOnly) { strForceValue = objSelectedGear.Extra; try { treGear.SelectedNode = treGear.SelectedNode.Parent; } catch { } } if (strForceItemValue != "") strForceValue = strForceItemValue; Gear objGear = new Gear(_objCharacter); objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, strForceValue, frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic); objGear.Quantity = frmPickGear.SelectedQty; objNode.Text = objGear.DisplayName; objNewGear = objGear; break; } objNewGear.Parent = objSelectedGear; if (blnNullParent) objNewGear.Parent = null; if (objNewGear.InternalId == Guid.Empty.ToString()) return false; // Reduce the cost for Do It Yourself components. if (frmPickGear.DoItYourself) objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString(); // Reduce the cost to 10% for Hacked programs. if (frmPickGear.Hacked) { if (objNewGear.Cost != "") objNewGear.Cost = "(" + objNewGear.Cost + ") * 0.1"; if (objNewGear.Cost3 != "") objNewGear.Cost3 = "(" + objNewGear.Cost3 + ") * 0.1"; if (objNewGear.Cost6 != "") objNewGear.Cost6 = "(" + objNewGear.Cost6 + ") * 0.1"; if (objNewGear.Cost10 != "") objNewGear.Cost10 = "(" + objNewGear.Cost10 + ") * 0.1"; if (objNewGear.Extra == "") objNewGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked"); else objNewGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked"); } int intCost = 0; if (objNewGear.Cost.Contains("Gear Cost")) { XPathNavigator nav = objXmlDocument.CreateNavigator(); string strCost = objNewGear.Cost.Replace("Gear Cost", objSelectedGear.CalculatedCost.ToString()); XPathExpression xprCost = nav.Compile(strCost); intCost = Convert.ToInt32(nav.Evaluate(xprCost).ToString()); } else { intCost = Convert.ToInt32(objNewGear.TotalCost); } bool blnMatchFound = false; Gear objStackWith = new Gear(_objCharacter); // See if the character already has the item on them if they chose to stack. if (frmPickGear.Stack) { if (objStackGear != null) { blnMatchFound = true; objStackWith = objStackGear; } else { foreach (Gear objCharacterGear in _objCharacter.Gear) { if (objCharacterGear.Name == objNewGear.Name && objCharacterGear.Category == objNewGear.Category && objCharacterGear.Rating == objNewGear.Rating && objCharacterGear.Extra == objNewGear.Extra) { blnMatchFound = true; objStackWith = objCharacterGear; break; } } } } if (blnMatchFound) { // If a match was found, we need to use the cost of a single item in the stack which can include plugins. foreach (Gear objPlugin in objStackWith.Children) intCost += (objPlugin.TotalCost * frmPickGear.SelectedQty); } if (!blnNullParent && !blnAmmoOnly) intCost *= objSelectedGear.Quantity; // Apply a markup if applicable. if (frmPickGear.Markup != 0) { double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo); dblCost *= 1 + (Convert.ToDouble(frmPickGear.Markup, GlobalOptions.Instance.CultureInfo) / 100.0); intCost = Convert.ToInt32(dblCost); } // Multiply the cost if applicable. if (objNewGear.TotalAvail().EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost) intCost *= _objOptions.RestrictedCostMultiplier; if (objNewGear.TotalAvail().EndsWith(LanguageManager.Instance.GetString("String_AvailForbidden")) && _objOptions.MultiplyForbiddenCost) intCost *= _objOptions.ForbiddenCostMultiplier; // Do not allow the user to add a new piece of Cyberware if its Capacity has been reached. // This is wrapped in a try statement since the character may not have a piece of Gear selected and has clicked the Buy Additional Ammo button for a Weapon. try { if (!blnMatchFound && treGear.SelectedNode.Level > 0) { if (_objOptions.EnforceCapacity && objSelectedGear.CapacityRemaining - objNewGear.PluginCapacity < 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } } } catch { } // Check the item's Cost and make sure the character can afford it. if (!frmPickGear.FreeCost) { if (intCost > _objCharacter.Nuyen) { MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information); // Remove any Improvements created by the Gear. _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objNewGear.InternalId); return frmPickGear.AddAgain; } else { // Create the Expense Log Entry. ExpenseLogEntry objExpense = new ExpenseLogEntry(); objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseGear") + " " + objNewGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now); _objCharacter.ExpenseEntries.Add(objExpense); _objCharacter.Nuyen -= intCost; objUndo.CreateNuyen(NuyenExpenseType.AddGear, objNewGear.InternalId, objNewGear.Quantity); objExpense.Undo = objUndo; } } if (objNewGear.InternalId == Guid.Empty.ToString()) return false; if (blnMatchFound) { // A match was found, so increase the quantity instead. objStackWith.Quantity += objNewGear.Quantity; blnMatchFound = true; if (objUndo.ObjectId != "") objUndo.ObjectId = objStackWith.InternalId; foreach (TreeNode objGearNode in treGear.Nodes[0].Nodes) { if (objStackWith.InternalId == objGearNode.Tag.ToString()) { objGearNode.Text = objStackWith.DisplayName; treGear.SelectedNode = objGearNode; break; } } } // Add the Gear. if (!blnMatchFound) { // Create any Weapons that came with this 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(); } try { if (treGear.SelectedNode.Level > 0) { objNode.ContextMenuStrip = cmsGear; treGear.SelectedNode.Nodes.Add(objNode); treGear.SelectedNode.Expand(); objSelectedGear.Children.Add(objNewGear); } else { objNode.ContextMenuStrip = cmsGear; treGear.Nodes[0].Nodes.Add(objNode); treGear.Nodes[0].Expand(); _objCharacter.Gear.Add(objNewGear); } } catch { treGear.Nodes[0].Nodes.Add(objNode); treGear.Nodes[0].Expand(); _objCharacter.Gear.Add(objNewGear); } // Select the node that was just added. lblGearQty.Text = objNewGear.Quantity.ToString(); if (objNode.Level < 2) treGear.SelectedNode = objNode; } UpdateCharacterInfo(); RefreshSelectedGear(); if (frmPickGear.DialogResult != DialogResult.Cancel) { _blnIsDirty = true; UpdateWindowTitle(); } return frmPickGear.AddAgain; }
/// <summary> /// Select a piece of Gear and add it to a piece of Armor. /// </summary> /// <param name="blnShowArmorCapacityOnly">Whether or not only items that consume capacity should be shown.</param> private bool PickArmorGear(bool blnShowArmorCapacityOnly = false) { bool blnNullParent = true; Gear objSelectedGear = new Gear(_objCharacter); Armor objSelectedArmor = new Armor(_objCharacter); ExpenseUndo objUndo = new ExpenseUndo(); foreach (Armor objArmor in _objCharacter.Armor) { if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString()) objSelectedArmor = objArmor; } if (treArmor.SelectedNode.Level > 1) { objSelectedGear = _objFunctions.FindArmorGear(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor, out objSelectedArmor); if (objSelectedGear != null) blnNullParent = false; } // Open the Gear XML file and locate the selected Gear. XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml"); XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSelectedGear.Name + "\" and category = \"" + objSelectedGear.Category + "\"]"); frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true); frmPickGear.EnableStack = false; frmPickGear.ShowArmorCapacityOnly = blnShowArmorCapacityOnly; frmPickGear.CapacityDisplayStyle = objSelectedArmor.CapacityDisplayStyle; try { if (treArmor.SelectedNode.Level > 1) { 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 += objSelectedGear.Category + ","; // If the Gear has a Capacity with no brackets (meaning it grants Capacity), show only Subsystems (those that conume Capacity). if (!objSelectedGear.Capacity.Contains('[')) { frmPickGear.MaximumCapacity = objSelectedGear.CapacityRemaining; // Do not allow the user to add a new piece of Gear if its Capacity has been reached. if (_objOptions.EnforceCapacity && objSelectedGear.CapacityRemaining < 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } } if (objSelectedGear.Category == "Commlink") { Commlink objCommlink = (Commlink)objSelectedGear; frmPickGear.CommlinkResponse = objCommlink.Response; frmPickGear.CommlinkSignal = objCommlink.Signal; frmPickGear.CommlinkFirewall = objCommlink.Firewall; frmPickGear.CommlinkSystem = objCommlink.System; } } else if (treArmor.SelectedNode.Level == 1) { // Open the Armor XML file and locate the selected Gear. objXmlDocument = XmlManager.Instance.Load("armor.xml"); objXmlGear = objXmlDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objSelectedArmor.Name + "\"]"); 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); } } } catch { } frmPickGear.ShowDialog(this); // Make sure the dialogue window was not canceled. if (frmPickGear.DialogResult == DialogResult.Cancel) return false; TreeNode objNode = new TreeNode(); // Open the Cyberware XML file and locate the selected piece. objXmlDocument = XmlManager.Instance.Load("gear.xml"); objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]"); // Create the new piece of Gear. Gear objNewGear = new Gear(_objCharacter); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); switch (frmPickGear.SelectedCategory) { case "Commlink": case "Commlink Upgrade": Commlink objCommlink = new Commlink(_objCharacter); objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating); objCommlink.Quantity = frmPickGear.SelectedQty; objNewGear = 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; objNewGear = objOperatingSystem; break; default: Gear objGear = new Gear(_objCharacter); objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", false, false, true, true, frmPickGear.Aerodynamic); objGear.Quantity = frmPickGear.SelectedQty; objNewGear = objGear; break; } if (objNewGear.InternalId == Guid.Empty.ToString()) return false; if (!blnNullParent) objNewGear.Parent = objSelectedGear; // Reduce the cost for Do It Yourself components. if (frmPickGear.DoItYourself) objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString(); // Apply a markup if applicable. int intCost = objNewGear.TotalCost; if (frmPickGear.Markup != 0) { double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo); dblCost *= 1 + (Convert.ToDouble(frmPickGear.Markup, GlobalOptions.Instance.CultureInfo) / 100.0); intCost = Convert.ToInt32(dblCost); } // Multiply the cost if applicable. if (objNewGear.TotalAvail().EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost) intCost *= _objOptions.RestrictedCostMultiplier; if (objNewGear.TotalAvail().EndsWith(LanguageManager.Instance.GetString("String_AvailForbidden")) && _objOptions.MultiplyForbiddenCost) intCost *= _objOptions.ForbiddenCostMultiplier; // Do not allow the user to add new Gear if the Armor's Capacity has been reached. if (_objOptions.EnforceCapacity) { objSelectedArmor.Gear.Add(objSelectedGear); if (objSelectedArmor.CapacityRemaining < 0) { objSelectedArmor.Gear.Remove(objSelectedGear); MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information); return frmPickGear.AddAgain; } else objSelectedArmor.Gear.Remove(objSelectedGear); } // Check the item's Cost and make sure the character can afford it. if (!frmPickGear.FreeCost) { if (intCost > _objCharacter.Nuyen) { MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information); // Remove any Improvements created by the Gear. _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objNewGear.InternalId); return frmPickGear.AddAgain; } else { // Create the Expense Log Entry. ExpenseLogEntry objExpense = new ExpenseLogEntry(); objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseArmorGear") + " " + objNewGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now); _objCharacter.ExpenseEntries.Add(objExpense); _objCharacter.Nuyen -= intCost; objUndo.CreateNuyen(NuyenExpenseType.AddArmorGear, objNewGear.InternalId, objNewGear.Quantity); objExpense.Undo = objUndo; } } if (objNewGear.InternalId == Guid.Empty.ToString()) return false; // Create any Weapons that came with this 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(); } bool blnMatchFound = false; // If this is Ammunition, see if the character already has it on them. if (objNewGear.Category == "Ammunition") { foreach (Gear objCharacterGear in _objCharacter.Gear) { if (objCharacterGear.Name == objNewGear.Name && objCharacterGear.Category == objNewGear.Category && objCharacterGear.Rating == objNewGear.Rating && objCharacterGear.Extra == objNewGear.Extra) { // A match was found, so increase the quantity instead. objCharacterGear.Quantity += objNewGear.Quantity; blnMatchFound = true; if (objUndo.ObjectId != "") objUndo.ObjectId = objCharacterGear.InternalId; foreach (TreeNode objGearNode in treGear.Nodes[0].Nodes) { if (objCharacterGear.InternalId == objGearNode.Tag.ToString()) { objGearNode.Text = objCharacterGear.DisplayName; treArmor.SelectedNode = objGearNode; break; } } break; } } } // Add the Gear. if (!blnMatchFound) { if (objSelectedGear.Name == string.Empty) { objNode.ContextMenuStrip = cmsArmorGear; treArmor.SelectedNode.Nodes.Add(objNode); treArmor.SelectedNode.Expand(); objSelectedArmor.Gear.Add(objNewGear); } else { objNode.ContextMenuStrip = cmsArmorGear; treArmor.SelectedNode.Nodes.Add(objNode); treArmor.SelectedNode.Expand(); objSelectedGear.Children.Add(objNewGear); } // Select the node that was just added. treArmor.SelectedNode = objNode; } UpdateCharacterInfo(); RefreshSelectedArmor(); _blnIsDirty = true; UpdateWindowTitle(); return frmPickGear.AddAgain; }
/// <summary> /// Update the Gear's information based on the Gear selected and current Rating. /// </summary> private void UpdateGearInfo() { if (lstGear.Text != "") { // Retireve the information for the selected piece of Cyberware. XmlNode objXmlGear; int intItemCost = 0; string strCategory = ""; objXmlGear = _objXmlDocument.SelectSingleNode("/chummer/gears/gear[id = \"" + lstGear.SelectedValue + "\"]"); strCategory = cboCategory.SelectedValue.ToString(); TreeNode objTreeNode = new TreeNode(); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstTreeNodes = new List<TreeNode>(); Gear objGear = new Gear(_objCharacter); Commlink objCommlink = new Commlink(_objCharacter); OperatingSystem objOperatingSystem = new OperatingSystem(_objCharacter); if (objXmlGear["category"].InnerText == "Commlink" || objXmlGear["category"].InnerText == "Commlink Upgrade") { objCommlink.Create(objXmlGear, _objCharacter, objTreeNode, Convert.ToInt32(nudRating.Value), false, true); objGear = (Gear)objCommlink; } else if (objXmlGear["category"].InnerText == "Operating System" || objXmlGear["category"].InnerText == "Operating System Upgrade") { objOperatingSystem.Create(objXmlGear, _objCharacter, objTreeNode, Convert.ToInt32(nudRating.Value), false, true); objGear = (Gear)objCommlink; } else objGear.Create(objXmlGear, _objCharacter, objTreeNode, Convert.ToInt32(nudRating.Value), lstWeapons, lstTreeNodes, "", chkHacked.Checked, false, false, true, chkAerodynamic.Checked); if (_objCharacter.Metatype == "A.I." || _objCharacter.MetatypeCategory == "Technocritters" || _objCharacter.MetatypeCategory == "Protosapients") { if ((strCategory == "Matrix Programs" || strCategory == "Skillsofts" || strCategory == "Autosofts" || strCategory == "Autosofts, Agent" || strCategory == "Autosofts, Drone") && _objCharacter.Options.BookEnabled("UN") && !lstGear.SelectedValue.ToString().StartsWith("Suite:")) chkInherentProgram.Visible = true; else chkInherentProgram.Visible = false; chkInherentProgram.Enabled = !chkHacked.Checked; if (!chkInherentProgram.Enabled) chkInherentProgram.Checked = false; } else chkInherentProgram.Visible = false; if (objGear.GetType() == typeof(Commlink)) { lblGearResponse.Text = objCommlink.TotalResponse.ToString(); lblGearSignal.Text = objCommlink.TotalSignal.ToString(); lblGearSystem.Text = ""; lblGearFirewall.Text = ""; } else if (objGear.GetType() == typeof(OperatingSystem)) { lblGearResponse.Text = ""; lblGearSignal.Text = ""; lblGearSystem.Text = objOperatingSystem.System.ToString(); lblGearFirewall.Text = objOperatingSystem.Firewall.ToString(); } else { lblGearResponse.Text = ""; lblGearSignal.Text = ""; lblGearSystem.Text = ""; lblGearFirewall.Text = ""; } if (objXmlGear["category"].InnerText.EndsWith("Software") || objXmlGear["category"].InnerText.EndsWith("Programs") || objXmlGear["category"].InnerText == "Program Options" || objXmlGear["category"].InnerText.StartsWith("Autosofts") || objXmlGear["category"].InnerText.StartsWith("Skillsoft") || objXmlGear["category"].InnerText == "Program Packages" || objXmlGear["category"].InnerText == "Software Suites") chkHacked.Visible = true; else chkHacked.Visible = false; string strBook = _objCharacter.Options.LanguageBookShort(objGear.Source); string strPage = objGear.Page; lblSource.Text = strBook + " " + strPage; // Avail. lblAvail.Text = objGear.TotalAvail(); double dblMultiplier = Convert.ToDouble(nudGearQty.Value / nudGearQty.Increment, GlobalOptions.Instance.CultureInfo); if (chkDoItYourself.Checked) dblMultiplier *= 0.5; // Cost. if (objGear.Cost.StartsWith("Variable")) { int intMin = 0; int intMax = 0; string strCost = objGear.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 (intMax == 0) { intMax = 1000000; lblCost.Text = String.Format("{0:###,###,##0¥+}", intMin); } else lblCost.Text = String.Format("{0:###,###,##0}", intMin) + "-" + String.Format("{0:###,###,##0¥}", intMax); intItemCost = intMin; } else { double dblCost = Convert.ToDouble(objGear.TotalCost, GlobalOptions.Instance.CultureInfo); dblCost *= dblMultiplier; dblCost *= 1 + (Convert.ToDouble(nudMarkup.Value, GlobalOptions.Instance.CultureInfo) / 100.0); if (chkHacked.Checked) dblCost *= 0.1; intItemCost = Convert.ToInt32(dblCost); lblCost.Text = String.Format("{0:###,###,##0¥}", intItemCost); } if (chkFreeItem.Checked) { lblCost.Text = String.Format("{0:###,###,##0¥}", 0); intItemCost = 0; } // Update the Avail Test Label. lblTest.Text = _objCharacter.AvailTest(intItemCost * _intCostMultiplier, lblAvail.Text); // Capacity. lblCapacity.Text = objGear.CalculatedCapacity; // Rating. if (Convert.ToInt32(objXmlGear["rating"].InnerText) > 0) { nudRating.Maximum = Convert.ToInt32(objXmlGear["rating"].InnerText); try { nudRating.Minimum = Convert.ToInt32(objXmlGear["minrating"].InnerText); } catch { nudRating.Minimum = 1; } if (nudRating.Minimum == nudRating.Maximum) nudRating.Enabled = false; else nudRating.Enabled = true; } else { nudRating.Minimum = 0; nudRating.Maximum = 0; nudRating.Enabled = false; } tipTooltip.SetToolTip(lblSource, _objCharacter.Options.LanguageBookLong(objGear.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + strPage); } }