Ejemplo n.º 1
0
        private void BuildVehicleList(XPathNodeIterator objXmlVehicleList)
        {
            List <ListItem> lstVehicles = new List <ListItem>();

            foreach (XPathNavigator objXmlVehicle in objXmlVehicleList)
            {
                if (!chkHideOverAvailLimit.Checked || SelectionShared.CheckAvailRestriction(objXmlVehicle, _objCharacter))
                {
                    string strDisplayname = objXmlVehicle.SelectSingleNode("translate")?.Value ?? objXmlVehicle.SelectSingleNode("name")?.Value ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language);

                    if (!_objCharacter.Options.SearchInCategoryOnly && txtSearch.TextLength != 0)
                    {
                        string strCategory = objXmlVehicle.SelectSingleNode("category")?.Value;
                        if (!string.IsNullOrEmpty(strCategory))
                        {
                            ListItem objFoundItem = _lstCategory.Find(objFind => objFind.Value.ToString() == strCategory);
                            if (!string.IsNullOrEmpty(objFoundItem.Name))
                            {
                                strDisplayname += " [" + objFoundItem.Name + ']';
                            }
                        }
                    }
                    lstVehicles.Add(new ListItem(objXmlVehicle.SelectSingleNode("id")?.Value ?? string.Empty, strDisplayname));
                }
            }
            lstVehicles.Sort(CompareListItems.CompareNames);
            lstVehicle.BeginUpdate();
            lstVehicle.DataSource    = null;
            lstVehicle.ValueMember   = "Value";
            lstVehicle.DisplayMember = "Name";
            lstVehicle.DataSource    = lstVehicles;
            lstVehicle.EndUpdate();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Accept the selected item and close the form.
        /// </summary>
        private void AcceptForm()
        {
            if (string.IsNullOrEmpty(lstQualities.Text))
            {
                return;
            }
            //Test for whether we're adding a "Special" quality. This should probably be a separate function at some point.
            switch (lstQualities.SelectedValue.ToString())
            {
            case "Changeling (Class I SURGE)":
                _objCharacter.MetageneticLimit = 30;
                break;

            case "Changeling (Class II SURGE)":
                _objCharacter.MetageneticLimit = 30;
                break;

            case "Changeling (Class III SURGE)":
                _objCharacter.MetageneticLimit = 30;
                break;

            default:
                break;
            }

            XmlNode objNode = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[name = \"" + lstQualities.SelectedValue + "\"]");

            if (objNode == null)
            {
                return;
            }
            _strSelectedQuality = objNode["name"]?.InnerText;
            _strSelectCategory  = objNode["category"]?.InnerText;

            if (!SelectionShared.RequirementsMet(objNode, true, _objCharacter, null, null, _objXmlDocument, IgnoreQuality, LanguageManager.Instance.GetString("String_Quality")))
            {
                return;
            }
            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Build the list of available weapon accessories.
        /// </summary>
        private void BuildAccessoryList()
        {
            List <ListItem> lstAccessories = new List <ListItem>();

            // Populate the Accessory list.
            StringBuilder strMount = new StringBuilder("contains(mount, \"Internal\") or contains(mount, \"None\") or mount = \"\"");

            foreach (string strAllowedMount in _lstAllowedMounts)
            {
                if (!string.IsNullOrEmpty(strAllowedMount))
                {
                    strMount.Append(" or contains(mount, \"" + strAllowedMount + "\")");
                }
            }
            strMount.Append(CommonFunctions.GenerateSearchXPath(txtSearch.Text));
            XPathNavigator xmlParentWeaponDataNode = _xmlBaseChummerNode.SelectSingleNode("weapons/weapon[id = \"" + _objParentWeapon.SourceIDString + "\"]");

            foreach (XPathNavigator objXmlAccessory in _xmlBaseChummerNode.Select("accessories/accessory[(" + strMount + ") and (" + _objCharacter.Options.BookXPath() + ")]"))
            {
                string strId = objXmlAccessory.SelectSingleNode("id")?.Value;
                if (string.IsNullOrEmpty(strId))
                {
                    continue;
                }

                XPathNavigator xmlExtraMountNode = objXmlAccessory.SelectSingleNode("extramount");
                if (xmlExtraMountNode != null)
                {
                    if (_lstAllowedMounts.Count > 1)
                    {
                        foreach (string strItem in xmlExtraMountNode.Value.Split('/'))
                        {
                            if (!string.IsNullOrEmpty(strItem) && _lstAllowedMounts.All(strAllowedMount => strAllowedMount != strItem))
                            {
                                goto NextItem;
                            }
                        }
                    }
                }

                if (!objXmlAccessory.RequirementsMet(_objCharacter, _objParentWeapon, string.Empty, string.Empty))
                {
                    continue;
                }

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

                decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                if (_blnIsParentWeaponBlackMarketAllowed)
                {
                    decCostMultiplier *= 0.9m;
                }
                if ((!chkHideOverAvailLimit.Checked || SelectionShared.CheckAvailRestriction(objXmlAccessory, _objCharacter) &&
                     (chkFreeItem.Checked || !chkShowOnlyAffordItems.Checked ||
                      SelectionShared.CheckNuyenRestriction(objXmlAccessory, _objCharacter.Nuyen, decCostMultiplier))))
                {
                    lstAccessories.Add(new ListItem(strId, objXmlAccessory.SelectSingleNode("translate")?.Value ?? objXmlAccessory.SelectSingleNode("name")?.Value ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language)));
                }
                NextItem :;
            }

            lstAccessories.Sort(CompareListItems.CompareNames);
            string strOldSelected = lstAccessory.SelectedValue?.ToString();

            _blnLoading = true;
            lstAccessory.BeginUpdate();
            lstAccessory.ValueMember   = "Value";
            lstAccessory.DisplayMember = "Name";
            lstAccessory.DataSource    = lstAccessories;
            _blnLoading = false;
            if (!string.IsNullOrEmpty(strOldSelected))
            {
                lstAccessory.SelectedValue = strOldSelected;
            }
            else
            {
                lstAccessory.SelectedIndex = -1;
            }
            lstAccessory.EndUpdate();
        }
