コード例 #1
0
        /// Create a Vehicle Modification from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlMod">XmlNode to create the object from.</param>
        /// <param name="decMarkup">Discount or markup that applies to the base cost of the mod.</param>
        public void Create(XmlNode objXmlMod, decimal decMarkup = 0)
        {
            if (objXmlMod == null)
            {
                Utils.BreakIfDebug();
            }
            objXmlMod.TryGetStringFieldQuickly("id", ref _strSourceId);
            objXmlMod.TryGetStringFieldQuickly("name", ref _strName);
            objXmlMod.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlMod.TryGetStringFieldQuickly("limit", ref _strLimit);
            objXmlMod.TryGetInt32FieldQuickly("slots", ref _intSlots);
            objXmlMod.TryGetStringFieldQuickly("weaponcategories", ref _strAllowedWeaponCategories);
            objXmlMod.TryGetStringFieldQuickly("avail", ref _strAvail);
            if (!objXmlMod.TryGetStringFieldQuickly("altnotes", ref _strNotes))
            {
                objXmlMod.TryGetStringFieldQuickly("notes", ref _strNotes);
            }
            // Check for a Variable Cost.
            objXmlMod.TryGetStringFieldQuickly("cost", ref _strCost);
            if (!string.IsNullOrEmpty(_strCost))
            {
                if (_strCost.StartsWith("Variable("))
                {
                    decimal decMin;
                    decimal decMax  = decimal.MaxValue;
                    string  strCost = _strCost.TrimStartOnce("Variable(", true).TrimEndOnce(')');
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo);
                        decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo);
                    }
                    else
                    {
                        decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo);
                    }

                    if (decMin != 0 || decMax != decimal.MaxValue)
                    {
                        frmSelectNumber frmPickNumber = new frmSelectNumber(_objCharacter.Options.NuyenDecimals);
                        if (decMax > 1000000)
                        {
                            decMax = 1000000;
                        }
                        frmPickNumber.Minimum     = decMin;
                        frmPickNumber.Maximum     = decMax;
                        frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost", GlobalOptions.Language).Replace("{0}", DisplayNameShort(GlobalOptions.Language));
                        frmPickNumber.AllowCancel = false;
                        frmPickNumber.ShowDialog();
                        _strCost = frmPickNumber.SelectedValue.ToString(GlobalOptions.InvariantCultureInfo);
                    }
                }
            }
            _decMarkup = decMarkup;

            objXmlMod.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlMod.TryGetStringFieldQuickly("page", ref _strPage);
            SourceDetail = new SourceString(_strSource, _strPage);
        }
コード例 #2
0
ファイル: ArmorMod.cs プロジェクト: maryshelley101/chummer5a
        /// Create a Armor Modification from an XmlNode.
        /// <param name="objXmlArmorNode">XmlNode to create the object from.</param>
        /// <param name="intRating">Rating of the selected ArmorMod.</param>
        /// <param name="lstWeapons">List of Weapons that are created by the Armor.</param>
        /// <param name="blnSkipCost">Whether or not creating the ArmorMod should skip the Variable price dialogue (should only be used by frmSelectArmor).</param>
        /// <param name="blnSkipSelectForms">Whether or not to skip selection forms (related to improvements) when creating this ArmorMod.</param>
        public void Create(XmlNode objXmlArmorNode, int intRating, List <Weapon> lstWeapons, bool blnSkipCost = false, bool blnSkipSelectForms = false)
        {
            if (objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName))
            {
                _objCachedMyXmlNode = null;
            }
            objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity);
            objXmlArmorNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity);
            _intRating = intRating;
            objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intArmorValue);
            objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating);
            objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail);
            objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage);
            if (!objXmlArmorNode.TryGetStringFieldQuickly("altnotes", ref _strNotes))
            {
                objXmlArmorNode.TryGetStringFieldQuickly("notes", ref _strNotes);
            }
            _nodBonus         = objXmlArmorNode["bonus"];
            _nodWirelessBonus = objXmlArmorNode["wirelessbonus"];
            _blnWirelessOn    = _nodWirelessBonus != null;

            objXmlArmorNode.TryGetStringFieldQuickly("cost", ref _strCost);

            // Check for a Variable Cost.
            if (!blnSkipCost && _strCost.StartsWith("Variable("))
            {
                string strFirstHalf   = _strCost.TrimStartOnce("Variable(", true).TrimEndOnce(')');
                string strSecondHalf  = string.Empty;
                int    intHyphenIndex = strFirstHalf.IndexOf('-');
                if (intHyphenIndex != -1)
                {
                    if (intHyphenIndex + 1 < strFirstHalf.Length)
                    {
                        strSecondHalf = strFirstHalf.Substring(intHyphenIndex + 1);
                    }
                    strFirstHalf = strFirstHalf.Substring(0, intHyphenIndex);
                }

                if (!blnSkipSelectForms)
                {
                    decimal decMin;
                    decimal decMax = decimal.MaxValue;
                    if (intHyphenIndex != -1)
                    {
                        decMin = Convert.ToDecimal(strFirstHalf, GlobalOptions.InvariantCultureInfo);
                        decMax = Convert.ToDecimal(strSecondHalf, GlobalOptions.InvariantCultureInfo);
                    }
                    else
                    {
                        decMin = Convert.ToDecimal(strFirstHalf.FastEscape('+'), GlobalOptions.InvariantCultureInfo);
                    }

                    if (decMin != decimal.MinValue || decMax != decimal.MaxValue)
                    {
                        frmSelectNumber frmPickNumber = new frmSelectNumber(_objCharacter.Options.NuyenDecimals);
                        if (decMax > 1000000)
                        {
                            decMax = 1000000;
                        }
                        frmPickNumber.Minimum     = decMin;
                        frmPickNumber.Maximum     = decMax;
                        frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost", GlobalOptions.Language).Replace("{0}", DisplayNameShort(GlobalOptions.Language));
                        frmPickNumber.AllowCancel = false;
                        frmPickNumber.ShowDialog();
                        _strCost = frmPickNumber.SelectedValue.ToString(GlobalOptions.InvariantCultureInfo);
                    }
                    else
                    {
                        _strCost = strFirstHalf;
                    }
                }
                else
                {
                    _strCost = strFirstHalf;
                }
            }

            if (objXmlArmorNode["bonus"] != null && !blnSkipSelectForms)
            {
                if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.ArmorMod, _guiID.ToString("D"), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort(GlobalOptions.Language)))
                {
                    _guiID = Guid.Empty;
                    return;
                }
                if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue))
                {
                    _strExtra = ImprovementManager.SelectedValue;
                }
            }

            // Add any Gear that comes with the Armor.
            XmlNode xmlChildrenNode = objXmlArmorNode["gears"];

            if (xmlChildrenNode != null)
            {
                XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml");
                using (XmlNodeList xmlUseGearList = xmlChildrenNode.SelectNodes("usegear"))
                    if (xmlUseGearList != null)
                    {
                        foreach (XmlNode objXmlArmorGear in xmlUseGearList)
                        {
                            intRating = 0;
                            string strForceValue = string.Empty;
                            objXmlArmorGear.TryGetInt32FieldQuickly("rating", ref intRating);
                            objXmlArmorGear.TryGetStringFieldQuickly("select", ref strForceValue);

                            XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = " + objXmlArmorGear.InnerText.CleanXPath() + "]");
                            Gear    objGear    = new Gear(_objCharacter);

                            objGear.Create(objXmlGear, intRating, lstWeapons, strForceValue, !blnSkipSelectForms);

                            objGear.Capacity      = "[0]";
                            objGear.ArmorCapacity = "[0]";
                            objGear.Cost          = "0";
                            objGear.ParentID      = InternalId;
                            _lstGear.Add(objGear);
                        }
                    }
            }

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

                // More than one Weapon can be added, so loop through all occurrences.
                using (XmlNodeList xmlAddWeaponList = objXmlArmorNode.SelectNodes("addweapon"))
                    if (xmlAddWeaponList != null)
                    {
                        foreach (XmlNode objXmlAddWeapon in xmlAddWeaponList)
                        {
                            string  strLoopID    = objXmlAddWeapon.InnerText;
                            XmlNode objXmlWeapon = strLoopID.IsGuid()
                                ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + strLoopID + "\"]")
                                : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + strLoopID + "\"]");

                            Weapon objGearWeapon = new Weapon(_objCharacter);
                            objGearWeapon.Create(objXmlWeapon, lstWeapons, true, !blnSkipSelectForms, blnSkipCost);
                            objGearWeapon.ParentID = InternalId;
                            objGearWeapon.Cost     = "0";
                            lstWeapons.Add(objGearWeapon);

                            Guid.TryParse(objGearWeapon.InternalId, out _guiWeaponID);
                        }
                    }
            }
            SourceDetail = new SourceString(_strSource, _strPage);
        }
