示例#1
0
        /// <summary>
        /// Create a weapon mount using names instead of IDs, because user readability is important and untrustworthy.
        /// </summary>
        /// <param name="xmlNode"></param>
        public void CreateByName(XmlNode xmlNode)
        {
            XmlDocument xmlDoc      = XmlManager.Load("vehicles.xml");
            WeaponMount objMount    = this;
            XmlNode     xmlDataNode = xmlDoc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{xmlNode["size"]?.InnerText}\" and category = \"Size\"]");

            if (xmlDataNode != null)
            {
                objMount.Create(xmlDataNode);

                xmlDataNode = xmlDoc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{xmlNode["flexibility"]?.InnerText}\" and category = \"Flexibility\"]");
                if (xmlDataNode != null)
                {
                    WeaponMountOption objWeaponMountOption = new WeaponMountOption(_objCharacter);
                    objWeaponMountOption.Create(xmlDataNode);
                    objMount.WeaponMountOptions.Add(objWeaponMountOption);
                }

                xmlDataNode = xmlDoc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{xmlNode["control"]?.InnerText}\" and category = \"Control\"]");
                if (xmlDataNode != null)
                {
                    WeaponMountOption objWeaponMountOption = new WeaponMountOption(_objCharacter);
                    objWeaponMountOption.Create(xmlDataNode);
                    objMount.WeaponMountOptions.Add(objWeaponMountOption);
                }

                xmlDataNode = xmlDoc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{xmlNode["visibility"]?.InnerText}\" and category = \"Visibility\"]");
                if (xmlDataNode != null)
                {
                    WeaponMountOption objWeaponMountOption = new WeaponMountOption(_objCharacter);
                    objWeaponMountOption.Create(xmlDataNode);
                    objMount.WeaponMountOptions.Add(objWeaponMountOption);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Load the VehicleMod from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        /// <param name="objVehicle">Vehicle that the mod is attached to.</param>
        /// <param name="blnCopy">Indicates whether a new item will be created as a copy of this one.</param>
        public void Load(XmlNode objNode, Vehicle objVehicle, bool blnCopy = false)
        {
            if (blnCopy)
            {
                _guiID = Guid.NewGuid();
            }
            else
            {
                objNode.TryGetField("guid", Guid.TryParse, out _guiID);
            }
            objNode.TryGetStringFieldQuickly("name", ref _strName);
            objNode.TryGetStringFieldQuickly("category", ref _strCategory);
            objNode.TryGetStringFieldQuickly("limit", ref _strLimit);
            objNode.TryGetInt32FieldQuickly("slots", ref _intSlots);
            objNode.TryGetStringFieldQuickly("weaponmountcategories", ref _strWeaponMountCategories);
            objNode.TryGetStringFieldQuickly("page", ref _strPage);
            objNode.TryGetStringFieldQuickly("avail", ref _strAvail);
            objNode.TryGetStringFieldQuickly("cost", ref _strCost);
            objNode.TryGetDecFieldQuickly("markup", ref _decMarkup);
            objNode.TryGetStringFieldQuickly("source", ref _strSource);
            objNode.TryGetBoolFieldQuickly("included", ref _blnIncludeInVehicle);
            objNode.TryGetBoolFieldQuickly("installed", ref _blnInstalled);
            if (objNode["weapons"] != null)
            {
                foreach (XmlNode n in objNode.SelectNodes("weapons/weapon"))
                {
                    Weapon w = new Weapon(_character);
                    w.Load(n, blnCopy);
                    _weapons.Add(w);
                }
            }
            if (objNode["weaponmountoptions"] != null)
            {
                foreach (XmlNode n in objNode.SelectNodes("weaponmountoptions/weaponmountoption"))
                {
                    WeaponMountOption w = new WeaponMountOption(_character);
                    w.Load(n, _vehicle);
                    WeaponMountOptions.Add(w);
                }
            }
            objNode.TryGetStringFieldQuickly("notes", ref _strNotes);
            objNode.TryGetBoolFieldQuickly("discountedcost", ref _blnDiscountCost);
            objNode.TryGetStringFieldQuickly("extra", ref _strExtra);

            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;
            }
        }
