Beispiel #1
0
        /// <summary>
        /// Copy a piece of Gear.
        /// </summary>
        /// <param name="objGear">Gear object to copy.</param>
        /// <param name="objNode">TreeNode created by copying the item.</param>
        /// <param name="objWeapons">List of Weapons created by copying the item.</param>
        /// <param name="objWeaponNodes">List of Weapon TreeNodes created by copying the item.</param>
        public void Copy(Commlink objGear, TreeNode objNode, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes)
        {
            _strName           = objGear.Name;
            _strCategory       = objGear.Category;
            _intMaxRating      = objGear.MaxRating;
            _intMinRating      = objGear.MinRating;
            _intRating         = objGear.Rating;
            _intQty            = objGear.Quantity;
            _strCapacity       = objGear.Capacity;
            _strArmorCapacity  = objGear.ArmorCapacity;
            _strAvail          = objGear.Avail;
            _strAvail3         = objGear.Avail3;
            _strAvail6         = objGear.Avail6;
            _strAvail10        = objGear.Avail10;
            _intCostFor        = objGear.CostFor;
            _strOverclocked    = objGear.Overclocked;
            _intDeviceRating   = objGear.DeviceRating;
            _intAttack         = objGear.Attack;
            _intDataProcessing = objGear.DataProcessing;
            _intFirewall       = objGear.Firewall;
            _intSleaze         = objGear.Sleaze;
            _strCost           = objGear.Cost;
            _strCost3          = objGear.Cost3;
            _strCost6          = objGear.Cost6;
            _strCost10         = objGear.Cost10;
            _strSource         = objGear.Source;
            _strPage           = objGear.Page;
            _strExtra          = objGear.Extra;
            _blnBonded         = objGear.Bonded;
            _blnEquipped       = objGear.Equipped;
            _blnHomeNode       = objGear.HomeNode;
            _nodBonus          = objGear.Bonus;
            _nodWeaponBonus    = objGear.WeaponBonus;
            _guiWeaponID       = Guid.Parse(objGear.WeaponID);
            _strNotes          = objGear.Notes;
            _strLocation       = objGear.Location;

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

            foreach (Gear objGearChild in objGear.Children)
            {
                TreeNode objChildNode = new TreeNode();
                Gear     objChild     = new Gear(_objCharacter);
                if (objGearChild.GetType() == typeof(Commlink))
                {
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Copy(objGearChild, objChildNode, objWeapons, objWeaponNodes);
                    objChild = objCommlink;
                }
                else
                {
                    objChild.Copy(objGearChild, objChildNode, objWeapons, objWeaponNodes);
                }
                _objChildren.Add(objChild);

                objNode.Nodes.Add(objChildNode);
                objNode.Expand();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Save the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public new void Save(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("gear");
     objWriter.WriteElementString("guid", _guiID.ToString());
     objWriter.WriteElementString("name", _strName);
     objWriter.WriteElementString("category", _strCategory);
     objWriter.WriteElementString("armorcapacity", _strArmorCapacity);
     objWriter.WriteElementString("maxrating", _intMaxRating.ToString());
     objWriter.WriteElementString("rating", _intRating.ToString());
     objWriter.WriteElementString("qty", _intQty.ToString());
     objWriter.WriteElementString("avail", _strAvail);
     objWriter.WriteElementString("cost", _strCost);
     objWriter.WriteElementString("extra", _strExtra);
     objWriter.WriteElementString("bonded", _blnBonded.ToString());
     objWriter.WriteElementString("equipped", _blnEquipped.ToString());
     objWriter.WriteElementString("homenode", _blnHomeNode.ToString());
     objWriter.WriteElementString("overclocked", _blnHomeNode.ToString());
     if (_nodBonus != null)
     {
         objWriter.WriteRaw("<bonus>" + _nodBonus.InnerXml + "</bonus>");
     }
     else
     {
         objWriter.WriteElementString("bonus", "");
     }
     objWriter.WriteElementString("source", _strSource);
     objWriter.WriteElementString("page", _strPage);
     objWriter.WriteElementString("devicerating", _intDeviceRating.ToString());
     objWriter.WriteElementString("attack", _intAttack.ToString());
     objWriter.WriteElementString("sleaze", _intSleaze.ToString());
     objWriter.WriteElementString("dataprocessing", _intDataProcessing.ToString());
     objWriter.WriteElementString("firewall", _intFirewall.ToString());
     objWriter.WriteElementString("gearname", _strGearName);
     objWriter.WriteStartElement("children");
     foreach (Gear objGear in _objChildren)
     {
         // Use the Gear's SubClass if applicable.
         if (objGear.GetType() == typeof(Commlink))
         {
             Commlink objCommlink = new Commlink(_objCharacter);
             objCommlink = (Commlink)objGear;
             objCommlink.Save(objWriter);
         }
         else
         {
             objGear.Save(objWriter);
         }
     }
     objWriter.WriteEndElement();
     objWriter.WriteElementString("location", _strLocation);
     objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteElementString("discountedcost", DiscountCost.ToString());
     objWriter.WriteElementString("active", _blnActiveCommlink.ToString());
     objWriter.WriteEndElement();
 }
Beispiel #3
0
 /// <summary>
 /// Copy a piece of Gear.
 /// </summary>
 /// <param name="objGear">Gear object to copy.</param>
 /// <param name="objNode">TreeNode created by copying the item.</param>
 /// <param name="objWeapons">List of Weapons created by copying the item.</param>
 /// <param name="objWeaponNodes">List of Weapon TreeNodes created by copying the item.</param>
 public void Copy(Commlink objGear, TreeNode objNode, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes)
 {
     base.Copy(objGear, objNode, new List <Weapon>(), new List <TreeNode>());
     _strOverclocked     = objGear.Overclocked;
     _strAttack          = objGear.Attack;
     _strDataProcessing  = objGear.DataProcessing;
     _strFirewall        = objGear.Firewall;
     _strSleaze          = objGear.Sleaze;
     _blnIsLivingPersona = objGear.IsLivingPersona;
     _blnActiveCommlink  = objGear.IsActive;
 }
Beispiel #4
0
 /// <summary>
 /// Copy a piece of Gear.
 /// </summary>
 /// <param name="objGear">Gear object to copy.</param>
 /// <param name="objNode">TreeNode created by copying the item.</param>
 /// <param name="objWeapons">List of Weapons created by copying the item.</param>
 /// <param name="objWeaponNodes">List of Weapon TreeNodes created by copying the item.</param>
 public void Copy(Commlink objGear, TreeNode objNode, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes)
 {
     base.Copy(objGear, objNode, objWeapons, objWeaponNodes);
     _strOverclocked    = objGear.Overclocked;
     _strAttack         = objGear.Attack;
     _strDataProcessing = objGear.DataProcessing;
     _strFirewall       = objGear.Firewall;
     _strSleaze         = objGear.Sleaze;
     IsActive           = objGear.IsActive;
     HomeNode           = objGear.HomeNode;
 }
Beispiel #5
0
 /// <summary>
 /// Print the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public void Print(XmlTextWriter objWriter, CultureInfo objCulture)
 {
     objWriter.WriteStartElement("armormod");
     objWriter.WriteElementString("name", DisplayNameShort);
     objWriter.WriteElementString("name_english", _strName);
     objWriter.WriteElementString("category", DisplayCategory);
     objWriter.WriteElementString("category_english", _strCategory);
     objWriter.WriteElementString("armor", _intA.ToString(objCulture));
     objWriter.WriteElementString("maxrating", _intMaxRating.ToString(objCulture));
     objWriter.WriteElementString("rating", _intRating.ToString(objCulture));
     objWriter.WriteElementString("avail", TotalAvail);
     objWriter.WriteElementString("cost", TotalCost.ToString(_objCharacter.Options.NuyenFormat, objCulture));
     objWriter.WriteElementString("owncost", OwnCost.ToString(_objCharacter.Options.NuyenFormat, objCulture));
     objWriter.WriteElementString("source", _objCharacter.Options.LanguageBookShort(_strSource));
     objWriter.WriteElementString("page", Page);
     objWriter.WriteElementString("included", _blnIncludedInArmor.ToString());
     objWriter.WriteElementString("equipped", _blnEquipped.ToString());
     objWriter.WriteElementString("wirelesson", _blnWirelessOn.ToString());
     objWriter.WriteStartElement("gears");
     foreach (Gear objGear in _lstGear)
     {
         // Use the Gear's SubClass if applicable.
         Commlink objCommlink = objGear as Commlink;
         if (objCommlink != null)
         {
             objCommlink.Print(objWriter, objCulture);
         }
         else
         {
             objGear.Print(objWriter, objCulture);
         }
     }
     objWriter.WriteEndElement();
     objWriter.WriteElementString("extra", LanguageManager.TranslateExtra(_strExtra));
     if (_objCharacter.Options.PrintNotes)
     {
         objWriter.WriteElementString("notes", _strNotes);
     }
     objWriter.WriteEndElement();
 }
Beispiel #6
0
 /// <summary>
 /// Print the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public void Print(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("accessory");
     objWriter.WriteElementString("name", DisplayName);
     objWriter.WriteElementString("mount", _strMount);
     objWriter.WriteElementString("extramount", _strExtraMount);
     objWriter.WriteElementString("rc", _strRC);
     objWriter.WriteElementString("conceal", _strConceal);
     objWriter.WriteElementString("avail", TotalAvail);
     objWriter.WriteElementString("cost", TotalCost.ToString());
     objWriter.WriteElementString("owncost", OwnCost.ToString());
     objWriter.WriteElementString("included", _blnIncludedInWeapon.ToString());
     objWriter.WriteElementString("source", _objCharacter.Options.LanguageBookShort(_strSource));
     objWriter.WriteElementString("page", Page);
     objWriter.WriteElementString("accuracy", _intAccuracy.ToString());
     if (_lstGear.Count > 0)
     {
         objWriter.WriteStartElement("gears");
         foreach (Gear objGear in _lstGear)
         {
             // Use the Gear's SubClass if applicable.
             if (objGear.GetType() == typeof(Commlink))
             {
                 Commlink objCommlink = new Commlink(_objCharacter);
                 objCommlink = (Commlink)objGear;
                 objCommlink.Print(objWriter);
             }
             else
             {
                 objGear.Print(objWriter);
             }
         }
         objWriter.WriteEndElement();
     }
     if (_objCharacter.Options.PrintNotes)
     {
         objWriter.WriteElementString("notes", _strNotes);
     }
     objWriter.WriteEndElement();
 }
Beispiel #7
0
        /// <summary>
        /// Load the Gear from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        public new void Load(XmlNode objNode, bool blnCopy = false)
        {
            _guiID = Guid.Parse(objNode["guid"].InnerText);
            _strName = objNode["name"].InnerText;
            _strCategory = objNode["category"].InnerText;
            objNode.TryGetField("armorcapacity", out _strArmorCapacity).ToString();
            _intMaxRating = Convert.ToInt32(objNode["maxrating"].InnerText);
            _intRating = Convert.ToInt32(objNode["rating"].InnerText);
            _intQty = Convert.ToInt32(objNode["qty"].InnerText);
            _strAvail = objNode["avail"].InnerText;
            _strCost = objNode["cost"].InnerText;
            _strExtra = objNode["extra"].InnerText;
            objNode.TryGetField("overclocked", out _strOverclocked);
            objNode.TryGetField("bonded", out _blnBonded);
            objNode.TryGetField("equipped", out _blnEquipped);
            objNode.TryGetField("homenode", out _blnHomeNode);
            _nodBonus = objNode["bonus"];
            _strSource = objNode["source"].InnerText;
            objNode.TryGetField("page", out _strPage);
            _intDeviceRating = Convert.ToInt32(objNode["devicerating"].InnerText);
            objNode.TryGetField("attack", out _intAttack);
            objNode.TryGetField("sleaze", out _intSleaze);
            objNode.TryGetField("dataprocessing", out _intDataProcessing);
            objNode.TryGetField("firewall", out _intFirewall);
            objNode.TryGetField("gearname", out _strGearName);

            if (objNode.InnerXml.Contains("<gear>"))
            {
                XmlNodeList nodChildren = objNode.SelectNodes("children/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);
                            objCommlink.Parent = this;
                            _objChildren.Add(objCommlink);
                            break;
                        default:
                            Gear objGear = new Gear(_objCharacter);
                            objGear.Load(nodChild, blnCopy);
                            objGear.Parent = this;
                            _objChildren.Add(objGear);
                            break;
                    }
                }
            }
            objNode.TryGetField("location", out _strLocation);
            objNode.TryGetField("notes", out _strNotes);
            objNode.TryGetField("discountedcost", out _blnDiscountCost);
            objNode.TryGetField("active", out _blnActiveCommlink);

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

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

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

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

            if (blnCopy)
            {
                _guiID = Guid.NewGuid();
                _strLocation = string.Empty;
                _blnHomeNode = false;
            }
        }
