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