Ejemplo n.º 1
0
        private void BuildWeaponList(XmlNodeList objNodeList)
        {
            SuspendLayout();
            if (tabControl.SelectedIndex == 1)
            {
                DataTable tabWeapons = new DataTable("weapons");
                tabWeapons.Columns.Add("WeaponGuid");
                tabWeapons.Columns.Add("WeaponName");
                tabWeapons.Columns.Add("Dice");
                tabWeapons.Columns.Add("Accuracy");
                tabWeapons.Columns.Add("Damage");
                tabWeapons.Columns.Add("AP");
                tabWeapons.Columns.Add("RC");
                tabWeapons.Columns.Add("Ammo");
                tabWeapons.Columns.Add("Mode");
                tabWeapons.Columns.Add("Reach");
                tabWeapons.Columns.Add("Concealability");
                tabWeapons.Columns.Add("Accessories");
                tabWeapons.Columns.Add("Avail");
                tabWeapons.Columns["Avail"].DataType = typeof(AvailabilityValue);
                tabWeapons.Columns.Add("Source");
                tabWeapons.Columns["Source"].DataType = typeof(SourceString);
                tabWeapons.Columns.Add("Cost");
                tabWeapons.Columns["Cost"].DataType = typeof(NuyenString);

                bool    blnAnyRanged            = false;
                bool    blnAnyMelee             = false;
                XmlNode xmlParentWeaponDataNode = _objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + ParentWeapon?.SourceIDString + "\"]");
                foreach (XmlNode objXmlWeapon in objNodeList)
                {
                    if (!objXmlWeapon.CreateNavigator().RequirementsMet(_objCharacter, ParentWeapon))
                    {
                        continue;
                    }

                    XmlNode xmlTestNode = objXmlWeapon.SelectSingleNode("forbidden/weapondetails");
                    if (xmlTestNode != null)
                    {
                        // Assumes topmost parent is an AND node
                        if (xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                        {
                            continue;
                        }
                    }
                    xmlTestNode = objXmlWeapon.SelectSingleNode("required/weapondetails");
                    if (xmlTestNode != null)
                    {
                        // Assumes topmost parent is an AND node
                        if (!xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                        {
                            continue;
                        }
                    }
                    if (objXmlWeapon["cyberware"]?.InnerText == bool.TrueString)
                    {
                        continue;
                    }
                    string strTest = objXmlWeapon["mount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strTest) && !Mounts.Contains(strTest))
                    {
                        continue;
                    }
                    strTest = objXmlWeapon["extramount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strTest) && !Mounts.Contains(strTest))
                    {
                        continue;
                    }
                    if (chkHideOverAvailLimit.Checked && !SelectionShared.CheckAvailRestriction(objXmlWeapon, _objCharacter))
                    {
                        continue;
                    }
                    if (!chkFreeItem.Checked && chkShowOnlyAffordItems.Checked)
                    {
                        decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                        if (_setBlackMarketMaps.Contains(objXmlWeapon["category"]?.InnerText))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        if (!SelectionShared.CheckNuyenRestriction(objXmlWeapon, _objCharacter.Nuyen, decCostMultiplier))
                        {
                            continue;
                        }
                    }

                    Weapon objWeapon = new Weapon(_objCharacter);
                    objWeapon.Create(objXmlWeapon, null, true, false, true);
                    objWeapon.Parent = ParentWeapon;
                    if (objWeapon.RangeType == "Ranged")
                    {
                        blnAnyRanged = true;
                    }
                    else
                    {
                        blnAnyMelee = true;
                    }
                    string strID         = objWeapon.SourceIDString;
                    string strWeaponName = objWeapon.CurrentDisplayName;
                    string strDice       = objWeapon.DicePool.ToString(GlobalOptions.CultureInfo);
                    string strAccuracy   = objWeapon.DisplayAccuracy;
                    string strDamage     = objWeapon.DisplayDamage;
                    string strAP         = objWeapon.DisplayTotalAP;
                    if (strAP == "-")
                    {
                        strAP = "0";
                    }
                    string        strRC          = objWeapon.DisplayTotalRC;
                    string        strAmmo        = objWeapon.DisplayAmmo;
                    string        strMode        = objWeapon.DisplayMode;
                    string        strReach       = objWeapon.TotalReach.ToString(GlobalOptions.CultureInfo);
                    string        strConceal     = objWeapon.DisplayConcealability;
                    StringBuilder sbdAccessories = new StringBuilder();
                    foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                    {
                        sbdAccessories.AppendLine(objAccessory.CurrentDisplayName);
                    }
                    if (sbdAccessories.Length > 0)
                    {
                        sbdAccessories.Length -= Environment.NewLine.Length;
                    }
                    AvailabilityValue objAvail  = objWeapon.TotalAvailTuple();
                    SourceString      strSource = new SourceString(objWeapon.Source, objWeapon.DisplayPage(GlobalOptions.Language), GlobalOptions.Language, GlobalOptions.CultureInfo);
                    NuyenString       strCost   = new NuyenString(objWeapon.DisplayCost(out decimal _));

                    tabWeapons.Rows.Add(strID, strWeaponName, strDice, strAccuracy, strDamage, strAP, strRC, strAmmo, strMode, strReach, strConceal, sbdAccessories.ToString(), objAvail, strSource, strCost);
                }

                DataSet set = new DataSet("weapons");
                set.Tables.Add(tabWeapons);
                if (blnAnyRanged)
                {
                    dgvWeapons.Columns[6].Visible = true;
                    dgvWeapons.Columns[7].Visible = true;
                    dgvWeapons.Columns[8].Visible = true;
                }
                else
                {
                    dgvWeapons.Columns[6].Visible = false;
                    dgvWeapons.Columns[7].Visible = false;
                    dgvWeapons.Columns[8].Visible = false;
                }
                if (blnAnyMelee)
                {
                    dgvWeapons.Columns[9].Visible = true;
                }
                else
                {
                    dgvWeapons.Columns[9].Visible = false;
                }
                dgvWeapons.Columns[0].Visible = false;
                dgvWeapons.Columns[13].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
                dgvWeapons.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                dgvWeapons.DataSource       = set;
                dgvWeapons.DataMember       = "weapons";
            }
            else
            {
                int             intOverLimit            = 0;
                List <ListItem> lstWeapons              = new List <ListItem>();
                XmlNode         xmlParentWeaponDataNode = _objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + ParentWeapon?.SourceIDString + "\"]");
                foreach (XmlNode objXmlWeapon in objNodeList)
                {
                    if (!objXmlWeapon.CreateNavigator().RequirementsMet(_objCharacter, ParentWeapon))
                    {
                        continue;
                    }

                    XmlNode xmlTestNode = objXmlWeapon.SelectSingleNode("forbidden/weapondetails");
                    if (xmlTestNode != null)
                    {
                        // Assumes topmost parent is an AND node
                        if (xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                        {
                            continue;
                        }
                    }
                    xmlTestNode = objXmlWeapon.SelectSingleNode("required/weapondetails");
                    if (xmlTestNode != null)
                    {
                        // Assumes topmost parent is an AND node
                        if (!xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                        {
                            continue;
                        }
                    }
                    if (objXmlWeapon["cyberware"]?.InnerText == bool.TrueString)
                    {
                        continue;
                    }

                    string strMount = objXmlWeapon["mount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strMount) && !Mounts.Contains(strMount))
                    {
                        continue;
                    }

                    string strExtraMount = objXmlWeapon["extramount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strExtraMount) && !Mounts.Contains(strExtraMount))
                    {
                        continue;
                    }

                    if (chkHideOverAvailLimit.Checked && !SelectionShared.CheckAvailRestriction(objXmlWeapon, _objCharacter))
                    {
                        ++intOverLimit;
                        continue;
                    }
                    if (!chkFreeItem.Checked && chkShowOnlyAffordItems.Checked)
                    {
                        decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                        if (_setBlackMarketMaps.Contains(objXmlWeapon["category"]?.InnerText))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        if (!string.IsNullOrEmpty(ParentWeapon?.DoubledCostModificationSlots) &&
                            (!string.IsNullOrEmpty(strMount) || !string.IsNullOrEmpty(strExtraMount)))
                        {
                            string[] astrParentDoubledCostModificationSlots = ParentWeapon.DoubledCostModificationSlots.Split('/', StringSplitOptions.RemoveEmptyEntries);
                            if (astrParentDoubledCostModificationSlots.Contains(strMount) || astrParentDoubledCostModificationSlots.Contains(strExtraMount))
                            {
                                decCostMultiplier *= 2;
                            }
                        }
                        if (!SelectionShared.CheckNuyenRestriction(objXmlWeapon, _objCharacter.Nuyen, decCostMultiplier))
                        {
                            ++intOverLimit;
                            continue;
                        }
                    }
                    lstWeapons.Add(new ListItem(objXmlWeapon["id"]?.InnerText, objXmlWeapon["translate"]?.InnerText ?? objXmlWeapon["name"]?.InnerText));
                }

                lstWeapons.Sort(CompareListItems.CompareNames);
                if (intOverLimit > 0)
                {
                    // Add after sort so that it's always at the end
                    lstWeapons.Add(new ListItem(string.Empty,
                                                string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("String_RestrictedItemsHidden"),
                                                              intOverLimit)));
                }
                string strOldSelected = lstWeapon.SelectedValue?.ToString();
                _blnLoading = true;
                lstWeapon.BeginUpdate();
                lstWeapon.ValueMember   = nameof(ListItem.Value);
                lstWeapon.DisplayMember = nameof(ListItem.Name);
                lstWeapon.DataSource    = lstWeapons;
                _blnLoading             = false;
                if (!string.IsNullOrEmpty(strOldSelected))
                {
                    lstWeapon.SelectedValue = strOldSelected;
                }
                else
                {
                    lstWeapon.SelectedIndex = -1;
                }
                lstWeapon.EndUpdate();
            }
            ResumeLayout();
        }
Ejemplo n.º 2
0
        private async ValueTask UpdateWeaponInfo()
        {
            if (_blnLoading || _blnSkipUpdate)
            {
                return;
            }
            _blnSkipUpdate = true;
            await this.DoThreadSafeAsync(x => x.SuspendLayout());

            try
            {
                if (_objSelectedWeapon != null)
                {
                    bool blnCanBlackMarketDiscount = _setBlackMarketMaps.Contains(_objSelectedWeapon.Category);
                    await chkBlackMarketDiscount.DoThreadSafeAsync(x =>
                    {
                        x.Enabled = blnCanBlackMarketDiscount;
                        if (!x.Checked)
                        {
                            x.Checked = GlobalSettings.AssumeBlackMarket && blnCanBlackMarketDiscount;
                        }
                        else if (!blnCanBlackMarketDiscount)
                        {
                            //Prevent chkBlackMarketDiscount from being checked if the category doesn't match.
                            x.Checked = false;
                        }

                        _objSelectedWeapon.DiscountCost = x.Checked;
                    });

                    string strReach = _objSelectedWeapon.TotalReach.ToString(GlobalSettings.CultureInfo);
                    await lblWeaponReach.DoThreadSafeAsync(x => x.Text = strReach);

                    await lblWeaponReachLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strReach));

                    string strDamage = _objSelectedWeapon.DisplayDamage;
                    await lblWeaponDamage.DoThreadSafeAsync(x => x.Text = strDamage);

                    await lblWeaponDamageLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strDamage));

                    string strAP = _objSelectedWeapon.DisplayTotalAP;
                    await lblWeaponAP.DoThreadSafeAsync(x => x.Text = strAP);

                    await lblWeaponAPLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strAP));

                    string strMode = _objSelectedWeapon.DisplayMode;
                    await lblWeaponMode.DoThreadSafeAsync(x => x.Text = strMode);

                    await lblWeaponModeLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strMode));

                    string strRC = _objSelectedWeapon.DisplayTotalRC;
                    await lblWeaponRC.DoThreadSafeAsync(x => x.Text = strRC);

                    await lblWeaponRC.SetToolTipAsync(_objSelectedWeapon.RCToolTip);

                    await lblWeaponRCLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strRC));

                    string strAmmo = _objSelectedWeapon.DisplayAmmo;
                    await lblWeaponAmmo.DoThreadSafeAsync(x => x.Text = strAmmo);

                    await lblWeaponAmmoLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strAmmo));

                    string strAccuracy = _objSelectedWeapon.DisplayAccuracy;
                    await lblWeaponAccuracy.DoThreadSafeAsync(x => x.Text = strAccuracy);

                    await lblWeaponAccuracyLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strAccuracy));

                    string strConceal = _objSelectedWeapon.DisplayConcealability;
                    await lblWeaponConceal.DoThreadSafeAsync(x => x.Text = strConceal);

                    await lblWeaponConcealLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strConceal));

                    decimal decItemCost = 0;
                    string  strWeaponCost;
                    if (await chkFreeItem.DoThreadSafeFuncAsync(x => x.Checked))
                    {
                        strWeaponCost = (0.0m).ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + '¥';
                    }
                    else
                    {
                        strWeaponCost = _objSelectedWeapon.DisplayCost(out decItemCost, await nudMarkup.DoThreadSafeFuncAsync(x => x.Value) / 100.0m);
                    }

                    await lblWeaponCost.DoThreadSafeAsync(x => x.Text = strWeaponCost);

                    await lblWeaponCostLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strWeaponCost));

                    AvailabilityValue objTotalAvail = _objSelectedWeapon.TotalAvailTuple();
                    string            strAvail      = objTotalAvail.ToString();
                    await lblWeaponAvail.DoThreadSafeAsync(x => x.Text = strAvail);

                    await lblWeaponAvailLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strAvail));

                    string strTest = _objCharacter.AvailTest(decItemCost, objTotalAvail);
                    await lblTest.DoThreadSafeAsync(x => x.Text = strTest);

                    await lblTestLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strTest));

                    await _objSelectedWeapon.SetSourceDetailAsync(lblSource);

                    await lblSource.DoThreadSafeFuncAsync(x => x.Text)
                    .ContinueWith(y => lblSourceLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(y.Result)))
                    .Unwrap();

                    string strIncludedAccessores;
                    // Build a list of included Accessories and Modifications that come with the weapon.
                    using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                                   out StringBuilder sbdAccessories))
                    {
                        foreach (WeaponAccessory objAccessory in _objSelectedWeapon.WeaponAccessories)
                        {
                            sbdAccessories.AppendLine(objAccessory.CurrentDisplayName);
                        }

                        if (sbdAccessories.Length > 0)
                        {
                            sbdAccessories.Length -= Environment.NewLine.Length;
                        }

                        strIncludedAccessores = sbdAccessories.Length == 0
                            ? await LanguageManager.GetStringAsync("String_None")
                            : sbdAccessories.ToString();
                    }

                    await lblIncludedAccessories.DoThreadSafeAsync(x => x.Text = strIncludedAccessores);

                    await tlpRight.DoThreadSafeAsync(x => x.Visible = true);

                    await gpbIncludedAccessories.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strIncludedAccessores));
                }
                else
                {
                    await chkBlackMarketDiscount.DoThreadSafeAsync(x => x.Checked = false);

                    await tlpRight.DoThreadSafeAsync(x => x.Visible = false);

                    await gpbIncludedAccessories.DoThreadSafeAsync(x => x.Visible = false);
                }
            }
            finally
            {
                await this.DoThreadSafeAsync(x => x.ResumeLayout());
            }
            _blnSkipUpdate = false;
        }