コード例 #3
0
ファイル: ArmorMod.cs プロジェクト: Kikatza/SR5Creator
        /// Create a Armor Modification 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="intRating">Rating of the selected ArmorMod.</param>
        /// <param name="objWeapons">List of Weapons that are created by the Armor.</param>
        /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param>
        /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param>
        public void Create(XmlNode objXmlArmorNode, TreeNode objNode, ContextMenuStrip cmsArmorGear, int intRating, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes, bool blnSkipCost = false, bool blnSkipSelectForms = false)
        {
            objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName);
            objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity);
            objXmlArmorNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity);
            _intRating = intRating;
            objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intA);
            objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating);
            objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail);
            objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage);
            _nodBonus         = objXmlArmorNode["bonus"];
            _nodWirelessBonus = objXmlArmorNode["wirelessbonus"];
            _blnWirelessOn    = _nodWirelessBonus != null;

            if (GlobalOptions.Language != GlobalOptions.DefaultLanguage)
            {
                XmlNode objArmorNode = MyXmlNode;
                if (objArmorNode != null)
                {
                    objArmorNode.TryGetStringFieldQuickly("translate", ref _strAltName);
                    objArmorNode.TryGetStringFieldQuickly("altpage", ref _strAltPage);
                }

                XmlDocument objXmlDocument = XmlManager.Load("armor.xml");
                objArmorNode    = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                _strAltCategory = objArmorNode?.Attributes?["translate"]?.InnerText;
            }

            // Check for a Variable Cost.
            if (blnSkipCost)
            {
                _strCost = "0";
            }
            else if (objXmlArmorNode["cost"] != null)
            {
                XmlNode objXmlArmorCostNode = objXmlArmorNode["cost"];

                if (objXmlArmorCostNode.InnerText.StartsWith("Variable"))
                {
                    decimal decMin          = 0.0m;
                    decimal decMax          = decimal.MaxValue;
                    char[]  charParentheses = { '(', ')' };
                    string  strCost         = objXmlArmorNode["cost"].InnerText.TrimStart("Variable", true).Trim(charParentheses);
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo);
                        decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo);
                    }
                    else
                    {
                        decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo);
                    }

                    if (decMin != 0 || decMax != decimal.MaxValue)
                    {
                        string strNuyenFormat   = _objCharacter.Options.NuyenFormat;
                        int    intDecimalPlaces = strNuyenFormat.IndexOf('.');
                        if (intDecimalPlaces == -1)
                        {
                            intDecimalPlaces = 0;
                        }
                        else
                        {
                            intDecimalPlaces = strNuyenFormat.Length - intDecimalPlaces - 1;
                        }
                        frmSelectNumber frmPickNumber = new frmSelectNumber(intDecimalPlaces);
                        if (decMax > 1000000)
                        {
                            decMax = 1000000;
                        }
                        frmPickNumber.Minimum     = decMin;
                        frmPickNumber.Maximum     = decMax;
                        frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort);
                        frmPickNumber.AllowCancel = false;
                        frmPickNumber.ShowDialog();
                        _strCost = frmPickNumber.SelectedValue.ToString();
                    }
                }
                else
                {
                    _strCost = objXmlArmorCostNode.InnerText;
                }
            }

            if (objXmlArmorNode["bonus"] != null && !blnSkipCost && !blnSkipSelectForms)
            {
                if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.ArmorMod, _guiID.ToString(), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort))
                {
                    _guiID = Guid.Empty;
                    return;
                }
                if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue))
                {
                    _strExtra     = ImprovementManager.SelectedValue;
                    objNode.Text += " (" + ImprovementManager.SelectedValue + ")";
                }
            }

            // Add any Gear that comes with the Armor.
            if (objXmlArmorNode["gears"] != null)
            {
                XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml");
                foreach (XmlNode objXmlArmorGear in objXmlArmorNode.SelectNodes("gears/usegear"))
                {
                    intRating = 0;
                    string strForceValue = string.Empty;
                    objXmlArmorGear.TryGetInt32FieldQuickly("rating", ref intRating);
                    objXmlArmorGear.TryGetStringFieldQuickly("select", ref strForceValue);

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

                    if (!string.IsNullOrEmpty(objXmlGear["devicerating"]?.InnerText))
                    {
                        Commlink objCommlink = new Commlink(_objCharacter);
                        objCommlink.Create(objXmlGear, objGearNode, intRating, lstWeapons, lstWeaponNodes, strForceValue, false, false, !blnSkipCost && !blnSkipSelectForms);
                        objGear = objCommlink;
                    }
                    else
                    {
                        objGear.Create(objXmlGear, objGearNode, intRating, lstWeapons, lstWeaponNodes, strForceValue, false, false, !blnSkipCost && !blnSkipSelectForms);
                    }
                    objGear.Capacity      = "[0]";
                    objGear.ArmorCapacity = "[0]";
                    objGear.Cost          = "0";
                    objGear.MaxRating     = objGear.Rating;
                    objGear.MinRating     = objGear.Rating;
                    objGear.ParentID      = InternalId;
                    _lstGear.Add(objGear);

                    objGearNode.ForeColor        = SystemColors.GrayText;
                    objGearNode.ContextMenuStrip = cmsArmorGear;
                    objNode.Nodes.Add(objGearNode);
                    objNode.Expand();
                }
            }

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

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

                    List <TreeNode> lstGearWeaponNodes = new List <TreeNode>();
                    Weapon          objGearWeapon      = new Weapon(_objCharacter);
                    objGearWeapon.Create(objXmlWeapon, lstGearWeaponNodes, null, null, objWeapons, null, true, !blnSkipCost && !blnSkipSelectForms);
                    objGearWeapon.ParentID = InternalId;
                    foreach (TreeNode objLoopNode in lstGearWeaponNodes)
                    {
                        objLoopNode.ForeColor = SystemColors.GrayText;
                        objWeaponNodes.Add(objLoopNode);
                    }
                    objWeapons.Add(objGearWeapon);

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

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
コード例 #4
0
ファイル: WeaponAccessory.cs プロジェクト: PStucke/chummer5a
        /// Create a Weapon Accessory from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlAccessory">XmlNode to create the object from.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="strMount">Mount slot that the Weapon Accessory will consume.</param>
        /// <param name="intRating">Rating of the Weapon Accessory.</param>
        public void Create(XmlNode objXmlAccessory, TreeNode objNode, Tuple <string, string> strMount, int intRating, ContextMenuStrip cmsAccessoryGear, bool blnSkipCost = false, bool blnCreateChildren = true)
        {
            objXmlAccessory.TryGetStringFieldQuickly("name", ref _strName);
            _strMount      = strMount.Item1;
            _strExtraMount = strMount.Item2;
            _intRating     = intRating;
            objXmlAccessory.TryGetStringFieldQuickly("avail", ref _strAvail);
            // Check for a Variable Cost.
            if (blnSkipCost)
            {
                _strCost = "0";
            }
            else if (objXmlAccessory["cost"] != null)
            {
                _strCost = objXmlAccessory["cost"].InnerText;
                if (_strCost.StartsWith("Variable"))
                {
                    decimal decMin  = 0;
                    decimal decMax  = decimal.MaxValue;
                    string  strCost = _strCost.TrimStart("Variable", true).Trim("()".ToCharArray());
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo);
                        decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo);
                    }
                    else
                    {
                        decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo);
                    }

                    if (decMin != 0 || decMax != decimal.MaxValue)
                    {
                        frmSelectNumber frmPickNumber = new frmSelectNumber();
                        if (decMax > 1000000)
                        {
                            decMax = 1000000;
                        }
                        frmPickNumber.Minimum     = decMin;
                        frmPickNumber.Maximum     = decMax;
                        frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort);
                        frmPickNumber.AllowCancel = false;
                        frmPickNumber.ShowDialog();
                        _strCost = frmPickNumber.SelectedValue.ToString();
                    }
                }
            }

            objXmlAccessory.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlAccessory.TryGetStringFieldQuickly("page", ref _strPage);
            _nodAllowGear = objXmlAccessory["allowgear"];
            objXmlAccessory.TryGetStringFieldQuickly("rc", ref _strRC);
            objXmlAccessory.TryGetBoolFieldQuickly("rcdeployable", ref _blnDeployable);
            objXmlAccessory.TryGetInt32FieldQuickly("rcgroup", ref _intRCGroup);
            objXmlAccessory.TryGetStringFieldQuickly("conceal", ref _strConceal);
            objXmlAccessory.TryGetInt32FieldQuickly("ammoslots", ref _intAmmoSlots);
            objXmlAccessory.TryGetStringFieldQuickly("ammoreplace", ref _strAmmoReplace);
            objXmlAccessory.TryGetInt32FieldQuickly("accuracy", ref _intAccuracy);
            objXmlAccessory.TryGetStringFieldQuickly("dicepool", ref _strDicePool);
            objXmlAccessory.TryGetStringFieldQuickly("damagetype", ref _strDamageType);
            objXmlAccessory.TryGetStringFieldQuickly("damage", ref _strDamage);
            objXmlAccessory.TryGetStringFieldQuickly("damagereplace", ref _strDamageReplace);
            objXmlAccessory.TryGetStringFieldQuickly("firemode", ref _strFireMode);
            objXmlAccessory.TryGetStringFieldQuickly("firemodereplace", ref _strFireModeReplace);
            objXmlAccessory.TryGetStringFieldQuickly("ap", ref _strAP);
            objXmlAccessory.TryGetStringFieldQuickly("apreplace", ref _strAPReplace);
            objXmlAccessory.TryGetStringFieldQuickly("addmode", ref _strAddMode);
            objXmlAccessory.TryGetInt32FieldQuickly("fullburst", ref _intFullBurst);
            objXmlAccessory.TryGetInt32FieldQuickly("suppressive", ref _intSuppressive);
            objXmlAccessory.TryGetInt32FieldQuickly("rangebonus", ref _intRangeBonus);
            objXmlAccessory.TryGetStringFieldQuickly("extra", ref _strExtra);
            objXmlAccessory.TryGetInt32FieldQuickly("ammobonus", ref _intAmmoBonus);
            objXmlAccessory.TryGetInt32FieldQuickly("accessorycostmultiplier", ref _intAccessoryCostMultiplier);

            // Add any Gear that comes with the Weapon Accessory.
            if (objXmlAccessory["gears"] != null && blnCreateChildren)
            {
                XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml");
                foreach (XmlNode objXmlAccessoryGear in objXmlAccessory.SelectNodes("gears/usegear"))
                {
                    int     intGearRating           = 0;
                    decimal decGearQty              = 1;
                    string  strChildForceSource     = string.Empty;
                    string  strChildForcePage       = string.Empty;
                    string  strChildForceValue      = string.Empty;
                    bool    blnStartCollapsed       = objXmlAccessoryGear["name"].Attributes?["startcollapsed"]?.InnerText == "yes";
                    bool    blnChildCreateChildren  = objXmlAccessoryGear["name"].Attributes?["createchildren"]?.InnerText != "no";
                    bool    blnAddChildImprovements = !blnSkipCost;
                    if (objXmlAccessoryGear["name"].Attributes?["addimprovements"]?.InnerText == "no")
                    {
                        blnAddChildImprovements = false;
                    }
                    if (objXmlAccessoryGear["rating"] != null)
                    {
                        intGearRating = Convert.ToInt32(objXmlAccessoryGear["rating"].InnerText);
                    }
                    if (objXmlAccessoryGear["name"].Attributes?["qty"] != null)
                    {
                        decGearQty = Convert.ToDecimal(objXmlAccessoryGear["name"].Attributes["qty"].InnerText, GlobalOptions.InvariantCultureInfo);
                    }
                    if (objXmlAccessoryGear["name"].Attributes?["select"] != null)
                    {
                        strChildForceValue = objXmlAccessoryGear["name"].Attributes["select"].InnerText;
                    }
                    if (objXmlAccessoryGear["source"] != null)
                    {
                        strChildForceSource = objXmlAccessoryGear["source"].InnerText;
                    }
                    if (objXmlAccessoryGear["page"] != null)
                    {
                        strChildForcePage = objXmlAccessoryGear["page"].InnerText;
                    }

                    XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlAccessoryGear["name"].InnerText + "\" and category = \"" + objXmlAccessoryGear["category"].InnerText + "\"]");
                    Gear    objGear    = new Gear(_objCharacter);

                    TreeNode        objGearNode    = new TreeNode();
                    List <Weapon>   lstWeapons     = new List <Weapon>();
                    List <TreeNode> lstWeaponNodes = new List <TreeNode>();

                    if (!string.IsNullOrEmpty(objXmlGear["devicerating"]?.InnerText))
                    {
                        Commlink objCommlink = new Commlink(_objCharacter);
                        objCommlink.Create(objXmlGear, objGearNode, intGearRating, lstWeapons, lstWeaponNodes, strChildForceValue, false, false, blnAddChildImprovements, blnChildCreateChildren);
                        objGear = objCommlink;
                    }
                    else
                    {
                        objGear.Create(objXmlGear, objGearNode, intGearRating, lstWeapons, lstWeaponNodes, strChildForceValue, false, false, blnAddChildImprovements, blnChildCreateChildren);
                    }
                    objGear.Quantity  = decGearQty;
                    objGear.Cost      = "0";
                    objGear.MinRating = intGearRating;
                    objGear.MaxRating = intGearRating;
                    objGear.ParentID  = InternalId;
                    if (!string.IsNullOrEmpty(strChildForceSource))
                    {
                        objGear.Source = strChildForceSource;
                    }
                    if (!string.IsNullOrEmpty(strChildForcePage))
                    {
                        objGear.Page = strChildForcePage;
                    }
                    _lstGear.Add(objGear);

                    // Change the Capacity of the child if necessary.
                    if (objXmlAccessoryGear["capacity"] != null)
                    {
                        objGear.Capacity = "[" + objXmlAccessoryGear["capacity"].InnerText + "]";
                    }
                    objGearNode.ContextMenuStrip = cmsAccessoryGear;
                    objGearNode.ForeColor        = SystemColors.GrayText;
                    objNode.Nodes.Add(objGearNode);
                    if (!blnStartCollapsed)
                    {
                        objNode.Expand();
                    }
                }
            }

            if (GlobalOptions.Language != GlobalOptions.DefaultLanguage)
            {
                XmlNode objAccessoryNode = MyXmlNode;
                if (objAccessoryNode != null)
                {
                    _strAltName = objAccessoryNode["translate"]?.InnerText ?? string.Empty;
                    _strAltPage = objAccessoryNode["altpage"]?.InnerText ?? string.Empty;
                }
            }

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
コード例 #5
0
ファイル: WeaponMount.cs プロジェクト: Kikatza/SR5Creator
        /// <summary>
        /// Create a Weapon Mount Option from an XmlNode.
        /// </summary>
        /// <param name="id">String guid of the object.</param>
        /// <param name="list">List to add the object to. Called inside the Create method in case the mount itself is null.</param>
        public void Create(string id, List <WeaponMountOption> list)
        {
            XmlDocument xmlDoc    = XmlManager.Load("vehicles.xml");
            XmlNode     objXmlMod = xmlDoc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[id = \"{id}\"]");

            if (objXmlMod == null)
            {
                Utils.BreakIfDebug();
            }
            Guid.TryParse(id, out _sourceID);
            objXmlMod.TryGetStringFieldQuickly("name", ref _strName);
            objXmlMod.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlMod.TryGetInt32FieldQuickly("slots", ref _intSlots);
            objXmlMod.TryGetStringFieldQuickly("weaponcategories", ref _strWeaponMountCategories);
            objXmlMod.TryGetStringFieldQuickly("avail", ref _strAvail);

            // Check for a Variable Cost.
            // ReSharper disable once PossibleNullReferenceException
            if (objXmlMod["cost"] != null)
            {
                if (objXmlMod["cost"].InnerText.StartsWith("Variable"))
                {
                    int    intMin;
                    var    intMax         = 0;
                    char[] chrParentheses = { '(', ')' };
                    string strCost        = objXmlMod["cost"].InnerText.Replace("Variable", string.Empty).Trim(chrParentheses);
                    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)
                    {
                        string strNuyenFormat   = _objCharacter.Options.NuyenFormat;
                        int    intDecimalPlaces = strNuyenFormat.IndexOf('.');
                        if (intDecimalPlaces == -1)
                        {
                            intDecimalPlaces = 0;
                        }
                        else
                        {
                            intDecimalPlaces = strNuyenFormat.Length - intDecimalPlaces - 1;
                        }
                        frmSelectNumber frmPickNumber = new frmSelectNumber(intDecimalPlaces);
                        if (intMax == 0)
                        {
                            intMax = 1000000;
                        }
                        frmPickNumber.Minimum     = intMin;
                        frmPickNumber.Maximum     = intMax;
                        frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost").Replace("{0}", DisplayName);
                        frmPickNumber.AllowCancel = false;
                        frmPickNumber.ShowDialog();
                        _strCost = frmPickNumber.SelectedValue.ToString();
                    }
                }
                else
                {
                    _strCost = objXmlMod["cost"].InnerText;
                }
            }
            list.Add(this);
            if (GlobalOptions.Language == "en-us")
            {
                return;
            }
            XmlDocument objXmlDocument = XmlManager.Load("vehicles.xml");
            XmlNode     objModNode     = objXmlDocument.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + _sourceID + "\"]");

            if (objModNode != null)
            {
                objModNode.TryGetStringFieldQuickly("translate", ref _strAltName);
                objModNode.TryGetStringFieldQuickly("altpage", ref _strAltPage);
            }

            objModNode      = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
            _strAltCategory = objModNode?.Attributes?["translate"]?.InnerText;
        }
