public bool Expend(int value) { int expended = Math.Min(value, CurrentValue); if (expended == 0) { return(CurrentValue == 0); } CurrentValue -= expended; OnValueChanged?.Invoke(CurrentValue + expended, CurrentValue); _decayCounter += expended; int decay = _decayRate == 0 ? 0 : _decayCounter / _decayRate; CurrentCapacity -= decay; OnCapacityChanged?.Invoke(CurrentCapacity + decay, CurrentCapacity); if (_decayRate != 0) { _decayCounter %= _decayRate; } if (CurrentValue <= 0) { OnDeplete?.Invoke(); } return(expended == value); }
public void Exhaust(int value) { CurrentValue -= value; CurrentCapacity -= value; OnValueChanged?.Invoke(CurrentValue + value, CurrentValue); OnCapacityChanged?.Invoke(CurrentCapacity + value, CurrentCapacity); }