Beispiel #8
0
 /// <summary>
 /// Save the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public new void Save(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("gear");
     objWriter.WriteElementString("guid", _guiID.ToString());
     objWriter.WriteElementString("name", _strName);
     objWriter.WriteElementString("category", _strCategory);
     objWriter.WriteElementString("armorcapacity", _strArmorCapacity);
     objWriter.WriteElementString("maxrating", _intMaxRating.ToString());
     objWriter.WriteElementString("rating", _intRating.ToString());
     objWriter.WriteElementString("qty", _intQty.ToString());
     objWriter.WriteElementString("avail", _strAvail);
     objWriter.WriteElementString("cost", _strCost);
     objWriter.WriteElementString("extra", _strExtra);
     objWriter.WriteElementString("bonded", _blnBonded.ToString());
     objWriter.WriteElementString("equipped", _blnEquipped.ToString());
     objWriter.WriteElementString("homenode", _blnHomeNode.ToString());
     objWriter.WriteElementString("overclocked", _blnHomeNode.ToString());
     if (_nodBonus != null)
         objWriter.WriteRaw("<bonus>" + _nodBonus.InnerXml + "</bonus>");
     else
         objWriter.WriteElementString("bonus", "");
     objWriter.WriteElementString("source", _strSource);
     objWriter.WriteElementString("page", _strPage);
     objWriter.WriteElementString("devicerating", _intDeviceRating.ToString());
     objWriter.WriteElementString("attack", _intAttack.ToString());
     objWriter.WriteElementString("sleaze", _intSleaze.ToString());
     objWriter.WriteElementString("dataprocessing", _intDataProcessing.ToString());
     objWriter.WriteElementString("firewall", _intFirewall.ToString());
     objWriter.WriteElementString("gearname", _strGearName);
     objWriter.WriteStartElement("children");
     foreach (Gear objGear in _objChildren)
     {
         // Use the Gear's SubClass if applicable.
         if (objGear.GetType() == typeof(Commlink))
         {
             Commlink objCommlink = new Commlink(_objCharacter);
             objCommlink = (Commlink)objGear;
             objCommlink.Save(objWriter);
         }
         else
         {
             objGear.Save(objWriter);
         }
     }
     objWriter.WriteEndElement();
     objWriter.WriteElementString("location", _strLocation);
     objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteElementString("discountedcost", DiscountCost.ToString());
     objWriter.WriteElementString("active", _blnActiveCommlink.ToString());
     objWriter.WriteEndElement();
 }
Beispiel #9
0
        /// <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;
            }
        }
Beispiel #10
0
 /// <summary>
 /// Save the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public void Save(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("vehicle");
     objWriter.WriteElementString("guid", _guiID.ToString());
     objWriter.WriteElementString("name", _strName);
     objWriter.WriteElementString("category", _strCategory);
     objWriter.WriteElementString("handling", _intHandling.ToString());
     objWriter.WriteElementString("offroadhandling", _intOffroadHandling.ToString());
     objWriter.WriteElementString("accel", _intAccel.ToString());
     objWriter.WriteElementString("speed", _intSpeed.ToString());
     objWriter.WriteElementString("pilot", _intPilot.ToString());
     objWriter.WriteElementString("body", _intBody.ToString());
     objWriter.WriteElementString("seats", _intSeats.ToString());
     objWriter.WriteElementString("armor", _intArmor.ToString());
     objWriter.WriteElementString("sensor", _intSensor.ToString());
     objWriter.WriteElementString("devicerating", TotalDeviceRating.ToString());
     objWriter.WriteElementString("avail", _strAvail);
     objWriter.WriteElementString("cost", _strCost);
     objWriter.WriteElementString("addslots", _intAddSlots.ToString());
     objWriter.WriteElementString("modslots", _intModSlots.ToString());
     objWriter.WriteElementString("source", _strSource);
     objWriter.WriteElementString("page", _strPage);
     objWriter.WriteElementString("physicalcmfilled", _intPhysicalCMFilled.ToString());
     objWriter.WriteElementString("matrixcmfilled", _intMatrixCMFilled.ToString());
     objWriter.WriteElementString("vehiclename", _strVehicleName);
     objWriter.WriteElementString("homenode", _blnHomeNode.ToString());
     objWriter.WriteStartElement("mods");
     foreach (VehicleMod objMod in _lstVehicleMods)
         objMod.Save(objWriter);
     objWriter.WriteEndElement();
     objWriter.WriteStartElement("gears");
     foreach (Gear objGear in _lstGear)
     {
         // Use the Gear's SubClass if applicable.
         if (objGear.GetType() == typeof(Commlink))
         {
             Commlink objCommlink = new Commlink(_objCharacter);
             objCommlink = (Commlink)objGear;
             objCommlink.Save(objWriter);
         }
         else
         {
             objGear.Save(objWriter);
         }
     }
     objWriter.WriteEndElement();
     objWriter.WriteStartElement("weapons");
     foreach (Weapon objWeapon in _lstWeapons)
         objWeapon.Save(objWriter);
     objWriter.WriteEndElement();
     objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteElementString("discountedcost", DealerConnectionDiscount.ToString());
     if (_lstLocations.Count > 0)
     {
         // <locations>
         objWriter.WriteStartElement("locations");
         foreach (string strLocation in _lstLocations)
         {
             objWriter.WriteElementString("location", strLocation);
         }
         // </locations>
         objWriter.WriteEndElement();
     }
     objWriter.WriteEndElement();
     _objCharacter.SourceProcess(_strSource);
 }
Beispiel #11
0
        private void chkVehicleHomeNode_CheckedChanged(object sender, EventArgs e)
        {
            if (treVehicles.SelectedNode.Level == 1)
            {
                Vehicle objVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles);
                if (objVehicle == null)
                    return;

                objVehicle.HomeNode = chkVehicleHomeNode.Checked;
                _objCharacter.HasHomeNode = chkVehicleHomeNode.Checked;
                _objCharacter.HomeNodeCategory = "Vehicle";
                _objCharacter.HomeNodeDataProcessing = 0;
                _objCharacter.HomeNodePilot = objVehicle.Pilot;
                _objCharacter.HomeNodeHandling = objVehicle.TotalHandling;
                _objCharacter.HomeNodeSensor = objVehicle.CalculatedSensor;
            }
            else
            {
                Commlink objCommlink = new Commlink(_objCharacter);
                Vehicle objSelectedVehicle = new Vehicle(_objCharacter);
                objCommlink = (Commlink)_objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objSelectedVehicle);
                if (objCommlink == null)
                {
                    return;
                }
                objCommlink.HomeNode = chkVehicleHomeNode.Checked;
                _objCharacter.HasHomeNode = chkVehicleHomeNode.Checked;
                _objCharacter.HomeNodeCategory = "Gear";
                _objCharacter.HomeNodeDataProcessing = objCommlink.TotalDataProcessing;
                _objCharacter.HomeNodePilot = 0;
                _objCharacter.HomeNodeHandling = "0";
                _objCharacter.HomeNodeSensor = 0;
            }

            _objCharacter.HasHomeNode = chkVehicleHomeNode.Checked;
            _objFunctions.ReplaceHomeNodes(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Gear, _objCharacter.Vehicles);

            RefreshSelectedVehicle();
            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Beispiel #12
0
 /// <summary>
 /// Save the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public new void Print(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("gear");
     objWriter.WriteElementString("name", DisplayNameShort);
     objWriter.WriteElementString("name_english", _strName);
     if (DisplayCategory.EndsWith("s"))
     {
         objWriter.WriteElementString("category", DisplayCategory.Substring(0, DisplayCategory.Length - 1));
     }
     else
     {
         objWriter.WriteElementString("category", DisplayCategory);
     }
     objWriter.WriteElementString("category_english", _strCategory);
     objWriter.WriteElementString("iscommlink", true.ToString());
     objWriter.WriteElementString("ispersona", IsLivingPersona.ToString());
     //objWriter.WriteElementString("isnexus", (_strCategory == "Nexus").ToString());
     objWriter.WriteElementString("isammo", (_strCategory == "Ammunition").ToString());
     objWriter.WriteElementString("isprogram", IsProgram.ToString());
     objWriter.WriteElementString("isos", false.ToString());
     objWriter.WriteElementString("issin", false.ToString());
     objWriter.WriteElementString("maxrating", _intMaxRating.ToString());
     objWriter.WriteElementString("rating", _intRating.ToString());
     objWriter.WriteElementString("attack", _intAttack.ToString());
     objWriter.WriteElementString("sleaze", _intSleaze.ToString());
     objWriter.WriteElementString("dataprocessing", _intDataProcessing.ToString());
     objWriter.WriteElementString("firewall", _intFirewall.ToString());
     objWriter.WriteElementString("qty", _intQty.ToString());
     objWriter.WriteElementString("avail", TotalAvail(true));
     objWriter.WriteElementString("avail_english", TotalAvail(true, true));
     objWriter.WriteElementString("cost", TotalCost.ToString());
     objWriter.WriteElementString("owncost", OwnCost.ToString());
     objWriter.WriteElementString("extra", LanguageManager.Instance.TranslateExtra(_strExtra));
     objWriter.WriteElementString("bonded", _blnBonded.ToString());
     objWriter.WriteElementString("equipped", _blnEquipped.ToString());
     objWriter.WriteElementString("homenode", _blnHomeNode.ToString());
     objWriter.WriteElementString("gearname", _strGearName);
     objWriter.WriteElementString("source", _objCharacter.Options.LanguageBookShort(_strSource));
     objWriter.WriteElementString("page", Page);
     objWriter.WriteElementString("devicerating", TotalDeviceRating.ToString());
     objWriter.WriteElementString("processorlimit", ProcessorLimit.ToString());
     objWriter.WriteElementString("conditionmonitor", ConditionMonitor.ToString());
     objWriter.WriteElementString("active", _blnActiveCommlink.ToString());
     objWriter.WriteStartElement("children");
     foreach (Gear objGear in _objChildren)
     {
         if (objGear.Category != "Commlink Upgrade" && objGear.Category != "Commlink Operating System Upgrade")
         {
             // Use the Gear's SubClass if applicable.
             if (objGear.GetType() == typeof(Commlink))
             {
                 Commlink objCommlink = new Commlink(_objCharacter);
                 objCommlink = (Commlink)objGear;
                 objCommlink.Print(objWriter);
             }
             else
             {
                 objGear.Print(objWriter);
             }
         }
     }
     objWriter.WriteEndElement();
     if (_objCharacter.Options.PrintNotes)
     {
         objWriter.WriteElementString("notes", _strNotes);
     }
     objWriter.WriteEndElement();
 }
Beispiel #13
0
        /// <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;
        }
Beispiel #14
0
 /// <summary>
 /// Print the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public void Print(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("armor");
     objWriter.WriteElementString("name", DisplayNameShort);
     objWriter.WriteElementString("name_english", _strName);
     objWriter.WriteElementString("category", DisplayCategory);
     objWriter.WriteElementString("category_english", _strCategory);
     objWriter.WriteElementString("armor", TotalArmor.ToString());
     objWriter.WriteElementString("avail", TotalAvail);
     objWriter.WriteElementString("cost", TotalCost.ToString());
     objWriter.WriteElementString("owncost", OwnCost.ToString());
     objWriter.WriteElementString("source", _objCharacter.Options.LanguageBookShort(_strSource));
     objWriter.WriteElementString("page", Page);
     objWriter.WriteElementString("armorname", _strArmorName);
     objWriter.WriteElementString("equipped", _blnEquipped.ToString());
     objWriter.WriteStartElement("armormods");
     foreach (ArmorMod objMod in _lstArmorMods)
     {
         objMod.Print(objWriter);
     }
     objWriter.WriteEndElement();
     objWriter.WriteStartElement("gears");
     foreach (Gear objGear in _lstGear)
     {
         // Use the Gear's SubClass if applicable.
         if (objGear.GetType() == typeof(Commlink))
         {
             Commlink objCommlink = new Commlink(_objCharacter);
             objCommlink = (Commlink)objGear;
             objCommlink.Print(objWriter);
         }
         else
         {
             objGear.Print(objWriter);
         }
     }
     objWriter.WriteEndElement();
     objWriter.WriteElementString("extra", LanguageManager.Instance.TranslateExtra(_strExtra));
     objWriter.WriteElementString("location", _strLocation);
     if (_objCharacter.Options.PrintNotes)
         objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteEndElement();
 }
