Exemple #1
0
        private void TestGear()
        {
            Character objCharacter = new Character();
            XmlDocument objXmlDocument = XmlManager.Instance.Load("gear.xml");
            pgbProgress.Minimum = 0;
            pgbProgress.Value = 0;
            pgbProgress.Maximum = objXmlDocument.SelectNodes("/chummer/gears/gear").Count;

            // Gear.
            foreach (XmlNode objXmlGear in objXmlDocument.SelectNodes("/chummer/gears/gear"))
            {
                pgbProgress.Value++;
                Application.DoEvents();
                try
                {
                    TreeNode objTempNode = new TreeNode();
                    Gear objTemp = new Gear(objCharacter);
                    List<Weapon> lstWeapons = new List<Weapon>();
                    List<TreeNode> lstNodes = new List<TreeNode>();
                    objTemp.Create(objXmlGear, objCharacter, objTempNode, 1, lstWeapons, lstNodes, "Blades");
                    try
                    {
                        int objValue = objTemp.TotalCost;
                    }
                    catch
                    {
                        if (objXmlGear["category"].InnerText != "Mook")
                            txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalCost\n";
                    }
                    try
                    {
                        string objValue = objTemp.TotalAvail();
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed TotalAvail\n";
                    }
                    try
                    {
                        string objValue = objTemp.CalculatedArmorCapacity;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedArmorCapacity\n";
                    }
                    try
                    {
                        string objValue = objTemp.CalculatedCapacity;
                    }
                    catch
                    {
                        txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCapacity\n";
                    }
                    try
                    {
                        int objValue = objTemp.CalculatedCost;
                    }
                    catch
                    {
                        if (objXmlGear["category"].InnerText != "Mook")
                            txtOutput.Text += objXmlGear["name"].InnerText + " failed CalculatedCost\n";
                    }
                }
                catch
                {
                    txtOutput.Text += objXmlGear["name"].InnerText + " general failure\n";
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Refresh the information for the currently displayed Gear.
        /// </summary>
        public void RefreshSelectedGear()
        {
            bool blnClear = false;
            try
            {
                if (treGear.SelectedNode.Level == 0)
                    blnClear = true;
            }
            catch
            {
                blnClear = true;
            }
            if (blnClear)
            {
                _blnSkipRefresh = true;
                nudGearRating.Minimum = 0;
                nudGearRating.Maximum = 0;
                nudGearRating.Enabled = false;
                nudGearQty.Enabled = false;
                chkGearEquipped.Text = LanguageManager.Instance.GetString("Checkbox_Equipped");
                chkGearEquipped.Visible = false;
                chkActiveCommlink.Visible = false;
                _blnSkipRefresh = false;
                return;
            }
            chkGearHomeNode.Visible = false;

            if (treGear.SelectedNode.Level > 0)
            {
                Gear objGear = new Gear(_objCharacter);
                objGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);

                lblGearName.Text = objGear.DisplayNameShort;
                lblGearCategory.Text = objGear.DisplayCategory;
                lblGearAvail.Text = objGear.TotalAvail(true);
                try
                {
                    lblGearCost.Text = String.Format("{0:###,###,##0¥}", objGear.TotalCost);
                }
                catch
                {
                    lblGearCost.Text = objGear.Cost;
                }
                lblGearCapacity.Text = objGear.CalculatedCapacity + " (" + objGear.CapacityRemaining.ToString() + " " + LanguageManager.Instance.GetString("String_Remaining") + ")";
                string strBook = _objOptions.LanguageBookShort(objGear.Source);
                string strPage = objGear.Page;
                lblGearSource.Text = strBook + " " + strPage;
                tipTooltip.SetToolTip(lblGearSource, _objOptions.LanguageBookLong(objGear.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objGear.Page);

                if (objGear.GetType() == typeof(Commlink))
                {
                    Commlink objCommlink = (Commlink)objGear;
                    List<string> objASDF = new List<string>() { objCommlink.Attack.ToString(), objCommlink.Sleaze.ToString(), objCommlink.DataProcessing.ToString(), objCommlink.Firewall.ToString() };

                    cboGearAttack.BindingContext = new BindingContext();
                    cboGearAttack.ValueMember = "Value";
                    cboGearAttack.DisplayMember = "Name";
                    cboGearAttack.DataSource = objASDF;
                    cboGearAttack.SelectedIndex = 0;
                    cboGearAttack.Visible = true;
                    cboGearSleaze.BindingContext = new BindingContext();
                    cboGearSleaze.ValueMember = "Value";
                    cboGearSleaze.DisplayMember = "Name";
                    cboGearSleaze.DataSource = objASDF;
                    cboGearSleaze.SelectedIndex = 1;
                    cboGearDataProcessing.BindingContext = new BindingContext();
                    cboGearDataProcessing.ValueMember = "Value";
                    cboGearDataProcessing.DisplayMember = "Name";
                    cboGearDataProcessing.DataSource = objASDF;
                    cboGearDataProcessing.SelectedIndex = 2;
                    cboGearFirewall.BindingContext = new BindingContext();
                    cboGearFirewall.ValueMember = "Value";
                    cboGearFirewall.DisplayMember = "Name";
                    cboGearFirewall.DataSource = objASDF;
                    cboGearFirewall.SelectedIndex = 3;
                    lblGearDeviceRating.Text = objCommlink.TotalDeviceRating.ToString();

                    lblGearDeviceRating.Visible = true;
                    cboGearAttack.Visible = true;
                    cboGearSleaze.Visible = true;
                    cboGearDataProcessing.Visible = true;
                    cboGearFirewall.Visible = true;
                    lblGearDeviceRatingLabel.Visible = true;
                    lblGearAttackLabel.Visible = true;
                    lblGearSleazeLabel.Visible = true;
                    lblGearDataProcessingLabel.Visible = true;
                    lblGearFirewallLabel.Visible = true;

                    _blnSkipRefresh = true;
                    chkActiveCommlink.Checked = objCommlink.IsActive;
                    _blnSkipRefresh = false;

                    if (objCommlink.Category != "Commlink Upgrade")
                        chkActiveCommlink.Visible = true;

                    if (_objCharacter.Metatype == "A.I.")
                    {
                        chkGearHomeNode.Visible = true;
                        chkGearHomeNode.Checked = objCommlink.HomeNode;
                    }
                }
                else
                {
                    lblGearDeviceRating.Text = objGear.DeviceRating.ToString();
                    chkActiveCommlink.Visible = false;
                    cboGearAttack.Visible = false;
                    cboGearSleaze.Visible = false;
                    cboGearDataProcessing.Visible = false;
                    cboGearFirewall.Visible = false;
                    lblGearAttackLabel.Visible = false;
                    lblGearSleazeLabel.Visible = false;
                    lblGearDataProcessingLabel.Visible = false;
                    lblGearFirewallLabel.Visible = false;
                }

                if (objGear.MaxRating > 0)
                {
                    _blnSkipRefresh = true;
                    if (objGear.MinRating > 0)
                        nudGearRating.Minimum = objGear.MinRating;
                    else if (objGear.MinRating == 0 && objGear.Name.Contains("Credstick,"))
                        nudGearRating.Minimum = 0;
                    else
                        nudGearRating.Minimum = 1;
                    nudGearRating.Maximum = objGear.MaxRating;
                    nudGearRating.Value = objGear.Rating;
                    if (nudGearRating.Minimum == nudGearRating.Maximum)
                        nudGearRating.Enabled = false;
                    else
                        nudGearRating.Enabled = true;
                    _blnSkipRefresh = false;
                }
                else
                {
                    _blnSkipRefresh = true;
                    nudGearRating.Minimum = 0;
                    nudGearRating.Maximum = 0;
                    nudGearRating.Enabled = false;
                    _blnSkipRefresh = false;
                }

                try
                {
                    _blnSkipRefresh = true;
                    //nudGearQty.Minimum = objGear.CostFor;
                    nudGearQty.Increment = objGear.CostFor;
                    nudGearQty.Value = objGear.Quantity;
                    _blnSkipRefresh = false;
                }
                catch
                {
                }

                if (treGear.SelectedNode.Level == 1)
                {
                    _blnSkipRefresh = true;
                    nudGearQty.Enabled = true;
                    nudGearQty.Increment = objGear.CostFor;
                    //nudGearQty.Minimum = objGear.CostFor;
                    chkGearEquipped.Visible = true;
                    chkGearEquipped.Checked = objGear.Equipped;
                    _blnSkipRefresh = false;
                }
                else
                {
                    nudGearQty.Enabled = false;
                    _blnSkipRefresh = true;
                    chkGearEquipped.Visible = true;
                    chkGearEquipped.Checked = objGear.Equipped;

                    // If this is a Program, determine if its parent Gear (if any) is a Commlink. If so, show the Equipped checkbox.
                    if (objGear.IsProgram && _objOptions.CalculateCommlinkResponse)
                    {
                        Gear objParent = new Gear(_objCharacter);
                        objParent = objGear.Parent;
                        if (objParent.Category != string.Empty)
                        {
                            if (objParent.Category == "Commlinks" || objParent.Category == "Cyberdecks" || objParent.Category == "Nexus")
                                chkGearEquipped.Text = LanguageManager.Instance.GetString("Checkbox_SoftwareRunning");
                        }
                    }
                    _blnSkipRefresh = false;
                }

                // Show the Weapon Bonus information if it's available.
                if (objGear.WeaponBonus != null)
                {
                    lblGearDamageLabel.Visible = true;
                    lblGearDamage.Visible = true;
                    lblGearAPLabel.Visible = true;
                    lblGearAP.Visible = true;
                    lblGearDamage.Text = objGear.WeaponBonusDamage();
                    lblGearAP.Text = objGear.WeaponBonusAP;
                }
                else
                {
                    lblGearDamageLabel.Visible = false;
                    lblGearDamage.Visible = false;
                    lblGearAPLabel.Visible = false;
                    lblGearAP.Visible = false;
                }

                treGear.SelectedNode.Text = objGear.DisplayName;
            }
        }
Exemple #3
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, 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);
                    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;

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

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

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

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

            UpdateCharacterInfo();
            RefreshSelectedWeapon();
        }
Exemple #4
0
        /// <summary>
        /// Refresh the information for the currently displayed Gear.
        /// </summary>
        public void RefreshSelectedGear()
        {
            bool blnClear = false;
            try
            {
                if (treGear.SelectedNode.Level == 0)
                    blnClear = true;
            }
            catch
            {
                blnClear = true;
            }
            if (blnClear)
            {
                lblGearRating.Text = "";
                lblGearQty.Text = "";
                cmdGearIncreaseQty.Enabled = false;
                cmdGearReduceQty.Enabled = false;
                chkGearEquipped.Text = LanguageManager.Instance.GetString("Checkbox_Equipped");
                chkGearEquipped.Visible = false;
                chkActiveCommlink.Visible = false;
                cmdGearSplitQty.Enabled = false;
                cmdGearMergeQty.Enabled = false;
                cmdGearMoveToVehicle.Enabled = false;
                tabGearMatrixCM.Visible = false;
                return;
            }
            cmdGearIncreaseQty.Enabled = false;
            chkGearHomeNode.Visible = false;

            if (treGear.SelectedNode.Level > 0)
            {
                Gear objGear = new Gear(_objCharacter);
                objGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);

                lblGearName.Text = objGear.DisplayNameShort;
                lblGearCategory.Text = objGear.DisplayCategory;
                lblGearAvail.Text = objGear.TotalAvail(true);
                try
                {
                    lblGearCost.Text = String.Format("{0:###,###,##0¥}", objGear.TotalCost);
                }
                catch
                {
                    lblGearCost.Text = objGear.Cost;
                }
                lblGearCapacity.Text = objGear.CalculatedCapacity + " (" + objGear.CapacityRemaining.ToString() + " " + LanguageManager.Instance.GetString("String_Remaining") + ")";
                string strBook = _objOptions.LanguageBookShort(objGear.Source);
                string strPage = objGear.Page;
                lblGearSource.Text = strBook + " " + strPage;
                tipTooltip.SetToolTip(lblGearSource, _objOptions.LanguageBookLong(objGear.Source) + " " + LanguageManager.Instance.GetString("String_Page") + " " + objGear.Page);

                _blnSkipRefresh = true;
                if (objGear.DeviceRating > 0)
                {
                    tabGearMatrixCM.Visible = true;
                    foreach (CheckBox objMatrixCM in tabMatrixCM.Controls.OfType<CheckBox>())
                    {
                        if (Convert.ToInt32(objMatrixCM.Tag.ToString()) <= objGear.MatrixCM)
                        {
                            if (Convert.ToInt32(objMatrixCM.Tag.ToString()) <= objGear.MatrixCMFilled)
                                objMatrixCM.Checked = true;
                            else
                                objMatrixCM.Checked = false;

                            objMatrixCM.Visible = true;
                        }
                        else
                        {
                            objMatrixCM.Checked = false;
                            objMatrixCM.Visible = false;
                            objMatrixCM.Text = "";
                        }
                    }
                }
                else
                {
                    tabGearMatrixCM.Visible = false;
                }
                _blnSkipRefresh = false;
                if (objGear.Category == "Ammunition")
                    cmdGearIncreaseQty.Enabled = true;

                if (objGear.GetType() == typeof(Commlink))
                {
                    Commlink objCommlink = (Commlink)objGear;
                    lblGearDeviceRating.Text = objCommlink.TotalDeviceRating.ToString();
                    _blnSkipRefresh = true;
                    chkActiveCommlink.Checked = objCommlink.IsActive;
                    _blnSkipRefresh = false;

                    cboGearOverclocker.Visible = _objCharacter.Overclocker;
                    lblGearOverclocker.Visible = _objCharacter.Overclocker;
                    ArrayList lstOverclocker = new ArrayList();
                    ListItem objAttribute = new ListItem();
                    objAttribute.Value = "None";
                    objAttribute.Name = LanguageManager.Instance.GetString("String_None");
                    lstOverclocker.Add(objAttribute);
                    if (_objCharacter.Overclocker)
                    {
                        objAttribute = new ListItem();
                        objAttribute.Value = "Attack";
                        objAttribute.Name = LanguageManager.Instance.GetString("String_Attack");
                        lstOverclocker.Add(objAttribute);
                        objAttribute = new ListItem();
                        objAttribute.Value = "Sleaze";
                        objAttribute.Name = LanguageManager.Instance.GetString("String_Sleaze");
                        lstOverclocker.Add(objAttribute);
                        objAttribute = new ListItem();
                        objAttribute.Value = "DataProc";
                        objAttribute.Name = LanguageManager.Instance.GetString("String_DataProcessing");
                        lstOverclocker.Add(objAttribute);
                        objAttribute = new ListItem();
                        objAttribute.Value = "Firewall";
                        objAttribute.Name = LanguageManager.Instance.GetString("String_Firewall");
                    }
                    lstOverclocker.Add(objAttribute);
                    cboGearOverclocker.BindingContext = new BindingContext();
                    cboGearOverclocker.DisplayMember = "Name";
                    cboGearOverclocker.ValueMember = "Value";
                    cboGearOverclocker.DataSource = lstOverclocker;
                    cboGearOverclocker.SelectedIndex = 0;

                    List<string> lstASDF = new List<string>() { objCommlink.Attack.ToString(), objCommlink.Sleaze.ToString(), objCommlink.DataProcessing.ToString(), objCommlink.Firewall.ToString() };
                    cboGearAttack.BindingContext = new BindingContext();
                    cboGearAttack.ValueMember = "Value";
                    cboGearAttack.DisplayMember = "Name";
                    cboGearAttack.DataSource = lstASDF;
                    cboGearAttack.SelectedIndex = 0;
                    cboGearAttack.Visible = true;
                    cboGearSleaze.BindingContext = new BindingContext();
                    cboGearSleaze.ValueMember = "Value";
                    cboGearSleaze.DisplayMember = "Name";
                    cboGearSleaze.DataSource = lstASDF;
                    cboGearSleaze.SelectedIndex = 1;
                    cboGearDataProcessing.BindingContext = new BindingContext();
                    cboGearDataProcessing.ValueMember = "Value";
                    cboGearDataProcessing.DisplayMember = "Name";
                    cboGearDataProcessing.DataSource = lstASDF;
                    cboGearDataProcessing.SelectedIndex = 2;
                    cboGearFirewall.BindingContext = new BindingContext();
                    cboGearFirewall.ValueMember = "Value";
                    cboGearFirewall.DisplayMember = "Name";
                    cboGearFirewall.DataSource = lstASDF;
                    cboGearFirewall.SelectedIndex = 3;
                    lblGearDeviceRating.Text = objCommlink.TotalDeviceRating.ToString();
                    cboCyberwareGearOverclocker.Visible = _objCharacter.Overclocker;
                    lblCyberwareGearOverclocker.Visible = _objCharacter.Overclocker;
                    cboGearAttack.Visible = true;
                    cboGearSleaze.Visible = true;
                    cboGearDataProcessing.Visible = true;
                    cboGearFirewall.Visible = true;
                    lblGearDeviceRating.Visible = true;
                    lblGearDeviceRatingLabel.Visible = true;
                    lblGearAttackLabel.Visible = true;
                    lblGearSleazeLabel.Visible = true;
                    lblGearDataProcessingLabel.Visible = true;
                    lblGearFirewallLabel.Visible = true;
                    if (objCommlink.Category != "Commlink Upgrade")
                        chkActiveCommlink.Visible = true;
                    if (_objCharacter.Metatype == "A.I.")
                    {
                        chkGearHomeNode.Visible = true;
                        chkGearHomeNode.Checked = objCommlink.HomeNode;
                    }
                }
                else
                {
                    cboCyberwareGearOverclocker.Visible = _objCharacter.Overclocker;
                    lblCyberwareGearOverclocker.Visible = _objCharacter.Overclocker;
                    lblGearDeviceRating.Text = objGear.DeviceRating.ToString();
                    chkActiveCommlink.Visible = false;
                    cboGearAttack.Visible = false;
                    cboGearSleaze.Visible = false;
                    cboGearDataProcessing.Visible = false;
                    cboGearFirewall.Visible = false;
                    lblGearAttackLabel.Visible = false;
                    lblGearSleazeLabel.Visible = false;
                    lblGearDataProcessingLabel.Visible = false;
                    lblGearFirewallLabel.Visible = false;
                }

                if (objGear.MaxRating > 0)
                    lblGearRating.Text = objGear.Rating.ToString();
                else
                    lblGearRating.Text = "";

                try
                {
                    lblGearQty.Text = objGear.Quantity.ToString();
                }
                catch
                {
                }

                if (treGear.SelectedNode.Level == 1)
                {
                    _blnSkipRefresh = true;
                    lblGearQty.Text = objGear.Quantity.ToString();
                    chkGearEquipped.Visible = true;
                    chkGearEquipped.Checked = objGear.Equipped;

                    _blnSkipRefresh = false;
                }
                else
                {
                    lblGearQty.Text = "1";
                    chkGearEquipped.Visible = true;
                    chkGearEquipped.Checked = objGear.Equipped;

                    // If this is a Program, determine if its parent Gear (if any) is a Commlink. If so, show the Equipped checkbox.
                    if (objGear.IsProgram && _objOptions.CalculateCommlinkResponse)
                    {
                        Gear objParent = new Gear(_objCharacter);
                        objParent = objGear.Parent;
                        if (objParent.Category != string.Empty)
                        {
                            if (objParent.Category == "Commlink" || objParent.Category == "Nexus")
                                chkGearEquipped.Text = LanguageManager.Instance.GetString("Checkbox_SoftwareRunning");
                        }
                    }
                }

                // Show the Weapon Bonus information if it's available.
                if (objGear.WeaponBonus != null)
                {
                    lblGearDamageLabel.Visible = true;
                    lblGearDamage.Visible = true;
                    lblGearAPLabel.Visible = true;
                    lblGearAP.Visible = true;
                    lblGearDamage.Text = objGear.WeaponBonusDamage();
                    lblGearAP.Text = objGear.WeaponBonusAP;
                }
                else
                {
                    lblGearDamageLabel.Visible = false;
                    lblGearDamage.Visible = false;
                    lblGearAPLabel.Visible = false;
                    lblGearAP.Visible = false;
                }

                cmdGearReduceQty.Enabled = true;

                treGear.SelectedNode.Text = objGear.DisplayName;
            }

            // Enable or disable the Split/Merge buttons as needed.
            if (treGear.SelectedNode.Level == 1)
            {
                cmdGearSplitQty.Enabled = true;
                cmdGearMergeQty.Enabled = true;
                if (_objCharacter.Vehicles.Count > 0)
                    cmdGearMoveToVehicle.Enabled = true;
                else
                    cmdGearMoveToVehicle.Enabled = false;
            }
            else
            {
                cmdGearSplitQty.Enabled = false;
                cmdGearMergeQty.Enabled = false;
                cmdGearMoveToVehicle.Enabled = false;
            }
        }