コード例 #6
0
ファイル: WeaponMount.cs プロジェクト: Kikatza/SR5Creator
        /// Create a Vehicle Modification from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlMod">XmlNode to create the object from.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="objParent">Vehicle that the mod will be attached to.</param>
        /// <param name="decMarkup">Discount or markup that applies to the base cost of the mod.</param>
        public void Create(XmlNode objXmlMod, TreeNode objNode, Vehicle objParent, decimal decMarkup = 0)
        {
            if (objParent == null)
            {
                throw new ArgumentNullException(nameof(objParent));
            }
            Parent = objParent;
            if (objXmlMod == null)
            {
                Utils.BreakIfDebug();
            }
            objXmlMod.TryGetStringFieldQuickly("name", ref _strName);
            objXmlMod.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlMod.TryGetStringFieldQuickly("limit", ref _strLimit);
            objXmlMod.TryGetInt32FieldQuickly("slots", ref _intSlots);
            objXmlMod.TryGetStringFieldQuickly("weaponcategories", ref _strWeaponMountCategories);
            objXmlMod.TryGetStringFieldQuickly("avail", ref _strAvail);

            // Check for a Variable Cost.
            if (objXmlMod["cost"] != null)
            {
                _strCost = objXmlMod["cost"].InnerText;
                if (_strCost.StartsWith("Variable"))
                {
                    decimal decMin  = 0;
                    decimal decMax  = decimal.MaxValue;
                    string  strCost = _strCost.TrimStart("Variable", true).Trim("()".ToCharArray());
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo);
                        decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo);
                    }
                    else
                    {
                        decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo);
                    }

                    if (decMin != 0 || decMax != decimal.MaxValue)
                    {
                        string strNuyenFormat   = _character.Options.NuyenFormat;
                        int    intDecimalPlaces = strNuyenFormat.IndexOf('.');
                        if (intDecimalPlaces == -1)
                        {
                            intDecimalPlaces = 0;
                        }
                        else
                        {
                            intDecimalPlaces = strNuyenFormat.Length - intDecimalPlaces - 1;
                        }
                        frmSelectNumber frmPickNumber = new frmSelectNumber(intDecimalPlaces);
                        if (decMax > 1000000)
                        {
                            decMax = 1000000;
                        }
                        frmPickNumber.Minimum     = decMin;
                        frmPickNumber.Maximum     = decMax;
                        frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort);
                        frmPickNumber.AllowCancel = false;
                        frmPickNumber.ShowDialog();
                        _strCost = frmPickNumber.SelectedValue.ToString();
                    }
                }
            }
            _decMarkup = decMarkup;

            objXmlMod.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlMod.TryGetStringFieldQuickly("page", ref _strPage);

            if (GlobalOptions.Language != GlobalOptions.DefaultLanguage)
            {
                XmlNode objModNode = MyXmlNode;
                if (objModNode != null)
                {
                    objModNode.TryGetStringFieldQuickly("translate", ref _strAltName);
                    objModNode.TryGetStringFieldQuickly("altpage", ref _strAltPage);
                }

                XmlDocument objXmlDocument = XmlManager.Load("vehicles.xml");
                objModNode      = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                _strAltCategory = objModNode?.Attributes?["translate"]?.InnerText;
            }

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
コード例 #7
0
ファイル: VehicleMod.cs プロジェクト: btterrette7/chummer5a
        /// Create a Vehicle Modification from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlMod">XmlNode to create the object from.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="intRating">Selected Rating for the Gear.</param>
        /// <param name="objParent">Vehicle that the mod will be attached to.</param>
        /// <param name="intMarkup">Discount or markup that applies to the base cost of the mod.</param>
        public void Create(XmlNode objXmlMod, TreeNode objNode, int intRating, Vehicle objParent, int intMarkup = 0)
        {
            if (objParent == null)
            {
                throw new ArgumentNullException(nameof(objParent));
            }
            Parent = objParent;
            objXmlMod.TryGetStringFieldQuickly("name", ref _strName);
            objXmlMod.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlMod.TryGetStringFieldQuickly("limit", ref _strLimit);
            objXmlMod.TryGetStringFieldQuickly("slots", ref _strSlots);
            _intRating = intRating;
            if (objXmlMod["downgrade"] != null)
            {
                _blnDowngrade = true;
            }

            objXmlMod.TryGetStringFieldQuickly("capacity", ref _strCapacity);
            objXmlMod.TryGetStringFieldQuickly("rating", ref _strMaxRating);
            objXmlMod.TryGetInt32FieldQuickly("response", ref _intResponse);
            objXmlMod.TryGetInt32FieldQuickly("system", ref _intSystem);
            objXmlMod.TryGetInt32FieldQuickly("firewall", ref _intFirewall);
            objXmlMod.TryGetInt32FieldQuickly("signal", ref _intSignal);
            objXmlMod.TryGetInt32FieldQuickly("pilot", ref _intPilot);
            objXmlMod.TryGetInt32FieldQuickly("conditionmonitor", ref _intConditionMonitor);
            objXmlMod.TryGetStringFieldQuickly("weaponmountcategories", ref _strWeaponMountCategories);
            // Add Subsytem information if applicable.
            if (objXmlMod.InnerXml.Contains("subsystems"))
            {
                string      strSubsystem     = string.Empty;
                XmlNodeList objXmlSubsystems = objXmlMod.SelectNodes("subsystems/subsystem");
                if (objXmlSubsystems != null)
                {
                    strSubsystem = objXmlSubsystems.Cast <XmlNode>().Aggregate(strSubsystem, (current, objXmlSubsystem) => current + (objXmlSubsystem.InnerText + ","));
                }
                _strSubsystems = strSubsystem;
            }
            objXmlMod.TryGetStringFieldQuickly("avail", ref _strAvail);

            // Check for a Variable Cost.
            if (objXmlMod["cost"] != null)
            {
                if (objXmlMod["cost"].InnerText.StartsWith("Variable"))
                {
                    int    intMin;
                    var    intMax         = 0;
                    char[] chrParentheses = { '(', ')' };
                    string strCost        = objXmlMod["cost"].InnerText.Replace("Variable", string.Empty).Trim(chrParentheses);
                    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)
                    {
                        var 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
                {
                    _strCost = objXmlMod["cost"].InnerText;
                }
            }
            _intMarkup = intMarkup;

            objXmlMod.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlMod.TryGetStringFieldQuickly("page", ref _strPage);
            _nodBonus = objXmlMod["bonus"];

            if (GlobalOptions.Instance.Language != "en-us")
            {
                XmlDocument objXmlDocument = XmlManager.Instance.Load("vehicles.xml");
                XmlNode     objModNode     = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + _strName + "\"]");
                if (objModNode != null)
                {
                    objModNode.TryGetStringFieldQuickly("translate", ref _strAltName);
                    objModNode.TryGetStringFieldQuickly("altpage", ref _strAltPage);
                }

                objModNode      = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                _strAltCategory = objModNode?.Attributes?["translate"]?.InnerText;
            }

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
コード例 #8
0
ファイル: Gear.cs プロジェクト: argo2445/chummer5a
        /// Create a Gear from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlGear">XmlNode to create the object from.</param>
        /// <param name="objCharacter">Character the Gear is being added to.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="intRating">Selected Rating for the Gear.</param>
        /// <param name="objWeapons">List of Weapons that should be added to the character.</param>
        /// <param name="objWeaponNodes">List of TreeNodes to represent the added Weapons</param>
        /// <param name="strForceValue">Value to forcefully select for any ImprovementManager prompts.</param>
        /// <param name="blnHacked">Whether or not a Matrix Program has been hacked (removing the Copy Protection and Registration plugins).</param>
        /// <param name="blnInherent">Whether or not a Program is Inherent to an A.I.</param>
        /// <param name="blnAddImprovements">Whether or not Improvements should be added to the character.</param>
        /// <param name="blnCreateChildren">Whether or not child Gear should be created.</param>
        /// <param name="blnAerodynamic">Whether or not Weapons should be created as Aerodynamic.</param>
        public void Create(XmlNode objXmlGear, Character objCharacter, TreeNode objNode, int intRating, List<Weapon> objWeapons, List<TreeNode> objWeaponNodes, string strForceValue = "", bool blnHacked = false, bool blnInherent = false, bool blnAddImprovements = true, bool blnCreateChildren = true, bool blnAerodynamic = false)
        {
            _strName = objXmlGear["name"].InnerText;
            _strCategory = objXmlGear["category"].InnerText;
            _strAvail = objXmlGear["avail"].InnerText;
            try
            {
                _strAvail3 = objXmlGear["avail3"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strAvail6 = objXmlGear["avail6"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strAvail10 = objXmlGear["avail10"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strCapacity = objXmlGear["capacity"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strArmorCapacity = objXmlGear["armorcapacity"].InnerText;
            }
            catch
            {
            }
            try
            {
                _intCostFor = Convert.ToInt32(objXmlGear["costfor"].InnerText);
                _intQty = Convert.ToInt32(objXmlGear["costfor"].InnerText);
            }
            catch
            {
            }
            try
            {
                _strCost = objXmlGear["cost"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strCost3 = objXmlGear["cost3"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strCost6 = objXmlGear["cost6"].InnerText;
            }
            catch
            {
            }
            try
            {
                _strCost10 = objXmlGear["cost10"].InnerText;
            }
            catch
            {
            }
            _nodBonus = objXmlGear["bonus"];
            _intMaxRating = Convert.ToInt32(objXmlGear["rating"].InnerText);
            try
            {
                _intMinRating = Convert.ToInt32(objXmlGear["minrating"].InnerText);
            }
            catch
            {
            }
            _intRating = intRating;
            _strSource = objXmlGear["source"].InnerText;
            _strPage = objXmlGear["page"].InnerText;

            try
            {
                _intChildCostMultiplier = Convert.ToInt32(objXmlGear["childcostmultiplier"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intChildAvailModifier = Convert.ToInt32(objXmlGear["childavailmodifier"].InnerText);
            }
            catch
            {
            }

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

                if (_strAltName.StartsWith("Stacked Focus"))
                    _strAltName = _strAltName.Replace("Stacked Focus", LanguageManager.Instance.GetString("String_StackedFocus"));

                objGearNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                if (objGearNode != null)
                {
                    if (objGearNode.Attributes["translate"] != null)
                        _strAltCategory = objGearNode.Attributes["translate"].InnerText;
                }

                if (_strAltCategory.StartsWith("Stacked Focus"))
                    _strAltCategory = _strAltCategory.Replace("Stacked Focus", LanguageManager.Instance.GetString("String_StackedFocus"));
            }

            // Check for a Custom name
            if (objXmlGear["name"].InnerText == "Custom Item")
            {
                frmSelectText frmPickText = new frmSelectText();
                frmPickText.Description = LanguageManager.Instance.GetString("String_CustomItem_SelectText");
                frmPickText.ShowDialog();

                // Make sure the dialogue window was not canceled.
                if (frmPickText.DialogResult != DialogResult.Cancel)
                {
                    _strName = frmPickText.SelectedValue;
                }
            }

            // Check for a Variable Cost.
            if (objXmlGear["cost"] != null)
            {
                if (objXmlGear["cost"].InnerText.StartsWith("Variable"))
                {
                    int intMin = 0;
                    int intMax = 0;
                    string strCost = objXmlGear["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();
                    }
                }
            }

            string strSource = _guiID.ToString();

            objNode.Text = _strName;
            objNode.Tag = _guiID.ToString();

            // If the Gear is Ammunition, ask the user to select a Weapon Category for it to be limited to.
            if (_strCategory == "Ammunition" && (_strName.StartsWith("Ammo:") || _strName.StartsWith("Arrow:") || _strName.StartsWith("Bolt:")))
            {
                frmSelectWeaponCategory frmPickWeaponCategory = new frmSelectWeaponCategory();
                frmPickWeaponCategory.Description = LanguageManager.Instance.GetString("String_SelectWeaponCategoryAmmo");
                if (strForceValue != "")
                    frmPickWeaponCategory.OnlyCategory = strForceValue;

                //should really go in a data file
                if (_strName.StartsWith("Ammo:"))
                {
                    if (_strName.StartsWith("Ammo: Assault Cannon") || _strName.StartsWith("Ammo: Gauss"))
                    {
                        frmPickWeaponCategory.WeaponType = "cannon";
                    }
                    else if (_strName.StartsWith("Ammo: Taser Dart"))
                    {
                        frmPickWeaponCategory.WeaponType = "taser";
                    }
                    else if(_strName.StartsWith("Ammo: Fuel Canister"))
                    {
                        frmPickWeaponCategory.WeaponType = "flame";
                    }
                    else if (_strName.StartsWith("Ammo: Injection Dart") || _strName.StartsWith("Ammo: Peak-Discharge"))
                    {
                        frmPickWeaponCategory.WeaponType = "exotic";
                    }
                    else
                    {
                        frmPickWeaponCategory.WeaponType = "gun";
                    }
                }
                else if (_strName.StartsWith("Arrow:"))
                {
                    frmPickWeaponCategory.WeaponType = "bow";
                }
                else if (_strName.StartsWith("Bolt:"))
                {
                    frmPickWeaponCategory.WeaponType = "crossbow";
                }
                frmPickWeaponCategory.ShowDialog();

                _strExtra = frmPickWeaponCategory.SelectedCategory;
                objNode.Text += " (" + _strExtra + ")";
            }

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

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

                    TreeNode objGearWeaponNode = new TreeNode();
                    Weapon objGearWeapon = new Weapon(objCharacter);
                    objGearWeapon.Create(objXmlWeapon, objCharacter, objGearWeaponNode, null, null);
                    objGearWeaponNode.ForeColor = SystemColors.GrayText;
                    if (blnAerodynamic)
                    {
                        objGearWeapon.Name += " (" + LanguageManager.Instance.GetString("Checkbox_Aerodynamic") + ")";
                        objGearWeapon.SetRange("Aerodynamic Grenades");
                        objGearWeaponNode.Text = objGearWeapon.DisplayName;
                        _strName += " (" + LanguageManager.Instance.GetString("Checkbox_Aerodynamic") + ")";
                        objNode.Text = DisplayName;
                    }

                    objWeaponNodes.Add(objGearWeaponNode);
                    objWeapons.Add(objGearWeapon);

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

            // If the item grants a bonus, pass the information to the Improvement Manager.
            if (objXmlGear.InnerXml.Contains("<bonus>"))
            {
                // Do not apply the Improvements if this is a Focus, unless we're speicifically creating a Weapon Focus. This is to avoid creating the Foci's Improvements twice (once when it's first added
                // to the character which is incorrect, and once when the Focus is actually Bonded).
                bool blnApply = !((_strCategory == "Foci" || _strCategory == "Metamagic Foci") && !objXmlGear["bonus"].InnerXml.Contains("selecttext"));

                if (blnApply)
                {
                    ImprovementManager objImprovementManager;
                    if (blnAddImprovements)
                        objImprovementManager = new ImprovementManager(objCharacter);
                    else
                        objImprovementManager = new ImprovementManager(null);

                    objImprovementManager.ForcedValue = strForceValue;
                    if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Gear, strSource, objXmlGear["bonus"], false, intRating, DisplayNameShort))
                    {
                        _guiID = Guid.Empty;
                        return;
                    }
                    if (objImprovementManager.SelectedValue != "")
                    {
                        _strExtra = objImprovementManager.SelectedValue;
                        objNode.Text += " (" + objImprovementManager.SelectedValue + ")";
                    }
                }
            }

            // Check to see if there are any child elements.
            if (objXmlGear.InnerXml.Contains("<gears>") && blnCreateChildren)
            {
                // Create Gear using whatever information we're given.
                foreach (XmlNode objXmlChild in objXmlGear.SelectNodes("gears/gear"))
                {
                    Gear objChild = new Gear(_objCharacter);
                    TreeNode objChildNode = new TreeNode();
                    objChild.Name = objXmlChild["name"].InnerText;
                    objChild.Category = objXmlChild["category"].InnerText;
                    objChild.Avail = "0";
                    objChild.Cost = "0";
                    objChild.Source = _strSource;
                    objChild.Page = _strPage;
                    objChild.Parent = this;
                    objChild.IncludedInParent = true;
                    _objChildren.Add(objChild);

                    objChildNode.Text = objChild.DisplayName;
                    objChildNode.Tag = objChild.InternalId;
                    objNode.Nodes.Add(objChildNode);
                    objNode.Expand();
                }

                XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");
                CreateChildren(objXmlGearDocument, objXmlGear, this, objNode, objCharacter, blnHacked);
            }

            // Add the Copy Protection and Registration plugins to the Matrix program. This does not apply if Unwired is not enabled, Hacked is selected, or this is a Suite being added (individual programs will add it to themselves).
            if (blnCreateChildren)
            {
                if ((_strCategory == "Matrix Programs" || _strCategory == "Skillsofts" || _strCategory == "Autosofts" || _strCategory == "Autosofts, Agent" || _strCategory == "Autosofts, Drone") && objCharacter.Options.BookEnabled("UN") && !blnHacked && !_strName.StartsWith("Suite:"))
                {
                    XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");

                    if (_objCharacter.Options.AutomaticCopyProtection && !blnInherent)
                    {
                        Gear objPlugin1 = new Gear(_objCharacter);
                        TreeNode objPlugin1Node = new TreeNode();
                        objPlugin1.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Copy Protection\"]"), objCharacter, objPlugin1Node, _intRating, null, null);
                        if (_intRating == 0)
                            objPlugin1.Rating = 1;
                        objPlugin1.Avail = "0";
                        objPlugin1.Cost = "0";
                        objPlugin1.Cost3 = "0";
                        objPlugin1.Cost6 = "0";
                        objPlugin1.Cost10 = "0";
                        objPlugin1.Capacity = "[0]";
                        objPlugin1.Parent = this;
                        _objChildren.Add(objPlugin1);
                        objNode.Nodes.Add(objPlugin1Node);
                    }

                    if (_objCharacter.Options.AutomaticRegistration && !blnInherent)
                    {
                        Gear objPlugin2 = new Gear(_objCharacter);
                        TreeNode objPlugin2Node = new TreeNode();
                        objPlugin2.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Registration\"]"), objCharacter, objPlugin2Node, 0, null, null);
                        objPlugin2.Avail = "0";
                        objPlugin2.Cost = "0";
                        objPlugin2.Cost3 = "0";
                        objPlugin2.Cost6 = "0";
                        objPlugin2.Cost10 = "0";
                        objPlugin2.Capacity = "[0]";
                        objPlugin2.Parent = this;
                        _objChildren.Add(objPlugin2);
                        objNode.Nodes.Add(objPlugin2Node);
                        objNode.Expand();
                    }

                    if ((objCharacter.Metatype == "A.I." || objCharacter.MetatypeCategory == "Technocritters" || objCharacter.MetatypeCategory == "Protosapients") && blnInherent)
                    {
                        Gear objPlugin3 = new Gear(_objCharacter);
                        TreeNode objPlugin3Node = new TreeNode();
                        objPlugin3.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Ergonomic\"]"), objCharacter, objPlugin3Node, 0, null, null);
                        objPlugin3.Avail = "0";
                        objPlugin3.Cost = "0";
                        objPlugin3.Cost3 = "0";
                        objPlugin3.Cost6 = "0";
                        objPlugin3.Cost10 = "0";
                        objPlugin3.Capacity = "[0]";
                        objPlugin3.Parent = this;
                        _objChildren.Add(objPlugin3);
                        objNode.Nodes.Add(objPlugin3Node);

                        Gear objPlugin4 = new Gear(_objCharacter);
                        TreeNode objPlugin4Node = new TreeNode();
                        objPlugin4.Create(objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"Optimization\" and category = \"Program Options\"]"), objCharacter, objPlugin4Node, _intRating, null, null);
                        if (_intRating == 0)
                            objPlugin4.Rating = 1;
                        objPlugin4.Avail = "0";
                        objPlugin4.Cost = "0";
                        objPlugin4.Cost3 = "0";
                        objPlugin4.Cost6 = "0";
                        objPlugin4.Cost10 = "0";
                        objPlugin4.Capacity = "[0]";
                        objPlugin4.Parent = this;
                        _objChildren.Add(objPlugin4);
                        objNode.Nodes.Add(objPlugin4Node);
                        objNode.Expand();
                    }
                }
            }

            // If the item grants a Weapon bonus (Ammunition), just fill the WeaponBonus XmlNode.
            if (objXmlGear.InnerXml.Contains("<weaponbonus>"))
                _nodWeaponBonus = objXmlGear["weaponbonus"];
            objNode.Text = DisplayName;
        }
