Ejemplo n.º 1
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)))
                    {
                        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 = new SourceString(
                                    objArmor.Source, objArmor.DisplayPage(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     = 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 (!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,
                                                                 LanguageManager.GetString(
                                                                     "String_RestrictedItemsHidden"),
                                                                 intOverLimit)));
                    }

                    _blnLoading = true;
                    string strOldSelected = lstArmor.SelectedValue?.ToString();
                    lstArmor.BeginUpdate();
                    lstArmor.PopulateWithListItems(lstArmors);
                    _blnLoading = false;
                    if (!string.IsNullOrEmpty(strOldSelected))
                    {
                        lstArmor.SelectedValue = strOldSelected;
                    }
                    else
                    {
                        lstArmor.SelectedIndex = -1;
                    }
                    lstArmor.EndUpdate();
                    break;
                }
            }
        }