/// <summary> /// Calculates the remaining <see cref="TimeSpan"/> until the thing's exhaustion is over. /// </summary> /// <param name="thing">The thing to check the conditions on.</param> /// <param name="exhaustionType">The type of condition.</param> /// <param name="currentTime">The current time to calculate from.</param> /// <returns>The <see cref="TimeSpan"/> result.</returns> public static TimeSpan RemainingExhaustionTime(this IThing thing, ExhaustionType exhaustionType, DateTimeOffset currentTime) { thing.ThrowIfNull(nameof(thing)); if (!thing.IsExhausted(exhaustionType)) { return(TimeSpan.Zero); } var exhaustionCondition = thing.TrackedEvents[ConditionType.Exhausted.ToString()] as IExhaustionCondition; if (!exhaustionCondition.ExhaustionTimesPerType.TryGetValue(exhaustionType, out DateTimeOffset exhaustionEndTime)) { return(TimeSpan.Zero); } var timeLeft = exhaustionEndTime - currentTime; return(timeLeft < TimeSpan.Zero ? TimeSpan.Zero : timeLeft); }