Ejemplo n.º 4
0
        private void UpdateGearInfo()
        {
            if (_blnLoading)
            {
                return;
            }

            XPathNavigator xmlAccessory  = null;
            string         strSelectedId = lstAccessory.SelectedValue?.ToString();

            // Retrieve the information for the selected Accessory.
            if (!string.IsNullOrEmpty(strSelectedId))
            {
                xmlAccessory = _xmlBaseChummerNode.SelectSingleNode("accessories/accessory[id = \"" + strSelectedId + "\"]");
            }
            if (xmlAccessory == null)
            {
                lblRC.Visible            = false;
                lblRCLabel.Visible       = false;
                nudRating.Enabled        = false;
                nudRating.Visible        = false;
                lblRatingLabel.Visible   = false;
                lblRatingNALabel.Visible = false;
                lblMountLabel.Visible    = false;
                cboMount.Visible         = false;
                cboMount.Items.Clear();
                lblExtraMountLabel.Visible = false;
                cboExtraMount.Visible      = false;
                cboExtraMount.Items.Clear();
                lblAvailLabel.Visible  = false;
                lblAvail.Text          = string.Empty;
                lblCostLabel.Visible   = false;
                lblCost.Text           = string.Empty;
                lblTestLabel.Visible   = false;
                lblTest.Text           = string.Empty;
                lblSourceLabel.Visible = false;
                lblSource.Text         = string.Empty;
                lblSource.SetToolTip(string.Empty);
                return;
            }

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

            if (!string.IsNullOrEmpty(strRC))
            {
                lblRC.Visible      = true;
                lblRCLabel.Visible = true;
                lblRC.Text         = strRC;
            }
            else
            {
                lblRC.Visible      = false;
                lblRCLabel.Visible = false;
            }
            if (int.TryParse(xmlAccessory.SelectSingleNode("rating")?.Value, out int intMaxRating) && intMaxRating > 0)
            {
                nudRating.Maximum = intMaxRating;
                if (chkHideOverAvailLimit.Checked)
                {
                    while (nudRating.Maximum > nudRating.Minimum && !SelectionShared.CheckAvailRestriction(xmlAccessory, _objCharacter, decimal.ToInt32(nudRating.Maximum)))
                    {
                        nudRating.Maximum -= 1;
                    }
                }
                if (chkShowOnlyAffordItems.Checked && !chkFreeItem.Checked)
                {
                    decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                    if (_setBlackMarketMaps.Contains(xmlAccessory.SelectSingleNode("category")?.Value))
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    while (nudRating.Maximum > nudRating.Minimum && !SelectionShared.CheckNuyenRestriction(xmlAccessory, _objCharacter.Nuyen, decCostMultiplier, decimal.ToInt32(nudRating.Maximum)))
                    {
                        nudRating.Maximum -= 1;
                    }
                }
                nudRating.Enabled        = nudRating.Maximum != nudRating.Minimum;
                nudRating.Visible        = true;
                lblRatingLabel.Visible   = true;
                lblRatingNALabel.Visible = false;
            }
            else
            {
                lblRatingNALabel.Visible = true;
                nudRating.Enabled        = false;
                nudRating.Visible        = false;
                lblRatingLabel.Visible   = true;
            }

            string[]      astrDataMounts = xmlAccessory.SelectSingleNode("mount")?.Value.Split('/');
            List <string> strMounts      = new List <string>();

            if (astrDataMounts != null)
            {
                strMounts.AddRange(astrDataMounts);
            }
            strMounts.Add("None");

            List <string> strAllowed = new List <string>(_lstAllowedMounts)
            {
                "None"
            };

            cboMount.Visible = true;
            cboMount.Items.Clear();
            foreach (string strCurrentMount in strMounts)
            {
                if (!string.IsNullOrEmpty(strCurrentMount))
                {
                    foreach (string strAllowedMount in strAllowed)
                    {
                        if (strCurrentMount == strAllowedMount)
                        {
                            cboMount.Items.Add(strCurrentMount);
                        }
                    }
                }
            }
            cboMount.Enabled       = cboMount.Items.Count > 1;
            cboMount.SelectedIndex = 0;
            lblMountLabel.Visible  = true;

            List <string> strExtraMounts = new List <string>();
            string        strExtraMount  = xmlAccessory.SelectSingleNode("extramount")?.Value;

            if (!string.IsNullOrEmpty(strExtraMount))
            {
                foreach (string strItem in strExtraMount.Split('/'))
                {
                    strExtraMounts.Add(strItem);
                }
            }
            strExtraMounts.Add("None");

            cboExtraMount.Items.Clear();
            foreach (string strCurrentMount in strExtraMounts)
            {
                if (!string.IsNullOrEmpty(strCurrentMount))
                {
                    foreach (string strAllowedMount in strAllowed)
                    {
                        if (strCurrentMount == strAllowedMount)
                        {
                            cboExtraMount.Items.Add(strCurrentMount);
                        }
                    }
                }
            }
            cboExtraMount.Enabled       = cboExtraMount.Items.Count > 1;
            cboExtraMount.SelectedIndex = 0;
            if (cboMount.SelectedItem.ToString() != "None" && cboExtraMount.SelectedItem.ToString() != "None" &&
                cboMount.SelectedItem.ToString() == cboExtraMount.SelectedItem.ToString())
            {
                cboExtraMount.SelectedIndex += 1;
            }
            cboExtraMount.Visible      = cboExtraMount.Enabled && cboExtraMount.SelectedItem.ToString() != "None";
            lblExtraMountLabel.Visible = cboExtraMount.Visible;
            // Avail.
            // If avail contains "F" or "R", remove it from the string so we can use the expression.
            string strSuffix = string.Empty;
            string strAvail  = xmlAccessory.SelectSingleNode("avail")?.Value;

            if (!string.IsNullOrWhiteSpace(strAvail))
            {
                char chrLastAvailChar = strAvail[strAvail.Length - 1];
                if (chrLastAvailChar == 'F')
                {
                    strSuffix = LanguageManager.GetString("String_AvailForbidden", GlobalOptions.Language);
                    strAvail  = strAvail.Substring(0, strAvail.Length - 1);
                }
                else if (chrLastAvailChar == 'R')
                {
                    strSuffix = LanguageManager.GetString("String_AvailRestricted", GlobalOptions.Language);
                    strAvail  = strAvail.Substring(0, strAvail.Length - 1);
                }

                object objProcess = CommonFunctions.EvaluateInvariantXPath(strAvail.Replace("Rating", nudRating.Value.ToString(GlobalOptions.CultureInfo)), out bool blnIsSuccess);
                lblAvail.Text = blnIsSuccess ? Convert.ToInt32(objProcess).ToString() : strAvail + strSuffix;
            }
            else
            {
                lblAvail.Text = "0";
            }
            lblAvailLabel.Visible = !string.IsNullOrEmpty(lblAvail.Text);

            if (!chkFreeItem.Checked)
            {
                string strCost = "0";
                if (xmlAccessory.TryGetStringFieldQuickly("cost", ref strCost))
                {
                    strCost = strCost.CheapReplace("Weapon Cost", () => _objParentWeapon.OwnCost.ToString(GlobalOptions.InvariantCultureInfo))
                              .Replace("Rating", nudRating.Value.ToString(GlobalOptions.CultureInfo));
                }
                if (strCost.StartsWith("Variable("))
                {
                    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, GlobalOptions.InvariantCultureInfo, out decMin);
                        decimal.TryParse(strValues[1], NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decMax);
                    }
                    else
                    {
                        decimal.TryParse(strCost.FastEscape('+'), NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decMin);
                    }

                    if (decMax == decimal.MaxValue)
                    {
                        lblCost.Text = decMin.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + "¥+";
                    }
                    else
                    {
                        lblCost.Text = decMin.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + " - " + decMax.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    }

                    lblTest.Text = _objCharacter.AvailTest(decMax, lblAvail.Text);
                }
                else
                {
                    object  objProcess = CommonFunctions.EvaluateInvariantXPath(strCost, out bool blnIsSuccess);
                    decimal decCost    = blnIsSuccess ? Convert.ToDecimal(objProcess, GlobalOptions.InvariantCultureInfo) : 0;

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

                    if (chkBlackMarketDiscount.Checked)
                    {
                        decCost *= 0.9m;
                    }

                    lblCost.Text = decCost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    lblTest.Text = _objCharacter.AvailTest(decCost, lblAvail.Text);
                }
            }
            else
            {
                lblCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                lblTest.Text = _objCharacter.AvailTest(0, lblAvail.Text);
            }
            lblCostLabel.Visible           = !string.IsNullOrEmpty(lblCost.Text);
            lblTestLabel.Visible           = !string.IsNullOrEmpty(lblTest.Text);
            chkBlackMarketDiscount.Checked = _blnIsParentWeaponBlackMarketAllowed;
            string strSource         = xmlAccessory.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language);
            string strPage           = xmlAccessory.SelectSingleNode("altpage")?.Value ?? xmlAccessory.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language);
            string strSpaceCharacter = LanguageManager.GetString("String_Space", GlobalOptions.Language);

            lblSource.Text = CommonFunctions.LanguageBookShort(strSource, GlobalOptions.Language) + strSpaceCharacter + strPage;
            lblSource.SetToolTip(CommonFunctions.LanguageBookLong(strSource, GlobalOptions.Language) + strSpaceCharacter + LanguageManager.GetString("String_Page", GlobalOptions.Language) + strSpaceCharacter + strPage);
            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
        }
        /// <summary>
        /// Build the list of available weapon accessories.
        /// </summary>
        private void BuildAccessoryList()
        {
            List <ListItem> lstAccessories = new List <ListItem>();

            // Populate the Accessory list.
            StringBuilder strMount = new StringBuilder("contains(mount, \"Internal\") or contains(mount, \"None\") or mount = \"\"");

            foreach (string strAllowedMount in _lstAllowedMounts)
            {
                if (!string.IsNullOrEmpty(strAllowedMount))
                {
                    strMount.Append(" or contains(mount, \"" + strAllowedMount + "\")");
                }
            }
            XmlNode xmlParentWeaponDataNode = _objParentWeapon.GetNode();

            using (XmlNodeList objXmlAccessoryList = _objXmlDocument.SelectNodes("/chummer/accessories/accessory[(" + strMount + ") and (" + _objCharacter.Options.BookXPath() + ")]"))
                if (objXmlAccessoryList != null)
                {
                    foreach (XmlNode objXmlAccessory in objXmlAccessoryList)
                    {
                        XmlNode xmlExtraMountNode = objXmlAccessory["extramount"];
                        if (xmlExtraMountNode != null)
                        {
                            if (_lstAllowedMounts.Count > 1)
                            {
                                foreach (string strItem in (xmlExtraMountNode.InnerText.Split('/')).Where(strItem => !string.IsNullOrEmpty(strItem)))
                                {
                                    if (_lstAllowedMounts.All(strAllowedMount => strAllowedMount != strItem))
                                    {
                                        goto NextItem;
                                    }
                                }
                            }
                        }

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

                        xmlTestNode = objXmlAccessory.SelectSingleNode("forbidden/oneof");
                        if (xmlTestNode != null)
                        {
                            using (XmlNodeList objXmlForbiddenList = xmlTestNode.SelectNodes("accessory"))
                            {
                                if (objXmlForbiddenList != null)
                                {
                                    //Add to set for O(N log M) runtime instead of O(N * M)

                                    HashSet <string> objForbiddenAccessory = new HashSet <string>();
                                    foreach (XmlNode node in objXmlForbiddenList)
                                    {
                                        objForbiddenAccessory.Add(node.InnerText);
                                    }

                                    if (_objParentWeapon.WeaponAccessories.Any(objAccessory =>
                                                                               objForbiddenAccessory.Contains(objAccessory.Name)))
                                    {
                                        continue;
                                    }
                                }
                            }
                        }

                        xmlTestNode = objXmlAccessory.SelectSingleNode("required/oneof");
                        if (xmlTestNode != null)
                        {
                            using (XmlNodeList objXmlRequiredList = xmlTestNode.SelectNodes("accessory"))
                            {
                                if (objXmlRequiredList != null)
                                {
                                    //Add to set for O(N log M) runtime instead of O(N * M)

                                    HashSet <string> objRequiredAccessory = new HashSet <string>();
                                    foreach (XmlNode node in objXmlRequiredList)
                                    {
                                        objRequiredAccessory.Add(node.InnerText);
                                    }

                                    if (!_objParentWeapon.WeaponAccessories.Any(objAccessory =>
                                                                                objRequiredAccessory.Contains(objAccessory.Name)))
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }

                        if (!chkHideOverAvailLimit.Checked || SelectionShared.CheckAvailRestriction(objXmlAccessory, _objCharacter))
                        {
                            lstAccessories.Add(new ListItem(objXmlAccessory["id"]?.InnerText, objXmlAccessory["translate"]?.InnerText ?? objXmlAccessory["name"]?.InnerText ?? string.Empty));
                        }
                        NextItem :;
                    }
                }

            lstAccessories.Sort(CompareListItems.CompareNames);
            string strOldSelected = lstAccessory.SelectedValue?.ToString();

            _blnLoading = true;
            lstAccessory.BeginUpdate();
            lstAccessory.ValueMember   = "Value";
            lstAccessory.DisplayMember = "Name";
            lstAccessory.DataSource    = lstAccessories;
            _blnLoading = false;
            if (!string.IsNullOrEmpty(strOldSelected))
            {
                lstAccessory.SelectedValue = strOldSelected;
            }
            else
            {
                lstAccessory.SelectedIndex = -1;
            }
            lstAccessory.EndUpdate();
        }
Ejemplo n.º 6
0
        private void lstArmor_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            XmlNode xmlArmor      = null;
            string  strSelectedId = lstArmor.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                xmlArmor = _objXmlDocument.SelectSingleNode("/chummer/armors/armor[id = \"" + strSelectedId + "\"]");
            }
            if (xmlArmor != null)
            {
                // Create the Armor so we can show its Total Avail (some Armor includes Chemical Seal which adds +6 which wouldn't be factored in properly otherwise).
                Armor         objArmor   = new Armor(_objCharacter);
                List <Weapon> lstWeapons = new List <Weapon>();
                objArmor.Create(xmlArmor, 0, lstWeapons, true, true, true);

                _objSelectedArmor = objArmor;

                string strRating = xmlArmor["rating"]?.InnerText;
                if (!string.IsNullOrEmpty(strRating))
                {
                    nudRating.Maximum = Convert.ToInt32(strRating);
                    if (chkHideOverAvailLimit.Checked)
                    {
                        while (nudRating.Maximum > 1 && !SelectionShared.CheckAvailRestriction(xmlArmor, _objCharacter, decimal.ToInt32(nudRating.Maximum)))
                        {
                            nudRating.Maximum -= 1;
                        }
                    }

                    if (chkShowOnlyAffordItems.Checked && !chkFreeItem.Checked)
                    {
                        decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                        if (_setBlackMarketMaps.Contains(xmlArmor.SelectSingleNode("category")?.Value))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        while (nudRating.Maximum > 1 && !SelectionShared.CheckNuyenRestriction(xmlArmor, _objCharacter.Nuyen, decCostMultiplier, decimal.ToInt32(nudRating.Maximum)))
                        {
                            nudRating.Maximum -= 1;
                        }
                    }
                    lblRatingLabel.Visible   = true;
                    nudRating.Minimum        = 1;
                    nudRating.Value          = 1;
                    nudRating.Enabled        = nudRating.Minimum != nudRating.Maximum;
                    nudRating.Visible        = true;
                    lblRatingNALabel.Visible = false;
                }
                else
                {
                    lblRatingLabel.Visible   = true;
                    lblRatingNALabel.Visible = true;
                    nudRating.Minimum        = 0;
                    nudRating.Maximum        = 0;
                    nudRating.Value          = 0;
                    nudRating.Enabled        = false;
                    nudRating.Visible        = false;
                }

                lblRatingLabel.Text = xmlArmor.SelectSingleNode("ratinglabel") != null
                    ? LanguageManager.GetString("Label_RatingFormat").Replace("{0}",
                                                                              LanguageManager.GetString(xmlArmor.SelectSingleNode("ratinglabel").Value,
                                                                                                        GlobalOptions.Language))
                    : LanguageManager.GetString("Label_Rating");
            }
            else
            {
                _objSelectedArmor        = null;
                lblRatingLabel.Visible   = false;
                lblRatingNALabel.Visible = false;
                nudRating.Visible        = false;
                nudRating.Enabled        = false;
                nudRating.Minimum        = 0;
                nudRating.Value          = 0;
            }

            UpdateArmorInfo();
        }