Beispiel #15
0
        /// <summary>
        /// Select a piece of Gear and add it to a piece of Armor.
        /// </summary>
        /// <param name="blnShowArmorCapacityOnly">Whether or not only items that consume capacity should be shown.</param>
        private bool PickArmorGear(bool blnShowArmorCapacityOnly = false)
        {
            bool blnNullParent = true;
            Gear objSelectedGear = new Gear(_objCharacter);
            Armor objSelectedArmor = new Armor(_objCharacter);

            foreach (Armor objArmor in _objCharacter.Armor)
            {
                if (objArmor.InternalId == treArmor.SelectedNode.Tag.ToString())
                    objSelectedArmor = objArmor;
            }

            if (treArmor.SelectedNode.Level > 1)
            {
                objSelectedGear = _objFunctions.FindArmorGear(treArmor.SelectedNode.Tag.ToString(), _objCharacter.Armor, out objSelectedArmor);
                if (objSelectedGear != null)
                    blnNullParent = false;
            }

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

            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSelectedGear.Name + "\" and category = \"" + objSelectedGear.Category + "\"]");

            bool blnFakeCareerMode = false;
            if (_objCharacter.Metatype == "A.I." || _objCharacter.MetatypeCategory == "Technocritters" || _objCharacter.MetatypeCategory == "Protosapients")
                blnFakeCareerMode = true;
            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, blnFakeCareerMode);
            frmPickGear.ShowArmorCapacityOnly = blnShowArmorCapacityOnly;
            frmPickGear.CapacityDisplayStyle = objSelectedArmor.CapacityDisplayStyle;
            try
            {
                if (treArmor.SelectedNode.Level > 1)
                {
                    if (objXmlGear.InnerXml.Contains("<addoncategory>"))
                    {
                        string strCategories = "";
                        foreach (XmlNode objXmlCategory in objXmlGear.SelectNodes("addoncategory"))
                            strCategories += objXmlCategory.InnerText + ",";
                        // Remove the trailing comma.
                        strCategories = strCategories.Substring(0, strCategories.Length - 1);
                        frmPickGear.AllowedCategories = strCategories;
                    }

                    // If the Gear has a Capacity with no brackets (meaning it grants Capacity), show only Subsystems (those that conume Capacity).
                    if (!objSelectedGear.Capacity.Contains('['))
                        frmPickGear.MaximumCapacity = objSelectedGear.CapacityRemaining;

                    if (objSelectedGear.Category == "Commlinks" || objSelectedGear.Category == "Cyberdecks")
                    {
                        Commlink objCommlink = (Commlink)objSelectedGear;
                        frmPickGear.CommlinkResponse = objCommlink.DeviceRating;
                    }
                }
                else if (treArmor.SelectedNode.Level == 1)
                {
                    // Open the Armor XML file and locate the selected Gear.
                    objXmlDocument = XmlManager.Instance.Load("armor.xml");
                    objXmlGear = objXmlDocument.SelectSingleNode("/chummer/armors/armor[name = \"" + objSelectedArmor.Name + "\"]");

                    if (objXmlGear.InnerXml.Contains("<addoncategory>"))
                    {
                        string strCategories = "";
                        foreach (XmlNode objXmlCategory in objXmlGear.SelectNodes("addoncategory"))
                            strCategories += objXmlCategory.InnerText + ",";
                        // Remove the trailing comma.
                        strCategories = strCategories.Substring(0, strCategories.Length - 1);
                        frmPickGear.AllowedCategories = strCategories;
                    }
                }
            }
            catch
            {
            }

            frmPickGear.ShowDialog(this);

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

            TreeNode objNode = new TreeNode();

            // Open the Cyberware XML file and locate the selected piece.
            objXmlDocument = XmlManager.Instance.Load("gear.xml");
            objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Gear objNewGear = new Gear(_objCharacter);

            objNewGear.DiscountCost = frmPickGear.BlackMarketDiscount;

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlinks":
                case "Cyberdecks":
                case "Rigger Command Consoles":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        nudGearQty.Increment = objCommlink.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                    }
                    catch
                    {
                    }

                    objNewGear = objCommlink;
                    break;
                default:
                    Gear objGear = new Gear(_objCharacter);
                    objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", false, false, true, true, frmPickGear.Aerodynamic);
                    objGear.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        nudGearQty.Increment = objGear.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                    }
                    catch
                    {
                    }

                    objNewGear = objGear;
                    break;
            }

            if (objNewGear.InternalId == Guid.Empty.ToString())
                return false;

            if (!blnNullParent)
                objNewGear.Parent = objSelectedGear;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objNewGear.Cost = "0";
                objNewGear.Cost3 = "0";
                objNewGear.Cost6 = "0";
                objNewGear.Cost10 = "0";
            }

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

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

            bool blnMatchFound = false;
            // If this is Ammunition, see if the character already has it on them.
            if (objNewGear.Category == "Ammunition")
            {
                foreach (Gear objCharacterGear in _objCharacter.Gear)
                {
                    if (objCharacterGear.Name == objNewGear.Name && objCharacterGear.Category == objNewGear.Category && objCharacterGear.Rating == objNewGear.Rating && objCharacterGear.Extra == objNewGear.Extra)
                    {
                        // A match was found, so increase the quantity instead.
                        objCharacterGear.Quantity += objNewGear.Quantity;
                        blnMatchFound = true;

                        foreach (TreeNode objGearNode in treGear.Nodes[0].Nodes)
                        {
                            if (objCharacterGear.InternalId == objGearNode.Tag.ToString())
                            {
                                objGearNode.Text = objCharacterGear.DisplayName;
                                treGear.SelectedNode = objGearNode;
                                break;
                            }
                        }

                        break;
                    }
                }
            }

            // Add the Gear.
            if (!blnMatchFound)
            {
                if (objSelectedGear.Name == string.Empty)
                {
                    objNode.ContextMenuStrip = cmsArmorGear;
                    treArmor.SelectedNode.Nodes.Add(objNode);
                    treArmor.SelectedNode.Expand();
                    objSelectedArmor.Gear.Add(objNewGear);
                }
                else
                {
                    objNode.ContextMenuStrip = cmsArmorGear;
                    treArmor.SelectedNode.Nodes.Add(objNode);
                    treArmor.SelectedNode.Expand();
                    objSelectedGear.Children.Add(objNewGear);
                }

                // Select the node that was just added.
                treGear.SelectedNode = objNode;
            }

            UpdateCharacterInfo();
            RefreshSelectedArmor();

            _blnIsDirty = true;
            UpdateWindowTitle();

            return frmPickGear.AddAgain;
        }
Beispiel #16
0
        /// <summary>
        /// Select a piece of Gear to be added to the character.
        /// </summary>
        private bool PickGear()
        {
            bool blnNullParent = false;
            Gear objSelectedGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);
            if (objSelectedGear == null)
            {
                objSelectedGear = new Gear(_objCharacter);
                blnNullParent = true;
            }

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

            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSelectedGear.Name + "\" and category = \"" + objSelectedGear.Category + "\"]");

            bool blnFakeCareerMode = false;
            if (_objCharacter.Metatype == "A.I." || _objCharacter.MetatypeCategory == "Technocritters" || _objCharacter.MetatypeCategory == "Protosapients")
                blnFakeCareerMode = true;
            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, blnFakeCareerMode, objSelectedGear.ChildAvailModifier, objSelectedGear.ChildCostMultiplier);
            try
            {
                if (treGear.SelectedNode.Level > 0)
                {
                    if (objXmlGear.InnerXml.Contains("<addoncategory>"))
                    {
                        string strCategories = "";
                        foreach (XmlNode objXmlCategory in objXmlGear.SelectNodes("addoncategory"))
                            strCategories += objXmlCategory.InnerText + ",";
                        // Remove the trailing comma.
                        strCategories = strCategories.Substring(0, strCategories.Length - 1);
                        frmPickGear.AllowedCategories = strCategories;
                    }

                    // If the Gear has a Capacity with no brackets (meaning it grants Capacity), show only Subsystems (those that conume Capacity).
                    if (!objSelectedGear.Capacity.Contains('['))
                        frmPickGear.MaximumCapacity = objSelectedGear.CapacityRemaining;

                    if (objSelectedGear.Category == "Commlinks" || objSelectedGear.Category == "Cyberdecks")
                    {
                        Commlink objCommlink = (Commlink)objSelectedGear;
                        frmPickGear.CommlinkResponse = objCommlink.DeviceRating;
                    }
                }
            }
            catch
            {
            }

            frmPickGear.ShowDialog(this);

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

            TreeNode objNode = new TreeNode();

            // Open the Cyberware XML file and locate the selected piece.
            objXmlDocument = XmlManager.Instance.Load("gear.xml");
            objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Gear objNewGear = new Gear(_objCharacter);

            objNewGear.DiscountCost = frmPickGear.BlackMarketDiscount;

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlinks":
                case "Cyberdecks":
                case "Rigger Command Consoles":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        _blnSkipRefresh = true;
                        nudGearQty.Increment = objCommlink.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                        _blnSkipRefresh = false;
                    }
                    catch
                    {
                    }
                    objNode.Text = objCommlink.DisplayName;

                    // If a Commlink has just been added, see if the character already has one. If not, make it the active Commlink.
                    if (_objFunctions.FindCharacterCommlinks(_objCharacter.Gear).Count == 0 && frmPickGear.SelectedCategory == "Commlinks")
                        objCommlink.IsActive = true;

                    objNewGear = objCommlink;
                    break;
                default:
                    Gear objGear = new Gear(_objCharacter);
                    objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objGear.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        _blnSkipRefresh = true;
                        nudGearQty.Increment = objGear.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                        _blnSkipRefresh = false;
                    }
                    catch
                    {
                    }
                    objNode.Text = objGear.DisplayName;

                    objNewGear = objGear;
                    break;
            }

            if (objNewGear.InternalId == Guid.Empty.ToString())
                return false;

            // reduce the cost for Black Market Pipeline
            objNewGear.DiscountCost = frmPickGear.BlackMarketDiscount;
            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objNewGear.Cost != "")
                    objNewGear.Cost = "(" + objNewGear.Cost + ") * 0.1";
                if (objNewGear.Cost3 != "")
                    objNewGear.Cost3 = "(" + objNewGear.Cost3 + ") * 0.1";
                if (objNewGear.Cost6 != "")
                    objNewGear.Cost6 = "(" + objNewGear.Cost6 + ") * 0.1";
                if (objNewGear.Cost10 != "")
                    objNewGear.Cost10 = "(" + objNewGear.Cost10 + ") * 0.1";
                if (objNewGear.Extra == "")
                    objNewGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objNewGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objNewGear.Cost = "0";
                objNewGear.Cost3 = "0";
                objNewGear.Cost6 = "0";
                objNewGear.Cost10 = "0";
            }

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

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

            objNewGear.Parent = objSelectedGear;
            if (blnNullParent)
                objNewGear.Parent = null;

            try
            {
                if (treGear.SelectedNode.Level > 0)
                {
                    objNode.ContextMenuStrip = cmsGear;
                    treGear.SelectedNode.Nodes.Add(objNode);
                    treGear.SelectedNode.Expand();
                    objSelectedGear.Children.Add(objNewGear);
                }
                else
                {
                    objNode.ContextMenuStrip = cmsGear;
                    treGear.Nodes[0].Nodes.Add(objNode);
                    treGear.Nodes[0].Expand();
                    _objCharacter.Gear.Add(objNewGear);
                }
            }
            catch
            {
                treGear.Nodes[0].Nodes.Add(objNode);
                treGear.Nodes[0].Expand();
                _objCharacter.Gear.Add(objNewGear);
            }

            // Select the node that was just added.
            if (objNode.Level < 2)
                treGear.SelectedNode = objNode;

            UpdateCharacterInfo();
            RefreshSelectedGear();

            _blnIsDirty = true;
            UpdateWindowTitle();

            return frmPickGear.AddAgain;
        }
Beispiel #17
0
        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
                    {
                    }
                }
            }
        }
Beispiel #18
0
        private void cmdGearSplitQty_Click(object sender, EventArgs e)
        {
            // This can only be done with the first level of Nodes.
            try
            {
                if (treGear.SelectedNode.Level != 1)
                    return;
            }
            catch
            {
                return;
            }

            Gear objSelectedGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);

            // Cannot split a stack of 1 item.
            if (objSelectedGear.Quantity == 1)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_CannotSplitGear"), LanguageManager.Instance.GetString("MessageTitle_CannotSplitGear"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            frmSelectNumber frmPickNumber = new frmSelectNumber();
            frmPickNumber.Minimum = 1;
            frmPickNumber.Maximum = objSelectedGear.Quantity - 1;
            frmPickNumber.Description = LanguageManager.Instance.GetString("String_SplitGear");
            frmPickNumber.ShowDialog(this);

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

            // Create a new piece of Gear.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");
            XmlNode objNode = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSelectedGear.Name + "\" and category = \"" + objSelectedGear.Category + "\"]");

            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.Quantity = frmPickNumber.SelectedValue;
            objGear.Equipped = objSelectedGear.Equipped;
            objGear.Location = objSelectedGear.Location;
            objGear.Notes = objSelectedGear.Notes;
            objGearNode.Text = objGear.DisplayName;
            objGearNode.ContextMenuStrip = treGear.SelectedNode.ContextMenuStrip;

            // Update the selected item.
            objSelectedGear.Quantity -= frmPickNumber.SelectedValue;
            treGear.SelectedNode.Text = objSelectedGear.DisplayName;

            treGear.SelectedNode.Parent.Nodes.Add(objGearNode);
            _objCharacter.Gear.Add(objGear);

            // Create any Weapons that came with this Gear.
            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();
            }

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Beispiel #19
0
 /// <summary>
 /// Save the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public void Save(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("armor");
     objWriter.WriteElementString("guid", _guiID.ToString());
     objWriter.WriteElementString("name", _strName);
     objWriter.WriteElementString("category", _strCategory);
     objWriter.WriteElementString("armor", _strA);
     objWriter.WriteElementString("armoroverride", _strO);
     objWriter.WriteElementString("armorcapacity", _strArmorCapacity);
     objWriter.WriteElementString("avail", _strAvail);
     objWriter.WriteElementString("cost", _strCost);
     objWriter.WriteElementString("source", _strSource);
     objWriter.WriteElementString("page", _strPage);
     objWriter.WriteElementString("armorname", _strArmorName);
     objWriter.WriteElementString("equipped", _blnEquipped.ToString());
     objWriter.WriteElementString("extra", _strExtra);
     objWriter.WriteElementString("damage", _intDamage.ToString());
     objWriter.WriteElementString("rating", _intRating.ToString());
     objWriter.WriteElementString("rating", _intMaxRating.ToString());
     objWriter.WriteStartElement("armormods");
     foreach (ArmorMod objMod in _lstArmorMods)
     {
         objMod.Save(objWriter);
     }
     objWriter.WriteEndElement();
     if (_lstGear.Count > 0)
     {
         objWriter.WriteStartElement("gears");
         foreach (Gear objGear in _lstGear)
         {
             // Use the Gear's SubClass if applicable.
             if (objGear.GetType() == typeof(Commlink))
             {
                 Commlink objCommlink = new Commlink(_objCharacter);
                 objCommlink = (Commlink)objGear;
                 objCommlink.Save(objWriter);
             }
             else
             {
                 objGear.Save(objWriter);
             }
         }
         objWriter.WriteEndElement();
     }
     if (_nodBonus != null)
         objWriter.WriteRaw(_nodBonus.OuterXml);
     else
         objWriter.WriteElementString("bonus", "");
     objWriter.WriteElementString("location", _strLocation);
     objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteElementString("discountedcost", DiscountCost.ToString());
     objWriter.WriteEndElement();
     _objCharacter.SourceProcess(_strSource);
 }
