/// <summary> /// Check, among the sequence of skills, the number of them to add to get the best training time. /// Matched skills are then added to the plan and to the suggestions list. /// </summary> /// <param name="attribute"></param> /// <returns></returns> private bool CheckForTimeBenefit(IEnumerable <PlanEntry> entries) { // Gets the skills which are neither known nor planned var entriesToAdd = new List <PlanEntry>(); foreach (var entry in entries) { if (entry.CharacterSkill.Level < entry.Level && !m_plan.IsPlanned(entry.Skill, entry.Level)) { entriesToAdd.Add(entry); } } // Check which is the best level to train int entriesCount = 0; int bestEntriesCount = 0; var bestTime = m_plan.TotalTrainingTime; var testPlan = new PlanScratchpad(m_plan.Character, m_plan); foreach (var entry in entriesToAdd) { // Insert the skill at the best position, making sure its prerequisites are trained first. entriesCount++; testPlan.InsertAtBestPosition(entry.Skill, entry.Level); // Compare the new training time with the old one TimeSpan newTime = testPlan.TotalTrainingTime; if (newTime < bestTime) { bestTime = newTime; bestEntriesCount = entriesCount; } } // Add the suggested entries to the plan and the suggestions list entriesCount = 0; foreach (var entry in entriesToAdd) { // Stop when we reached the desired entries count if (entriesCount == bestEntriesCount) { break; } entriesCount++; m_items.Add(entry); m_plan.InsertAtBestPosition(entry.Skill, entry.Level); } // Returns true if new benefits have been found return(bestEntriesCount != 0); }
/// <summary> /// Optimize the learning skills order /// </summary> /// <param name="baseEntries"></param> /// <param name="startSP"></param> /// <returns></returns> private PlanScratchpad OptimizeLearningSkills(IEnumerable <PlanEntry> baseEntries, int startSP) { var learningPlan = new PlanScratchpad(m_character); var entries = PrepareLearningSkillsInsertionQueue(baseEntries); // Insert all the entries in an optimal order while (entries.Count != 0) { // Pops the next level when there is one, quit otherwise PlanEntry entry = entries.Dequeue(); learningPlan.InsertAtBestPosition(entry.Skill, entry.Level); } return(learningPlan); }