Ejemplo n.º 7
0
        private void BuildVehicleList(XPathNodeIterator objXmlVehicleList)
        {
            List <ListItem> lstVehicles = new List <ListItem>();

            foreach (XPathNavigator objXmlVehicle in objXmlVehicleList)
            {
                if (chkHideOverAvailLimit.Checked && !SelectionShared.CheckAvailRestriction(objXmlVehicle, _objCharacter))
                {
                    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 (_setBlackMarketMaps.Contains(objXmlVehicle.SelectSingleNode("category")?.Value))
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    if (_setDealerConnectionMaps?.Any(set => objXmlVehicle.SelectSingleNode("category")?.Value.StartsWith(set) == true) == true)
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    if (!SelectionShared.CheckNuyenRestriction(objXmlVehicle, _objCharacter.Nuyen, decCostMultiplier))
                    {
                        continue;
                    }
                }

                string strDisplayname = objXmlVehicle.SelectSingleNode("translate")?.Value ?? objXmlVehicle.SelectSingleNode("name")?.Value ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language);

                if (!_objCharacter.Options.SearchInCategoryOnly && txtSearch.TextLength != 0)
                {
                    string strCategory = objXmlVehicle.SelectSingleNode("category")?.Value;
                    if (!string.IsNullOrEmpty(strCategory))
                    {
                        ListItem objFoundItem = _lstCategory.Find(objFind => objFind.Value.ToString() == strCategory);
                        if (!string.IsNullOrEmpty(objFoundItem.Name))
                        {
                            strDisplayname += " [" + objFoundItem.Name + ']';
                        }
                    }
                }
                lstVehicles.Add(new ListItem(objXmlVehicle.SelectSingleNode("id")?.Value ?? string.Empty, strDisplayname));
            }
            lstVehicles.Sort(CompareListItems.CompareNames);
            string strOldSelected = lstVehicle.SelectedValue?.ToString();

            _blnLoading = true;
            lstVehicle.BeginUpdate();
            lstVehicle.ValueMember   = "Value";
            lstVehicle.DisplayMember = "Name";
            lstVehicle.DataSource    = lstVehicles;
            _blnLoading = false;
            if (string.IsNullOrEmpty(strOldSelected))
            {
                lstVehicle.SelectedIndex = -1;
            }
            else
            {
                lstVehicle.SelectedValue = strOldSelected;
            }
            lstVehicle.EndUpdate();
        }
Ejemplo n.º 8
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (!_blnAddAgain)
            {
                _lstExpandCategories = null;
            }

            if (treSpells.SelectedNode != null)
            {
                if (treSpells.SelectedNode.Level == 0)
                {
                    return;
                }
                else
                {
                    // Display the Spell information.
                    XmlNode objXmlSpell = _objXmlDocument.SelectSingleNode("/chummer/spells/spell[name = \"" + treSpells.SelectedNode.Tag + "\"]");
                    // Count the number of Spells the character currently has and make sure they do not try to select more Spells than they are allowed.
                    // The maximum number of Spells a character can start with is 2 x (highest of Spellcasting or Ritual Spellcasting Skill).
                    int intSpellCount    = 0;
                    int intRitualCount   = 0;
                    int intAlchPrepCount = 0;

                    foreach (Spell objspell in _objCharacter.Spells)
                    {
                        if (objspell.Alchemical)
                        {
                            intAlchPrepCount++;
                        }
                        else if (objspell.Category == "Rituals")
                        {
                            intRitualCount++;
                        }
                        else
                        {
                            intSpellCount++;
                        }
                    }
                    if (!_objCharacter.IgnoreRules)
                    {
                        int intSpellLimit = (_objCharacter.MAG.TotalValue * 2);
                        if (chkAlchemical.Checked && (intAlchPrepCount >= intSpellLimit) && !_objCharacter.Created)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_SpellLimit"), LanguageManager.Instance.GetString("MessageTitle_SpellLimit"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (objXmlSpell["category"].InnerText == "Rituals" && (intRitualCount >= intSpellLimit) && !_objCharacter.Created)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_SpellLimit"), LanguageManager.Instance.GetString("MessageTitle_SpellLimit"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (intSpellCount >= intSpellLimit && !_objCharacter.Created)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_SpellLimit"),
                                            LanguageManager.Instance.GetString("MessageTitle_SpellLimit"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (!SelectionShared.RequirementsMet(objXmlSpell, true, _objCharacter, null, null, _objXmlDocument, "", LanguageManager.Instance.GetString("String_DescSpell")))
                        {
                            return;
                        }
                    }
                }
                if (treSpells.SelectedNode != null && treSpells.SelectedNode.Level > 0)
                {
                    AcceptForm();
                }
            }
        }
Ejemplo n.º 9
0
        private void lstDrug_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }
            _blnLoading = true;
            XPathNavigator xmlDrug       = null;
            string         strSelectedId = lstDrug.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                // Retrieve the information for the selected piece of Drug.
                xmlDrug = _xmlBaseDrugDataNode.SelectSingleNode(_strNodeXPath + "[id = \"" + strSelectedId + "\"]");
            }
            string strForceGrade;

            if (xmlDrug != null)
            {
                strForceGrade = xmlDrug.SelectSingleNode("forcegrade")?.Value;
                // If the piece has a Rating value, enable the Rating control, otherwise, disable it and set its value to 0.
                XPathNavigator xmlRatingNode = xmlDrug.SelectSingleNode("rating");
                if (xmlRatingNode != null)
                {
                    string strMinRating = xmlDrug.SelectSingleNode("minrating")?.Value;
                    int    intMinRating = 1;
                    // Not a simple integer, so we need to start mucking around with strings
                    if (!string.IsNullOrEmpty(strMinRating) && !int.TryParse(strMinRating, out intMinRating))
                    {
                        strMinRating = strMinRating.CheapReplace("MaximumSTR", () => (ParentVehicle != null ? Math.Max(1, ParentVehicle.TotalBody * 2) : _objCharacter.STR.TotalMaximum).ToString())
                                       .CheapReplace("MaximumAGI", () => (ParentVehicle != null ? Math.Max(1, ParentVehicle.Pilot * 2) : _objCharacter.AGI.TotalMaximum).ToString())
                                       .CheapReplace("MinimumSTR", () => (ParentVehicle?.TotalBody ?? 3).ToString())
                                       .CheapReplace("MinimumAGI", () => (ParentVehicle?.Pilot ?? 3).ToString());

                        object objProcess = CommonFunctions.EvaluateInvariantXPath(strMinRating, out bool blnIsSuccess);
                        intMinRating = blnIsSuccess ? Convert.ToInt32(objProcess) : 1;
                    }
                    nudRating.Minimum = intMinRating;

                    string strMaxRating = xmlRatingNode.Value;
                    int    intMaxRating = 0;
                    // Not a simple integer, so we need to start mucking around with strings
                    if (!string.IsNullOrEmpty(strMaxRating) && !int.TryParse(strMaxRating, out intMaxRating))
                    {
                        strMaxRating = strMaxRating.CheapReplace("MaximumSTR", () => (ParentVehicle != null ? Math.Max(1, ParentVehicle.TotalBody * 2) : _objCharacter.STR.TotalMaximum).ToString())
                                       .CheapReplace("MaximumAGI", () => (ParentVehicle != null ? Math.Max(1, ParentVehicle.Pilot * 2) : _objCharacter.AGI.TotalMaximum).ToString())
                                       .CheapReplace("MinimumSTR", () => (ParentVehicle?.TotalBody ?? 3).ToString())
                                       .CheapReplace("MinimumAGI", () => (ParentVehicle?.Pilot ?? 3).ToString());

                        object objProcess = CommonFunctions.EvaluateInvariantXPath(strMaxRating, out bool blnIsSuccess);
                        intMaxRating = blnIsSuccess ? Convert.ToInt32(objProcess) : 1;
                    }
                    nudRating.Maximum = intMaxRating;
                    if (chkHideOverAvailLimit.Checked)
                    {
                        int intAvailModifier = strForceGrade == "None" ? 0 : _intAvailModifier;
                        while (nudRating.Maximum > intMinRating && !SelectionShared.CheckAvailRestriction(xmlDrug, _objCharacter, decimal.ToInt32(nudRating.Maximum), intAvailModifier))
                        {
                            nudRating.Maximum -= 1;
                        }
                    }

                    if (chkShowOnlyAffordItems.Checked && !chkFree.Checked)
                    {
                        decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                        if (chkBlackMarketDiscount.Checked)
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        while (nudRating.Maximum > intMinRating && !SelectionShared.CheckNuyenRestriction(xmlDrug, _objCharacter.Nuyen, decCostMultiplier, decimal.ToInt32(nudRating.Maximum)))
                        {
                            nudRating.Maximum -= 1;
                        }
                    }
                    nudRating.Value          = nudRating.Minimum;
                    nudRating.Enabled        = nudRating.Minimum != nudRating.Maximum;
                    nudRating.Visible        = true;
                    lblRatingNALabel.Visible = false;
                    lblRatingLabel.Visible   = true;
                }
                else
                {
                    lblRatingLabel.Visible   = true;
                    lblRatingNALabel.Visible = true;
                    nudRating.Minimum        = 0;
                    nudRating.Value          = 0;
                    nudRating.Visible        = false;
                }

                string strSource         = xmlDrug.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language);
                string strPage           = xmlDrug.SelectSingleNode("altpage")?.Value ?? xmlDrug.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language);
                string strSpaceCharacter = LanguageManager.GetString("String_Space", GlobalOptions.Language);
                lblSource.Text = CommonFunctions.LanguageBookShort(strSource, GlobalOptions.Language) + strSpaceCharacter + strPage;
                lblSource.SetToolTip(CommonFunctions.LanguageBookLong(strSource, GlobalOptions.Language) + strSpaceCharacter + LanguageManager.GetString("String_Page", GlobalOptions.Language) + ' ' + strPage);
                lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);

                Grade objForcedGrade = null;
                if (!string.IsNullOrEmpty(strForceGrade))
                {
                    // Force the Drug to be a particular Grade.
                    if (cboGrade.Enabled)
                    {
                        cboGrade.Enabled = false;
                    }
                    objForcedGrade = _lstGrades.FirstOrDefault(x => x.Name == strForceGrade);
                    strForceGrade  = objForcedGrade?.SourceId.ToString("D");
                }
                else
                {
                    cboGrade.Enabled = !_blnLockGrade;
                    if (_blnLockGrade)
                    {
                        strForceGrade  = _objForcedGrade?.SourceId.ToString("D") ?? cboGrade.SelectedValue?.ToString();
                        objForcedGrade = _objForcedGrade ?? _lstGrades.FirstOrDefault(x => x.SourceId.ToString("D") == strForceGrade);
                    }
                }

                chkBlackMarketDiscount.Enabled = _objCharacter.BlackMarketDiscount;

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

                // We may need to rebuild the Grade list since Cultured Bioware is not allowed to select Standard (Second-Hand) as Grade and ForceGrades can change.
                PopulateGrades(xmlDrug.SelectSingleNode("nosecondhand") != null || (!cboGrade.Enabled && objForcedGrade?.SecondHand != true), false, strForceGrade, chkHideBannedGrades.Checked);

                /*
                 * string strNotes = xmlDrug.SelectSingleNode("altnotes")?.Value ?? xmlDrug.SelectSingleNode("notes")?.Value;
                 * if (!string.IsNullOrEmpty(strNotes))
                 * {
                 *  lblDrugNotes.Visible = true;
                 *  lblDrugNotesLabel.Visible = true;
                 *  lblDrugNotes.Text = strNotes;
                 * }
                 * else
                 * {
                 *  lblDrugNotes.Visible = false;
                 *  lblDrugNotesLabel.Visible = false;
                 * }*/
            }
            else
            {
                lblRatingLabel.Visible   = false;
                lblRatingNALabel.Visible = false;
                nudRating.Minimum        = 0;
                nudRating.Value          = 0;
                nudRating.Visible        = false;
                cboGrade.Enabled         = !_blnLockGrade;
                strForceGrade            = string.Empty;
                Grade objForcedGrade = null;
                if (_blnLockGrade)
                {
                    strForceGrade  = _objForcedGrade?.SourceId.ToString("D") ?? cboGrade.SelectedValue?.ToString();
                    objForcedGrade = _objForcedGrade ?? _lstGrades.FirstOrDefault(x => x.SourceId.ToString("D") == strForceGrade);
                }
                PopulateGrades(_blnLockGrade && objForcedGrade?.SecondHand != true, false, strForceGrade, chkHideBannedGrades.Checked);
                chkBlackMarketDiscount.Checked = false;
                lblSourceLabel.Visible         = false;
                lblSource.Text = string.Empty;
                lblSource.SetToolTip(string.Empty);
            }
            _blnLoading = false;
            UpdateDrugInfo();
        }