Beispiel #20
0
        private void tsWeaponAccessoryAddGear_Click(object sender, EventArgs e)
        {
            WeaponAccessory objAccessory = _objFunctions.FindWeaponAccessory(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);

            // Make sure the Weapon Accessory is allowed to accept Gear.
            if (objAccessory.AllowGear == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_WeaponGear"), LanguageManager.Instance.GetString("MessageTitle_CyberwareGear"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true);
            string strCategories = "";
            foreach (XmlNode objXmlCategory in objAccessory.AllowGear)
                strCategories += objXmlCategory.InnerText + ",";
            frmPickGear.AllowedCategories = strCategories;
            frmPickGear.ShowDialog(this);

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

            TreeNode objNode = new TreeNode();

            // Open the Gear XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");
            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Gear objNewGear = new Gear(_objCharacter);
            switch (frmPickGear.SelectedCategory)
            {
                case "Commlinks":
                case "Cyberdecks":
                case "Rigger Command Consoles":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objCommlink.DisplayName;

                    objNewGear = objCommlink;
                    break;
                default:
                    Gear objGear = new Gear(_objCharacter);
                    objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objGear.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objGear.DisplayName;

                    objNewGear = objGear;
                    break;
            }

            if (objNewGear.InternalId == Guid.Empty.ToString())
                return;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objNewGear.Cost != "")
                    objNewGear.Cost = "(" + objNewGear.Cost + ") * 0.1";
                if (objNewGear.Cost3 != "")
                    objNewGear.Cost3 = "(" + objNewGear.Cost3 + ") * 0.1";
                if (objNewGear.Cost6 != "")
                    objNewGear.Cost6 = "(" + objNewGear.Cost6 + ") * 0.1";
                if (objNewGear.Cost10 != "")
                    objNewGear.Cost10 = "(" + objNewGear.Cost10 + ") * 0.1";
                if (objNewGear.Extra == "")
                    objNewGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objNewGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objNewGear.Cost = "0";
                objNewGear.Cost3 = "0";
                objNewGear.Cost6 = "0";
                objNewGear.Cost10 = "0";
            }

            int intCost = objNewGear.TotalCost;

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

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

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

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddWeaponGear, objNewGear.InternalId, 1);
                    objExpense.Undo = objUndo;
                }
            }

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

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

            objAccessory.Gear.Add(objNewGear);

            objNode.ContextMenuStrip = cmsWeaponAccessoryGear;
            treWeapons.SelectedNode.Nodes.Add(objNode);
            treWeapons.SelectedNode.Expand();

            UpdateCharacterInfo();

            if (frmPickGear.AddAgain)
                tsWeaponAccessoryAddGear_Click(sender, e);

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Beispiel #21
0
        private void tsVehicleAddGear_Click(object sender, EventArgs e)
        {
            // Make sure a parent items is selected, then open the Select Gear window.
            try
            {
                if (treVehicles.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

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

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

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter);
            //frmPickGear.ShowPositiveCapacityOnly = true;
            frmPickGear.ShowDialog(this);

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

            // Open the Gear XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");
            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            Gear objGear = new Gear(_objCharacter);

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlinks":
                case "Cyberdecks":
                case "Rigger Command Consoles":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, false);
                    objCommlink.DiscountCost = frmPickGear.BlackMarketDiscount;

                    objGear = objCommlink;
                    break;
                default:
                    Gear objNewGear = new Gear(_objCharacter);
                    objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, false, true, frmPickGear.Aerodynamic);
                    objNewGear.Quantity = frmPickGear.SelectedQty;

                    objGear = objNewGear;
                    break;
            }

            objGear.DiscountCost = frmPickGear.BlackMarketDiscount;

            if (objGear.InternalId == Guid.Empty.ToString())
                return;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objGear.Cost = (Convert.ToDouble(objGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objGear.Cost != "")
                    objGear.Cost = "(" + objGear.Cost + ") * 0.1";
                if (objGear.Cost3 != "")
                    objGear.Cost3 = "(" + objGear.Cost3 + ") * 0.1";
                if (objGear.Cost6 != "")
                    objGear.Cost6 = "(" + objGear.Cost6 + ") * 0.1";
                if (objGear.Cost10 != "")
                    objGear.Cost10 = "(" + objGear.Cost10 + ") * 0.1";
                if (objGear.Extra == "")
                    objGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objGear.Cost = "0";
                objGear.Cost3 = "0";
                objGear.Cost6 = "0";
                objGear.Cost10 = "0";
            }

            objGear.Quantity = frmPickGear.SelectedQty;
            objNode.Text = objGear.DisplayName;
            try
            {
                nudVehicleRating.Increment = objGear.CostFor;
                nudVehicleRating.Minimum = nudGearQty.Increment;
            }
            catch
            {
            }

            // Change the cost of the Sensor itself to 0.
            //if (frmPickGear.SelectedCategory == "Sensors")
            //{
            //    objGear.Cost = "0";
            //    objGear.Cost3 = "0";
            //    objGear.Cost6 = "0";
            //    objGear.Cost10 = "0";
            //}

            objNode.ContextMenuStrip = cmsVehicleGear;

            bool blnMatchFound = false;
            // If this is Ammunition, see if the character already has it on them.
            if (objGear.Category == "Ammunition")
            {
                foreach (Gear objVehicleGear in objSelectedVehicle.Gear)
                {
                    if (objVehicleGear.Name == objGear.Name && objVehicleGear.Category == objGear.Category && objVehicleGear.Rating == objGear.Rating && objVehicleGear.Extra == objGear.Extra)
                    {
                        // A match was found, so increase the quantity instead.
                        objVehicleGear.Quantity += objGear.Quantity;
                        blnMatchFound = true;

                        foreach (TreeNode objGearNode in treVehicles.SelectedNode.Nodes)
                        {
                            if (objVehicleGear.InternalId == objGearNode.Tag.ToString())
                            {
                                objGearNode.Text = objVehicleGear.DisplayName;
                                break;
                            }
                        }

                        break;
                    }
                }
            }

            if (!blnMatchFound)
            {
                treVehicles.SelectedNode.Nodes.Add(objNode);
                treVehicles.SelectedNode.Expand();

                // Add the Gear to the Vehicle.
                objSelectedVehicle.Gear.Add(objGear);
            }

            if (frmPickGear.AddAgain)
                tsVehicleAddGear_Click(sender, e);

            UpdateCharacterInfo();
            RefreshSelectedVehicle();
        }
Beispiel #22
0
        /// <summary>
        /// Load the CharacterAttribute from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        /// <param name="blnCopy">Whether or not we are copying an existing node.</param>
        public void Load(XmlNode objNode, bool blnCopy = false)
        {
            if (blnCopy)
            {
                _guiID = Guid.NewGuid();
            }
            else
            {
                _guiID = Guid.Parse(objNode["guid"].InnerText);
            }
            objNode.TryGetStringFieldQuickly("name", ref _strName);
            objNode.TryGetStringFieldQuickly("category", ref _strCategory);
            objNode.TryGetInt32FieldQuickly("armor", ref _intA);
            objNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity);
            objNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity);
            objNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating);
            objNode.TryGetInt32FieldQuickly("rating", ref _intRating);
            objNode.TryGetStringFieldQuickly("avail", ref _strAvail);
            objNode.TryGetStringFieldQuickly("cost", ref _strCost);
            _nodBonus         = objNode["bonus"];
            _nodWirelessBonus = objNode["wirelessbonus"];
            objNode.TryGetStringFieldQuickly("source", ref _strSource);
            objNode.TryGetStringFieldQuickly("page", ref _strPage);
            objNode.TryGetBoolFieldQuickly("included", ref _blnIncludedInArmor);
            objNode.TryGetBoolFieldQuickly("equipped", ref _blnEquipped);
            if (!objNode.TryGetBoolFieldQuickly("wirelesson", ref _blnWirelessOn))
            {
                _blnWirelessOn = _nodWirelessBonus != null;
            }
            objNode.TryGetStringFieldQuickly("extra", ref _strExtra);
            if (objNode["weaponguid"] != null)
            {
                _guiWeaponID = Guid.Parse(objNode["weaponguid"].InnerText);
            }
            objNode.TryGetStringFieldQuickly("notes", ref _strNotes);

            objNode.TryGetBoolFieldQuickly("discountedcost", ref _blnDiscountCost);

            if (objNode.InnerXml.Contains("gears"))
            {
                XmlNodeList nodGears = objNode.SelectNodes("gears/gear");
                foreach (XmlNode nodGear in nodGears)
                {
                    if (nodGear["iscommlink"]?.InnerText == System.Boolean.TrueString || (nodGear["category"].InnerText == "Commlinks" ||
                                                                                          nodGear["category"].InnerText == "Commlink Accessories" || nodGear["category"].InnerText == "Cyberdecks" || nodGear["category"].InnerText == "Rigger Command Consoles"))
                    {
                        Gear objCommlink = new Commlink(_objCharacter);
                        objCommlink.Load(nodGear, blnCopy);
                        _lstGear.Add(objCommlink);
                    }
                    else
                    {
                        Gear objGear = new Gear(_objCharacter);
                        objGear.Load(nodGear, blnCopy);
                        _lstGear.Add(objGear);
                    }
                }
            }
            if (GlobalOptions.Language != GlobalOptions.DefaultLanguage)
            {
                XmlNode objArmorNode = MyXmlNode;
                if (objArmorNode != null)
                {
                    objArmorNode.TryGetStringFieldQuickly("translate", ref _strAltName);
                    objArmorNode.TryGetStringFieldQuickly("altpage", ref _strAltPage);
                }

                XmlDocument objXmlDocument = XmlManager.Load("armor.xml");
                objArmorNode    = objXmlDocument.SelectSingleNode("/chummer/categories/category[. = \"" + _strCategory + "\"]");
                _strAltCategory = objArmorNode?.Attributes?["translate"]?.InnerText;
            }
        }
