/// <summary> /// Gets the time required to train all the prerequisites /// </summary> /// <returns></returns> public static TimeSpan GetTotalTrainingTime(this IEnumerable <SkillLevel> src, Dictionary <Skill, int> alreadyCountedList, ref bool isCurrentlyTraining) { TimeSpan result = TimeSpan.Zero; foreach (var item in src) { Skill skill = item.Skill; isCurrentlyTraining |= skill.IsTraining; // Gets the number of points we're starting from int fromPoints = skill.SkillPoints; if (alreadyCountedList.ContainsKey(skill)) { fromPoints = alreadyCountedList[skill]; } // Gets the number of points we're targeting int toPoints = skill.GetLeftPointsRequiredToLevel(item.Level); if (fromPoints < toPoints) { result += skill.GetTimeSpanForPoints(toPoints - fromPoints); } // Updates the alreadyCountedList alreadyCountedList[skill] = Math.Max(fromPoints, toPoints); // Recursive if (fromPoints < toPoints) { result += skill.Prerequisites.GetTotalTrainingTime(alreadyCountedList, ref isCurrentlyTraining); } } return(result); }