Ejemplo n.º 10
0
        private void BuildSpellList()
        {
            string strCategory = cboCategory.SelectedValue?.ToString();
            string strFilter   = "(" + _objCharacter.Options.BookXPath() + ")";

            if (!string.IsNullOrEmpty(strCategory) && strCategory != "Show All" && (_objCharacter.Options.SearchInCategoryOnly || txtSearch.TextLength == 0))
            {
                strFilter += " and category = \"" + strCategory + "\"";
            }
            else
            {
                StringBuilder objCategoryFilter = new StringBuilder();
                foreach (string strItem in _lstCategory.Select(x => x.Value))
                {
                    if (!string.IsNullOrEmpty(strItem))
                    {
                        objCategoryFilter.Append("category = \"" + strItem + "\" or ");
                    }
                }
                if (objCategoryFilter.Length > 0)
                {
                    strFilter += " and (" + objCategoryFilter.ToString().TrimEnd(" or ") + ")";
                }
            }
            if (txtSearch.TextLength != 0)
            {
                // Treat everything as being uppercase so the search is case-insensitive.
                string strSearchText = txtSearch.Text.ToUpper();
                strFilter += " and ((contains(translate(name,'abcdefghijklmnopqrstuvwxyzàáâãäåçèéêëìíîïñòóôõöùúûüýß','ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß'), \"" + strSearchText + "\") and not(translate)) or contains(translate(translate,'abcdefghijklmnopqrstuvwxyzàáâãäåçèéêëìíîïñòóôõöùúûüýß','ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß'), \"" + strSearchText + "\"))";
            }

            if (_objCharacter.Options.ExtendAnyDetectionSpell)
            {
                strFilter += " and ((not(contains(name, \", Extended\"))))";
            }

            // Populate the Spell list.
            XmlNodeList objXmlNodeList = _objXmlDocument.SelectNodes("/chummer/spells/spell[" + strFilter + "]");

            List <ListItem> lstSpellItems = new List <ListItem>();

            foreach (XmlNode objXmlSpell in objXmlNodeList)
            {
                string strSpellCategory = objXmlSpell["category"]?.InnerText;
                if (!_blnIgnoreRequirements)
                {
                    if (_objCharacter.AdeptEnabled && !_objCharacter.MagicianEnabled)
                    {
                        if (!((strSpellCategory == "Rituals" && !objXmlSpell["descriptor"].InnerText.Contains("Spell")) ||
                              (_blnCanTouchOnlySpellBeFree && objXmlSpell["range"].InnerText == "T")))
                        {
                            continue;
                        }
                    }
                    else if (!_objCharacter.AdeptEnabled && objXmlSpell["descriptor"].InnerText.Contains("Adept"))
                    {
                        continue;
                    }
                    if (!SelectionShared.RequirementsMet(objXmlSpell, false, _objCharacter))
                    {
                        continue;
                    }
                }

                string strDisplayName = objXmlSpell["translate"]?.InnerText ?? objXmlSpell["name"].InnerText;
                if (!_objCharacter.Options.SearchInCategoryOnly && txtSearch.TextLength != 0)
                {
                    if (!string.IsNullOrEmpty(strSpellCategory))
                    {
                        ListItem objFoundItem = _lstCategory.Find(objFind => objFind.Value == strSpellCategory);
                        if (!string.IsNullOrEmpty(objFoundItem.Name))
                        {
                            strDisplayName += " [" + objFoundItem.Name + "]";
                        }
                    }
                }
                lstSpellItems.Add(new ListItem(objXmlSpell["id"].InnerText, strDisplayName));
            }

            SortListItem objSort = new SortListItem();

            lstSpellItems.Sort(objSort.Compare);
            lstSpells.BeginUpdate();
            lstSpells.DataSource    = null;
            lstSpells.ValueMember   = "Value";
            lstSpells.DisplayMember = "Name";
            lstSpells.DataSource    = lstSpellItems;
            lstSpells.EndUpdate();
        }