Exemple #5
0
        private void tsVehicleAddNexus_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;

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

            frmSelectNexus frmPickNexus = new frmSelectNexus(_objCharacter, true);
            frmPickNexus.ShowDialog(this);

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

            Gear objGear = new Gear(_objCharacter);
            objGear = frmPickNexus.SelectedNexus;

            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 (!frmPickNexus.FreeCost)
            {
                if (intCost > _objCharacter.Nuyen)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughNuyen"), LanguageManager.Instance.GetString("MessageTitle_NotEnoughNuyen"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    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;
                }
            }

            TreeNode nodNexus = new TreeNode();
            nodNexus.Text = objGear.Name;
            nodNexus.Tag = objGear.InternalId;
            nodNexus.ContextMenuStrip = cmsVehicleGear;

            foreach (Gear objChild in objGear.Children)
            {
                TreeNode nodModule = new TreeNode();
                nodModule.Text = objChild.Name;
                nodModule.Tag = objChild.InternalId;
                nodModule.ContextMenuStrip = cmsVehicleGear;
                nodNexus.Nodes.Add(nodModule);
                nodNexus.Expand();
            }

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

            objSelectedVehicle.Gear.Add(objGear);

            UpdateCharacterInfo();
            RefreshSelectedVehicle();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Exemple #6
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();
        }
