private void tsAddArmorMod_Click(object sender, EventArgs e) { // Make sure a parent item is selected, then open the Select Accessory window. try { if (treArmor.SelectedNode.Level == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectArmor"), LanguageManager.Instance.GetString("MessageTitle_SelectArmor"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectArmor"), LanguageManager.Instance.GetString("MessageTitle_SelectArmor"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (treArmor.SelectedNode.Level > 1) treArmor.SelectedNode = treArmor.SelectedNode.Parent; // Locate the Armor that is selected in the tree. Armor objArmor = _objFunctions.FindArmor(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor); // Open the Armor XML file and locate the selected Armor. XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml"); XmlNode objXmlArmor = objXmlDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objArmor.Name + "\"]"); frmSelectArmorMod frmPickArmorMod = new frmSelectArmorMod(_objCharacter); frmPickArmorMod.ArmorCost = objArmor.Cost; frmPickArmorMod.AllowedCategories = objArmor.Category + "," + objArmor.Name; frmPickArmorMod.CapacityDisplayStyle = objArmor.CapacityDisplayStyle; if (objXmlArmor.InnerXml.Contains("<addmodcategory>")) frmPickArmorMod.AllowedCategories += "," + objXmlArmor["addmodcategory"].InnerText; frmPickArmorMod.ShowDialog(this); if (frmPickArmorMod.DialogResult == DialogResult.Cancel) return; // Locate the selected piece. objXmlArmor = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + frmPickArmorMod.SelectedArmorMod + "\"]"); TreeNode objNode = new TreeNode(); ArmorMod objMod = new ArmorMod(_objCharacter); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); int intRating = 0; if (Convert.ToInt32(objXmlArmor["maxrating"].InnerText) > 1) intRating = frmPickArmorMod.SelectedRating; objMod.Create(objXmlArmor, objNode, intRating, lstWeapons, lstWeaponNodes); objMod.Parent = objArmor; objNode.ContextMenuStrip = cmsArmorMod; if (objMod.InternalId == Guid.Empty.ToString()) return; objArmor.ArmorMods.Add(objMod); treArmor.SelectedNode.Nodes.Add(objNode); treArmor.SelectedNode.Expand(); treArmor.SelectedNode = objNode; // Add any Weapons created by the Mod. foreach (Weapon objWeapon in lstWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in lstWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } UpdateCharacterInfo(); RefreshSelectedArmor(); if (frmPickArmorMod.AddAgain) tsAddArmorMod_Click(sender, e); }
/// <summary> /// Add a PACKS Kit to the character. /// </summary> public void AddPACKSKit() { frmSelectPACKSKit frmPickPACKSKit = new frmSelectPACKSKit(_objCharacter); frmPickPACKSKit.ShowDialog(this); bool blnCreateChildren = true; // If the form was canceled, don't do anything. if (frmPickPACKSKit.DialogResult == DialogResult.Cancel) return; XmlDocument objXmlDocument = XmlManager.Instance.Load("packs.xml"); // Do not create child items for Gear if the chosen Kit is in the Custom category since these items will contain the exact plugins desired. //if (frmPickPACKSKit.SelectedCategory == "Custom") //blnCreateChildren = false; XmlNode objXmlKit = objXmlDocument.SelectSingleNode("/chummer/packs/pack[name = \"" + frmPickPACKSKit.SelectedKit + "\" and category = \"" + frmPickPACKSKit.SelectedCategory + "\"]"); // Update Qualities. if (objXmlKit["qualities"] != null) { XmlDocument objXmlQualityDocument = XmlManager.Instance.Load("qualities.xml"); // Positive Qualities. foreach (XmlNode objXmlQuality in objXmlKit.SelectNodes("qualities/positive/quality")) { XmlNode objXmlQualityNode = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQuality.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); Quality objQuality = new Quality(_objCharacter); string strForceValue = ""; if (objXmlQuality.Attributes["select"] != null) strForceValue = objXmlQuality.Attributes["select"].InnerText; objQuality.Create(objXmlQualityNode, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes, strForceValue); _objCharacter.Qualities.Add(objQuality); treQualities.Nodes[0].Nodes.Add(objNode); treQualities.Nodes[0].Expand(); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) _objCharacter.Weapons.Add(objWeapon); // Create the Weapon Node if one exists. foreach (TreeNode objWeaponNode in objWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } } // Negative Qualities. foreach (XmlNode objXmlQuality in objXmlKit.SelectNodes("qualities/negative/quality")) { XmlNode objXmlQualityNode = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQuality.InnerText + "\"]"); TreeNode objNode = new TreeNode(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); Quality objQuality = new Quality(_objCharacter); string strForceValue = ""; if (objXmlQuality.Attributes["select"] != null) strForceValue = objXmlQuality.Attributes["select"].InnerText; objQuality.Create(objXmlQualityNode, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes, strForceValue); _objCharacter.Qualities.Add(objQuality); treQualities.Nodes[1].Nodes.Add(objNode); treQualities.Nodes[1].Expand(); // Add any created Weapons to the character. foreach (Weapon objWeapon in objWeapons) _objCharacter.Weapons.Add(objWeapon); // Create the Weapon Node if one exists. foreach (TreeNode objWeaponNode in objWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } } } // Update Attributes. if (objXmlKit["attributes"] != null) { // Reset all Attributes back to 1 so we don't go over any BP limits. nudBOD.Value = nudBOD.Minimum; nudAGI.Value = nudAGI.Minimum; nudREA.Value = nudREA.Minimum; nudSTR.Value = nudSTR.Minimum; nudCHA.Value = nudCHA.Minimum; nudINT.Value = nudINT.Minimum; nudLOG.Value = nudLOG.Minimum; nudWIL.Value = nudWIL.Minimum; nudEDG.Value = nudEDG.Minimum; nudMAG.Value = nudMAG.Minimum; nudRES.Value = nudRES.Minimum; foreach (XmlNode objXmlAttribute in objXmlKit["attributes"]) { // The CharacterAttribute is calculated as given value - (6 - Metatype Maximum) so that each Metatype has the values from the file adjusted correctly. switch (objXmlAttribute.Name) { case "bod": nudBOD.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.BOD.MetatypeMaximum); break; case "agi": nudAGI.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.AGI.MetatypeMaximum); break; case "rea": nudREA.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.REA.MetatypeMaximum); break; case "str": nudSTR.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.STR.MetatypeMaximum); break; case "cha": nudCHA.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.CHA.MetatypeMaximum); break; case "int": nudINT.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.INT.MetatypeMaximum); break; case "log": nudLOG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.LOG.MetatypeMaximum); break; case "wil": nudWIL.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.WIL.MetatypeMaximum); break; case "mag": nudMAG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.MAG.MetatypeMaximum); break; case "res": nudRES.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.RES.MetatypeMaximum); break; default: nudEDG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.EDG.MetatypeMaximum); break; } } } //TODO: PACKS SKILLS? // Select a Martial Art. if (objXmlKit["selectmartialart"] != null) { string strForcedValue = ""; int intRating = 1; if (objXmlKit["selectmartialart"].Attributes["select"] != null) strForcedValue = objXmlKit["selectmartialart"].Attributes["select"].InnerText; if (objXmlKit["selectmartialart"].Attributes["rating"] != null) intRating = Convert.ToInt32(objXmlKit["selectmartialart"].Attributes["rating"].InnerText); frmSelectMartialArt frmPickMartialArt = new frmSelectMartialArt(_objCharacter); frmPickMartialArt.ForcedValue = strForcedValue; frmPickMartialArt.ShowDialog(this); if (frmPickMartialArt.DialogResult != DialogResult.Cancel) { // Open the Martial Arts XML file and locate the selected piece. XmlDocument objXmlMartialArtDocument = XmlManager.Instance.Load("martialarts.xml"); XmlNode objXmlArt = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + frmPickMartialArt.SelectedMartialArt + "\"]"); TreeNode objNode = new TreeNode(); MartialArt objMartialArt = new MartialArt(_objCharacter); objMartialArt.Create(objXmlArt, objNode, _objCharacter); objMartialArt.Rating = intRating; _objCharacter.MartialArts.Add(objMartialArt); objNode.ContextMenuStrip = cmsMartialArts; treMartialArts.Nodes[0].Nodes.Add(objNode); treMartialArts.Nodes[0].Expand(); treMartialArts.SelectedNode = objNode; } } // Update Martial Arts. if (objXmlKit["martialarts"] != null) { // Open the Martial Arts XML file and locate the selected art. XmlDocument objXmlMartialArtDocument = XmlManager.Instance.Load("martialarts.xml"); foreach (XmlNode objXmlArt in objXmlKit.SelectNodes("martialarts/martialart")) { TreeNode objNode = new TreeNode(); MartialArt objArt = new MartialArt(_objCharacter); XmlNode objXmlArtNode = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + objXmlArt["name"].InnerText + "\"]"); objArt.Create(objXmlArtNode, objNode, _objCharacter); objArt.Rating = Convert.ToInt32(objXmlArt["rating"].InnerText); _objCharacter.MartialArts.Add(objArt); // Check for Advantages. foreach (XmlNode objXmlAdvantage in objXmlArt.SelectNodes("techniques/technique")) { TreeNode objChildNode = new TreeNode(); MartialArtAdvantage objAdvantage = new MartialArtAdvantage(_objCharacter); XmlNode objXmlAdvantageNode = objXmlMartialArtDocument.SelectSingleNode("/chummer/techniques/technique[name = \"" + objXmlAdvantage["name"].InnerText + "\"]"); objAdvantage.Create(objXmlAdvantageNode, _objCharacter, objChildNode); objArt.Advantages.Add(objAdvantage); objNode.Nodes.Add(objChildNode); objNode.Expand(); } treMartialArts.Nodes[0].Nodes.Add(objNode); treMartialArts.Nodes[0].Expand(); } } // Update Adept Powers. if (objXmlKit["powers"] != null) { // Open the Powers XML file and locate the selected power. XmlDocument objXmlPowerDocument = XmlManager.Instance.Load("powers.xml"); foreach (XmlNode objXmlPower in objXmlKit.SelectNodes("powers/power")) { XmlNode objXmlPowerNode = objXmlPowerDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower["name"].InnerText + "\"]"); int i = panPowers.Controls.Count; Power objPower = new Power(_objCharacter); _objCharacter.Powers.Add(objPower); PowerControl objPowerControl = new PowerControl(); objPowerControl.PowerObject = objPower; // Attach an EventHandler for the PowerRatingChanged Event. objPowerControl.PowerRatingChanged += objPower_PowerRatingChanged; objPowerControl.DeletePower += objPower_DeletePower; objPowerControl.PowerName = objXmlPowerNode["name"].InnerText; objPowerControl.PointsPerLevel = Convert.ToDecimal(objXmlPowerNode["points"].InnerText, GlobalOptions.Instance.CultureInfo); objPowerControl.AdeptWayDiscount = Convert.ToDecimal(objXmlPowerNode["adeptway"].InnerText, GlobalOptions.Instance.CultureInfo); if (objXmlPowerNode["levels"].InnerText == "no") { objPowerControl.LevelEnabled = false; } else { objPowerControl.LevelEnabled = true; if (objXmlPowerNode["levels"].InnerText != "yes") objPower.MaxLevels = Convert.ToInt32(objXmlPowerNode["levels"].InnerText); } objPower.Source = objXmlPowerNode["source"].InnerText; objPower.Page = objXmlPowerNode["page"].InnerText; if (objXmlPowerNode["doublecost"] != null) objPower.DoubleCost = false; if (objXmlPowerNode.InnerXml.Contains("bonus")) { objPower.Bonus = objXmlPowerNode["bonus"]; if (objXmlPower["name"].Attributes["select"] != null) _objImprovementManager.ForcedValue = objXmlPower["name"].Attributes["select"].InnerText; _objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Power, objPower.InternalId, objPower.Bonus, false, Convert.ToInt32(objPower.Rating), objPower.DisplayNameShort); objPowerControl.Extra = _objImprovementManager.SelectedValue; } objPowerControl.Top = i * objPowerControl.Height; panPowers.Controls.Add(objPowerControl); // Set the Rating of the Power if applicable. if (objXmlPower["rating"] != null) objPowerControl.PowerLevel = Convert.ToInt32(objXmlPower["rating"].InnerText); } } // Update Complex Forms. if (objXmlKit["programs"] != null) { // Open the Programs XML file and locate the selected program. XmlDocument objXmlProgramDocument = XmlManager.Instance.Load("complexforms.xml"); foreach (XmlNode objXmlProgram in objXmlKit.SelectNodes("complexforms/complexform")) { XmlNode objXmlProgramNode = objXmlProgramDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + objXmlProgram["name"].InnerText + "\"]"); string strForceValue = ""; if (objXmlProgram.Attributes["select"] != null) strForceValue = objXmlProgram.Attributes["select"].InnerText; TreeNode objNode = new TreeNode(); ComplexForm objProgram = new ComplexForm(_objCharacter); objProgram.Create(objXmlProgramNode, _objCharacter, objNode, strForceValue); treComplexForms.Nodes[0].Nodes.Add(objNode); treComplexForms.Nodes[0].Expand(); _objCharacter.ComplexForms.Add(objProgram); treComplexForms.SortCustom(); } } // Update Spells. if (objXmlKit["spells"] != null) { XmlDocument objXmlSpellDocument = XmlManager.Instance.Load("spells.xml"); foreach (XmlNode objXmlSpell in objXmlKit.SelectNodes("spells/spell")) { // Make sure the Spell has not already been added to the character. bool blnFound = false; foreach (TreeNode nodSpell in treSpells.Nodes[0].Nodes) { if (nodSpell.Text == objXmlSpell.InnerText) { blnFound = true; break; } } // The Spell is not in the list, so add it. if (!blnFound) { string strForceValue = ""; if (objXmlSpell.Attributes["select"] != null) strForceValue = objXmlSpell.Attributes["select"].InnerText; XmlNode objXmlSpellNode = objXmlSpellDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + objXmlSpell.InnerText + "\"]"); Spell objSpell = new Spell(_objCharacter); TreeNode objNode = new TreeNode(); objSpell.Create(objXmlSpellNode, _objCharacter, objNode, strForceValue); objNode.ContextMenuStrip = cmsSpell; _objCharacter.Spells.Add(objSpell); switch (objSpell.Category) { case "Combat": treSpells.Nodes[0].Nodes.Add(objNode); treSpells.Nodes[0].Expand(); break; case "Detection": treSpells.Nodes[1].Nodes.Add(objNode); treSpells.Nodes[1].Expand(); break; case "Health": treSpells.Nodes[2].Nodes.Add(objNode); treSpells.Nodes[2].Expand(); break; case "Illusion": treSpells.Nodes[3].Nodes.Add(objNode); treSpells.Nodes[3].Expand(); break; case "Manipulation": treSpells.Nodes[4].Nodes.Add(objNode); treSpells.Nodes[4].Expand(); break; case "Rituals": int intNode = 5; if (_objCharacter.AdeptEnabled && !_objCharacter.MagicianEnabled) intNode = 0; treSpells.Nodes[intNode].Nodes.Add(objNode); treSpells.Nodes[intNode].Expand(); break; } treSpells.SortCustom(); } } } // Update Spirits. if (objXmlKit["spirits"] != null) { foreach (XmlNode objXmlSpirit in objXmlKit.SelectNodes("spirits/spirit")) { int i = panSpirits.Controls.Count; Spirit objSpirit = new Spirit(_objCharacter); _objCharacter.Spirits.Add(objSpirit); SpiritControl objSpiritControl = new SpiritControl(); objSpiritControl.SpiritObject = objSpirit; objSpiritControl.EntityType = SpiritType.Spirit; // Attach an EventHandler for the ServicesOwedChanged Event. objSpiritControl.ServicesOwedChanged += objSpirit_ServicesOwedChanged; objSpiritControl.ForceChanged += objSpirit_ForceChanged; objSpiritControl.BoundChanged += objSpirit_BoundChanged; objSpiritControl.DeleteSpirit += objSpirit_DeleteSpirit; objSpiritControl.Name = objXmlSpirit["name"].InnerText; objSpiritControl.Force = Convert.ToInt32(objXmlSpirit["force"].InnerText); objSpiritControl.ServicesOwed = Convert.ToInt32(objXmlSpirit["services"].InnerText); objSpiritControl.Top = i * objSpiritControl.Height; panSpirits.Controls.Add(objSpiritControl); } } // Update Lifestyles. if (objXmlKit["lifestyles"] != null) { XmlDocument objXmlLifestyleDocument = XmlManager.Instance.Load("lifestyles.xml"); foreach (XmlNode objXmlLifestyle in objXmlKit.SelectNodes("lifestyles/lifestyle")) { string strName = objXmlLifestyle["name"].InnerText; int intMonths = Convert.ToInt32(objXmlLifestyle["months"].InnerText); // Create the Lifestyle. TreeNode objNode = new TreeNode(); Lifestyle objLifestyle = new Lifestyle(_objCharacter); XmlNode objXmlLifestyleNode = objXmlLifestyleDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + strName + "\"]"); if (objXmlLifestyleNode != null) { // This is a standard Lifestyle, so just use the Create method. objLifestyle.Create(objXmlLifestyleNode, objNode); objLifestyle.Months = intMonths; } else { // This is an Advanced Lifestyle, so build it manually. objLifestyle.Name = strName; objLifestyle.Months = intMonths; objLifestyle.Cost = Convert.ToInt32(objXmlLifestyle["cost"].InnerText); objLifestyle.Dice = Convert.ToInt32(objXmlLifestyle["dice"].InnerText); objLifestyle.Multiplier = Convert.ToInt32(objXmlLifestyle["multiplier"].InnerText); objLifestyle.BaseLifestyle = objXmlLifestyle["baselifestyle"].InnerText; objLifestyle.Source = "SR5"; objLifestyle.Page = "373"; objLifestyle.Comforts = Convert.ToInt32(objXmlLifestyle["comforts"].InnerText); objLifestyle.ComfortsEntertainment = Convert.ToInt32(objXmlLifestyle["comfortsentertainment"].InnerText); objLifestyle.Security = Convert.ToInt32(objXmlLifestyle["security"].InnerText); objLifestyle.SecurityEntertainment = Convert.ToInt32(objXmlLifestyle["securityentertainment"].InnerText); objLifestyle.Area = Convert.ToInt32(objXmlLifestyle["area"].InnerText); objLifestyle.AreaEntertainment = Convert.ToInt32(objXmlLifestyle["areaentertainment"].InnerText); foreach (LifestyleQuality objXmlQuality in objXmlLifestyle.SelectNodes("lifestylequalities/lifestylequality")) objLifestyle.LifestyleQualities.Add(objXmlQuality); objNode.Text = strName; } // Add the Lifestyle to the character and Lifestyle Tree. if (objLifestyle.BaseLifestyle != "") objNode.ContextMenuStrip = cmsAdvancedLifestyle; else objNode.ContextMenuStrip = cmsLifestyleNotes; _objCharacter.Lifestyles.Add(objLifestyle); treLifestyles.Nodes[0].Nodes.Add(objNode); treLifestyles.Nodes[0].Expand(); } } // Update NuyenBP. if (objXmlKit["nuyenbp"] != null) { int intAmount = Convert.ToInt32(objXmlKit["nuyenbp"].InnerText); //if (_objCharacter.BuildMethod == CharacterBuildMethod.Karma) //intAmount *= 2; // Make sure we don't go over the field's maximum which would throw an Exception. if (nudNuyen.Value + intAmount > nudNuyen.Maximum) nudNuyen.Value = nudNuyen.Maximum; else nudNuyen.Value += intAmount; } // Update Armor. if (objXmlKit["armors"] != null) { XmlDocument objXmlArmorDocument = XmlManager.Instance.Load("armor.xml"); foreach (XmlNode objXmlArmor in objXmlKit.SelectNodes("armors/armor")) { XmlNode objXmlArmorNode = objXmlArmorDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objXmlArmor["name"].InnerText + "\"]"); Armor objArmor = new Armor(_objCharacter); TreeNode objNode = new TreeNode(); int intArmorRating = 0; if (objXmlArmor["rating"] != null) { intArmorRating = Convert.ToInt32(objXmlArmor["rating"].InnerText); } objArmor.Create(objXmlArmorNode, objNode, cmsArmorMod, intArmorRating, false, blnCreateChildren); _objCharacter.Armor.Add(objArmor); // Look for Armor Mods. if (objXmlArmor["mods"] != null) { foreach (XmlNode objXmlMod in objXmlArmor.SelectNodes("mods/mod")) { List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); XmlNode objXmlModNode = objXmlArmorDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]"); ArmorMod objMod = new ArmorMod(_objCharacter); TreeNode objModNode = new TreeNode(); int intRating = 0; if (objXmlMod["rating"] != null) intRating = Convert.ToInt32(objXmlMod["rating"].InnerText); objMod.Create(objXmlModNode, objModNode, intRating, lstWeapons, lstWeaponNodes); objModNode.ContextMenuStrip = cmsArmorMod; objMod.Parent = objArmor; objArmor.ArmorMods.Add(objMod); objNode.Nodes.Add(objModNode); objNode.Expand(); // Add any Weapons created by the Mod. foreach (Weapon objWeapon in lstWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in lstWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } } } XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlArmor.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objNode, objArmor, cmsArmorGear, blnCreateChildren); objNode.ContextMenuStrip = cmsArmor; treArmor.Nodes[0].Nodes.Add(objNode); treArmor.Nodes[0].Expand(); } } // Update Weapons. if (objXmlKit["weapons"] != null) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("weapons/weapon").Count; int i = 0; foreach (XmlNode objXmlWeapon in objXmlKit.SelectNodes("weapons/weapon")) { i++; pgbProgress.Value = i; Application.DoEvents(); XmlNode objXmlWeaponNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["name"].InnerText + "\"]"); Weapon objWeapon = new Weapon(_objCharacter); TreeNode objNode = new TreeNode(); objWeapon.Create(objXmlWeaponNode, _objCharacter, objNode, cmsWeapon, cmsWeaponAccessory, blnCreateChildren); _objCharacter.Weapons.Add(objWeapon); // Look for Weapon Accessories. if (objXmlWeapon["accessories"] != null) { foreach (XmlNode objXmlAccessory in objXmlWeapon.SelectNodes("accessories/accessory")) { XmlNode objXmlAccessoryNode = objXmlWeaponDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + objXmlAccessory["name"].InnerText + "\"]"); WeaponAccessory objMod = new WeaponAccessory(_objCharacter); TreeNode objModNode = new TreeNode(); string strMount = ""; int intRating = 0; if (objXmlAccessory["mount"] != null) strMount = objXmlAccessory["mount"].InnerText; objMod.Create(objXmlAccessoryNode, objModNode, strMount, intRating); objModNode.ContextMenuStrip = cmsWeaponAccessory; objMod.Parent = objWeapon; objWeapon.WeaponAccessories.Add(objMod); XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlAccessory.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objModNode, objMod, cmsWeaponAccessoryGear, blnCreateChildren); objNode.Nodes.Add(objModNode); objNode.Expand(); } } // Look for an Underbarrel Weapon. if (objXmlWeapon["underbarrel"] != null) { XmlNode objXmlUnderbarrelNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["underbarrel"].InnerText + "\"]"); Weapon objUnderbarrelWeapon = new Weapon(_objCharacter); TreeNode objUnderbarrelNode = new TreeNode(); objUnderbarrelWeapon.Create(objXmlUnderbarrelNode, _objCharacter, objUnderbarrelNode, cmsWeapon, cmsWeaponAccessory, blnCreateChildren); objWeapon.UnderbarrelWeapons.Add(objUnderbarrelWeapon); objNode.Nodes.Add(objUnderbarrelNode); objNode.Expand(); } objNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objNode); treWeapons.Nodes[0].Expand(); Application.DoEvents(); } } // Update Cyberware. if (objXmlKit["cyberwares"] != null) { XmlDocument objXmlCyberwareDocument = XmlManager.Instance.Load("cyberware.xml"); XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("cyberwares/cyberware").Count; int i = 0; foreach (XmlNode objXmlCyberware in objXmlKit.SelectNodes("cyberwares/cyberware")) { i++; pgbProgress.Value = i; Application.DoEvents(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); TreeNode objNode = new TreeNode(); Cyberware objCyberware = new Cyberware(_objCharacter); Grade objGrade = objCyberware.ConvertToCyberwareGrade(objXmlCyberware["grade"].InnerText, Improvement.ImprovementSource.Cyberware); int intRating = 0; if (objXmlCyberware["rating"] != null) intRating = Convert.ToInt32(objXmlCyberware["rating"].InnerText); XmlNode objXmlCyberwareNode = objXmlCyberwareDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + objXmlCyberware["name"].InnerText + "\"]"); objCyberware.Create(objXmlCyberwareNode, _objCharacter, objGrade, Improvement.ImprovementSource.Cyberware, intRating, objNode, objWeapons, objWeaponNodes, true, blnCreateChildren); _objCharacter.Cyberware.Add(objCyberware); // Add any children. if (objXmlCyberware["cyberwares"] != null) { foreach (XmlNode objXmlChild in objXmlCyberware.SelectNodes("cyberwares/cyberware")) { TreeNode objChildNode = new TreeNode(); Cyberware objChildCyberware = new Cyberware(_objCharacter); int intChildRating = 0; if (objXmlChild["rating"] != null) intChildRating = Convert.ToInt32(objXmlChild["rating"].InnerText); XmlNode objXmlChildNode = objXmlCyberwareDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + objXmlChild["name"].InnerText + "\"]"); objChildCyberware.Create(objXmlChildNode, _objCharacter, objGrade, Improvement.ImprovementSource.Cyberware, intChildRating, objChildNode, objWeapons, objWeaponNodes, true, blnCreateChildren); objCyberware.Children.Add(objChildCyberware); objChildNode.ContextMenuStrip = cmsCyberware; foreach (XmlNode objXmlGear in objXmlChild.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objChildNode, objChildCyberware, cmsCyberwareGear, blnCreateChildren); objNode.Nodes.Add(objChildNode); objNode.Expand(); } } foreach (XmlNode objXmlGear in objXmlCyberware.SelectNodes("gears/gear")) AddPACKSGear(objXmlGearDocument, objXmlGear, objNode, objCyberware, cmsCyberwareGear, blnCreateChildren); objNode.ContextMenuStrip = cmsCyberware; treCyberware.Nodes[0].Nodes.Add(objNode); treCyberware.Nodes[0].Expand(); // Add any Weapons created by the Gear. foreach (Weapon objWeapon in objWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in objWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } Application.DoEvents(); } treCyberware.SortCustom(); } // Update Bioware. if (objXmlKit["biowares"] != null) { XmlDocument objXmlBiowareDocument = XmlManager.Instance.Load("bioware.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("biowares/bioware").Count; int i = 0; foreach (XmlNode objXmlBioware in objXmlKit.SelectNodes("biowares/bioware")) { i++; pgbProgress.Value = i; Application.DoEvents(); List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); TreeNode objNode = new TreeNode(); Cyberware objCyberware = new Cyberware(_objCharacter); Grade objGrade = objCyberware.ConvertToCyberwareGrade(objXmlBioware["grade"].InnerText, Improvement.ImprovementSource.Bioware); int intRating = 0; if (objXmlBioware["rating"] != null) intRating = Convert.ToInt32(objXmlBioware["rating"].InnerText); XmlNode objXmlBiowareNode = objXmlBiowareDocument.SelectSingleNode("/chummer/biowares/bioware[name = \"" + objXmlBioware["name"].InnerText + "\"]"); objCyberware.Create(objXmlBiowareNode, _objCharacter, objGrade, Improvement.ImprovementSource.Bioware, intRating, objNode, objWeapons, objWeaponNodes, true, blnCreateChildren); _objCharacter.Cyberware.Add(objCyberware); objNode.ContextMenuStrip = cmsBioware; treCyberware.Nodes[1].Nodes.Add(objNode); treCyberware.Nodes[1].Expand(); // Add any Weapons created by the Gear. foreach (Weapon objWeapon in objWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in objWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } Application.DoEvents(); } treCyberware.SortCustom(); } // Update Gear. if (objXmlKit["gears"] != null) { XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("gears/gear").Count; int i = 0; foreach (XmlNode objXmlGear in objXmlKit.SelectNodes("gears/gear")) { i++; pgbProgress.Value = i; Application.DoEvents(); AddPACKSGear(objXmlGearDocument, objXmlGear, treGear.Nodes[0], _objCharacter, cmsGear, blnCreateChildren); Application.DoEvents(); } } // Update Vehicles. if (objXmlKit["vehicles"] != null) { XmlDocument objXmlVehicleDocument = XmlManager.Instance.Load("vehicles.xml"); pgbProgress.Visible = true; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlKit.SelectNodes("vehicles/vehicle").Count; int i = 0; foreach (XmlNode objXmlVehicle in objXmlKit.SelectNodes("vehicles/vehicle")) { i++; pgbProgress.Value = i; Application.DoEvents(); Gear objDefaultSensor = new Gear(_objCharacter); TreeNode objNode = new TreeNode(); Vehicle objVehicle = new Vehicle(_objCharacter); XmlNode objXmlVehicleNode = objXmlVehicleDocument.SelectSingleNode("/chummer/vehicles/vehicle[name = \"" + objXmlVehicle["name"].InnerText + "\"]"); objVehicle.Create(objXmlVehicleNode, objNode, cmsVehicle, cmsVehicleGear, cmsVehicleWeapon, cmsVehicleWeaponAccessory, blnCreateChildren); _objCharacter.Vehicles.Add(objVehicle); // Grab the default Sensor that comes with the Vehicle. foreach (Gear objSensorGear in objVehicle.Gear) { if (objSensorGear.Category == "Sensors" && objSensorGear.Cost == "0" && objSensorGear.Rating == 0) { objDefaultSensor = objSensorGear; break; } } // Add any Vehicle Mods. if (objXmlVehicle["mods"] != null) { foreach (XmlNode objXmlMod in objXmlVehicle.SelectNodes("mods/mod")) { TreeNode objModNode = new TreeNode(); VehicleMod objMod = new VehicleMod(_objCharacter); int intRating = 0; if (objXmlMod["rating"] != null) intRating = Convert.ToInt32(objXmlMod["rating"].InnerText); XmlNode objXmlModNode = objXmlVehicleDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]"); objMod.Create(objXmlModNode, objModNode, intRating); objVehicle.Mods.Add(objMod); objNode.Nodes.Add(objModNode); objNode.Expand(); } } // Add any Vehicle Gear. if (objXmlVehicle["gears"] != null) { XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlGear in objXmlVehicle.SelectNodes("gears/gear")) { List<Weapon> objWeapons = new List<Weapon>(); List<TreeNode> objWeaponNodes = new List<TreeNode>(); TreeNode objGearNode = new TreeNode(); Gear objGear = new Gear(_objCharacter); int intQty = 1; int intRating = 0; if (objXmlGear["rating"] != null) intRating = Convert.ToInt32(objXmlGear["rating"].InnerText); string strForceValue = ""; if (objXmlGear["name"].Attributes["select"] != null) strForceValue = objXmlGear["name"].Attributes["select"].InnerText; if (objXmlGear["qty"] != null) intQty = Convert.ToInt32(objXmlGear["qty"].InnerText); XmlNode objXmlGearNode = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear["name"].InnerText + "\"]"); objGear.Create(objXmlGearNode, _objCharacter, objGearNode, intRating, objWeapons, objWeaponNodes, strForceValue, false, false, false, blnCreateChildren, false); objGear.Quantity = intQty; objGearNode.Text = objGear.DisplayName; objVehicle.Gear.Add(objGear); // Look for child components. if (objXmlGear["gears"] != null) { foreach (XmlNode objXmlChild in objXmlGear.SelectNodes("gears/gear")) { AddPACKSGear(objXmlGearDocument, objXmlChild, objGearNode, objGear, cmsVehicleGear, blnCreateChildren); } } objGearNode.Expand(); objGearNode.ContextMenuStrip = cmsVehicleGear; objNode.Nodes.Add(objGearNode); objNode.Expand(); // If this is a Sensor, it will replace the Vehicle's base sensor, so remove it. if (objGear.Category == "Sensors" && objGear.Cost == "0" && objGear.Rating == 0) { objVehicle.Gear.Remove(objDefaultSensor); foreach (TreeNode objSensorNode in objNode.Nodes) { if (objSensorNode.Tag.ToString() == objDefaultSensor.InternalId) { objSensorNode.Remove(); break; } } } } } // Add any Vehicle Weapons. if (objXmlVehicle["weapons"] != null) { XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml"); foreach (XmlNode objXmlWeapon in objXmlVehicle.SelectNodes("weapons/weapon")) { TreeNode objWeaponNode = new TreeNode(); Weapon objWeapon = new Weapon(_objCharacter); XmlNode objXmlWeaponNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["name"].InnerText + "\"]"); objWeapon.Create(objXmlWeaponNode, _objCharacter, objWeaponNode, cmsVehicleWeapon, cmsVehicleWeaponAccessory, blnCreateChildren); objWeapon.VehicleMounted = true; // Find the first Weapon Mount in the Vehicle. foreach (VehicleMod objMod in objVehicle.Mods) { if (objMod.Name.Contains("Weapon Mount") || (objMod.WeaponMountCategories != "" && objMod.WeaponMountCategories.Contains(objWeapon.Category))) { objMod.Weapons.Add(objWeapon); foreach (TreeNode objModNode in objNode.Nodes) { if (objModNode.Tag.ToString() == objMod.InternalId) { objWeaponNode.ContextMenuStrip = cmsVehicleWeapon; objModNode.Nodes.Add(objWeaponNode); objModNode.Expand(); break; } } break; } } // Look for Weapon Accessories. if (objXmlWeapon["accessories"] != null) { foreach (XmlNode objXmlAccessory in objXmlWeapon.SelectNodes("accessories/accessory")) { XmlNode objXmlAccessoryNode = objXmlWeaponDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + objXmlAccessory["name"].InnerText + "\"]"); WeaponAccessory objMod = new WeaponAccessory(_objCharacter); TreeNode objModNode = new TreeNode(); string strMount = ""; int intRating = 0; if (objXmlAccessory["mount"] != null) strMount = objXmlAccessory["mount"].InnerText; objMod.Create(objXmlAccessoryNode, objModNode, strMount,intRating); objModNode.ContextMenuStrip = cmsWeaponAccessory; objMod.Parent = objWeapon; objWeapon.WeaponAccessories.Add(objMod); objWeaponNode.Nodes.Add(objModNode); objWeaponNode.Expand(); } } } } objNode.ContextMenuStrip = cmsVehicle; treVehicles.Nodes[0].Nodes.Add(objNode); treVehicles.Nodes[0].Expand(); Application.DoEvents(); } } pgbProgress.Visible = false; if (frmPickPACKSKit.AddAgain) AddPACKSKit(); PopulateGearList(); UpdateCharacterInfo(); }
/// Create a Cyberware from an XmlNode and return the TreeNodes for it. /// <param name="objXmlArmorNode">XmlNode to create the object from.</param> /// <param name="objNode">TreeNode to populate a TreeView.</param> /// <param name="cmsArmorMod">ContextMenuStrip to apply to Armor Mode TreeNodes.</param> /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param> /// <param name="blnCreateChildren">Whether or not child items should be created.</param> public void Create(XmlNode objXmlArmorNode, TreeNode objNode, ContextMenuStrip cmsArmorMod, int intRating, bool blnSkipCost = false, bool blnCreateChildren = true) { _strName = objXmlArmorNode["name"].InnerText; _strCategory = objXmlArmorNode["category"].InnerText; _strA = objXmlArmorNode["armor"].InnerText; if (objXmlArmorNode["armoroverride"] != null) _strO = objXmlArmorNode["armoroverride"].InnerText; _intRating = intRating; if (objXmlArmorNode["rating"] != null) _intMaxRating = Convert.ToInt32(objXmlArmorNode["rating"].InnerText); _strArmorCapacity = objXmlArmorNode["armorcapacity"].InnerText; _strAvail = objXmlArmorNode["avail"].InnerText; _strSource = objXmlArmorNode["source"].InnerText; _strPage = objXmlArmorNode["page"].InnerText; _nodBonus = objXmlArmorNode["bonus"]; if (GlobalOptions.Instance.Language != "en-us") { XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml"); XmlNode objArmorNode = objXmlDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + _strName + "\"]"); if (objArmorNode != null) { if (objArmorNode["translate"] != null) _strAltName = objArmorNode["translate"].InnerText; if (objArmorNode["altpage"] != null) _strAltPage = objArmorNode["altpage"].InnerText; } objArmorNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]"); if (objNode != null) { if (objArmorNode.Attributes["translate"] != null) _strAltCategory = objArmorNode.Attributes["translate"].InnerText; } } // Check for a Variable Cost. if (objXmlArmorNode["cost"].InnerText.StartsWith("Variable")) { if (blnSkipCost) _strCost = "0"; else { int intMin = 0; int intMax = 0; string strCost = objXmlArmorNode["cost"].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(); _strCost = frmPickNumber.SelectedValue.ToString(); } } } else if (objXmlArmorNode["cost"].InnerText.StartsWith("Rating")) { // If the cost is determined by the Rating, evaluate the expression. XmlDocument objXmlDocument = new XmlDocument(); XPathNavigator nav = objXmlDocument.CreateNavigator(); string strCost = ""; string strCostExpression = _strCost; strCost = strCostExpression.Replace("Rating", _intRating.ToString()); XPathExpression xprCost = nav.Compile(strCost); _strCost = nav.Evaluate(xprCost).ToString(); } else { _strCost = objXmlArmorNode["cost"].InnerText; } if (objXmlArmorNode["bonus"] != null && !blnSkipCost) { ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter); if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Armor, _guiID.ToString(), objXmlArmorNode["bonus"], false, 1, DisplayNameShort)) { _guiID = Guid.Empty; return; } if (objImprovementManager.SelectedValue != "") { _strExtra = objImprovementManager.SelectedValue; objNode.Text += " (" + objImprovementManager.SelectedValue + ")"; } } // Add any Armor Mods that come with the Armor. if (objXmlArmorNode["mods"] != null && blnCreateChildren) { XmlDocument objXmlArmorDocument = XmlManager.Instance.Load("armor.xml"); foreach (XmlNode objXmlArmorMod in objXmlArmorNode.SelectNodes("mods/name")) { intRating = 0; string strForceValue = ""; if (objXmlArmorMod.Attributes["rating"] != null) intRating = Convert.ToInt32(objXmlArmorMod.Attributes["rating"].InnerText); if (objXmlArmorMod.Attributes["select"] != null) strForceValue = objXmlArmorMod.Attributes["select"].ToString(); XmlNode objXmlMod = objXmlArmorDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlArmorMod.InnerText + "\"]"); if (objXmlMod != null) { ArmorMod objMod = new ArmorMod(_objCharacter); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); TreeNode objModNode = new TreeNode(); objMod.Create(objXmlMod, objModNode, intRating, lstWeapons, lstWeaponNodes, blnSkipCost); objMod.Parent = this; objMod.IncludedInArmor = true; objMod.ArmorCapacity = "[0]"; objMod.Cost = "0"; objMod.MaximumRating = objMod.Rating; _lstArmorMods.Add(objMod); objModNode.ContextMenuStrip = cmsArmorMod; objNode.Nodes.Add(objModNode); objNode.Expand(); } else { ArmorMod objMod = new ArmorMod(_objCharacter); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); TreeNode objModNode = new TreeNode(); objMod.Name = objXmlArmorNode["name"].InnerText; objMod.Category = "Features"; objMod.Avail = "0"; objMod.Source = _strSource; objMod.Page = _strPage; objMod.Parent = this; objMod.IncludedInArmor = true; objMod.ArmorCapacity = "[0]"; objMod.Cost = "0"; objMod.Rating = 0; objMod.MaximumRating = objMod.Rating; _lstArmorMods.Add(objMod); objModNode.ContextMenuStrip = cmsArmorMod; objNode.Nodes.Add(objModNode); objNode.Expand(); } } } // Add any Gear that comes with the Armor. if (objXmlArmorNode["gears"] != null && blnCreateChildren) { XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml"); foreach (XmlNode objXmlArmorGear in objXmlArmorNode.SelectNodes("gears/usegear")) { intRating = 0; string strForceValue = ""; if (objXmlArmorGear.Attributes["rating"] != null) intRating = Convert.ToInt32(objXmlArmorGear.Attributes["rating"].InnerText); if (objXmlArmorGear.Attributes["select"] != null) strForceValue = objXmlArmorGear.Attributes["select"].InnerText; XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlArmorGear.InnerText + "\"]"); Gear objGear = new Gear(_objCharacter); TreeNode objGearNode = new TreeNode(); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); objGear.Create(objXmlGear, _objCharacter, objGearNode, intRating, lstWeapons, lstWeaponNodes, strForceValue, false, false, !blnSkipCost); objGear.Capacity = "[0]"; objGear.ArmorCapacity = "[0]"; objGear.Cost = "0"; objGear.MaxRating = objGear.Rating; objGear.MinRating = objGear.Rating; objGear.IncludedInParent = true; _lstGear.Add(objGear); objNode.Nodes.Add(objGearNode); objNode.Expand(); } } objNode.Text = DisplayName; objNode.Tag = _guiID.ToString(); }
private void TestArmor() { Character objCharacter = new Character(); XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml"); pgbProgress.Minimum = 0; pgbProgress.Value = 0; pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/armors/armor").Count; pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/mods/mod").Count; // Armor. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/armors/armor")) { pgbProgress.Value++; Application.DoEvents(); try { TreeNode objTempNode = new TreeNode(); Armor objTemp = new Armor(objCharacter); objTemp.Create(objXmlGear, objTempNode, null, 0); try { int objValue = objTemp.TotalCost; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\n"; } try { int objValue = objTemp.TotalArmor; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalArmor\n"; } try { string objValue = objTemp.TotalAvail; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\n"; } try { string objValue = objTemp.CalculatedCapacity; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCapacity\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\n"; } } // Armor Mods. foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/mods/mod")) { pgbProgress.Value++; Application.DoEvents(); try { TreeNode objTempNode = new TreeNode(); ArmorMod objTemp = new ArmorMod(objCharacter); List<Weapon> lstWeaopns = new List<Weapon>(); List<TreeNode> lstNodes = new List<TreeNode>(); objTemp.Create(objXmlGear, objTempNode, 1, lstWeaopns, lstNodes); try { string objValue = objTemp.TotalAvail; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\n"; } try { string objValue = objTemp.CalculatedCapacity; } catch { txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCapacity\n"; } } catch { txtOutput.Text += objXmlGear["name"].InnerText + " general failure\n"; } } }
private void tsAddArmorMod_Click(object sender, EventArgs e) { // Make sure a parent item is selected, then open the Select Accessory window. try { if (treArmor.SelectedNode.Level == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectArmor"), LanguageManager.Instance.GetString("MessageTitle_SelectArmor"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch { MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectArmor"), LanguageManager.Instance.GetString("MessageTitle_SelectArmor"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (treArmor.SelectedNode.Level > 1) treArmor.SelectedNode = treArmor.SelectedNode.Parent; // Locate the Armor that is selected in the tree. Armor objArmor = _objFunctions.FindArmor(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor); // Open the Armor XML file and locate the selected Armor. XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml"); XmlNode objXmlArmor = objXmlDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objArmor.Name + "\"]"); frmSelectArmorMod frmPickArmorMod = new frmSelectArmorMod(_objCharacter, true); frmPickArmorMod.ArmorCost = objArmor.Cost; frmPickArmorMod.AllowedCategories = objArmor.Category + "," + objArmor.Name; frmPickArmorMod.CapacityDisplayStyle = objArmor.CapacityDisplayStyle; if (objXmlArmor.InnerXml.Contains("<addmodcategory>")) frmPickArmorMod.AllowedCategories += "," + objXmlArmor["addmodcategory"].InnerText; frmPickArmorMod.ShowDialog(this); if (frmPickArmorMod.DialogResult == DialogResult.Cancel) return; // Locate the selected piece. objXmlArmor = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + frmPickArmorMod.SelectedArmorMod + "\"]"); TreeNode objNode = new TreeNode(); ArmorMod objMod = new ArmorMod(_objCharacter); List<Weapon> lstWeapons = new List<Weapon>(); List<TreeNode> lstWeaponNodes = new List<TreeNode>(); int intRating = 0; if (Convert.ToInt32(objXmlArmor["maxrating"].InnerText) > 1) intRating = frmPickArmorMod.SelectedRating; objMod.Create(objXmlArmor, objNode, intRating, lstWeapons, lstWeaponNodes); objMod.Parent = objArmor; objNode.ContextMenuStrip = cmsArmorMod; if (objMod.InternalId == Guid.Empty.ToString()) return; // Check the item's Cost and make sure the character can afford it. int intOriginalCost = objArmor.TotalCost; objArmor.ArmorMods.Add(objMod); // Do not allow the user to add a new piece of Armor if its Capacity has been reached. if (_objOptions.EnforceCapacity && objArmor.CapacityRemaining < 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information); objArmor.ArmorMods.Remove(objMod); if (frmPickArmorMod.AddAgain) tsAddArmorMod_Click(sender, e); return; } int intCost = objArmor.TotalCost - intOriginalCost; // Apply a markup if applicable. if (frmPickArmorMod.Markup != 0) { double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo); dblCost *= 1 + (Convert.ToDouble(frmPickArmorMod.Markup, GlobalOptions.Instance.CultureInfo) / 100.0); intCost = Convert.ToInt32(dblCost); } // Multiply the cost if applicable. if (objMod.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost) intCost *= _objOptions.RestrictedCostMultiplier; if (objMod.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailForbidden")) && _objOptions.MultiplyForbiddenCost) intCost *= _objOptions.ForbiddenCostMultiplier; if (!frmPickArmorMod.FreeCost) { if (intCost > _objCharacter.Nuyen) { objArmor.ArmorMods.Remove(objMod); MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information); // Remove the Improvements created by the Armor Mod. _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.ArmorMod, objMod.InternalId); if (frmPickArmorMod.AddAgain) tsAddArmorMod_Click(sender, e); return; } else { // Create the Expense Log Entry. ExpenseLogEntry objExpense = new ExpenseLogEntry(); objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseArmorMod") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now); _objCharacter.ExpenseEntries.Add(objExpense); _objCharacter.Nuyen -= intCost; ExpenseUndo objUndo = new ExpenseUndo(); objUndo.CreateNuyen(NuyenExpenseType.AddArmorMod, objMod.InternalId); objExpense.Undo = objUndo; } } treArmor.SelectedNode.Nodes.Add(objNode); treArmor.SelectedNode.Expand(); treArmor.SelectedNode = objNode; // Add any Weapons created by the Mod. foreach (Weapon objWeapon in lstWeapons) _objCharacter.Weapons.Add(objWeapon); foreach (TreeNode objWeaponNode in lstWeaponNodes) { objWeaponNode.ContextMenuStrip = cmsWeapon; treWeapons.Nodes[0].Nodes.Add(objWeaponNode); treWeapons.Nodes[0].Expand(); } UpdateCharacterInfo(); RefreshSelectedArmor(); _blnIsDirty = true; UpdateWindowTitle(); if (frmPickArmorMod.AddAgain) tsAddArmorMod_Click(sender, e); }