Ejemplo n.º 3
0
        private void UpdateInfo()
        {
            if (_blnLoading)
            {
                return;
            }

            XmlNode xmlSelectedMount = null;
            string  strSelectedMount = cboSize.SelectedValue?.ToString();

            if (string.IsNullOrEmpty(strSelectedMount))
            {
                cmdOK.Enabled = false;
            }
            else
            {
                xmlSelectedMount = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedMount + "\"]");
                if (xmlSelectedMount == null)
                {
                    cmdOK.Enabled = false;
                }
                else
                {
                    string strSelectedControl = cboControl.SelectedValue?.ToString();
                    if (string.IsNullOrEmpty(strSelectedControl))
                    {
                        cmdOK.Enabled = false;
                    }
                    else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedControl + "\"]") == null)
                    {
                        cmdOK.Enabled = false;
                    }
                    else
                    {
                        string strSelectedFlexibility = cboFlexibility.SelectedValue?.ToString();
                        if (string.IsNullOrEmpty(strSelectedFlexibility))
                        {
                            cmdOK.Enabled = false;
                        }
                        else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedFlexibility + "\"]") == null)
                        {
                            cmdOK.Enabled = false;
                        }
                        else
                        {
                            string strSelectedVisibility = cboVisibility.SelectedValue?.ToString();
                            if (string.IsNullOrEmpty(strSelectedVisibility))
                            {
                                cmdOK.Enabled = false;
                            }
                            else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedVisibility + "\"]") == null)
                            {
                                cmdOK.Enabled = false;
                            }
                            else
                            {
                                cmdOK.Enabled = true;
                            }
                        }
                    }
                }
            }

            string[] astrSelectedValues = { cboVisibility.SelectedValue?.ToString(), cboFlexibility.SelectedValue?.ToString(), cboControl.SelectedValue?.ToString() };

            cmdDeleteMod.Enabled = false;
            string strSelectedModId = treMods.SelectedNode?.Tag.ToString();
            string strSpace         = LanguageManager.GetString("String_Space");

            if (!string.IsNullOrEmpty(strSelectedModId) && strSelectedModId.IsGuid())
            {
                VehicleMod objMod = _lstMods.FirstOrDefault(x => x.InternalId == strSelectedModId);
                if (objMod != null)
                {
                    cmdDeleteMod.Enabled = !objMod.IncludedInVehicle;
                    lblSlots.Text        = objMod.CalculatedSlots.ToString(GlobalOptions.InvariantCultureInfo);
                    lblAvailability.Text = objMod.DisplayTotalAvail;

                    if (chkFreeItem.Checked)
                    {
                        lblCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    }
                    else
                    {
                        int intTotalSlots = Convert.ToInt32(xmlSelectedMount?["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                        foreach (string strSelectedId in astrSelectedValues)
                        {
                            if (!string.IsNullOrEmpty(strSelectedId))
                            {
                                XmlNode xmlLoopNode = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedId + "\"]");
                                if (xmlLoopNode != null)
                                {
                                    intTotalSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                                }
                            }
                        }
                        foreach (VehicleMod objLoopMod in _lstMods)
                        {
                            intTotalSlots += objLoopMod.CalculatedSlots;
                        }
                        lblCost.Text = (objMod.TotalCostInMountCreation(intTotalSlots) * (1 + (nudMarkup.Value / 100.0m))).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    }

                    objMod.SetSourceDetail(lblSource);
                    lblCostLabel.Visible         = !string.IsNullOrEmpty(lblCost.Text);
                    lblSlotsLabel.Visible        = !string.IsNullOrEmpty(lblSlots.Text);
                    lblAvailabilityLabel.Visible = !string.IsNullOrEmpty(lblAvailability.Text);
                    lblSourceLabel.Visible       = !string.IsNullOrEmpty(lblSource.Text);
                    return;
                }
            }

            if (xmlSelectedMount == null)
            {
                lblCost.Text                 = string.Empty;
                lblSlots.Text                = string.Empty;
                lblAvailability.Text         = string.Empty;
                lblCostLabel.Visible         = false;
                lblSlotsLabel.Visible        = false;
                lblAvailabilityLabel.Visible = false;
                return;
            }
            decimal decCost  = !chkFreeItem.Checked ? Convert.ToDecimal(xmlSelectedMount["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo) : 0;
            int     intSlots = Convert.ToInt32(xmlSelectedMount["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);

            string strAvail       = xmlSelectedMount["avail"]?.InnerText ?? string.Empty;
            char   chrAvailSuffix = strAvail.Length > 0 ? strAvail[strAvail.Length - 1] : ' ';

            if (chrAvailSuffix == 'F' || chrAvailSuffix == 'R')
            {
                strAvail = strAvail.Substring(0, strAvail.Length - 1);
            }
            else
            {
                chrAvailSuffix = ' ';
            }
            int intAvail = Convert.ToInt32(strAvail, GlobalOptions.InvariantCultureInfo);

            foreach (string strSelectedId in astrSelectedValues)
            {
                if (!string.IsNullOrEmpty(strSelectedId))
                {
                    XmlNode xmlLoopNode = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedId + "\"]");
                    if (xmlLoopNode != null)
                    {
                        if (!chkFreeItem.Checked)
                        {
                            decCost += Convert.ToInt32(xmlLoopNode["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                        }

                        intSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);

                        string strLoopAvail       = xmlLoopNode["avail"]?.InnerText ?? string.Empty;
                        char   chrLoopAvailSuffix = strLoopAvail.Length > 0 ? strLoopAvail[strLoopAvail.Length - 1] : ' ';
                        if (chrLoopAvailSuffix == 'F')
                        {
                            strLoopAvail   = strLoopAvail.Substring(0, strLoopAvail.Length - 1);
                            chrAvailSuffix = 'F';
                        }
                        else if (chrLoopAvailSuffix == 'R')
                        {
                            strLoopAvail = strLoopAvail.Substring(0, strLoopAvail.Length - 1);
                            if (chrAvailSuffix == ' ')
                            {
                                chrAvailSuffix = 'R';
                            }
                        }
                        intAvail += Convert.ToInt32(strLoopAvail, GlobalOptions.InvariantCultureInfo);
                    }
                }
            }
            foreach (VehicleMod objMod in _lstMods)
            {
                intSlots += objMod.CalculatedSlots;
                AvailabilityValue objLoopAvail = objMod.TotalAvailTuple();
                char chrLoopAvailSuffix        = objLoopAvail.Suffix;
                if (chrLoopAvailSuffix == 'F')
                {
                    chrAvailSuffix = 'F';
                }
                else if (chrAvailSuffix != 'F' && chrLoopAvailSuffix == 'R')
                {
                    chrAvailSuffix = 'R';
                }
                intAvail += objLoopAvail.Value;
            }
            if (!chkFreeItem.Checked)
            {
                foreach (VehicleMod objMod in _lstMods)
                {
                    decCost += objMod.TotalCostInMountCreation(intSlots);
                }
            }

            string strAvailText = intAvail.ToString(GlobalOptions.CultureInfo);

            if (chrAvailSuffix == 'F')
            {
                strAvailText += LanguageManager.GetString("String_AvailForbidden");
            }
            else if (chrAvailSuffix == 'R')
            {
                strAvailText += LanguageManager.GetString("String_AvailRestricted");
            }

            decCost                     *= 1 + (nudMarkup.Value / 100.0m);
            lblCost.Text                 = decCost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
            lblSlots.Text                = intSlots.ToString(GlobalOptions.CultureInfo);
            lblAvailability.Text         = strAvailText;
            lblCostLabel.Visible         = !string.IsNullOrEmpty(lblCost.Text);
            lblSlotsLabel.Visible        = !string.IsNullOrEmpty(lblSlots.Text);
            lblAvailabilityLabel.Visible = !string.IsNullOrEmpty(lblAvailability.Text);

            string strSource = xmlSelectedMount["source"]?.InnerText ?? LanguageManager.GetString("String_Unknown");
            string strPage   = xmlSelectedMount["altpage"]?.InnerText ?? xmlSelectedMount["page"]?.InnerText ?? LanguageManager.GetString("String_Unknown");

            lblSource.Text = CommonFunctions.LanguageBookShort(strSource) + strSpace + strPage;
            lblSource.SetToolTip(CommonFunctions.LanguageBookLong(strSource) + strSpace +
                                 LanguageManager.GetString("String_Page") + strSpace + strPage);
            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
        }
Ejemplo n.º 4
0
        private void UpdateWeaponInfo()
        {
            if (_blnLoading || _blnSkipUpdate)
            {
                return;
            }
            _blnSkipUpdate = true;
            SuspendLayout();
            if (_objSelectedWeapon != null)
            {
                chkBlackMarketDiscount.Enabled = _objCharacter.BlackMarketDiscount;

                if (!chkBlackMarketDiscount.Checked)
                {
                    chkBlackMarketDiscount.Checked = GlobalOptions.AssumeBlackMarket &&
                                                     _setBlackMarketMaps.Contains(_objSelectedWeapon.Category);
                }
                else if (!_setBlackMarketMaps.Contains(_objSelectedWeapon.Category))
                {
                    //Prevent chkBlackMarketDiscount from being checked if the gear category doesn't match.
                    chkBlackMarketDiscount.Checked = false;
                }

                _objSelectedWeapon.DiscountCost = chkBlackMarketDiscount.Checked;

                lblWeaponReach.Text          = _objSelectedWeapon.TotalReach.ToString(GlobalOptions.CultureInfo);
                lblWeaponReachLabel.Visible  = !string.IsNullOrEmpty(lblWeaponReach.Text);
                lblWeaponDamage.Text         = _objSelectedWeapon.DisplayDamage;
                lblWeaponDamageLabel.Visible = !string.IsNullOrEmpty(lblWeaponDamage.Text);
                lblWeaponAP.Text             = _objSelectedWeapon.DisplayTotalAP;
                lblWeaponAPLabel.Visible     = !string.IsNullOrEmpty(lblWeaponAP.Text);
                lblWeaponMode.Text           = _objSelectedWeapon.DisplayMode;
                lblWeaponModeLabel.Visible   = !string.IsNullOrEmpty(lblWeaponMode.Text);
                lblWeaponRC.Text             = _objSelectedWeapon.DisplayTotalRC;
                lblWeaponRC.SetToolTip(_objSelectedWeapon.RCToolTip);
                lblWeaponRCLabel.Visible       = !string.IsNullOrEmpty(lblWeaponRC.Text);
                lblWeaponAmmo.Text             = _objSelectedWeapon.DisplayAmmo;
                lblWeaponAmmoLabel.Visible     = !string.IsNullOrEmpty(lblWeaponAmmo.Text);
                lblWeaponAccuracy.Text         = _objSelectedWeapon.DisplayAccuracy;
                lblWeaponAccuracyLabel.Visible = !string.IsNullOrEmpty(lblWeaponAccuracy.Text);
                lblWeaponConceal.Text          = _objSelectedWeapon.DisplayConcealability;
                lblWeaponConcealLabel.Visible  = !string.IsNullOrEmpty(lblWeaponConceal.Text);

                decimal decItemCost = 0;
                if (chkFreeItem.Checked)
                {
                    lblWeaponCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                }
                else
                {
                    lblWeaponCost.Text = _objSelectedWeapon.DisplayCost(out decItemCost, nudMarkup.Value / 100.0m);
                }
                lblWeaponCostLabel.Visible = !string.IsNullOrEmpty(lblWeaponCost.Text);

                AvailabilityValue objTotalAvail = _objSelectedWeapon.TotalAvailTuple();
                lblWeaponAvail.Text         = objTotalAvail.ToString();
                lblWeaponAvailLabel.Visible = !string.IsNullOrEmpty(lblWeaponAvail.Text);
                lblTest.Text         = _objCharacter.AvailTest(decItemCost, objTotalAvail);
                lblTestLabel.Visible = !string.IsNullOrEmpty(lblTest.Text);
                _objSelectedWeapon.SetSourceDetail(lblSource);
                lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);

                // Build a list of included Accessories and Modifications that come with the weapon.
                StringBuilder strAccessories = new StringBuilder();
                foreach (WeaponAccessory objAccessory in _objSelectedWeapon.WeaponAccessories)
                {
                    strAccessories.AppendLine(objAccessory.CurrentDisplayName);
                }
                if (strAccessories.Length > 0)
                {
                    strAccessories.Length -= Environment.NewLine.Length;
                }

                lblIncludedAccessories.Text    = strAccessories.Length == 0 ? LanguageManager.GetString("String_None") : strAccessories.ToString();
                gpbIncludedAccessories.Visible = !string.IsNullOrEmpty(lblIncludedAccessories.Text);
            }
            else
            {
                chkBlackMarketDiscount.Checked = false;
                lblWeaponReach.Text            = string.Empty;
                lblWeaponReachLabel.Visible    = false;
                lblWeaponDamage.Text           = string.Empty;
                lblWeaponDamageLabel.Visible   = false;
                lblWeaponAP.Text           = string.Empty;
                lblWeaponAPLabel.Visible   = false;
                lblWeaponMode.Text         = string.Empty;
                lblWeaponModeLabel.Visible = false;
                lblWeaponRC.Text           = string.Empty;
                lblWeaponRC.SetToolTip(string.Empty);
                lblWeaponRCLabel.Visible       = false;
                lblWeaponAmmo.Text             = string.Empty;
                lblWeaponAmmoLabel.Visible     = false;
                lblWeaponAccuracy.Text         = string.Empty;
                lblWeaponAccuracyLabel.Visible = false;
                lblWeaponConceal.Text          = string.Empty;
                lblWeaponConcealLabel.Visible  = false;
                lblWeaponCost.Text             = string.Empty;
                lblWeaponCostLabel.Visible     = false;
                lblWeaponAvail.Text            = string.Empty;
                lblWeaponAvailLabel.Visible    = false;
                lblTest.Text                   = string.Empty;
                lblTestLabel.Visible           = false;
                lblSource.Text                 = string.Empty;
                lblSourceLabel.Visible         = false;
                lblIncludedAccessories.Text    = string.Empty;
                gpbIncludedAccessories.Visible = false;
                lblSource.SetToolTip(string.Empty);
            }
            ResumeLayout();
            _blnSkipUpdate = false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Builds the list of Armors to render in the active tab.
        /// </summary>
        /// <param name="objXmlArmorList">XmlNodeList of Armors to render.</param>
        private void BuildArmorList(XmlNodeList objXmlArmorList)
        {
            switch (tabControl.SelectedIndex)
            {
            case 1:
                DataTable tabArmor = new DataTable("armor");
                tabArmor.Columns.Add("ArmorGuid");
                tabArmor.Columns.Add("ArmorName");
                tabArmor.Columns.Add("Armor");
                tabArmor.Columns["Armor"].DataType = typeof(int);
                tabArmor.Columns.Add("Capacity");
                tabArmor.Columns["Capacity"].DataType = typeof(decimal);
                tabArmor.Columns.Add("Avail");
                tabArmor.Columns["Avail"].DataType = typeof(AvailabilityValue);
                tabArmor.Columns.Add("Special");
                tabArmor.Columns.Add("Source");
                tabArmor.Columns["Source"].DataType = typeof(SourceString);
                tabArmor.Columns.Add("Cost");
                tabArmor.Columns["Cost"].DataType = typeof(NuyenString);

                // Populate the Armor list.
                foreach (XmlNode objXmlArmor in objXmlArmorList)
                {
                    decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                    if (_setBlackMarketMaps.Contains(objXmlArmor["category"]?.InnerText))
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    if (!chkHideOverAvailLimit.Checked || SelectionShared.CheckAvailRestriction(objXmlArmor, _objCharacter) &&
                        (chkFreeItem.Checked || !chkShowOnlyAffordItems.Checked ||
                         SelectionShared.CheckNuyenRestriction(objXmlArmor, _objCharacter.Nuyen, decCostMultiplier)))
                    {
                        Armor         objArmor   = new Armor(_objCharacter);
                        List <Weapon> lstWeapons = new List <Weapon>();
                        objArmor.Create(objXmlArmor, 0, lstWeapons, true, true, true);

                        string            strArmorGuid   = objArmor.SourceIDString;
                        string            strArmorName   = objArmor.CurrentDisplayName;
                        int               intArmor       = objArmor.TotalArmor;
                        decimal           decCapacity    = Convert.ToDecimal(objArmor.CalculatedCapacity, GlobalOptions.CultureInfo);
                        AvailabilityValue objAvail       = objArmor.TotalAvailTuple();
                        StringBuilder     strAccessories = new StringBuilder();
                        foreach (ArmorMod objMod in objArmor.ArmorMods)
                        {
                            strAccessories.AppendLine(objMod.CurrentDisplayName);
                        }
                        foreach (Gear objGear in objArmor.Gear)
                        {
                            strAccessories.AppendLine(objGear.CurrentDisplayName);
                        }
                        if (strAccessories.Length > 0)
                        {
                            strAccessories.Length -= Environment.NewLine.Length;
                        }
                        SourceString strSource = new SourceString(objArmor.Source, objArmor.DisplayPage(GlobalOptions.Language), GlobalOptions.Language);
                        NuyenString  strCost   = new NuyenString(objArmor.DisplayCost(out decimal _, false));

                        tabArmor.Rows.Add(strArmorGuid, strArmorName, intArmor, decCapacity, objAvail, strAccessories.ToString(), strSource, strCost);
                    }
                }

                DataSet set = new DataSet("armor");
                set.Tables.Add(tabArmor);

                dgvArmor.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                dgvArmor.DataSource       = set;
                dgvArmor.DataMember       = "armor";
                break;

            default:
                List <ListItem> lstArmors    = new List <ListItem>();
                int             intOverLimit = 0;
                string          strSpace     = LanguageManager.GetString("String_Space");
                foreach (XmlNode objXmlArmor in objXmlArmorList)
                {
                    decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                    if (_setBlackMarketMaps.Contains(objXmlArmor["category"]?.InnerText))
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    if ((!chkHideOverAvailLimit.Checked ||
                         (chkHideOverAvailLimit.Checked &&
                          SelectionShared.CheckAvailRestriction(objXmlArmor, _objCharacter))) &&
                        (chkFreeItem.Checked ||
                         !chkShowOnlyAffordItems.Checked ||
                         (chkShowOnlyAffordItems.Checked &&
                          SelectionShared.CheckNuyenRestriction(objXmlArmor, _objCharacter.Nuyen, decCostMultiplier))))
                    {
                        string strDisplayName = objXmlArmor["translate"]?.InnerText ?? objXmlArmor["name"]?.InnerText;
                        if (!_objCharacter.Options.SearchInCategoryOnly && txtSearch.TextLength != 0)
                        {
                            string strCategory = objXmlArmor["category"]?.InnerText;
                            if (!string.IsNullOrEmpty(strCategory))
                            {
                                ListItem objFoundItem = _lstCategory.Find(objFind => objFind.Value.ToString() == strCategory);
                                if (!string.IsNullOrEmpty(objFoundItem.Name))
                                {
                                    strDisplayName += strSpace + '[' + objFoundItem.Name + ']';
                                }
                            }
                        }

                        lstArmors.Add(new ListItem(objXmlArmor["id"]?.InnerText, strDisplayName));
                    }
                    else
                    {
                        ++intOverLimit;
                    }
                }

                lstArmors.Sort(CompareListItems.CompareNames);
                if (intOverLimit > 0)
                {
                    // Add after sort so that it's always at the end
                    lstArmors.Add(new ListItem(string.Empty,
                                               LanguageManager.GetString("String_RestrictedItemsHidden")
                                               .Replace("{0}", intOverLimit.ToString(GlobalOptions.CultureInfo))));
                }
                _blnLoading = true;
                string strOldSelected = lstArmor.SelectedValue?.ToString();
                lstArmor.BeginUpdate();
                lstArmor.ValueMember   = "Value";
                lstArmor.DisplayMember = "Name";
                lstArmor.DataSource    = lstArmors;
                _blnLoading            = false;
                if (!string.IsNullOrEmpty(strOldSelected))
                {
                    lstArmor.SelectedValue = strOldSelected;
                }
                else
                {
                    lstArmor.SelectedIndex = -1;
                }
                lstArmor.EndUpdate();
                break;
            }
        }
Ejemplo n.º 6
0
        private void UpdateArmorInfo()
        {
            if (_blnLoading || _blnSkipUpdate)
            {
                return;
            }

            _blnSkipUpdate = true;
            if (_objSelectedArmor != null)
            {
                chkBlackMarketDiscount.Enabled = _objCharacter.BlackMarketDiscount;
                chkBlackMarketDiscount.Checked = GlobalOptions.AssumeBlackMarket && _setBlackMarketMaps.Contains(_objSelectedArmor.Category);

                _objSelectedArmor.DiscountCost = chkBlackMarketDiscount.Checked;
                _objSelectedArmor.Rating       = decimal.ToInt32(nudRating.Value);

                lblSource.Text = _objSelectedArmor.SourceDetail.ToString();
                lblSource.SetToolTip(_objSelectedArmor.SourceDetail.LanguageBookTooltip);
                lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);

                lblArmorValueLabel.Visible = true;
                lblArmorValue.Text         = _objSelectedArmor.DisplayArmorValue;
                lblCapacityLabel.Visible   = true;
                lblCapacity.Text           = _objSelectedArmor.CalculatedCapacity;

                lblCostLabel.Visible = true;
                decimal decItemCost = 0;
                if (chkFreeItem.Checked)
                {
                    lblCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                }
                else
                {
                    lblCost.Text = _objSelectedArmor.DisplayCost(out decItemCost, true, nudMarkup.Value / 100.0m);
                }

                AvailabilityValue objTotalAvail = _objSelectedArmor.TotalAvailTuple();
                lblAvailLabel.Visible = true;
                lblTestLabel.Visible  = true;
                lblAvail.Text         = objTotalAvail.ToString();
                lblTest.Text          = _objCharacter.AvailTest(decItemCost, objTotalAvail);
            }
            else
            {
                chkBlackMarketDiscount.Enabled = false;
                chkBlackMarketDiscount.Checked = false;
                lblSourceLabel.Visible         = false;
                lblSource.Text = string.Empty;
                lblSource.SetToolTip(string.Empty);

                lblArmorValueLabel.Visible = false;
                lblArmorValue.Text         = string.Empty;
                lblCapacityLabel.Visible   = false;
                lblCapacity.Text           = string.Empty;
                lblCostLabel.Visible       = false;
                lblCost.Text          = string.Empty;
                lblAvailLabel.Visible = false;
                lblTestLabel.Visible  = false;
                lblAvail.Text         = string.Empty;
                lblTest.Text          = string.Empty;
            }
            _blnSkipUpdate = false;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Builds the list of Armors to render in the active tab.
        /// </summary>
        /// <param name="objXmlArmorList">XmlNodeList of Armors to render.</param>
        private async ValueTask BuildArmorList(XmlNodeList objXmlArmorList)
        {
            decimal decBaseMarkup         = 1 + (await nudMarkup.DoThreadSafeFuncAsync(x => x.Value) / 100.0m);
            bool    blnHideOverAvailLimit = await chkHideOverAvailLimit.DoThreadSafeFuncAsync(x => x.Checked);

            bool blnFreeItem = await chkFreeItem.DoThreadSafeFuncAsync(x => x.Checked);

            bool blnShowOnlyAffordItems = await chkShowOnlyAffordItems.DoThreadSafeFuncAsync(x => x.Checked);

            switch (await tabControl.DoThreadSafeFuncAsync(x => x.SelectedIndex))
            {
            case 1:
                DataTable tabArmor = new DataTable("armor");
                tabArmor.Columns.Add("ArmorGuid");
                tabArmor.Columns.Add("ArmorName");
                tabArmor.Columns.Add("Armor");
                tabArmor.Columns["Armor"].DataType = typeof(int);
                tabArmor.Columns.Add("Capacity");
                tabArmor.Columns["Capacity"].DataType = typeof(decimal);
                tabArmor.Columns.Add("Avail");
                tabArmor.Columns["Avail"].DataType = typeof(AvailabilityValue);
                tabArmor.Columns.Add("Special");
                tabArmor.Columns.Add("Source");
                tabArmor.Columns["Source"].DataType = typeof(SourceString);
                tabArmor.Columns.Add("Cost");
                tabArmor.Columns["Cost"].DataType = typeof(NuyenString);

                // Populate the Armor list.
                foreach (XmlNode objXmlArmor in objXmlArmorList)
                {
                    decimal decCostMultiplier = decBaseMarkup;
                    if (_setBlackMarketMaps.Contains(objXmlArmor["category"]?.InnerText))
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    if (!blnHideOverAvailLimit ||
                        SelectionShared.CheckAvailRestriction(objXmlArmor, _objCharacter) && (blnFreeItem ||
                                                                                              !blnShowOnlyAffordItems ||
                                                                                              SelectionShared.CheckNuyenRestriction(
                                                                                                  objXmlArmor, _objCharacter.Nuyen, decCostMultiplier)))
                    {
                        using (Armor objArmor = new Armor(_objCharacter))
                        {
                            List <Weapon> lstWeapons = new List <Weapon>(1);
                            objArmor.Create(objXmlArmor, 0, lstWeapons, true, true, true);

                            string  strArmorGuid = objArmor.SourceIDString;
                            string  strArmorName = objArmor.CurrentDisplayName;
                            int     intArmor     = objArmor.TotalArmor;
                            decimal decCapacity
                                = Convert.ToDecimal(objArmor.CalculatedCapacity(GlobalSettings.InvariantCultureInfo), GlobalSettings.InvariantCultureInfo);
                            AvailabilityValue objAvail = objArmor.TotalAvailTuple();
                            using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                                           out StringBuilder sbdAccessories))
                            {
                                foreach (ArmorMod objMod in objArmor.ArmorMods)
                                {
                                    sbdAccessories.AppendLine(objMod.CurrentDisplayName);
                                }

                                foreach (Gear objGear in objArmor.GearChildren)
                                {
                                    sbdAccessories.AppendLine(objGear.CurrentDisplayName);
                                }

                                if (sbdAccessories.Length > 0)
                                {
                                    sbdAccessories.Length -= Environment.NewLine.Length;
                                }
                                SourceString strSource = await SourceString.GetSourceStringAsync(
                                    objArmor.Source, await objArmor.DisplayPageAsync(GlobalSettings.Language),
                                    GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter);

                                NuyenString strCost = new NuyenString(objArmor.DisplayCost(out decimal _, false));

                                tabArmor.Rows.Add(strArmorGuid, strArmorName, intArmor, decCapacity, objAvail,
                                                  sbdAccessories.ToString(), strSource, strCost);
                            }
                        }
                    }
                }

                DataSet set = new DataSet("armor");
                set.Tables.Add(tabArmor);

                dgvArmor.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                dgvArmor.DataSource       = set;
                dgvArmor.DataMember       = "armor";
                break;

            default:
                using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool,
                                                                  out List <ListItem> lstArmors))
                {
                    int    intOverLimit = 0;
                    string strSpace     = await LanguageManager.GetStringAsync("String_Space");

                    foreach (XmlNode objXmlArmor in objXmlArmorList)
                    {
                        decimal decCostMultiplier = decBaseMarkup;
                        if (_setBlackMarketMaps.Contains(objXmlArmor["category"]?.InnerText))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        if ((!blnHideOverAvailLimit ||
                             SelectionShared.CheckAvailRestriction(objXmlArmor, _objCharacter)) &&
                            (blnFreeItem ||
                             !blnShowOnlyAffordItems ||
                             (SelectionShared.CheckNuyenRestriction(
                                  objXmlArmor, _objCharacter.Nuyen, decCostMultiplier))))
                        {
                            string strDisplayName = objXmlArmor["translate"]?.InnerText
                                                    ?? objXmlArmor["name"]?.InnerText;
                            if (!GlobalSettings.SearchInCategoryOnly && txtSearch.TextLength != 0)
                            {
                                string strCategory = objXmlArmor["category"]?.InnerText;
                                if (!string.IsNullOrEmpty(strCategory))
                                {
                                    ListItem objFoundItem
                                        = _lstCategory.Find(objFind => objFind.Value.ToString() == strCategory);
                                    if (!string.IsNullOrEmpty(objFoundItem.Name))
                                    {
                                        strDisplayName += strSpace + '[' + objFoundItem.Name + ']';
                                    }
                                }
                            }

                            lstArmors.Add(new ListItem(objXmlArmor["id"]?.InnerText, strDisplayName));
                        }
                        else
                        {
                            ++intOverLimit;
                        }
                    }

                    lstArmors.Sort(CompareListItems.CompareNames);
                    if (intOverLimit > 0)
                    {
                        // Add after sort so that it's always at the end
                        lstArmors.Add(new ListItem(string.Empty,
                                                   string.Format(GlobalSettings.CultureInfo,
                                                                 await LanguageManager.GetStringAsync(
                                                                     "String_RestrictedItemsHidden"),
                                                                 intOverLimit)));
                    }

                    _blnLoading = true;
                    string strOldSelected = await lstArmor.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

                    await lstArmor.PopulateWithListItemsAsync(lstArmors);

                    _blnLoading = false;
                    if (!string.IsNullOrEmpty(strOldSelected))
                    {
                        await lstArmor.DoThreadSafeAsync(x => x.SelectedValue = strOldSelected);
                    }
                    else
                    {
                        await lstArmor.DoThreadSafeAsync(x => x.SelectedIndex = -1);
                    }
                    break;
                }
            }
        }
Ejemplo n.º 8
0
        private void BuildWeaponList(XmlNodeList objNodeList)
        {
            if (tabControl.SelectedIndex == 1)
            {
                DataTable tabWeapons = new DataTable("weapons");
                tabWeapons.Columns.Add("WeaponGuid");
                tabWeapons.Columns.Add("WeaponName");
                tabWeapons.Columns.Add("Dice");
                tabWeapons.Columns.Add("Accuracy");
                tabWeapons.Columns.Add("Damage");
                tabWeapons.Columns.Add("AP");
                tabWeapons.Columns.Add("RC");
                tabWeapons.Columns.Add("Ammo");
                tabWeapons.Columns.Add("Mode");
                tabWeapons.Columns.Add("Reach");
                tabWeapons.Columns.Add("Accessories");
                tabWeapons.Columns.Add("Avail");
                tabWeapons.Columns["Avail"].DataType = typeof(AvailabilityValue);
                tabWeapons.Columns.Add("Source");
                tabWeapons.Columns["Source"].DataType = typeof(SourceString);
                tabWeapons.Columns.Add("Cost");
                tabWeapons.Columns["Cost"].DataType = typeof(NuyenString);

                XmlNode xmlParentWeaponDataNode = _objXmlDocument.SelectSingleNode($"/chummer/weapons/weapon[id = \"{ParentWeapon?.SourceIDString}\"]");
                foreach (XmlNode objXmlWeapon in objNodeList)
                {
                    if (!objXmlWeapon.RequirementsMet(_objCharacter, ParentWeapon, string.Empty, string.Empty))
                    {
                        continue;
                    }

                    XmlNode xmlTestNode = objXmlWeapon.SelectSingleNode("forbidden/weapondetails");
                    if (xmlTestNode != null)
                    {
                        // Assumes topmost parent is an AND node
                        if (xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                        {
                            continue;
                        }
                    }
                    xmlTestNode = objXmlWeapon.SelectSingleNode("required/weapondetails");
                    if (xmlTestNode != null)
                    {
                        // Assumes topmost parent is an AND node
                        if (!xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                        {
                            continue;
                        }
                    }
                    if (objXmlWeapon["cyberware"]?.InnerText == bool.TrueString)
                    {
                        continue;
                    }
                    string strTest = objXmlWeapon["mount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strTest) && !Mounts.Contains(strTest))
                    {
                        continue;
                    }
                    strTest = objXmlWeapon["extramount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strTest) && !Mounts.Contains(strTest))
                    {
                        continue;
                    }
                    if (chkHideOverAvailLimit.Checked && !SelectionShared.CheckAvailRestriction(objXmlWeapon, _objCharacter))
                    {
                        continue;
                    }
                    if (!chkFreeItem.Checked && chkShowOnlyAffordItems.Checked)
                    {
                        decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                        if (_setBlackMarketMaps.Contains(objXmlWeapon["category"]?.InnerText))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        if (!SelectionShared.CheckNuyenRestriction(objXmlWeapon, _objCharacter.Nuyen, decCostMultiplier))
                        {
                            continue;
                        }
                    }

                    Weapon objWeapon = new Weapon(_objCharacter);
                    objWeapon.Create(objXmlWeapon, null, true, false, true);
                    objWeapon.Parent = ParentWeapon;

                    string strID         = objWeapon.SourceIDString;
                    string strWeaponName = objWeapon.DisplayName(GlobalOptions.Language);
                    string strDice       = objWeapon.GetDicePool(GlobalOptions.CultureInfo, GlobalOptions.Language);
                    string strAccuracy   = objWeapon.DisplayAccuracy(GlobalOptions.CultureInfo, GlobalOptions.Language);
                    string strDamage     = objWeapon.CalculatedDamage(GlobalOptions.CultureInfo, GlobalOptions.Language);
                    string strAP         = objWeapon.TotalAP(GlobalOptions.Language);
                    if (strAP == "-")
                    {
                        strAP = "0";
                    }
                    string        strRC             = objWeapon.TotalRC(GlobalOptions.CultureInfo, GlobalOptions.Language, true);
                    string        strAmmo           = objWeapon.CalculatedAmmo(GlobalOptions.CultureInfo, GlobalOptions.Language);
                    string        strMode           = objWeapon.CalculatedMode(GlobalOptions.Language);
                    string        strReach          = objWeapon.TotalReach.ToString();
                    StringBuilder strbldAccessories = new StringBuilder();
                    foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                    {
                        strbldAccessories.AppendLine(objAccessory.DisplayName(GlobalOptions.Language));
                    }
                    if (strbldAccessories.Length > 0)
                    {
                        strbldAccessories.Length -= Environment.NewLine.Length;
                    }
                    AvailabilityValue objAvail  = objWeapon.TotalAvailTuple();
                    SourceString      strSource = new SourceString(objWeapon.Source, objWeapon.DisplayPage(GlobalOptions.Language), GlobalOptions.Language);
                    NuyenString       strCost   = new NuyenString(objWeapon.DisplayCost(out decimal _));

                    tabWeapons.Rows.Add(strID, strWeaponName, strDice, strAccuracy, strDamage, strAP, strRC, strAmmo, strMode, strReach, strbldAccessories.ToString(), objAvail, strSource, strCost);
                }

                DataSet set = new DataSet("weapons");
                set.Tables.Add(tabWeapons);
                string strSelectedCategory = cboCategory.SelectedValue?.ToString();
                if (string.IsNullOrEmpty(strSelectedCategory) || strSelectedCategory == "Show All")
                {
                    //dgvWeapons.Columns[5].Visible = true;
                    dgvWeapons.Columns[6].Visible = true;
                    dgvWeapons.Columns[7].Visible = true;
                    dgvWeapons.Columns[8].Visible = true;
                }
                else if (strSelectedCategory == "Blades" ||
                         strSelectedCategory == "Clubs" ||
                         strSelectedCategory == "Improvised Weapons" ||
                         strSelectedCategory == "Exotic Melee Weapons" ||
                         strSelectedCategory == "Unarmed")
                {
                    //dgvWeapons.Columns[5].Visible = false;
                    dgvWeapons.Columns[6].Visible = false;
                    dgvWeapons.Columns[7].Visible = false;
                    dgvWeapons.Columns[8].Visible = false;
                }
                else
                {
                    //dgvWeapons.Columns[5].Visible = true;
                    dgvWeapons.Columns[6].Visible = true;
                    dgvWeapons.Columns[7].Visible = true;
                    dgvWeapons.Columns[8].Visible = true;
                }
                dgvWeapons.Columns[0].Visible = false;
                dgvWeapons.Columns[12].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
                dgvWeapons.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                dgvWeapons.DataSource       = set;
                dgvWeapons.DataMember       = "weapons";
            }
            else
            {
                List <ListItem> lstWeapons = new List <ListItem>();

                XmlNode xmlParentWeaponDataNode = _objXmlDocument.SelectSingleNode($"/chummer/weapons/weapon[id = \"{ParentWeapon?.SourceIDString}\"]");
                foreach (XmlNode objXmlWeapon in objNodeList)
                {
                    if (!objXmlWeapon.RequirementsMet(_objCharacter, ParentWeapon, string.Empty, string.Empty))
                    {
                        continue;
                    }

                    XmlNode xmlTestNode = objXmlWeapon.SelectSingleNode("forbidden/weapondetails");
                    if (xmlTestNode != null)
                    {
                        // Assumes topmost parent is an AND node
                        if (xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                        {
                            continue;
                        }
                    }
                    xmlTestNode = objXmlWeapon.SelectSingleNode("required/weapondetails");
                    if (xmlTestNode != null)
                    {
                        // Assumes topmost parent is an AND node
                        if (!xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                        {
                            continue;
                        }
                    }
                    if (objXmlWeapon["cyberware"]?.InnerText == bool.TrueString)
                    {
                        continue;
                    }

                    string strMount = objXmlWeapon["mount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strMount) && !Mounts.Contains(strMount))
                    {
                        continue;
                    }

                    string strExtraMount = objXmlWeapon["extramount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strExtraMount) && !Mounts.Contains(strExtraMount))
                    {
                        continue;
                    }

                    if (chkHideOverAvailLimit.Checked && !SelectionShared.CheckAvailRestriction(objXmlWeapon, _objCharacter))
                    {
                        continue;
                    }
                    if (!chkFreeItem.Checked && chkShowOnlyAffordItems.Checked)
                    {
                        decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                        if (_setBlackMarketMaps.Contains(objXmlWeapon["category"]?.InnerText))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        if (!string.IsNullOrEmpty(ParentWeapon?.DoubledCostModificationSlots) &&
                            (!string.IsNullOrEmpty(strMount) || !string.IsNullOrEmpty(strExtraMount)))
                        {
                            string[] astrParentDoubledCostModificationSlots = ParentWeapon.DoubledCostModificationSlots.Split('/');
                            if (astrParentDoubledCostModificationSlots.Contains(strMount) || astrParentDoubledCostModificationSlots.Contains(strExtraMount))
                            {
                                decCostMultiplier *= 2;
                            }
                        }
                        if (!SelectionShared.CheckNuyenRestriction(objXmlWeapon, _objCharacter.Nuyen, decCostMultiplier))
                        {
                            continue;
                        }
                    }
                    lstWeapons.Add(new ListItem(objXmlWeapon["id"]?.InnerText, objXmlWeapon["translate"]?.InnerText ?? objXmlWeapon["name"]?.InnerText));
                }

                lstWeapons.Sort(CompareListItems.CompareNames);
                string strOldSelected = lstWeapon.SelectedValue?.ToString();
                _blnLoading = true;
                lstWeapon.BeginUpdate();
                lstWeapon.ValueMember   = "Value";
                lstWeapon.DisplayMember = "Name";
                lstWeapon.DataSource    = lstWeapons;
                _blnLoading             = false;
                if (!string.IsNullOrEmpty(strOldSelected))
                {
                    lstWeapon.SelectedValue = strOldSelected;
                }
                else
                {
                    lstWeapon.SelectedIndex = -1;
                }
                lstWeapon.EndUpdate();
            }
        }
Ejemplo n.º 9
0
        private void UpdateWeaponInfo()
        {
            if (_blnSkipUpdate)
            {
                return;
            }
            _blnSkipUpdate = true;
            if (_objSelectedWeapon != null)
            {
                chkBlackMarketDiscount.Enabled = true;
                chkBlackMarketDiscount.Checked = _setBlackMarketMaps.Contains(_objSelectedWeapon.Category);

                _objSelectedWeapon.DiscountCost = chkBlackMarketDiscount.Checked;

                lblWeaponReach.Text    = _objSelectedWeapon.TotalReach.ToString();
                lblWeaponDamage.Text   = _objSelectedWeapon.CalculatedDamage(GlobalOptions.CultureInfo, GlobalOptions.Language);
                lblWeaponAP.Text       = _objSelectedWeapon.TotalAP(GlobalOptions.Language);
                lblWeaponMode.Text     = _objSelectedWeapon.CalculatedMode(GlobalOptions.Language);
                lblWeaponRC.Text       = _objSelectedWeapon.TotalRC;
                lblWeaponAmmo.Text     = _objSelectedWeapon.CalculatedAmmo(GlobalOptions.CultureInfo, GlobalOptions.Language);
                lblWeaponAccuracy.Text = _objSelectedWeapon.TotalAccuracy.ToString();

                decimal decItemCost = 0;
                if (chkFreeItem.Checked)
                {
                    lblWeaponCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                }
                else
                {
                    lblWeaponCost.Text = _objSelectedWeapon.DisplayCost(out decItemCost, nudMarkup.Value / 100.0m);
                }

                AvailabilityValue objTotalAvail = _objSelectedWeapon.TotalAvailTuple();
                lblWeaponAvail.Text = objTotalAvail.ToString(GlobalOptions.CultureInfo, GlobalOptions.Language);
                lblTest.Text        = _objCharacter.AvailTest(decItemCost, objTotalAvail);

                string strPage = _objSelectedWeapon.DisplayPage(GlobalOptions.Language);
                lblSource.Text = CommonFunctions.LanguageBookShort(_objSelectedWeapon.Source, GlobalOptions.Language) + ' ' + strPage;

                // Build a list of included Accessories and Modifications that come with the weapon.
                StringBuilder strAccessories = new StringBuilder();
                foreach (WeaponAccessory objAccessory in _objSelectedWeapon.WeaponAccessories)
                {
                    strAccessories.Append(objAccessory.DisplayName(GlobalOptions.Language));
                    strAccessories.Append('\n');
                }
                if (strAccessories.Length > 0)
                {
                    strAccessories.Length -= 1;
                }

                lblIncludedAccessories.Text = strAccessories.Length == 0 ? LanguageManager.GetString("String_None", GlobalOptions.Language) : strAccessories.ToString();

                tipTooltip.SetToolTip(lblSource, CommonFunctions.LanguageBookLong(_objSelectedWeapon.Source, GlobalOptions.Language) + ' ' + LanguageManager.GetString("String_Page", GlobalOptions.Language) + ' ' + strPage);
            }
            else
            {
                chkBlackMarketDiscount.Enabled = false;
                chkBlackMarketDiscount.Checked = false;
                lblWeaponReach.Text            = string.Empty;
                lblWeaponDamage.Text           = string.Empty;
                lblWeaponAP.Text            = string.Empty;
                lblWeaponMode.Text          = string.Empty;
                lblWeaponRC.Text            = string.Empty;
                lblWeaponAmmo.Text          = string.Empty;
                lblWeaponAccuracy.Text      = string.Empty;
                lblWeaponCost.Text          = string.Empty;
                lblWeaponAvail.Text         = string.Empty;
                lblTest.Text                = string.Empty;
                lblSource.Text              = string.Empty;
                lblIncludedAccessories.Text = string.Empty;
                tipTooltip.SetToolTip(lblSource, string.Empty);
            }
            _blnSkipUpdate = false;
        }
Ejemplo n.º 10
0
        private void BuildWeaponList(XmlNodeList objNodeList)
        {
            if (tabControl.SelectedIndex == 1)
            {
                DataTable tabWeapons = new DataTable("weapons");
                tabWeapons.Columns.Add("WeaponGuid");
                tabWeapons.Columns.Add("WeaponName");
                tabWeapons.Columns.Add("Dice");
                tabWeapons.Columns.Add("Accuracy");
                tabWeapons.Columns["Accuracy"].DataType = typeof(int);
                tabWeapons.Columns.Add("Damage");
                tabWeapons.Columns.Add("AP");
                tabWeapons.Columns.Add("RC");
                tabWeapons.Columns["RC"].DataType = typeof(int);
                tabWeapons.Columns.Add("Ammo");
                tabWeapons.Columns.Add("Mode");
                tabWeapons.Columns.Add("Reach");
                tabWeapons.Columns.Add("Accessories");
                tabWeapons.Columns.Add("Avail");
                tabWeapons.Columns["Avail"].DataType = typeof(AvailabilityValue);
                tabWeapons.Columns.Add("Source");
                tabWeapons.Columns["Source"].DataType = typeof(SourceString);
                tabWeapons.Columns.Add("Cost");
                tabWeapons.Columns["Cost"].DataType = typeof(NuyenString);

                foreach (XmlNode objXmlWeapon in objNodeList)
                {
                    if (objXmlWeapon["cyberware"]?.InnerText == bool.TrueString)
                    {
                        continue;
                    }
                    string strTest = objXmlWeapon["mount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strTest) && !Mounts.Contains(strTest))
                    {
                        continue;
                    }
                    strTest = objXmlWeapon["extramount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strTest) && !Mounts.Contains(strTest))
                    {
                        continue;
                    }
                    if (chkHideOverAvailLimit.Checked && !SelectionShared.CheckAvailRestriction(objXmlWeapon, _objCharacter))
                    {
                        continue;
                    }

                    Weapon objWeapon = new Weapon(_objCharacter);
                    objWeapon.Create(objXmlWeapon, null, true, false, true);

                    string strID         = objWeapon.SourceID.ToString("D");
                    string strWeaponName = objWeapon.DisplayName(GlobalOptions.Language);
                    string strDice       = objWeapon.GetDicePool(GlobalOptions.CultureInfo);
                    int    intAccuracy   = objWeapon.TotalAccuracy;
                    string strDamage     = objWeapon.CalculatedDamage(GlobalOptions.CultureInfo, GlobalOptions.Language);
                    string strAP         = objWeapon.TotalAP(GlobalOptions.Language);
                    if (strAP == "-")
                    {
                        strAP = "0";
                    }
                    int.TryParse(objWeapon.TotalRC, out int intRC);
                    string        strAmmo        = objWeapon.CalculatedAmmo(GlobalOptions.CultureInfo, GlobalOptions.Language);
                    string        strMode        = objWeapon.CalculatedMode(GlobalOptions.Language);
                    string        strReach       = objWeapon.TotalReach.ToString();
                    StringBuilder strAccessories = new StringBuilder();
                    foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                    {
                        strAccessories.Append(objAccessory.DisplayName(GlobalOptions.Language));
                        strAccessories.Append('\n');
                    }
                    if (strAccessories.Length > 0)
                    {
                        strAccessories.Length -= 1;
                    }
                    AvailabilityValue objAvail  = objWeapon.TotalAvailTuple();
                    SourceString      strSource = new SourceString(objWeapon.Source, objWeapon.DisplayPage(GlobalOptions.Language));
                    NuyenString       strCost   = new NuyenString(objWeapon.DisplayCost(out decimal decDummy));

                    tabWeapons.Rows.Add(strID, strWeaponName, strDice, intAccuracy, strDamage, strAP, intRC, strAmmo, strMode, strReach, strAccessories.ToString(), objAvail, strSource, strCost);
                }

                DataSet set = new DataSet("weapons");
                set.Tables.Add(tabWeapons);

                if (cboCategory.SelectedValue == null || cboCategory.SelectedValue.ToString() == "Show All")
                {
                    dgvWeapons.Columns[5].Visible = true;
                    dgvWeapons.Columns[6].Visible = true;
                    dgvWeapons.Columns[7].Visible = true;
                    dgvWeapons.Columns[8].Visible = true;
                }
                else if (cboCategory.SelectedValue.ToString() == "Blades" || cboCategory.SelectedValue.ToString() == "Clubs" || cboCategory.SelectedValue.ToString() == "Improvised Weapons" || cboCategory.SelectedValue.ToString() == "Exotic Melee Weapons" || cboCategory.SelectedValue.ToString() == "Unarmed")
                {
                    dgvWeapons.Columns[5].Visible = false;
                    dgvWeapons.Columns[6].Visible = false;
                    dgvWeapons.Columns[7].Visible = false;
                    dgvWeapons.Columns[8].Visible = true;
                }
                else
                {
                    dgvWeapons.Columns[5].Visible = true;
                    dgvWeapons.Columns[6].Visible = true;
                    dgvWeapons.Columns[7].Visible = true;
                    dgvWeapons.Columns[8].Visible = false;
                }
                dgvWeapons.Columns[0].Visible = false;
                dgvWeapons.Columns[12].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
                dgvWeapons.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                dgvWeapons.DataSource       = set;
                dgvWeapons.DataMember       = "weapons";
            }
            else
            {
                List <ListItem> lstWeapons = new List <ListItem>();
                foreach (XmlNode objXmlWeapon in objNodeList)
                {
                    if (objXmlWeapon["cyberware"]?.InnerText == bool.TrueString)
                    {
                        continue;
                    }

                    string strTest = objXmlWeapon["mount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strTest) && !Mounts.Contains(strTest))
                    {
                        continue;
                    }

                    strTest = objXmlWeapon["extramount"]?.InnerText;
                    if (!string.IsNullOrEmpty(strTest) && !Mounts.Contains(strTest))
                    {
                        continue;
                    }

                    if (chkHideOverAvailLimit.Checked && !SelectionShared.CheckAvailRestriction(objXmlWeapon, _objCharacter))
                    {
                        continue;
                    }
                    lstWeapons.Add(new ListItem(objXmlWeapon["id"]?.InnerText, objXmlWeapon["translate"]?.InnerText ?? objXmlWeapon["name"]?.InnerText));
                }
                lstWeapons.Sort(CompareListItems.CompareNames);
                lstWeapon.BeginUpdate();
                lstWeapon.DataSource    = null;
                lstWeapon.ValueMember   = "Value";
                lstWeapon.DisplayMember = "Name";
                lstWeapon.DataSource    = lstWeapons;
                lstWeapon.EndUpdate();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Refresh the information for the selected Vehicle.
        /// </summary>
        private void UpdateSelectedVehicle()
        {
            if (_blnLoading)
            {
                return;
            }

            string         strSelectedId = lstVehicle.SelectedValue?.ToString();
            XPathNavigator objXmlVehicle = null;

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                // Retireve the information for the selected Vehicle.
                objXmlVehicle = _xmlBaseVehicleDataNode.SelectSingleNode("vehicles/vehicle[id = \"" + strSelectedId + "\"]");
            }
            if (objXmlVehicle == null)
            {
                lblVehicleHandlingLabel.Visible = false;
                lblVehicleAccelLabel.Visible    = false;
                lblVehicleSpeedLabel.Visible    = false;
                lblVehiclePilotLabel.Visible    = false;
                lblVehicleBodyLabel.Visible     = false;
                lblVehicleArmorLabel.Visible    = false;
                lblVehicleSeatsLabel.Visible    = false;
                lblVehicleSensorLabel.Visible   = false;
                lblVehicleAvailLabel.Visible    = false;
                lblSourceLabel.Visible          = false;
                lblVehicleCostLabel.Visible     = false;
                lblTestLabel.Visible            = false;
                lblVehicleHandling.Text         = string.Empty;
                lblVehicleAccel.Text            = string.Empty;
                lblVehicleSpeed.Text            = string.Empty;
                lblVehiclePilot.Text            = string.Empty;
                lblVehicleBody.Text             = string.Empty;
                lblVehicleArmor.Text            = string.Empty;
                lblVehicleSeats.Text            = string.Empty;
                lblVehicleSensor.Text           = string.Empty;
                lblVehicleAvail.Text            = string.Empty;
                lblSource.Text      = string.Empty;
                lblVehicleCost.Text = string.Empty;
                lblTest.Text        = string.Empty;
                lblSource.SetToolTip(string.Empty);
                return;
            }

            decimal decCostModifier = 1.0m;

            if (chkUsedVehicle.Checked)
            {
                decCostModifier -= (nudUsedVehicleDiscount.Value / 100.0m);
            }

            lblVehicleHandling.Text         = objXmlVehicle.SelectSingleNode("handling")?.Value;
            lblVehicleAccel.Text            = objXmlVehicle.SelectSingleNode("accel")?.Value;
            lblVehicleSpeed.Text            = objXmlVehicle.SelectSingleNode("speed")?.Value;
            lblVehiclePilot.Text            = objXmlVehicle.SelectSingleNode("pilot")?.Value;
            lblVehicleBody.Text             = objXmlVehicle.SelectSingleNode("body")?.Value;
            lblVehicleArmor.Text            = objXmlVehicle.SelectSingleNode("armor")?.Value;
            lblVehicleSeats.Text            = objXmlVehicle.SelectSingleNode("seats")?.Value;
            lblVehicleSensor.Text           = objXmlVehicle.SelectSingleNode("sensor")?.Value;
            lblVehicleHandlingLabel.Visible = !string.IsNullOrEmpty(lblVehicleHandling.Text);
            lblVehicleAccelLabel.Visible    = !string.IsNullOrEmpty(lblVehicleAccel.Text);
            lblVehicleSpeedLabel.Visible    = !string.IsNullOrEmpty(lblVehicleSpeed.Text);
            lblVehiclePilotLabel.Visible    = !string.IsNullOrEmpty(lblVehiclePilot.Text);
            lblVehicleBodyLabel.Visible     = !string.IsNullOrEmpty(lblVehicleBody.Text);
            lblVehicleArmorLabel.Visible    = !string.IsNullOrEmpty(lblVehicleArmor.Text);
            lblVehicleSeatsLabel.Visible    = !string.IsNullOrEmpty(lblVehicleSeats.Text);
            lblVehicleSensorLabel.Visible   = !string.IsNullOrEmpty(lblVehicleSensor.Text);
            AvailabilityValue objTotalAvail = new AvailabilityValue(0, objXmlVehicle.SelectSingleNode("avail")?.Value, chkUsedVehicle.Checked ? -4 : 0);

            lblVehicleAvail.Text         = objTotalAvail.ToString();
            lblVehicleAvailLabel.Visible = !string.IsNullOrEmpty(lblVehicleAvail.Text);

            chkBlackMarketDiscount.Enabled = _objCharacter.BlackMarketDiscount;

            if (!chkBlackMarketDiscount.Checked)
            {
                chkBlackMarketDiscount.Checked = GlobalOptions.AssumeBlackMarket &&
                                                 _setBlackMarketMaps.Contains(objXmlVehicle.SelectSingleNode("category")
                                                                              ?.Value);
            }
            else if (!_setBlackMarketMaps.Contains(objXmlVehicle.SelectSingleNode("category")?.Value))
            {
                //Prevent chkBlackMarketDiscount from being checked if the gear category doesn't match.
                chkBlackMarketDiscount.Checked = false;
            }

            // Apply the cost multiplier to the Vehicle (will be 1 unless Used Vehicle is selected)
            string strCost = objXmlVehicle.SelectSingleNode("cost")?.Value ?? string.Empty;

            if (strCost.StartsWith("Variable", StringComparison.Ordinal))
            {
                lblVehicleCost.Text         = strCost.TrimStartOnce("Variable(", true).TrimEndOnce(')');
                lblVehicleCostLabel.Visible = !string.IsNullOrEmpty(lblVehicleCost.Text);
                lblTest.Text         = string.Empty;
                lblTestLabel.Visible = false;
            }
            else
            {
                decimal decCost = 0.0m;
                if (!chkFreeItem.Checked)
                {
                    if (decimal.TryParse(strCost, NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decimal decTmp))
                    {
                        decCost = decTmp;
                    }

                    // Apply the markup if applicable.
                    decCost *= decCostModifier;
                    decCost *= 1 + (nudMarkup.Value / 100.0m);

                    if (chkBlackMarketDiscount.Checked)
                    {
                        decCost *= 0.9m;
                    }
                    if (_setDealerConnectionMaps != null)
                    {
                        if (_setDealerConnectionMaps.Any(set => objXmlVehicle.SelectSingleNode("category")?.Value.StartsWith(set, StringComparison.Ordinal) == true))
                        {
                            decCost *= 0.9m;
                        }
                    }
                }

                lblVehicleCost.Text         = decCost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                lblVehicleCostLabel.Visible = !string.IsNullOrEmpty(lblVehicleCost.Text);
                lblTest.Text         = _objCharacter.AvailTest(decCost, lblVehicleAvail.Text);
                lblTestLabel.Visible = !string.IsNullOrEmpty(lblTest.Text);
            }


            string strSource = objXmlVehicle.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown");
            string strPage   = objXmlVehicle.SelectSingleNode("altpage")?.Value ?? objXmlVehicle.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown");
            string strSpace  = LanguageManager.GetString("String_Space");

            lblSource.Text = CommonFunctions.LanguageBookShort(strSource) + strSpace + strPage;
            lblSource.SetToolTip(CommonFunctions.LanguageBookLong(strSource) + strSpace + LanguageManager.GetString("String_Page") + strSpace + strPage);
            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
        }
Ejemplo n.º 12
0
        private void BuildVehicleList(XPathNodeIterator objXmlVehicleList)
        {
            SuspendLayout();
            int intOverLimit = 0;

            if (tabViews.SelectedIndex == 1)
            {
                XmlDocument dummy = new XmlDocument {
                    XmlResolver = null
                };
                DataTable tabVehicles = new DataTable("vehicles");
                tabVehicles.Columns.Add("VehicleGuid");
                tabVehicles.Columns.Add("VehicleName");
                tabVehicles.Columns.Add("Accel");
                tabVehicles.Columns.Add("Armor");
                tabVehicles.Columns.Add("Body");
                tabVehicles.Columns.Add("Handling");
                tabVehicles.Columns.Add("Pilot");
                tabVehicles.Columns.Add("Sensor");
                tabVehicles.Columns.Add("Speed");
                tabVehicles.Columns.Add("Seats");
                tabVehicles.Columns.Add("Gear");
                tabVehicles.Columns.Add("Mods");
                tabVehicles.Columns.Add("Weapons");
                tabVehicles.Columns.Add("WeaponMounts");
                tabVehicles.Columns.Add("Avail", typeof(AvailabilityValue));
                tabVehicles.Columns.Add("Source", typeof(SourceString));
                tabVehicles.Columns.Add("Cost", typeof(NuyenString));
                foreach (XPathNavigator objXmlVehicle in objXmlVehicleList)
                {
                    if (chkHideOverAvailLimit.Checked && !objXmlVehicle.CheckAvailRestriction(_objCharacter))
                    {
                        ++intOverLimit;
                        continue;
                    }

                    if (!chkFreeItem.Checked && chkShowOnlyAffordItems.Checked)
                    {
                        decimal decCostMultiplier = 1.0m;
                        if (chkUsedVehicle.Checked)
                        {
                            decCostMultiplier -= (nudUsedVehicleDiscount.Value / 100.0m);
                        }
                        decCostMultiplier *= 1 + (nudMarkup.Value / 100.0m);
                        if (chkBlackMarketDiscount.Checked &&
                            _setBlackMarketMaps.Contains(objXmlVehicle
                                                         .SelectSingleNodeAndCacheExpression("category")
                                                         ?.Value))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        if (Vehicle.DoesDealerConnectionApply(_setDealerConnectionMaps,
                                                              objXmlVehicle
                                                              .SelectSingleNodeAndCacheExpression("category")
                                                              ?.Value))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        if (!objXmlVehicle.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier))
                        {
                            ++intOverLimit;
                            continue;
                        }
                    }

                    using (Vehicle objVehicle = new Vehicle(_objCharacter))
                    {
                        objVehicle.Create(objXmlVehicle.ToXmlNode(dummy), true, true, false, true);
                        string strID          = objVehicle.SourceIDString;
                        string strVehicleName = objVehicle.CurrentDisplayName;
                        string strAccel       = objVehicle.TotalAccel;
                        string strArmor       = objVehicle.TotalArmor.ToString(GlobalSettings.CultureInfo);
                        string strBody        = objVehicle.TotalBody.ToString(GlobalSettings.CultureInfo);
                        string strHandling    = objVehicle.TotalHandling;
                        string strPilot       = objVehicle.Pilot.ToString(GlobalSettings.CultureInfo);
                        string strSensor      = objVehicle.CalculatedSensor.ToString(GlobalSettings.CultureInfo);
                        string strSpeed       = objVehicle.TotalSpeed;
                        string strSeats       = objVehicle.TotalSeats.ToString(GlobalSettings.CultureInfo);
                        using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                                       out StringBuilder sbdGear))
                        {
                            foreach (Gear objGear in objVehicle.GearChildren)
                            {
                                sbdGear.AppendLine(objGear.CurrentDisplayName);
                            }

                            if (sbdGear.Length > 0)
                            {
                                sbdGear.Length -= Environment.NewLine.Length;
                            }

                            using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                                           out StringBuilder sbdMods))
                            {
                                foreach (VehicleMod objMod in objVehicle.Mods)
                                {
                                    sbdMods.AppendLine(objMod.CurrentDisplayName);
                                }

                                if (sbdMods.Length > 0)
                                {
                                    sbdMods.Length -= Environment.NewLine.Length;
                                }
                                using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                                               out StringBuilder sbdWeapons))
                                {
                                    if (sbdWeapons.Length > 0)
                                    {
                                        sbdWeapons.Length -= Environment.NewLine.Length;
                                    }
                                    foreach (Weapon objWeapon in objVehicle.Weapons)
                                    {
                                        sbdWeapons.AppendLine(objWeapon.CurrentDisplayName);
                                    }

                                    using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                                                   out StringBuilder sbdWeaponMounts))
                                    {
                                        foreach (WeaponMount objWeaponMount in objVehicle.WeaponMounts)
                                        {
                                            sbdWeaponMounts.AppendLine(objWeaponMount.CurrentDisplayName);
                                        }

                                        if (sbdWeaponMounts.Length > 0)
                                        {
                                            sbdWeaponMounts.Length -= Environment.NewLine.Length;
                                        }

                                        AvailabilityValue objAvail  = objVehicle.TotalAvailTuple();
                                        SourceString      strSource = new SourceString(objVehicle.Source,
                                                                                       objVehicle.DisplayPage(GlobalSettings.Language),
                                                                                       GlobalSettings.Language, GlobalSettings.CultureInfo,
                                                                                       _objCharacter);
                                        NuyenString strCost =
                                            new NuyenString(objVehicle.TotalCost.ToString(GlobalSettings.CultureInfo));

                                        tabVehicles.Rows.Add(strID, strVehicleName, strAccel, strArmor, strBody,
                                                             strHandling, strPilot, strSensor, strSpeed, strSeats,
                                                             sbdGear.ToString(), sbdMods.ToString(),
                                                             sbdWeapons.ToString(), sbdWeaponMounts.ToString(),
                                                             objAvail, strSource, strCost);
                                    }
                                }
                            }
                        }
                    }
                }
                dgvVehicles.Columns[0].Visible = false;
                dgvVehicles.Columns[13].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
                dgvVehicles.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;


                DataSet set = new DataSet("vehicles");
                set.Tables.Add(tabVehicles);
                dgvVehicles.DataSource = set;
                dgvVehicles.DataMember = "vehicles";
            }
            else
            {
                string strSpace = LanguageManager.GetString("String_Space");
                using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool, out List <ListItem> lstVehicles))
                {
                    foreach (XPathNavigator objXmlVehicle in objXmlVehicleList)
                    {
                        if (chkHideOverAvailLimit.Checked && !objXmlVehicle.CheckAvailRestriction(_objCharacter))
                        {
                            ++intOverLimit;
                            continue;
                        }

                        if (!chkFreeItem.Checked && chkShowOnlyAffordItems.Checked)
                        {
                            decimal decCostMultiplier = 1.0m;
                            if (chkUsedVehicle.Checked)
                            {
                                decCostMultiplier -= (nudUsedVehicleDiscount.Value / 100.0m);
                            }
                            decCostMultiplier *= 1 + (nudMarkup.Value / 100.0m);
                            if (chkBlackMarketDiscount.Checked &&
                                _setBlackMarketMaps.Contains(objXmlVehicle
                                                             .SelectSingleNodeAndCacheExpression("category")
                                                             ?.Value))
                            {
                                decCostMultiplier *= 0.9m;
                            }
                            if (Vehicle.DoesDealerConnectionApply(_setDealerConnectionMaps,
                                                                  objXmlVehicle
                                                                  .SelectSingleNodeAndCacheExpression("category")
                                                                  ?.Value))
                            {
                                decCostMultiplier *= 0.9m;
                            }
                            if (!objXmlVehicle.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier))
                            {
                                ++intOverLimit;
                                continue;
                            }
                        }

                        string strDisplayname = objXmlVehicle.SelectSingleNodeAndCacheExpression("translate")?.Value
                                                ?? objXmlVehicle.SelectSingleNodeAndCacheExpression("name")?.Value
                                                ?? LanguageManager.GetString("String_Unknown");

                        if (!GlobalSettings.SearchInCategoryOnly && txtSearch.TextLength != 0)
                        {
                            string strCategory = objXmlVehicle.SelectSingleNodeAndCacheExpression("category")?.Value;
                            if (!string.IsNullOrEmpty(strCategory))
                            {
                                ListItem objFoundItem
                                    = _lstCategory.Find(objFind => objFind.Value.ToString() == strCategory);
                                if (!string.IsNullOrEmpty(objFoundItem.Name))
                                {
                                    strDisplayname += strSpace + '[' + objFoundItem.Name + ']';
                                }
                            }
                        }

                        lstVehicles.Add(new ListItem(
                                            objXmlVehicle.SelectSingleNodeAndCacheExpression("id")?.Value ?? string.Empty,
                                            strDisplayname));
                    }

                    lstVehicles.Sort(CompareListItems.CompareNames);
                    if (intOverLimit > 0)
                    {
                        // Add after sort so that it's always at the end
                        lstVehicles.Add(new ListItem(string.Empty,
                                                     string.Format(GlobalSettings.CultureInfo,
                                                                   LanguageManager.GetString(
                                                                       "String_RestrictedItemsHidden"),
                                                                   intOverLimit)));
                    }

                    string strOldSelected = lstVehicle.SelectedValue?.ToString();
                    _blnLoading = true;
                    lstVehicle.BeginUpdate();
                    lstVehicle.PopulateWithListItems(lstVehicles);
                    _blnLoading = false;
                    if (string.IsNullOrEmpty(strOldSelected))
                    {
                        lstVehicle.SelectedIndex = -1;
                    }
                    else
                    {
                        lstVehicle.SelectedValue = strOldSelected;
                    }
                    lstVehicle.EndUpdate();
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Refresh the information for the selected Vehicle.
        /// </summary>
        private void UpdateSelectedVehicle()
        {
            if (_blnLoading)
            {
                return;
            }

            string         strSelectedId = lstVehicle.SelectedValue?.ToString();
            XPathNavigator objXmlVehicle = null;

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                // Retrieve the information for the selected Vehicle.
                objXmlVehicle = _xmlBaseVehicleDataNode.SelectSingleNode("vehicles/vehicle[id = " + strSelectedId.CleanXPath() + ']');
            }
            if (objXmlVehicle == null)
            {
                tlpRight.Visible = false;
                return;
            }

            SuspendLayout();
            lblVehicleHandling.Text         = objXmlVehicle.SelectSingleNode("handling")?.Value;
            lblVehicleAccel.Text            = objXmlVehicle.SelectSingleNode("accel")?.Value;
            lblVehicleSpeed.Text            = objXmlVehicle.SelectSingleNode("speed")?.Value;
            lblVehiclePilot.Text            = objXmlVehicle.SelectSingleNode("pilot")?.Value;
            lblVehicleBody.Text             = objXmlVehicle.SelectSingleNode("body")?.Value;
            lblVehicleArmor.Text            = objXmlVehicle.SelectSingleNode("armor")?.Value;
            lblVehicleSeats.Text            = objXmlVehicle.SelectSingleNode("seats")?.Value;
            lblVehicleSensor.Text           = objXmlVehicle.SelectSingleNode("sensor")?.Value;
            lblVehicleHandlingLabel.Visible = !string.IsNullOrEmpty(lblVehicleHandling.Text);
            lblVehicleAccelLabel.Visible    = !string.IsNullOrEmpty(lblVehicleAccel.Text);
            lblVehicleSpeedLabel.Visible    = !string.IsNullOrEmpty(lblVehicleSpeed.Text);
            lblVehiclePilotLabel.Visible    = !string.IsNullOrEmpty(lblVehiclePilot.Text);
            lblVehicleBodyLabel.Visible     = !string.IsNullOrEmpty(lblVehicleBody.Text);
            lblVehicleArmorLabel.Visible    = !string.IsNullOrEmpty(lblVehicleArmor.Text);
            lblVehicleSeatsLabel.Visible    = !string.IsNullOrEmpty(lblVehicleSeats.Text);
            lblVehicleSensorLabel.Visible   = !string.IsNullOrEmpty(lblVehicleSensor.Text);
            AvailabilityValue objTotalAvail = new AvailabilityValue(0, objXmlVehicle.SelectSingleNode("avail")?.Value, chkUsedVehicle.Checked ? -4 : 0);

            lblVehicleAvail.Text         = objTotalAvail.ToString();
            lblVehicleAvailLabel.Visible = !string.IsNullOrEmpty(lblVehicleAvail.Text);

            bool blnCanBlackMarketDiscount = _setBlackMarketMaps.Contains(objXmlVehicle.SelectSingleNode("category")?.Value);

            chkBlackMarketDiscount.Enabled = blnCanBlackMarketDiscount;
            if (!chkBlackMarketDiscount.Checked)
            {
                chkBlackMarketDiscount.Checked = GlobalSettings.AssumeBlackMarket && blnCanBlackMarketDiscount;
            }
            else if (!blnCanBlackMarketDiscount)
            {
                //Prevent chkBlackMarketDiscount from being checked if the category doesn't match.
                chkBlackMarketDiscount.Checked = false;
            }

            UpdateSelectedVehicleCost();

            string       strSource = objXmlVehicle.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown");
            string       strPage   = objXmlVehicle.SelectSingleNodeAndCacheExpression("altpage")?.Value ?? objXmlVehicle.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown");
            SourceString objSource = new SourceString(strSource, strPage, GlobalSettings.Language,
                                                      GlobalSettings.CultureInfo, _objCharacter);

            lblSource.Text = objSource.ToString();
            lblSource.SetToolTip(objSource.LanguageBookTooltip);
            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
            tlpRight.Visible       = true;
            ResumeLayout();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Builds the list of Armors to render in the active tab.
        /// </summary>
        /// <param name="objXmlArmorList">XmlNodeList of Armors to render.</param>
        private void BuildArmorList(XmlNodeList objXmlArmorList)
        {
            switch (tabControl.SelectedIndex)
            {
            case 1:
                DataTable tabArmor = new DataTable("armor");
                tabArmor.Columns.Add("ArmorGuid");
                tabArmor.Columns.Add("ArmorName");
                tabArmor.Columns.Add("Armor");
                tabArmor.Columns["Armor"].DataType = typeof(int);
                tabArmor.Columns.Add("Capacity");
                tabArmor.Columns["Capacity"].DataType = typeof(decimal);
                tabArmor.Columns.Add("Avail");
                tabArmor.Columns["Avail"].DataType = typeof(AvailabilityValue);
                tabArmor.Columns.Add("Special");
                tabArmor.Columns.Add("Source");
                tabArmor.Columns["Source"].DataType = typeof(SourceString);
                tabArmor.Columns.Add("Cost");
                tabArmor.Columns["Cost"].DataType = typeof(NuyenString);

                // Populate the Armor list.
                foreach (XmlNode objXmlArmor in objXmlArmorList)
                {
                    if (!chkHideOverAvailLimit.Checked || SelectionShared.CheckAvailRestriction(objXmlArmor, _objCharacter))
                    {
                        Armor         objArmor   = new Armor(_objCharacter);
                        List <Weapon> lstWeapons = new List <Weapon>();
                        objArmor.Create(objXmlArmor, 0, lstWeapons, true, true, true);

                        string            strArmorGuid   = objArmor.SourceID.ToString("D");
                        string            strArmorName   = objArmor.DisplayName(GlobalOptions.Language);
                        int               intArmor       = objArmor.TotalArmor;
                        decimal           decCapacity    = Convert.ToDecimal(objArmor.CalculatedCapacity, GlobalOptions.CultureInfo);
                        AvailabilityValue objAvail       = objArmor.TotalAvailTuple();
                        StringBuilder     strAccessories = new StringBuilder();
                        foreach (ArmorMod objMod in objArmor.ArmorMods)
                        {
                            strAccessories.AppendLine(objMod.DisplayName(GlobalOptions.Language));
                        }
                        foreach (Gear objGear in objArmor.Gear)
                        {
                            strAccessories.AppendLine(objGear.DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language));
                        }
                        if (strAccessories.Length > 0)
                        {
                            strAccessories.Length -= Environment.NewLine.Length;
                        }
                        SourceString strSource = new SourceString(objArmor.Source, objArmor.Page(GlobalOptions.Language));
                        NuyenString  strCost   = new NuyenString(objArmor.DisplayCost(out decimal _, false));

                        tabArmor.Rows.Add(strArmorGuid, strArmorName, intArmor, decCapacity, objAvail, strAccessories.ToString(), strSource, strCost);
                    }
                }

                DataSet set = new DataSet("armor");
                set.Tables.Add(tabArmor);

                dgvArmor.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                dgvArmor.DataSource       = set;
                dgvArmor.DataMember       = "armor";
                break;

            default:
                List <ListItem> lstArmors = new List <ListItem>();
                foreach (XmlNode objXmlArmor in objXmlArmorList)
                {
                    if (!chkHideOverAvailLimit.Checked || SelectionShared.CheckAvailRestriction(objXmlArmor, _objCharacter))
                    {
                        string strDisplayName = objXmlArmor["translate"]?.InnerText ?? objXmlArmor["name"]?.InnerText;
                        if (!_objCharacter.Options.SearchInCategoryOnly && txtSearch.TextLength != 0)
                        {
                            string strCategory = objXmlArmor["category"]?.InnerText;
                            if (!string.IsNullOrEmpty(strCategory))
                            {
                                ListItem objFoundItem = _lstCategory.Find(objFind => objFind.Value.ToString() == strCategory);
                                if (!string.IsNullOrEmpty(objFoundItem.Name))
                                {
                                    strDisplayName += " [" + objFoundItem.Name + "]";
                                }
                            }
                        }

                        lstArmors.Add(new ListItem(objXmlArmor["id"]?.InnerText, strDisplayName));
                    }
                }
                lstArmors.Sort(CompareListItems.CompareNames);
                _blnLoading = true;
                string strOldSelected = lstArmor.SelectedValue?.ToString();
                lstArmor.BeginUpdate();
                lstArmor.ValueMember   = "Value";
                lstArmor.DisplayMember = "Name";
                lstArmor.DataSource    = lstArmors;
                _blnLoading            = false;
                if (!string.IsNullOrEmpty(strOldSelected))
                {
                    lstArmor.SelectedValue = strOldSelected;
                }
                else
                {
                    lstArmor.SelectedIndex = -1;
                }
                lstArmor.EndUpdate();
                break;
            }
        }
Ejemplo n.º 15
0
        private async ValueTask UpdateGearInfo(bool blnUpdateMountComboBoxes = true)
        {
            if (_blnLoading)
            {
                return;
            }

            XPathNavigator xmlAccessory  = null;
            string         strSelectedId = await lstAccessory.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

            // Retrieve the information for the selected Accessory.
            if (!string.IsNullOrEmpty(strSelectedId))
            {
                xmlAccessory = _xmlBaseChummerNode.SelectSingleNode("accessories/accessory[id = " + strSelectedId.CleanXPath() + ']');
            }
            if (xmlAccessory == null)
            {
                await tlpRight.DoThreadSafeAsync(x => x.Visible = false);

                return;
            }

            string strRC = xmlAccessory.SelectSingleNode("rc")?.Value;

            if (!string.IsNullOrEmpty(strRC))
            {
                await lblRCLabel.DoThreadSafeAsync(x => x.Visible = true);

                await lblRC.DoThreadSafeAsync(x =>
                {
                    x.Visible = true;
                    x.Text    = strRC;
                });
            }
            else
            {
                await lblRC.DoThreadSafeAsync(x => x.Visible = false);

                await lblRCLabel.DoThreadSafeAsync(x => x.Visible = false);
            }
            if (int.TryParse(xmlAccessory.SelectSingleNode("rating")?.Value, out int intMaxRating) && intMaxRating > 0)
            {
                await nudRating.DoThreadSafeAsync(x => x.Maximum = intMaxRating);

                if (await chkHideOverAvailLimit.DoThreadSafeFuncAsync(x => x.Checked))
                {
                    await nudRating.DoThreadSafeAsync(x =>
                    {
                        while (x.Maximum > x.Minimum &&
                               !xmlAccessory.CheckAvailRestriction(_objCharacter, x.MaximumAsInt))
                        {
                            --x.Maximum;
                        }
                    });
                }
                if (await chkShowOnlyAffordItems.DoThreadSafeFuncAsync(x => x.Checked) && !await chkFreeItem.DoThreadSafeFuncAsync(x => x.Checked))
                {
                    decimal decCostMultiplier = 1 + (await nudMarkup.DoThreadSafeFuncAsync(x => x.Value) / 100.0m);
                    if (_setBlackMarketMaps.Contains(xmlAccessory.SelectSingleNode("category")?.Value))
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    await nudRating.DoThreadSafeAsync(x =>
                    {
                        while (x.Maximum > x.Minimum &&
                               !xmlAccessory.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier,
                                                                   x.MaximumAsInt))
                        {
                            --x.Maximum;
                        }
                    });
                }

                await nudRating.DoThreadSafeAsync(x =>
                {
                    x.Enabled = nudRating.Maximum != nudRating.Minimum;
                    x.Visible = true;
                });

                await lblRatingLabel.DoThreadSafeAsync(x => x.Visible = true);

                await lblRatingNALabel.DoThreadSafeAsync(x => x.Visible = false);
            }
            else
            {
                await lblRatingNALabel.DoThreadSafeAsync(x => x.Visible = true);

                await nudRating.DoThreadSafeAsync(x =>
                {
                    x.Enabled = false;
                    x.Visible = false;
                });

                await lblRatingLabel.DoThreadSafeAsync(x => x.Visible = true);
            }

            if (blnUpdateMountComboBoxes)
            {
                string        strDataMounts = xmlAccessory.SelectSingleNode("mount")?.Value;
                List <string> strMounts     = new List <string>(1);
                if (!string.IsNullOrEmpty(strDataMounts))
                {
                    strMounts.AddRange(strDataMounts.SplitNoAlloc('/', StringSplitOptions.RemoveEmptyEntries));
                }

                strMounts.Add("None");

                List <string> strAllowed = new List <string>(_lstAllowedMounts)
                {
                    "None"
                };
                string strSelectedMount = await cboMount.DoThreadSafeFuncAsync(x =>
                {
                    x.Visible = true;
                    x.Items.Clear();
                    foreach (string strCurrentMount in strMounts)
                    {
                        if (!string.IsNullOrEmpty(strCurrentMount))
                        {
                            foreach (string strAllowedMount in strAllowed)
                            {
                                if (strCurrentMount == strAllowedMount)
                                {
                                    x.Items.Add(strCurrentMount);
                                }
                            }
                        }
                    }

                    x.Enabled       = x.Items.Count > 1;
                    x.SelectedIndex = 0;
                    return(x.SelectedItem.ToString());
                });

                await lblMountLabel.DoThreadSafeAsync(x => x.Visible = true);

                List <string> strExtraMounts = new List <string>(1);
                string        strExtraMount  = xmlAccessory.SelectSingleNode("extramount")?.Value;
                if (!string.IsNullOrEmpty(strExtraMount))
                {
                    foreach (string strItem in strExtraMount.SplitNoAlloc('/', StringSplitOptions.RemoveEmptyEntries))
                    {
                        strExtraMounts.Add(strItem);
                    }
                }

                strExtraMounts.Add("None");

                await cboExtraMount.DoThreadSafeFuncAsync(x =>
                {
                    x.Items.Clear();
                    foreach (string strCurrentMount in strExtraMounts)
                    {
                        if (!string.IsNullOrEmpty(strCurrentMount))
                        {
                            foreach (string strAllowedMount in strAllowed)
                            {
                                if (strCurrentMount == strAllowedMount)
                                {
                                    x.Items.Add(strCurrentMount);
                                }
                            }
                        }
                    }

                    x.Enabled       = x.Items.Count > 1;
                    x.SelectedIndex = 0;
                    if (strSelectedMount != "None" && x.SelectedItem.ToString() != "None" &&
                        strSelectedMount == x.SelectedItem.ToString())
                    {
                        ++x.SelectedIndex;
                    }
                    x.Visible = x.Enabled && x.SelectedItem.ToString() != "None";
                    return(x.Visible);
                }).ContinueWith(y => lblExtraMountLabel.DoThreadSafeAsync(x => x.Visible = y.Result)).Unwrap();
            }

            int intRating = await nudRating.DoThreadSafeFuncAsync(x => x.ValueAsInt);

            // Avail.
            // If avail contains "F" or "R", remove it from the string so we can use the expression.
            string strAvail
                = new AvailabilityValue(intRating, xmlAccessory.SelectSingleNode("avail")?.Value)
                  .ToString();
            await lblAvail.DoThreadSafeAsync(x => x.Text = strAvail);

            await lblAvailLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strAvail));

            if (!await chkFreeItem.DoThreadSafeFuncAsync(x => x.Checked))
            {
                string strCost = "0";
                if (xmlAccessory.TryGetStringFieldQuickly("cost", ref strCost))
                {
                    strCost = (await strCost.CheapReplaceAsync("Weapon Cost",
                                                               () => _objParentWeapon.OwnCost.ToString(GlobalSettings.InvariantCultureInfo))
                               .CheapReplaceAsync("Weapon Total Cost",
                                                  () => _objParentWeapon.MultipliableCost(null)
                                                  .ToString(GlobalSettings.InvariantCultureInfo)))
                              .Replace("Rating", intRating.ToString(GlobalSettings.CultureInfo));
                }
                if (strCost.StartsWith("Variable(", StringComparison.Ordinal))
                {
                    decimal decMin;
                    decimal decMax = decimal.MaxValue;
                    strCost = strCost.TrimStartOnce("Variable(", true).TrimEndOnce(')');
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decimal.TryParse(strValues[0], NumberStyles.Any, GlobalSettings.InvariantCultureInfo, out decMin);
                        decimal.TryParse(strValues[1], NumberStyles.Any, GlobalSettings.InvariantCultureInfo, out decMax);
                    }
                    else
                    {
                        decimal.TryParse(strCost.FastEscape('+'), NumberStyles.Any, GlobalSettings.InvariantCultureInfo, out decMin);
                    }

                    if (decMax == decimal.MaxValue)
                    {
                        await lblCost.DoThreadSafeAsync(
                            x => x.Text = decMin.ToString(_objCharacter.Settings.NuyenFormat,
                                                          GlobalSettings.CultureInfo) + "¥+");
                    }
                    else
                    {
                        string strSpace = await LanguageManager.GetStringAsync("String_Space");

                        await lblCost.DoThreadSafeAsync(
                            x => x.Text = decMin.ToString(_objCharacter.Settings.NuyenFormat,
                                                          GlobalSettings.CultureInfo) + strSpace + '-'
                            + strSpace + decMax.ToString(_objCharacter.Settings.NuyenFormat,
                                                         GlobalSettings.CultureInfo) + '¥');
                    }

                    await lblTest.DoThreadSafeAsync(x => x.Text = _objCharacter.AvailTest(decMax, strAvail));
                }
                else
                {
                    object  objProcess = CommonFunctions.EvaluateInvariantXPath(strCost, out bool blnIsSuccess);
                    decimal decCost    = blnIsSuccess ? Convert.ToDecimal(objProcess, GlobalSettings.InvariantCultureInfo) : 0;

                    // Apply any markup.
                    decCost *= 1 + (await nudMarkup.DoThreadSafeFuncAsync(x => x.Value) / 100.0m);

                    if (await chkBlackMarketDiscount.DoThreadSafeFuncAsync(x => x.Checked))
                    {
                        decCost *= 0.9m;
                    }
                    decCost *= _objParentWeapon.AccessoryMultiplier;
                    if (!string.IsNullOrEmpty(_objParentWeapon.DoubledCostModificationSlots))
                    {
                        string[] astrParentDoubledCostModificationSlots = _objParentWeapon.DoubledCostModificationSlots.Split('/', StringSplitOptions.RemoveEmptyEntries);
                        if (astrParentDoubledCostModificationSlots.Contains(await cboMount.DoThreadSafeFuncAsync(x => x.SelectedItem?.ToString())) ||
                            astrParentDoubledCostModificationSlots.Contains(await cboExtraMount.DoThreadSafeFuncAsync(x => x.SelectedItem?.ToString())))
                        {
                            decCost *= 2;
                        }
                    }

                    await lblCost.DoThreadSafeAsync(x => x.Text = decCost.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + '¥');

                    await lblTest.DoThreadSafeAsync(x => x.Text = _objCharacter.AvailTest(decCost, strAvail));
                }
            }
            else
            {
                await lblCost.DoThreadSafeAsync(x => x.Text = (0.0m).ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + '¥');

                await lblTest.DoThreadSafeAsync(x => x.Text = _objCharacter.AvailTest(0, strAvail));
            }

            XPathNavigator xmlAccessoryRatingLabel = xmlAccessory.SelectSingleNode("ratinglabel");
            string         strRatingLabel          = xmlAccessoryRatingLabel != null
                ? string.Format(GlobalSettings.CultureInfo, await LanguageManager.GetStringAsync("Label_RatingFormat"),
                                await LanguageManager.GetStringAsync(xmlAccessoryRatingLabel.Value))
                : await LanguageManager.GetStringAsync("Label_Rating");

            await lblRatingLabel.DoThreadSafeAsync(x => x.Text = strRatingLabel);

            await lblCost.DoThreadSafeFuncAsync(x => x.Text)
            .ContinueWith(y => lblCostLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(y.Result)))
            .Unwrap();

            await lblTest.DoThreadSafeFuncAsync(x => x.Text)
            .ContinueWith(y => lblTestLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(y.Result)))
            .Unwrap();

            await chkBlackMarketDiscount.DoThreadSafeAsync(x =>
            {
                x.Enabled = _blnIsParentWeaponBlackMarketAllowed;
                if (!x.Checked)
                {
                    x.Checked = GlobalSettings.AssumeBlackMarket && _blnIsParentWeaponBlackMarketAllowed;
                }
                else if (!_blnIsParentWeaponBlackMarketAllowed)
                {
                    //Prevent chkBlackMarketDiscount from being checked if the gear category doesn't match.
                    x.Checked = false;
                }
            });

            string strSource = xmlAccessory.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

            string strPage = (await xmlAccessory.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? xmlAccessory.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

            SourceString objSourceString = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter);

            await objSourceString.SetControlAsync(lblSource);

            await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(objSourceString.ToString()));

            await tlpRight.DoThreadSafeAsync(x => x.Visible = true);
        }