Exemple #7
0
        private void tsCyberwareAddGear_Click(object sender, EventArgs e)
        {
            // Make sure a parent items is selected, then open the Select Gear window.
            try
            {
                if (treCyberware.SelectedNode.Level == 0)
                {
                    MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectCyberware"), LanguageManager.Instance.GetString("MessageTitle_SelectCyberware"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_SelectCyberware"), LanguageManager.Instance.GetString("MessageTitle_SelectCyberware"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Cyberware objCyberware = new Cyberware(_objCharacter);
            foreach (Cyberware objCharacterCyberware in _objCharacter.Cyberware)
            {
                if (objCharacterCyberware.InternalId == treCyberware.SelectedNode.Tag.ToString())
                {
                    objCyberware = objCharacterCyberware;
                    break;
                }

                foreach (Cyberware objChild in objCharacterCyberware.Children)
                {
                    if (objChild.InternalId == treCyberware.SelectedNode.Tag.ToString())
                    {
                        objCyberware = objChild;
                        break;
                    }
                }
            }

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

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true);
            string strCategories = "";
            foreach (XmlNode objXmlCategory in objCyberware.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)
                        tsCyberwareAddGear_Click(sender, e);

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

                    ExpenseUndo objUndo = new ExpenseUndo();
                    objUndo.CreateNuyen(NuyenExpenseType.AddCyberwareGear, 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 = cmsWeapon;
                treWeapons.Nodes[0].Nodes.Add(objWeaponNode);
                treWeapons.Nodes[0].Expand();
            }

            objCyberware.Gear.Add(objNewGear);

            objNode.ContextMenuStrip = cmsCyberwareGear;
            treCyberware.SelectedNode.Nodes.Add(objNode);
            treCyberware.SelectedNode.Expand();

            UpdateCharacterInfo();

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

            _blnIsDirty = true;
            UpdateWindowTitle();
        }
Exemple #8
0
        /// <summary>
        /// Select a piece of Gear to be added to the character.
        /// </summary>
        /// <param name="blnAmmoOnly">Whether or not only Ammunition should be shown in the window.</param>
        /// <param name="objStackGear">Whether or not the selected item should stack with a matching item on the character.</param>
        /// <param name="strForceItemValue">Force the user to select an item with the passed name..</param>
        private bool PickGear(bool blnAmmoOnly = false, Gear objStackGear = null, string strForceItemValue = "")
        {
            bool blnNullParent = false;
            Gear objSelectedGear = new Gear(_objCharacter);
            if (treGear.SelectedNode != null)
                objSelectedGear = _objFunctions.FindGear(treGear.SelectedNode.Tag.ToString(), _objCharacter.Gear);
            if (objSelectedGear == null)
            {
                objSelectedGear = new Gear(_objCharacter);
                blnNullParent = true;
            }

            ExpenseUndo objUndo = new ExpenseUndo();

            // 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 + "\"]");

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true, 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;

                        // Do not allow the user to add a new piece of Gear if its Capacity has been reached.
                        if (_objOptions.EnforceCapacity && objSelectedGear.CapacityRemaining < 0)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return false;
                        }
                    }

                    if (objSelectedGear.Category == "Commlink")
                    {
                        Commlink objCommlink = (Commlink)objSelectedGear;
                        frmPickGear.CommlinkResponse = objCommlink.DeviceRating;

                        // 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)
                            objCommlink.IsActive = true;
                    }
                }
            }
            catch
            {
            }

            if (blnAmmoOnly)
            {
                frmPickGear.AllowedCategories = "Ammunition";
                frmPickGear.SelectedGear = objSelectedGear.Name;
            }

            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.
            Gear objNewGear = new Gear(_objCharacter);
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();

            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:
                    string strForceValue = "";
                    if (blnAmmoOnly)
                    {
                        strForceValue = objSelectedGear.Extra;
                        try
                        {
                            treGear.SelectedNode = treGear.SelectedNode.Parent;
                        }
                        catch
                        {
                        }
                    }
                    if (strForceItemValue != "")
                        strForceValue = strForceItemValue;
                    Gear objGear = new Gear(_objCharacter);
                    objGear.Create(objXmlGear, _objCharacter, objNode, frmPickGear.SelectedRating, objWeapons, objWeaponNodes, strForceValue, frmPickGear.Hacked, frmPickGear.InherentProgram, true, true, frmPickGear.Aerodynamic);
                    objGear.Quantity = frmPickGear.SelectedQty;
                    objNode.Text = objGear.DisplayName;

                    objNewGear = objGear;
                    break;
            }

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

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

            //Reduce the Cost for Black Market Pipelin
            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");
            }

            int intCost = 0;
            if (objNewGear.Cost.Contains("Gear Cost"))
            {
                XPathNavigator nav = objXmlDocument.CreateNavigator();
                string strCost = objNewGear.Cost.Replace("Gear Cost", objSelectedGear.CalculatedCost.ToString());
                XPathExpression xprCost = nav.Compile(strCost);
                intCost = Convert.ToInt32(nav.Evaluate(xprCost).ToString());
            }
            else
            {
                intCost = Convert.ToInt32(objNewGear.TotalCost);
            }

            bool blnMatchFound = false;
            Gear objStackWith = new Gear(_objCharacter);
            // See if the character already has the item on them if they chose to stack.
            if (frmPickGear.Stack)
            {
                if (objStackGear != null)
                {
                    blnMatchFound = true;
                    objStackWith = objStackGear;
                }
                else
                {
                    foreach (Gear objCharacterGear in _objCharacter.Gear)
                    {
                        if (objCharacterGear.Name == objNewGear.Name && objCharacterGear.Category == objNewGear.Category && objCharacterGear.Rating == objNewGear.Rating && objCharacterGear.Extra == objNewGear.Extra)
                        {
                            blnMatchFound = true;
                            objStackWith = objCharacterGear;

                            break;
                        }
                    }
                }
            }

            if (blnMatchFound)
            {
                // If a match was found, we need to use the cost of a single item in the stack which can include plugins.
                foreach (Gear objPlugin in objStackWith.Children)
                    intCost += (objPlugin.TotalCost * frmPickGear.SelectedQty);
            }
            if (!blnNullParent && !blnAmmoOnly)
                intCost *= objSelectedGear.Quantity;

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

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

            // Do not allow the user to add a new piece of Cyberware if its Capacity has been reached.
            // This is wrapped in a try statement since the character may not have a piece of Gear selected and has clicked the Buy Additional Ammo button for a Weapon.
            try
            {
                if (!blnMatchFound && treGear.SelectedNode.Level > 0)
                {
                    if (_objOptions.EnforceCapacity && objSelectedGear.CapacityRemaining - objNewGear.PluginCapacity < 0)
                    {
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return false;
                    }
                }
            }
            catch
            {
            }

            // 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);
                    // Remove any Improvements created by the Gear.
                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objNewGear.InternalId);
                    return frmPickGear.AddAgain;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseGear") + " " + objNewGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    objUndo.CreateNuyen(NuyenExpenseType.AddGear, objNewGear.InternalId, objNewGear.Quantity);
                    objExpense.Undo = objUndo;
                }
            }

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

            if (blnMatchFound)
            {
                // A match was found, so increase the quantity instead.
                objStackWith.Quantity += objNewGear.Quantity;
                blnMatchFound = true;

                if (objUndo.ObjectId != "")
                    objUndo.ObjectId = objStackWith.InternalId;

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

            // Add the Gear.
            if (!blnMatchFound)
            {
                // 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();
                }

                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.
                lblGearQty.Text = objNewGear.Quantity.ToString();
                if (objNode.Level < 2)
                    treGear.SelectedNode = objNode;
            }

            _objCharacter.SkillsSection.ForceProperyChangedNotificationAll(nameof(Skill.PoolModifiers));

            UpdateCharacterInfo();
            RefreshSelectedGear();

            if (frmPickGear.DialogResult != DialogResult.Cancel)
            {
                _blnIsDirty = true;
                UpdateWindowTitle();
            }

            return frmPickGear.AddAgain;
        }
