예제 #1
0
        /// <summary>
        /// Gets the file type of a given path.
        /// </summary>
        /// <param name="path">The path to check</param>
        /// <returns>The FileType of the path</returns>
        public static FileType GetFileType(string path)
        {
            if (path == "__upone")
            {
                return(FileType.UpOne);
            }

            if (DirectoryExists(path))
            {
                if (Mounts.Contains(GetDirectoryInfo(path)))
                {
                    return(FileType.Mount);
                }
                else
                {
                    return(FileType.Directory);
                }
            }


            string ext = path.Split('.')[path.Split('.').Length - 1];

            switch (ext)
            {
            case "txt":
                return(FileType.TextFile);

            case "pic":
            case "png":
            case "jpg":
            case "bmp":
            case "gif":
                return(FileType.Image);

            case "py":
                return(FileType.Python);

            case "mfs":
                return(FileType.Filesystem);

            case "lua":
                return(FileType.Lua);

            case "skn":
                return(FileType.Skin);

            case "json":
                return(FileType.JSON);

            case "sft":
            //No, not "sex" - ShiftOS EXecutable. xD
            case "sex":
                return(FileType.Executable);

            default:
                return(FileType.Unknown);
            }
        }
예제 #2
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);

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

                    string strID         = objWeapon.SourceID.ToString("D");
                    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>();
                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;
                    }
                    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;
                        }
                    }
                    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();
            }
        }
예제 #3
0
        private async ValueTask <bool> BuildWeaponList(XmlNodeList objNodeList, bool blnForCategories = false)
        {
            SuspendLayout();
            if (tabControl.SelectedIndex == 1 && !blnForCategories)
            {
                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 = ParentWeapon != null?_objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[id = " + ParentWeapon.SourceIDString.CleanXPath() + ']') : null;

                foreach (XmlNode objXmlWeapon in objNodeList)
                {
                    if (!objXmlWeapon.CreateNavigator().RequirementsMet(_objCharacter, ParentWeapon))
                    {
                        continue;
                    }

                    XmlNode xmlTestNode = objXmlWeapon.SelectSingleNode("forbidden/weapondetails");
                    if (xmlTestNode != null && xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                    {
                        // Assumes topmost parent is an AND node
                        continue;
                    }
                    xmlTestNode = objXmlWeapon.SelectSingleNode("required/weapondetails");
                    if (xmlTestNode != null && !xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                    {
                        // Assumes topmost parent is an AND node
                        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;
                        }
                    }

                    using (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(GlobalSettings.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(GlobalSettings.CultureInfo);
                        string strConceal = objWeapon.DisplayConcealability;
                        using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                                       out StringBuilder sbdAccessories))
                        {
                            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 = await SourceString.GetSourceStringAsync(objWeapon.Source,
                                                                                                  await objWeapon.DisplayPageAsync(GlobalSettings.Language),
                                                                                                  GlobalSettings.Language,
                                                                                                  GlobalSettings.CultureInfo,
                                                                                                  _objCharacter);

                            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;
                }
                dgvWeapons.Columns[9].Visible = blnAnyMelee;
                dgvWeapons.Columns[0].Visible = false;
                dgvWeapons.Columns[13].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
                dgvWeapons.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                dgvWeapons.DataSource       = set;
                dgvWeapons.DataMember       = "weapons";
            }
            else
            {
                using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool,
                                                                  out List <ListItem> lstWeapons))
                {
                    int     intOverLimit            = 0;
                    XmlNode xmlParentWeaponDataNode = ParentWeapon != null
                        ? _objXmlDocument.SelectSingleNode("/chummer/weapons/weapon[id = "
                                                           + ParentWeapon.SourceIDString.CleanXPath() + ']')
                        : null;

                    foreach (XmlNode objXmlWeapon in objNodeList)
                    {
                        if (!objXmlWeapon.CreateNavigator().RequirementsMet(_objCharacter, ParentWeapon))
                        {
                            continue;
                        }

                        XmlNode xmlTestNode = objXmlWeapon.SelectSingleNode("forbidden/weapondetails");
                        if (xmlTestNode != null &&
                            xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                        {
                            // Assumes topmost parent is an AND node
                            continue;
                        }

                        xmlTestNode = objXmlWeapon.SelectSingleNode("required/weapondetails");
                        if (xmlTestNode != null &&
                            !xmlParentWeaponDataNode.ProcessFilterOperationNode(xmlTestNode, false))
                        {
                            // Assumes topmost parent is an AND node
                            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 (blnForCategories)
                        {
                            return(true);
                        }
                        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));
                    }

                    if (blnForCategories)
                    {
                        return(false);
                    }
                    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(GlobalSettings.CultureInfo,
                                                                  await LanguageManager.GetStringAsync(
                                                                      "String_RestrictedItemsHidden"),
                                                                  intOverLimit)));
                    }

                    string strOldSelected = lstWeapon.SelectedValue?.ToString();
                    _blnLoading = true;
                    await lstWeapon.PopulateWithListItemsAsync(lstWeapons);

                    _blnLoading = false;
                    if (!string.IsNullOrEmpty(strOldSelected))
                    {
                        lstWeapon.SelectedValue = strOldSelected;
                    }
                    else
                    {
                        lstWeapon.SelectedIndex = -1;
                    }
                }
            }
            ResumeLayout();
            return(true);
        }
