public void MakeContainerActive(SearchResultProcessingContainerViewModel container)
 {
     foreach (SearchResultProcessingContainerViewModel x in Containers)
     {
         x.IsActive = x == container;
     }
 }
        private void LoadConfiguration()
        {
            SearchResultProcessingConfiguration config = GlobalData.Instance.Configuration.SearchResultProcessing;

            if (config.Sorting != null)
            {
                Containers.Clear();
                foreach (SearchResultSortItemConfiguration x in config.Sorting)
                {
                    var container = new SearchResultProcessingContainerViewModel(this)
                    {
                        Name = x.Name
                    };

                    foreach (SearchResultSortCriteria criteria in x.Criterias)
                    {
                        container.AddSortItem(new SearchResultSortItemViewModel(container)
                        {
                            SortCriteria = criteria
                        });
                    }

                    Containers.Add(container);
                }

                if (config.ActiveSortingIndex >= 0 && config.ActiveSortingIndex < Containers.Count)
                {
                    MakeContainerActive(Containers[config.ActiveSortingIndex]);
                }
            }
        }
        public SearchResultSortItemViewModel(SearchResultProcessingContainerViewModel parent)
        {
            this.parent = parent;

            MoveSelfUpCommand   = new AnonymousCommand(OnMoveSelfUp);
            MoveSelfDownCommand = new AnonymousCommand(OnMoveSelfDown);
            RemoveSelfCommand   = new AnonymousCommand(OnRemoveSelf);
        }
 public bool RemoveContainer(SearchResultProcessingContainerViewModel container)
 {
     return(ReorganizableCollectionUtilities <SearchResultProcessingContainerViewModel> .Remove(
                Containers,
                container,
                x => SelectedContainer == x,
                () => SelectedContainer = null
                ));
 }
 public bool MoveContainerDown(SearchResultProcessingContainerViewModel container)
 {
     return(ReorganizableCollectionUtilities <SearchResultProcessingContainerViewModel> .MoveDown(
                Containers,
                container,
                () => SelectedContainer,
                x => SelectedContainer = x
                ));
 }
        public void ApplySorting(SearchResultProcessingContainerViewModel container, bool force, int limit = 200)
        {
            if (rawFoundArmorSets == null)
            {
                return;
            }

            IEnumerable <ArmorSetViewModel> result = rawFoundArmorSets;

            if (SearchResultProcessing.ApplySort(ref result, container, force, limit))
            {
                FoundArmorSets = result;
            }
        }
 internal void ApplyContainerRules(SearchResultProcessingContainerViewModel container)
 {
     rootViewModel.ApplySorting(container, false);
 }
        public bool ApplySort(ref IEnumerable <ArmorSetViewModel> input, SearchResultProcessingContainerViewModel container, bool force, int limit)
        {
            if (input == null)
            {
                return(false);
            }

            limit = Math.Max(0, limit);

            if (container == null || container.SortItems.Count == 0)
            {
                if (force == false)
                {
                    return(false);
                }

                input = input
                        .OrderByDescending(x => x.TotalAugmentedDefense)
                        .ThenByDescending(x => x.AdditionalSkills.Length)
                        .ThenByDescending(x => x.SpareSlotCount)
                        .Take(limit)
                        .ToList();

                return(true);
            }

            IOrderedEnumerable <ArmorSetViewModel> result = input.OrderBy(x => 1); // wasting a bit of CPU cycles for productivity purpose :(

            foreach (SearchResultSortCriteria sortCriteria in container.SortItems.Select(x => x.SortCriteria))
            {
                switch (sortCriteria)
                {
                case SearchResultSortCriteria.BaseDefense:
                    result = result.ThenByDescending(x => x.TotalBaseDefense);
                    break;

                case SearchResultSortCriteria.MaxUnaugmentedDefense:
                    result = result.ThenByDescending(x => x.TotalMaxDefense);
                    break;

                case SearchResultSortCriteria.MaxAugmentedDefense:
                    result = result.ThenByDescending(x => x.TotalAugmentedDefense);
                    break;

                case SearchResultSortCriteria.AverageRarity:
                    result = result.ThenBy(x => x.ArmorPieces.Average(a => (float)a.Rarity));
                    break;

                case SearchResultSortCriteria.HighestRarity:
                    result = result.ThenBy(x => x.ArmorPieces.Max(a => a.Rarity));
                    break;

                case SearchResultSortCriteria.TotalRarity:
                    result = result.ThenBy(x => x.TotalRarity);
                    break;

                case SearchResultSortCriteria.SpareSlotCount:
                    result = result.ThenByDescending(x => x.SpareSlotCount);
                    break;

                case SearchResultSortCriteria.SpareSlotSizeSquare:
                    result = result
                             .ThenByDescending(x => x.SpareSlotSizeSquare)
                             .ThenByDescending(x => x.SpareSlots.Count(s => s > 0)); // For same score, gives precedence to slot count. (only 221 and 3--, sets 221 before 3--)
                    break;

                case SearchResultSortCriteria.SpareSlotSizeCube:
                    result = result.ThenByDescending(x => x.SpareSlotSizeCube);
                    break;

                case SearchResultSortCriteria.JewelCount:
                    result = result.ThenBy(x => x.Jewels.Count);
                    break;

                case SearchResultSortCriteria.FireResistance:
                    result = result.ThenByDescending(x => x.TotalFireResistance);
                    break;

                case SearchResultSortCriteria.WaterResistance:
                    result = result.ThenByDescending(x => x.TotalWaterResistance);
                    break;

                case SearchResultSortCriteria.ThunderResistance:
                    result = result.ThenByDescending(x => x.TotalThunderResistance);
                    break;

                case SearchResultSortCriteria.IceResistance:
                    result = result.ThenByDescending(x => x.TotalIceResistance);
                    break;

                case SearchResultSortCriteria.DragonResistance:
                    result = result.ThenByDescending(x => x.TotalDragonResistance);
                    break;

                case SearchResultSortCriteria.AdditionalSkillsCount:
                    result = result.ThenByDescending(x => x.AdditionalSkills.Length);
                    break;

                case SearchResultSortCriteria.AdditionalSkillsTotalLevel:
                    result = result.ThenByDescending(x => x.AdditionalSkillsTotalLevel);
                    break;

                case SearchResultSortCriteria.Optimal:
                    result = result.ThenByDescending(x => x.IsOptimal);
                    break;

                case SearchResultSortCriteria.SubOptimal:
                    result = result.ThenBy(x => x.IsOptimal);
                    break;
                }
            }

            input = result
                    .Take(limit)
                    .ToList();

            return(true);
        }
        public bool ApplySort(ref IEnumerable <ArmorSetViewModel> input, bool force, int limit)
        {
            SearchResultProcessingContainerViewModel activeContainer = Containers.FirstOrDefault(x => x.IsActive);

            return(ApplySort(ref input, activeContainer, force, limit));
        }