示例#3
0
        /// <summary>
        /// Create a weapon mount using names instead of IDs, because user readability is important and untrustworthy.
        /// </summary>
        /// <param name="xmlNode"></param>
        public void CreateByName(XmlNode xmlNode)
        {
            XmlDocument xmlDoc      = XmlManager.Load("vehicles.xml");
            WeaponMount objMount    = this;
            XmlNode     xmlDataNode = xmlDoc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{xmlNode["size"]?.InnerText}\" and category = \"Size\"]");

            if (xmlDataNode != null)
            {
                objMount.Create(xmlDataNode);

                xmlDataNode = xmlDoc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{xmlNode["flexibility"]?.InnerText}\" and category = \"Flexibility\"]");
                if (xmlDataNode != null)
                {
                    WeaponMountOption objWeaponMountOption = new WeaponMountOption(_objCharacter);
                    objWeaponMountOption.Create(xmlDataNode);
                    objMount.WeaponMountOptions.Add(objWeaponMountOption);
                }

                xmlDataNode = xmlDoc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{xmlNode["control"]?.InnerText}\" and category = \"Control\"]");
                if (xmlDataNode != null)
                {
                    WeaponMountOption objWeaponMountOption = new WeaponMountOption(_objCharacter);
                    objWeaponMountOption.Create(xmlDataNode);
                    objMount.WeaponMountOptions.Add(objWeaponMountOption);
                }

                xmlDataNode = xmlDoc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{xmlNode["visibility"]?.InnerText}\" and category = \"Visibility\"]");
                if (xmlDataNode != null)
                {
                    WeaponMountOption objWeaponMountOption = new WeaponMountOption(_objCharacter);
                    objWeaponMountOption.Create(xmlDataNode);
                    objMount.WeaponMountOptions.Add(objWeaponMountOption);
                }
                _strLocation       = xmlNode["location"]?.InnerText ?? string.Empty;
                _strAllowedWeapons = xmlNode["allowedweapons"]?.InnerText ?? string.Empty;
                xmlDataNode        = xmlNode["mods"];
                if (xmlDataNode == null)
                {
                    return;
                }
                using (XmlNodeList xmlModList = xmlDataNode.SelectNodes("mod"))
                    if (xmlModList != null)
                    {
                        foreach (XmlNode xmlModNode in xmlModList)
                        {
                            VehicleMod objMod = new VehicleMod(_objCharacter)
                            {
                                Parent            = Parent,
                                WeaponMountParent = this
                            };
                            objMod.Load(xmlModNode);
                            _lstMods.Add(objMod);
                        }
                    }
            }
        }
示例#4
0
 /// <summary>
 /// Load the VehicleMod from the XmlNode.
 /// </summary>
 /// <param name="objNode">XmlNode to load.</param>
 /// <param name="objVehicle">Vehicle that the mod is attached to.</param>
 /// <param name="blnCopy">Indicates whether a new item will be created as a copy of this one.</param>
 public void Load(XmlNode objNode, Vehicle objVehicle, bool blnCopy = false)
 {
     if (blnCopy)
     {
         _guiID = Guid.NewGuid();
     }
     else
     {
         objNode.TryGetField("guid", Guid.TryParse, out _guiID);
     }
     objNode.TryGetStringFieldQuickly("name", ref _strName);
     if (!objNode.TryGetStringFieldQuickly("sourceid", ref _strSourceId))
     {
         _strSourceId = XmlManager.Load("vehicles.xml")?.SelectSingleNode("/chummer/weaponmounts/weaponmount[name = \"" + _strName + "\"]")?["id"]?.InnerText ?? Guid.NewGuid().ToString();
     }
     objNode.TryGetStringFieldQuickly("category", ref _strCategory);
     objNode.TryGetStringFieldQuickly("limit", ref _strLimit);
     objNode.TryGetInt32FieldQuickly("slots", ref _intSlots);
     objNode.TryGetStringFieldQuickly("weaponmountcategories", ref _strWeaponMountCategories);
     objNode.TryGetStringFieldQuickly("page", ref _strPage);
     objNode.TryGetStringFieldQuickly("avail", ref _strAvail);
     objNode.TryGetStringFieldQuickly("cost", ref _strCost);
     objNode.TryGetDecFieldQuickly("markup", ref _decMarkup);
     objNode.TryGetStringFieldQuickly("source", ref _strSource);
     objNode.TryGetBoolFieldQuickly("included", ref _blnIncludeInVehicle);
     objNode.TryGetBoolFieldQuickly("installed", ref _blnInstalled);
     if (objNode["weapons"] != null)
     {
         foreach (XmlNode n in objNode.SelectNodes("weapons/weapon"))
         {
             Weapon w = new Weapon(_character);
             w.Load(n, blnCopy);
             _weapons.Add(w);
         }
     }
     if (objNode["weaponmountoptions"] != null)
     {
         foreach (XmlNode n in objNode.SelectNodes("weaponmountoptions/weaponmountoption"))
         {
             WeaponMountOption w = new WeaponMountOption(_character);
             w.Load(n, _vehicle);
             WeaponMountOptions.Add(w);
         }
     }
     objNode.TryGetStringFieldQuickly("notes", ref _strNotes);
     objNode.TryGetBoolFieldQuickly("discountedcost", ref _blnDiscountCost);
     objNode.TryGetStringFieldQuickly("extra", ref _strExtra);
 }
示例#5
0
        /// <summary>
        /// Create a weapon mount using names instead of IDs, because user readability is important and untrustworthy.
        /// </summary>
        /// <param name="n"></param>
        internal void CreateByName(XmlNode n, TreeNode t)
        {
            XmlDocument doc   = XmlManager.Load("vehicles.xml");
            TreeNode    tree  = new TreeNode();
            WeaponMount mount = this;
            XmlNode     node  = doc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{n["size"].InnerText}\" and category = \"Size\"]");

            mount.Create(node, tree, _vehicle);
            WeaponMountOption option = new WeaponMountOption(_character);

            node = doc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{n["flexibility"].InnerText}\" and category = \"Flexibility\"]");
            option.Create(node["id"].InnerText, mount.WeaponMountOptions);
            option = new WeaponMountOption(_character);
            node   = doc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{n["control"].InnerText}\" and category = \"Control\"]");
            option.Create(node["id"].InnerText, mount.WeaponMountOptions);
            option = new WeaponMountOption(_character);
            node   = doc.SelectSingleNode($"/chummer/weaponmounts/weaponmount[name = \"{n["visibility"].InnerText}\" and category = \"Visibility\"]");
            option.Create(node["id"].InnerText, mount.WeaponMountOptions);
            t.Text = DisplayName;
            t.Tag  = _guiID.ToString();
        }
示例#6
0
        /// <summary>
        /// Load the VehicleMod from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        /// <param name="objVehicle">Vehicle that the mod is attached to.</param>
        /// <param name="blnCopy">Indicates whether a new item will be created as a copy of this one.</param>
        public void Load(XmlNode objNode, Vehicle objVehicle, bool blnCopy = false)
        {
            if (blnCopy)
            {
                _guiID = Guid.NewGuid();
            }
            else
            {
                objNode.TryGetField("guid", Guid.TryParse, out _guiID);
            }
            objNode.TryGetStringFieldQuickly("name", ref _strName);
            if (!objNode.TryGetStringFieldQuickly("sourceid", ref _strSourceId))
            {
                _strSourceId = XmlManager.Load("vehicles.xml").SelectSingleNode("/chummer/weaponmounts/weaponmount[name = \"" + _strName + "\"]/id")?.InnerText ?? Guid.NewGuid().ToString("D");
            }
            objNode.TryGetStringFieldQuickly("category", ref _strCategory);
            objNode.TryGetStringFieldQuickly("limit", ref _strLimit);
            objNode.TryGetInt32FieldQuickly("slots", ref _intSlots);
            objNode.TryGetStringFieldQuickly("weaponmountcategories", ref _strWeaponMountCategories);
            objNode.TryGetStringFieldQuickly("page", ref _strPage);
            objNode.TryGetStringFieldQuickly("avail", ref _strAvail);
            objNode.TryGetStringFieldQuickly("cost", ref _strCost);
            objNode.TryGetDecFieldQuickly("markup", ref _decMarkup);
            objNode.TryGetStringFieldQuickly("source", ref _strSource);
            objNode.TryGetBoolFieldQuickly("included", ref _blnIncludeInVehicle);
            objNode.TryGetBoolFieldQuickly("installed", ref _blnInstalled);

            XmlNode xmlChildrenNode = objNode["weapons"];

            if (xmlChildrenNode != null)
            {
                using (XmlNodeList xmlWeaponList = xmlChildrenNode.SelectNodes("weapon"))
                    if (xmlWeaponList != null)
                    {
                        foreach (XmlNode xmlWeaponNode in xmlWeaponList)
                        {
                            Weapon objWeapon = new Weapon(_objCharacter)
                            {
                                ParentVehicle = Parent,
                                ParentMount   = this
                            };
                            objWeapon.Load(xmlWeaponNode, blnCopy);
                            _lstWeapons.Add(objWeapon);
                        }
                    }
            }
            xmlChildrenNode = objNode["weaponmountoptions"];
            if (xmlChildrenNode != null)
            {
                using (XmlNodeList xmlWeaponMountOptionList = xmlChildrenNode.SelectNodes("weaponmountoption"))
                    if (xmlWeaponMountOptionList != null)
                    {
                        foreach (XmlNode xmlWeaponMountOptionNode in xmlWeaponMountOptionList)
                        {
                            WeaponMountOption objWeaponMountOption = new WeaponMountOption(_objCharacter);
                            objWeaponMountOption.Load(xmlWeaponMountOptionNode);
                            WeaponMountOptions.Add(objWeaponMountOption);
                        }
                    }
            }
            xmlChildrenNode = objNode["mods"];
            if (xmlChildrenNode != null)
            {
                using (XmlNodeList xmlModList = xmlChildrenNode.SelectNodes("mod"))
                    if (xmlModList != null)
                    {
                        foreach (XmlNode xmlModNode in xmlModList)
                        {
                            VehicleMod objMod = new VehicleMod(_objCharacter)
                            {
                                Parent            = Parent,
                                WeaponMountParent = this
                            };
                            objMod.Load(xmlModNode);
                            _lstMods.Add(objMod);
                        }
                    }
            }
            objNode.TryGetStringFieldQuickly("notes", ref _strNotes);
            objNode.TryGetBoolFieldQuickly("discountedcost", ref _blnDiscountCost);
            objNode.TryGetStringFieldQuickly("extra", ref _strExtra);
        }