예제 #4
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(Int32);
                tabWeapons.Columns.Add("Damage");
                tabWeapons.Columns.Add("AP");
                tabWeapons.Columns.Add("RC");
                tabWeapons.Columns["RC"].DataType = typeof(Int32);
                tabWeapons.Columns.Add("Ammo");
                tabWeapons.Columns.Add("Mode");
                tabWeapons.Columns.Add("Reach");
                tabWeapons.Columns.Add("Accessories");
                tabWeapons.Columns.Add("Avail");
                tabWeapons.Columns.Add("Source");
                tabWeapons.Columns.Add("Cost");
                tabWeapons.Columns["Cost"].DataType = typeof(Int32);

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

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

                    string strID         = objWeapon.SourceID.ToString();
                    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.Ammo;
                    string strMode        = objWeapon.Mode;
                    string strReach       = objWeapon.TotalReach.ToString();
                    string strAccessories = string.Empty;
                    foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                    {
                        if (strAccessories.Length > 0)
                        {
                            strAccessories += "\n";
                        }
                        strAccessories += objAccessory.DisplayName(GlobalOptions.Language);
                    }
                    string  strAvail  = objWeapon.TotalAvail(GlobalOptions.Language);
                    string  strSource = objWeapon.Source + " " + objWeapon.DisplayPage(GlobalOptions.Language);
                    decimal decCost   = objWeapon.Cost;

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

                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)
                {
                    bool blnHide = objXmlWeapon["cyberware"]?.InnerText == "yes" || objXmlWeapon["hide"]?.InnerText == "yes";

                    if (objXmlWeapon["mount"] != null && !blnHide)
                    {
                        blnHide = !Mounts.Contains(objXmlWeapon["mount"].InnerText);
                    }
                    if (objXmlWeapon["extramount"] != null && !blnHide)
                    {
                        blnHide = !Mounts.Contains(objXmlWeapon["extramount"].InnerText);
                    }
                    if (blnHide || !Backend.SelectionShared.CheckAvailRestriction(objXmlWeapon, _objCharacter, chkHideOverAvailLimit.Checked))
                    {
                        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();
            }
        }
예제 #5
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("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.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;

                    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);
                    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, sbdAccessories.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" ||
                    !(strSelectedCategory == "Blades" ||
                      strSelectedCategory == "Clubs" ||
                      strSelectedCategory == "Improvised Weapons" ||
                      strSelectedCategory == "Exotic Melee Weapons" ||
                      strSelectedCategory == "Unarmed"))
                {
                    //dgvWeapons.Columns[5].Visible = true;
                    dgvWeapons.Columns[6].Visible = true;
                    dgvWeapons.Columns[7].Visible = true;
                    dgvWeapons.Columns[8].Visible = true;
                }
                else
                {
                    //dgvWeapons.Columns[5].Visible = false;
                    dgvWeapons.Columns[6].Visible = false;
                    dgvWeapons.Columns[7].Visible = false;
                    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
            {
                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();
        }