Beispiel #23
0
        private void tsWeaponAccessoryAddGear_Click(object sender, EventArgs e)
        {
            WeaponAccessory objAccessory = _objFunctions.FindWeaponAccessory(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons);

            // Make sure the Weapon Accessory is allowed to accept Gear.
            if (objAccessory.AllowGear == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_WeaponGear"), LanguageManager.Instance.GetString("MessageTitle_CyberwareGear"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, false);
            string strCategories = "";
            foreach (XmlNode objXmlCategory in objAccessory.AllowGear)
                strCategories += objXmlCategory.InnerText + ",";
            frmPickGear.AllowedCategories = strCategories;
            frmPickGear.ShowDialog(this);

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

            TreeNode objNode = new TreeNode();

            // Open the Gear XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");
            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            Gear objNewGear = new Gear(_objCharacter);
            switch (frmPickGear.SelectedCategory)
            {
                case "Commlinks":
                case "Cyberdecks":
                case "Rigger Command Consoles":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        _blnSkipRefresh = true;
                        nudGearQty.Increment = objCommlink.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                        _blnSkipRefresh = false;
                    }
                    catch
                    {
                    }
                    objNode.Text = objCommlink.DisplayName;

                    objNewGear = objCommlink;
                    break;
                default:
                    Gear objGear = new Gear(_objCharacter);
                    objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objGear.Quantity = frmPickGear.SelectedQty;
                    try
                    {
                        _blnSkipRefresh = true;
                        nudGearQty.Increment = objGear.CostFor;
                        //nudGearQty.Minimum = nudGearQty.Increment;
                        _blnSkipRefresh = false;
                    }
                    catch
                    {
                    }
                    objNode.Text = objGear.DisplayName;

                    objNewGear = objGear;
                    break;
            }

            if (objNewGear.InternalId == Guid.Empty.ToString())
                return;
            objNewGear.DiscountCost = frmPickGear.BlackMarketDiscount;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objNewGear.Cost = (Convert.ToDouble(objNewGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objNewGear.Cost != "")
                    objNewGear.Cost = "(" + objNewGear.Cost + ") * 0.1";
                if (objNewGear.Cost3 != "")
                    objNewGear.Cost3 = "(" + objNewGear.Cost3 + ") * 0.1";
                if (objNewGear.Cost6 != "")
                    objNewGear.Cost6 = "(" + objNewGear.Cost6 + ") * 0.1";
                if (objNewGear.Cost10 != "")
                    objNewGear.Cost10 = "(" + objNewGear.Cost10 + ") * 0.1";
                if (objNewGear.Extra == "")
                    objNewGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objNewGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objNewGear.Cost = "0";
                objNewGear.Cost3 = "0";
                objNewGear.Cost6 = "0";
                objNewGear.Cost10 = "0";
            }

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

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

            objAccessory.Gear.Add(objNewGear);

            objNode.ContextMenuStrip = cmsWeaponAccessoryGear;
            treWeapons.SelectedNode.Nodes.Add(objNode);
            treWeapons.SelectedNode.Expand();

            UpdateCharacterInfo();

            if (frmPickGear.AddAgain)
                tsWeaponAccessoryAddGear_Click(sender, e);

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Beispiel #24
0
        private void cmdGearMoveToVehicle_Click(object sender, EventArgs e)
        {
            frmSelectItem frmPickItem = new frmSelectItem();
            frmPickItem.Vehicles = _objCharacter.Vehicles;
            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;
                }
            }

            Gear objSelectedGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);
            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 Vehicle already has a matching piece of Gear.
            bool blnMatch = false;
            Gear objFoundGear = new Gear(_objCharacter);
            foreach (Gear objVehicleGear in objVehicle.Gear)
            {
                if (objVehicleGear.Name == objSelectedGear.Name && objVehicleGear.Category == objSelectedGear.Category && objVehicleGear.Rating == objSelectedGear.Rating && objVehicleGear.Extra == objSelectedGear.Extra && objVehicleGear.GearName == objSelectedGear.GearName && objVehicleGear.Notes == objSelectedGear.Notes)
                {
                    blnMatch = true;
                    objFoundGear = objVehicleGear;
                    if (objVehicleGear.Children.Count == objSelectedGear.Children.Count)
                    {
                        for (int i = 0; i <= objVehicleGear.Children.Count - 1; i++)
                        {
                            if (objVehicleGear.Children[i].Name != objSelectedGear.Children[i].Name || objVehicleGear.Children[i].Extra != objSelectedGear.Children[i].Extra || objVehicleGear.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;
                objGear.Location = string.Empty;
                objGearNode.Text = objGear.DisplayName;
                objGearNode.ContextMenuStrip = cmsVehicleGear;

                // Locate the Node for the selected Vehicle.
                TreeNode nodParent = new TreeNode();
                foreach (TreeNode nodNode in treVehicles.Nodes[0].Nodes)
                {
                    if (nodNode.Tag.ToString() == objVehicle.InternalId)
                    {
                        nodParent = nodNode;
                        break;
                    }
                }

                nodParent.Nodes.Add(objGearNode);
                objVehicle.Gear.Add(objGear);
            }
            else
            {
                // Everything matches up, so just increase the quantity.
                objFoundGear.Quantity += intMove;
                foreach (TreeNode nodVehicle in treVehicles.Nodes[0].Nodes)
                {
                    if (nodVehicle.Tag.ToString() == objVehicle.InternalId)
                    {
                        foreach (TreeNode nodGear in nodVehicle.Nodes)
                        {
                            if (nodGear.Tag.ToString() == objFoundGear.InternalId)
                                nodGear.Text = objFoundGear.DisplayName;
                        }
                    }
                }
            }

            // Update the selected item.
            objSelectedGear.Quantity -= intMove;
            if (objSelectedGear.Quantity == 0)
            {
                if (objSelectedGear.Parent != null)
                    objSelectedGear.Parent.Children.Remove(objSelectedGear);
                else
                    _objCharacter.Gear.Remove(objSelectedGear);
                _objFunctions.DeleteGear(objSelectedGear, treWeapons, _objImprovementManager);
                treGear.SelectedNode.Remove();
                UpdateCharacterInfo();
            }
            else
            {
                treGear.SelectedNode.Text = objSelectedGear.DisplayName;
            }

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Beispiel #25
0
        private void tsWeaponAccessoryGearMenuAddAsPlugin_Click(object sender, EventArgs e)
        {
            // Locate the Vehicle Sensor Gear.
            bool blnFound = false;
            WeaponAccessory objFoundAccessory = new WeaponAccessory(_objCharacter);
            Gear objSensor = _objFunctions.FindWeaponGear(treWeapons.SelectedNode.Tag.ToString(), _objCharacter.Weapons, out objFoundAccessory);
            if (objSensor != null)
                blnFound = true;

            // Make sure the Gear was found.
            if (!blnFound)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_ModifyVehicleGear"), LanguageManager.Instance.GetString("MessageTitle_SelectGear"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

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

            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSensor.Name + "\" and category = \"" + objSensor.Category + "\"]");

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter);
            //frmPickGear.ShowNegativeCapacityOnly = true;

            if (objXmlGear.InnerXml.Contains("<addoncategory>"))
            {
                string strCategories = "";
                foreach (XmlNode objXmlCategory in objXmlGear.SelectNodes("addoncategory"))
                    strCategories += objXmlCategory.InnerText + ",";
                // Remove the trailing comma.
                strCategories = strCategories.Substring(0, strCategories.Length - 1);
                frmPickGear.AllowedCategories = strCategories;
            }

            frmPickGear.ShowDialog(this);

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

            // Open the Gear XML file and locate the selected piece.
            objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            Gear objGear = new Gear(_objCharacter);

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlinks":
                case "Cyberdecks":
                case "Rigger Command Consoles":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objCommlink.DisplayName;

                    objGear = objCommlink;
                    break;
                default:
                    Gear objNewGear = new Gear(_objCharacter);
                    objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objNewGear.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objNewGear.DisplayName;

                    objGear = objNewGear;
                    break;
            }

            if (objGear.InternalId == Guid.Empty.ToString())
                return;

            objGear.DiscountCost = frmPickGear.BlackMarketDiscount;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objGear.Cost = (Convert.ToDouble(objGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objGear.Cost != "")
                    objGear.Cost = "(" + objGear.Cost + ") * 0.1";
                if (objGear.Cost3 != "")
                    objGear.Cost3 = "(" + objGear.Cost3 + ") * 0.1";
                if (objGear.Cost6 != "")
                    objGear.Cost6 = "(" + objGear.Cost6 + ") * 0.1";
                if (objGear.Cost10 != "")
                    objGear.Cost10 = "(" + objGear.Cost10 + ") * 0.1";
                if (objGear.Extra == "")
                    objGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objGear.Cost = "0";
                objGear.Cost3 = "0";
                objGear.Cost6 = "0";
                objGear.Cost10 = "0";
            }

            objNode.Text = objGear.DisplayName;

            objNode.ContextMenuStrip = cmsWeaponAccessoryGear;

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

            objGear.Parent = objSensor;
            objSensor.Children.Add(objGear);

            if (frmPickGear.AddAgain)
                tsWeaponAccessoryGearMenuAddAsPlugin_Click(sender, e);

            UpdateCharacterInfo();
            RefreshSelectedWeapon();
        }
Beispiel #26
0
        /// <summary>
        /// Load the Gear from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        public new void Load(XmlNode objNode, bool blnCopy = false)
        {
            _guiID       = Guid.Parse(objNode["guid"].InnerText);
            _strName     = objNode["name"].InnerText;
            _strCategory = objNode["category"].InnerText;
            objNode.TryGetField("armorcapacity", out _strArmorCapacity).ToString();
            _intMaxRating = Convert.ToInt32(objNode["maxrating"].InnerText);
            _intRating    = Convert.ToInt32(objNode["rating"].InnerText);
            _intQty       = Convert.ToInt32(objNode["qty"].InnerText);
            _strAvail     = objNode["avail"].InnerText;
            _strCost      = objNode["cost"].InnerText;
            _strExtra     = objNode["extra"].InnerText;
            objNode.TryGetField("overclocked", out _strOverclocked);
            objNode.TryGetField("bonded", out _blnBonded);
            objNode.TryGetField("equipped", out _blnEquipped);
            objNode.TryGetField("homenode", out _blnHomeNode);
            _nodBonus  = objNode["bonus"];
            _strSource = objNode["source"].InnerText;
            objNode.TryGetField("page", out _strPage);
            _intDeviceRating = Convert.ToInt32(objNode["devicerating"].InnerText);
            objNode.TryGetField("attack", out _intAttack);
            objNode.TryGetField("sleaze", out _intSleaze);
            objNode.TryGetField("dataprocessing", out _intDataProcessing);
            objNode.TryGetField("firewall", out _intFirewall);
            objNode.TryGetField("gearname", out _strGearName);

            if (objNode.InnerXml.Contains("<gear>"))
            {
                XmlNodeList nodChildren = objNode.SelectNodes("children/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);
                        objCommlink.Parent = this;
                        _objChildren.Add(objCommlink);
                        break;

                    default:
                        Gear objGear = new Gear(_objCharacter);
                        objGear.Load(nodChild, blnCopy);
                        objGear.Parent = this;
                        _objChildren.Add(objGear);
                        break;
                    }
                }
            }
            objNode.TryGetField("location", out _strLocation);
            objNode.TryGetField("notes", out _strNotes);
            objNode.TryGetField("discountedcost", out _blnDiscountCost);
            objNode.TryGetField("active", out _blnActiveCommlink);

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

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

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

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

            if (blnCopy)
            {
                _guiID       = Guid.NewGuid();
                _strLocation = string.Empty;
                _blnHomeNode = false;
            }
        }
Beispiel #27
0
        /// <summary>
        /// Add a piece of Gear that was found in a PACKS Kit.
        /// </summary>
        /// <param name="objXmlGearDocument">XmlDocument that contains the Gear.</param>
        /// <param name="objXmlGear">XmlNode of the Gear to add.</param>
        /// <param name="objParent">TreeNode to attach the created items to.</param>
        /// <param name="objParentObject">Object to associate the newly-created items with.</param>
        /// <param name="cmsContextMenu">ContextMenuStrip to assign to the TreeNodes created.</param>
        /// <param name="blnCreateChildren">Whether or not the default plugins for the Gear should be created.</param>
        private void AddPACKSGear(XmlDocument objXmlGearDocument, XmlNode objXmlGear, TreeNode objParent, Object objParentObject, ContextMenuStrip cmsContextMenu, bool blnCreateChildren)
        {
            int intRating = 0;
            if (objXmlGear["rating"] != null)
                intRating = Convert.ToInt32(objXmlGear["rating"].InnerText);
            int intQty = 1;
            if (objXmlGear["qty"] != null)
                intQty = Convert.ToInt32(objXmlGear["qty"].InnerText);

            XmlNode objXmlGearNode;
            if (objXmlGear["category"] != null)
                objXmlGearNode = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear["name"].InnerText + "\" and category = \"" + objXmlGear["category"].InnerText + "\"]");
            else
                objXmlGearNode = objXmlGearDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objXmlGear["name"].InnerText + "\"]");

            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            string strForceValue = "";
            if (objXmlGear["name"].Attributes["select"] != null)
                strForceValue = objXmlGear["name"].Attributes["select"].InnerText;

            Gear objNewGear = new Gear(_objCharacter);
            if (objXmlGearNode != null)
            {
                switch (objXmlGearNode["category"].InnerText)
                {
                    case "Commlinks":
                    case "Cyberdecks":
                    case "Rigger Command Consoles":
                        Commlink objCommlink = new Commlink(_objCharacter);
                        objCommlink.Create(objXmlGearNode, _objCharacter, objNode, intRating, true, blnCreateChildren);
                        objCommlink.Quantity = intQty;
                        objNewGear = objCommlink;
                        break;
                    default:
                        Gear objGear = new Gear(_objCharacter);
                        objGear.Create(objXmlGearNode, _objCharacter, objNode, intRating, objWeapons, objWeaponNodes, strForceValue, false, false, true, blnCreateChildren);
                        objGear.Quantity = intQty;
                        objNode.Text = objGear.DisplayName;
                        objNewGear = objGear;
                        break;
                }
            }

            if (objParentObject.GetType() == typeof(Character))
                ((Character)objParentObject).Gear.Add(objNewGear);
            if (objParentObject.GetType() == typeof(Gear) || objParentObject.GetType() == typeof(Commlink) || objParentObject.GetType() == typeof(OperatingSystem))
            {
                ((Gear)objParentObject).Children.Add(objNewGear);
                objNewGear.Parent = (Gear)objParentObject;
            }
            if (objParentObject.GetType() == typeof(Armor))
                ((Armor)objParentObject).Gear.Add(objNewGear);
            if (objParentObject.GetType() == typeof(WeaponAccessory))
                ((WeaponAccessory)objParentObject).Gear.Add(objNewGear);
            if (objParentObject.GetType() == typeof(Cyberware))
                ((Cyberware)objParentObject).Gear.Add(objNewGear);

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

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

            objNode.ContextMenuStrip = cmsContextMenu;
            objNode.Text = objNewGear.DisplayName;

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

            foreach (TreeNode objWeaponNode in objWeaponNodes)
            {
                objWeaponNode.ContextMenuStrip = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }
        }
Beispiel #28
0
        /// <summary>
        /// Load the CharacterAttribute from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        /// <param name="blnCopy">Whether another node is being copied.</param>
        public void Load(XmlNode objNode, bool blnCopy = false)
        {
            _guiID    = Guid.Parse(objNode["guid"].InnerText);
            _strName  = objNode["name"].InnerText;
            _strMount = objNode["mount"].InnerText;
            objNode.TryGetField("extramount", out _strExtraMount, "");
            _strRC = objNode["rc"].InnerText;
            objNode.TryGetField("rating", out _intRating, 0);
            objNode.TryGetField("rcgroup", out _intRCGroup, 0);
            objNode.TryGetField("accuracy", out _intAccuracy, 0);
            objNode.TryGetField("rating", out _intRating, 0);
            objNode.TryGetField("rating", out _intRating, 0);
            objNode.TryGetField("conceal", out _strConceal, "0");
            objNode.TryGetField("rcdeployable", out _blnDeployable);
            _strAvail            = objNode["avail"].InnerText;
            _strCost             = objNode["cost"].InnerText;
            _blnIncludedInWeapon = Convert.ToBoolean(objNode["included"].InnerText);
            objNode.TryGetField("installed", out _blnInstalled, true);
            try
            {
                _nodAllowGear = objNode["allowgear"];
            }
            catch
            {
            }
            _strSource = objNode["source"].InnerText;

            objNode.TryGetField("page", out _strPage, "0");
            objNode.TryGetField("dicepool", out _strDicePool, "0");

            if (objNode.InnerXml.Contains("ammoslots"))
            {
                objNode.TryGetField("ammoslots", out _intAmmoSlots, 0);                  //TODO: Might work if 0 -> 1
            }


            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;
                    }
                }
            }
            objNode.TryGetField("notes", out _strNotes, "");
            objNode.TryGetField("discountedcost", out _blnDiscountCost, false);

            if (GlobalOptions.Instance.Language != "en-us")
            {
                XmlDocument objXmlDocument   = XmlManager.Instance.Load("weapons.xml");
                XmlNode     objAccessoryNode = objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + _strName + "\"]");
                if (objAccessoryNode != null)
                {
                    if (objAccessoryNode["translate"] != null)
                    {
                        _strAltName = objAccessoryNode["translate"].InnerText;
                    }
                    if (objAccessoryNode["altpage"] != null)
                    {
                        _strAltPage = objAccessoryNode["altpage"].InnerText;
                    }
                }
            }
            if (objNode["damage"] != null)
            {
                _strDamage = objNode["damage"].InnerText;
            }
            if (objNode["damagetype"] != null)
            {
                _strDamageType = objNode["damagetype"].InnerText;
            }
            if (objNode["damagereplace"] != null)
            {
                _strDamageReplace = objNode["damagereplace"].InnerText;
            }
            if (objNode["firemode"] != null)
            {
                _strFireMode = objNode["firemode"].InnerText;
            }
            if (objNode["firemodereplace"] != null)
            {
                _strFireModeReplace = objNode["firemodereplace"].InnerText;
            }

            if (objNode["ap"] != null)
            {
                _strAP = objNode["ap"].InnerText;
            }
            if (objNode["apreplace"] != null)
            {
                _strAPReplace = objNode["apreplace"].InnerText;
            }
            objNode.TryGetField("accessorycostmultiplier", out _intAccessoryCostMultiplier);
            objNode.TryGetField("addmode", out _strAddMode);
            objNode.TryGetField("fullburst", out _intFullBurst, 0);
            objNode.TryGetField("suppressive", out _intSuppressive, 0);
            objNode.TryGetField("rangebonus", out _intRangeBonus, 0);
            objNode.TryGetField("extra", out _strExtra, "");
            objNode.TryGetField("ammobonus", out _intAmmoBonus, 0);

            if (blnCopy)
            {
                _guiID = Guid.NewGuid();
            }
        }