コード例 #9
0
        /// Create a Vehicle Modification from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlMod">XmlNode to create the object from.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="intRating">Selected Rating for the Gear.</param>
        /// <param name="objParent">Vehicle that the mod will be attached to.</param>
        /// <param name="intMarkup">Discount or markup that applies to the base cost of the mod.</param>
        public void Create(XmlNode objXmlMod, TreeNode objNode, int intRating, Vehicle objParent, decimal decMarkup = 0)
        {
            if (objParent == null)
            {
                throw new ArgumentNullException(nameof(objParent));
            }
            Parent = objParent;
            if (objXmlMod == null)
            {
                Utils.BreakIfDebug();
            }
            objXmlMod.TryGetStringFieldQuickly("name", ref _strName);
            objXmlMod.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlMod.TryGetStringFieldQuickly("limit", ref _strLimit);
            objXmlMod.TryGetStringFieldQuickly("slots", ref _strSlots);
            _intRating = intRating;
            if (objXmlMod["downgrade"] != null)
            {
                _blnDowngrade = true;
            }

            objXmlMod.TryGetStringFieldQuickly("capacity", ref _strCapacity);
            objXmlMod.TryGetStringFieldQuickly("rating", ref _strMaxRating);
            objXmlMod.TryGetInt32FieldQuickly("response", ref _intResponse);
            objXmlMod.TryGetInt32FieldQuickly("system", ref _intSystem);
            objXmlMod.TryGetInt32FieldQuickly("firewall", ref _intFirewall);
            objXmlMod.TryGetInt32FieldQuickly("signal", ref _intSignal);
            objXmlMod.TryGetInt32FieldQuickly("pilot", ref _intPilot);
            objXmlMod.TryGetInt32FieldQuickly("conditionmonitor", ref _intConditionMonitor);
            objXmlMod.TryGetStringFieldQuickly("weaponmountcategories", ref _strWeaponMountCategories);
            // Add Subsytem information if applicable.
            if (objXmlMod.InnerXml.Contains("subsystems"))
            {
                string      strSubsystem     = string.Empty;
                XmlNodeList objXmlSubsystems = objXmlMod.SelectNodes("subsystems/subsystem");
                if (objXmlSubsystems != null)
                {
                    strSubsystem = objXmlSubsystems.Cast <XmlNode>().Aggregate(strSubsystem, (current, objXmlSubsystem) => current + (objXmlSubsystem.InnerText + ","));
                }
                _strSubsystems = strSubsystem;
            }
            objXmlMod.TryGetStringFieldQuickly("avail", ref _strAvail);

            // Check for a Variable Cost.
            if (objXmlMod["cost"] != null)
            {
                _strCost = objXmlMod["cost"].InnerText;
                if (_strCost.StartsWith("Variable"))
                {
                    decimal decMin  = 0;
                    decimal decMax  = decimal.MaxValue;
                    string  strCost = _strCost.TrimStart("Variable", true).Trim("()".ToCharArray());
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo);
                        decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo);
                    }
                    else
                    {
                        decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo);
                    }

                    if (decMin != 0 || decMax != decimal.MaxValue)
                    {
                        frmSelectNumber frmPickNumber = new frmSelectNumber();
                        if (decMax > 1000000)
                        {
                            decMax = 1000000;
                        }
                        frmPickNumber.Minimum     = decMin;
                        frmPickNumber.Maximum     = decMax;
                        frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost").Replace("{0}", DisplayNameShort);
                        frmPickNumber.AllowCancel = false;
                        frmPickNumber.ShowDialog();
                        _strCost = frmPickNumber.SelectedValue.ToString();
                    }
                }
            }
            _decMarkup = decMarkup;

            objXmlMod.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlMod.TryGetStringFieldQuickly("page", ref _strPage);
            _nodBonus         = objXmlMod["bonus"];
            _nodWirelessBonus = objXmlMod["wirelessbonus"];
            _blnWirelessOn    = _nodWirelessBonus != null;

            if (GlobalOptions.Language != "en-us")
            {
                XmlNode objModNode = MyXmlNode;
                if (objModNode != null)
                {
                    objModNode.TryGetStringFieldQuickly("translate", ref _strAltName);
                    objModNode.TryGetStringFieldQuickly("altpage", ref _strAltPage);
                }

                XmlDocument objXmlDocument = XmlManager.Load("vehicles.xml");
                objModNode      = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                _strAltCategory = objModNode?.Attributes?["translate"]?.InnerText;
            }

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
コード例 #10
0
ファイル: VehicleMod.cs プロジェクト: Rockzo/chummer5a
        /// Create a Vehicle Modification from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlMod">XmlNode to create the object from.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="intRating">Selected Rating for the Gear.</param>
        public void Create(XmlNode objXmlMod, TreeNode objNode, int intRating)
        {
            _strName = objXmlMod["name"].InnerText;
            _strCategory = objXmlMod["category"].InnerText;
            objXmlMod.TryGetField("limit", out _strLimit);
            objXmlMod.TryGetField("slots", out _strSlots);
            if (intRating != 0)
            {
                _intRating = Convert.ToInt32(intRating);
            }
            if (objXmlMod["rating"] != null)
                _strMaxRating = objXmlMod["rating"].InnerText;
            else
                _strMaxRating = "0";
            objXmlMod.TryGetField("response", out _intResponse);
            objXmlMod.TryGetField("system", out _intSystem);
            objXmlMod.TryGetField("firewall", out _intFirewall);
            objXmlMod.TryGetField("signal", out _intSignal);
            objXmlMod.TryGetField("pilot", out _intPilot);
            objXmlMod.TryGetField("weaponmountcategories", out _strWeaponMountCategories);
            // Add Subsytem information if applicable.
            if (objXmlMod.InnerXml.Contains("subsystems"))
            {
                string strSubsystem = "";
                foreach (XmlNode objXmlSubsystem in objXmlMod.SelectNodes("subsystems/subsystem"))
                {
                    strSubsystem += objXmlSubsystem.InnerText + ",";
                }
                _strSubsystems = strSubsystem;
            }
            _strAvail = objXmlMod["avail"].InnerText;

            // Check for a Variable Cost.
            if (objXmlMod["cost"] != null)
            {
                if (objXmlMod["cost"].InnerText.StartsWith("Variable"))
                {
                    int intMin = 0;
                    int intMax = 0;
                    string strCost = objXmlMod["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
                    _strCost = objXmlMod["cost"].InnerText;
            }

            _strSource = objXmlMod["source"].InnerText;
            _strPage = objXmlMod["page"].InnerText;
            if (objXmlMod["bonus"] != null)
                _nodBonus = objXmlMod["bonus"];

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

                objModNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                if (objModNode != null)
                {
                    if (objModNode.Attributes["translate"] != null)
                        _strAltCategory = objModNode.Attributes["translate"].InnerText;
                }
            }

            objNode.Text = DisplayName;
            objNode.Tag = _guiID.ToString();
        }
コード例 #11
0
ファイル: Vehicle.cs プロジェクト: Rockzo/chummer5a
        /// Create a Vehicle from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlVehicle">XmlNode of the Vehicle to create.</param>
        /// <param name="objNode">TreeNode to add to a TreeView.</param>
        /// <param name="cmsVehicle">ContextMenuStrip to attach to Weapon Mounts.</param>
        /// <param name="cmsVehicleGear">ContextMenuStrip to attach to Gear.</param>
        /// <param name="cmsVehicleWeapon">ContextMenuStrip to attach to Vehicle Weapons.</param>
        /// <param name="cmsVehicleWeaponAccessory">ContextMenuStrip to attach to Weapon Accessories.</param>
        /// <param name="blnCreateChildren">Whether or not child items should be created.</param>
        public void Create(XmlNode objXmlVehicle, TreeNode objNode, ContextMenuStrip cmsVehicle, ContextMenuStrip cmsVehicleGear, ContextMenuStrip cmsVehicleWeapon, ContextMenuStrip cmsVehicleWeaponAccessory, bool blnCreateChildren = true)
        {
            _strName = objXmlVehicle["name"].InnerText;
            _strCategory = objXmlVehicle["category"].InnerText;
            //Some vehicles have different Offroad Handling speeds. If so, we want to split this up for use with mods and such later.
            if (objXmlVehicle["handling"].InnerText.Contains('/'))
            {
                _intHandling = Convert.ToInt32(objXmlVehicle["handling"].InnerText.Split('/')[0]);
                _intOffroadHandling = Convert.ToInt32(objXmlVehicle["handling"].InnerText.Split('/')[1]);
            }
            else
            {
                _intHandling = Convert.ToInt32(objXmlVehicle["handling"].InnerText);
            }
            _intAccel = Convert.ToInt32(objXmlVehicle["accel"].InnerText);
            _intSpeed = Convert.ToInt32(objXmlVehicle["speed"].InnerText);
            _intPilot = Convert.ToInt32(objXmlVehicle["pilot"].InnerText);
            _intBody = Convert.ToInt32(objXmlVehicle["body"].InnerText);
            _intArmor = Convert.ToInt32(objXmlVehicle["armor"].InnerText);
            _intSensor = Convert.ToInt32(objXmlVehicle["sensor"].InnerText);
            try
            {
                _intDeviceRating = Convert.ToInt32(objXmlVehicle["devicerating"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intSeats = Convert.ToInt32(objXmlVehicle["seats"].InnerText);
            }
            catch
            {
            }
            try
            {
                _intModSlots = Convert.ToInt32(objXmlVehicle["modslots"].InnerText);
            }
            catch (NullReferenceException e)
            {
                _intModSlots = _intBody;
            }
            _strAvail = objXmlVehicle["avail"].InnerText;
            _strCost = objXmlVehicle["cost"].InnerText;
            // Check for a Variable Cost.
            if (objXmlVehicle["cost"].InnerText.StartsWith("Variable"))
            {
                int intMin = 0;
                int intMax = 0;
                string strCost = objXmlVehicle["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();
                }
            }
            _strSource = objXmlVehicle["source"].InnerText;
            _strPage = objXmlVehicle["page"].InnerText;

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

                objVehicleNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                if (objVehicleNode != null)
                {
                    if (objVehicleNode.Attributes["translate"] != null)
                        _strAltCategory = objVehicleNode.Attributes["translate"].InnerText;
                }
            }

            objNode.Text = DisplayName;
            objNode.Tag = _guiID.ToString();

            // If there are any VehicleMods that come with the Vehicle, add them.
            if (objXmlVehicle.InnerXml.Contains("<mods>") && blnCreateChildren)
            {
                XmlDocument objXmlDocument = new XmlDocument();
                objXmlDocument = XmlManager.Instance.Load("vehicles.xml");

                XmlNodeList objXmlModList = objXmlVehicle.SelectNodes("mods/name");
                foreach (XmlNode objXmlVehicleMod in objXmlModList)
                {
                    XmlNode objXmlMod = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlVehicleMod.InnerText + "\"]");
                    if (objXmlMod != null)
                    {
                        TreeNode objModNode = new TreeNode();
                        VehicleMod objMod = new VehicleMod(_objCharacter);
                        int intRating = 0;

                        if (objXmlVehicleMod.Attributes["rating"] != null)
                            intRating = Convert.ToInt32(objXmlVehicleMod.Attributes["rating"].InnerText);

                        if (objXmlVehicleMod.Attributes["select"] != null)
                            objMod.Extra = objXmlVehicleMod.Attributes["select"].InnerText;

                        objMod.Create(objXmlMod, objModNode, intRating);
                        objMod.IncludedInVehicle = true;

                        _lstVehicleMods.Add(objMod);
                        objModNode.ForeColor = SystemColors.GrayText;
                        objModNode.ContextMenuStrip = cmsVehicle;

                        objNode.Nodes.Add(objModNode);
                        objNode.Expand();
                    }
                }
                if (objXmlVehicle.SelectSingleNode("mods/addslots") != null)
                    _intAddSlots = Convert.ToInt32(objXmlVehicle.SelectSingleNode("mods/addslots").InnerText);
            }

            // If there is any Gear that comes with the Vehicle, add them.
            if (objXmlVehicle.InnerXml.Contains("<gears>") && blnCreateChildren)
            {
                XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");

                XmlNodeList objXmlGearList = objXmlVehicle.SelectNodes("gears/gear");
                foreach (XmlNode objXmlVehicleGear in objXmlGearList)
                {
                    XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlVehicleGear.InnerText + "\"]");
                    if (objXmlGear != null)
                    {
                        TreeNode objGearNode = new TreeNode();
                        Gear objGear = new Gear(_objCharacter);
                        int intRating = 0;
                        int intQty = 1;
                        string strForceValue = "";

                        if (objXmlVehicleGear.Attributes["rating"] != null)
                            intRating = Convert.ToInt32(objXmlVehicleGear.Attributes["rating"].InnerText);

                        int intMaxRating = intRating;
                        if (objXmlVehicleGear.Attributes["maxrating"] != null)
                            intMaxRating = Convert.ToInt32(objXmlVehicleGear.Attributes["maxrating"].InnerText);

                        if (objXmlVehicleGear.Attributes["qty"] != null)
                            intQty = Convert.ToInt32(objXmlVehicleGear.Attributes["qty"].InnerText);

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

                        List<Weapon> objWeapons = new List<Weapon>();
                        List<TreeNode> objWeaponNodes = new List<TreeNode>();
                        objGear.Create(objXmlGear, _objCharacter, objGearNode, intRating, objWeapons, objWeaponNodes, strForceValue);
                        objGear.Cost = "0";
                        objGear.Quantity = intQty;
                        objGear.MaxRating = intMaxRating;
                        objGear.IncludedInParent = true;
                        objGearNode.Text = objGear.DisplayName;
                        objGearNode.ContextMenuStrip = cmsVehicleGear;

                        foreach (Weapon objWeapon in objWeapons)
                            objWeapon.VehicleMounted = true;

                        _lstGear.Add(objGear);

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

            // If there are any Weapons that come with the Vehicle, add them.
            if (objXmlVehicle.InnerXml.Contains("<weapons>") && blnCreateChildren)
            {
                XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml");

                foreach (XmlNode objXmlWeapon in objXmlVehicle.SelectNodes("weapons/weapon"))
                {
                    bool blnAttached = false;
                    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);
                    objWeapon.Cost = 0;
                    objWeapon.VehicleMounted = true;

                    // Find the first free Weapon Mount in the Vehicle.
                    foreach (VehicleMod objMod in _lstVehicleMods)
                    {
                        if ((objMod.Name.Contains("Weapon Mount") || (!String.IsNullOrEmpty(objMod.WeaponMountCategories) && objMod.WeaponMountCategories.Contains(objWeapon.Category) && objMod.Weapons.Count == 0)))
                        {
                            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();
                                    blnAttached = true;
                                    break;
                                }
                            }
                            break;
                        }
                    }

                    // If a free Weapon Mount could not be found, just attach it to the first one found and let the player deal with it.
                    if (!blnAttached)
                    {
                        foreach (VehicleMod objMod in _lstVehicleMods)
                        {
                            if (objMod.Name.Contains("Weapon Mount") || (!String.IsNullOrEmpty(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();
                                        blnAttached = true;
                                        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);
                            objMod.Cost = "0";
                            objModNode.ContextMenuStrip = cmsVehicleWeaponAccessory;

                            objWeapon.WeaponAccessories.Add(objMod);

                            objWeaponNode.Nodes.Add(objModNode);
                            objWeaponNode.Expand();
                        }
                    }
                }
            }
        }
コード例 #12
0
        /// Create a Vehicle Modification from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlMod">XmlNode to create the object from.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="intRating">Selected Rating for the Gear.</param>
        public void Create(XmlNode objXmlMod, TreeNode objNode, int intRating)
        {
            _strName     = objXmlMod["name"].InnerText;
            _strCategory = objXmlMod["category"].InnerText;
            objXmlMod.TryGetField("limit", out _strLimit);
            objXmlMod.TryGetField("slots", out _strSlots);
            if (intRating != 0)
            {
                _intRating = Convert.ToInt32(intRating);
            }
            if (objXmlMod["rating"] != null)
            {
                _strMaxRating = objXmlMod["rating"].InnerText;
            }
            else
            {
                _strMaxRating = "0";
            }
            objXmlMod.TryGetField("response", out _intResponse);
            objXmlMod.TryGetField("system", out _intSystem);
            objXmlMod.TryGetField("firewall", out _intFirewall);
            objXmlMod.TryGetField("signal", out _intSignal);
            objXmlMod.TryGetField("pilot", out _intPilot);
            objXmlMod.TryGetField("weaponmountcategories", out _strWeaponMountCategories);
            // Add Subsytem information if applicable.
            if (objXmlMod.InnerXml.Contains("subsystems"))
            {
                string strSubsystem = "";
                foreach (XmlNode objXmlSubsystem in objXmlMod.SelectNodes("subsystems/subsystem"))
                {
                    strSubsystem += objXmlSubsystem.InnerText + ",";
                }
                _strSubsystems = strSubsystem;
            }
            _strAvail = objXmlMod["avail"].InnerText;

            // Check for a Variable Cost.
            if (objXmlMod["cost"] != null)
            {
                if (objXmlMod["cost"].InnerText.StartsWith("Variable"))
                {
                    int    intMin  = 0;
                    int    intMax  = 0;
                    string strCost = objXmlMod["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
                {
                    _strCost = objXmlMod["cost"].InnerText;
                }
            }

            _strSource = objXmlMod["source"].InnerText;
            _strPage   = objXmlMod["page"].InnerText;
            if (objXmlMod["bonus"] != null)
            {
                _nodBonus = objXmlMod["bonus"];
            }

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

                objModNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                if (objModNode != null)
                {
                    if (objModNode.Attributes["translate"] != null)
                    {
                        _strAltCategory = objModNode.Attributes["translate"].InnerText;
                    }
                }
            }

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
コード例 #13
0
ファイル: Armor.cs プロジェクト: argo2445/chummer5a
        /// 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();
        }
コード例 #14
0
        /// Create a Vehicle Modification from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlMod">XmlNode to create the object from.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="objParent">Vehicle that the mod will be attached to.</param>
        /// <param name="intMarkup">Discount or markup that applies to the base cost of the mod.</param>
        public void Create(XmlNode objXmlMod, TreeNode objNode, Vehicle objParent, int intMarkup = 0)
        {
            if (objParent == null)
            {
                throw new ArgumentNullException(nameof(objParent));
            }
            Parent = objParent;
            if (objXmlMod == null)
            {
                Utils.BreakIfDebug();
            }
            objXmlMod.TryGetStringFieldQuickly("name", ref _strName);
            objXmlMod.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlMod.TryGetStringFieldQuickly("limit", ref _strLimit);
            objXmlMod.TryGetStringFieldQuickly("slots", ref _strSlots);
            objXmlMod.TryGetStringFieldQuickly("weaponmountcategories", ref _strWeaponMountCategories);
            objXmlMod.TryGetStringFieldQuickly("avail", ref _strAvail);

            // Check for a Variable Cost.
            if (objXmlMod["cost"] != null)
            {
                if (objXmlMod["cost"].InnerText.StartsWith("Variable"))
                {
                    int    intMin;
                    var    intMax         = 0;
                    char[] chrParentheses = { '(', ')' };
                    string strCost        = objXmlMod["cost"].InnerText.Replace("Variable", string.Empty).Trim(chrParentheses);
                    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)
                    {
                        var 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
                {
                    _strCost = objXmlMod["cost"].InnerText;
                }
            }
            _intMarkup = intMarkup;

            objXmlMod.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlMod.TryGetStringFieldQuickly("page", ref _strPage);

            if (GlobalOptions.Instance.Language != "en-us")
            {
                XmlDocument objXmlDocument = XmlManager.Instance.Load("vehicles.xml");
                XmlNode     objModNode     = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + _strName + "\"]");
                if (objModNode != null)
                {
                    objModNode.TryGetStringFieldQuickly("translate", ref _strAltName);
                    objModNode.TryGetStringFieldQuickly("altpage", ref _strAltPage);
                }

                objModNode      = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                _strAltCategory = objModNode?.Attributes?["translate"]?.InnerText;
            }

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
コード例 #15
0
        /// Create a Weapon Accessory from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlAccessory">XmlNode to create the object from.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="strMount">Mount slot that the Weapon Accessory will consume.</param>
        /// <param name="intRating">Rating of the Weapon Accessory.</param>
        public void Create(XmlNode objXmlAccessory, TreeNode objNode, Tuple <string, string> strMount, int intRating, ContextMenuStrip cmsAccessoryGear, bool blnSkipCost = false, bool blnCreateChildren = true)
        {
            objXmlAccessory.TryGetStringFieldQuickly("name", ref _strName);
            _strMount      = strMount.Item1;
            _strExtraMount = strMount.Item2;
            _intRating     = intRating;
            objXmlAccessory.TryGetStringFieldQuickly("avail", ref _strAvail);
            // Check for a Variable Cost.
            if (blnSkipCost)
            {
                _strCost = "0";
            }
            else if (objXmlAccessory["cost"] != null)
            {
                if (objXmlAccessory["cost"].InnerText.StartsWith("Variable"))
                {
                    int    intMin  = 0;
                    int    intMax  = 0;
                    string strCost = objXmlAccessory["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
                {
                    _strCost = objXmlAccessory["cost"].InnerText;
                }
            }

            objXmlAccessory.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlAccessory.TryGetStringFieldQuickly("page", ref _strPage);
            _nodAllowGear = objXmlAccessory["allowgear"];
            objXmlAccessory.TryGetStringFieldQuickly("rc", ref _strRC);
            objXmlAccessory.TryGetBoolFieldQuickly("rcdeployable", ref _blnDeployable);
            objXmlAccessory.TryGetInt32FieldQuickly("rcgroup", ref _intRCGroup);
            objXmlAccessory.TryGetStringFieldQuickly("conceal", ref _strConceal);
            objXmlAccessory.TryGetInt32FieldQuickly("ammoslots", ref _intAmmoSlots);
            objXmlAccessory.TryGetStringFieldQuickly("ammoreplace", ref _strAmmoReplace);
            objXmlAccessory.TryGetInt32FieldQuickly("accuracy", ref _intAccuracy);
            objXmlAccessory.TryGetStringFieldQuickly("dicepool", ref _strDicePool);
            objXmlAccessory.TryGetStringFieldQuickly("damagetype", ref _strDamageType);
            objXmlAccessory.TryGetStringFieldQuickly("damage", ref _strDamage);
            objXmlAccessory.TryGetStringFieldQuickly("damagereplace", ref _strDamageReplace);
            objXmlAccessory.TryGetStringFieldQuickly("firemode", ref _strFireMode);
            objXmlAccessory.TryGetStringFieldQuickly("firemodereplace", ref _strFireModeReplace);
            objXmlAccessory.TryGetStringFieldQuickly("ap", ref _strAP);
            objXmlAccessory.TryGetStringFieldQuickly("apreplace", ref _strAPReplace);
            objXmlAccessory.TryGetStringFieldQuickly("addmode", ref _strAddMode);
            objXmlAccessory.TryGetInt32FieldQuickly("fullburst", ref _intFullBurst);
            objXmlAccessory.TryGetInt32FieldQuickly("suppressive", ref _intSuppressive);
            objXmlAccessory.TryGetInt32FieldQuickly("rangebonus", ref _intRangeBonus);
            objXmlAccessory.TryGetStringFieldQuickly("extra", ref _strExtra);
            objXmlAccessory.TryGetInt32FieldQuickly("ammobonus", ref _intAmmoBonus);
            objXmlAccessory.TryGetInt32FieldQuickly("accessorycostmultiplier", ref _intAccessoryCostMultiplier);

            // Add any Gear that comes with the Weapon Accessory.
            if (objXmlAccessory["gears"] != null && blnCreateChildren)
            {
                XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");
                foreach (XmlNode objXmlAccessoryGear in objXmlAccessory.SelectNodes("gears/usegear"))
                {
                    intRating = 0;
                    string strForceValue = string.Empty;
                    if (objXmlAccessoryGear.Attributes["rating"] != null)
                    {
                        intRating = Convert.ToInt32(objXmlAccessoryGear.Attributes["rating"].InnerText);
                    }
                    if (objXmlAccessoryGear.Attributes["select"] != null)
                    {
                        strForceValue = objXmlAccessoryGear.Attributes["select"].InnerText;
                    }

                    XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlAccessoryGear.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.Cost             = "0";
                    objGear.MaxRating        = objGear.Rating;
                    objGear.MinRating        = objGear.Rating;
                    objGear.IncludedInParent = true;
                    _lstGear.Add(objGear);

                    objGearNode.ContextMenuStrip = cmsAccessoryGear;
                    objNode.Nodes.Add(objGearNode);
                    objNode.Expand();
                }
            }

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

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
コード例 #16
0
ファイル: ArmorMod.cs プロジェクト: btterrette7/chummer5a
        /// Create a Armor Modification 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="intRating">Rating of the selected ArmorMod.</param>
        /// <param name="objWeapons">List of Weapons that are created by the Armor.</param>
        /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param>
        /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param>
        public void Create(XmlNode objXmlArmorNode, TreeNode objNode, int intRating, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes, bool blnSkipCost = false)
        {
            objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName);
            objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity);
            _intRating = intRating;
            objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intA);
            objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating);
            objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail);
            objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage);
            _nodBonus = objXmlArmorNode["bonus"];

            if (GlobalOptions.Instance.Language != "en-us")
            {
                XmlDocument objXmlDocument = XmlManager.Instance.Load("armor.xml");
                XmlNode     objArmorNode   = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + _strName + "\"]");
                if (objArmorNode != null)
                {
                    objArmorNode.TryGetStringFieldQuickly("translate", ref _strAltName);
                    objArmorNode.TryGetStringFieldQuickly("altpage", ref _strAltPage);
                }

                objArmorNode = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                if (objArmorNode != null)
                {
                    if (objArmorNode.Attributes["translate"] != null)
                    {
                        _strAltCategory = objArmorNode.Attributes["translate"].InnerText;
                    }
                }
            }

            // Check for a Variable Cost.
            if (blnSkipCost)
            {
                _strCost = "0";
            }
            else if (objXmlArmorNode["cost"] != null)
            {
                XmlNode objXmlArmorCostNode = objXmlArmorNode["cost"];

                if (objXmlArmorCostNode.InnerText.StartsWith("Variable"))
                {
                    int    intMin;
                    int    intMax         = 0;
                    char[] chrParentheses = { '(', ')' };
                    string strCost        = objXmlArmorCostNode.InnerText.Replace("Variable", string.Empty).Trim(chrParentheses);
                    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
                {
                    _strCost = objXmlArmorCostNode.InnerText;
                }
            }

            if (objXmlArmorNode["bonus"] != null && !blnSkipCost)
            {
                ImprovementManager objImprovementManager = new ImprovementManager(_objCharacter);
                if (!objImprovementManager.CreateImprovements(Improvement.ImprovementSource.ArmorMod, _guiID.ToString(), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort))
                {
                    _guiID = Guid.Empty;
                    return;
                }
                if (!string.IsNullOrEmpty(objImprovementManager.SelectedValue))
                {
                    _strExtra     = objImprovementManager.SelectedValue;
                    objNode.Text += " (" + objImprovementManager.SelectedValue + ")";
                }
            }

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

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

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

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

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
コード例 #17
0
        /// Create a Weapon Accessory from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlAccessory">XmlNode to create the object from.</param>
        /// <param name="strMount">Mount slot that the Weapon Accessory will consume.</param>
        /// <param name="intRating">Rating of the Weapon Accessory.</param>
        /// <param name="blnCreateChildren">Whether or not child items should be created.</param>
        /// <param name="blnCreateImprovements">Whether or not bonuses should be created.</param>
        /// <param name="blnSkipCost">Whether or not forms asking to determine variable costs should be displayed.</param>
        public void Create(XmlNode objXmlAccessory, Tuple <string, string> strMount, int intRating, bool blnSkipCost = false, bool blnCreateChildren = true, bool blnCreateImprovements = true)
        {
            if (objXmlAccessory.TryGetStringFieldQuickly("name", ref _strName))
            {
                _objCachedMyXmlNode = null;
            }
            _strMount      = strMount.Item1;
            _strExtraMount = strMount.Item2;
            _intRating     = intRating;
            objXmlAccessory.TryGetStringFieldQuickly("avail", ref _strAvail);
            // Check for a Variable Cost.
            if (blnSkipCost)
            {
                _strCost = "0";
            }
            else
            {
                _strCost = objXmlAccessory["cost"]?.InnerText ?? "0";
                if (_strCost.StartsWith("Variable("))
                {
                    decimal decMin;
                    decimal decMax  = decimal.MaxValue;
                    string  strCost = _strCost.TrimStartOnce("Variable(", true).TrimEndOnce(')');
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo);
                        decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo);
                    }
                    else
                    {
                        decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo);
                    }

                    if (decMin != 0 || decMax != decimal.MaxValue)
                    {
                        string strNuyenFormat   = _objCharacter.Options.NuyenFormat;
                        int    intDecimalPlaces = strNuyenFormat.IndexOf('.');
                        if (intDecimalPlaces == -1)
                        {
                            intDecimalPlaces = 0;
                        }
                        else
                        {
                            intDecimalPlaces = strNuyenFormat.Length - intDecimalPlaces - 1;
                        }
                        frmSelectNumber frmPickNumber = new frmSelectNumber(intDecimalPlaces);
                        if (decMax > 1000000)
                        {
                            decMax = 1000000;
                        }
                        frmPickNumber.Minimum     = decMin;
                        frmPickNumber.Maximum     = decMax;
                        frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost", GlobalOptions.Language).Replace("{0}", DisplayNameShort(GlobalOptions.Language));
                        frmPickNumber.AllowCancel = false;
                        frmPickNumber.ShowDialog();
                        _strCost = frmPickNumber.SelectedValue.ToString(GlobalOptions.InvariantCultureInfo);
                    }
                }
            }

            objXmlAccessory.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlAccessory.TryGetStringFieldQuickly("page", ref _strPage);
            _nodAllowGear = objXmlAccessory["allowgear"];
            if (!objXmlAccessory.TryGetStringFieldQuickly("altnotes", ref _strNotes))
            {
                objXmlAccessory.TryGetStringFieldQuickly("notes", ref _strNotes);
            }
            objXmlAccessory.TryGetStringFieldQuickly("rc", ref _strRC);
            objXmlAccessory.TryGetBoolFieldQuickly("rcdeployable", ref _blnDeployable);
            objXmlAccessory.TryGetInt32FieldQuickly("rcgroup", ref _intRCGroup);
            objXmlAccessory.TryGetStringFieldQuickly("conceal", ref _strConceal);
            objXmlAccessory.TryGetInt32FieldQuickly("ammoslots", ref _intAmmoSlots);
            objXmlAccessory.TryGetStringFieldQuickly("ammoreplace", ref _strAmmoReplace);
            objXmlAccessory.TryGetInt32FieldQuickly("accuracy", ref _intAccuracy);
            objXmlAccessory.TryGetStringFieldQuickly("dicepool", ref _strDicePool);
            objXmlAccessory.TryGetStringFieldQuickly("damagetype", ref _strDamageType);
            objXmlAccessory.TryGetStringFieldQuickly("damage", ref _strDamage);
            objXmlAccessory.TryGetStringFieldQuickly("damagereplace", ref _strDamageReplace);
            objXmlAccessory.TryGetStringFieldQuickly("firemode", ref _strFireMode);
            objXmlAccessory.TryGetStringFieldQuickly("firemodereplace", ref _strFireModeReplace);
            objXmlAccessory.TryGetStringFieldQuickly("ap", ref _strAP);
            objXmlAccessory.TryGetStringFieldQuickly("apreplace", ref _strAPReplace);
            objXmlAccessory.TryGetStringFieldQuickly("addmode", ref _strAddMode);
            objXmlAccessory.TryGetInt32FieldQuickly("fullburst", ref _intFullBurst);
            objXmlAccessory.TryGetInt32FieldQuickly("suppressive", ref _intSuppressive);
            objXmlAccessory.TryGetInt32FieldQuickly("rangebonus", ref _intRangeBonus);
            objXmlAccessory.TryGetStringFieldQuickly("extra", ref _strExtra);
            objXmlAccessory.TryGetInt32FieldQuickly("ammobonus", ref _intAmmoBonus);
            objXmlAccessory.TryGetInt32FieldQuickly("accessorycostmultiplier", ref _intAccessoryCostMultiplier);

            // Add any Gear that comes with the Weapon Accessory.
            XmlNode xmlGearsNode = objXmlAccessory["gears"];

            if (xmlGearsNode != null && blnCreateChildren)
            {
                XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml");
                using (XmlNodeList xmlGearsList = xmlGearsNode.SelectNodes("usegear"))
                    if (xmlGearsList != null)
                    {
                        foreach (XmlNode objXmlAccessoryGear in xmlGearsList)
                        {
                            XmlNode objXmlAccessoryGearName = objXmlAccessoryGear["name"];
                            XmlAttributeCollection objXmlAccessoryGearNameAttributes = objXmlAccessoryGearName?.Attributes;
                            int     intGearRating           = 0;
                            decimal decGearQty              = 1;
                            string  strChildForceSource     = objXmlAccessoryGear["source"]?.InnerText ?? string.Empty;
                            string  strChildForcePage       = objXmlAccessoryGear["page"]?.InnerText ?? string.Empty;
                            string  strChildForceValue      = objXmlAccessoryGearNameAttributes?["select"]?.InnerText ?? string.Empty;
                            bool    blnChildCreateChildren  = objXmlAccessoryGearNameAttributes?["createchildren"]?.InnerText != bool.FalseString;
                            bool    blnAddChildImprovements = objXmlAccessoryGearNameAttributes?["addimprovements"]?.InnerText != bool.FalseString && blnCreateImprovements;
                            if (objXmlAccessoryGear["rating"] != null)
                            {
                                intGearRating = Convert.ToInt32(objXmlAccessoryGear["rating"].InnerText);
                            }
                            if (objXmlAccessoryGearNameAttributes?["qty"] != null)
                            {
                                decGearQty = Convert.ToDecimal(objXmlAccessoryGearNameAttributes["qty"].InnerText, GlobalOptions.InvariantCultureInfo);
                            }

                            XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlAccessoryGearName?.InnerText + "\" and category = \"" + objXmlAccessoryGear["category"].InnerText + "\"]");
                            Gear    objGear    = new Gear(_objCharacter);

                            List <Weapon> lstWeapons = new List <Weapon>();

                            objGear.Create(objXmlGear, intGearRating, lstWeapons, strChildForceValue, blnAddChildImprovements, blnChildCreateChildren);

                            objGear.Quantity  = decGearQty;
                            objGear.Cost      = "0";
                            objGear.MinRating = intGearRating;
                            objGear.MaxRating = intGearRating;
                            objGear.ParentID  = InternalId;
                            if (!string.IsNullOrEmpty(strChildForceSource))
                            {
                                objGear.Source = strChildForceSource;
                            }
                            if (!string.IsNullOrEmpty(strChildForcePage))
                            {
                                objGear.Page = strChildForcePage;
                            }
                            _lstGear.Add(objGear);

                            // Change the Capacity of the child if necessary.
                            if (objXmlAccessoryGear["capacity"] != null)
                            {
                                objGear.Capacity = '[' + objXmlAccessoryGear["capacity"].InnerText + ']';
                            }
                        }
                    }
            }
        }