Ejemplo n.º 11
0
        private void frmSelectSpell_Load(object sender, EventArgs e)
        {
            // If a value is forced, set the name of the spell and accept the form.
            if (!string.IsNullOrEmpty(_strForceSpell))
            {
                _strSelectedSpell = _strForceSpell;
                DialogResult      = DialogResult.OK;
            }

            foreach (Label objLabel in Controls.OfType <Label>())
            {
                if (objLabel.Text.StartsWith("["))
                {
                    objLabel.Text = string.Empty;
                }
            }

            //Free Spells (typically from Dedicated Spellslinger or custom Improvements) are only handled manually
            //in Career Mode. Create mode manages itself.
            int intFreeGenericSpells   = ImprovementManager.ValueOf(_objCharacter, Improvement.ImprovementType.FreeSpells);
            int intFreeTouchOnlySpells = 0;

            foreach (Improvement imp in _objCharacter.Improvements.Where(i => i.ImproveType == Improvement.ImprovementType.FreeSpellsATT))
            {
                int intAttValue = _objCharacter.GetAttribute(imp.ImprovedName).TotalValue;
                if (imp.UniqueName.Contains("half"))
                {
                    intAttValue = (intAttValue + 1) / 2;
                }
                if (imp.UniqueName.Contains("touchonly"))
                {
                    intFreeTouchOnlySpells += intAttValue;
                }
                else
                {
                    intFreeGenericSpells += intAttValue;
                }
            }
            foreach (Improvement imp in _objCharacter.Improvements.Where(i => i.ImproveType == Improvement.ImprovementType.FreeSpellsSkill))
            {
                int intSkillValue = _objCharacter.SkillsSection.Skills.First(x => x.Name == imp.ImprovedName).TotalBaseRating;
                if (imp.UniqueName.Contains("half"))
                {
                    intSkillValue = (intSkillValue + 1) / 2;
                }
                if (imp.UniqueName.Contains("touchonly"))
                {
                    intFreeTouchOnlySpells += intSkillValue;
                }
                else
                {
                    intFreeGenericSpells += intSkillValue;
                }
            }
            int intTotalFreeNonTouchSpellsCount  = _objCharacter.Spells.Count(spell => spell.FreeBonus && spell.Range != "T");
            int intTotalFreeTouchOnlySpellsCount = _objCharacter.Spells.Count(spell => spell.FreeBonus && spell.Range == "T");

            if (intFreeTouchOnlySpells > intTotalFreeTouchOnlySpellsCount)
            {
                _blnCanTouchOnlySpellBeFree = true;
            }
            if (intFreeGenericSpells > intTotalFreeNonTouchSpellsCount + Math.Max(intTotalFreeTouchOnlySpellsCount - intFreeTouchOnlySpells, 0))
            {
                _blnCanGenericSpellBeFree = true;
            }

            // Load the Spells information.
            _objXmlDocument = XmlManager.Instance.Load("spells.xml");

            // Populate the Category list.
            XmlNodeList      objXmlNodeList = _objXmlDocument.SelectNodes("/chummer/categories/category");
            HashSet <string> limit          = new HashSet <string>();

            foreach (Improvement improvement in _objCharacter.Improvements.Where(improvement => improvement.ImproveType == Improvement.ImprovementType.LimitSpellCategory))
            {
                limit.Add(improvement.ImprovedName);
            }
            foreach (XmlNode objXmlCategory in objXmlNodeList)
            {
                if ((limit.Count <= 0 || !limit.Contains(objXmlCategory.InnerText)) && limit.Count != 0)
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(_strLimitCategory) && _strLimitCategory != objXmlCategory.InnerText)
                {
                    continue;
                }
                TreeNode nodCategory = new TreeNode();
                nodCategory.Tag  = objXmlCategory.InnerText;
                nodCategory.Text = objXmlCategory.Attributes?["translate"]?.InnerText ?? objXmlCategory.InnerText;

                treSpells.Nodes.Add(nodCategory);
            }

            // Don't show the Extended Spell checkbox if the option to Extend any Detection Spell is diabled.
            chkExtended.Visible = _objCharacter.Options.ExtendAnyDetectionSpell;
            string strAdditionalFilter = string.Empty;

            if (_objCharacter.Options.ExtendAnyDetectionSpell)
            {
                strAdditionalFilter = "not(contains(name, \", Extended\"))";
            }

            // Populate the Spell list.
            if (!string.IsNullOrEmpty(_strLimitCategory))
            {
                objXmlNodeList = _objXmlDocument.SelectNodes("/chummer/spells/spell[category = \"" + _strLimitCategory + "\" and " + strAdditionalFilter + " and (" + _objCharacter.Options.BookXPath() + ")]");
            }
            else if (string.IsNullOrEmpty(strAdditionalFilter))
            {
                objXmlNodeList = _objXmlDocument.SelectNodes("/chummer/spells/spell[" + _objCharacter.Options.BookXPath() + "]");
            }
            else
            {
                objXmlNodeList = _objXmlDocument.SelectNodes("/chummer/spells/spell[" + strAdditionalFilter + " and (" + _objCharacter.Options.BookXPath() + ")]");
            }

            treSpells.TreeViewNodeSorter = new SortByName();
            treSpells.SelectedNode       = treSpells.Nodes[0];
            foreach (XmlNode objXmlSpell in objXmlNodeList)
            {
                TreeNode nodSpell   = new TreeNode();
                TreeNode nodParent  = new TreeNode();
                bool     blnInclude = false;

                if (_blnIgnoreRequirements)
                {
                    blnInclude = true;
                }
                else if (_objCharacter.AdeptEnabled && !_objCharacter.MagicianEnabled)
                {
                    blnInclude = (objXmlSpell["category"].InnerText == "Rituals" && !objXmlSpell["descriptor"].InnerText.Contains("Spell")) ||
                                 (_blnCanTouchOnlySpellBeFree && objXmlSpell["range"].InnerText == "T");
                }
                else if (!_objCharacter.AdeptEnabled)
                {
                    blnInclude = !objXmlSpell["descriptor"].InnerText.Contains("Adept");
                }
                else
                {
                    blnInclude = true;
                }

                if (blnInclude)
                {
                    blnInclude = SelectionShared.RequirementsMet(objXmlSpell, false, _objCharacter);
                }

                if (!blnInclude)
                {
                    continue;
                }
                nodSpell.Text = objXmlSpell["translate"]?.InnerText ?? objXmlSpell["name"].InnerText;
                nodSpell.Tag  = objXmlSpell["id"].InnerText;
                // Check to see if there is already a Category node for the Spell's category.
                foreach (TreeNode nodCategory in treSpells.Nodes)
                {
                    if (nodCategory.Level == 0 && nodCategory.Tag.ToString() == objXmlSpell["category"].InnerText)
                    {
                        nodParent = nodCategory;
                    }
                }

                // Add the Spell to the Category node.
                nodParent.Nodes.Add(nodSpell);

                if (!string.IsNullOrEmpty(_strLimitCategory))
                {
                    nodParent.Expand();
                }
            }

            if (_lstExpandCategories != null)
            {
                foreach (TreeNode objExpandedNode in _lstExpandCategories)
                {
                    foreach (TreeNode objNode in treSpells.Nodes)
                    {
                        if (objNode.Text == objExpandedNode.Text)
                        {
                            objNode.Expand();
                        }
                    }
                }
            }

            txtSearch.Enabled = string.IsNullOrEmpty(_strLimitCategory);

            if (!_objCharacter.Created)
            {
                return;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Build the list of Qualities.
        /// </summary>
        private void BuildQualityList()
        {
            if (_blnLoading)
            {
                return;
            }

            string strCategory = cboCategory.SelectedValue?.ToString();
            string strFilter   = "(" + _objCharacter.Options.BookXPath() + ")";

            if (!string.IsNullOrEmpty(strCategory) && strCategory != "Show All" && (_objCharacter.Options.SearchInCategoryOnly || txtSearch.TextLength == 0))
            {
                strFilter += " and category = \"" + strCategory + "\"";
            }
            else
            {
                StringBuilder objCategoryFilter = new StringBuilder();
                foreach (string strItem in _lstCategory.Select(x => x.Value))
                {
                    if (!string.IsNullOrEmpty(strItem))
                    {
                        objCategoryFilter.Append("category = \"" + strItem + "\" or ");
                    }
                }
                if (objCategoryFilter.Length > 0)
                {
                    strFilter += " and (" + objCategoryFilter.ToString().TrimEnd(" or ") + ")";
                }
            }
            if (!string.IsNullOrWhiteSpace(txtSearch.Text))
            {
                // Treat everything as being uppercase so the search is case-insensitive.
                string strSearchText = txtSearch.Text.ToUpper();
                strFilter += " and ((contains(translate(name,'abcdefghijklmnopqrstuvwxyzàáâãäåçèéêëìíîïñòóôõöùúûüýß','ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß'), \"" + strSearchText + "\") and not(translate)) or contains(translate(translate,'abcdefghijklmnopqrstuvwxyzàáâãäåçèéêëìíîïñòóôõöùúûüýß','ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß'), \"" + strSearchText + "\"))";
            }
            if (chkMetagenetic.Checked)
            {
                strFilter += " and (metagenetic = 'yes' or required/oneof[contains(., 'Changeling')])";
            }
            else if (chkNotMetagenetic.Checked)
            {
                strFilter += " and not(metagenetic = 'yes') and not(required/oneof[contains(., 'Changeling')])";
            }
            if (nudValueBP.Value != 0)
            {
                strFilter += "and karma = " + nudValueBP.Value;
            }
            else
            {
                if (nudMinimumBP.Value != 0)
                {
                    strFilter += "and karma >= " + nudMinimumBP.Value;
                }

                if (nudMaximumBP.Value != 0)
                {
                    strFilter += "and karma <= " + nudMaximumBP.Value;
                }
            }

            XmlDocument objXmlMetatypeDocument  = XmlManager.Load("metatypes.xml");
            XmlDocument objXmlCrittersDocument  = XmlManager.Load("critters.xml");
            bool        blnNeedQualityWhitelist = false;
            XmlNode     objXmlMetatype          = objXmlMetatypeDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]");

            if (objXmlMetatype?.SelectSingleNode("qualityrestriction") != null)
            {
                blnNeedQualityWhitelist = true;
            }
            else
            {
                objXmlMetatype = objXmlCrittersDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]");
                if (objXmlMetatype?.SelectSingleNode("qualityrestriction") != null)
                {
                    blnNeedQualityWhitelist = true;
                }
            }

            XmlNodeList objXmlQualityList = _objXmlDocument.SelectNodes("/chummer/qualities/quality[" + strFilter + "]");

            List <ListItem> lstQuality = new List <ListItem>();

            foreach (XmlNode objXmlQuality in objXmlQualityList)
            {
                if (objXmlQuality["name"] == null)
                {
                    continue;
                }
                if (blnNeedQualityWhitelist)
                {
                    if (strCategory == "Show All")
                    {
                        bool blnAllowed = false;
                        foreach (ListItem objCategory in _lstCategory)
                        {
                            if (objXmlMetatype.SelectSingleNode("qualityrestriction/*/quality[. = \"" + objXmlQuality["name"].InnerText + "\"]") != null)
                            {
                                blnAllowed = true;
                                break;
                            }
                        }
                        if (!blnAllowed)
                        {
                            continue;
                        }
                    }
                    else if (objXmlMetatype.SelectSingleNode("qualityrestriction/" + strCategory.ToLower() + "/quality[. = \"" + objXmlQuality["name"].InnerText + "\"]") == null)
                    {
                        continue;
                    }
                }
                if (!chkLimitList.Checked || SelectionShared.RequirementsMet(objXmlQuality, false, _objCharacter, objXmlMetatypeDocument, objXmlCrittersDocument, _objXmlDocument, IgnoreQuality))
                {
                    ListItem objItem = new ListItem();
                    objItem.Value = objXmlQuality["name"].InnerText;
                    objItem.Name  = objXmlQuality["translate"]?.InnerText ?? objItem.Value;

                    lstQuality.Add(objItem);
                }
            }
            SortListItem objSort = new SortListItem();

            lstQuality.Sort(objSort.Compare);
            lstQualities.BeginUpdate();
            lstQualities.DataSource    = null;
            lstQualities.ValueMember   = "Value";
            lstQualities.DisplayMember = "Name";
            lstQualities.DataSource    = lstQuality;
            lstQualities.EndUpdate();
        }
Ejemplo n.º 13
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;
                }
            }
        }
Ejemplo n.º 14
0
        private void lstArmor_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            XmlNode xmlArmor      = null;
            string  strSelectedId = lstArmor.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                xmlArmor = _objXmlDocument.SelectSingleNode("/chummer/armors/armor[id = " + strSelectedId.CleanXPath() + ']');
            }
            if (xmlArmor != null)
            {
                // Create the Armor so we can show its Total Avail (some Armor includes Chemical Seal which adds +6 which wouldn't be factored in properly otherwise).
                Armor         objArmor   = new Armor(_objCharacter);
                List <Weapon> lstWeapons = new List <Weapon>(1);
                objArmor.Create(xmlArmor, 0, lstWeapons, true, true, true);

                _objSelectedArmor?.Dispose();
                _objSelectedArmor = objArmor;

                int intRating = 0;
                if (xmlArmor.TryGetInt32FieldQuickly("rating", ref intRating))
                {
                    nudRating.Maximum = intRating;
                    if (chkHideOverAvailLimit.Checked)
                    {
                        while (nudRating.Maximum > 1 && !SelectionShared.CheckAvailRestriction(xmlArmor, _objCharacter, nudRating.MaximumAsInt))
                        {
                            --nudRating.Maximum;
                        }
                    }

                    if (chkShowOnlyAffordItems.Checked && !chkFreeItem.Checked)
                    {
                        decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                        if (_setBlackMarketMaps.Contains(xmlArmor.SelectSingleNode("category")?.Value))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        while (nudRating.Maximum > 1 && !SelectionShared.CheckNuyenRestriction(xmlArmor, _objCharacter.Nuyen, decCostMultiplier, nudRating.MaximumAsInt))
                        {
                            --nudRating.Maximum;
                        }
                    }
                    lblRatingLabel.Visible   = true;
                    nudRating.Minimum        = 1;
                    nudRating.Value          = 1;
                    nudRating.Enabled        = nudRating.Minimum != nudRating.Maximum;
                    nudRating.Visible        = true;
                    lblRatingNALabel.Visible = false;
                }
                else
                {
                    lblRatingLabel.Visible   = true;
                    lblRatingNALabel.Visible = true;
                    nudRating.Minimum        = 0;
                    nudRating.Maximum        = 0;
                    nudRating.Value          = 0;
                    nudRating.Enabled        = false;
                    nudRating.Visible        = false;
                }

                string strRatingLabel = xmlArmor.SelectSingleNode("ratinglabel")?.Value;
                lblRatingLabel.Text = !string.IsNullOrEmpty(strRatingLabel)
                    ? string.Format(GlobalSettings.CultureInfo, LanguageManager.GetString("Label_RatingFormat"),
                                    LanguageManager.GetString(strRatingLabel))
                    : LanguageManager.GetString("Label_Rating");
            }
            else
            {
                _objSelectedArmor?.Dispose();
                _objSelectedArmor        = null;
                lblRatingLabel.Visible   = false;
                lblRatingNALabel.Visible = false;
                nudRating.Visible        = false;
                nudRating.Enabled        = false;
                nudRating.Minimum        = 0;
                nudRating.Value          = 0;
            }

            UpdateArmorInfo();
        }