Beispiel #29
0
        /// <summary>
        /// Change the active Commlink for the Character.
        /// </summary>
        /// <param name="objActiveCommlink"></param>
        private void ChangeActiveCommlink(Commlink objActiveCommlink)
        {
            List<Commlink> lstCommlinks = _objFunctions.FindCharacterCommlinks(_objCharacter.Gear);

            foreach (Commlink objCommlink in lstCommlinks)
            {
                if (objCommlink.InternalId != objActiveCommlink.InternalId)
                    objCommlink.IsActive = false;
            }
        }
Beispiel #30
0
 /// <summary>
 /// Print the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public void Print(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("vehicle");
     objWriter.WriteElementString("name", DisplayNameShort);
     objWriter.WriteElementString("category", DisplayCategory);
     objWriter.WriteElementString("handling", TotalHandling.ToString());
     objWriter.WriteElementString("accel", TotalAccel.ToString());
     objWriter.WriteElementString("speed", TotalSpeed.ToString());
     objWriter.WriteElementString("pilot", Pilot.ToString());
     objWriter.WriteElementString("body", TotalBody.ToString());
     objWriter.WriteElementString("armor", TotalArmor.ToString());
     objWriter.WriteElementString("seats", _intSeats.ToString());
     objWriter.WriteElementString("sensor", _intSensor.ToString());
     objWriter.WriteElementString("avail", CalculatedAvail);
     objWriter.WriteElementString("cost", TotalCost.ToString());
     objWriter.WriteElementString("owncost", OwnCost.ToString());
     objWriter.WriteElementString("source", _objCharacter.Options.LanguageBookShort(_strSource));
     objWriter.WriteElementString("page", Page);
     objWriter.WriteElementString("physicalcm", PhysicalCM.ToString());
     objWriter.WriteElementString("matrixcm", ConditionMonitor.ToString());
     objWriter.WriteElementString("physicalcmfilled", _intPhysicalCMFilled.ToString());
     objWriter.WriteElementString("vehiclename", _strVehicleName);
     objWriter.WriteElementString("devicerating", TotalDeviceRating.ToString());
     objWriter.WriteElementString("maneuver", Maneuver.ToString());
     objWriter.WriteElementString("homenode", _blnHomeNode.ToString());
     objWriter.WriteStartElement("mods");
     foreach (VehicleMod objMod in _lstVehicleMods)
         objMod.Print(objWriter);
     objWriter.WriteEndElement();
     objWriter.WriteStartElement("gears");
     foreach (Gear objGear in _lstGear)
     {
         // Use the Gear's SubClass if applicable.
         if (objGear.GetType() == typeof(Commlink))
         {
             Commlink objCommlink = new Commlink(_objCharacter);
             objCommlink = (Commlink)objGear;
             objCommlink.Print(objWriter);
         }
         else
         {
             objGear.Print(objWriter);
         }
     }
     objWriter.WriteEndElement();
     objWriter.WriteStartElement("weapons");
     foreach (Weapon objWeapon in _lstWeapons)
         objWeapon.Print(objWriter);
     objWriter.WriteEndElement();
     if (_objCharacter.Options.PrintNotes)
         objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteEndElement();
 }
Beispiel #31
0
        private void chkGearHomeNode_CheckedChanged(object sender, EventArgs e)
        {
            Commlink objCommlink = new Commlink(_objCharacter);
            objCommlink = _objFunctions.FindCommlink(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);
            objCommlink.HomeNode = chkGearHomeNode.Checked;
            _objCharacter.HasHomeNode = chkGearHomeNode.Checked;
            _objFunctions.ReplaceHomeNodes(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear, _objCharacter.Vehicles);
            RefreshSelectedGear();
            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Beispiel #32
0
        /// <summary>
        /// Copy a piece of Gear.
        /// </summary>
        /// <param name="objGear">Gear object to copy.</param>
        /// <param name="objNode">TreeNode created by copying the item.</param>
        /// <param name="objWeapons">List of Weapons created by copying the item.</param>
        /// <param name="objWeaponNodes">List of Weapon TreeNodes created by copying the item.</param>
        public void Copy(Commlink objGear, TreeNode objNode, List<Weapon> objWeapons, List<TreeNode> objWeaponNodes)
        {
            _strName = objGear.Name;
            _strCategory = objGear.Category;
            _intMaxRating = objGear.MaxRating;
            _intMinRating = objGear.MinRating;
            _intRating = objGear.Rating;
            _intQty = objGear.Quantity;
            _strCapacity = objGear.Capacity;
            _strArmorCapacity = objGear.ArmorCapacity;
            _strAvail = objGear.Avail;
            _strAvail3 = objGear.Avail3;
            _strAvail6 = objGear.Avail6;
            _strAvail10 = objGear.Avail10;
            _intCostFor = objGear.CostFor;
            _strOverclocked = objGear.Overclocked;
            _intDeviceRating = objGear.DeviceRating;
            _intAttack = objGear.Attack;
            _intDataProcessing = objGear.DataProcessing;
            _intFirewall = objGear.Firewall;
            _intSleaze = objGear.Sleaze;
            _strCost = objGear.Cost;
            _strCost3 = objGear.Cost3;
            _strCost6 = objGear.Cost6;
            _strCost10 = objGear.Cost10;
            _strSource = objGear.Source;
            _strPage = objGear.Page;
            _strExtra = objGear.Extra;
            _blnBonded = objGear.Bonded;
            _blnEquipped = objGear.Equipped;
            _blnHomeNode = objGear.HomeNode;
            _nodBonus = objGear.Bonus;
            _nodWeaponBonus = objGear.WeaponBonus;
            _guiWeaponID = Guid.Parse(objGear.WeaponID);
            _strNotes = objGear.Notes;
            _strLocation = objGear.Location;

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

            foreach (Gear objGearChild in objGear.Children)
            {
                TreeNode objChildNode = new TreeNode();
                Gear objChild = new Gear(_objCharacter);
                if (objGearChild.GetType() == typeof(Commlink))
                {
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Copy(objGearChild, objChildNode, objWeapons, objWeaponNodes);
                    objChild = objCommlink;
                }
                else
                    objChild.Copy(objGearChild, objChildNode, objWeapons, objWeaponNodes);
                _objChildren.Add(objChild);

                objNode.Nodes.Add(objChildNode);
                objNode.Expand();
            }
        }
Beispiel #33
0
        /// Create a Armor Modification from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlArmorNode">XmlNode to create the object from.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="intRating">Rating of the selected ArmorMod.</param>
        /// <param name="objWeapons">List of Weapons that are created by the Armor.</param>
        /// <param name="objWeaponNodes">List of Weapon Nodes that are created by the Armor.</param>
        /// <param name="blnSkipCost">Whether or not creating the Armor should skip the Variable price dialogue (should only be used by frmSelectArmor).</param>
        public void Create(XmlNode objXmlArmorNode, TreeNode objNode, ContextMenuStrip cmsArmorGear, int intRating, List <Weapon> objWeapons, List <TreeNode> objWeaponNodes, bool blnSkipCost = false, bool blnSkipSelectForms = false)
        {
            objXmlArmorNode.TryGetStringFieldQuickly("name", ref _strName);
            objXmlArmorNode.TryGetStringFieldQuickly("category", ref _strCategory);
            objXmlArmorNode.TryGetStringFieldQuickly("armorcapacity", ref _strArmorCapacity);
            objXmlArmorNode.TryGetStringFieldQuickly("gearcapacity", ref _strGearCapacity);
            _intRating = intRating;
            objXmlArmorNode.TryGetInt32FieldQuickly("armor", ref _intA);
            objXmlArmorNode.TryGetInt32FieldQuickly("maxrating", ref _intMaxRating);
            objXmlArmorNode.TryGetStringFieldQuickly("avail", ref _strAvail);
            objXmlArmorNode.TryGetStringFieldQuickly("source", ref _strSource);
            objXmlArmorNode.TryGetStringFieldQuickly("page", ref _strPage);
            _nodBonus         = objXmlArmorNode["bonus"];
            _nodWirelessBonus = objXmlArmorNode["wirelessbonus"];
            _blnWirelessOn    = _nodWirelessBonus != null;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
Beispiel #34
0
 /// <summary>
 /// Save the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public new void Print(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("gear");
     objWriter.WriteElementString("name", DisplayNameShort);
     objWriter.WriteElementString("name_english", _strName);
     if (DisplayCategory.EndsWith("s"))
         objWriter.WriteElementString("category", DisplayCategory.Substring(0,DisplayCategory.Length -1));
     else
         objWriter.WriteElementString("category", DisplayCategory);
     objWriter.WriteElementString("category_english", _strCategory);
     objWriter.WriteElementString("iscommlink", true.ToString());
     objWriter.WriteElementString("ispersona", IsLivingPersona.ToString());
     objWriter.WriteElementString("isnexus", (_strCategory == "Nexus").ToString());
     objWriter.WriteElementString("isammo", (_strCategory == "Ammunition").ToString());
     objWriter.WriteElementString("isprogram", IsProgram.ToString());
     objWriter.WriteElementString("isos", false.ToString());
     objWriter.WriteElementString("issin", false.ToString());
     objWriter.WriteElementString("maxrating", _intMaxRating.ToString());
     objWriter.WriteElementString("rating", _intRating.ToString());
     objWriter.WriteElementString("attack", _intAttack.ToString());
     objWriter.WriteElementString("sleaze", _intSleaze.ToString());
     objWriter.WriteElementString("dataprocessing", _intDataProcessing.ToString());
     objWriter.WriteElementString("firewall", _intFirewall.ToString());
     objWriter.WriteElementString("qty", _intQty.ToString());
     objWriter.WriteElementString("avail", TotalAvail(true));
     objWriter.WriteElementString("avail_english", TotalAvail(true, true));
     objWriter.WriteElementString("cost", TotalCost.ToString());
     objWriter.WriteElementString("owncost", OwnCost.ToString());
     objWriter.WriteElementString("extra", LanguageManager.Instance.TranslateExtra(_strExtra));
     objWriter.WriteElementString("bonded", _blnBonded.ToString());
     objWriter.WriteElementString("equipped", _blnEquipped.ToString());
     objWriter.WriteElementString("homenode", _blnHomeNode.ToString());
     objWriter.WriteElementString("gearname", _strGearName);
     objWriter.WriteElementString("source", _objCharacter.Options.LanguageBookShort(_strSource));
     objWriter.WriteElementString("page", Page);
     objWriter.WriteElementString("devicerating", TotalDeviceRating.ToString());
     objWriter.WriteElementString("processorlimit", ProcessorLimit.ToString());
     objWriter.WriteElementString("conditionmonitor", ConditionMonitor.ToString());
     objWriter.WriteElementString("active", _blnActiveCommlink.ToString());
     objWriter.WriteStartElement("children");
     foreach (Gear objGear in _objChildren)
     {
         if (objGear.Category != "Commlink Upgrade" && objGear.Category != "Commlink Operating System Upgrade")
         {
             // Use the Gear's SubClass if applicable.
             if (objGear.GetType() == typeof(Commlink))
             {
                 Commlink objCommlink = new Commlink(_objCharacter);
                 objCommlink = (Commlink)objGear;
                 objCommlink.Print(objWriter);
             }
             else
             {
                 objGear.Print(objWriter);
             }
         }
     }
     objWriter.WriteEndElement();
     if (_objCharacter.Options.PrintNotes)
         objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteEndElement();
 }
Beispiel #35
0
        /// <summary>
        /// Load the CharacterAttribute from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        /// <param name="blnCopy">Whether another node is being copied.</param>
        public void Load(XmlNode objNode, bool blnCopy = false)
        {
            if (blnCopy)
            {
                _guiID = Guid.NewGuid();
            }
            else
            {
                _guiID = Guid.Parse(objNode["guid"].InnerText);
            }
            objNode.TryGetStringFieldQuickly("name", ref _strName);
            objNode.TryGetStringFieldQuickly("mount", ref _strMount);
            objNode.TryGetStringFieldQuickly("extramount", ref _strExtraMount);
            objNode.TryGetStringFieldQuickly("rc", ref _strRC);
            objNode.TryGetInt32FieldQuickly("rating", ref _intRating);
            objNode.TryGetInt32FieldQuickly("rcgroup", ref _intRCGroup);
            objNode.TryGetInt32FieldQuickly("accuracy", ref _intAccuracy);
            objNode.TryGetInt32FieldQuickly("rating", ref _intRating);
            objNode.TryGetStringFieldQuickly("conceal", ref _strConceal);
            objNode.TryGetBoolFieldQuickly("rcdeployable", ref _blnDeployable);
            objNode.TryGetStringFieldQuickly("avail", ref _strAvail);
            objNode.TryGetStringFieldQuickly("cost", ref _strCost);
            objNode.TryGetBoolFieldQuickly("included", ref _blnIncludedInWeapon);
            objNode.TryGetBoolFieldQuickly("installed", ref _blnInstalled);
            _nodAllowGear = objNode["allowgear"];
            objNode.TryGetStringFieldQuickly("source", ref _strSource);

            objNode.TryGetStringFieldQuickly("page", ref _strPage);
            objNode.TryGetStringFieldQuickly("dicepool", ref _strDicePool);

            objNode.TryGetInt32FieldQuickly("ammoslots", ref _intAmmoSlots);

            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;
                    }
                }
            }
            objNode.TryGetStringFieldQuickly("notes", ref _strNotes);
            objNode.TryGetBoolFieldQuickly("discountedcost", ref _blnDiscountCost);

            if (GlobalOptions.Instance.Language != "en-us")
            {
                XmlDocument objXmlDocument   = XmlManager.Instance.Load("weapons.xml");
                XmlNode     objAccessoryNode = objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + _strName + "\"]");
                if (objAccessoryNode != null)
                {
                    objAccessoryNode.TryGetStringFieldQuickly("translate", ref _strAltName);
                    objAccessoryNode.TryGetStringFieldQuickly("altpage", ref _strAltPage);
                }
            }
            objNode.TryGetStringFieldQuickly("damage", ref _strDamage);
            objNode.TryGetStringFieldQuickly("damagetype", ref _strDamageType);
            objNode.TryGetStringFieldQuickly("damagereplace", ref _strDamageReplace);
            objNode.TryGetStringFieldQuickly("firemode", ref _strFireMode);
            objNode.TryGetStringFieldQuickly("firemodereplace", ref _strFireModeReplace);
            objNode.TryGetStringFieldQuickly("ap", ref _strAP);
            objNode.TryGetStringFieldQuickly("apreplace", ref _strAPReplace);
            objNode.TryGetInt32FieldQuickly("accessorycostmultiplier", ref _intAccessoryCostMultiplier);
            objNode.TryGetStringFieldQuickly("addmode", ref _strAddMode);
            objNode.TryGetInt32FieldQuickly("fullburst", ref _intFullBurst);
            objNode.TryGetInt32FieldQuickly("suppressive", ref _intSuppressive);
            objNode.TryGetInt32FieldQuickly("rangebonus", ref _intRangeBonus);
            objNode.TryGetStringFieldQuickly("extra", ref _strExtra);
            objNode.TryGetInt32FieldQuickly("ammobonus", ref _intAmmoBonus);
        }