コード例 #18
0
        /// Create a Armor Modification from an XmlNode.
        /// <param name="objXmlArmorNode">XmlNode to create the object from.</param>
        /// <param name="intRating">Rating of the selected ArmorMod.</param>
        /// <param name="lstWeapons">List of Weapons that are created by the Armor.</param>
        /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param>
        /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param>
        public void Create(XmlNode objXmlArmorNode, int intRating, List <Weapon> lstWeapons, bool blnSkipCost = false, bool blnSkipSelectForms = false)
        {
            if (objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName))
            {
                _objCachedMyXmlNode = null;
            }
            objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity);
            objXmlArmorNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity);
            _intRating = intRating;
            objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intA);
            objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating);
            objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail);
            objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage);
            objXmlArmorNode.TryGetStringFieldQuickly("notes", ref _strNotes);
            _nodBonus         = objXmlArmorNode["bonus"];
            _nodWirelessBonus = objXmlArmorNode["wirelessbonus"];
            _blnWirelessOn    = _nodWirelessBonus != null;

            // Check for a Variable Cost.
            if (blnSkipCost)
            {
                _strCost = "0";
            }
            else if (objXmlArmorNode["cost"] != null)
            {
                XmlNode objXmlArmorCostNode = objXmlArmorNode["cost"];

                if (objXmlArmorCostNode.InnerText.StartsWith("Variable("))
                {
                    decimal decMin  = 0.0m;
                    decimal decMax  = decimal.MaxValue;
                    string  strCost = objXmlArmorNode["cost"].InnerText.TrimStart("Variable(", true).TrimEnd(')');
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo);
                        decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo);
                    }
                    else
                    {
                        decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo);
                    }

                    if (decMin != 0 || decMax != decimal.MaxValue)
                    {
                        string strNuyenFormat   = _objCharacter.Options.NuyenFormat;
                        int    intDecimalPlaces = strNuyenFormat.IndexOf('.');
                        if (intDecimalPlaces == -1)
                        {
                            intDecimalPlaces = 0;
                        }
                        else
                        {
                            intDecimalPlaces = strNuyenFormat.Length - intDecimalPlaces - 1;
                        }
                        frmSelectNumber frmPickNumber = new frmSelectNumber(intDecimalPlaces);
                        if (decMax > 1000000)
                        {
                            decMax = 1000000;
                        }
                        frmPickNumber.Minimum     = decMin;
                        frmPickNumber.Maximum     = decMax;
                        frmPickNumber.Description = LanguageManager.GetString("String_SelectVariableCost", GlobalOptions.Language).Replace("{0}", DisplayNameShort(GlobalOptions.Language));
                        frmPickNumber.AllowCancel = false;
                        frmPickNumber.ShowDialog();
                        _strCost = frmPickNumber.SelectedValue.ToString(GlobalOptions.InvariantCultureInfo);
                    }
                }
                else
                {
                    _strCost = objXmlArmorCostNode.InnerText;
                }
            }

            if (objXmlArmorNode["bonus"] != null && !blnSkipCost && !blnSkipSelectForms)
            {
                if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.ArmorMod, _guiID.ToString(), objXmlArmorNode["bonus"], false, intRating, DisplayNameShort(GlobalOptions.Language)))
                {
                    _guiID = Guid.Empty;
                    return;
                }
                if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue))
                {
                    _strExtra = ImprovementManager.SelectedValue;
                }
            }

            // Add any Gear that comes with the Armor.
            if (objXmlArmorNode["gears"] != null)
            {
                XmlDocument objXmlGearDocument = XmlManager.Load("gear.xml");
                foreach (XmlNode objXmlArmorGear in objXmlArmorNode.SelectNodes("gears/usegear"))
                {
                    intRating = 0;
                    string strForceValue = string.Empty;
                    objXmlArmorGear.TryGetInt32FieldQuickly("rating", ref intRating);
                    objXmlArmorGear.TryGetStringFieldQuickly("select", ref strForceValue);

                    XmlNode objXmlGear = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlArmorGear.InnerText + "\"]");
                    Gear    objGear    = new Gear(_objCharacter);

                    objGear.Create(objXmlGear, intRating, lstWeapons, strForceValue, !blnSkipCost && !blnSkipSelectForms);

                    objGear.Capacity      = "[0]";
                    objGear.ArmorCapacity = "[0]";
                    objGear.Cost          = "0";
                    objGear.MaxRating     = objGear.Rating;
                    objGear.MinRating     = objGear.Rating;
                    objGear.ParentID      = InternalId;
                    _lstGear.Add(objGear);
                }
            }

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

                // More than one Weapon can be added, so loop through all occurrences.
                foreach (XmlNode objXmlAddWeapon in objXmlArmorNode.SelectNodes("addweapon"))
                {
                    string  strLoopID    = objXmlAddWeapon.InnerText;
                    XmlNode objXmlWeapon = strLoopID.IsGuid()
                        ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + strLoopID + "\"]")
                        : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + strLoopID + "\"]");

                    Weapon objGearWeapon = new Weapon(_objCharacter);
                    objGearWeapon.Create(objXmlWeapon, lstWeapons, true, !blnSkipCost && !blnSkipSelectForms);
                    objGearWeapon.ParentID = InternalId;
                    lstWeapons.Add(objGearWeapon);

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