Beispiel #1
0
        /// <summary>
        /// Removes a set of skill levels from this plan.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="skillsToRemove">The skill levels to remove.</param>
        /// <returns>
        /// An object allowing to perform and control the removal.
        /// </returns>
        public IPlanOperation TryRemoveSet <T>(IEnumerable <T> skillsToRemove)
            where T : ISkillLevel
        {
            IEnumerable <PlanEntry> allEntriesToRemove = GetAllEntriesToRemove(skillsToRemove);

            // Creates a plan where the entries and their dependencies have been removed
            PlanScratchpad freePlan = new PlanScratchpad(Character);

            freePlan.RebuildPlanFrom(Items);
            foreach (PlanEntry entry in allEntriesToRemove)
            {
                freePlan.Remove(entry);
            }

            // Gather removables prerequisites now useless
            List <PlanEntry> removablePrerequisites = new List <PlanEntry>();

            foreach (PlanEntry prereqEntry in allEntriesToRemove.SelectMany(
                         entryToRemove => Items.Where(entryToRemove.IsDependentOf).Where(
                             prereq => freePlan.GetMinimumLevel(prereq.Skill) == 0).Select(
                             prereq => freePlan.GetEntry(prereq.Skill, prereq.Level)).Where(
                             prereqEntry => prereqEntry != null && prereqEntry.Type == PlanEntryType.Prerequisite)))
            {
                removablePrerequisites.Add(prereqEntry);
                freePlan.Remove(prereqEntry);
            }

            // Create the operation
            return(new PlanOperation(this, skillsToRemove.Cast <ISkillLevel>(), allEntriesToRemove,
                                     removablePrerequisites));
        }
Beispiel #2
0
        /// <summary>
        /// Fetches the items to the given list box.
        /// </summary>
        private void FillListBox <T>(IEnumerable <T> items, ListBox listBox)
            where T : ISkillLevel
        {
            var plan = new PlanScratchpad(m_operation.Plan.Character);

            plan.RebuildPlanFrom(items.Select(x => new PlanEntry(x.Skill, x.Level)));
            plan.Fix();

            listBox.Items.Clear();
            foreach (var entry in plan)
            {
                string name = entry.ToString();
                if (entry.Type == PlanEntryType.Planned)
                {
                    name += " (planned)";
                }

                listBox.Items.Add(name);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Fetches the items to the given list box.
        /// </summary>
        private void FillListBox <T>(IEnumerable <T> items, ListBox listBox)
            where T : ISkillLevel
        {
            var plan = new PlanScratchpad(m_operation.Plan.Character);

            plan.RebuildPlanFrom(items.Select(x => new PlanEntry(x.Skill, x.Level)));
            plan.Fix();

            listBox.Items.Clear();
            foreach (var entry in plan)
            {
                string name = entry.ToString();

                if (m_operation.Type == PlanOperations.Addition)
                {
                    // Skip if the entry is already in the plan
                    if (m_operation.Plan.IsPlanned(entry.Skill, entry.Level))
                    {
                        continue;
                    }
                }
                else
                {
                    // On creation of "entries to remove" listbox (first pass),
                    // skip if entry type is of prerequisite.
                    // "Useless prerequisites" listbox is created on second pass
                    // and in that case entry type is of type planned.
                    if (entry.Type == PlanEntryType.Prerequisite)
                    {
                        continue;
                    }

                    if (entry.Type == PlanEntryType.Planned)
                    {
                        name += " (planned)";
                    }
                }

                listBox.Items.Add(name);
            }
        }