/// <summary> /// If this item has an attribute array, refresh it. /// </summary> public static void RefreshMatrixAttributeArray(this IHasMatrixAttributes objThis, Character objCharacter) { if (objThis == null) { return; } if (objThis.CanSwapAttributes) { int intBaseAttack = objThis.GetBaseMatrixAttribute("Attack"); int intBaseSleaze = objThis.GetBaseMatrixAttribute("Sleaze"); int intBaseDataProcessing = objThis.GetBaseMatrixAttribute("Data Processing"); int intBaseFirewall = objThis.GetBaseMatrixAttribute("Firewall"); List <int> lstStatsArray = new List <int>(4) { intBaseAttack, intBaseSleaze, intBaseDataProcessing, intBaseFirewall }; lstStatsArray.Sort(); lstStatsArray.Reverse(); string[] strCyberdeckArray = objThis.AttributeArray.Split(','); using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdCyberdeckArray0)) using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdCyberdeckArray1)) using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdCyberdeckArray2)) using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdCyberdeckArray3)) { sbdCyberdeckArray0.Append(strCyberdeckArray[0]); sbdCyberdeckArray1.Append(strCyberdeckArray[1]); sbdCyberdeckArray2.Append(strCyberdeckArray[2]); sbdCyberdeckArray3.Append(strCyberdeckArray[3]); StringBuilder[] asbdCyberdeckArray = { sbdCyberdeckArray0, sbdCyberdeckArray1, sbdCyberdeckArray2, sbdCyberdeckArray3 }; foreach (string strLoopArrayText in objThis.ChildrenWithMatrixAttributes.Select( x => x.ModAttributeArray)) { if (string.IsNullOrEmpty(strLoopArrayText)) { continue; } string[] strLoopArray = strLoopArrayText.Split(','); for (int i = 0; i < 4; ++i) { asbdCyberdeckArray[i].Append("+(").Append(strLoopArray[i]).Append(')'); } } for (int i = 0; i < 4; ++i) { if (intBaseAttack == lstStatsArray[i]) { objThis.Attack = asbdCyberdeckArray[i].ToString(); lstStatsArray[i] = int.MinValue; break; } } for (int i = 0; i < 4; ++i) { if (intBaseSleaze == lstStatsArray[i]) { objThis.Sleaze = asbdCyberdeckArray[i].ToString(); lstStatsArray[i] = int.MinValue; break; } } for (int i = 0; i < 4; ++i) { if (intBaseDataProcessing == lstStatsArray[i]) { objThis.DataProcessing = asbdCyberdeckArray[i].ToString(); lstStatsArray[i] = int.MinValue; break; } } for (int i = 0; i < 4; ++i) { if (intBaseFirewall == lstStatsArray[i]) { objThis.Firewall = asbdCyberdeckArray[i].ToString(); break; } } } } if (objCharacter != null) { if (objThis.IsActiveCommlink(objCharacter)) { if (objThis.IsHomeNode(objCharacter)) { objCharacter.OnMultiplePropertyChanged(nameof(Character.MatrixInitiativeValue), nameof(Character.MatrixInitiativeColdValue), nameof(Character.MatrixInitiativeHotValue)); } else { objCharacter.OnMultiplePropertyChanged(nameof(Character.MatrixInitiativeColdValue), nameof(Character.MatrixInitiativeHotValue)); } } else { objCharacter.OnPropertyChanged(nameof(Character.MatrixInitiativeValue)); } } }
public static bool ProcessMatrixAttributeCBOChange(this IHasMatrixAttributes objThis, Character objCharacter, ComboBox cboChangedAttributeCBO, ComboBox cboAttack, ComboBox cboSleaze, ComboBox cboDP, ComboBox cboFirewall) { if (objThis == null) { return(false); } if (objCharacter == null) { throw new ArgumentNullException(nameof(objCharacter)); } if (cboChangedAttributeCBO == null) { throw new ArgumentNullException(nameof(cboChangedAttributeCBO)); } if (cboAttack == null) { throw new ArgumentNullException(nameof(cboAttack)); } if (cboSleaze == null) { throw new ArgumentNullException(nameof(cboSleaze)); } if (cboDP == null) { throw new ArgumentNullException(nameof(cboDP)); } if (cboFirewall == null) { throw new ArgumentNullException(nameof(cboFirewall)); } string strTemp; Action <string> funcAttributePropertySetter; if (cboChangedAttributeCBO == cboAttack) { strTemp = objThis.Attack; funcAttributePropertySetter = (x => objThis.Attack = x); } else if (cboChangedAttributeCBO == cboSleaze) { strTemp = objThis.Sleaze; funcAttributePropertySetter = (x => objThis.Sleaze = x); } else if (cboChangedAttributeCBO == cboDP) { strTemp = objThis.DataProcessing; funcAttributePropertySetter = (x => objThis.DataProcessing = x); } else if (cboChangedAttributeCBO == cboFirewall) { strTemp = objThis.Firewall; funcAttributePropertySetter = (x => objThis.Firewall = x); } else { return(false); } int intCurrentIndex = cboChangedAttributeCBO.SelectedIndex; bool blnRefreshCharacter = false; // Find the combo with the same value as this one and change it to the missing value. if (cboChangedAttributeCBO != cboAttack && cboAttack.SelectedIndex == intCurrentIndex) { funcAttributePropertySetter.Invoke(objThis.Attack); objThis.Attack = strTemp; blnRefreshCharacter = true; } else if (cboChangedAttributeCBO != cboSleaze && cboSleaze.SelectedIndex == intCurrentIndex) { funcAttributePropertySetter.Invoke(objThis.Sleaze); objThis.Sleaze = strTemp; blnRefreshCharacter = true; } else if (cboChangedAttributeCBO != cboDP && cboDP.SelectedIndex == intCurrentIndex) { funcAttributePropertySetter.Invoke(objThis.DataProcessing); objThis.DataProcessing = strTemp; blnRefreshCharacter = true; } else if (cboChangedAttributeCBO != cboFirewall && cboFirewall.SelectedIndex == intCurrentIndex) { funcAttributePropertySetter.Invoke(objThis.Firewall); objThis.Firewall = strTemp; blnRefreshCharacter = true; } if (blnRefreshCharacter) { objThis.RefreshMatrixAttributeCBOs(cboAttack, cboSleaze, cboDP, cboFirewall); } return(blnRefreshCharacter && (objThis.IsActiveCommlink(objCharacter) || objThis.IsHomeNode(objCharacter))); }
public static async Task <bool> ProcessMatrixAttributeComboBoxChangeAsync(this IHasMatrixAttributes objThis, Character objCharacter, ElasticComboBox cboChangedAttribute, ElasticComboBox cboAttack, ElasticComboBox cboSleaze, ElasticComboBox cboDataProcessing, ElasticComboBox cboFirewall, CancellationToken token = default) { token.ThrowIfCancellationRequested(); if (objThis == null) { return(false); } if (objCharacter == null) { throw new ArgumentNullException(nameof(objCharacter)); } if (cboChangedAttribute == null) { throw new ArgumentNullException(nameof(cboChangedAttribute)); } if (cboAttack == null) { throw new ArgumentNullException(nameof(cboAttack)); } if (cboSleaze == null) { throw new ArgumentNullException(nameof(cboSleaze)); } if (cboDataProcessing == null) { throw new ArgumentNullException(nameof(cboDataProcessing)); } if (cboFirewall == null) { throw new ArgumentNullException(nameof(cboFirewall)); } string strTemp; Action <string> funcAttributePropertySetter; if (cboChangedAttribute == cboAttack) { strTemp = objThis.Attack; funcAttributePropertySetter = (x => objThis.Attack = x); } else if (cboChangedAttribute == cboSleaze) { strTemp = objThis.Sleaze; funcAttributePropertySetter = (x => objThis.Sleaze = x); } else if (cboChangedAttribute == cboDataProcessing) { strTemp = objThis.DataProcessing; funcAttributePropertySetter = (x => objThis.DataProcessing = x); } else if (cboChangedAttribute == cboFirewall) { strTemp = objThis.Firewall; funcAttributePropertySetter = (x => objThis.Firewall = x); } else { return(false); } int intCurrentIndex = await cboChangedAttribute.DoThreadSafeFuncAsync(x => x.SelectedIndex, token); bool blnRefreshCharacter = false; bool blnDPChanged = cboChangedAttribute == cboDataProcessing; // Find the combo with the same value as this one and change it to the missing value. if (cboChangedAttribute != cboAttack && await cboAttack.DoThreadSafeFuncAsync(x => x.SelectedIndex, token) == intCurrentIndex) { funcAttributePropertySetter.Invoke(objThis.Attack); objThis.Attack = strTemp; blnRefreshCharacter = true; } else if (cboChangedAttribute != cboSleaze && await cboSleaze.DoThreadSafeFuncAsync(x => x.SelectedIndex, token) == intCurrentIndex) { funcAttributePropertySetter.Invoke(objThis.Sleaze); objThis.Sleaze = strTemp; blnRefreshCharacter = true; } else if (!blnDPChanged && await cboDataProcessing.DoThreadSafeFuncAsync(x => x.SelectedIndex, token) == intCurrentIndex) { funcAttributePropertySetter.Invoke(objThis.DataProcessing); objThis.DataProcessing = strTemp; blnRefreshCharacter = true; blnDPChanged = true; } else if (cboChangedAttribute != cboFirewall && await cboFirewall.DoThreadSafeFuncAsync(x => x.SelectedIndex, token) == intCurrentIndex) { funcAttributePropertySetter.Invoke(objThis.Firewall); objThis.Firewall = strTemp; blnRefreshCharacter = true; } if (blnRefreshCharacter) { await objThis.RefreshMatrixAttributeComboBoxesAsync(cboAttack, cboSleaze, cboDataProcessing, cboFirewall, token); if (objThis.IsActiveCommlink(objCharacter) || objThis.IsHomeNode(objCharacter)) { if (blnDPChanged) { if (objThis.IsActiveCommlink(objCharacter)) { if (objThis.IsHomeNode(objCharacter)) { objCharacter.OnMultiplePropertyChanged(nameof(Character.MatrixInitiativeValue), nameof(Character.MatrixInitiativeColdValue), nameof(Character.MatrixInitiativeHotValue)); } else { objCharacter.OnMultiplePropertyChanged(nameof(Character.MatrixInitiativeColdValue), nameof(Character.MatrixInitiativeHotValue)); } } else { objCharacter.OnPropertyChanged(nameof(Character.MatrixInitiativeValue)); } } return(true); } } return(false); }