Beispiel #36
0
        /// Create a Weapon Accessory from an XmlNode and return the TreeNodes for it.
        /// <param name="objXmlAccessory">XmlNode to create the object from.</param>
        /// <param name="objNode">TreeNode to populate a TreeView.</param>
        /// <param name="strMount">Mount slot that the Weapon Accessory will consume.</param>
        /// <param name="intRating">Rating of the Weapon Accessory.</param>
        public void Create(XmlNode objXmlAccessory, TreeNode objNode, Tuple <string, string> strMount, int intRating, ContextMenuStrip cmsAccessoryGear, bool blnSkipCost = false, bool blnCreateChildren = true)
        {
            objXmlAccessory.TryGetStringFieldQuickly("name", ref _strName);
            _strMount      = strMount.Item1;
            _strExtraMount = strMount.Item2;
            _intRating     = intRating;
            objXmlAccessory.TryGetStringFieldQuickly("avail", ref _strAvail);
            // Check for a Variable Cost.
            if (blnSkipCost)
            {
                _strCost = "0";
            }
            else if (objXmlAccessory["cost"] != null)
            {
                _strCost = objXmlAccessory["cost"].InnerText;
                if (_strCost.StartsWith("Variable"))
                {
                    decimal decMin  = 0;
                    decimal decMax  = decimal.MaxValue;
                    string  strCost = _strCost.TrimStart("Variable", true).Trim("()".ToCharArray());
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decMin = Convert.ToDecimal(strValues[0], GlobalOptions.InvariantCultureInfo);
                        decMax = Convert.ToDecimal(strValues[1], GlobalOptions.InvariantCultureInfo);
                    }
                    else
                    {
                        decMin = Convert.ToDecimal(strCost.FastEscape('+'), GlobalOptions.InvariantCultureInfo);
                    }

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

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

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

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

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

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

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

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

            objNode.Text = DisplayName;
            objNode.Tag  = _guiID.ToString();
        }
Beispiel #37
0
        private void tsVehicleWeaponAccessoryGearMenuAddAsPlugin_Click(object sender, EventArgs e)
        {
            // Locate the Vehicle Sensor Gear.
            bool blnFound = false;
            Vehicle objFoundVehicle = new Vehicle(_objCharacter);
            Gear objSensor = _objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objFoundVehicle);
            if (objSensor != null)
                blnFound = true;

            // Make sure the Gear was found.
            if (!blnFound)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_ModifyVehicleGear"), LanguageManager.Instance.GetString("MessageTitle_SelectGear"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

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

            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + objSensor.Name + "\" and category = \"" + objSensor.Category + "\"]");

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true);
            //frmPickGear.ShowNegativeCapacityOnly = true;

            if (objXmlGear.InnerXml.Contains("<addoncategory>"))
            {
                string strCategories = "";
                foreach (XmlNode objXmlCategory in objXmlGear.SelectNodes("addoncategory"))
                    strCategories += objXmlCategory.InnerText + ",";
                // Remove the trailing comma.
                strCategories = strCategories.Substring(0, strCategories.Length - 1);
                frmPickGear.AllowedCategories = strCategories;
            }

            frmPickGear.ShowDialog(this);

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

            // Open the Gear XML file and locate the selected piece.
            objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            Gear objGear = new Gear(_objCharacter);

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlinks":
                case "Cyberdecks":
                case "Rigger Command Consoles":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, false);
                    objCommlink.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objCommlink.DisplayName;

                    objGear = objCommlink;
                    break;
                default:
                    Gear objNewGear = new Gear(_objCharacter);
                    objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, false, true, frmPickGear.Aerodynamic);
                    objNewGear.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objNewGear.DisplayName;

                    objGear = objNewGear;
                    break;
            }

            if (objGear.InternalId == Guid.Empty.ToString())
                return;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objGear.Cost = (Convert.ToDouble(objGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objGear.Cost != "")
                    objGear.Cost = "(" + objGear.Cost + ") * 0.1";
                if (objGear.Cost3 != "")
                    objGear.Cost3 = "(" + objGear.Cost3 + ") * 0.1";
                if (objGear.Cost6 != "")
                    objGear.Cost6 = "(" + objGear.Cost6 + ") * 0.1";
                if (objGear.Cost10 != "")
                    objGear.Cost10 = "(" + objGear.Cost10 + ") * 0.1";
                if (objGear.Extra == "")
                    objGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objGear.Cost = "0";
                objGear.Cost3 = "0";
                objGear.Cost6 = "0";
                objGear.Cost10 = "0";
            }

            objNode.Text = objGear.DisplayName;

            int intCost = objGear.TotalCost;

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

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

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

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddWeaponGear, objGear.InternalId, frmPickGear.SelectedQty);
                    objExpense.Undo = objUndo;
                }
            }

            objNode.ContextMenuStrip = cmsCyberwareGear;

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

            objGear.Parent = objSensor;
            objSensor.Children.Add(objGear);

            if (frmPickGear.AddAgain)
                tsVehicleWeaponAccessoryGearMenuAddAsPlugin_Click(sender, e);

            UpdateCharacterInfo();
            RefreshSelectedVehicle();
        }
Beispiel #38
0
 /// <summary>
 /// Save the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public void Save(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("armormod");
     objWriter.WriteElementString("guid", _guiID.ToString());
     objWriter.WriteElementString("name", _strName);
     objWriter.WriteElementString("category", _strCategory);
     objWriter.WriteElementString("armor", _intA.ToString(CultureInfo.InvariantCulture));
     objWriter.WriteElementString("armorcapacity", _strArmorCapacity);
     objWriter.WriteElementString("gearcapacity", _strGearCapacity);
     objWriter.WriteElementString("maxrating", _intMaxRating.ToString(CultureInfo.InvariantCulture));
     objWriter.WriteElementString("rating", _intRating.ToString(CultureInfo.InvariantCulture));
     objWriter.WriteElementString("avail", _strAvail);
     objWriter.WriteElementString("cost", _strCost);
     if (_lstGear.Count > 0)
     {
         objWriter.WriteStartElement("gears");
         foreach (Gear objGear in _lstGear)
         {
             // Use the Gear's SubClass if applicable.
             if (objGear.GetType() == typeof(Commlink))
             {
                 Commlink objCommlink = objGear as Commlink;
                 objCommlink?.Save(objWriter);
             }
             else
             {
                 objGear.Save(objWriter);
             }
         }
         objWriter.WriteEndElement();
     }
     if (_nodBonus != null)
     {
         objWriter.WriteRaw(_nodBonus.OuterXml);
     }
     else
     {
         objWriter.WriteElementString("bonus", string.Empty);
     }
     if (_nodWirelessBonus != null)
     {
         objWriter.WriteRaw(_nodWirelessBonus.OuterXml);
     }
     else
     {
         objWriter.WriteElementString("wirelessbonus", string.Empty);
     }
     objWriter.WriteElementString("wirelesson", _blnWirelessOn.ToString());
     objWriter.WriteElementString("source", _strSource);
     objWriter.WriteElementString("page", _strPage);
     objWriter.WriteElementString("included", _blnIncludedInArmor.ToString());
     objWriter.WriteElementString("equipped", _blnEquipped.ToString());
     objWriter.WriteElementString("extra", _strExtra);
     if (_guiWeaponID != Guid.Empty)
     {
         objWriter.WriteElementString("weaponguid", _guiWeaponID.ToString());
     }
     objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteElementString("discountedcost", DiscountCost.ToString());
     objWriter.WriteEndElement();
     _objCharacter.SourceProcess(_strSource);
 }
Beispiel #39
0
 /// <summary>
 /// Print the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public void Print(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("accessory");
     objWriter.WriteElementString("name", DisplayName);
     objWriter.WriteElementString("mount", _strMount);
     objWriter.WriteElementString("rc", _strRC);
     objWriter.WriteElementString("conceal", _strConceal);
     objWriter.WriteElementString("avail", TotalAvail);
     objWriter.WriteElementString("cost", TotalCost.ToString());
     objWriter.WriteElementString("owncost", OwnCost.ToString());
     objWriter.WriteElementString("included", _blnIncludedInWeapon.ToString());
     objWriter.WriteElementString("source", _objCharacter.Options.LanguageBookShort(_strSource));
     objWriter.WriteElementString("page", Page);
     objWriter.WriteElementString("accuracy", _intAccuracy.ToString());
     if (_lstGear.Count > 0)
     {
         objWriter.WriteStartElement("gears");
         foreach (Gear objGear in _lstGear)
         {
             // Use the Gear's SubClass if applicable.
             if (objGear.GetType() == typeof(Commlink))
             {
                 Commlink objCommlink = new Commlink(_objCharacter);
                 objCommlink = (Commlink)objGear;
                 objCommlink.Print(objWriter);
             }
             else
             {
                 objGear.Print(objWriter);
             }
         }
         objWriter.WriteEndElement();
     }
     if (_objCharacter.Options.PrintNotes)
         objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteEndElement();
 }
Beispiel #40
0
        private void chkVehicleHomeNode_CheckedChanged(object sender, EventArgs e)
        {
            if (treVehicles.SelectedNode.Level == 1)
            {
                Vehicle objVehicle = _objFunctions.FindVehicle(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles);
                if (objVehicle == null)
                    return;

                objVehicle.HomeNode = chkVehicleHomeNode.Checked;
            }
            else
            {
                Commlink objGear = new Commlink(_objCharacter);
                Vehicle objSelectedVehicle = new Vehicle(_objCharacter);
                objGear = (Commlink)_objFunctions.FindVehicleGear(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Vehicles, out objSelectedVehicle);
                objGear.HomeNode = chkVehicleHomeNode.Checked;
            }

            _objFunctions.ReplaceHomeNodes(treVehicles.SelectedNode.Tag.ToString(), _objCharacter.Gear, _objCharacter.Vehicles);
            RefreshSelectedVehicle();
            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Beispiel #41
0
        /// <summary>
        /// Load the CharacterAttribute 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;
            _strA = objNode["armor"].InnerText;
            _strAvail = objNode["avail"].InnerText;
            _strCost = objNode["cost"].InnerText;
            _strSource = objNode["source"].InnerText;
            objNode.TryGetField("armoroverride", out _strO);
            objNode.TryGetField("armorcapacity", out _strArmorCapacity);
            objNode.TryGetField("rating", out _intRating);
            objNode.TryGetField("maxrating", out _intMaxRating);
            objNode.TryGetField("page", out _strPage);
            objNode.TryGetField("armorname", out _strArmorName);
            objNode.TryGetField("equipped", out _blnEquipped);
            objNode.TryGetField("extra", out _strExtra);
            objNode.TryGetField("damage", out _intDamage);
            objNode.TryGetField("location", out _strLocation);
            objNode.TryGetField("notes", out _strNotes);
            objNode.TryGetField("discountedcost", out _blnDiscountCost);
            try
            {
                _nodBonus = objNode["bonus"];
            }
            catch { }
            if (objNode.InnerXml.Contains("armormods"))
            {
                XmlNodeList nodMods = objNode.SelectNodes("armormods/armormod");
                foreach (XmlNode nodMod in nodMods)
                {
                    ArmorMod objMod = new ArmorMod(_objCharacter);
                    objMod.Load(nodMod, blnCopy);
                    objMod.Parent = this;
                    _lstArmorMods.Add(objMod);
                }
            }
            if (objNode.InnerXml.Contains("gears"))
            {
                XmlNodeList nodGears = objNode.SelectNodes("gears/gear");
                foreach (XmlNode nodGear in nodGears)
                {
                    switch (nodGear["category"].InnerText)
                    {
                        case "Commlinks":
                        case "Commlink Accessories":
                        case "Cyberdecks":
                        case "Rigger Command Consoles":
                            Commlink objCommlink = new Commlink(_objCharacter);
                            objCommlink.Load(nodGear, blnCopy);
                            _lstGear.Add(objCommlink);
                            break;
                        default:
                            Gear objGear = new Gear(_objCharacter);
                            objGear.Load(nodGear, blnCopy);
                            _lstGear.Add(objGear);
                            break;
                    }
                }
            }

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

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

            if (blnCopy)
            {
                _guiID = Guid.NewGuid();
                _strLocation = string.Empty;
            }
        }
