private async void nudBase_ValueChanged(object sender, EventArgs e) { int intValue = await((NumericUpDownEx)sender).DoThreadSafeFuncAsync(x => x.ValueAsInt); if (intValue == _oldBase) { return; } if (!await CanBeMetatypeMax( Math.Max( await nudKarma.DoThreadSafeFuncAsync(x => x.ValueAsInt) + await AttributeObject.FreeBaseAsync + await AttributeObject.RawMinimumAsync + await AttributeObject.AttributeValueModifiersAsync, await AttributeObject.TotalMinimumAsync) + intValue)) { await nudBase.DoThreadSafeAsync(x => { decimal newValue = Math.Max(x.Value - 1, 0); if (newValue > x.Maximum) { newValue = x.Maximum; } if (newValue < x.Minimum) { newValue = x.Minimum; } x.Value = newValue; }); return; } await this.DoThreadSafeAsync(x => x.ValueChanged?.Invoke(this, e)); _oldBase = intValue; }
private async void nudKarma_ValueChanged(object sender, EventArgs e) { int intValue = await((NumericUpDownEx)sender).DoThreadSafeFuncAsync(x => x.ValueAsInt); if (intValue == _oldKarma) { return; } if (!await CanBeMetatypeMax( Math.Max( await nudBase.DoThreadSafeFuncAsync(x => x.ValueAsInt) + await AttributeObject.FreeBaseAsync + await AttributeObject.RawMinimumAsync + await AttributeObject.AttributeValueModifiersAsync, await AttributeObject.TotalMinimumAsync) + intValue)) { // It's possible that the attribute maximum was reduced by an improvement, so confirm the appropriate value to bounce up/down to. int intKarmaMaximum = await AttributeObject.KarmaMaximumAsync; if (_oldKarma > intKarmaMaximum) { _oldKarma = intKarmaMaximum - 1; } if (_oldKarma < 0) { await nudBase.DoThreadSafeAsync(x => { decimal newValue = Math.Max(x.Value - _oldKarma, 0); if (newValue > x.Maximum) { newValue = x.Maximum; } if (newValue < x.Minimum) { newValue = x.Minimum; } x.Value = newValue; }); _oldKarma = 0; } await nudKarma.DoThreadSafeAsync(x => x.Value = _oldKarma); return; } await this.DoThreadSafeAsync(x => x.ValueChanged?.Invoke(this, e)); _oldKarma = intValue; }