Пример #1
0
        /// <summary>
        /// Try to set the priority of the given entries and cancel if a conflict arises.
        /// </summary>
        /// <param name="displayPlan">The m_display plan.</param>
        /// <param name="entries">The list of entries to change priority of</param>
        /// <param name="priority">The new priority to set</param>
        /// <returns>
        /// True when successful, false when a conflict arised.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">entries</exception>
        public bool TrySetPriority(PlanScratchpad displayPlan, IEnumerable <PlanEntry> entries, int priority)
        {
            entries.ThrowIfNull(nameof(entries));

            // Change priorities and make a backup
            Queue <int> oldPriorities = new Queue <int>();

            foreach (PlanEntry entry in entries)
            {
                oldPriorities.Enqueue(entry.Priority);
                entry.Priority = priority;
            }

            // We are rebuilding the plan with the new priorities in order to check them
            RebuildPlanFrom(displayPlan, true);

            // Check priorities
            if (FixPrioritiesOrder(false, false))
            {
                // Priorities are OK we save them and return
                OnChanged(PlanChange.Notification);
                return(true);
            }

            // Failure, restore the priorities
            foreach (PlanEntry entry in entries)
            {
                entry.Priority = oldPriorities.Dequeue();
            }

            // We are rebuilding the plan from the old priorities
            RebuildPlanFrom(displayPlan, true);

            return(false);
        }
Пример #2
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));
        }
Пример #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 (entry.Type == PlanEntryType.Planned)
                {
                    name += " (planned)";
                }

                listBox.Items.Add(name);
            }
        }
Пример #4
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);
            }
        }