Exemple #9
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);
            ExpenseUndo objUndo = new ExpenseUndo();

            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 + "\"]");

            frmSelectGear frmPickGear = new frmSelectGear(_objCharacter, true);
            frmPickGear.EnableStack = false;
            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;

                        // Do not allow the user to add a new piece of Gear if its Capacity has been reached.
                        if (_objOptions.EnforceCapacity && objSelectedGear.CapacityRemaining < 0)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return false;
                        }
                    }

                    if (objSelectedGear.Category == "Commlink")
                    {
                        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.
            Gear objNewGear = new Gear(_objCharacter);
            List<Weapon> objWeapons = new List<Weapon>();
            List<TreeNode> objWeaponNodes = new List<TreeNode>();

            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;

                    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;

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

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

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

            // Do not allow the user to add new Gear if the Armor's Capacity has been reached.
            if (_objOptions.EnforceCapacity)
            {
                objSelectedArmor.Gear.Add(objSelectedGear);
                if (treArmor.SelectedNode.Level > 1)
                {
                    if (objSelectedGear.CapacityRemaining < 0)
                    {
                        objSelectedArmor.Gear.Remove(objSelectedGear);
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return frmPickGear.AddAgain;
                    }
                    else
                        objSelectedArmor.Gear.Remove(objSelectedGear);
                }
                else
                {
                    if (objSelectedArmor.CapacityRemaining < 0)
                    {
                        objSelectedArmor.Gear.Remove(objSelectedGear);
                        MessageBox.Show(LanguageManager.Instance.GetString("Message_CapacityReached"), LanguageManager.Instance.GetString("MessageTitle_CapacityReached"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return frmPickGear.AddAgain;
                    }
                    else
                        objSelectedArmor.Gear.Remove(objSelectedGear);
                }
            }

            // 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);
                    // Remove any Improvements created by the Gear.
                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objNewGear.InternalId);
                    return frmPickGear.AddAgain;
                }
                else
                {
                    // Create the Expense Log Entry.
                    ExpenseLogEntry objExpense = new ExpenseLogEntry();
                    objExpense.Create(intCost * -1, LanguageManager.Instance.GetString("String_ExpensePurchaseArmorGear") + " " + objNewGear.DisplayNameShort, ExpenseType.Nuyen, DateTime.Now);
                    _objCharacter.ExpenseEntries.Add(objExpense);
                    _objCharacter.Nuyen -= intCost;

                    objUndo.CreateNuyen(NuyenExpenseType.AddArmorGear, objNewGear.InternalId, objNewGear.Quantity);
                    objExpense.Undo = objUndo;
                }
            }

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

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

                        if (objUndo.ObjectId != "")
                            objUndo.ObjectId = objCharacterGear.InternalId;

                        foreach (TreeNode objGearNode in treGear.Nodes[0].Nodes)
                        {
                            if (objCharacterGear.InternalId == objGearNode.Tag.ToString())
                            {
                                objGearNode.Text = objCharacterGear.DisplayName;
                                treArmor.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.
                treArmor.SelectedNode = objNode;
            }

            UpdateCharacterInfo();
            RefreshSelectedArmor();

            _blnIsDirty = true;
            UpdateWindowTitle();

            return frmPickGear.AddAgain;
        }