Ejemplo n.º 15
0
        private void BuildPowerList()
        {
            string strFilter = "(" + _objCharacter.Options.BookXPath() + ")";

            if (!string.IsNullOrEmpty(_strLimitToPowers))
            {
                StringBuilder objFilter = new StringBuilder();
                foreach (string strPower in _strLimitToPowers.Split(','))
                {
                    if (!string.IsNullOrEmpty(strPower))
                    {
                        objFilter.Append("name = \"" + strPower.Trim() + "\" or ");
                    }
                }
                if (objFilter.Length > 0)
                {
                    strFilter += " and (" + objFilter.ToString().TrimEnd(" or ") + ")";
                }
            }
            if (txtSearch.TextLength != 0)
            {
                // Treat everything as being uppercase so the search is case-insensitive.
                string strSearchText = txtSearch.Text.ToUpper();
                strFilter += " and ((contains(translate(name,'abcdefghijklmnopqrstuvwxyzàáâãäåçèéêëìíîïñòóôõöùúûüýß','ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß'), \"" + strSearchText + "\") and not(translate)) or contains(translate(translate,'abcdefghijklmnopqrstuvwxyzàáâãäåçèéêëìíîïñòóôõöùúûüýß','ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß'), \"" + strSearchText + "\"))";
            }

            XmlNodeList     objXmlPowerList = _objXmlDocument.SelectNodes("/chummer/powers/power[" + strFilter + "]");
            List <ListItem> lstPower        = new List <ListItem>();

            foreach (XmlNode objXmlPower in objXmlPowerList)
            {
                decimal decPoints = Convert.ToDecimal(objXmlPower["points"].InnerText, GlobalOptions.InvariantCultureInfo);
                if (objXmlPower["extrapointcost"]?.InnerText != null)
                {
                    //If this power has already had its rating paid for with PP, we don't care about the extrapoints cost.
                    if (!_objCharacter.Powers.Any(power => power.Name == objXmlPower["name"].InnerText && power.TotalRating > 0))
                    {
                        decPoints += Convert.ToDecimal(objXmlPower["extrapointcost"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                    }
                }
                if (_decLimitToRating > 0 && decPoints > _decLimitToRating)
                {
                    continue;
                }

                if (!SelectionShared.RequirementsMet(objXmlPower, false, _objCharacter, null, null, _objXmlDocument, string.Empty, string.Empty, string.Empty, string.Empty, IgnoreLimits))
                {
                    continue;
                }

                string strName = objXmlPower["name"].InnerText;
                lstPower.Add(new ListItem(strName, objXmlPower["translate"]?.InnerText ?? strName));
            }
            SortListItem objSort = new SortListItem();

            lstPower.Sort(objSort.Compare);
            lstPowers.BeginUpdate();
            lstPowers.DataSource    = null;
            lstPowers.ValueMember   = "Value";
            lstPowers.DisplayMember = "Name";
            lstPowers.DataSource    = lstPower;
            lstPowers.EndUpdate();
        }
Ejemplo n.º 16
0
        private void frmSelectPower_Load(object sender, EventArgs e)
        {
            foreach (Label objLabel in Controls.OfType <Label>())
            {
                if (objLabel.Text.StartsWith('['))
                {
                    objLabel.Text = string.Empty;
                }
            }

            List <ListItem> lstPower = new List <ListItem>();

            // Populate the Powers list.
            string strFilter = string.Empty;

            if (!string.IsNullOrEmpty(_strLimitToPowers))
            {
                strFilter = "(";
                string[] strValue = _strLimitToPowers.Split(',');
                foreach (string strPower in strValue)
                {
                    strFilter += "name = \"" + strPower.Trim() + "\" or ";
                }
                // Remove the trailing " or ".
                strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                strFilter += ") and ";
            }
            XmlNodeList objXmlPowerList = _objXmlDocument.SelectNodes("/chummer/powers/power[" + strFilter + "(" + _objCharacter.Options.BookXPath() + ")]");

            foreach (XmlNode objXmlPower in objXmlPowerList)
            {
                decimal decPoints = Convert.ToDecimal(objXmlPower["points"].InnerText, GlobalOptions.InvariantCultureInfo);
                if (objXmlPower["extrapointcost"]?.InnerText != null)
                {
                    //If this power has already had its rating paid for with PP, we don't care about the extrapoints cost.
                    if (!_objCharacter.Powers.Any(power => power.Name == objXmlPower["name"].InnerText && power.TotalRating > 0))
                    {
                        decPoints += Convert.ToDecimal(objXmlPower["extrapointcost"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                    }
                }
                if (_decLimitToRating > 0 && decPoints > _decLimitToRating)
                {
                    continue;
                }

                if (!SelectionShared.RequirementsMet(objXmlPower, false, _objCharacter, null, null, _objXmlDocument, string.Empty, string.Empty, string.Empty, string.Empty, IgnoreLimits))
                {
                    continue;
                }

                ListItem objItem = new ListItem();
                objItem.Value = objXmlPower["name"].InnerText;
                objItem.Name  = objXmlPower["translate"]?.InnerText ?? objItem.Value;
                lstPower.Add(objItem);
            }
            SortListItem objSort = new SortListItem();

            lstPower.Sort(objSort.Compare);
            lstPowers.BeginUpdate();
            lstPowers.DataSource    = null;
            lstPowers.ValueMember   = "Value";
            lstPowers.DisplayMember = "Name";
            lstPowers.DataSource    = lstPower;
            lstPowers.EndUpdate();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Build the list of Qualities.
        /// </summary>
        private void BuildQualityList()
        {
            if (_blnLoading)
            {
                return;
            }
            List <ListItem> lstQuality             = new List <ListItem>();
            XmlDocument     objXmlMetatypeDocument = XmlManager.Instance.Load("metatypes.xml");
            XmlDocument     objXmlCrittersDocument = XmlManager.Instance.Load("critters.xml");

            if (!string.IsNullOrEmpty(txtSearch.Text.Trim()))
            {
                // Treat everything as being uppercase so the search is case-insensitive.
                string strSearch = "/chummer/qualities/quality[(" + _objCharacter.Options.BookXPath() + ") and ((contains(translate(name,'abcdefghijklmnopqrstuvwxyzàáâãäåçèéêëìíîïñòóôõöùúûüýß','ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß'), \"" + txtSearch.Text.ToUpper() + "\") and not(translate)) or contains(translate(translate,'abcdefghijklmnopqrstuvwxyzàáâãäåçèéêëìíîïñòóôõöùúûüýß','ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß'), \"" + txtSearch.Text.ToUpper() + "\"))";
                if (chkMetagenetic.Checked)
                {
                    strSearch += " and (required/oneof[contains(., 'Changeling (Class I SURGE)')] or metagenetic = 'yes')";
                }
                else if (chkNotMetagenetic.Checked)
                {
                    strSearch += " and not (metagenetic = 'yes')";
                }
                if (nudMinimumBP.Value != 0)
                {
                    strSearch += "and karma => " + nudMinimumBP.Value;
                }
                strSearch += "]";

                bool    blnNeedQualityWhitelist = false;
                XmlNode objXmlMetatype          = objXmlMetatypeDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]");
                if (objXmlMetatype?.SelectNodes("qualityrestriction")?.Count > 0)
                {
                    blnNeedQualityWhitelist = true;
                }
                else
                {
                    objXmlMetatype = objXmlCrittersDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]");
                    if (objXmlMetatype?.SelectNodes("qualityrestriction")?.Count > 0)
                    {
                        blnNeedQualityWhitelist = true;
                    }
                }

                XmlNodeList objXmlQualityList;
                try
                {
                    objXmlQualityList = _objXmlDocument.SelectNodes(strSearch);
                }
                catch (XPathException)
                {
                    return;
                }

                foreach (XmlNode objXmlQuality in objXmlQualityList)
                {
                    bool blnQualityAllowed = !blnNeedQualityWhitelist;
                    if (blnNeedQualityWhitelist)
                    {
                        if (objXmlQuality["name"] != null && (
                                objXmlMetatype.SelectSingleNode("qualityrestriction/positive/quality[. = \"" +
                                                                objXmlQuality["name"].InnerText + "\"]") != null ||
                                objXmlMetatype.SelectSingleNode("qualityrestriction/negative/quality[. = \"" +
                                                                objXmlQuality["name"].InnerText + "\"]") != null))
                        {
                            blnQualityAllowed = true;
                        }
                    }

                    if (objXmlQuality["hide"] == null && blnQualityAllowed)
                    {
                        if (!chkLimitList.Checked || chkLimitList.Checked && SelectionShared.RequirementsMet(objXmlQuality, false, _objCharacter, objXmlMetatypeDocument, objXmlCrittersDocument, _objXmlDocument, IgnoreQuality, LanguageManager.Instance.GetString("String_Quality")))
                        {
                            ListItem objItem = new ListItem();
                            objItem.Value = objXmlQuality["name"]?.InnerText;
                            objItem.Name  = objXmlQuality["translate"]?.InnerText ?? objItem.Value;

                            if (objXmlQuality["category"] != null)
                            {
                                ListItem objFoundItem = _lstCategory.Find(objFind => objFind.Value == objXmlQuality["category"].InnerText);
                                if (objFoundItem != null)
                                {
                                    objItem.Name += " [" + objFoundItem.Name + "]";
                                }
                            }

                            lstQuality.Add(objItem);
                        }
                    }
                }
            }
            else
            {
                string strXPath = "category = \"" + cboCategory.SelectedValue + "\" and (" + _objCharacter.Options.BookXPath() + ")";
                if (chkMetagenetic.Checked)
                {
                    strXPath += " and (required/oneof[contains(., 'Changeling (Class I SURGE)')] or metagenetic = 'yes')";
                }
                else if (!chkNotMetagenetic.Checked && (cboCategory.SelectedValue.ToString() == "Negative" || _objCharacter.MetageneticLimit > 0))
                {
                    //Load everything, including metagenetic qualities.
                }
                else
                {
                    strXPath += " and not (required/oneof[contains(., 'Changeling (Class I SURGE)')] or metagenetic = 'yes')";
                }
                if (nudValueBP.Value != 0)
                {
                    strXPath += "and karma = " + nudValueBP.Value;
                }
                else
                {
                    if (nudMinimumBP.Value != 0)
                    {
                        strXPath += "and karma >= " + nudMinimumBP.Value;
                    }

                    if (nudMaximumBP.Value != 0)
                    {
                        strXPath += "and karma <= " + nudMaximumBP.Value;
                    }
                }

                bool    blnNeedQualityWhitelist = false;
                XmlNode objXmlMetatype          = objXmlMetatypeDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]");
                if (objXmlMetatype?.SelectNodes("qualityrestriction")?.Count > 0)
                {
                    blnNeedQualityWhitelist = true;
                }
                else
                {
                    objXmlMetatype = objXmlCrittersDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]");
                    if (objXmlMetatype?.SelectNodes("qualityrestriction")?.Count > 0)
                    {
                        blnNeedQualityWhitelist = true;
                    }
                }

                foreach (XmlNode objXmlQuality in _objXmlDocument.SelectNodes("/chummer/qualities/quality[" + strXPath + "]"))
                {
                    if (objXmlQuality["name"] == null)
                    {
                        continue;
                    }
                    if (objXmlQuality["name"].InnerText.StartsWith("Infected"))
                    {
                        //There was something I was going to do with this, but I can't remember what it was.
                    }
                    bool blnQualityAllowed = !blnNeedQualityWhitelist;
                    if (blnNeedQualityWhitelist)
                    {
                        if (objXmlMetatype.SelectSingleNode("qualityrestriction/" + cboCategory.SelectedValue.ToString().ToLower() + "/quality[. = \"" + objXmlQuality["name"].InnerText + "\"]") != null)
                        {
                            blnQualityAllowed = true;
                        }
                    }
                    if (blnQualityAllowed)
                    {
                        if (!chkLimitList.Checked || chkLimitList.Checked && SelectionShared.RequirementsMet(objXmlQuality, false, _objCharacter, objXmlMetatypeDocument, objXmlCrittersDocument, _objXmlDocument, IgnoreQuality, LanguageManager.Instance.GetString("String_Quality")))
                        {
                            if (objXmlQuality["hide"] == null)
                            {
                                ListItem objItem = new ListItem();
                                objItem.Value = objXmlQuality["name"].InnerText;
                                objItem.Name  = objXmlQuality["translate"]?.InnerText ?? objXmlQuality["name"].InnerText;

                                lstQuality.Add(objItem);
                            }
                        }
                    }
                }
            }
            SortListItem objSort = new SortListItem();

            lstQuality.Sort(objSort.Compare);
            lstQualities.BeginUpdate();
            lstQualities.DataSource    = null;
            lstQualities.ValueMember   = "Value";
            lstQualities.DisplayMember = "Name";
            lstQualities.DataSource    = lstQuality;
            lstQualities.EndUpdate();
        }
Ejemplo n.º 18
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);
        }
        /// <summary>
        /// Build the list of available weapon accessories.
        /// </summary>
        private void BuildAccessoryList()
        {
            List <ListItem> lstAccessories = new List <ListItem>();

            // Populate the Accessory list.
            StringBuilder strMount = new StringBuilder("contains(mount, \"Internal\") or contains(mount, \"None\") or mount = \"\"");

            foreach (string strAllowedMount in _lstAllowedMounts)
            {
                if (!string.IsNullOrEmpty(strAllowedMount))
                {
                    strMount.Append(" or contains(mount, \"" + strAllowedMount + "\")");
                }
            }
            XPathNavigator xmlParentWeaponDataNode = _xmlBaseChummerNode.SelectSingleNode("weapons/weapon[id = \"" + _objParentWeapon.SourceID.ToString("D") + "\"]");

            foreach (XPathNavigator objXmlAccessory in _xmlBaseChummerNode.Select("accessories/accessory[(" + strMount + ") and (" + _objCharacter.Options.BookXPath() + ")]"))
            {
                string strId = objXmlAccessory.SelectSingleNode("id")?.Value;
                if (string.IsNullOrEmpty(strId))
                {
                    continue;
                }

                XPathNavigator xmlExtraMountNode = objXmlAccessory.SelectSingleNode("extramount");
                if (xmlExtraMountNode != null)
                {
                    if (_lstAllowedMounts.Count > 1)
                    {
                        foreach (string strItem in xmlExtraMountNode.Value.Split('/'))
                        {
                            if (!string.IsNullOrEmpty(strItem) && _lstAllowedMounts.All(strAllowedMount => strAllowedMount != strItem))
                            {
                                goto NextItem;
                            }
                        }
                    }
                }

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

                xmlTestNode = objXmlAccessory.SelectSingleNode("forbidden/oneof");
                XPathNodeIterator objXmlForbiddenList = xmlTestNode?.Select("accessory");
                if (objXmlForbiddenList?.Count > 0)
                {
                    //Add to set for O(N log M) runtime instead of O(N * M)

                    HashSet <string> objForbiddenAccessory = new HashSet <string>();
                    foreach (XPathNavigator node in objXmlForbiddenList)
                    {
                        objForbiddenAccessory.Add(node.Value);
                    }

                    if (_objParentWeapon.WeaponAccessories.Any(objAccessory =>
                                                               objForbiddenAccessory.Contains(objAccessory.Name)))
                    {
                        continue;
                    }
                }

                xmlTestNode = objXmlAccessory.SelectSingleNode("required/oneof");
                if (xmlTestNode != null)
                {
                    XPathNodeIterator objXmlRequiredList = xmlTestNode.Select("accessory");
                    if (objXmlRequiredList.Count > 0)
                    {
                        //Add to set for O(N log M) runtime instead of O(N * M)

                        HashSet <string> objRequiredAccessory = new HashSet <string>();
                        foreach (XPathNavigator node in objXmlRequiredList)
                        {
                            objRequiredAccessory.Add(node.Value);
                        }

                        if (!_objParentWeapon.WeaponAccessories.Any(objAccessory =>
                                                                    objRequiredAccessory.Contains(objAccessory.Name)))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                if (!chkHideOverAvailLimit.Checked || SelectionShared.CheckAvailRestriction(objXmlAccessory, _objCharacter))
                {
                    lstAccessories.Add(new ListItem(strId, objXmlAccessory.SelectSingleNode("translate")?.Value ?? objXmlAccessory.SelectSingleNode("name")?.Value ?? LanguageManager.GetString("String_Unknown", GlobalOptions.Language)));
                }
                NextItem :;
            }

            lstAccessories.Sort(CompareListItems.CompareNames);
            string strOldSelected = lstAccessory.SelectedValue?.ToString();

            _blnLoading = true;
            lstAccessory.BeginUpdate();
            lstAccessory.ValueMember   = "Value";
            lstAccessory.DisplayMember = "Name";
            lstAccessory.DataSource    = lstAccessories;
            _blnLoading = false;
            if (!string.IsNullOrEmpty(strOldSelected))
            {
                lstAccessory.SelectedValue = strOldSelected;
            }
            else
            {
                lstAccessory.SelectedIndex = -1;
            }
            lstAccessory.EndUpdate();
        }
Ejemplo n.º 20
0
        private void frmSelectSpell_Load(object sender, EventArgs e)
        {
            // If a value is forced, set the name of the spell and accept the form.
            if (!string.IsNullOrEmpty(_strForceSpell))
            {
                _strSelectedSpell = _strForceSpell;
                DialogResult      = DialogResult.OK;
            }

            foreach (Label objLabel in Controls.OfType <Label>())
            {
                if (objLabel.Text.StartsWith("["))
                {
                    objLabel.Text = string.Empty;
                }
            }

            // Load the Spells information.
            _objXmlDocument = XmlManager.Instance.Load("spells.xml");

            // Populate the Category list.
            XmlNodeList      objXmlNodeList = _objXmlDocument.SelectNodes("/chummer/categories/category");
            HashSet <string> limit          = new HashSet <string>();

            foreach (Improvement improvement in _objCharacter.Improvements.Where(improvement => improvement.ImproveType == Improvement.ImprovementType.LimitSpellCategory))
            {
                limit.Add(improvement.ImprovedName);
            }
            foreach (XmlNode objXmlCategory in objXmlNodeList)
            {
                if ((limit.Count <= 0 || !limit.Contains(objXmlCategory.InnerText)) && limit.Count != 0)
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(_strLimitCategory) && _strLimitCategory != objXmlCategory.InnerText)
                {
                    continue;
                }
                TreeNode nodCategory = new TreeNode();
                nodCategory.Tag  = objXmlCategory.InnerText;
                nodCategory.Text = objXmlCategory.Attributes["translate"]?.InnerText ?? objXmlCategory.InnerText;

                treSpells.Nodes.Add(nodCategory);
            }

            // Don't show the Extended Spell checkbox if the option to Extend any Detection Spell is diabled.
            chkExtended.Visible = _objCharacter.Options.ExtendAnyDetectionSpell;
            string strAdditionalFilter = string.Empty;

            if (_objCharacter.Options.ExtendAnyDetectionSpell)
            {
                strAdditionalFilter = "not(contains(name, \", Extended\"))";
            }

            // Populate the Spell list.
            if (!string.IsNullOrEmpty(_strLimitCategory))
            {
                objXmlNodeList = _objXmlDocument.SelectNodes("/chummer/spells/spell[category = \"" + _strLimitCategory + "\" and " + strAdditionalFilter + " and (" + _objCharacter.Options.BookXPath() + ")]");
            }
            else if (string.IsNullOrEmpty(strAdditionalFilter))
            {
                objXmlNodeList = _objXmlDocument.SelectNodes("/chummer/spells/spell[" + _objCharacter.Options.BookXPath() + "]");
            }
            else
            {
                objXmlNodeList = _objXmlDocument.SelectNodes("/chummer/spells/spell[" + strAdditionalFilter + " and (" + _objCharacter.Options.BookXPath() + ")]");
            }

            treSpells.TreeViewNodeSorter = new SortByName();
            treSpells.SelectedNode       = treSpells.Nodes[0];
            foreach (XmlNode objXmlSpell in objXmlNodeList)
            {
                TreeNode nodSpell   = new TreeNode();
                TreeNode nodParent  = new TreeNode();
                bool     blnInclude = false;

                if (_blnIgnoreRequirements)
                {
                    blnInclude = true;
                }
                else if (_objCharacter.AdeptEnabled && !_objCharacter.MagicianEnabled)
                {
                    if (objXmlSpell["category"].InnerText != "Rituals")
                    {
                        blnInclude = false;
                    }
                    else if (objXmlSpell["descriptor"].InnerText.Contains("Spell"))
                    {
                        blnInclude = false;
                    }
                    else
                    {
                        blnInclude = true;
                    }
                }
                else if (!_objCharacter.AdeptEnabled)
                {
                    blnInclude = !objXmlSpell["descriptor"].InnerText.Contains("Adept");
                }
                else
                {
                    blnInclude = true;
                }

                if (blnInclude)
                {
                    blnInclude = SelectionShared.RequirementsMet(objXmlSpell, false, _objCharacter);
                }

                if (blnInclude)
                {
                    nodSpell.Text = objXmlSpell["translate"]?.InnerText ?? objXmlSpell["name"].InnerText;
                    nodSpell.Tag  = objXmlSpell["name"].InnerText;
                    // Check to see if there is already a Category node for the Spell's category.
                    foreach (TreeNode nodCategory in treSpells.Nodes)
                    {
                        if (nodCategory.Level == 0 && nodCategory.Tag.ToString() == objXmlSpell["category"].InnerText)
                        {
                            nodParent = nodCategory;
                        }
                    }

                    // Add the Spell to the Category node.
                    nodParent.Nodes.Add(nodSpell);

                    if (!string.IsNullOrEmpty(_strLimitCategory))
                    {
                        nodParent.Expand();
                    }
                }
            }

            if (_lstExpandCategories != null)
            {
                foreach (TreeNode objExpandedNode in _lstExpandCategories)
                {
                    foreach (TreeNode objNode in treSpells.Nodes)
                    {
                        if (objNode.Text == objExpandedNode.Text)
                        {
                            objNode.Expand();
                        }
                    }
                }
            }

            txtSearch.Enabled = string.IsNullOrEmpty(_strLimitCategory);

            int freeSpells = _objCharacter.ObjImprovementManager.ValueOf(Improvement.ImprovementType.FreeSpells)
                             + _objCharacter.Improvements.Where(i => i.ImproveType == Improvement.ImprovementType.FreeSpellsATT)
                             .Select(imp => _objCharacter.GetAttribute(imp.UniqueName)).Select(att => att.TotalValue).Sum()
                             + _objCharacter.Improvements.Where(i => i.ImproveType == Improvement.ImprovementType.FreeSpellsSkill)
                             .Select(imp => _objCharacter.SkillsSection.Skills.First(x => x.Name == imp.UniqueName)).Select(objSkill => objSkill.LearnedRating).Sum();

            chkFreeBonus.Visible = freeSpells > 0 && freeSpells > _objCharacter.Spells.Count(spell => spell.FreeBonus);
        }
Ejemplo n.º 21
0
        private void lstArmor_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            XmlNode xmlArmor      = null;
            string  strSelectedId = lstArmor.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                xmlArmor = _objXmlDocument.SelectSingleNode("/chummer/armors/armor[id = \"" + strSelectedId + "\"]");
            }
            if (xmlArmor != null)
            {
                // Create the Armor so we can show its Total Avail (some Armor includes Chemical Seal which adds +6 which wouldn't be factored in properly otherwise).
                Armor         objArmor   = new Armor(_objCharacter);
                List <Weapon> lstWeapons = new List <Weapon>();
                objArmor.Create(xmlArmor, 0, lstWeapons, true, true, true);

                _objSelectedArmor = objArmor;

                string strRating = xmlArmor["rating"]?.InnerText;
                if (!string.IsNullOrEmpty(strRating))
                {
                    nudRating.Maximum = Convert.ToInt32(strRating);
                    if (chkHideOverAvailLimit.Checked)
                    {
                        while (nudRating.Maximum > 1 && !SelectionShared.CheckAvailRestriction(xmlArmor, _objCharacter, decimal.ToInt32(nudRating.Maximum)))
                        {
                            nudRating.Maximum -= 1;
                        }
                    }
                    lblRatingLabel.Visible = true;
                    nudRating.Visible      = true;
                    nudRating.Enabled      = true;
                    nudRating.Minimum      = 1;
                    nudRating.Value        = 1;
                }
                else
                {
                    lblRatingLabel.Visible = false;
                    nudRating.Visible      = false;
                    nudRating.Enabled      = false;
                    nudRating.Minimum      = 0;
                    nudRating.Value        = 0;
                }
            }
            else
            {
                _objSelectedArmor      = null;
                lblRatingLabel.Visible = false;
                nudRating.Visible      = false;
                nudRating.Enabled      = false;
                nudRating.Minimum      = 0;
                nudRating.Value        = 0;
            }

            UpdateArmorInfo();
        }
