public void TakeDamage(int damageToTake) { if (!invincibility.isInvincible) { invincibility.BecomeInvicible(inviciblityTime); OnShrink?.Invoke(); } else { // Trying to take damage while invincible. } }
/// <summary> /// Shrinks database transactions and reduces file size on disk /// </summary> /// <returns></returns> public async Task <ShrinkInfo> Shrink() { ShrinkInfo info = null; try { Stream stream = File.GetStream(); List <string> msgs; long position; int count; await WaitForLock(); try { count = _deletedMessages.Count; position = stream.Position; msgs = _deletedMessages.Count > 0 ? new List <string>(_deletedMessages) : new List <string>(); } finally { ReleaseLock(); } info = await _shrinkManager.Shrink(position, msgs); //sync deleted messages array if (info.Successful) { if (count > 0) { await WaitForLock(); try { if (_deletedMessages.Count > count) { _deletedMessages = _deletedMessages.GetRange(count, _deletedMessages.Count - count); } else { _deletedMessages.Clear(); } } finally { ReleaseLock(); } } } OnShrink?.Invoke(this, info); } catch (Exception ex) { if (info == null) { info = new ShrinkInfo(); } info.Error = ex; TriggerError(ErrorHint.Shrink, ex); } return(info); }