Beispiel #42
0
 /// <summary>
 /// Save the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public void Save(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("accessory");
     objWriter.WriteElementString("guid", _guiID.ToString());
     objWriter.WriteElementString("name", _strName);
     objWriter.WriteElementString("mount", _strMount);
     objWriter.WriteElementString("extramount", _strExtraMount);
     objWriter.WriteElementString("rc", _strRC);
     objWriter.WriteElementString("rating", _intRating.ToString(CultureInfo.InvariantCulture));
     objWriter.WriteElementString("rcgroup", _intRCGroup.ToString(CultureInfo.InvariantCulture));
     objWriter.WriteElementString("rcdeployable", _blnDeployable.ToString());
     objWriter.WriteElementString("conceal", _strConceal);
     if (!string.IsNullOrEmpty(_strDicePool))
     {
         objWriter.WriteElementString("dicepool", _strDicePool);
     }
     objWriter.WriteElementString("avail", _strAvail);
     objWriter.WriteElementString("cost", _strCost);
     objWriter.WriteElementString("included", _blnIncludedInWeapon.ToString());
     objWriter.WriteElementString("installed", _blnInstalled.ToString());
     if (_nodAllowGear != null)
     {
         objWriter.WriteRaw(_nodAllowGear.OuterXml);
     }
     objWriter.WriteElementString("source", _strSource);
     objWriter.WriteElementString("page", _strPage);
     objWriter.WriteElementString("accuracy", _intAccuracy.ToString(CultureInfo.InvariantCulture));
     if (_lstGear.Count > 0)
     {
         objWriter.WriteStartElement("gears");
         foreach (Gear objGear in _lstGear)
         {
             // Use the Gear's SubClass if applicable.
             if (objGear.GetType() == typeof(Commlink))
             {
                 Commlink objCommlink = new Commlink(_objCharacter);
                 objCommlink = (Commlink)objGear;
                 objCommlink.Save(objWriter);
             }
             else
             {
                 objGear.Save(objWriter);
             }
         }
         objWriter.WriteEndElement();
     }
     objWriter.WriteElementString("ammoslots", _intAmmoSlots.ToString());
     objWriter.WriteElementString("damagetype", _strDamageType);
     objWriter.WriteElementString("damage", _strDamage);
     objWriter.WriteElementString("damagereplace", _strDamageReplace);
     objWriter.WriteElementString("firemode", _strFireMode);
     objWriter.WriteElementString("firemodereplace", _strFireModeReplace);
     objWriter.WriteElementString("ap", _strAP);
     objWriter.WriteElementString("apreplace", _strAPReplace);
     objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteElementString("discountedcost", DiscountCost.ToString());
     objWriter.WriteElementString("addmode", _strAddMode);
     objWriter.WriteElementString("fullburst", _intFullBurst.ToString());
     objWriter.WriteElementString("suppressive", _intSuppressive.ToString());
     objWriter.WriteElementString("rangebonus", _intRangeBonus.ToString());
     objWriter.WriteElementString("extra", _strExtra);
     objWriter.WriteElementString("ammobonus", _intAmmoBonus.ToString());
     objWriter.WriteEndElement();
     _objCharacter.SourceProcess(_strSource);
 }
Beispiel #43
0
 /// <summary>
 /// Save the object's XML to the XmlWriter.
 /// </summary>
 /// <param name="objWriter">XmlTextWriter to write with.</param>
 public void Save(XmlTextWriter objWriter)
 {
     objWriter.WriteStartElement("accessory");
     objWriter.WriteElementString("guid", _guiID.ToString());
     objWriter.WriteElementString("name", _strName);
     objWriter.WriteElementString("mount", _strMount);
     objWriter.WriteElementString("rc", _strRC);
     objWriter.WriteElementString("rating", _intRating.ToString());
     objWriter.WriteElementString("rcgroup", _intRCGroup.ToString());
     objWriter.WriteElementString("rcdeployable", _blnDeployable.ToString());
     objWriter.WriteElementString("conceal", _strConceal);
     if (_strDicePool != "")
         objWriter.WriteElementString("dicepool", _strDicePool);
     objWriter.WriteElementString("avail", _strAvail);
     objWriter.WriteElementString("cost", _strCost);
     objWriter.WriteElementString("included", _blnIncludedInWeapon.ToString());
     objWriter.WriteElementString("installed", _blnInstalled.ToString());
     if (_nodAllowGear != null)
         objWriter.WriteRaw(_nodAllowGear.OuterXml);
     objWriter.WriteElementString("source", _strSource);
     objWriter.WriteElementString("page", _strPage);
     objWriter.WriteElementString("accuracy", _intAccuracy.ToString());
     if (_lstGear.Count > 0)
     {
         objWriter.WriteStartElement("gears");
         foreach (Gear objGear in _lstGear)
         {
             // Use the Gear's SubClass if applicable.
             if (objGear.GetType() == typeof(Commlink))
             {
                 Commlink objCommlink = new Commlink(_objCharacter);
                 objCommlink = (Commlink)objGear;
                 objCommlink.Save(objWriter);
             }
             else
             {
                 objGear.Save(objWriter);
             }
         }
         objWriter.WriteEndElement();
     }
     objWriter.WriteElementString("ammoslots", _intAmmoSlots.ToString());
     objWriter.WriteElementString("damagetype", _strDamageType);
     objWriter.WriteElementString("damage", _strDamage);
     objWriter.WriteElementString("damagereplace", _strDamageReplace);
     objWriter.WriteElementString("firemode", _strFireMode);
     objWriter.WriteElementString("firemodereplace", _strFireModeReplace);
     objWriter.WriteElementString("ap", _strAP);
     objWriter.WriteElementString("apreplace", _strAPReplace);
     objWriter.WriteElementString("notes", _strNotes);
     objWriter.WriteElementString("discountedcost", DiscountCost.ToString());
     objWriter.WriteElementString("addmode", _strAddMode);
     objWriter.WriteElementString("fullburst", _intFullBurst.ToString());
     objWriter.WriteElementString("suppressive", _intSuppressive.ToString());
     objWriter.WriteElementString("rangebonus", _intRangeBonus.ToString());
     objWriter.WriteElementString("extra", _strExtra);
     objWriter.WriteElementString("ammobonus", _intAmmoBonus.ToString());
     objWriter.WriteEndElement();
     _objCharacter.SourceProcess(_strSource);
 }
Beispiel #44
0
        /// <summary>
        /// Load the CharacterAttribute from the XmlNode.
        /// </summary>
        /// <param name="objNode">XmlNode to load.</param>
        /// <param name="blnCopy">Whether another node is being copied.</param>
        public void Load(XmlNode objNode, bool blnCopy = false)
        {
            _guiID = Guid.Parse(objNode["guid"].InnerText);
            _strName = objNode["name"].InnerText;
            _strMount = objNode["mount"].InnerText;
            _strRC = objNode["rc"].InnerText;
            objNode.TryGetField("rating", out _intRating,0);
            objNode.TryGetField("rcgroup", out _intRCGroup, 0);
            objNode.TryGetField("accuracy", out _intAccuracy, 0);
            objNode.TryGetField("rating", out _intRating, 0);
            objNode.TryGetField("rating", out _intRating, 0);
            objNode.TryGetField("conceal", out _strConceal, "0");
            objNode.TryGetField("rcdeployable", out _blnDeployable);
            _strAvail = objNode["avail"].InnerText;
            _strCost = objNode["cost"].InnerText;
            _blnIncludedInWeapon = Convert.ToBoolean(objNode["included"].InnerText);
            objNode.TryGetField("installed", out _blnInstalled, true);
            try
            {
                _nodAllowGear = objNode["allowgear"];
            }
            catch
            {
            }
            _strSource = objNode["source"].InnerText;

            objNode.TryGetField("page", out _strPage, "0");
            objNode.TryGetField("dicepool", out _strDicePool, "0");

            if (objNode.InnerXml.Contains("ammoslots"))
            {
                objNode.TryGetField("ammoslots", out _intAmmoSlots, 0);  //TODO: Might work if 0 -> 1
            }

            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;
                    }
                }
            }
            objNode.TryGetField("notes", out _strNotes, "");
            objNode.TryGetField("discountedcost", out _blnDiscountCost, false);

            if (GlobalOptions.Instance.Language != "en-us")
            {
                XmlDocument objXmlDocument = XmlManager.Instance.Load("weapons.xml");
                XmlNode objAccessoryNode = objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[name = \"" + _strName + "\"]");
                if (objAccessoryNode != null)
                {
                    if (objAccessoryNode["translate"] != null)
                        _strAltName = objAccessoryNode["translate"].InnerText;
                    if (objAccessoryNode["altpage"] != null)
                        _strAltPage = objAccessoryNode["altpage"].InnerText;
                }
            }
            if (objNode["damage"] != null)
            {
                _strDamage = objNode["damage"].InnerText;
            }
            if (objNode["damagetype"] != null)
            {
                _strDamageType = objNode["damagetype"].InnerText;
            }
            if (objNode["damagereplace"] != null)
            {
                _strDamageReplace = objNode["damagereplace"].InnerText;
            }
            if (objNode["firemode"] != null)
            {
                _strFireMode = objNode["firemode"].InnerText;
            }
            if (objNode["firemodereplace"] != null)
            {
                _strFireModeReplace = objNode["firemodereplace"].InnerText;
            }

            if (objNode["ap"] != null)
            {
                _strAP = objNode["ap"].InnerText;
            }
            if (objNode["apreplace"] != null)
            {
                _strAPReplace = objNode["apreplace"].InnerText;
            }
            objNode.TryGetField("accessorycostmultiplier", out _intAccessoryCostMultiplier);
            objNode.TryGetField("addmode", out _strAddMode);
            objNode.TryGetField("fullburst", out _intFullBurst,0);
            objNode.TryGetField("suppressive", out _intSuppressive,0);
            objNode.TryGetField("rangebonus", out _intRangeBonus,0);
            objNode.TryGetField("extra", out _strExtra,"");
            objNode.TryGetField("ammobonus", out _intAmmoBonus,0);

            if (blnCopy)
            {
                _guiID = Guid.NewGuid();
            }
        }
Beispiel #45
0
        private void tsVehicleAddGear_Click(object sender, EventArgs e)
        {
            // Make sure a parent items is selected, then open the Select Gear window.
            try
            {
                if (treVehicles.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectGearVehicle"), LanguageManager.Instance.GetString("MessageTitle_SelectGearVehicle"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

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

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

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true);
            frmPickGear.ShowPositiveCapacityOnly = false;
            frmPickGear.ShowDialog(this);

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

            // Open the Gear XML file and locate the selected piece.
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");
            XmlNode objXmlGear = objXmlDocument.SelectSingleNode("/chummer/gears/gear[name = \"" + frmPickGear.SelectedGear + "\" and category = \"" + frmPickGear.SelectedCategory + "\"]");

            // Create the new piece of Gear.
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();
            TreeNode objNode = new TreeNode();
            Gear objGear = new Gear(_objCharacter);

            switch (frmPickGear.SelectedCategory)
            {
                case "Commlinks":
                case "Cyberdecks":
                case "Rigger Command Consoles":
                    Commlink objCommlink = new Commlink(_objCharacter);
                    objCommlink.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, false);
                    objCommlink.Quantity = frmPickGear.SelectedQty;

                    objGear = objCommlink;
                    break;
                default:
                    Gear objNewGear = new Gear(_objCharacter);
                    objNewGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, "", frmPickGear.Hacked, frmPickGear.InherentProgram, false, true, frmPickGear.Aerodynamic);
                    objNewGear.Quantity = frmPickGear.SelectedQty;

                    objGear = objNewGear;
                    break;
            }

            if (objGear.InternalId == Guid.Empty.ToString())
                return;

            // Reduce the cost for Do It Yourself components.
            if (frmPickGear.DoItYourself)
                objGear.Cost = (Convert.ToDouble(objGear.Cost, GlobalOptions.Instance.CultureInfo) * 0.5).ToString();
            // Reduce the cost to 10% for Hacked programs.
            if (frmPickGear.Hacked)
            {
                if (objGear.Cost != "")
                    objGear.Cost = "(" + objGear.Cost + ") * 0.1";
                if (objGear.Cost3 != "")
                    objGear.Cost3 = "(" + objGear.Cost3 + ") * 0.1";
                if (objGear.Cost6 != "")
                    objGear.Cost6 = "(" + objGear.Cost6 + ") * 0.1";
                if (objGear.Cost10 != "")
                    objGear.Cost10 = "(" + objGear.Cost10 + ") * 0.1";
                if (objGear.Extra == "")
                    objGear.Extra = LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
                else
                    objGear.Extra += ", " + LanguageManager.Instance.GetString("Label_SelectGear_Hacked");
            }
            // If the item was marked as free, change its cost.
            if (frmPickGear.FreeCost)
            {
                objGear.Cost = "0";
                objGear.Cost3 = "0";
                objGear.Cost6 = "0";
                objGear.Cost10 = "0";
            }

            objGear.Quantity = frmPickGear.SelectedQty;
            objNode.Text = objGear.DisplayName;

            // Change the cost of the Sensor itself to 0.
            //if (frmPickGear.SelectedCategory == "Sensors")
            //{
            //    objGear.Cost = "0";
            //    objGear.Cost3 = "0";
            //    objGear.Cost6 = "0";
            //    objGear.Cost10 = "0";
            //}

            int intCost = objGear.TotalCost;

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

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

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

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddVehicleGear, objGear.InternalId, 1);
                    objExpense.Undo = objUndo;
                }
            }

            objNode.ContextMenuStrip = cmsVehicleGear;

            bool blnMatchFound = false;
            // If this is Ammunition, see if the character already has it on them.
            if (objGear.Category == "Ammunition")
            {
                foreach (Gear objVehicleGear in objSelectedVehicle.Gear)
                {
                    if (objVehicleGear.Name == objGear.Name && objVehicleGear.Category == objGear.Category && objVehicleGear.Rating == objGear.Rating && objVehicleGear.Extra == objGear.Extra)
                    {
                        // A match was found, so increase the quantity instead.
                        objVehicleGear.Quantity += objGear.Quantity;
                        blnMatchFound = true;

                        foreach (TreeNode objGearNode in treVehicles.SelectedNode.Nodes)
                        {
                            if (objVehicleGear.InternalId == objGearNode.Tag.ToString())
                            {
                                objGearNode.Text = objVehicleGear.DisplayName;
                                break;
                            }
                        }

                        break;
                    }
                }
            }

            if (!blnMatchFound)
            {
                treVehicles.SelectedNode.Nodes.Add(objNode);
                treVehicles.SelectedNode.Expand();

                // Add the Gear to the Vehicle.
                objSelectedVehicle.Gear.Add(objGear);
            }

            if (frmPickGear.AddAgain)
                tsVehicleAddGear_Click(sender, e);

            UpdateCharacterInfo();
            RefreshSelectedVehicle();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }