コード例 #1
0
ファイル: WeaponMount.cs プロジェクト: shay4brains/chummer5a
        /// <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);
                        }
                    }
            }
        }
コード例 #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);
            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);
        }
コード例 #3
0
ファイル: Vehicle.cs プロジェクト: Rockzo/chummer5a
        /// <summary>
        /// Load the Vehicle from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        public void Load(XmlNode objNode, bool blnCopy = false)
        {
            _guiID = Guid.Parse(objNode["guid"].InnerText);
            _strName = objNode["name"].InnerText;
            _strCategory = objNode["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 (objNode["handling"].InnerText.Contains('/'))
            {
                _intHandling = Convert.ToInt32(objNode["handling"].InnerText.Split('/')[0]);
                _intOffroadHandling = Convert.ToInt32(objNode["handling"].InnerText.Split('/')[1]);
            }
            else
            {
                _intHandling = Convert.ToInt32(objNode["handling"].InnerText);
                if (objNode.InnerXml.Contains("offroadhandling"))
                {
                    _intOffroadHandling = Convert.ToInt32(objNode["offroadhandling"].InnerText);
                }
            }
            _intAccel = Convert.ToInt32(objNode["accel"].InnerText);
            objNode.TryGetField("seats", out _intSeats);
            _intSpeed = Convert.ToInt32(objNode["speed"].InnerText);
            _intPilot = Convert.ToInt32(objNode["pilot"].InnerText);
            _intBody = Convert.ToInt32(objNode["body"].InnerText);
            _intArmor = Convert.ToInt32(objNode["armor"].InnerText);
            _intSensor = Convert.ToInt32(objNode["sensor"].InnerText);
            objNode.TryGetField("devicerating", out _intDeviceRating);
            _strAvail = objNode["avail"].InnerText;
            _strCost = objNode["cost"].InnerText;
            objNode.TryGetField("addslots", out _intAddSlots);
            objNode.TryGetField("modslots", out _intModSlots);
            _strSource = objNode["source"].InnerText;
            objNode.TryGetField("page", out _strPage);
            objNode.TryGetField("matrixcmfilled", out _intMatrixCMFilled);
            objNode.TryGetField("physicalcmfilled", out _intPhysicalCMFilled);
            objNode.TryGetField("vehiclename", out _strVehicleName);
            objNode.TryGetField("homenode", out _blnHomeNode);

            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;
                }
            }

            if (objNode.InnerXml.Contains("<mods>"))
            {
                XmlNodeList nodChildren = objNode.SelectNodes("mods/mod");
                foreach (XmlNode nodChild in nodChildren)
                {
                    VehicleMod objMod = new VehicleMod(_objCharacter);
                    objMod.Load(nodChild, blnCopy);
                    _lstVehicleMods.Add(objMod);
                }
            }

            if (objNode.InnerXml.Contains("<gears>"))
            {
                XmlNodeList nodChildren = objNode.SelectNodes("gears/gear");
                foreach (XmlNode nodChild in nodChildren)
                {
                    switch (nodChild["category"].InnerText)
                    {
                        case "Commlinks":
                        case "Commlink Accessories":
                        case "Cyberdecks":
                        case "Rigger Command Consoles":
                            Commlink objCommlink = new Commlink(_objCharacter);
                            objCommlink.Load(nodChild, blnCopy);
                            _lstGear.Add(objCommlink);
                            break;
                        default:
                            Gear objGear = new Gear(_objCharacter);
                            objGear.Load(nodChild, blnCopy);
                            _lstGear.Add(objGear);
                            break;
                    }
                }
            }

            if (objNode.InnerXml.Contains("<weapons>"))
            {
                XmlNodeList nodChildren = objNode.SelectNodes("weapons/weapon");
                foreach (XmlNode nodChild in nodChildren)
                {
                    Weapon objWeapon = new Weapon(_objCharacter);
                    objWeapon.Load(nodChild, blnCopy);
                    objWeapon.VehicleMounted = true;
                    if (objWeapon.UnderbarrelWeapons.Count > 0)
                    {
                        foreach (Weapon objUnderbarrel in objWeapon.UnderbarrelWeapons)
                            objUnderbarrel.VehicleMounted = true;
                    }
                    _lstWeapons.Add(objWeapon);
                }
            }

            objNode.TryGetField("notes", out _strNotes);
            objNode.TryGetField("dealerconnection", out _blnDealerConnectionDiscount);

            if (objNode["locations"] != null)
            {
                // Locations.
                foreach (XmlNode objXmlLocation in objNode.SelectNodes("locations/location"))
                {
                    _lstLocations.Add(objXmlLocation.InnerText);
                }
            }

            if (blnCopy)
            {
                _guiID = Guid.NewGuid();
                _blnHomeNode = false;
            }
        }
コード例 #4
0
ファイル: frmCreate.cs プロジェクト: argo2445/chummer5a
        private void cmdDeleteVehicle_Click(object sender, EventArgs e)
        {
            // Delete the selected Vehicle.
            try
            {
                if (treVehicles.SelectedNode.Level == 0)
                    return;
            }
            catch
            {
                return;
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            UpdateCharacterInfo();
            RefreshSelectedVehicle();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
コード例 #5
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();
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: frmCreate.cs プロジェクト: argo2445/chummer5a
        private void tsVehicleAddWeaponWeapon_Click(object sender, EventArgs e)
        {
            VehicleMod objMod = new VehicleMod(_objCharacter);

            // Make sure that a Weapon Mount has been selected.
            try
            {
                // Attempt to locate the selected VehicleMod.
                Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                objMod = _objFunctions.FindVehicleMod(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);

                if (!objMod.Name.Contains("Weapon Mount") && !objMod.Name.StartsWith("Mechanical Arm") || objMod.WeaponMountCategories == "")
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotAddWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotAddWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotAddWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotAddWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectWeapon frmPickWeapon = new frmSelectWeapon(_objCharacter);
            frmPickWeapon.LimitToCategories = objMod.WeaponMountCategories;
            frmPickWeapon.ShowDialog();

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

            // Open the Weapons XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("weapons.xml");

            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + frmPickWeapon.SelectedWeapon + "\"]");

            TreeNode objNode = new TreeNode();
            Weapon objWeapon = new Weapon(_objCharacter);
            objWeapon.Create(objXmlWeapon, _objCharacter, objNode, cmsVehicleWeapon, cmsVehicleWeaponAccessory);
            objWeapon.DiscountCost = frmPickWeapon.BlackMarketDiscount;
            objWeapon.VehicleMounted = true;

            objMod.Weapons.Add(objWeapon);

            objNode.ContextMenuStrip = cmsVehicleWeapon;
            treVehicles.SelectedNode.Nodes.Add(objNode);
            treVehicles.SelectedNode.Expand();

            if (frmPickWeapon.AddAgain)
                tsVehicleAddWeaponWeapon_Click(sender, e);

            UpdateCharacterInfo();
        }
コード例 #7
0
ファイル: frmCreate.cs プロジェクト: argo2445/chummer5a
        private void tsVehicleNotes_Click(object sender, EventArgs e)
        {
            Vehicle objVehicle = new Vehicle(_objCharacter);
            VehicleMod objMod = new VehicleMod(_objCharacter);
            bool blnFoundVehicle = false;
            bool blnFoundMod = false;
            try
            {
                foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                {
                    if (objCharacterVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString())
                    {
                        objVehicle = objCharacterVehicle;
                        blnFoundVehicle = true;
                        break;
                    }
                    foreach (VehicleMod objVehicleMod in objCharacterVehicle.Mods)
                    {
                        if (objVehicleMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                        {
                            objMod = objVehicleMod;
                            blnFoundMod = true;
                            break;
                        }
                    }
                }

                if (blnFoundVehicle)
                {
                    frmNotes frmItemNotes = new frmNotes();
                    frmItemNotes.Notes = objVehicle.Notes;
                    string strOldValue = objVehicle.Notes;
                    frmItemNotes.ShowDialog(this);

                    if (frmItemNotes.DialogResult == DialogResult.OK)
                    {
                        objVehicle.Notes = frmItemNotes.Notes;
                        if (objVehicle.Notes != strOldValue)
                        {
                            _blnIsDirty = true;
                            UpdateWindowTitle();
                        }
                    }

                    if (objVehicle.Notes != string.Empty)
                        treVehicles.SelectedNode.ForeColor = Color.SaddleBrown;
                    else
                        treVehicles.SelectedNode.ForeColor = SystemColors.WindowText;
                    treVehicles.SelectedNode.ToolTipText = CommonFunctions.WordWrap(objVehicle.Notes, 100);
                }
                if (blnFoundMod)
                {
                    frmNotes frmItemNotes = new frmNotes();
                    frmItemNotes.Notes = objMod.Notes;
                    string strOldValue = objMod.Notes;
                    frmItemNotes.ShowDialog(this);

                    if (frmItemNotes.DialogResult == DialogResult.OK)
                    {
                        objMod.Notes = frmItemNotes.Notes;
                        if (objMod.Notes != strOldValue)
                        {
                            _blnIsDirty = true;
                            UpdateWindowTitle();
                        }
                    }

                    if (objMod.Notes != string.Empty)
                        treVehicles.SelectedNode.ForeColor = Color.SaddleBrown;
                    else
                    {
                        if (objMod.IncludedInVehicle)
                            treVehicles.SelectedNode.ForeColor = SystemColors.GrayText;
                        else
                            treVehicles.SelectedNode.ForeColor = SystemColors.WindowText;
                    }
                    treVehicles.SelectedNode.ToolTipText = CommonFunctions.WordWrap(objMod.Notes, 100);
                }
            }
            catch
            {
            }
        }
コード例 #8
0
ファイル: frmCreate.cs プロジェクト: argo2445/chummer5a
        /// <summary>
        /// Enable/Disable the Paste Menu and ToolStrip items as appropriate.
        /// </summary>
        private void RefreshPasteStatus()
        {
            bool blnPasteEnabled = false;
            bool blnCopyEnabled = false;

            if (tabCharacterTabs.SelectedTab == tabStreetGear)
            {
                // Lifestyle Tab.
                if (tabStreetGearTabs.SelectedTab == tabLifestyle)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Lifestyle)
                        blnPasteEnabled = true;

                    try
                    {
                        foreach (Lifestyle objLifestyle in _objCharacter.Lifestyles)
                        {
                            if (objLifestyle.InternalId == treLifestyles.SelectedNode.Tag.ToString())
                            {
                                blnCopyEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                }

                // Armor Tab.
                if (tabStreetGearTabs.SelectedTab == tabArmor)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Armor)
                        blnPasteEnabled = true;
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                    {
                        // Gear can only be pasted into Armor, not Armor Mods.
                        try
                        {
                            foreach (Armor objArmor in _objCharacter.Armor)
                            {
                                if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString())
                                {
                                    blnPasteEnabled = true;
                                    break;
                                }
                            }
                        }
                        catch
                        {
                        }
                    }

                    try
                    {
                        foreach (Armor objArmor in _objCharacter.Armor)
                        {
                            if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString())
                            {
                                blnCopyEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        Armor objArmor = new Armor(_objCharacter);
                        Gear objGear = _objFunctions.FindArmorGear(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor, out objArmor);
                        if (objGear != null)
                            blnCopyEnabled = true;
                    }
                    catch
                    {
                    }
                }

                // Weapons Tab.
                if (tabStreetGearTabs.SelectedTab == tabWeapons)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Weapon)
                        blnPasteEnabled = true;
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                    {
                        // Check if the copied Gear can be pasted into the selected Weapon Accessory.
                        Gear objGear = new Gear(_objCharacter);
                        XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear");
                        if (objXmlNode != null)
                        {
                            switch (objXmlNode["category"].InnerText)
                            {
                                case "Commlinks":
                                case "Cyberdecks":
                                case "Rigger Command Consoles":
                                    Commlink objCommlink = new Commlink(_objCharacter);
                                    objCommlink.Load(objXmlNode, true);
                                    objGear = objCommlink;
                                    break;
                                default:
                                    Gear objNewGear = new Gear(_objCharacter);
                                    objNewGear.Load(objXmlNode, true);
                                    objGear = objNewGear;
                                    break;
                            }

                            objGear.Parent = null;

                            // Make sure that a Weapon Accessory is selected and that it allows Gear of the item's Category.
                            WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                            try
                            {
                                foreach (Weapon objCharacterWeapon in _objCharacter.Weapons)
                                {
                                    foreach (WeaponAccessory objWeaponAccessory in objCharacterWeapon.WeaponAccessories)
                                    {
                                        if (objWeaponAccessory.InternalId == treWeapons.SelectedNode.Tag.ToString())
                                        {
                                            objAccessory = objWeaponAccessory;
                                            break;
                                        }
                                    }
                                }
                                if (objAccessory.AllowGear != null)
                                {
                                    foreach (XmlNode objAllowed in objAccessory.AllowGear.SelectNodes("gearcategory"))
                                    {
                                        if (objAllowed.InnerText == objGear.Category)
                                        {
                                            blnPasteEnabled = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }

                    try
                    {
                        foreach (Weapon objWeapon in _objCharacter.Weapons)
                        {
                            if (objWeapon.InternalId == treWeapons.SelectedNode.Tag.ToString())
                            {
                                blnCopyEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        WeaponAccessory objAccessory = new WeaponAccessory(_objCharacter);
                        Gear objGear = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objAccessory);
                        if (objGear != null)
                            blnCopyEnabled = true;
                    }
                    catch
                    {
                    }
                }

                // Gear Tab.
                if (tabStreetGearTabs.SelectedTab == tabGear)
                {
                    if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                        blnPasteEnabled = true;

                    try
                    {
                        Gear objGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);
                        if (objGear != null)
                            blnCopyEnabled = true;
                    }
                    catch
                    {
                    }
                }
            }

            // Vehicles Tab.
            if (tabCharacterTabs.SelectedTab == tabVehicles)
            {
                if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Vehicle)
                    blnPasteEnabled = true;
                if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Gear || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Commlink || GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.OperatingSystem)
                {
                    // Gear can only be pasted into Vehicles and Vehicle Gear.
                    try
                    {
                        foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                        {
                            if (objVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString())
                            {
                                blnPasteEnabled = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        Vehicle objVehicle = new Vehicle(_objCharacter);
                        Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle);
                        if (objGear != null)
                            blnPasteEnabled = true;
                    }
                    catch
                    {
                    }
                }
                if (GlobalOptions.Instance.ClipboardContentType == ClipboardContentType.Weapon)
                {
                    // Weapons can only be pasted into Vehicle Mods that allow them (Weapon Mounts and Mechanical Arms).
                    try
                    {
                        VehicleMod objMod = new VehicleMod(_objCharacter);
                        foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                        {
                            foreach (VehicleMod objVehicleMod in objVehicle.Mods)
                            {
                                if (objVehicleMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    if (objVehicleMod.Name.Contains("Weapon Mount") || objVehicleMod.Name.StartsWith("Mechanical Arm") || objMod.WeaponMountCategories != "")
                                    {
                                        blnPasteEnabled = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }

                try
                {
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        if (objVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString())
                        {
                            blnCopyEnabled = true;
                            break;
                        }
                    }
                }
                catch
                {
                }
                try
                {
                    Vehicle objVehicle = new Vehicle(_objCharacter);
                    Gear objGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle);
                    if (objGear != null)
                        blnCopyEnabled = true;
                }
                catch
                {
                }
                try
                {
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                if (objWeapon.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    blnCopyEnabled = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            mnuEditPaste.Enabled = blnPasteEnabled;
            tsbPaste.Enabled = blnPasteEnabled;
            mnuEditCopy.Enabled = blnCopyEnabled;
            tsbCopy.Enabled = blnCopyEnabled;
        }
コード例 #9
0
ファイル: frmCreate.cs プロジェクト: argo2445/chummer5a
        private void tsVehicleAddMod_Click(object sender, EventArgs e)
        {
            // Make sure a parent items is selected, then open the Select Vehicle Mod window.
            try
            {
                if (treVehicles.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (treVehicles.SelectedNode.Level > 1)
                treVehicles.SelectedNode = treVehicles.SelectedNode.Parent;

            Vehicle objSelectedVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles);

            frmSelectVehicleMod frmPickVehicleMod = new frmSelectVehicleMod(_objCharacter);
            // Set the Vehicle properties for the window.
            frmPickVehicleMod.SelectedVehicle = objSelectedVehicle;

            frmPickVehicleMod.ShowDialog(this);

            // Make sure the dialogue window was not canceled.
            if (frmPickVehicleMod.DialogResult == DialogResult.Cancel)
                return;

            // Open the Vehicles XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("vehicles.xml");

            XmlNode objXmlMod = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + frmPickVehicleMod.SelectedMod + "\"]");

            TreeNode objNode = new TreeNode();
            VehicleMod objMod = new VehicleMod(_objCharacter);
            objMod.Create(objXmlMod, objNode, frmPickVehicleMod.SelectedRating);

            // Make sure that the Armor Rating does not exceed the maximum allowed by the Vehicle.
            if (objMod.Name.StartsWith("Armor"))
            {
                if (objMod.Rating > objSelectedVehicle.MaxArmor)
                {
                    objMod.Rating = objSelectedVehicle.MaxArmor;
                    objNode.Text = objMod.DisplayName;
                }
            }

            objSelectedVehicle.Mods.Add(objMod);

            objNode.ContextMenuStrip = cmsVehicle;
            treVehicles.SelectedNode.Nodes.Add(objNode);
            treVehicles.SelectedNode.Expand();
            RefreshSelectedVehicle();

            // Check for Improved Sensor bonus.
            if (objMod.Bonus != null)
            {
                if (objMod.Bonus["selecttext"] != null)
                {
                    frmSelectText frmPickText = new frmSelectText();
                    frmPickText.Description = LanguageManager.Instance.GetString("String_Improvement_SelectText").Replace("{0}", objMod.DisplayNameShort);
                    frmPickText.ShowDialog(this);
                    objMod.Extra = frmPickText.SelectedValue;
                    objNode.Text = objMod.DisplayName;
                }
                if (objMod.Bonus["improvesensor"] != null)
                {
                    ChangeVehicleSensor(objSelectedVehicle, true);
                }
            }

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickVehicleMod.AddAgain)
                tsVehicleAddMod_Click(sender, e);
        }
コード例 #10
0
ファイル: frmCreate.cs プロジェクト: argo2445/chummer5a
        private void mnuEditPaste_Click(object sender, EventArgs e)
        {
            if (tabCharacterTabs.SelectedTab == tabStreetGear)
            {
                // Lifestyle Tab.
                if (tabStreetGearTabs.SelectedTab == tabLifestyle)
                {
                    // Paste Lifestyle.
                    Lifestyle objLifestyle = new Lifestyle(_objCharacter);
                    XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/lifestyle");
                    if (objXmlNode != null)
                    {
                        objLifestyle.Load(objXmlNode, true);
                        // Reset the number of months back to 1 since 0 isn't valid in Create Mode.
                        objLifestyle.Months = 1;

                        _objCharacter.Lifestyles.Add(objLifestyle);

                        TreeNode objLifestyleNode = new TreeNode();
                        objLifestyleNode.Text = objLifestyle.DisplayName;
                        objLifestyleNode.Tag = objLifestyle.InternalId;
                        if (objLifestyle.StyleType.ToString() != "Standard")
                            objLifestyleNode.ContextMenuStrip = cmsAdvancedLifestyle;
                        else
                            objLifestyleNode.ContextMenuStrip = cmsLifestyleNotes;
                        if (objLifestyle.Notes != string.Empty)
                            objLifestyleNode.ForeColor = Color.SaddleBrown;
                        objLifestyleNode.ToolTipText = CommonFunctions.WordWrap(objLifestyle.Notes, 100);
                        treLifestyles.Nodes[0].Nodes.Add(objLifestyleNode);

                        UpdateCharacterInfo();
                        _blnIsDirty = true;
                        UpdateWindowTitle();
                        return;
                    }
                }

                // Armor Tab.
                if (tabStreetGearTabs.SelectedTab == tabArmor)
                {
                    // Paste Armor.
                    Armor objArmor = new Armor(_objCharacter);
                    XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/armor");
                    if (objXmlNode != null)
                    {
                        objArmor.Load(objXmlNode, true);

                        _objCharacter.Armor.Add(objArmor);

                        _objFunctions.CreateArmorTreeNode(objArmor, treArmor, cmsArmor, cmsArmorMod, cmsArmorGear);

                        UpdateCharacterInfo();
                        _blnIsDirty = true;
                        UpdateWindowTitle();
                        return;
                    }

                    // Paste Gear.
                    Gear objGear = new Gear(_objCharacter);
                    objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear");

                    if (objXmlNode != null)
                    {
                        switch (objXmlNode["category"].InnerText)
                        {
                            case "Commlinks":
                            case "Cyberdecks":
                            case "Rigger Command Consoles":
                                Commlink objCommlink = new Commlink(_objCharacter);
                                objCommlink.Load(objXmlNode, true);
                                objGear = objCommlink;
                                break;
                            default:
                                Gear objNewGear = new Gear(_objCharacter);
                                objNewGear.Load(objXmlNode, true);
                                objGear = objNewGear;
                                break;
                        }

                        foreach (Armor objCharacterArmor in _objCharacter.Armor)
                        {
                            if (objCharacterArmor.InternalId == treArmor.SelectedNode.Tag.ToString())
                            {
                                objCharacterArmor.Gear.Add(objGear);
                                TreeNode objNode = new TreeNode();
                                objNode.Text = objGear.DisplayName;
                                objNode.Tag = objGear.InternalId;
                                objNode.ContextMenuStrip = cmsArmorGear;

                                _objFunctions.BuildGearTree(objGear, objNode, cmsArmorGear);

                                treArmor.SelectedNode.Nodes.Add(objNode);
                                treArmor.SelectedNode.Expand();
                            }
                        }

                        // Add any Weapons that come with the Gear.
                        objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/weapon");
                        if (objXmlNode != null)
                        {
                            Weapon objWeapon = new Weapon(_objCharacter);
                            objWeapon.Load(objXmlNode, true);
                            _objCharacter.Weapons.Add(objWeapon);
                            objGear.WeaponID = objWeapon.InternalId;
                            _objFunctions.CreateWeaponTreeNode(objWeapon, treWeapons.Nodes[0], cmsWeapon, cmsWeaponAccessory, cmsWeaponAccessoryGear);
                        }

                        UpdateCharacterInfo();
                        _blnIsDirty = true;
                        UpdateWindowTitle();
                        return;
                    }
                }

                // Weapons Tab.
                if (tabStreetGearTabs.SelectedTab == tabWeapons)
                {
                    // Paste Gear into a Weapon Accessory.
                    Gear objGear = new Gear(_objCharacter);
                    XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear");
                    if (objXmlNode != null)
                    {
                        switch (objXmlNode["category"].InnerText)
                        {
                            case "Commlinks":
                            case "Cyberdecks":
                            case "Rigger Command Consoles":
                                Commlink objCommlink = new Commlink(_objCharacter);
                                objCommlink.Load(objXmlNode, true);
                                objGear = objCommlink;
                                break;
                            default:
                                Gear objNewGear = new Gear(_objCharacter);
                                objNewGear.Load(objXmlNode, true);
                                objGear = objNewGear;
                                break;
                        }

                        objGear.Parent = null;

                        // Make sure that a Weapon Accessory is selected and that it allows Gear of the item's Category.
                        WeaponAccessory objAccessory = _objFunctions.FindWeaponAccessory(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);
                        bool blnAllowPaste = false;
                        if (objAccessory.AllowGear != null)
                        {
                            foreach (XmlNode objAllowed in objAccessory.AllowGear.SelectNodes("gearcategory"))
                            {
                                if (objAllowed.InnerText == objGear.Category)
                                {
                                    blnAllowPaste = true;
                                    break;
                                }
                            }
                        }
                        if (blnAllowPaste)
                        {
                            objAccessory.Gear.Add(objGear);
                            TreeNode objNode = new TreeNode();
                            objNode.Text = objGear.DisplayName;
                            objNode.Tag = objGear.InternalId;
                            objNode.ContextMenuStrip = cmsWeaponAccessoryGear;

                            _objFunctions.BuildGearTree(objGear, objNode, cmsWeaponAccessoryGear);

                            treWeapons.SelectedNode.Nodes.Add(objNode);
                            treWeapons.SelectedNode.Expand();

                            // Add any Weapons that come with the Gear.
                            objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/weapon");
                            if (objXmlNode != null)
                            {
                                Weapon objGearWeapon = new Weapon(_objCharacter);
                                objGearWeapon.Load(objXmlNode, true);
                                _objCharacter.Weapons.Add(objGearWeapon);
                                objGear.WeaponID = objGearWeapon.InternalId;
                                _objFunctions.CreateWeaponTreeNode(objGearWeapon, treWeapons.Nodes[0], cmsWeapon, cmsWeaponAccessory, cmsWeaponAccessoryGear);
                            }

                            UpdateCharacterInfo();
                            _blnIsDirty = true;
                            UpdateWindowTitle();
                            return;
                        }
                    }

                    // Paste Weapon.
                    Weapon objWeapon = new Weapon(_objCharacter);
                    objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/weapon");
                    if (objXmlNode != null)
                    {
                        objWeapon.Load(objXmlNode, true);
                        objWeapon.VehicleMounted = false;

                        _objCharacter.Weapons.Add(objWeapon);

                        _objFunctions.CreateWeaponTreeNode(objWeapon, treWeapons.Nodes[0], cmsWeapon, cmsWeaponAccessory, cmsWeaponAccessoryGear);

                        UpdateCharacterInfo();
                        _blnIsDirty = true;
                        UpdateWindowTitle();
                        return;
                    }
                }

                // Gear Tab.
                if (tabStreetGearTabs.SelectedTab == tabGear)
                {
                    // Paste Gear.
                    Gear objGear = new Gear(_objCharacter);
                    XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear");
                    if (objXmlNode != null)
                    {
                        switch (objXmlNode["category"].InnerText)
                        {
                            case "Commlinks":
                            case "Cyberdecks":
                            case "Rigger Command Consoles":
                                Commlink objCommlink = new Commlink(_objCharacter);
                                objCommlink.Load(objXmlNode, true);
                                _objCharacter.Gear.Add(objCommlink);
                                objGear = objCommlink;
                                break;
                            default:
                                Gear objNewGear = new Gear(_objCharacter);
                                objNewGear.Load(objXmlNode, true);
                                _objCharacter.Gear.Add(objNewGear);
                                objGear = objNewGear;
                                break;
                        }

                        objGear.Parent = null;

                        TreeNode objNode = new TreeNode();
                        objNode.Text = objGear.DisplayName;
                        objNode.Tag = objGear.InternalId;
                        if (objGear.Notes != string.Empty)
                            objNode.ForeColor = Color.SaddleBrown;
                        objNode.ToolTipText = CommonFunctions.WordWrap(objGear.Notes, 100);

                        _objFunctions.BuildGearTree(objGear, objNode, cmsGear);

                        objNode.ContextMenuStrip = cmsGear;

                        TreeNode objParent = new TreeNode();
                        if (objGear.Location == "")
                            objParent = treGear.Nodes[0];
                        else
                        {
                            foreach (TreeNode objFind in treGear.Nodes)
                            {
                                if (objFind.Text == objGear.Location)
                                {
                                    objParent = objFind;
                                    break;
                                }
                            }
                        }
                        objParent.Nodes.Add(objNode);
                        objParent.Expand();

                        // Add any Weapons that come with the Gear.
                        objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/weapon");
                        if (objXmlNode != null)
                        {
                            Weapon objWeapon = new Weapon(_objCharacter);
                            objWeapon.Load(objXmlNode, true);
                            _objCharacter.Weapons.Add(objWeapon);
                            objGear.WeaponID = objWeapon.InternalId;
                            _objFunctions.CreateWeaponTreeNode(objWeapon, treWeapons.Nodes[0], cmsWeapon, cmsWeaponAccessory, cmsWeaponAccessoryGear);
                        }

                        UpdateCharacterInfo();
                        _blnIsDirty = true;
                        UpdateWindowTitle();
                        return;
                    }
                }
            }

            // Vehicles Tab.
            if (tabCharacterTabs.SelectedTab == tabVehicles)
            {
                // Paste Vehicle.
                Vehicle objVehicle = new Vehicle(_objCharacter);
                XmlNode objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/vehicle");
                if (objXmlNode != null)
                {
                    objVehicle.Load(objXmlNode, true);

                    _objCharacter.Vehicles.Add(objVehicle);

                    _objFunctions.CreateVehicleTreeNode(objVehicle, treVehicles, cmsVehicle, cmsVehicleLocation, cmsVehicleWeapon, cmsVehicleWeaponAccessory, cmsVehicleWeaponAccessoryGear, cmsVehicleGear);

                    UpdateCharacterInfo();
                    _blnIsDirty = true;
                    UpdateWindowTitle();
                    return;
                }

                // Paste Gear.
                Gear objGear = new Gear(_objCharacter);
                objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/gear");

                if (objXmlNode != null)
                {
                    switch (objXmlNode["category"].InnerText)
                    {
                        case "Commlinks":
                        case "Cyberdecks":
                        case "Rigger Command Consoles":
                            Commlink objCommlink = new Commlink(_objCharacter);
                            objCommlink.Load(objXmlNode, true);
                            objGear = objCommlink;
                            break;
                        default:
                            Gear objNewGear = new Gear(_objCharacter);
                            objNewGear.Load(objXmlNode, true);
                            objGear = objNewGear;
                            break;
                    }

                    // Paste the Gear into a Vehicle.
                    foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                    {
                        if (objCharacterVehicle.InternalId == treVehicles.SelectedNode.Tag.ToString())
                        {
                            objCharacterVehicle.Gear.Add(objGear);
                            TreeNode objNode = new TreeNode();
                            objNode.Text = objGear.DisplayName;
                            objNode.Tag = objGear.InternalId;
                            objNode.ContextMenuStrip = cmsVehicleGear;
                            objVehicle = objCharacterVehicle;

                            _objFunctions.BuildGearTree(objGear, objNode, cmsVehicleGear);

                            treVehicles.SelectedNode.Nodes.Add(objNode);
                            treVehicles.SelectedNode.Expand();
                        }
                    }

                    // Paste the Gear into a Vehicle's Gear.
                    Vehicle objTempVehicle = objVehicle;
                    Gear objVehicleGear = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objVehicle);
                    if (objVehicle == null)
                        objVehicle = objTempVehicle;
                    if (objVehicleGear != null)
                    {
                        objVehicleGear.Children.Add(objGear);
                        objGear.Parent = objVehicleGear;
                        TreeNode objNode = new TreeNode();
                        objNode.Text = objGear.DisplayName;
                        objNode.Tag = objGear.InternalId;
                        objNode.ContextMenuStrip = cmsVehicleGear;

                        _objFunctions.BuildGearTree(objGear, objNode, cmsVehicleGear);

                        treVehicles.SelectedNode.Nodes.Add(objNode);
                        treVehicles.SelectedNode.Expand();
                    }

                    UpdateCharacterInfo();
                    _blnIsDirty = true;
                    UpdateWindowTitle();
                    return;
                }

                // Paste Weapon.
                Weapon objWeapon = new Weapon(_objCharacter);
                objXmlNode = GlobalOptions.Instance.Clipboard.SelectSingleNode("/character/weapon");
                if (objXmlNode != null)
                {
                    objWeapon.Load(objXmlNode, true);
                    objWeapon.VehicleMounted = true;

                    try
                    {
                        // Weapons can only be added to Vehicle Mods that support them (Weapon Mounts and Mechanical Arms).
                        VehicleMod objMod = new VehicleMod(_objCharacter);
                        foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
                        {
                            foreach (VehicleMod objVehicleMod in objCharacterVehicle.Mods)
                            {
                                if (objVehicleMod.InternalId == treVehicles.SelectedNode.Tag.ToString())
                                {
                                    if (objVehicleMod.Name.StartsWith("Weapon Mount") || objVehicleMod.Name.StartsWith("Heavy Weapon Mount") || objVehicleMod.Name.StartsWith("Mechanical Arm") || objVehicleMod.WeaponMountCategories != "")
                                    {
                                        objVehicleMod.Weapons.Add(objWeapon);

                                        _objFunctions.CreateWeaponTreeNode(objWeapon, treVehicles.SelectedNode, cmsVehicleWeapon, cmsVehicleWeaponAccessory, null);

                                        UpdateCharacterInfo();
                                        _blnIsDirty = true;
                                        UpdateWindowTitle();
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
コード例 #11
0
ファイル: frmCreate.cs プロジェクト: argo2445/chummer5a
        /// <summary>
        /// Add a PACKS Kit to the character.
        /// </summary>
        public void AddPACKSKit()
        {
            frmSelectPACKSKit frmPickPACKSKit = new frmSelectPACKSKit(_objCharacter);
            frmPickPACKSKit.ShowDialog(this);

            bool blnCreateChildren = true;

            // If the form was canceled, don't do anything.
            if (frmPickPACKSKit.DialogResult == DialogResult.Cancel)
                return;

            XmlDocument objXmlDocument = XmlManager.Instance.Load("packs.xml");

            // Do not create child items for Gear if the chosen Kit is in the Custom category since these items will contain the exact plugins desired.
            //if (frmPickPACKSKit.SelectedCategory == "Custom")
            //blnCreateChildren = false;

            XmlNode objXmlKit = objXmlDocument.SelectSingleNode("/chummer/packs/pack[name = \"" + frmPickPACKSKit.SelectedKit + "\" and category = \"" + frmPickPACKSKit.SelectedCategory + "\"]");
            // Update Qualities.
            if (objXmlKit["qualities"] != null)
            {
                XmlDocument objXmlQualityDocument = XmlManager.Instance.Load("qualities.xml");

                // Positive Qualities.
                foreach (XmlNode objXmlQuality in objXmlKit.SelectNodes("qualities/positive/quality"))
                {
                    XmlNode objXmlQualityNode = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQuality.InnerText + "\"]");

                    TreeNode objNode = new TreeNode();
                    List<Weapon> objWeapons = new List<Weapon>();
                    List<TreeNode> objWeaponNodes = new List<TreeNode>();
                    Quality objQuality = new Quality(_objCharacter);
                    string strForceValue = "";

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

                    objQuality.Create(objXmlQualityNode, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes, strForceValue);
                    _objCharacter.Qualities.Add(objQuality);

                    treQualities.Nodes[0].Nodes.Add(objNode);
                    treQualities.Nodes[0].Expand();

                    // Add any created Weapons to the character.
                    foreach (Weapon objWeapon in objWeapons)
                        _objCharacter.Weapons.Add(objWeapon);

                    // Create the Weapon Node if one exists.
                    foreach (TreeNode objWeaponNode in objWeaponNodes)
                    {
                        objWeaponNode.ContextMenuStrip = cmsWeapon;
                        treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                        treWeapons.Nodes[0].Expand();
                    }
                }

                // Negative Qualities.
                foreach (XmlNode objXmlQuality in objXmlKit.SelectNodes("qualities/negative/quality"))
                {
                    XmlNode objXmlQualityNode = objXmlQualityDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + objXmlQuality.InnerText + "\"]");

                    TreeNode objNode = new TreeNode();
                    List<Weapon> objWeapons = new List<Weapon>();
                    List<TreeNode> objWeaponNodes = new List<TreeNode>();
                    Quality objQuality = new Quality(_objCharacter);
                    string strForceValue = "";

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

                    objQuality.Create(objXmlQualityNode, _objCharacter, QualitySource.Selected, objNode, objWeapons, objWeaponNodes, strForceValue);
                    _objCharacter.Qualities.Add(objQuality);

                    treQualities.Nodes[1].Nodes.Add(objNode);
                    treQualities.Nodes[1].Expand();

                    // Add any created Weapons to the character.
                    foreach (Weapon objWeapon in objWeapons)
                        _objCharacter.Weapons.Add(objWeapon);

                    // Create the Weapon Node if one exists.
                    foreach (TreeNode objWeaponNode in objWeaponNodes)
                    {
                        objWeaponNode.ContextMenuStrip = cmsWeapon;
                        treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                        treWeapons.Nodes[0].Expand();
                    }
                }
            }

            // Update Attributes.
            if (objXmlKit["attributes"] != null)
            {
                // Reset all Attributes back to 1 so we don't go over any BP limits.
                nudBOD.Value = nudBOD.Minimum;
                nudAGI.Value = nudAGI.Minimum;
                nudREA.Value = nudREA.Minimum;
                nudSTR.Value = nudSTR.Minimum;
                nudCHA.Value = nudCHA.Minimum;
                nudINT.Value = nudINT.Minimum;
                nudLOG.Value = nudLOG.Minimum;
                nudWIL.Value = nudWIL.Minimum;
                nudEDG.Value = nudEDG.Minimum;
                nudMAG.Value = nudMAG.Minimum;
                nudRES.Value = nudRES.Minimum;
                foreach (XmlNode objXmlAttribute in objXmlKit["attributes"])
                {
                    // The CharacterAttribute is calculated as given value - (6 - Metatype Maximum) so that each Metatype has the values from the file adjusted correctly.
                    switch (objXmlAttribute.Name)
                    {
                        case "bod":
                            nudBOD.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.BOD.MetatypeMaximum);
                            break;
                        case "agi":
                            nudAGI.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.AGI.MetatypeMaximum);
                            break;
                        case "rea":
                            nudREA.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.REA.MetatypeMaximum);
                            break;
                        case "str":
                            nudSTR.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.STR.MetatypeMaximum);
                            break;
                        case "cha":
                            nudCHA.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.CHA.MetatypeMaximum);
                            break;
                        case "int":
                            nudINT.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.INT.MetatypeMaximum);
                            break;
                        case "log":
                            nudLOG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.LOG.MetatypeMaximum);
                            break;
                        case "wil":
                            nudWIL.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.WIL.MetatypeMaximum);
                            break;
                        case "mag":
                            nudMAG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.MAG.MetatypeMaximum);
                            break;
                        case "res":
                            nudRES.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.RES.MetatypeMaximum);
                            break;
                        default:
                            nudEDG.Value = Convert.ToInt32(objXmlAttribute.InnerText) - (6 - _objCharacter.EDG.MetatypeMaximum);
                            break;
                    }
                }
            }

               //TODO: PACKS SKILLS?

            // Select a Martial Art.
            if (objXmlKit["selectmartialart"] != null)
            {
                string strForcedValue = "";
                int intRating = 1;
                if (objXmlKit["selectmartialart"].Attributes["select"] != null)
                    strForcedValue = objXmlKit["selectmartialart"].Attributes["select"].InnerText;
                if (objXmlKit["selectmartialart"].Attributes["rating"] != null)
                    intRating = Convert.ToInt32(objXmlKit["selectmartialart"].Attributes["rating"].InnerText);

                frmSelectMartialArt frmPickMartialArt = new frmSelectMartialArt(_objCharacter);
                frmPickMartialArt.ForcedValue = strForcedValue;
                frmPickMartialArt.ShowDialog(this);

                if (frmPickMartialArt.DialogResult != DialogResult.Cancel)
                {
                    // Open the Martial Arts XML file and locate the selected piece.
                    XmlDocument objXmlMartialArtDocument = XmlManager.Instance.Load("martialarts.xml");

                    XmlNode objXmlArt = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + frmPickMartialArt.SelectedMartialArt + "\"]");

                    TreeNode objNode = new TreeNode();
                    MartialArt objMartialArt = new MartialArt(_objCharacter);
                    objMartialArt.Create(objXmlArt, objNode, _objCharacter);
                    objMartialArt.Rating = intRating;
                    _objCharacter.MartialArts.Add(objMartialArt);

                    objNode.ContextMenuStrip = cmsMartialArts;

                    treMartialArts.Nodes[0].Nodes.Add(objNode);
                    treMartialArts.Nodes[0].Expand();

                    treMartialArts.SelectedNode = objNode;
                }
            }

            // Update Martial Arts.
            if (objXmlKit["martialarts"] != null)
            {
                // Open the Martial Arts XML file and locate the selected art.
                XmlDocument objXmlMartialArtDocument = XmlManager.Instance.Load("martialarts.xml");

                foreach (XmlNode objXmlArt in objXmlKit.SelectNodes("martialarts/martialart"))
                {
                    TreeNode objNode = new TreeNode();
                    MartialArt objArt = new MartialArt(_objCharacter);
                    XmlNode objXmlArtNode = objXmlMartialArtDocument.SelectSingleNode("/chummer/martialarts/martialart[name = \"" + objXmlArt["name"].InnerText + "\"]");
                    objArt.Create(objXmlArtNode, objNode, _objCharacter);
                    objArt.Rating = Convert.ToInt32(objXmlArt["rating"].InnerText);
                    _objCharacter.MartialArts.Add(objArt);

                    // Check for Advantages.
                    foreach (XmlNode objXmlAdvantage in objXmlArt.SelectNodes("techniques/technique"))
                    {
                        TreeNode objChildNode = new TreeNode();
                        MartialArtAdvantage objAdvantage = new MartialArtAdvantage(_objCharacter);
                        XmlNode objXmlAdvantageNode = objXmlMartialArtDocument.SelectSingleNode("/chummer/techniques/technique[name = \"" + objXmlAdvantage["name"].InnerText + "\"]");
                        objAdvantage.Create(objXmlAdvantageNode, _objCharacter, objChildNode);
                        objArt.Advantages.Add(objAdvantage);

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

                    treMartialArts.Nodes[0].Nodes.Add(objNode);
                    treMartialArts.Nodes[0].Expand();
                }
            }

            // Update Adept Powers.
            if (objXmlKit["powers"] != null)
            {
                // Open the Powers XML file and locate the selected power.
                XmlDocument objXmlPowerDocument = XmlManager.Instance.Load("powers.xml");

                foreach (XmlNode objXmlPower in objXmlKit.SelectNodes("powers/power"))
                {
                    XmlNode objXmlPowerNode = objXmlPowerDocument.SelectSingleNode("/chummer/powers/power[name = \"" + objXmlPower["name"].InnerText + "\"]");

                    int i = panPowers.Controls.Count;

                    Power objPower = new Power(_objCharacter);
                    _objCharacter.Powers.Add(objPower);

                    PowerControl objPowerControl = new PowerControl();
                    objPowerControl.PowerObject = objPower;

                    // Attach an EventHandler for the PowerRatingChanged Event.
                    objPowerControl.PowerRatingChanged += objPower_PowerRatingChanged;
                    objPowerControl.DeletePower += objPower_DeletePower;

                    objPowerControl.PowerName = objXmlPowerNode["name"].InnerText;
                    objPowerControl.PointsPerLevel = Convert.ToDecimal(objXmlPowerNode["points"].InnerText, GlobalOptions.Instance.CultureInfo);
                    objPowerControl.AdeptWayDiscount = Convert.ToDecimal(objXmlPowerNode["adeptway"].InnerText, GlobalOptions.Instance.CultureInfo);
                    if (objXmlPowerNode["levels"].InnerText == "no")
                    {
                        objPowerControl.LevelEnabled = false;
                    }
                    else
                    {
                        objPowerControl.LevelEnabled = true;
                        if (objXmlPowerNode["levels"].InnerText != "yes")
                            objPower.MaxLevels = Convert.ToInt32(objXmlPowerNode["levels"].InnerText);
                    }

                    objPower.Source = objXmlPowerNode["source"].InnerText;
                    objPower.Page = objXmlPowerNode["page"].InnerText;
                    if (objXmlPowerNode["doublecost"] != null)
                        objPower.DoubleCost = false;

                    if (objXmlPowerNode.InnerXml.Contains("bonus"))
                    {
                        objPower.Bonus = objXmlPowerNode["bonus"];

                        if (objXmlPower["name"].Attributes["select"] != null)
                            _objImprovementManager.ForcedValue = objXmlPower["name"].Attributes["select"].InnerText;

                        _objImprovementManager.CreateImprovements(Improvement.ImprovementSource.Power, objPower.InternalId, objPower.Bonus, false, Convert.ToInt32(objPower.Rating), objPower.DisplayNameShort);
                        objPowerControl.Extra = _objImprovementManager.SelectedValue;
                    }

                    objPowerControl.Top = i * objPowerControl.Height;
                    panPowers.Controls.Add(objPowerControl);

                    // Set the Rating of the Power if applicable.
                    if (objXmlPower["rating"] != null)
                        objPowerControl.PowerLevel = Convert.ToInt32(objXmlPower["rating"].InnerText);
                }
            }

            // Update Complex Forms.
            if (objXmlKit["programs"] != null)
            {
                // Open the Programs XML file and locate the selected program.
                XmlDocument objXmlProgramDocument = XmlManager.Instance.Load("complexforms.xml");

                foreach (XmlNode objXmlProgram in objXmlKit.SelectNodes("complexforms/complexform"))
                {
                    XmlNode objXmlProgramNode = objXmlProgramDocument.SelectSingleNode("/chummer/complexforms/complexform[name = \"" + objXmlProgram["name"].InnerText + "\"]");

                    string strForceValue = "";
                    if (objXmlProgram.Attributes["select"] != null)
                        strForceValue = objXmlProgram.Attributes["select"].InnerText;

                    TreeNode objNode = new TreeNode();
                    ComplexForm objProgram = new ComplexForm(_objCharacter);
                    objProgram.Create(objXmlProgramNode, _objCharacter, objNode, strForceValue);

                    treComplexForms.Nodes[0].Nodes.Add(objNode);
                    treComplexForms.Nodes[0].Expand();

                    _objCharacter.ComplexForms.Add(objProgram);

                    treComplexForms.SortCustom();
                }
            }

            // Update Spells.
            if (objXmlKit["spells"] != null)
            {
                XmlDocument objXmlSpellDocument = XmlManager.Instance.Load("spells.xml");

                foreach (XmlNode objXmlSpell in objXmlKit.SelectNodes("spells/spell"))
                {
                    // Make sure the Spell has not already been added to the character.
                    bool blnFound = false;
                    foreach (TreeNode nodSpell in treSpells.Nodes[0].Nodes)
                    {
                        if (nodSpell.Text == objXmlSpell.InnerText)
                        {
                            blnFound = true;
                            break;
                        }
                    }

                    // The Spell is not in the list, so add it.
                    if (!blnFound)
                    {
                        string strForceValue = "";
                        if (objXmlSpell.Attributes["select"] != null)
                            strForceValue = objXmlSpell.Attributes["select"].InnerText;

                        XmlNode objXmlSpellNode = objXmlSpellDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + objXmlSpell.InnerText + "\"]");

                        Spell objSpell = new Spell(_objCharacter);
                        TreeNode objNode = new TreeNode();
                        objSpell.Create(objXmlSpellNode, _objCharacter, objNode, strForceValue);
                        objNode.ContextMenuStrip = cmsSpell;
                        _objCharacter.Spells.Add(objSpell);

                        switch (objSpell.Category)
                        {
                            case "Combat":
                                treSpells.Nodes[0].Nodes.Add(objNode);
                                treSpells.Nodes[0].Expand();
                                break;
                            case "Detection":
                                treSpells.Nodes[1].Nodes.Add(objNode);
                                treSpells.Nodes[1].Expand();
                                break;
                            case "Health":
                                treSpells.Nodes[2].Nodes.Add(objNode);
                                treSpells.Nodes[2].Expand();
                                break;
                            case "Illusion":
                                treSpells.Nodes[3].Nodes.Add(objNode);
                                treSpells.Nodes[3].Expand();
                                break;
                            case "Manipulation":
                                treSpells.Nodes[4].Nodes.Add(objNode);
                                treSpells.Nodes[4].Expand();
                                break;
                            case "Rituals":
                                int intNode = 5;
                                if (_objCharacter.AdeptEnabled && !_objCharacter.MagicianEnabled)
                                    intNode = 0;
                                treSpells.Nodes[intNode].Nodes.Add(objNode);
                                treSpells.Nodes[intNode].Expand();
                                break;
                        }

                        treSpells.SortCustom();
                    }
                }
            }

            // Update Spirits.
            if (objXmlKit["spirits"] != null)
            {
                foreach (XmlNode objXmlSpirit in objXmlKit.SelectNodes("spirits/spirit"))
                {
                    int i = panSpirits.Controls.Count;

                    Spirit objSpirit = new Spirit(_objCharacter);
                    _objCharacter.Spirits.Add(objSpirit);

                    SpiritControl objSpiritControl = new SpiritControl();
                    objSpiritControl.SpiritObject = objSpirit;
                    objSpiritControl.EntityType = SpiritType.Spirit;

                    // Attach an EventHandler for the ServicesOwedChanged Event.
                    objSpiritControl.ServicesOwedChanged += objSpirit_ServicesOwedChanged;
                    objSpiritControl.ForceChanged += objSpirit_ForceChanged;
                    objSpiritControl.BoundChanged += objSpirit_BoundChanged;
                    objSpiritControl.DeleteSpirit += objSpirit_DeleteSpirit;

                    objSpiritControl.Name = objXmlSpirit["name"].InnerText;
                    objSpiritControl.Force = Convert.ToInt32(objXmlSpirit["force"].InnerText);
                    objSpiritControl.ServicesOwed = Convert.ToInt32(objXmlSpirit["services"].InnerText);

                    objSpiritControl.Top = i * objSpiritControl.Height;
                    panSpirits.Controls.Add(objSpiritControl);
                }
            }

            // Update Lifestyles.
            if (objXmlKit["lifestyles"] != null)
            {
                XmlDocument objXmlLifestyleDocument = XmlManager.Instance.Load("lifestyles.xml");

                foreach (XmlNode objXmlLifestyle in objXmlKit.SelectNodes("lifestyles/lifestyle"))
                {
                    string strName = objXmlLifestyle["name"].InnerText;
                    int intMonths = Convert.ToInt32(objXmlLifestyle["months"].InnerText);

                    // Create the Lifestyle.
                    TreeNode objNode = new TreeNode();
                    Lifestyle objLifestyle = new Lifestyle(_objCharacter);

                    XmlNode objXmlLifestyleNode = objXmlLifestyleDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[name = \"" + strName + "\"]");
                    if (objXmlLifestyleNode != null)
                    {
                        // This is a standard Lifestyle, so just use the Create method.
                        objLifestyle.Create(objXmlLifestyleNode, objNode);
                        objLifestyle.Months = intMonths;
                    }
                    else
                    {
                        // This is an Advanced Lifestyle, so build it manually.
                        objLifestyle.Name = strName;
                        objLifestyle.Months = intMonths;
                        objLifestyle.Cost = Convert.ToInt32(objXmlLifestyle["cost"].InnerText);
                        objLifestyle.Dice = Convert.ToInt32(objXmlLifestyle["dice"].InnerText);
                        objLifestyle.Multiplier = Convert.ToInt32(objXmlLifestyle["multiplier"].InnerText);
                        objLifestyle.BaseLifestyle = objXmlLifestyle["baselifestyle"].InnerText;
                        objLifestyle.Source = "SR5";
                        objLifestyle.Page = "373";
                        objLifestyle.Comforts = Convert.ToInt32(objXmlLifestyle["comforts"].InnerText);
                        objLifestyle.ComfortsEntertainment = Convert.ToInt32(objXmlLifestyle["comfortsentertainment"].InnerText);
                        objLifestyle.Security = Convert.ToInt32(objXmlLifestyle["security"].InnerText);
                        objLifestyle.SecurityEntertainment = Convert.ToInt32(objXmlLifestyle["securityentertainment"].InnerText);
                        objLifestyle.Area = Convert.ToInt32(objXmlLifestyle["area"].InnerText);
                        objLifestyle.AreaEntertainment = Convert.ToInt32(objXmlLifestyle["areaentertainment"].InnerText);

                        foreach (LifestyleQuality objXmlQuality in objXmlLifestyle.SelectNodes("lifestylequalities/lifestylequality"))
                            objLifestyle.LifestyleQualities.Add(objXmlQuality);

                        objNode.Text = strName;
                    }

                    // Add the Lifestyle to the character and Lifestyle Tree.
                    if (objLifestyle.BaseLifestyle != "")
                        objNode.ContextMenuStrip = cmsAdvancedLifestyle;
                    else
                        objNode.ContextMenuStrip = cmsLifestyleNotes;
                    _objCharacter.Lifestyles.Add(objLifestyle);
                    treLifestyles.Nodes[0].Nodes.Add(objNode);
                    treLifestyles.Nodes[0].Expand();
                }
            }

            // Update NuyenBP.
            if (objXmlKit["nuyenbp"] != null)
            {
                int intAmount = Convert.ToInt32(objXmlKit["nuyenbp"].InnerText);
                //if (_objCharacter.BuildMethod == CharacterBuildMethod.Karma)
                //intAmount *= 2;

                // Make sure we don't go over the field's maximum which would throw an Exception.
                if (nudNuyen.Value + intAmount > nudNuyen.Maximum)
                    nudNuyen.Value = nudNuyen.Maximum;
                else
                    nudNuyen.Value += intAmount;
            }

            // Update Armor.
            if (objXmlKit["armors"] != null)
            {
                XmlDocument objXmlArmorDocument = XmlManager.Instance.Load("armor.xml");

                foreach (XmlNode objXmlArmor in objXmlKit.SelectNodes("armors/armor"))
                {
                    XmlNode objXmlArmorNode = objXmlArmorDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objXmlArmor["name"].InnerText + "\"]");

                    Armor objArmor = new Armor(_objCharacter);
                    TreeNode objNode = new TreeNode();
                    int intArmorRating = 0;
                    if (objXmlArmor["rating"] != null)
                    {
                        intArmorRating = Convert.ToInt32(objXmlArmor["rating"].InnerText);
                    }
                    objArmor.Create(objXmlArmorNode, objNode, cmsArmorMod, intArmorRating, false, blnCreateChildren);
                    _objCharacter.Armor.Add(objArmor);

                    // Look for Armor Mods.
                    if (objXmlArmor["mods"] != null)
                    {
                        foreach (XmlNode objXmlMod in objXmlArmor.SelectNodes("mods/mod"))
                        {
                            List<Weapon> lstWeapons = new List<Weapon>();
                            List<TreeNode> lstWeaponNodes = new List<TreeNode>();
                            XmlNode objXmlModNode = objXmlArmorDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]");
                            ArmorMod objMod = new ArmorMod(_objCharacter);
                            TreeNode objModNode = new TreeNode();
                            int intRating = 0;
                            if (objXmlMod["rating"] != null)
                                intRating = Convert.ToInt32(objXmlMod["rating"].InnerText);
                            objMod.Create(objXmlModNode, objModNode, intRating, lstWeapons, lstWeaponNodes);
                            objModNode.ContextMenuStrip = cmsArmorMod;
                            objMod.Parent = objArmor;

                            objArmor.ArmorMods.Add(objMod);

                            objNode.Nodes.Add(objModNode);
                            objNode.Expand();

                            // Add any Weapons created by the Mod.
                            foreach (Weapon objWeapon in lstWeapons)
                                _objCharacter.Weapons.Add(objWeapon);

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

                    XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");
                    foreach (XmlNode objXmlGear in objXmlArmor.SelectNodes("gears/gear"))
                        AddPACKSGear(objXmlGearDocument, objXmlGear, objNode, objArmor, cmsArmorGear, blnCreateChildren);

                    objNode.ContextMenuStrip = cmsArmor;
                    treArmor.Nodes[0].Nodes.Add(objNode);
                    treArmor.Nodes[0].Expand();
                }
            }

            // Update Weapons.
            if (objXmlKit["weapons"] != null)
            {
                XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml");

                pgbProgress.Visible = true;
                pgbProgress.Value = 0;
                pgbProgress.Maximum = objXmlKit.SelectNodes("weapons/weapon").Count;
                int i = 0;
                foreach (XmlNode objXmlWeapon in objXmlKit.SelectNodes("weapons/weapon"))
                {
                    i++;
                    pgbProgress.Value = i;
                    Application.DoEvents();

                    XmlNode objXmlWeaponNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["name"].InnerText + "\"]");

                    Weapon objWeapon = new Weapon(_objCharacter);
                    TreeNode objNode = new TreeNode();
                    objWeapon.Create(objXmlWeaponNode, _objCharacter, objNode, cmsWeapon, cmsWeaponAccessory, blnCreateChildren);
                    _objCharacter.Weapons.Add(objWeapon);

                    // Look for Weapon Accessories.
                    if (objXmlWeapon["accessories"] != null)
                    {
                        foreach (XmlNode objXmlAccessory in objXmlWeapon.SelectNodes("accessories/accessory"))
                        {
                            XmlNode objXmlAccessoryNode = objXmlWeaponDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + objXmlAccessory["name"].InnerText + "\"]");
                            WeaponAccessory objMod = new WeaponAccessory(_objCharacter);
                            TreeNode objModNode = new TreeNode();
                            string strMount = "";
                            int intRating = 0;
                            if (objXmlAccessory["mount"] != null)
                                strMount = objXmlAccessory["mount"].InnerText;
                            objMod.Create(objXmlAccessoryNode, objModNode, strMount, intRating);
                            objModNode.ContextMenuStrip = cmsWeaponAccessory;
                            objMod.Parent = objWeapon;

                            objWeapon.WeaponAccessories.Add(objMod);

                            XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");
                            foreach (XmlNode objXmlGear in objXmlAccessory.SelectNodes("gears/gear"))
                                AddPACKSGear(objXmlGearDocument, objXmlGear, objModNode, objMod, cmsWeaponAccessoryGear, blnCreateChildren);

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

                    // Look for an Underbarrel Weapon.
                    if (objXmlWeapon["underbarrel"] != null)
                    {
                        XmlNode objXmlUnderbarrelNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["underbarrel"].InnerText + "\"]");

                        Weapon objUnderbarrelWeapon = new Weapon(_objCharacter);
                        TreeNode objUnderbarrelNode = new TreeNode();
                        objUnderbarrelWeapon.Create(objXmlUnderbarrelNode, _objCharacter, objUnderbarrelNode, cmsWeapon, cmsWeaponAccessory, blnCreateChildren);
                        objWeapon.UnderbarrelWeapons.Add(objUnderbarrelWeapon);
                        objNode.Nodes.Add(objUnderbarrelNode);
                        objNode.Expand();
                    }

                    objNode.ContextMenuStrip = cmsWeapon;
                    treWeapons.Nodes[0].Nodes.Add(objNode);
                    treWeapons.Nodes[0].Expand();

                    Application.DoEvents();
                }
            }

            // Update Cyberware.
            if (objXmlKit["cyberwares"] != null)
            {
                XmlDocument objXmlCyberwareDocument = XmlManager.Instance.Load("cyberware.xml");
                XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");

                pgbProgress.Visible = true;
                pgbProgress.Value = 0;
                pgbProgress.Maximum = objXmlKit.SelectNodes("cyberwares/cyberware").Count;
                int i = 0;
                foreach (XmlNode objXmlCyberware in objXmlKit.SelectNodes("cyberwares/cyberware"))
                {
                    i++;
                    pgbProgress.Value = i;
                    Application.DoEvents();

                    List<Weapon> objWeapons = new List<Weapon>();
                    List<TreeNode> objWeaponNodes = new List<TreeNode>();
                    TreeNode objNode = new TreeNode();
                    Cyberware objCyberware = new Cyberware(_objCharacter);
                    Grade objGrade = objCyberware.ConvertToCyberwareGrade(objXmlCyberware["grade"].InnerText, Improvement.ImprovementSource.Cyberware);

                    int intRating = 0;
                    if (objXmlCyberware["rating"] != null)
                        intRating = Convert.ToInt32(objXmlCyberware["rating"].InnerText);

                    XmlNode objXmlCyberwareNode = objXmlCyberwareDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + objXmlCyberware["name"].InnerText + "\"]");
                    objCyberware.Create(objXmlCyberwareNode, _objCharacter, objGrade, Improvement.ImprovementSource.Cyberware, intRating, objNode, objWeapons, objWeaponNodes, true, blnCreateChildren);
                    _objCharacter.Cyberware.Add(objCyberware);

                    // Add any children.
                    if (objXmlCyberware["cyberwares"] != null)
                    {
                        foreach (XmlNode objXmlChild in objXmlCyberware.SelectNodes("cyberwares/cyberware"))
                        {
                            TreeNode objChildNode = new TreeNode();
                            Cyberware objChildCyberware = new Cyberware(_objCharacter);

                            int intChildRating = 0;
                            if (objXmlChild["rating"] != null)
                                intChildRating = Convert.ToInt32(objXmlChild["rating"].InnerText);

                            XmlNode objXmlChildNode = objXmlCyberwareDocument.SelectSingleNode("/chummer/cyberwares/cyberware[name = \"" + objXmlChild["name"].InnerText + "\"]");
                            objChildCyberware.Create(objXmlChildNode, _objCharacter, objGrade, Improvement.ImprovementSource.Cyberware, intChildRating, objChildNode, objWeapons, objWeaponNodes, true, blnCreateChildren);
                            objCyberware.Children.Add(objChildCyberware);
                            objChildNode.ContextMenuStrip = cmsCyberware;

                            foreach (XmlNode objXmlGear in objXmlChild.SelectNodes("gears/gear"))
                                AddPACKSGear(objXmlGearDocument, objXmlGear, objChildNode, objChildCyberware, cmsCyberwareGear, blnCreateChildren);

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

                    foreach (XmlNode objXmlGear in objXmlCyberware.SelectNodes("gears/gear"))
                        AddPACKSGear(objXmlGearDocument, objXmlGear, objNode, objCyberware, cmsCyberwareGear, blnCreateChildren);

                    objNode.ContextMenuStrip = cmsCyberware;
                    treCyberware.Nodes[0].Nodes.Add(objNode);
                    treCyberware.Nodes[0].Expand();

                    // Add any Weapons created by the Gear.
                    foreach (Weapon objWeapon in objWeapons)
                        _objCharacter.Weapons.Add(objWeapon);

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

                    Application.DoEvents();
                }

                treCyberware.SortCustom();
            }

            // Update Bioware.
            if (objXmlKit["biowares"] != null)
            {
                XmlDocument objXmlBiowareDocument = XmlManager.Instance.Load("bioware.xml");

                pgbProgress.Visible = true;
                pgbProgress.Value = 0;
                pgbProgress.Maximum = objXmlKit.SelectNodes("biowares/bioware").Count;
                int i = 0;

                foreach (XmlNode objXmlBioware in objXmlKit.SelectNodes("biowares/bioware"))
                {
                    i++;
                    pgbProgress.Value = i;
                    Application.DoEvents();

                    List<Weapon> objWeapons = new List<Weapon>();
                    List<TreeNode> objWeaponNodes = new List<TreeNode>();
                    TreeNode objNode = new TreeNode();
                    Cyberware objCyberware = new Cyberware(_objCharacter);
                    Grade objGrade = objCyberware.ConvertToCyberwareGrade(objXmlBioware["grade"].InnerText, Improvement.ImprovementSource.Bioware);

                    int intRating = 0;
                    if (objXmlBioware["rating"] != null)
                        intRating = Convert.ToInt32(objXmlBioware["rating"].InnerText);

                    XmlNode objXmlBiowareNode = objXmlBiowareDocument.SelectSingleNode("/chummer/biowares/bioware[name = \"" + objXmlBioware["name"].InnerText + "\"]");
                    objCyberware.Create(objXmlBiowareNode, _objCharacter, objGrade, Improvement.ImprovementSource.Bioware, intRating, objNode, objWeapons, objWeaponNodes, true, blnCreateChildren);
                    _objCharacter.Cyberware.Add(objCyberware);

                    objNode.ContextMenuStrip = cmsBioware;
                    treCyberware.Nodes[1].Nodes.Add(objNode);
                    treCyberware.Nodes[1].Expand();

                    // Add any Weapons created by the Gear.
                    foreach (Weapon objWeapon in objWeapons)
                        _objCharacter.Weapons.Add(objWeapon);

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

                    Application.DoEvents();
                }

                treCyberware.SortCustom();
            }

            // Update Gear.
            if (objXmlKit["gears"] != null)
            {
                XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");

                pgbProgress.Visible = true;
                pgbProgress.Value = 0;
                pgbProgress.Maximum = objXmlKit.SelectNodes("gears/gear").Count;
                int i = 0;

                foreach (XmlNode objXmlGear in objXmlKit.SelectNodes("gears/gear"))
                {
                    i++;
                    pgbProgress.Value = i;
                    Application.DoEvents();

                    AddPACKSGear(objXmlGearDocument, objXmlGear, treGear.Nodes[0], _objCharacter, cmsGear, blnCreateChildren);

                    Application.DoEvents();
                }
            }

            // Update Vehicles.
            if (objXmlKit["vehicles"] != null)
            {
                XmlDocument objXmlVehicleDocument = XmlManager.Instance.Load("vehicles.xml");

                pgbProgress.Visible = true;
                pgbProgress.Value = 0;
                pgbProgress.Maximum = objXmlKit.SelectNodes("vehicles/vehicle").Count;
                int i = 0;

                foreach (XmlNode objXmlVehicle in objXmlKit.SelectNodes("vehicles/vehicle"))
                {
                    i++;
                    pgbProgress.Value = i;
                    Application.DoEvents();

                    Gear objDefaultSensor = new Gear(_objCharacter);

                    TreeNode objNode = new TreeNode();
                    Vehicle objVehicle = new Vehicle(_objCharacter);

                    XmlNode objXmlVehicleNode = objXmlVehicleDocument.SelectSingleNode("/chummer/vehicles/vehicle[name = \"" + objXmlVehicle["name"].InnerText + "\"]");
                    objVehicle.Create(objXmlVehicleNode, objNode, cmsVehicle, cmsVehicleGear, cmsVehicleWeapon, cmsVehicleWeaponAccessory, blnCreateChildren);
                    _objCharacter.Vehicles.Add(objVehicle);

                    // Grab the default Sensor that comes with the Vehicle.
                    foreach (Gear objSensorGear in objVehicle.Gear)
                    {
                        if (objSensorGear.Category == "Sensors" && objSensorGear.Cost == "0" && objSensorGear.Rating == 0)
                        {
                            objDefaultSensor = objSensorGear;
                            break;
                        }
                    }

                    // Add any Vehicle Mods.
                    if (objXmlVehicle["mods"] != null)
                    {
                        foreach (XmlNode objXmlMod in objXmlVehicle.SelectNodes("mods/mod"))
                        {
                            TreeNode objModNode = new TreeNode();
                            VehicleMod objMod = new VehicleMod(_objCharacter);

                            int intRating = 0;
                            if (objXmlMod["rating"] != null)
                                intRating = Convert.ToInt32(objXmlMod["rating"].InnerText);

                            XmlNode objXmlModNode = objXmlVehicleDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + objXmlMod["name"].InnerText + "\"]");
                            objMod.Create(objXmlModNode, objModNode, intRating);
                            objVehicle.Mods.Add(objMod);

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

                    // Add any Vehicle Gear.
                    if (objXmlVehicle["gears"] != null)
                    {
                        XmlDocument objXmlGearDocument = XmlManager.Instance.Load("gear.xml");

                        foreach (XmlNode objXmlGear in objXmlVehicle.SelectNodes("gears/gear"))
                        {
                            List<Weapon> objWeapons = new List<Weapon>();
                            List<TreeNode> objWeaponNodes = new List<TreeNode>();
                            TreeNode objGearNode = new TreeNode();
                            Gear objGear = new Gear(_objCharacter);
                            int intQty = 1;

                            int intRating = 0;
                            if (objXmlGear["rating"] != null)
                                intRating = Convert.ToInt32(objXmlGear["rating"].InnerText);
                            string strForceValue = "";
                            if (objXmlGear["name"].Attributes["select"] != null)
                                strForceValue = objXmlGear["name"].Attributes["select"].InnerText;
                            if (objXmlGear["qty"] != null)
                                intQty = Convert.ToInt32(objXmlGear["qty"].InnerText);

                            XmlNode objXmlGearNode = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear["name"].InnerText + "\"]");
                            objGear.Create(objXmlGearNode, _objCharacter, objGearNode, intRating, objWeapons, objWeaponNodes, strForceValue, false, false, false, blnCreateChildren, false);
                            objGear.Quantity = intQty;
                            objGearNode.Text = objGear.DisplayName;
                            objVehicle.Gear.Add(objGear);

                            // Look for child components.
                            if (objXmlGear["gears"] != null)
                            {
                                foreach (XmlNode objXmlChild in objXmlGear.SelectNodes("gears/gear"))
                                {
                                    AddPACKSGear(objXmlGearDocument, objXmlChild, objGearNode, objGear, cmsVehicleGear, blnCreateChildren);
                                }
                            }

                            objGearNode.Expand();
                            objGearNode.ContextMenuStrip = cmsVehicleGear;
                            objNode.Nodes.Add(objGearNode);
                            objNode.Expand();

                            // If this is a Sensor, it will replace the Vehicle's base sensor, so remove it.
                            if (objGear.Category == "Sensors" && objGear.Cost == "0" && objGear.Rating == 0)
                            {
                                objVehicle.Gear.Remove(objDefaultSensor);
                                foreach (TreeNode objSensorNode in objNode.Nodes)
                                {
                                    if (objSensorNode.Tag.ToString() == objDefaultSensor.InternalId)
                                    {
                                        objSensorNode.Remove();
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    // Add any Vehicle Weapons.
                    if (objXmlVehicle["weapons"] != null)
                    {
                        XmlDocument objXmlWeaponDocument = XmlManager.Instance.Load("weapons.xml");

                        foreach (XmlNode objXmlWeapon in objXmlVehicle.SelectNodes("weapons/weapon"))
                        {
                            TreeNode objWeaponNode = new TreeNode();
                            Weapon objWeapon = new Weapon(_objCharacter);

                            XmlNode objXmlWeaponNode = objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + objXmlWeapon["name"].InnerText + "\"]");
                            objWeapon.Create(objXmlWeaponNode, _objCharacter, objWeaponNode, cmsVehicleWeapon, cmsVehicleWeaponAccessory, blnCreateChildren);
                            objWeapon.VehicleMounted = true;

                            // Find the first Weapon Mount in the Vehicle.
                            foreach (VehicleMod objMod in objVehicle.Mods)
                            {
                                if (objMod.Name.Contains("Weapon Mount") || (objMod.WeaponMountCategories != "" && objMod.WeaponMountCategories.Contains(objWeapon.Category)))
                                {
                                    objMod.Weapons.Add(objWeapon);
                                    foreach (TreeNode objModNode in objNode.Nodes)
                                    {
                                        if (objModNode.Tag.ToString() == objMod.InternalId)
                                        {
                                            objWeaponNode.ContextMenuStrip = cmsVehicleWeapon;
                                            objModNode.Nodes.Add(objWeaponNode);
                                            objModNode.Expand();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }

                            // Look for Weapon Accessories.
                            if (objXmlWeapon["accessories"] != null)
                            {
                                foreach (XmlNode objXmlAccessory in objXmlWeapon.SelectNodes("accessories/accessory"))
                                {
                                    XmlNode objXmlAccessoryNode = objXmlWeaponDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + objXmlAccessory["name"].InnerText + "\"]");
                                    WeaponAccessory objMod = new WeaponAccessory(_objCharacter);
                                    TreeNode objModNode = new TreeNode();
                                    string strMount = "";
                                    int intRating = 0;
                                    if (objXmlAccessory["mount"] != null)
                                        strMount = objXmlAccessory["mount"].InnerText;
                                    objMod.Create(objXmlAccessoryNode, objModNode, strMount,intRating);
                                    objModNode.ContextMenuStrip = cmsWeaponAccessory;
                                    objMod.Parent = objWeapon;

                                    objWeapon.WeaponAccessories.Add(objMod);

                                    objWeaponNode.Nodes.Add(objModNode);
                                    objWeaponNode.Expand();
                                }
                            }
                        }
                    }

                    objNode.ContextMenuStrip = cmsVehicle;
                    treVehicles.Nodes[0].Nodes.Add(objNode);
                    treVehicles.Nodes[0].Expand();

                    Application.DoEvents();
                }
            }

            pgbProgress.Visible = false;

            if (frmPickPACKSKit.AddAgain)
                AddPACKSKit();

            PopulateGearList();
            UpdateCharacterInfo();
        }
コード例 #12
0
ファイル: frmTest.cs プロジェクト: argo2445/chummer5a
        private void TestVehicles()
        {
            Character objCharacter = new Character();
            XmlDocument objXmlDocument = XmlManager.Instance.Load("vehicles.xml");
            pgbProgress.Minimum = 0;
            pgbProgress.Value = 0;
            pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/vehicles/vehicle").Count;
            pgbProgress.Maximum += objXmlDocument.SelectNodes("/chummer/mods/mod").Count;

            // Vehicles.
            foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/vehicles/vehicle"))
            {
                pgbProgress.Value++;
                Application.DoEvents();
                try
                {
                    TreeNode objTempNode = new TreeNode();
                    Vehicle objTemp = new Vehicle(objCharacter);
                    objTemp.Create(objXmlGear, objTempNode, null, null, null, null);
                    try
                    {
                        int objValue = objTemp.TotalCost;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\n";
                    }
                    try
                    {
                        int objValue = objTemp.TotalAccel;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAccel\n";
                    }
                    try
                    {
                        int objValue = objTemp.TotalArmor;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalArmor\n";
                    }
                    try
                    {
                        int objValue = objTemp.TotalBody;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalBody\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalHandling;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalHandling\n";
                    }
                    try
                    {
                        int objValue = objTemp.TotalSpeed;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalSpeed\n";
                    }
                    try
                    {
                        string objValue = objTemp.CalculatedAvail;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedAvail\n";
                    }
                }
                catch
                {
                    txtOutput.Text += objXmlGear["name"].InnerText + " general failure\n";
                }
            }

            // Vehicle Mods.
            foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/mods/mod"))
            {
                pgbProgress.Value++;
                Application.DoEvents();
                try
                {
                    TreeNode objTempNode = new TreeNode();
                    VehicleMod objTemp = new VehicleMod(objCharacter);
                    objTemp.Create(objXmlGear, objTempNode, 1);
                    try
                    {
                        int objValue = objTemp.TotalCost;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalAvail;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\n";
                    }
                    try
                    {
                        int objValue = objTemp.CalculatedSlots;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedSlots\n";
                    }
                }
                catch
                {
                    txtOutput.Text += objXmlGear["name"].InnerText + " general failure\n";
                }
            }
        }
コード例 #13
0
ファイル: frmCareer.cs プロジェクト: argo2445/chummer5a
        private void tsVehicleAddWeaponWeapon_Click(object sender, EventArgs e)
        {
            VehicleMod objMod = new VehicleMod(_objCharacter);

            // Make sure that a Weapon Mount has been selected.
            try
            {
                // Attempt to locate the selected VehicleMod.
                Vehicle objFoundVehicle = new Vehicle(_objCharacter);
                objMod = _objFunctions.FindVehicleMod(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);

                if (!objMod.Name.Contains("Weapon Mount") && !objMod.Name.StartsWith("Mechanical Arm") || objMod.WeaponMountCategories == "")
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotAddWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotAddWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotAddWeapon"), LanguageManager.Instance.GetString("MessageTitle_CannotAddWeapon"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectWeapon frmPickWeapon = new frmSelectWeapon(_objCharacter, true);
            frmPickWeapon.LimitToCategories = objMod.WeaponMountCategories;
            frmPickWeapon.ShowDialog();

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

            // Open the Weapons XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("weapons.xml");

            XmlNode objXmlWeapon = objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + frmPickWeapon.SelectedWeapon + "\"]");

            TreeNode objNode = new TreeNode();
            Weapon objWeapon = new Weapon(_objCharacter);
            objWeapon.Create(objXmlWeapon, _objCharacter, objNode, cmsVehicleWeapon, cmsVehicleWeaponAccessory);
            objWeapon.VehicleMounted = true;

            int intCost = objWeapon.TotalCost;
            // Apply a markup if applicable.
            if (frmPickWeapon.Markup != 0)
            {
                double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo);
                dblCost *= 1 + (Convert.ToDouble(frmPickWeapon.Markup, GlobalOptions.Instance.CultureInfo) / 100.0);
                intCost = Convert.ToInt32(dblCost);
            }

            // Multiply the cost if applicable.
            if (objWeapon.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost)
                intCost *= _objOptions.RestrictedCostMultiplier;
            if (objWeapon.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailForbidden")) && _objOptions.MultiplyForbiddenCost)
                intCost *= _objOptions.ForbiddenCostMultiplier;

            if (!frmPickWeapon.FreeCost)
            {
                // Check the item's Cost and make sure the character can afford it.
                if (intCost > _objCharacter.Nuyen)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (frmPickWeapon.AddAgain)
                        tsVehicleAddWeaponWeapon_Click(sender, e);

                    return;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseVehicleWeapon") + " " + objWeapon.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddVehicleWeapon, objWeapon.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            objMod.Weapons.Add(objWeapon);

            objNode.ContextMenuStrip = cmsVehicleWeapon;
            treVehicles.SelectedNode.Nodes.Add(objNode);
            treVehicles.SelectedNode.Expand();

            if (frmPickWeapon.AddAgain)
                tsVehicleAddWeaponWeapon_Click(sender, e);

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
コード例 #14
0
ファイル: frmCareer.cs プロジェクト: argo2445/chummer5a
        private void tsVehicleAddMod_Click(object sender, EventArgs e)
        {
            // Make sure a parent items is selected, then open the Select Vehicle Mod window.
            try
            {
                if (treVehicles.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (treVehicles.SelectedNode.Level > 1)
                treVehicles.SelectedNode = treVehicles.SelectedNode.Parent;

            Vehicle objSelectedVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles);

            frmSelectVehicleMod frmPickVehicleMod = new frmSelectVehicleMod(_objCharacter, true);
            // Pass the selected vehicle on to the form.
            frmPickVehicleMod.SelectedVehicle = objSelectedVehicle;

            frmPickVehicleMod.ShowDialog(this);

            // Make sure the dialogue window was not canceled.
            if (frmPickVehicleMod.DialogResult == DialogResult.Cancel)
                return;

            // Open the Vehicles XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("vehicles.xml");

            XmlNode objXmlMod = objXmlDocument.SelectSingleNode("/chummer/mods/mod[name = \"" + frmPickVehicleMod.SelectedMod + "\"]");

            TreeNode objNode = new TreeNode();
            VehicleMod objMod = new VehicleMod(_objCharacter);
            objMod.Create(objXmlMod, objNode, frmPickVehicleMod.SelectedRating);

            // Make sure that the Armor Rating does not exceed the maximum allowed by the Vehicle.
            if (objMod.Name.StartsWith("Armor"))
            {
                if (objMod.Rating > objSelectedVehicle.MaxArmor)
                {
                    objMod.Rating = objSelectedVehicle.MaxArmor;
                    objNode.Text = objMod.DisplayName;
                }
            }

            // Check the item's Cost and make sure the character can afford it.
            int intOriginalCost = objSelectedVehicle.TotalCost;
            objSelectedVehicle.Mods.Add(objMod);

            // Do not allow the user to add a new Vehicle Mod if the Vehicle's Capacity has been reached.
            if (_objOptions.EnforceCapacity)
            {
                bool blnOverCapacity = false;
                if (_objOptions.BookEnabled("R5"))
                {
                    if (objSelectedVehicle.IsDrone && GlobalOptions.Instance.Dronemods)
                    {
                        if (objSelectedVehicle.DroneModSlotsUsed > objSelectedVehicle.DroneModSlots)
                            blnOverCapacity = true;
                    }
                    else
                    {
                        int intUsed = objSelectedVehicle.CalcCategoryUsed(objMod.Category);
                        int intAvail = objSelectedVehicle.CalcCategoryAvail(objMod.Category);
                        if (intUsed > intAvail)
                            blnOverCapacity = true;
                    }
                }
                else if (objSelectedVehicle.Slots < objSelectedVehicle.SlotsUsed)
                {
                    blnOverCapacity = true;
                }

                if(blnOverCapacity)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    objSelectedVehicle.Mods.Remove(objMod);
                    if (frmPickVehicleMod.AddAgain)
                        tsVehicleAddMod_Click(sender, e);
                    return;
                }
            }

            int intCost = objSelectedVehicle.TotalCost - intOriginalCost;
            // Apply a markup if applicable.
            if (frmPickVehicleMod.Markup != 0)
            {
                double dblCost = Convert.ToDouble(intCost, GlobalOptions.Instance.CultureInfo);
                dblCost *= 1 + (Convert.ToDouble(frmPickVehicleMod.Markup, GlobalOptions.Instance.CultureInfo) / 100.0);
                intCost = Convert.ToInt32(dblCost);
            }

            // Multiply the cost if applicable.
            if (objMod.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailRestricted")) && _objOptions.MultiplyRestrictedCost)
                intCost *= _objOptions.RestrictedCostMultiplier;
            if (objMod.TotalAvail.EndsWith(LanguageManager.Instance.GetString("String_AvailForbidden")) && _objOptions.MultiplyForbiddenCost)
                intCost *= _objOptions.ForbiddenCostMultiplier;

            if (!frmPickVehicleMod.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    objSelectedVehicle.Mods.Remove(objMod);
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (frmPickVehicleMod.AddAgain)
                        tsVehicleAddMod_Click(sender, e);

                    return;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseVehicleMod") + " " + objMod.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddVehicleMod, objMod.InternalId);
                    objExpense.Undo = objUndo;
                }
            }

            objNode.ContextMenuStrip = cmsVehicle;
            treVehicles.SelectedNode.Nodes.Add(objNode);
            treVehicles.SelectedNode.Expand();
            RefreshSelectedVehicle();

            // Check for Improved Sensor bonus.
            if (objMod.Bonus != null)
            {
                if (objMod.Bonus["selecttext"] != null)
                {
                    frmSelectText frmPickText = new frmSelectText();
                    frmPickText.Description = LanguageManager.Instance.GetString("String_Improvement_SelectText").Replace("{0}", objMod.DisplayNameShort);
                    frmPickText.ShowDialog(this);
                    objMod.Extra = frmPickText.SelectedValue;
                    objNode.Text = objMod.DisplayName;
                }
                if (objMod.Bonus["improvesensor"] != null)
                {
                    ChangeVehicleSensor(objSelectedVehicle, true);
                }
            }

            _blnIsDirty = true;
            UpdateWindowTitle();

            if (frmPickVehicleMod.AddAgain)
                tsVehicleAddMod_Click(sender, e);
        }
コード例 #15
0
ファイル: frmCareer.cs プロジェクト: argo2445/chummer5a
        private void cmdWeaponMoveToVehicle_Click(object sender, EventArgs e)
        {
            // Locate the selected Weapon.
            Weapon objWeapon = new Weapon(_objCharacter);
            foreach (Weapon objCharacterWeapon in _objCharacter.Weapons)
            {
                if (objCharacterWeapon.InternalId == treWeapons.SelectedNode.Tag.ToString())
                {
                    objWeapon = objCharacterWeapon;
                    break;
                }
            }

            List<Vehicle> lstVehicles = new List<Vehicle>();
            foreach (Vehicle objCharacterVehicle in _objCharacter.Vehicles)
            {
                foreach (VehicleMod objVehicleMod in objCharacterVehicle.Mods)
                {
                    // Only add a Vehicle to the list if it has a Weapon Mount or Mechanical Arm.
                    if (objVehicleMod.Name.Contains("Weapon Mount") || objVehicleMod.Name.StartsWith("Mechanical Arm") || (objVehicleMod.WeaponMountCategories != "" && objVehicleMod.WeaponMountCategories.Contains(objWeapon.Category)))
                    {
                        lstVehicles.Add(objCharacterVehicle);
                        break;
                    }
                }
            }

            // Cannot continue if there are no Vehicles with a Weapon Mount or Mechanical Arm.
            if (lstVehicles.Count == 0)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotMoveWeapons"), LanguageManager.Instance.GetString("MessageTitle_CannotMoveWeapons"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectItem frmPickItem = new frmSelectItem();
            frmPickItem.Vehicles = lstVehicles;
            frmPickItem.ShowDialog(this);

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

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

            // Now display a list of the acceptable mounting points for the Weapon.
            List<VehicleMod> lstMods = new List<VehicleMod>();
            foreach (VehicleMod objVehicleMod in objVehicle.Mods)
            {
                if (objVehicleMod.Name.Contains("Weapon Mount") || objVehicleMod.Name.StartsWith("Mechanical Arm") || (objVehicleMod.WeaponMountCategories != "" && objVehicleMod.WeaponMountCategories.Contains(objWeapon.Category)))
                    lstMods.Add(objVehicleMod);
            }

            frmPickItem.VehicleMods = lstMods;
            frmPickItem.ShowDialog(this);

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

            // Locate the selected Vehicle Mod.
            VehicleMod objMod = new VehicleMod(_objCharacter);
            foreach (VehicleMod objCharacterMod in objVehicle.Mods)
            {
                if (objCharacterMod.InternalId == frmPickItem.SelectedItem)
                {
                    objMod = objCharacterMod;
                    break;
                }
            }

            // Remove the Weapon from the character and add it to the Vehicle Mod.
            _objCharacter.Weapons.Remove(objWeapon);
            objMod.Weapons.Add(objWeapon);
            objWeapon.VehicleMounted = true;
            objWeapon.Location = string.Empty;

            // Move the TreeNode to the Vehicle Mod.
            TreeNode objNode = new TreeNode();
            objNode = treWeapons.SelectedNode;
            treWeapons.SelectedNode.Remove();

            foreach (TreeNode objVehicleNode in treVehicles.Nodes[0].Nodes)
            {
                foreach (TreeNode objModNode in objVehicleNode.Nodes)
                {
                    if (objModNode.Tag.ToString() == objMod.InternalId)
                    {
                        objModNode.Nodes.Add(objNode);
                        objModNode.Expand();
                        objNode.Expand();
                        break;
                    }
                }
            }

            // Remove any Improvements from the Character.
            foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
            {
                foreach (Gear objGear in objAccessory.Gear)
                    _objFunctions.DeleteGear(objGear, treWeapons, _objImprovementManager);
            }
            if (objWeapon.UnderbarrelWeapons.Count > 0)
            {
                foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                {
                    foreach (WeaponAccessory objAccessory in objUnderbarrelWeapon.WeaponAccessories)
                    {
                        foreach (Gear objGear in objAccessory.Gear)
                            _objFunctions.DeleteGear(objGear, treWeapons, _objImprovementManager);
                    }
                }
            }

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

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

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

                _objCharacter.Weapons.Add(objWeapon);

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

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

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

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

                    intMove = frmPickNumber.SelectedValue;
                }

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

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

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

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

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

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

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

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

            _blnIsDirty = true;
            UpdateWindowTitle();
        }