Ejemplo n.º 22
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();
            }
        }
Ejemplo n.º 23
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();
        }
Ejemplo n.º 24
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.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.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>();
                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)))
                    {
                        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.º 25
0
        private void UpdateGearInfo()
        {
            if (_blnLoading)
            {
                return;
            }

            XmlNode xmlAccessory  = null;
            string  strSelectedId = lstAccessory.SelectedValue?.ToString();

            // Retrieve the information for the selected Accessory.
            if (!string.IsNullOrEmpty(strSelectedId))
            {
                xmlAccessory = _objXmlDocument.SelectSingleNode("/chummer/accessories/accessory[id = \"" + strSelectedId + "\"]");
            }
            if (xmlAccessory == null)
            {
                lblRC.Visible          = false;
                lblRCLabel.Visible     = false;
                nudRating.Enabled      = false;
                nudRating.Visible      = false;
                lblRatingLabel.Visible = false;
                cboMount.Visible       = false;
                cboMount.Items.Clear();
                cboExtraMount.Visible = false;
                cboExtraMount.Items.Clear();
                lblAvail.Text  = string.Empty;
                lblCost.Text   = string.Empty;
                lblTest.Text   = string.Empty;
                lblSource.Text = string.Empty;
                tipTooltip.SetToolTip(lblSource, string.Empty);
                return;
            }

            string strRC = xmlAccessory["rc"]?.InnerText;

            if (!string.IsNullOrEmpty(strRC))
            {
                lblRC.Visible      = true;
                lblRCLabel.Visible = true;
                lblRC.Text         = strRC;
            }
            else
            {
                lblRC.Visible      = false;
                lblRCLabel.Visible = false;
            }
            if (int.TryParse(xmlAccessory["rating"]?.InnerText, out int intMaxRating) && intMaxRating > 0)
            {
                nudRating.Enabled      = true;
                nudRating.Visible      = true;
                lblRatingLabel.Visible = true;
                nudRating.Maximum      = intMaxRating;
                if (chkHideOverAvailLimit.Checked)
                {
                    while (nudRating.Maximum > nudRating.Minimum && !SelectionShared.CheckAvailRestriction(xmlAccessory, _objCharacter, decimal.ToInt32(nudRating.Maximum)))
                    {
                        nudRating.Maximum -= 1;
                    }
                }
            }
            else
            {
                nudRating.Enabled      = false;
                nudRating.Visible      = false;
                lblRatingLabel.Visible = false;
            }

            string[]      astrDataMounts = xmlAccessory["mount"]?.InnerText.Split('/');
            List <string> strMounts      = new List <string>();

            if (astrDataMounts != null)
            {
                strMounts.AddRange(astrDataMounts);
            }
            strMounts.Add("None");

            List <string> strAllowed = new List <string>(_lstAllowedMounts)
            {
                "None"
            };

            cboMount.Visible = true;
            cboMount.Items.Clear();
            foreach (string strCurrentMount in strMounts)
            {
                if (!string.IsNullOrEmpty(strCurrentMount))
                {
                    foreach (string strAllowedMount in strAllowed)
                    {
                        if (strCurrentMount == strAllowedMount)
                        {
                            cboMount.Items.Add(strCurrentMount);
                        }
                    }
                }
            }
            cboMount.Enabled       = cboMount.Items.Count > 1;
            cboMount.SelectedIndex = 0;

            List <string> strExtraMounts = new List <string>();
            string        strExtraMount  = xmlAccessory["extramount"]?.InnerText;

            if (!string.IsNullOrEmpty(strExtraMount))
            {
                foreach (string strItem in strExtraMount.Split('/'))
                {
                    strExtraMounts.Add(strItem);
                }
            }
            strExtraMounts.Add("None");

            cboExtraMount.Visible = true;
            cboExtraMount.Items.Clear();
            foreach (string strCurrentMount in strExtraMounts)
            {
                if (!string.IsNullOrEmpty(strCurrentMount))
                {
                    foreach (string strAllowedMount in strAllowed)
                    {
                        if (strCurrentMount == strAllowedMount)
                        {
                            cboExtraMount.Items.Add(strCurrentMount);
                        }
                    }
                }
            }
            cboExtraMount.Enabled       = cboExtraMount.Items.Count > 1;
            cboExtraMount.SelectedIndex = 0;
            if (cboMount.SelectedItem.ToString() != "None" && cboExtraMount.SelectedItem.ToString() != "None" &&
                cboMount.SelectedItem.ToString() == cboExtraMount.SelectedItem.ToString())
            {
                cboExtraMount.SelectedIndex += 1;
            }
            // Avail.
            // If avail contains "F" or "R", remove it from the string so we can use the expression.
            string strSuffix = string.Empty;
            string strAvail  = xmlAccessory["avail"]?.InnerText;

            if (!string.IsNullOrWhiteSpace(strAvail))
            {
                char chrLastAvailChar = strAvail[strAvail.Length - 1];
                if (chrLastAvailChar == 'F')
                {
                    strSuffix = LanguageManager.GetString("String_AvailForbidden", GlobalOptions.Language);
                    strAvail  = strAvail.Substring(0, strAvail.Length - 1);
                }
                else if (chrLastAvailChar == 'R')
                {
                    strSuffix = LanguageManager.GetString("String_AvailRestricted", GlobalOptions.Language);
                    strAvail  = strAvail.Substring(0, strAvail.Length - 1);
                }
                try
                {
                    lblAvail.Text = Convert.ToInt32(CommonFunctions.EvaluateInvariantXPath(strAvail.Replace("Rating", nudRating.Value.ToString(GlobalOptions.CultureInfo)))).ToString() + strSuffix;
                }
                catch (XPathException)
                {
                    lblAvail.Text = strAvail + strSuffix;
                }
            }
            else
            {
                lblAvail.Text = string.Empty;
            }
            if (!chkFreeItem.Checked)
            {
                string strCost = "0";
                if (xmlAccessory.TryGetStringFieldQuickly("cost", ref strCost))
                {
                    strCost = strCost.CheapReplace("Weapon Cost", () => _objParentWeapon.OwnCost.ToString(GlobalOptions.InvariantCultureInfo))
                              .Replace("Rating", nudRating.Value.ToString(GlobalOptions.CultureInfo));
                }
                if (strCost.StartsWith("Variable("))
                {
                    decimal decMin;
                    decimal decMax = decimal.MaxValue;
                    strCost = strCost.TrimStart("Variable(", true).TrimEnd(')');
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decimal.TryParse(strValues[0], NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decMin);
                        decimal.TryParse(strValues[1], NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decMax);
                    }
                    else
                    {
                        decimal.TryParse(strCost.FastEscape('+'), NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decMin);
                    }

                    if (decMax == decimal.MaxValue)
                    {
                        lblCost.Text = decMin.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + "¥+";
                    }
                    else
                    {
                        lblCost.Text = decMin.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + " - " + decMax.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    }

                    lblTest.Text = _objCharacter.AvailTest(decMax, lblAvail.Text);
                }
                else
                {
                    decimal decCost = 0.0m;
                    try
                    {
                        decCost = Convert.ToDecimal(CommonFunctions.EvaluateInvariantXPath(strCost), GlobalOptions.InvariantCultureInfo);
                    }
                    catch (XPathException)
                    {
                    }

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

                    lblCost.Text = decCost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    lblTest.Text = _objCharacter.AvailTest(decCost, lblAvail.Text);
                }
            }
            else
            {
                lblCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                lblTest.Text = _objCharacter.AvailTest(0, lblAvail.Text);
            }

            /*TODO: Accessories don't use a category mapping, so this doesn't work.
             * if (_blackMarketMaps != null)
             *  chkBlackMarketDiscount.Checked =
             *      _blackMarketMaps.Contains(objXmlAccessory["category"]?.InnerText);
             */
            string strSource = xmlAccessory["source"].InnerText;
            string strPage   = xmlAccessory["altpage"]?.InnerText ?? xmlAccessory["page"].InnerText;

            lblSource.Text = CommonFunctions.LanguageBookShort(strSource, GlobalOptions.Language) + ' ' + strPage;

            tipTooltip.SetToolTip(lblSource, CommonFunctions.LanguageBookLong(strSource, GlobalOptions.Language) + ' ' + LanguageManager.GetString("String_Page", GlobalOptions.Language) + ' ' + strPage);
        }