private async void lstMetamagic_SelectedIndexChanged(object sender, EventArgs e) { if (_blnLoading) { return; } string strSelectedId = await lstMetamagic.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()); if (!string.IsNullOrEmpty(strSelectedId)) { // Retrieve the information for the selected metamagic/echo. XPathNavigator objXmlMetamagic = _objXmlDocument.SelectSingleNode(_strRootXPath + "[id = " + strSelectedId.CleanXPath() + ']'); if (objXmlMetamagic != null) { string strSource = objXmlMetamagic.SelectSingleNode("source")?.Value; string strPage = (await objXmlMetamagic.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? objXmlMetamagic.SelectSingleNode("page")?.Value; SourceString objSourceString = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); await objSourceString.SetControlAsync(lblSource); await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(objSourceString.ToString())); await tlpRight.DoThreadSafeAsync(x => x.Visible = true); } else { await tlpRight.DoThreadSafeAsync(x => x.Visible = false); } } else { await tlpRight.DoThreadSafeAsync(x => x.Visible = false); } }
/// Create a Program from an XmlNode. /// <param name="objXmlProgramNode">XmlNode to create the object from.</param> /// <param name="strExtra">Value to forcefully select for any ImprovementManager prompts.</param> /// <param name="boolCanDelete">Can this AI program be deleted on its own (set to false for Improvement-granted programs).</param> public void Create(XmlNode objXmlProgramNode, string strExtra = "", bool boolCanDelete = true) { if (objXmlProgramNode.TryGetStringFieldQuickly("name", ref _strName)) { _objCachedMyXmlNode = null; } _strRequiresProgram = LanguageManager.GetString("String_None", GlobalOptions.Language); _boolCanDelete = boolCanDelete; objXmlProgramNode.TryGetStringFieldQuickly("require", ref _strRequiresProgram); objXmlProgramNode.TryGetStringFieldQuickly("source", ref _strSource); objXmlProgramNode.TryGetStringFieldQuickly("page", ref _strPage); if (!objXmlProgramNode.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlProgramNode.TryGetStringFieldQuickly("notes", ref _strNotes); } _strExtra = strExtra; string strCategory = string.Empty; if (objXmlProgramNode.TryGetStringFieldQuickly("category", ref strCategory)) { _boolIsAdvancedProgram = strCategory == "Advanced Programs"; } SourceDetail = new SourceString(_strSource, _strPage); }
private async void lstArt_SelectedIndexChanged(object sender, EventArgs e) { if (_blnLoading) { return; } string strSelected = lstArt.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelected)) { tlpRight.Visible = false; return; } // Retrieve the information for the selected art XPathNavigator objXmlMetamagic = _objXmlDocument.SelectSingleNode(_strBaseXPath + "[id = " + strSelected.CleanXPath() + ']'); if (objXmlMetamagic == null) { tlpRight.Visible = false; return; } string strSource = objXmlMetamagic.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); string strPage = (await objXmlMetamagic.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? objXmlMetamagic.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); lblSource.Text = objSource.ToString(); await lblSource.SetToolTipAsync(objSource.LanguageBookTooltip); tlpRight.Visible = true; }
private async void lstTechniques_SelectedIndexChanged(object sender, EventArgs e) { if (_blnLoading) { return; } string strSelectedId = lstTechniques.SelectedValue?.ToString(); if (!string.IsNullOrEmpty(strSelectedId)) { XPathNavigator xmlTechnique = _xmlBaseChummerNode.SelectSingleNode("/chummer/techniques/technique[id = " + strSelectedId.CleanXPath() + ']'); if (xmlTechnique != null) { string strSource = xmlTechnique.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); string strPage = (await xmlTechnique.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? xmlTechnique.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); SourceString objSourceString = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); await objSourceString.SetControlAsync(lblSource); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); tlpRight.Visible = true; } else { tlpRight.Visible = false; } } else { tlpRight.Visible = false; } }
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(); } }
/// <summary> /// Calculate the LP value for the selected items. /// </summary> private void CalculateValues(bool blnIncludePercentage = true) { if (_blnSkipRefresh) { return; } decimal decBaseCost = 0; decimal decCost = 0; decimal decMod = 0; string strBaseLifestyle = string.Empty; // Get the base cost of the lifestyle string strSelectedId = cboLifestyle.SelectedValue?.ToString(); if (strSelectedId != null) { XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[id = " + strSelectedId.CleanXPath() + ']'); if (objXmlAspect != null) { objXmlAspect.TryGetStringFieldQuickly("name", ref strBaseLifestyle); decimal decTemp = 0; if (objXmlAspect.TryGetDecFieldQuickly("cost", ref decTemp)) { decBaseCost += decTemp; } string strSource = objXmlAspect["source"]?.InnerText; string strPage = objXmlAspect["altpage"]?.InnerText ?? objXmlAspect["page"]?.InnerText; if (!string.IsNullOrEmpty(strSource) && !string.IsNullOrEmpty(strPage)) { SourceString objSource = new SourceString(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); lblSource.Text = objSource.ToString(); lblSource.SetToolTip(objSource.LanguageBookTooltip); } else { lblSource.Text = LanguageManager.GetString("String_Unknown"); lblSource.SetToolTip(LanguageManager.GetString("String_Unknown")); } lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); // Add the flat costs from qualities foreach (TreeNode objNode in treQualities.Nodes) { if (objNode.Checked) { string strCost = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + objNode.Tag.ToString().CleanXPath() + "]/cost")?.InnerText; if (!string.IsNullOrEmpty(strCost)) { object objProcess = CommonFunctions.EvaluateInvariantXPath(strCost, out bool blnIsSuccess); if (blnIsSuccess) { decCost += Convert.ToDecimal(objProcess, GlobalSettings.InvariantCultureInfo); } } } } decimal decBaseMultiplier = 0; if (blnIncludePercentage) { // Add the modifiers from qualities foreach (TreeNode objNode in treQualities.Nodes) { if (!objNode.Checked) { continue; } objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + objNode.Tag.ToString().CleanXPath() + ']'); if (objXmlAspect == null) { continue; } if (objXmlAspect.TryGetDecFieldQuickly("multiplier", ref decTemp)) { decMod += decTemp / 100.0m; } if (objXmlAspect.TryGetDecFieldQuickly("multiplierbaseonly", ref decTemp)) { decBaseMultiplier += decTemp / 100.0m; } } // Check for modifiers in the improvements decMod += ImprovementManager.ValueOf(_objCharacter, Improvement.ImprovementType.LifestyleCost) / 100.0m; } decBaseCost += decBaseCost * decBaseMultiplier; if (nudRoommates.Value > 0) { decBaseCost *= 1.0m + Math.Max(nudRoommates.Value / 10.0m, 0); } } } decimal decNuyen = decBaseCost + decBaseCost * decMod + decCost; lblCost.Text = decNuyen.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + '¥'; if (nudPercentage.Value != 100 || nudRoommates.Value != 0 && !chkPrimaryTenant.Checked) { decimal decDiscount = decNuyen; decDiscount *= nudPercentage.Value / 100; if (nudRoommates.Value != 0) { decDiscount /= nudRoommates.Value; } lblCost.Text += LanguageManager.GetString("String_Space") + '(' + decDiscount.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + "¥)"; } lblCostLabel.Visible = !string.IsNullOrEmpty(lblCost.Text); // Characters with the Trust Fund Quality can have the lifestyle discounted. if (Lifestyle.StaticIsTrustFundEligible(_objCharacter, strBaseLifestyle)) { chkTrustFund.Visible = true; chkTrustFund.Checked = _objSourceLifestyle?.TrustFund ?? !_objCharacter.Lifestyles.Any(x => x.TrustFund); } else { chkTrustFund.Checked = false; chkTrustFund.Visible = false; } }
private void lstMentor_SelectedIndexChanged(object sender, EventArgs e) { if (_blnSkipRefresh) { return; } XPathNavigator objXmlMentor = null; string strSelectedId = lstMentor.SelectedValue?.ToString(); if (!string.IsNullOrEmpty(strSelectedId)) { objXmlMentor = _xmlBaseMentorSpiritDataNode.SelectSingleNode("mentors/mentor[id = " + lstMentor.SelectedValue.ToString().CleanXPath() + "]"); } if (objXmlMentor != null) { cboChoice1.BeginUpdate(); cboChoice2.BeginUpdate(); cboChoice1.DataSource = null; cboChoice2.DataSource = null; // If the Mentor offers a choice of bonuses, build the list and let the user select one. XPathNavigator xmlChoices = objXmlMentor.SelectSingleNode("choices"); if (xmlChoices != null) { List <ListItem> lstChoice1 = new List <ListItem>(); List <ListItem> lstChoice2 = new List <ListItem>(); foreach (XPathNavigator objChoice in xmlChoices.Select("choice")) { string strName = objChoice.SelectSingleNode("name")?.Value ?? string.Empty; if ((_objCharacter.AdeptEnabled || !strName.StartsWith("Adept:", StringComparison.Ordinal)) && (_objCharacter.MagicianEnabled || !strName.StartsWith("Magician:", StringComparison.Ordinal))) { if (objChoice.SelectSingleNode("@set")?.Value == "2") { lstChoice2.Add(new ListItem(strName, objChoice.SelectSingleNode("translate")?.Value ?? strName)); } else { lstChoice1.Add(new ListItem(strName, objChoice.SelectSingleNode("translate")?.Value ?? strName)); } } } cboChoice1.Visible = true; cboChoice1.DataSource = lstChoice1; cboChoice1.ValueMember = nameof(ListItem.Value); cboChoice1.DisplayMember = nameof(ListItem.Name); if (lstChoice2.Count > 0) { cboChoice2.Visible = true; cboChoice2.DataSource = lstChoice2; cboChoice2.ValueMember = nameof(ListItem.Value); cboChoice2.DisplayMember = nameof(ListItem.Name); } else { cboChoice2.Visible = false; } cboChoice1.Visible = lstChoice1.Count > 0; cboChoice1.Enabled = lstChoice1.Count > 1; cboChoice2.Enabled = lstChoice2.Count > 1; } else { cboChoice1.Visible = false; cboChoice2.Visible = false; } cboChoice1.EndUpdate(); cboChoice2.EndUpdate(); lblChoice1.Visible = cboChoice1.Visible; lblChoice2.Visible = cboChoice2.Visible; // Get the information for the selected Mentor. lblAdvantage.Text = objXmlMentor.SelectSingleNode("altadvantage")?.Value ?? objXmlMentor.SelectSingleNode("advantage")?.Value ?? LanguageManager.GetString("String_Unknown"); lblAdvantageLabel.Visible = !string.IsNullOrEmpty(lblAdvantage.Text); lblDisadvantage.Text = objXmlMentor.SelectSingleNode("altdisadvantage")?.Value ?? objXmlMentor.SelectSingleNode("disadvantage")?.Value ?? LanguageManager.GetString("String_Unknown"); lblDisadvantageLabel.Visible = !string.IsNullOrEmpty(lblDisadvantage.Text); string strSource = objXmlMentor.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown"); string strPage = objXmlMentor.SelectSingleNode("altpage")?.Value ?? objXmlMentor.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown"); SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter); objSourceString.SetControl(lblSource); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); cmdOK.Enabled = true; } else { lblAdvantageLabel.Visible = false; lblAdvantage.Text = string.Empty; lblDisadvantageLabel.Visible = false; lblDisadvantage.Text = string.Empty; lblChoice1.Visible = false; lblChoice2.Visible = false; cboChoice1.Visible = false; cboChoice2.Visible = false; lblSourceLabel.Visible = false; lblSource.Text = string.Empty; lblSource.SetToolTip(string.Empty); cmdOK.Enabled = false; } }
private void trePowers_AfterSelect(object sender, TreeViewEventArgs e) { lblPowerPoints.Visible = false; lblPowerPointsLabel.Visible = false; string strSelectedPower = trePowers.SelectedNode.Tag?.ToString(); if (!string.IsNullOrEmpty(strSelectedPower)) { XPathNavigator objXmlPower = _xmlBaseCritterPowerDataNode.SelectSingleNode("powers/power[id = " + strSelectedPower.CleanXPath() + "]"); if (objXmlPower != null) { lblCritterPowerCategory.Text = objXmlPower.SelectSingleNode("category")?.Value ?? string.Empty; switch (objXmlPower.SelectSingleNode("type")?.Value) { case "M": lblCritterPowerType.Text = LanguageManager.GetString("String_SpellTypeMana"); break; case "P": lblCritterPowerType.Text = LanguageManager.GetString("String_SpellTypePhysical"); break; default: lblCritterPowerType.Text = string.Empty; break; } switch (objXmlPower.SelectSingleNode("action")?.Value) { case "Auto": lblCritterPowerAction.Text = LanguageManager.GetString("String_ActionAutomatic"); break; case "Free": lblCritterPowerAction.Text = LanguageManager.GetString("String_ActionFree"); break; case "Simple": lblCritterPowerAction.Text = LanguageManager.GetString("String_ActionSimple"); break; case "Complex": lblCritterPowerAction.Text = LanguageManager.GetString("String_ActionComplex"); break; case "Special": lblCritterPowerAction.Text = LanguageManager.GetString("String_SpellDurationSpecial"); break; default: lblCritterPowerAction.Text = string.Empty; break; } string strRange = objXmlPower.SelectSingleNode("range")?.Value ?? string.Empty; if (!string.IsNullOrEmpty(strRange)) { strRange = strRange.CheapReplace("Self", () => LanguageManager.GetString("String_SpellRangeSelf")) .CheapReplace("Special", () => LanguageManager.GetString("String_SpellDurationSpecial")) .CheapReplace("LOS", () => LanguageManager.GetString("String_SpellRangeLineOfSight")) .CheapReplace("LOI", () => LanguageManager.GetString("String_SpellRangeLineOfInfluence")) .CheapReplace("T", () => LanguageManager.GetString("String_SpellRangeTouch")) .CheapReplace("(A)", () => "(" + LanguageManager.GetString("String_SpellRangeArea") + ')') .CheapReplace("MAG", () => LanguageManager.GetString("String_AttributeMAGShort")); } lblCritterPowerRange.Text = strRange; string strDuration = objXmlPower.SelectSingleNode("duration")?.Value ?? string.Empty; switch (strDuration) { case "Instant": lblCritterPowerDuration.Text = LanguageManager.GetString("String_SpellDurationInstantLong"); break; case "Sustained": lblCritterPowerDuration.Text = LanguageManager.GetString("String_SpellDurationSustained"); break; case "Always": lblCritterPowerDuration.Text = LanguageManager.GetString("String_SpellDurationAlways"); break; case "Special": lblCritterPowerDuration.Text = LanguageManager.GetString("String_SpellDurationSpecial"); break; default: lblCritterPowerDuration.Text = strDuration; break; } string strSource = objXmlPower.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown"); string strPage = objXmlPower.SelectSingleNode("altpage")?.Value ?? objXmlPower.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown"); SourceString objSource = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter); lblCritterPowerSource.Text = objSource.ToString(); lblCritterPowerSource.SetToolTip(objSource.LanguageBookTooltip); nudCritterPowerRating.Visible = objXmlPower.SelectSingleNode("rating") != null; lblKarma.Text = objXmlPower.SelectSingleNode("karma")?.Value ?? "0"; // If the character is a Free Spirit, populate the Power Points Cost as well. if (_objCharacter.Metatype == "Free Spirit") { XPathNavigator xmlOptionalPowerCostNode = _xmlMetatypeDataNode.SelectSingleNode("optionalpowers/power[. = " + objXmlPower.SelectSingleNode("name")?.Value.CleanXPath() + "]/@cost"); if (xmlOptionalPowerCostNode != null) { lblPowerPoints.Text = xmlOptionalPowerCostNode.Value; lblPowerPoints.Visible = true; lblPowerPointsLabel.Visible = true; } } } lblCritterPowerTypeLabel.Visible = !string.IsNullOrEmpty(lblCritterPowerType.Text); lblCritterPowerActionLabel.Visible = !string.IsNullOrEmpty(lblCritterPowerAction.Text); lblCritterPowerRangeLabel.Visible = !string.IsNullOrEmpty(lblCritterPowerRange.Text); lblCritterPowerDurationLabel.Visible = !string.IsNullOrEmpty(lblCritterPowerDuration.Text); lblCritterPowerSourceLabel.Visible = !string.IsNullOrEmpty(lblCritterPowerSource.Text); lblKarmaLabel.Visible = !string.IsNullOrEmpty(lblKarma.Text); tlpRight.Visible = true; } else { tlpRight.Visible = false; } }
/// <summary> /// Load the Power from the XmlNode. /// </summary> /// <param name="objNode">XmlNode to load.</param> public void Load(XmlNode objNode) { objNode.TryGetField("guid", Guid.TryParse, out _guiID); objNode.TryGetStringFieldQuickly("name", ref _strName); if (objNode.TryGetField("id", Guid.TryParse, out _sourceID)) { _objCachedMyXmlNode = null; } else { string strPowerName = Name; int intPos = strPowerName.IndexOf('('); if (intPos != -1) { strPowerName = strPowerName.Substring(0, intPos - 1); } XmlDocument objXmlDocument = XmlManager.Load("powers.xml"); XmlNode xmlPower = objXmlDocument.SelectSingleNode("/chummer/powers/power[starts-with(./name,\"" + strPowerName + "\")]"); if (xmlPower.TryGetField("id", Guid.TryParse, out _sourceID)) { _objCachedMyXmlNode = null; } } Extra = objNode["extra"]?.InnerText ?? string.Empty; _strPointsPerLevel = objNode["pointsperlevel"]?.InnerText; objNode.TryGetStringFieldQuickly("action", ref _strAction); _strAdeptWayDiscount = objNode["adeptway"]?.InnerText; if (string.IsNullOrEmpty(_strAdeptWayDiscount)) { string strPowerName = Name; int intPos = strPowerName.IndexOf('('); if (intPos != -1) { strPowerName = strPowerName.Substring(0, intPos - 1); } _strAdeptWayDiscount = XmlManager.Load("powers.xml").SelectSingleNode("/chummer/powers/power[starts-with(./name,\"" + strPowerName + "\")]/adeptway")?.InnerText ?? string.Empty; } objNode.TryGetInt32FieldQuickly("rating", ref _intRating); objNode.TryGetBoolFieldQuickly("levels", ref _blnLevelsEnabled); objNode.TryGetInt32FieldQuickly("maxlevel", ref _intMaxLevel); objNode.TryGetBoolFieldQuickly("discounted", ref _blnDiscountedAdeptWay); objNode.TryGetBoolFieldQuickly("discountedgeas", ref _blnDiscountedGeas); objNode.TryGetStringFieldQuickly("bonussource", ref _strBonusSource); objNode.TryGetDecFieldQuickly("freepoints", ref _decFreePoints); objNode.TryGetDecFieldQuickly("extrapointcost", ref _decExtraPointCost); objNode.TryGetStringFieldQuickly("source", ref _strSource); objNode.TryGetStringFieldQuickly("page", ref _strPage); objNode.TryGetStringFieldQuickly("notes", ref _strNotes); Bonus = objNode["bonus"]; if (objNode["adeptway"] != null) { _nodAdeptWayRequirements = objNode["adeptwayrequires"] ?? GetNode()?["adeptwayrequires"]; } if (Name != "Improved Reflexes" && Name.StartsWith("Improved Reflexes")) { XmlNode objXmlPower = XmlManager.Load("powers.xml").SelectSingleNode("/chummer/powers/power[starts-with(./name,\"Improved Reflexes\")]"); if (objXmlPower != null) { if (int.TryParse(Name.TrimStartOnce("Improved Reflexes", true).Trim(), out int intTemp)) { Create(objXmlPower, intTemp, null, false); objNode.TryGetStringFieldQuickly("notes", ref _strNotes); } } } else { XmlNodeList nodEnhancements = objNode.SelectNodes("enhancements/enhancement"); if (nodEnhancements != null) { foreach (XmlNode nodEnhancement in nodEnhancements) { Enhancement objEnhancement = new Enhancement(CharacterObject); objEnhancement.Load(nodEnhancement); objEnhancement.Parent = this; Enhancements.Add(objEnhancement); } } } //TODO: Seems that the MysAd Second Attribute house rule gets accidentally enabled sometimes? if (LevelsEnabled) { if (Rating > TotalMaximumLevels) { Utils.BreakIfDebug(); Rating = TotalMaximumLevels; } } SourceDetail = new SourceString(_strSource, _strPage); }
private void lstMartialArts_SelectedIndexChanged(object sender, EventArgs e) { if (_blnLoading) { return; } string strSelectedId = lstMartialArts.SelectedValue?.ToString(); if (!string.IsNullOrEmpty(strSelectedId)) { // Populate the Martial Arts list. XPathNavigator objXmlArt = _xmlBaseMartialArtsNode.SelectSingleNode("martialart[id = " + strSelectedId.CleanXPath() + ']'); if (objXmlArt != null) { lblKarmaCost.Text = objXmlArt.SelectSingleNodeAndCacheExpression("cost")?.Value ?? 7.ToString(GlobalSettings.CultureInfo); lblKarmaCostLabel.Visible = !string.IsNullOrEmpty(lblKarmaCost.Text); using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdTechniques)) { foreach (XPathNavigator xmlMartialArtsTechnique in objXmlArt.SelectAndCacheExpression( "techniques/technique")) { string strLoopTechniqueName = xmlMartialArtsTechnique.SelectSingleNodeAndCacheExpression("name")?.Value ?? string.Empty; if (!string.IsNullOrEmpty(strLoopTechniqueName)) { XPathNavigator xmlTechniqueNode = _xmlBaseMartialArtsTechniquesNode.SelectSingleNode( "technique[name = " + strLoopTechniqueName.CleanXPath() + " and (" + _objCharacter.Settings.BookXPath() + ")]"); if (xmlTechniqueNode != null) { if (sbdTechniques.Length > 0) { sbdTechniques.AppendLine(','); } sbdTechniques.Append( !GlobalSettings.Language.Equals(GlobalSettings.DefaultLanguage, StringComparison.OrdinalIgnoreCase) ? xmlTechniqueNode.SelectSingleNodeAndCacheExpression("translate")?.Value ?? strLoopTechniqueName : strLoopTechniqueName); } } } lblIncludedTechniques.Text = sbdTechniques.ToString(); } gpbIncludedTechniques.Visible = !string.IsNullOrEmpty(lblIncludedTechniques.Text); string strSource = objXmlArt.SelectSingleNodeAndCacheExpression("source")?.Value ?? LanguageManager.GetString("String_Unknown"); string strPage = objXmlArt.SelectSingleNodeAndCacheExpression("altpage")?.Value ?? objXmlArt.SelectSingleNodeAndCacheExpression("page")?.Value ?? LanguageManager.GetString("String_Unknown"); SourceString objSourceString = new SourceString(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); objSourceString.SetControl(lblSource); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); tlpRight.Visible = true; } else { tlpRight.Visible = false; gpbIncludedTechniques.Visible = false; } } else { tlpRight.Visible = false; gpbIncludedTechniques.Visible = false; } }
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.CleanXPath() + "]"); } 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(GlobalOptions.InvariantCultureInfo)) .CheapReplace("MaximumAGI", () => (ParentVehicle != null ? Math.Max(1, ParentVehicle.Pilot * 2) : _objCharacter.AGI.TotalMaximum).ToString(GlobalOptions.InvariantCultureInfo)) .CheapReplace("MinimumSTR", () => (ParentVehicle?.TotalBody ?? 3).ToString(GlobalOptions.InvariantCultureInfo)) .CheapReplace("MinimumAGI", () => (ParentVehicle?.Pilot ?? 3).ToString(GlobalOptions.InvariantCultureInfo)); object objProcess = CommonFunctions.EvaluateInvariantXPath(strMinRating, out bool blnIsSuccess); intMinRating = blnIsSuccess ? ((double)objProcess).StandardRound() : 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(GlobalOptions.InvariantCultureInfo)) .CheapReplace("MaximumAGI", () => (ParentVehicle != null ? Math.Max(1, ParentVehicle.Pilot * 2) : _objCharacter.AGI.TotalMaximum).ToString(GlobalOptions.InvariantCultureInfo)) .CheapReplace("MinimumSTR", () => (ParentVehicle?.TotalBody ?? 3).ToString(GlobalOptions.InvariantCultureInfo)) .CheapReplace("MinimumAGI", () => (ParentVehicle?.Pilot ?? 3).ToString(GlobalOptions.InvariantCultureInfo)); object objProcess = CommonFunctions.EvaluateInvariantXPath(strMaxRating, out bool blnIsSuccess); intMaxRating = blnIsSuccess ? ((double)objProcess).StandardRound() : 1; } nudRating.Maximum = intMaxRating; if (chkHideOverAvailLimit.Checked) { int intAvailModifier = strForceGrade == "None" ? 0 : _intAvailModifier; while (nudRating.Maximum > intMinRating && !xmlDrug.CheckAvailRestriction(_objCharacter, nudRating.MaximumAsInt, 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 && !xmlDrug.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier, nudRating.MaximumAsInt)) { 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"); string strPage = xmlDrug.SelectSingleNode("altpage")?.Value ?? xmlDrug.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown"); SourceString objSource = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter); lblSource.Text = objSource.ToString(); lblSource.SetToolTip(objSource.LanguageBookTooltip); 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", GlobalOptions.InvariantCultureInfo); } else { cboGrade.Enabled = !_blnLockGrade; if (_blnLockGrade) { strForceGrade = _objForcedGrade?.SourceId.ToString("D", GlobalOptions.InvariantCultureInfo) ?? cboGrade.SelectedValue?.ToString(); objForcedGrade = _objForcedGrade ?? _lstGrades.FirstOrDefault(x => x.SourceId.ToString("D", GlobalOptions.InvariantCultureInfo) == 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); /* * 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; * }*/ tlpRight.Visible = true; } else { tlpRight.Visible = false; cboGrade.Enabled = !_blnLockGrade; strForceGrade = string.Empty; Grade objForcedGrade = null; if (_blnLockGrade) { strForceGrade = _objForcedGrade?.SourceId.ToString("D", GlobalOptions.InvariantCultureInfo) ?? cboGrade.SelectedValue?.ToString(); objForcedGrade = _objForcedGrade ?? _lstGrades.FirstOrDefault(x => x.SourceId.ToString("D", GlobalOptions.InvariantCultureInfo) == strForceGrade); } PopulateGrades(_blnLockGrade && objForcedGrade?.SecondHand != true, false, strForceGrade); chkBlackMarketDiscount.Checked = false; } _blnLoading = false; UpdateDrugInfo(); }
/// <summary> /// Calculate the LP value for the selected items. /// </summary> private async ValueTask CalculateValues(bool blnIncludePercentage = true) { if (_blnSkipRefresh) { return; } decimal decRoommates = await nudRoommates.DoThreadSafeFuncAsync(x => x.Value); decimal decBaseCost = 0; decimal decCost = 0; decimal decMod = 0; string strBaseLifestyle = string.Empty; // Get the base cost of the lifestyle string strSelectedId = await cboLifestyle.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()); if (!string.IsNullOrEmpty(strSelectedId)) { XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[id = " + strSelectedId.CleanXPath() + ']'); if (objXmlAspect != null) { objXmlAspect.TryGetStringFieldQuickly("name", ref strBaseLifestyle); decimal decTemp = 0; if (objXmlAspect.TryGetDecFieldQuickly("cost", ref decTemp)) { decBaseCost += decTemp; } string strSource = objXmlAspect["source"]?.InnerText; string strPage = objXmlAspect["altpage"]?.InnerText ?? objXmlAspect["page"]?.InnerText; if (!string.IsNullOrEmpty(strSource) && !string.IsNullOrEmpty(strPage)) { SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); await objSource.SetControlAsync(lblSource); await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = true); } else { lblSource.Text = string.Empty; await lblSource.SetToolTipAsync(string.Empty); await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false); } // Add the flat costs from qualities foreach (TreeNode objNode in await treQualities.DoThreadSafeFuncAsync(x => x.Nodes)) { if (objNode.Checked) { string strCost = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + objNode.Tag.ToString().CleanXPath() + "]/cost")?.InnerText; if (!string.IsNullOrEmpty(strCost)) { object objProcess = CommonFunctions.EvaluateInvariantXPath(strCost, out bool blnIsSuccess); if (blnIsSuccess) { decCost += Convert.ToDecimal(objProcess, GlobalSettings.InvariantCultureInfo); } } } } decimal decBaseMultiplier = 0; if (blnIncludePercentage) { // Add the modifiers from qualities foreach (TreeNode objNode in await treQualities.DoThreadSafeFuncAsync(x => x.Nodes)) { if (!objNode.Checked) { continue; } objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + objNode.Tag.ToString().CleanXPath() + ']'); if (objXmlAspect == null) { continue; } if (objXmlAspect.TryGetDecFieldQuickly("multiplier", ref decTemp)) { decMod += decTemp / 100.0m; } if (objXmlAspect.TryGetDecFieldQuickly("multiplierbaseonly", ref decTemp)) { decBaseMultiplier += decTemp / 100.0m; } } // Check for modifiers in the improvements decMod += await ImprovementManager.ValueOfAsync(_objCharacter, Improvement.ImprovementType.LifestyleCost) / 100.0m; } decBaseCost += decBaseCost * decBaseMultiplier; if (decRoommates > 0) { decBaseCost *= 1.0m + Math.Max(decRoommates / 10.0m, 0); } } else { await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false); } } else { await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false); } decimal decNuyen = decBaseCost + decBaseCost * decMod + decCost; await lblCost.DoThreadSafeAsync(x => x.Text = decNuyen.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + '¥'); decimal decPercentage = await nudPercentage.DoThreadSafeFuncAsync(x => x.Value); if (decPercentage != 100 || decRoommates != 0 && !await chkPrimaryTenant.DoThreadSafeFuncAsync(x => x.Checked)) { decimal decDiscount = decNuyen; decDiscount *= decPercentage / 100; if (decRoommates != 0) { decDiscount /= decRoommates; } string strSpace = await LanguageManager.GetStringAsync("String_Space"); await lblCost.DoThreadSafeAsync(x => x.Text += strSpace + '(' + decDiscount.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + "¥)"); } await lblCost.DoThreadSafeFuncAsync(x => x.Text) .ContinueWith( y => lblCostLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(y.Result))) .Unwrap(); // Characters with the Trust Fund Quality can have the lifestyle discounted. if (Lifestyle.StaticIsTrustFundEligible(_objCharacter, strBaseLifestyle)) { bool blnTrustFund = _objSourceLifestyle?.TrustFund ?? !await _objCharacter.Lifestyles.AnyAsync(x => x.TrustFund); await chkTrustFund.DoThreadSafeAsync(x => { x.Visible = true; x.Checked = blnTrustFund; }); } else { await chkTrustFund.DoThreadSafeAsync(x => { x.Checked = false; x.Visible = false; }); } }
/// <summary> /// Refresh the information for the selected Vehicle. /// </summary> private async ValueTask UpdateSelectedVehicle() { if (_blnLoading) { return; } string strSelectedId = lstVehicle.SelectedValue?.ToString(); XPathNavigator objXmlVehicle = null; if (!string.IsNullOrEmpty(strSelectedId)) { // Retrieve the information for the selected Vehicle. objXmlVehicle = _xmlBaseVehicleDataNode.SelectSingleNode("vehicles/vehicle[id = " + strSelectedId.CleanXPath() + ']'); } if (objXmlVehicle == null) { tlpRight.Visible = false; return; } SuspendLayout(); lblVehicleHandling.Text = objXmlVehicle.SelectSingleNode("handling")?.Value; lblVehicleAccel.Text = objXmlVehicle.SelectSingleNode("accel")?.Value; lblVehicleSpeed.Text = objXmlVehicle.SelectSingleNode("speed")?.Value; lblVehiclePilot.Text = objXmlVehicle.SelectSingleNode("pilot")?.Value; lblVehicleBody.Text = objXmlVehicle.SelectSingleNode("body")?.Value; lblVehicleArmor.Text = objXmlVehicle.SelectSingleNode("armor")?.Value; lblVehicleSeats.Text = objXmlVehicle.SelectSingleNode("seats")?.Value; lblVehicleSensor.Text = objXmlVehicle.SelectSingleNode("sensor")?.Value; lblVehicleHandlingLabel.Visible = !string.IsNullOrEmpty(lblVehicleHandling.Text); lblVehicleAccelLabel.Visible = !string.IsNullOrEmpty(lblVehicleAccel.Text); lblVehicleSpeedLabel.Visible = !string.IsNullOrEmpty(lblVehicleSpeed.Text); lblVehiclePilotLabel.Visible = !string.IsNullOrEmpty(lblVehiclePilot.Text); lblVehicleBodyLabel.Visible = !string.IsNullOrEmpty(lblVehicleBody.Text); lblVehicleArmorLabel.Visible = !string.IsNullOrEmpty(lblVehicleArmor.Text); lblVehicleSeatsLabel.Visible = !string.IsNullOrEmpty(lblVehicleSeats.Text); lblVehicleSensorLabel.Visible = !string.IsNullOrEmpty(lblVehicleSensor.Text); AvailabilityValue objTotalAvail = new AvailabilityValue(0, objXmlVehicle.SelectSingleNode("avail")?.Value, chkUsedVehicle.Checked ? -4 : 0); lblVehicleAvail.Text = objTotalAvail.ToString(); lblVehicleAvailLabel.Visible = !string.IsNullOrEmpty(lblVehicleAvail.Text); bool blnCanBlackMarketDiscount = _setBlackMarketMaps.Contains(objXmlVehicle.SelectSingleNode("category")?.Value); chkBlackMarketDiscount.Enabled = blnCanBlackMarketDiscount; if (!chkBlackMarketDiscount.Checked) { chkBlackMarketDiscount.Checked = GlobalSettings.AssumeBlackMarket && blnCanBlackMarketDiscount; } else if (!blnCanBlackMarketDiscount) { //Prevent chkBlackMarketDiscount from being checked if the category doesn't match. chkBlackMarketDiscount.Checked = false; } UpdateSelectedVehicleCost(); string strSource = objXmlVehicle.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); string strPage = (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? objXmlVehicle.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); lblSource.Text = objSource.ToString(); await lblSource.SetToolTipAsync(objSource.LanguageBookTooltip); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); tlpRight.Visible = true; ResumeLayout(); }
private async void lstDrug_SelectedIndexChanged(object sender, EventArgs e) { if (_blnLoading) { return; } _blnLoading = true; XPathNavigator xmlDrug = null; string strSelectedId = await lstDrug.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()); if (!string.IsNullOrEmpty(strSelectedId)) { // Retrieve the information for the selected piece of Drug. xmlDrug = _xmlBaseDrugDataNode.SelectSingleNode(_strNodeXPath + "[id = " + strSelectedId.CleanXPath() + ']'); } 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 = await strMinRating .CheapReplaceAsync("MaximumSTR", () => (ParentVehicle != null ? Math.Max(1, ParentVehicle.TotalBody * 2) : _objCharacter.STR.TotalMaximum) .ToString(GlobalSettings.InvariantCultureInfo)) .CheapReplaceAsync("MaximumAGI", () => (ParentVehicle != null ? Math.Max(1, ParentVehicle.Pilot * 2) : _objCharacter.AGI.TotalMaximum) .ToString(GlobalSettings.InvariantCultureInfo)) .CheapReplaceAsync("MinimumSTR", () => (ParentVehicle?.TotalBody ?? 3).ToString( GlobalSettings.InvariantCultureInfo)) .CheapReplaceAsync("MinimumAGI", () => (ParentVehicle?.Pilot ?? 3).ToString( GlobalSettings.InvariantCultureInfo)); object objProcess = CommonFunctions.EvaluateInvariantXPath(strMinRating, out bool blnIsSuccess); intMinRating = blnIsSuccess ? ((double)objProcess).StandardRound() : 1; } await nudRating.DoThreadSafeAsync(x => x.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 = await strMaxRating .CheapReplaceAsync("MaximumSTR", () => (ParentVehicle != null ? Math.Max(1, ParentVehicle.TotalBody * 2) : _objCharacter.STR.TotalMaximum) .ToString(GlobalSettings.InvariantCultureInfo)) .CheapReplaceAsync("MaximumAGI", () => (ParentVehicle != null ? Math.Max(1, ParentVehicle.Pilot * 2) : _objCharacter.AGI.TotalMaximum) .ToString(GlobalSettings.InvariantCultureInfo)) .CheapReplaceAsync("MinimumSTR", () => (ParentVehicle?.TotalBody ?? 3).ToString( GlobalSettings.InvariantCultureInfo)) .CheapReplaceAsync("MinimumAGI", () => (ParentVehicle?.Pilot ?? 3).ToString( GlobalSettings.InvariantCultureInfo)); object objProcess = CommonFunctions.EvaluateInvariantXPath(strMaxRating, out bool blnIsSuccess); intMaxRating = blnIsSuccess ? ((double)objProcess).StandardRound() : 1; } await nudRating.DoThreadSafeAsync(x => x.Maximum = intMaxRating); if (await chkHideOverAvailLimit.DoThreadSafeFuncAsync(x => x.Checked)) { int intAvailModifier = strForceGrade == "None" ? 0 : _intAvailModifier; await nudRating.DoThreadSafeAsync(x => { while (x.Maximum > intMinRating && !xmlDrug.CheckAvailRestriction(_objCharacter, x.MaximumAsInt, intAvailModifier)) { --x.Maximum; } }); } if (await chkShowOnlyAffordItems.DoThreadSafeFuncAsync(x => x.Checked) && !await chkFree.DoThreadSafeFuncAsync(x => x.Checked)) { decimal decCostMultiplier = 1 + nudMarkup.Value / 100.0m; if (await chkBlackMarketDiscount.DoThreadSafeFuncAsync(x => x.Checked)) { decCostMultiplier *= 0.9m; } await nudRating.DoThreadSafeAsync(x => { while (x.Maximum > intMinRating && !xmlDrug.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier, x.MaximumAsInt)) { --x.Maximum; } }); } await nudRating.DoThreadSafeAsync(x => { x.Value = x.Minimum; x.Enabled = x.Minimum != x.Maximum; x.Visible = true; }); await lblRatingNALabel.DoThreadSafeAsync(x => x.Visible = false); await lblRatingLabel.DoThreadSafeAsync(x => x.Visible = true); } else { await lblRatingLabel.DoThreadSafeAsync(x => x.Visible = true); await lblRatingNALabel.DoThreadSafeAsync(x => x.Visible = true); await nudRating.DoThreadSafeAsync(x => { x.Minimum = 0; x.Value = 0; x.Visible = false; }); } string strSource = xmlDrug.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); string strPage = (await xmlDrug.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? xmlDrug.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); await objSource.SetControlAsync(lblSource); await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(objSource.ToString())); Grade objForcedGrade = null; if (!string.IsNullOrEmpty(strForceGrade)) { // Force the Drug to be a particular Grade. await cboGrade.DoThreadSafeAsync(x => { if (x.Enabled) { x.Enabled = false; } }); objForcedGrade = _lstGrades.Find(x => x.Name == strForceGrade); strForceGrade = objForcedGrade?.SourceId.ToString("D", GlobalSettings.InvariantCultureInfo); } else { await cboGrade.DoThreadSafeAsync(x => x.Enabled = !_blnLockGrade); if (_blnLockGrade) { strForceGrade = _objForcedGrade?.SourceId.ToString("D", GlobalSettings.InvariantCultureInfo) ?? cboGrade.SelectedValue?.ToString(); objForcedGrade = _objForcedGrade ?? _lstGrades.Find(x => x.SourceId.ToString("D", GlobalSettings.InvariantCultureInfo) == strForceGrade); } } bool blnCanBlackMarketDiscount = _setBlackMarketMaps.Contains(xmlDrug.SelectSingleNode("category")?.Value); await chkBlackMarketDiscount.DoThreadSafeAsync(x => { x.Enabled = blnCanBlackMarketDiscount; if (!x.Checked) { x.Checked = GlobalSettings.AssumeBlackMarket && blnCanBlackMarketDiscount; } else if (!blnCanBlackMarketDiscount) { //Prevent chkBlackMarketDiscount from being checked if the category doesn't match. x.Checked = false; } }); // 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. await PopulateGrades(xmlDrug.SelectSingleNode("nosecondhand") != null || !await cboGrade.DoThreadSafeFuncAsync(x => x.Enabled) && objForcedGrade?.SecondHand != true, false, strForceGrade); /* * string strNotes = xmlDrug.SelectSingleNode("altnotes")?.Value ?? xmlDrug.SelectSingleNode("notes")?.Value; * if (!string.IsNullOrEmpty(strNotes)) * { * await lblDrugNotesLabel.DoThreadSafeAsync(x => x.Visible = true); * await lblDrugNotes.DoThreadSafeAsync(x => * { * x.Text = strNotes; * x.Visible = true; * }); * } * else * { * await lblDrugNotes.DoThreadSafeAsync(x => x.Visible = false); * await lblDrugNotesLabel.DoThreadSafeAsync(x => x.Visible = false); * }*/ await tlpRight.DoThreadSafeAsync(x => x.Visible = true); } else { await tlpRight.DoThreadSafeAsync(x => x.Visible = false); await cboGrade.DoThreadSafeAsync(x => x.Enabled = !_blnLockGrade); strForceGrade = string.Empty; Grade objForcedGrade = null; if (_blnLockGrade) { strForceGrade = _objForcedGrade?.SourceId.ToString("D", GlobalSettings.InvariantCultureInfo) ?? await cboGrade.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()); objForcedGrade = _objForcedGrade ?? _lstGrades.Find(x => x.SourceId.ToString("D", GlobalSettings.InvariantCultureInfo) == strForceGrade); } await PopulateGrades(_blnLockGrade && objForcedGrade?.SecondHand != true, false, strForceGrade); await chkBlackMarketDiscount.DoThreadSafeAsync(x => x.Checked = false); } _blnLoading = false; await UpdateDrugInfo(); }
private async ValueTask RefreshSelectedLifestyle() { if (_blnSkipRefresh) { return; } _objLifestyle.BaseLifestyle = await cboBaseLifestyle.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()) ?? string.Empty; XPathNavigator xmlAspect = await _objLifestyle.GetNodeXPathAsync(); if (xmlAspect != null) { string strSource = xmlAspect.SelectSingleNode("source")?.Value ?? string.Empty; string strPage = (await xmlAspect.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? xmlAspect.SelectSingleNode("page")?.Value ?? string.Empty; if (!string.IsNullOrEmpty(strSource) && !string.IsNullOrEmpty(strPage)) { SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); await objSource.SetControlAsync(lblSource); await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = true); } else { await SourceString.Blank.SetControlAsync(lblSource); await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false); } } else { await SourceString.Blank.SetControlAsync(lblSource); await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false); } // Characters with the Trust Fund Quality can have the lifestyle discounted. if (_objLifestyle.IsTrustFundEligible) { await chkTrustFund.DoThreadSafeAsync(x => { x.Visible = true; x.Checked = _objLifestyle.TrustFund; }); } else { await chkTrustFund.DoThreadSafeAsync(x => { x.Checked = false; x.Visible = false; }); } if (_objLifestyle.AllowBonusLP) { await lblBonusLP.DoThreadSafeAsync(x => x.Visible = true); await nudBonusLP.DoThreadSafeAsync(x => x.Visible = true); await chkBonusLPRandomize.DoThreadSafeAsync(x => x.Visible = true); if (await chkBonusLPRandomize.DoThreadSafeFuncAsync(x => x.Checked)) { int intValue = await GlobalSettings.RandomGenerator.NextD6ModuloBiasRemovedAsync(); await nudBonusLP.DoThreadSafeAsync(x => { x.Enabled = false; _blnSkipRefresh = true; x.Value = intValue; _blnSkipRefresh = false; }); } else { await nudBonusLP.DoThreadSafeAsync(x => x.Enabled = true); } } else { await lblBonusLP.DoThreadSafeAsync(x => x.Visible = false); await nudBonusLP.DoThreadSafeAsync(x => x.Visible = false); await nudBonusLP.DoThreadSafeAsync(x => x.Value = 0); await chkBonusLPRandomize.DoThreadSafeAsync(x => x.Visible = false); } }
private async void lstQualities_SelectedIndexChanged(object sender, EventArgs e) { if (_blnLoading) { return; } _blnLoading = true; try { XPathNavigator xmlQuality = null; string strSelectedQuality = await lstQualities.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()); if (!string.IsNullOrEmpty(strSelectedQuality)) { xmlQuality = _xmlBaseQualityDataNode.SelectSingleNode( "qualities/quality[id = " + strSelectedQuality.CleanXPath() + ']'); } if (xmlQuality != null) { await nudRating.DoThreadSafeAsync(x => x.ValueAsInt = x.MinimumAsInt); int intMaxRating = int.MaxValue; if (xmlQuality.TryGetInt32FieldQuickly("limit", ref intMaxRating) && xmlQuality.SelectSingleNode("nolevels") == null) { await lblRatingNALabel.DoThreadSafeAsync(x => x.Visible = false); await nudRating.DoThreadSafeAsync(x => { x.MaximumAsInt = intMaxRating; x.Visible = true; }); } else { await lblRatingNALabel.DoThreadSafeAsync(x => x.Visible = true); await nudRating.DoThreadSafeAsync(x => { x.MaximumAsInt = 1; x.ValueAsInt = 1; x.Visible = false; }); } await UpdateCostLabel(xmlQuality); string strSource = xmlQuality.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); string strPage = (await xmlQuality.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? xmlQuality.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); SourceString objSource = await SourceString.GetSourceStringAsync( strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); await objSource.SetControlAsync(lblSource); await lblSourceLabel.DoThreadSafeAsync( x => x.Visible = !string.IsNullOrEmpty(objSource.ToString())); await tlpRight.DoThreadSafeAsync(x => x.Visible = true); } else { await tlpRight.DoThreadSafeAsync(x => x.Visible = false); } } finally { _blnLoading = false; } }
public MasterIndexEntry(string strDisplayName, string strFileName, SourceString objSource, SourceString objDisplaySource, string strEnglishNameOnPage, string strTranslatedNameOnPage) { DisplayName = strDisplayName; FileNames = Utils.StringHashSetPool.Get(); FileNames.Add(strFileName); Source = objSource; DisplaySource = objDisplaySource; EnglishNameOnPage = strEnglishNameOnPage; TranslatedNameOnPage = strTranslatedNameOnPage; }
private void UpdateInfo() { if (_blnLoading) { return; } XmlNode xmlSelectedMount = null; string strSelectedMount = cboSize.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedMount)) { cmdOK.Enabled = false; } else { xmlSelectedMount = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedMount.CleanXPath() + "]"); if (xmlSelectedMount == null) { cmdOK.Enabled = false; } else { string strSelectedControl = cboControl.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedControl)) { cmdOK.Enabled = false; } else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedControl.CleanXPath() + "]") == null) { cmdOK.Enabled = false; } else { string strSelectedFlexibility = cboFlexibility.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedFlexibility)) { cmdOK.Enabled = false; } else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedFlexibility.CleanXPath() + "]") == null) { cmdOK.Enabled = false; } else { string strSelectedVisibility = cboVisibility.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedVisibility)) { cmdOK.Enabled = false; } else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedVisibility.CleanXPath() + "]") == null) { cmdOK.Enabled = false; } else { cmdOK.Enabled = true; } } } } } string[] astrSelectedValues = { cboVisibility.SelectedValue?.ToString(), cboFlexibility.SelectedValue?.ToString(), cboControl.SelectedValue?.ToString() }; cmdDeleteMod.Enabled = false; string strSelectedModId = treMods.SelectedNode?.Tag.ToString(); if (!string.IsNullOrEmpty(strSelectedModId) && strSelectedModId.IsGuid()) { VehicleMod objMod = _lstMods.FirstOrDefault(x => x.InternalId == strSelectedModId); if (objMod != null) { cmdDeleteMod.Enabled = !objMod.IncludedInVehicle; lblSlots.Text = objMod.CalculatedSlots.ToString(GlobalOptions.InvariantCultureInfo); lblAvailability.Text = objMod.DisplayTotalAvail; if (chkFreeItem.Checked) { lblCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥'; } else { int intTotalSlots = Convert.ToInt32(xmlSelectedMount?["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo); foreach (string strSelectedId in astrSelectedValues) { if (!string.IsNullOrEmpty(strSelectedId)) { XmlNode xmlLoopNode = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedId.CleanXPath() + "]"); if (xmlLoopNode != null) { intTotalSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo); } } } foreach (VehicleMod objLoopMod in _lstMods) { intTotalSlots += objLoopMod.CalculatedSlots; } lblCost.Text = (objMod.TotalCostInMountCreation(intTotalSlots) * (1 + (nudMarkup.Value / 100.0m))).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥'; } objMod.SetSourceDetail(lblSource); lblCostLabel.Visible = !string.IsNullOrEmpty(lblCost.Text); lblSlotsLabel.Visible = !string.IsNullOrEmpty(lblSlots.Text); lblAvailabilityLabel.Visible = !string.IsNullOrEmpty(lblAvailability.Text); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); return; } } if (xmlSelectedMount == null) { lblCost.Text = string.Empty; lblSlots.Text = string.Empty; lblAvailability.Text = string.Empty; lblCostLabel.Visible = false; lblSlotsLabel.Visible = false; lblAvailabilityLabel.Visible = false; return; } decimal decCost = !chkFreeItem.Checked ? Convert.ToDecimal(xmlSelectedMount["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo) : 0; int intSlots = Convert.ToInt32(xmlSelectedMount["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo); string strAvail = xmlSelectedMount["avail"]?.InnerText ?? string.Empty; char chrAvailSuffix = strAvail.Length > 0 ? strAvail[strAvail.Length - 1] : ' '; if (chrAvailSuffix == 'F' || chrAvailSuffix == 'R') { strAvail = strAvail.Substring(0, strAvail.Length - 1); } else { chrAvailSuffix = ' '; } int intAvail = Convert.ToInt32(strAvail, GlobalOptions.InvariantCultureInfo); foreach (string strSelectedId in astrSelectedValues) { if (!string.IsNullOrEmpty(strSelectedId)) { XmlNode xmlLoopNode = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedId.CleanXPath() + "]"); if (xmlLoopNode != null) { if (!chkFreeItem.Checked) { decCost += Convert.ToInt32(xmlLoopNode["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo); } intSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo); string strLoopAvail = xmlLoopNode["avail"]?.InnerText ?? string.Empty; char chrLoopAvailSuffix = strLoopAvail.Length > 0 ? strLoopAvail[strLoopAvail.Length - 1] : ' '; if (chrLoopAvailSuffix == 'F') { strLoopAvail = strLoopAvail.Substring(0, strLoopAvail.Length - 1); chrAvailSuffix = 'F'; } else if (chrLoopAvailSuffix == 'R') { strLoopAvail = strLoopAvail.Substring(0, strLoopAvail.Length - 1); if (chrAvailSuffix == ' ') { chrAvailSuffix = 'R'; } } intAvail += Convert.ToInt32(strLoopAvail, GlobalOptions.InvariantCultureInfo); } } } foreach (VehicleMod objMod in _lstMods) { intSlots += objMod.CalculatedSlots; AvailabilityValue objLoopAvail = objMod.TotalAvailTuple(); char chrLoopAvailSuffix = objLoopAvail.Suffix; if (chrLoopAvailSuffix == 'F') { chrAvailSuffix = 'F'; } else if (chrAvailSuffix != 'F' && chrLoopAvailSuffix == 'R') { chrAvailSuffix = 'R'; } intAvail += objLoopAvail.Value; } if (!chkFreeItem.Checked) { foreach (VehicleMod objMod in _lstMods) { decCost += objMod.TotalCostInMountCreation(intSlots); } } string strAvailText = intAvail.ToString(GlobalOptions.CultureInfo); if (chrAvailSuffix == 'F') { strAvailText += LanguageManager.GetString("String_AvailForbidden"); } else if (chrAvailSuffix == 'R') { strAvailText += LanguageManager.GetString("String_AvailRestricted"); } decCost *= 1 + (nudMarkup.Value / 100.0m); lblCost.Text = decCost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥'; lblSlots.Text = intSlots.ToString(GlobalOptions.CultureInfo); lblAvailability.Text = strAvailText; lblCostLabel.Visible = !string.IsNullOrEmpty(lblCost.Text); lblSlotsLabel.Visible = !string.IsNullOrEmpty(lblSlots.Text); lblAvailabilityLabel.Visible = !string.IsNullOrEmpty(lblAvailability.Text); string strSource = xmlSelectedMount["source"]?.InnerText ?? LanguageManager.GetString("String_Unknown"); string strPage = xmlSelectedMount["altpage"]?.InnerText ?? xmlSelectedMount["page"]?.InnerText ?? LanguageManager.GetString("String_Unknown"); SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter); objSourceString.SetControl(lblSource); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); }
public bool Create(XmlNode objNode, int intRating = 1, XmlNode objBonusNodeOverride = null, bool blnCreateImprovements = true) { objNode.TryGetStringFieldQuickly("name", ref _strName); objNode.TryGetField("id", Guid.TryParse, out _sourceID); _objCachedMyXmlNode = null; objNode.TryGetStringFieldQuickly("points", ref _strPointsPerLevel); objNode.TryGetStringFieldQuickly("adeptway", ref _strAdeptWayDiscount); objNode.TryGetBoolFieldQuickly("levels", ref _blnLevelsEnabled); _intRating = intRating; if (!objNode.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objNode.TryGetStringFieldQuickly("notes", ref _strNotes); } objNode.TryGetInt32FieldQuickly("maxlevels", ref _intMaxLevel); objNode.TryGetBoolFieldQuickly("discounted", ref _blnDiscountedAdeptWay); objNode.TryGetBoolFieldQuickly("discountedgeas", ref _blnDiscountedGeas); objNode.TryGetStringFieldQuickly("bonussource", ref _strBonusSource); objNode.TryGetDecFieldQuickly("freepoints", ref _decFreePoints); objNode.TryGetDecFieldQuickly("extrapointcost", ref _decExtraPointCost); objNode.TryGetStringFieldQuickly("action", ref _strAction); objNode.TryGetStringFieldQuickly("source", ref _strSource); objNode.TryGetStringFieldQuickly("page", ref _strPage); Bonus = objNode["bonus"]; if (objBonusNodeOverride != null) { Bonus = objBonusNodeOverride; } _nodAdeptWayRequirements = objNode["adeptwayrequires"]; XmlNode nodEnhancements = objNode["enhancements"]; if (nodEnhancements != null) { using (XmlNodeList xmlEnhancementList = nodEnhancements.SelectNodes("enhancement")) if (xmlEnhancementList != null) { foreach (XmlNode nodEnhancement in xmlEnhancementList) { Enhancement objEnhancement = new Enhancement(CharacterObject); objEnhancement.Load(nodEnhancement); objEnhancement.Parent = this; Enhancements.Add(objEnhancement); } } } if (blnCreateImprovements && Bonus != null && Bonus.HasChildNodes) { string strOldForce = ImprovementManager.ForcedValue; string strOldSelected = ImprovementManager.SelectedValue; ImprovementManager.ForcedValue = Extra; if (!ImprovementManager.CreateImprovements(CharacterObject, Improvement.ImprovementSource.Power, InternalId, Bonus, false, TotalRating, DisplayNameShort(GlobalOptions.Language))) { ImprovementManager.ForcedValue = strOldForce; DeletePower(); return(false); } Extra = ImprovementManager.SelectedValue; ImprovementManager.SelectedValue = strOldSelected; ImprovementManager.ForcedValue = strOldForce; } if (TotalMaximumLevels < Rating) { Rating = TotalMaximumLevels; } SourceDetail = new SourceString(_strSource, _strPage); return(true); }
private void lstMartialArts_SelectedIndexChanged(object sender, EventArgs e) { if (_blnLoading) { return; } string strSelectedId = lstMartialArts.SelectedValue?.ToString(); if (!string.IsNullOrEmpty(strSelectedId)) { // Populate the Martial Arts list. XPathNavigator objXmlArt = _xmlBaseMartialArtsNode.SelectSingleNode("martialart[id = \"" + strSelectedId + "\"]"); if (objXmlArt != null) { lblKarmaCost.Text = objXmlArt.SelectSingleNode("cost")?.Value ?? 7.ToString(GlobalOptions.CultureInfo); lblKarmaCostLabel.Visible = !string.IsNullOrEmpty(lblKarmaCost.Text); StringBuilder objTechniqueStringBuilder = new StringBuilder(); foreach (XPathNavigator xmlMartialArtsTechnique in objXmlArt.Select("techniques/technique")) { string strLoopTechniqueName = xmlMartialArtsTechnique.SelectSingleNode("name")?.Value ?? string.Empty; if (!string.IsNullOrEmpty(strLoopTechniqueName)) { XPathNavigator xmlTechniqueNode = _xmlBaseMartialArtsTechniquesNode.SelectSingleNode(string.Format(GlobalOptions.InvariantCultureInfo, "technique[name = {0} and ({1})]", strLoopTechniqueName.CleanXPath(), _objCharacter.Options.BookXPath())); if (xmlTechniqueNode != null) { if (objTechniqueStringBuilder.Length > 0) { objTechniqueStringBuilder.AppendLine(","); } objTechniqueStringBuilder.Append(GlobalOptions.Language != GlobalOptions.DefaultLanguage ? xmlTechniqueNode.SelectSingleNode("translate")?.Value ?? strLoopTechniqueName: strLoopTechniqueName); } } } lblIncludedTechniques.Text = objTechniqueStringBuilder.ToString(); lblIncludedTechniquesLabel.Visible = !string.IsNullOrEmpty(lblIncludedTechniques.Text); string strSource = objXmlArt.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown"); string strPage = objXmlArt.SelectSingleNode("altpage")?.Value ?? objXmlArt.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown"); SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language); objSourceString.SetControl(lblSource); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); } else { lblKarmaCostLabel.Visible = false; lblKarmaCost.Text = string.Empty; lblIncludedTechniquesLabel.Visible = false; lblIncludedTechniques.Text = string.Empty; lblSourceLabel.Visible = false; lblSource.Text = string.Empty; lblSource.SetToolTip(string.Empty); } } else { lblKarmaCostLabel.Visible = false; lblKarmaCost.Text = string.Empty; lblIncludedTechniquesLabel.Visible = false; lblIncludedTechniques.Text = string.Empty; lblSourceLabel.Visible = false; lblSource.Text = string.Empty; lblSource.SetToolTip(string.Empty); } }
public MasterIndexEntry(string strDisplayName, string strFileName, SourceString objSource, SourceString objDisplaySource, string strEnglishNameOnPage, string strTranslatedNameOnPage) { DisplayName = strDisplayName; FileNames = new HashSet <string> { strFileName }; Source = objSource; DisplaySource = objDisplaySource; EnglishNameOnPage = strEnglishNameOnPage; TranslatedNameOnPage = strTranslatedNameOnPage; }
private async void lstMentor_SelectedIndexChanged(object sender, EventArgs e) { if (_blnSkipRefresh) { return; } SuspendLayout(); try { XPathNavigator objXmlMentor = null; if (lstMentor.SelectedIndex >= 0) { string strSelectedId = lstMentor.SelectedValue?.ToString(); if (!string.IsNullOrEmpty(strSelectedId)) { objXmlMentor = _xmlBaseMentorSpiritDataNode.SelectSingleNode("mentors/mentor[id = " + strSelectedId.CleanXPath() + ']'); } } if (objXmlMentor != null) { // If the Mentor offers a choice of bonuses, build the list and let the user select one. XPathNavigator xmlChoices = await objXmlMentor.SelectSingleNodeAndCacheExpressionAsync("choices"); if (xmlChoices != null) { using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool, out List <ListItem> lstChoice1)) using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool, out List <ListItem> lstChoice2)) { foreach (XPathNavigator objChoice in await xmlChoices.SelectAndCacheExpressionAsync("choice")) { string strName = (await objChoice.SelectSingleNodeAndCacheExpressionAsync("name"))?.Value ?? string.Empty; if ((_objCharacter.AdeptEnabled || !strName.StartsWith("Adept:", StringComparison.Ordinal)) && (_objCharacter.MagicianEnabled || !strName.StartsWith("Magician:", StringComparison.Ordinal))) { if (objChoice.SelectSingleNode("@set")?.Value == "2") { lstChoice2.Add(new ListItem(strName, (await objChoice.SelectSingleNodeAndCacheExpressionAsync( "translate"))?.Value ?? strName)); } else { lstChoice1.Add(new ListItem(strName, (await objChoice.SelectSingleNodeAndCacheExpressionAsync( "translate"))?.Value ?? strName)); } } } //If there is only a single option, show it as a label. //If there are more, show the drop down menu if (lstChoice1.Count > 0) { await cboChoice1.PopulateWithListItemsAsync(lstChoice1); } cboChoice1.Visible = lstChoice1.Count > 1; lblBonusText1.Visible = lstChoice1.Count == 1; if (lstChoice1.Count == 1) { lblBonusText1.Text = lstChoice1[0].Name; } if (lstChoice2.Count > 0) { await cboChoice2.PopulateWithListItemsAsync(lstChoice2); } cboChoice2.Visible = lstChoice2.Count > 1; lblBonusText2.Visible = lstChoice2.Count == 1; if (lstChoice2.Count == 1) { lblBonusText2.Text = lstChoice2[0].Name; } } } else { cboChoice1.Visible = false; cboChoice2.Visible = false; lblBonusText1.Visible = false; lblBonusText2.Visible = false; } lblChoice1.Visible = cboChoice1.Visible; lblChoice2.Visible = cboChoice2.Visible; lblBonus1.Visible = lblBonusText1.Visible; lblBonus2.Visible = lblBonusText2.Visible; // Get the information for the selected Mentor. lblAdvantage.Text = objXmlMentor.SelectSingleNode("altadvantage")?.Value ?? objXmlMentor.SelectSingleNode("advantage")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); lblAdvantageLabel.Visible = !string.IsNullOrEmpty(lblAdvantage.Text); lblDisadvantage.Text = objXmlMentor.SelectSingleNode("altdisadvantage")?.Value ?? objXmlMentor.SelectSingleNode("disadvantage")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); lblDisadvantageLabel.Visible = !string.IsNullOrEmpty(lblDisadvantage.Text); string strSource = objXmlMentor.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); string strPage = (await objXmlMentor.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? objXmlMentor.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); SourceString objSourceString = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); await objSourceString.SetControlAsync(lblSource); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); cmdOK.Enabled = true; tlpRight.Visible = true; tlpBottomRight.Visible = true; } else { tlpRight.Visible = false; tlpBottomRight.Visible = false; cmdOK.Enabled = false; } } finally { ResumeLayout(); } }
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(); }
/// <summary> /// Refresh the information for the selected Vehicle. /// </summary> private async ValueTask UpdateSelectedVehicle() { if (_blnLoading) { return; } string strSelectedId = await lstVehicle.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()); XPathNavigator objXmlVehicle = null; if (!string.IsNullOrEmpty(strSelectedId)) { // Retrieve the information for the selected Vehicle. objXmlVehicle = _xmlBaseVehicleDataNode.SelectSingleNode("vehicles/vehicle[id = " + strSelectedId.CleanXPath() + ']'); } if (objXmlVehicle == null) { await tlpRight.DoThreadSafeAsync(x => x.Visible = false); return; } await this.DoThreadSafeAsync(x => x.SuspendLayout()); try { string strHandling = objXmlVehicle.SelectSingleNode("handling")?.Value; await lblVehicleHandling.DoThreadSafeAsync(x => x.Text = strHandling); string strAccel = objXmlVehicle.SelectSingleNode("accel")?.Value; await lblVehicleAccel.DoThreadSafeAsync(x => x.Text = strAccel); string strSpeed = objXmlVehicle.SelectSingleNode("speed")?.Value; await lblVehicleSpeed.DoThreadSafeAsync(x => x.Text = strSpeed); string strPilot = objXmlVehicle.SelectSingleNode("pilot")?.Value; await lblVehiclePilot.DoThreadSafeAsync(x => x.Text = strPilot); string strBody = objXmlVehicle.SelectSingleNode("body")?.Value; await lblVehicleBody.DoThreadSafeAsync(x => x.Text = strBody); string strArmor = objXmlVehicle.SelectSingleNode("armor")?.Value; await lblVehicleArmor.DoThreadSafeAsync(x => x.Text = strArmor); string strSeats = objXmlVehicle.SelectSingleNode("seats")?.Value; await lblVehicleSeats.DoThreadSafeAsync(x => x.Text = strSeats); string strSensor = objXmlVehicle.SelectSingleNode("sensor")?.Value; await lblVehicleSensor.DoThreadSafeAsync(x => x.Text = strSensor); await lblVehicleHandlingLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strHandling)); await lblVehicleAccelLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strAccel)); await lblVehicleSpeedLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strSpeed)); await lblVehiclePilotLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strPilot)); await lblVehicleBodyLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strBody)); await lblVehicleArmorLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strArmor)); await lblVehicleSeatsLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strSeats)); await lblVehicleSensorLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strSensor)); AvailabilityValue objTotalAvail = new AvailabilityValue(0, objXmlVehicle.SelectSingleNode("avail")?.Value, await chkUsedVehicle.DoThreadSafeFuncAsync(x => x.Checked) ? -4 : 0); string strAvail = objTotalAvail.ToString(); await lblVehicleAvail.DoThreadSafeAsync(x => x.Text = strAvail); await lblVehicleAvailLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strAvail)); bool blnCanBlackMarketDiscount = _setBlackMarketMaps.Contains(objXmlVehicle.SelectSingleNode("category")?.Value); await chkBlackMarketDiscount.DoThreadSafeAsync(x => { x.Enabled = blnCanBlackMarketDiscount; if (!x.Checked) { x.Checked = GlobalSettings.AssumeBlackMarket && blnCanBlackMarketDiscount; } else if (!blnCanBlackMarketDiscount) { //Prevent chkBlackMarketDiscount from being checked if the category doesn't match. x.Checked = false; } }); await UpdateSelectedVehicleCost(); string strSource = objXmlVehicle.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); string strPage = (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? objXmlVehicle.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); SourceString objSource = await SourceString.GetSourceStringAsync( strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); await objSource.SetControlAsync(lblSource); await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(objSource.ToString())); await tlpRight.DoThreadSafeAsync(x => x.Visible = true); } finally { await this.DoThreadSafeAsync(x => x.ResumeLayout()); } }
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); }
private async ValueTask BuildVehicleList(XPathNodeIterator objXmlVehicleList) { await this.DoThreadSafeAsync(x => x.SuspendLayout()); try { int intOverLimit = 0; bool blnHideOverAvailLimit = await chkHideOverAvailLimit.DoThreadSafeFuncAsync(x => x.Checked); bool blnFreeItem = await chkFreeItem.DoThreadSafeFuncAsync(x => x.Checked); bool blnShowOnlyAffordItems = await chkShowOnlyAffordItems.DoThreadSafeFuncAsync(x => x.Checked); bool blnBlackMarketDiscount = await chkBlackMarketDiscount.DoThreadSafeFuncAsync(x => x.Checked); decimal decBaseCostMultiplier = 1.0m; if (await chkUsedVehicle.DoThreadSafeFuncAsync(x => x.Checked)) { decBaseCostMultiplier -= (await nudUsedVehicleDiscount.DoThreadSafeFuncAsync(x => x.Value) / 100.0m); } decBaseCostMultiplier *= 1 + (await nudMarkup.DoThreadSafeFuncAsync(x => x.Value) / 100.0m); bool blnHasSearch = await txtSearch.DoThreadSafeFuncAsync(x => x.TextLength != 0); if (await tabViews.DoThreadSafeFuncAsync(x => x.SelectedIndex) == 1) { XmlDocument dummy = new XmlDocument { XmlResolver = null }; DataTable tabVehicles = new DataTable("vehicles"); tabVehicles.Columns.Add("VehicleGuid"); tabVehicles.Columns.Add("VehicleName"); tabVehicles.Columns.Add("Accel"); tabVehicles.Columns.Add("Armor"); tabVehicles.Columns.Add("Body"); tabVehicles.Columns.Add("Handling"); tabVehicles.Columns.Add("Pilot"); tabVehicles.Columns.Add("Sensor"); tabVehicles.Columns.Add("Speed"); tabVehicles.Columns.Add("Seats"); tabVehicles.Columns.Add("Gear"); tabVehicles.Columns.Add("Mods"); tabVehicles.Columns.Add("Weapons"); tabVehicles.Columns.Add("WeaponMounts"); tabVehicles.Columns.Add("Avail", typeof(AvailabilityValue)); tabVehicles.Columns.Add("Source", typeof(SourceString)); tabVehicles.Columns.Add("Cost", typeof(NuyenString)); foreach (XPathNavigator objXmlVehicle in objXmlVehicleList) { if (blnHideOverAvailLimit && !objXmlVehicle.CheckAvailRestriction(_objCharacter)) { ++intOverLimit; continue; } if (!blnFreeItem && blnShowOnlyAffordItems) { decimal decCostMultiplier = decBaseCostMultiplier; if (blnBlackMarketDiscount && _setBlackMarketMaps.Contains((await objXmlVehicle .SelectSingleNodeAndCacheExpressionAsync( "category")) ?.Value)) { decCostMultiplier *= 0.9m; } if (Vehicle.DoesDealerConnectionApply(_setDealerConnectionMaps, (await objXmlVehicle .SelectSingleNodeAndCacheExpressionAsync( "category")) ?.Value)) { decCostMultiplier *= 0.9m; } if (!objXmlVehicle.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier)) { ++intOverLimit; continue; } } using (Vehicle objVehicle = new Vehicle(_objCharacter)) { objVehicle.Create(objXmlVehicle.ToXmlNode(dummy), true, true, false, true); string strID = objVehicle.SourceIDString; string strVehicleName = objVehicle.CurrentDisplayName; string strAccel = objVehicle.TotalAccel; string strArmor = objVehicle.TotalArmor.ToString(GlobalSettings.CultureInfo); string strBody = objVehicle.TotalBody.ToString(GlobalSettings.CultureInfo); string strHandling = objVehicle.TotalHandling; string strPilot = objVehicle.Pilot.ToString(GlobalSettings.CultureInfo); string strSensor = objVehicle.CalculatedSensor.ToString(GlobalSettings.CultureInfo); string strSpeed = objVehicle.TotalSpeed; string strSeats = objVehicle.TotalSeats.ToString(GlobalSettings.CultureInfo); using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdGear)) { foreach (Gear objGear in objVehicle.GearChildren) { sbdGear.AppendLine(objGear.CurrentDisplayName); } if (sbdGear.Length > 0) { sbdGear.Length -= Environment.NewLine.Length; } using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdMods)) { foreach (VehicleMod objMod in objVehicle.Mods) { sbdMods.AppendLine(objMod.CurrentDisplayName); } if (sbdMods.Length > 0) { sbdMods.Length -= Environment.NewLine.Length; } using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdWeapons)) { if (sbdWeapons.Length > 0) { sbdWeapons.Length -= Environment.NewLine.Length; } foreach (Weapon objWeapon in objVehicle.Weapons) { sbdWeapons.AppendLine(objWeapon.CurrentDisplayName); } using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdWeaponMounts)) { foreach (WeaponMount objWeaponMount in objVehicle.WeaponMounts) { sbdWeaponMounts.AppendLine(objWeaponMount.CurrentDisplayName); } if (sbdWeaponMounts.Length > 0) { sbdWeaponMounts.Length -= Environment.NewLine.Length; } AvailabilityValue objAvail = objVehicle.TotalAvailTuple(); SourceString strSource = await SourceString.GetSourceStringAsync( objVehicle.Source, objVehicle.DisplayPage(GlobalSettings.Language), GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); NuyenString strCost = new NuyenString( objVehicle.TotalCost.ToString(GlobalSettings.CultureInfo)); tabVehicles.Rows.Add(strID, strVehicleName, strAccel, strArmor, strBody, strHandling, strPilot, strSensor, strSpeed, strSeats, sbdGear.ToString(), sbdMods.ToString(), sbdWeapons.ToString(), sbdWeaponMounts.ToString(), objAvail, strSource, strCost); } } } } } } await dgvVehicles.DoThreadSafeAsync(x => { x.Columns[0].Visible = false; x.Columns[13].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight; x.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; DataSet set = new DataSet("vehicles"); set.Tables.Add(tabVehicles); x.DataSource = set; x.DataMember = "vehicles"; }); } else { string strSpace = await LanguageManager.GetStringAsync("String_Space"); using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool, out List <ListItem> lstVehicles)) { foreach (XPathNavigator objXmlVehicle in objXmlVehicleList) { if (blnHideOverAvailLimit && !objXmlVehicle.CheckAvailRestriction(_objCharacter)) { ++intOverLimit; continue; } if (!blnFreeItem && blnShowOnlyAffordItems) { decimal decCostMultiplier = decBaseCostMultiplier; if (blnBlackMarketDiscount && _setBlackMarketMaps.Contains((await objXmlVehicle .SelectSingleNodeAndCacheExpressionAsync( "category")) ?.Value)) { decCostMultiplier *= 0.9m; } if (Vehicle.DoesDealerConnectionApply(_setDealerConnectionMaps, (await objXmlVehicle .SelectSingleNodeAndCacheExpressionAsync( "category")) ?.Value)) { decCostMultiplier *= 0.9m; } if (!objXmlVehicle.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier)) { ++intOverLimit; continue; } } string strDisplayname = (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("translate"))?.Value ?? (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("name"))?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); if (!GlobalSettings.SearchInCategoryOnly && blnHasSearch) { string strCategory = (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("category"))?.Value; if (!string.IsNullOrEmpty(strCategory)) { ListItem objFoundItem = _lstCategory.Find(objFind => objFind.Value.ToString() == strCategory); if (!string.IsNullOrEmpty(objFoundItem.Name)) { strDisplayname += strSpace + '[' + objFoundItem.Name + ']'; } } } lstVehicles.Add(new ListItem( (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("id")) ?.Value ?? string.Empty, strDisplayname)); } lstVehicles.Sort(CompareListItems.CompareNames); if (intOverLimit > 0) { // Add after sort so that it's always at the end lstVehicles.Add(new ListItem(string.Empty, string.Format(GlobalSettings.CultureInfo, await LanguageManager.GetStringAsync( "String_RestrictedItemsHidden"), intOverLimit))); } string strOldSelected = await lstVehicle.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()); _blnLoading = true; await lstVehicle.PopulateWithListItemsAsync(lstVehicles); _blnLoading = false; await lstVehicle.DoThreadSafeAsync(x => { if (string.IsNullOrEmpty(strOldSelected)) { x.SelectedIndex = -1; } else { x.SelectedValue = strOldSelected; } }); } } } finally { await this.DoThreadSafeAsync(x => x.ResumeLayout()); } }
private void UpdateGearInfo(bool blnUpdateMountCBOs = true) { 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.CleanXPath() + "]"); } 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 strSpace = LanguageManager.GetString("String_Space"); 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 && !xmlAccessory.CheckAvailRestriction(_objCharacter, nudRating.MaximumAsInt)) { 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 && !xmlAccessory.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier, nudRating.MaximumAsInt)) { 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; } if (blnUpdateMountCBOs) { string strDataMounts = xmlAccessory.SelectSingleNode("mount")?.Value; List <string> strMounts = new List <string>(); if (!string.IsNullOrEmpty(strDataMounts)) { strMounts.AddRange(strDataMounts.SplitNoAlloc('/', StringSplitOptions.RemoveEmptyEntries)); } 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.SplitNoAlloc('/', StringSplitOptions.RemoveEmptyEntries)) { 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. lblAvail.Text = new AvailabilityValue(Convert.ToInt32(nudRating.Value), xmlAccessory.SelectSingleNode("avail")?.Value).ToString(); 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)) .CheapReplace("Weapon Total Cost", () => _objParentWeapon.MultipliableCost(null).ToString(GlobalOptions.InvariantCultureInfo)) .Replace("Rating", nudRating.Value.ToString(GlobalOptions.CultureInfo)); } if (strCost.StartsWith("Variable(", StringComparison.Ordinal)) { decimal decMin; decimal decMax = decimal.MaxValue; strCost = strCost.TrimStartOnce("Variable(", true).TrimEndOnce(')'); if (strCost.Contains('-')) { string[] strValues = strCost.Split('-'); decimal.TryParse(strValues[0], NumberStyles.Any, 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) + strSpace + '-' + strSpace + 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; } decCost *= _objParentWeapon.AccessoryMultiplier; if (!string.IsNullOrEmpty(_objParentWeapon.DoubledCostModificationSlots)) { string[] astrParentDoubledCostModificationSlots = _objParentWeapon.DoubledCostModificationSlots.Split('/', StringSplitOptions.RemoveEmptyEntries); if (astrParentDoubledCostModificationSlots.Contains(cboMount.SelectedItem?.ToString()) || astrParentDoubledCostModificationSlots.Contains(cboExtraMount.SelectedItem?.ToString())) { decCost *= 2; } } 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); } lblRatingLabel.Text = xmlAccessory.SelectSingleNode("ratinglabel") != null ? string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("Label_RatingFormat"), LanguageManager.GetString(xmlAccessory.SelectSingleNode("ratinglabel").Value)) : LanguageManager.GetString("Label_Rating"); lblCostLabel.Visible = !string.IsNullOrEmpty(lblCost.Text); lblTestLabel.Visible = !string.IsNullOrEmpty(lblTest.Text); if (!chkBlackMarketDiscount.Checked) { chkBlackMarketDiscount.Checked = GlobalOptions.AssumeBlackMarket && _blnIsParentWeaponBlackMarketAllowed; } else if (!_blnIsParentWeaponBlackMarketAllowed) { //Prevent chkBlackMarketDiscount from being checked if the gear category doesn't match. chkBlackMarketDiscount.Checked = false; } chkBlackMarketDiscount.Enabled = _blnIsParentWeaponBlackMarketAllowed; string strSource = xmlAccessory.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown"); string strPage = xmlAccessory.SelectSingleNode("altpage")?.Value ?? xmlAccessory.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown"); SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter); objSourceString.SetControl(lblSource); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); }
private void lstComplexForms_SelectedIndexChanged(object sender, EventArgs e) { string strSelectedComplexFormId = lstComplexForms.SelectedValue?.ToString(); if (_blnLoading || string.IsNullOrEmpty(strSelectedComplexFormId)) { tlpRight.Visible = false; return; } // Display the Complex Form information. XPathNavigator xmlComplexForm = _xmlBaseComplexFormsNode.SelectSingleNode("complexform[id = " + strSelectedComplexFormId.CleanXPath() + ']'); if (xmlComplexForm == null) { tlpRight.Visible = false; return; } SuspendLayout(); switch (xmlComplexForm.SelectSingleNode("duration")?.Value) { case "P": lblDuration.Text = LanguageManager.GetString("String_SpellDurationPermanent"); break; case "S": lblDuration.Text = LanguageManager.GetString("String_SpellDurationSustained"); break; case "Special": lblDuration.Text = LanguageManager.GetString("String_SpellDurationSpecial"); break; default: lblDuration.Text = LanguageManager.GetString("String_SpellDurationInstant"); break; } switch (xmlComplexForm.SelectSingleNode("target")?.Value) { case "Persona": lblTarget.Text = LanguageManager.GetString("String_ComplexFormTargetPersona"); break; case "Device": lblTarget.Text = LanguageManager.GetString("String_ComplexFormTargetDevice"); break; case "File": lblTarget.Text = LanguageManager.GetString("String_ComplexFormTargetFile"); break; case "Self": lblTarget.Text = LanguageManager.GetString("String_SpellRangeSelf"); break; case "Sprite": lblTarget.Text = LanguageManager.GetString("String_ComplexFormTargetSprite"); break; case "Host": lblTarget.Text = LanguageManager.GetString("String_ComplexFormTargetHost"); break; case "IC": lblTarget.Text = LanguageManager.GetString("String_ComplexFormTargetIC"); break; default: lblTarget.Text = LanguageManager.GetString("String_None"); break; } string strFv = xmlComplexForm.SelectSingleNode("fv")?.Value.Replace('/', '÷').Replace('*', '×') ?? string.Empty; if (!GlobalSettings.Language.Equals(GlobalSettings.DefaultLanguage, StringComparison.OrdinalIgnoreCase)) { strFv = strFv.CheapReplace("L", () => LanguageManager.GetString("String_ComplexFormLevel")) .CheapReplace("Overflow damage", () => LanguageManager.GetString("String_SpellOverflowDamage")) .CheapReplace("Damage Value", () => LanguageManager.GetString("String_SpellDamageValue")) .CheapReplace("Toxin DV", () => LanguageManager.GetString("String_SpellToxinDV")) .CheapReplace("Disease DV", () => LanguageManager.GetString("String_SpellDiseaseDV")) .CheapReplace("Radiation Power", () => LanguageManager.GetString("String_SpellRadiationPower")); } lblFV.Text = strFv; string strSource = xmlComplexForm.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown"); string strPage = xmlComplexForm.SelectSingleNodeAndCacheExpression("altpage")?.Value ?? xmlComplexForm.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown"); SourceString objSource = new SourceString(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); lblSource.Text = objSource.ToString(); lblSource.SetToolTip(objSource.LanguageBookTooltip); lblDurationLabel.Visible = !string.IsNullOrEmpty(lblDuration.Text); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); lblFVLabel.Visible = !string.IsNullOrEmpty(lblFV.Text); lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text); tlpRight.Visible = true; ResumeLayout(); }
/// <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; } }
/// <summary> /// Create a Quality from an XmlNode. /// </summary> /// <param name="objXmlQuality">XmlNode to create the object from.</param> /// <param name="objQualitySource">Source of the Quality.</param> /// <param name="lstWeapons">List of Weapons that should be added to the Character.</param> /// <param name="strForceValue">Force a value to be selected for the Quality.</param> /// <param name="strSourceName">Friendly name for the improvement that added this quality.</param> public void Create(XmlNode objXmlQuality, QualitySource objQualitySource, IList <Weapon> lstWeapons, string strForceValue = "", string strSourceName = "") { _strSourceName = strSourceName; objXmlQuality.TryGetStringFieldQuickly("name", ref _strName); objXmlQuality.TryGetBoolFieldQuickly("metagenetic", ref _blnMetagenetic); if (!objXmlQuality.TryGetStringFieldQuickly("altnotes", ref _strNotes)) { objXmlQuality.TryGetStringFieldQuickly("notes", ref _strNotes); } objXmlQuality.TryGetInt32FieldQuickly("karma", ref _intBP); _eQualityType = ConvertToQualityType(objXmlQuality["category"]?.InnerText); _eQualitySource = objQualitySource; objXmlQuality.TryGetBoolFieldQuickly("doublecareer", ref _blnDoubleCostCareer); objXmlQuality.TryGetBoolFieldQuickly("canbuywithspellpoints", ref _blnCanBuyWithSpellPoints); objXmlQuality.TryGetBoolFieldQuickly("print", ref _blnPrint); objXmlQuality.TryGetBoolFieldQuickly("implemented", ref _blnImplemented); objXmlQuality.TryGetBoolFieldQuickly("contributetolimit", ref _blnContributeToLimit); objXmlQuality.TryGetStringFieldQuickly("source", ref _strSource); objXmlQuality.TryGetStringFieldQuickly("page", ref _strPage); _blnMutant = objXmlQuality["mutant"] != null; if (_eQualityType == QualityType.LifeModule) { objXmlQuality.TryGetStringFieldQuickly("stage", ref _strStage); } if (objXmlQuality.TryGetField("id", Guid.TryParse, out Guid guiTemp)) { _guiQualityId = guiTemp; _objCachedMyXmlNode = null; } // Add Weapons if applicable. // More than one Weapon can be added, so loop through all occurrences. using (XmlNodeList xmlAddWeaponList = objXmlQuality.SelectNodes("addweapon")) if (xmlAddWeaponList?.Count > 0) { XmlDocument objXmlWeaponDocument = XmlManager.Load("weapons.xml"); foreach (XmlNode objXmlAddWeapon in xmlAddWeaponList) { string strLoopID = objXmlAddWeapon.InnerText; XmlNode objXmlWeapon = strLoopID.IsGuid() ? objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[id = \"" + strLoopID + "\"]") : objXmlWeaponDocument.SelectSingleNode("/chummer/weapons/weapon[name = \"" + strLoopID + "\"]"); Weapon objGearWeapon = new Weapon(_objCharacter); objGearWeapon.Create(objXmlWeapon, lstWeapons); objGearWeapon.ParentID = InternalId; objGearWeapon.Cost = "0"; lstWeapons.Add(objGearWeapon); Guid.TryParse(objGearWeapon.InternalId, out _guiWeaponID); } } using (XmlNodeList xmlNaturalWeaponList = objXmlQuality.SelectNodes("naturalweapons/naturalweapon")) if (xmlNaturalWeaponList?.Count > 0) { foreach (XmlNode objXmlNaturalWeapon in xmlNaturalWeaponList) { Weapon objWeapon = new Weapon(_objCharacter); if (objXmlNaturalWeapon["name"] != null) { objWeapon.Name = objXmlNaturalWeapon["name"].InnerText; } objWeapon.Category = LanguageManager.GetString("Tab_Critter", GlobalOptions.Language); objWeapon.WeaponType = "Melee"; if (objXmlNaturalWeapon["reach"] != null) { objWeapon.Reach = Convert.ToInt32(objXmlNaturalWeapon["reach"].InnerText); } if (objXmlNaturalWeapon["accuracy"] != null) { objWeapon.Accuracy = objXmlNaturalWeapon["accuracy"].InnerText; } if (objXmlNaturalWeapon["damage"] != null) { objWeapon.Damage = objXmlNaturalWeapon["damage"].InnerText; } if (objXmlNaturalWeapon["ap"] != null) { objWeapon.AP = objXmlNaturalWeapon["ap"].InnerText; } objWeapon.Mode = "0"; objWeapon.RC = "0"; objWeapon.Concealability = 0; objWeapon.Avail = "0"; objWeapon.Cost = "0"; if (objXmlNaturalWeapon["useskill"] != null) { objWeapon.UseSkill = objXmlNaturalWeapon["useskill"].InnerText; } if (objXmlNaturalWeapon["source"] != null) { objWeapon.Source = objXmlNaturalWeapon["source"].InnerText; } if (objXmlNaturalWeapon["page"] != null) { objWeapon.Page = objXmlNaturalWeapon["page"].InnerText; } _objCharacter.Weapons.Add(objWeapon); } } _nodDiscounts = objXmlQuality["costdiscount"]; // If the item grants a bonus, pass the information to the Improvement Manager. _nodBonus = objXmlQuality["bonus"]; if (_nodBonus?.ChildNodes.Count > 0) { ImprovementManager.ForcedValue = strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Quality, InternalId, _nodBonus, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } if (!string.IsNullOrEmpty(ImprovementManager.SelectedValue)) { _strExtra = ImprovementManager.SelectedValue; } } else if (!string.IsNullOrEmpty(strForceValue)) { _strExtra = strForceValue; } _nodFirstLevelBonus = objXmlQuality["firstlevelbonus"]; if (_nodFirstLevelBonus?.ChildNodes.Count > 0 && Levels == 0) { ImprovementManager.ForcedValue = string.IsNullOrEmpty(strForceValue) ? Extra : strForceValue; if (!ImprovementManager.CreateImprovements(_objCharacter, Improvement.ImprovementSource.Quality, InternalId, _nodFirstLevelBonus, false, 1, DisplayNameShort(GlobalOptions.Language))) { _guiID = Guid.Empty; return; } } if (string.IsNullOrEmpty(Notes)) { string strEnglishNameOnPage = Name; string strNameOnPage = string.Empty; // make sure we have something and not just an empty tag if (objXmlQuality.TryGetStringFieldQuickly("nameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage)) { strEnglishNameOnPage = strNameOnPage; } string strQualityNotes = CommonFunctions.GetTextFromPDF($"{Source} {Page}", strEnglishNameOnPage); if (string.IsNullOrEmpty(strQualityNotes) && GlobalOptions.Language != GlobalOptions.DefaultLanguage) { string strTranslatedNameOnPage = DisplayName(GlobalOptions.CultureInfo, GlobalOptions.Language); // don't check again it is not translated if (strTranslatedNameOnPage != _strName) { // if we found <altnameonpage>, and is not empty and not the same as english we must use that instead if (objXmlQuality.TryGetStringFieldQuickly("altnameonpage", ref strNameOnPage) && !string.IsNullOrEmpty(strNameOnPage) && strNameOnPage != strEnglishNameOnPage) { strTranslatedNameOnPage = strNameOnPage; } Notes = CommonFunctions.GetTextFromPDF($"{Source} {DisplayPage(GlobalOptions.Language)}", strTranslatedNameOnPage); } } else { Notes = strQualityNotes; } } SourceDetail = new SourceString(_strSource, _strPage); }