Ejemplo n.º 1
0
        public static string GetSortFieldValue(FlattenedTroopRosterElement element, CustomSortOrder customOrder, MBBindingList <PartyCharacterVM> partyVmUnits)
        {
            switch (customOrder)
            {
            case CustomSortOrder.TierAsc:
            case CustomSortOrder.TierDesc:
                return(element.Troop.Tier.ToString());

            case CustomSortOrder.CultureAsc:
            case CustomSortOrder.CultureDesc:
                return(element.Troop.Culture.Name.ToString());

            case CustomSortOrder.MountedAsc:
            case CustomSortOrder.MountedDesc:
                return(element.Troop.IsMounted ? "1" : "0");

            case CustomSortOrder.MeleeAsc:
            case CustomSortOrder.MeleeDesc:
                return(element.Troop.IsArcher ? "1" : "0");

            case CustomSortOrder.UnitNameAsc:
            case CustomSortOrder.UnitNameDesc:
                return(element.Troop.Name.ToString());

            case CustomSortOrder.UnitCountAsc:
            case CustomSortOrder.UnitCountDesc:
                return(partyVmUnits?.Where(x => x.Character.Name == element.Troop.Name)?.Select(x => x.Number)
                       ?.FirstOrDefault().ToString());

            case CustomSortOrder.CustomUpgradesPathAsc:
            case CustomSortOrder.CustomUpgradesPathDesc:
                var unitHasUpgrade = PartyManagerSettings.Settings.SavedTroopUpgradePaths?.Exists(x =>
                                                                                                  x.UnitName == element.Troop.Name.ToString());
                if (unitHasUpgrade == true)
                {
                    return("1");
                }
                return("0");

            case CustomSortOrder.FormationAsc:
            case CustomSortOrder.FormationDesc:
                var formation = element.Troop?.CurrentFormationClass;
                if (formation != null)
                {
                    return(((int)formation).ToString());
                }
                return(null);

            default:
                return("");
            }
        }
Ejemplo n.º 2
0
        public static List <FlattenedTroopRosterElement> CreateFlattenedRoster(TroopRoster roster, SortType sortType, MBBindingList <PartyCharacterVM> partyVmUnits = null)
        {
            sortType = sortType == SortType.Default ? PartyManagerSettings.Settings.SortOrder : sortType;

            if (sortType == SortType.Default)
            {
                var sortOrder = PartyManagerSettings.Settings.SortOrder;
            }


            var flattenedRoster = roster.ToFlattenedRoster().Where(x => !x.Troop.IsHero);

            if (sortType == SortType.RecruitUpgrade && partyVmUnits != null)
            {
                //Units that can be upgraded
                var recruitUpgradeUnitTypes = partyVmUnits
                                              .Where(x => !x.IsHero && (x.IsTroopRecruitable || (x.IsUpgrade1Available && !x.IsUpgrade1Insufficient) || (x.IsUpgrade2Available && !x.IsUpgrade2Insufficient)))
                                              .Select(x => x.Name).Distinct().ToList();
                //Units that can be upgraded but are missing materials/skills
                var insufficientUpgrades = partyVmUnits
                                           .Where(x => !x.IsHero && ((x.IsUpgrade1Available && x.IsUpgrade1Insufficient) || (x.IsUpgrade2Available && x.IsUpgrade2Insufficient)))
                                           .Select(x => x.Name).Distinct().ToList();
                return(flattenedRoster.OrderByDescending(x => recruitUpgradeUnitTypes.Contains(x.Troop.Name.ToString())).ThenByDescending(x => insufficientUpgrades.Contains(x.Troop.Name.ToString())).ThenByDescending(x => x.Troop.Tier).ThenBy(x => x.Troop.Name.ToString()).ToList());
            }

            switch (sortType)
            {
            case SortType.TierDesc:
                return(flattenedRoster.OrderByDescending(x => x.Troop.Tier)
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());

            case SortType.TierAsc:
                return(flattenedRoster.OrderBy(x => x.Troop.Tier)
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());

            case SortType.TierDescType:
                return(flattenedRoster.OrderByDescending(x => x.Troop.Tier)
                       .ThenByDescending(x => PartyManagerSettings.Settings.CavalryAboveFootmen ? x.Troop.IsMounted : !x.Troop.IsMounted)
                       .ThenBy(x => PartyManagerSettings.Settings.MeleeAboveArchers ? x.Troop.IsArcher : !x.Troop.IsArcher)
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());

            case SortType.TierAscType:
                return(flattenedRoster.OrderBy(x => x.Troop.Tier)
                       .ThenByDescending(x => PartyManagerSettings.Settings.CavalryAboveFootmen ? x.Troop.IsMounted : !x.Troop.IsMounted)
                       .ThenBy(x => PartyManagerSettings.Settings.MeleeAboveArchers ? x.Troop.IsArcher : !x.Troop.IsArcher)
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());

            case SortType.MountRangeTierDesc:
                return(flattenedRoster.OrderByDescending(x => PartyManagerSettings.Settings.CavalryAboveFootmen ? x.Troop.IsMounted : !x.Troop.IsMounted)
                       .ThenBy(x => PartyManagerSettings.Settings.MeleeAboveArchers ? x.Troop.IsArcher : !x.Troop.IsArcher)
                       .ThenByDescending(x => x.Troop.Tier)
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());

            case SortType.MountRangeTierAsc:
                return(flattenedRoster.OrderByDescending(x => PartyManagerSettings.Settings.CavalryAboveFootmen ? x.Troop.IsMounted : !x.Troop.IsMounted)
                       .ThenBy(x => PartyManagerSettings.Settings.MeleeAboveArchers ? x.Troop.IsArcher : !x.Troop.IsArcher)
                       .ThenBy(x => x.Troop.Tier)
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());

            case SortType.CultureTierDesc:
                return(flattenedRoster.OrderBy(x => x.Troop.Culture.Name.ToString())
                       .ThenByDescending(x => x.Troop.Tier)
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());

            case SortType.CultureTierAsc:
                return(flattenedRoster.OrderBy(x => x.Troop.Culture.Name.ToString())
                       .ThenBy(x => x.Troop.Tier)
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());

            case SortType.RangeMountTierDesc:
                return(flattenedRoster.OrderBy(x => PartyManagerSettings.Settings.MeleeAboveArchers ? x.Troop.IsArcher : !x.Troop.IsArcher)
                       .ThenByDescending(x => PartyManagerSettings.Settings.CavalryAboveFootmen ? x.Troop.IsMounted : !x.Troop.IsMounted)
                       .ThenByDescending(x => x.Troop.Tier)
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());

            case SortType.RangeMountTierAsc:
                return(flattenedRoster.OrderBy(x => PartyManagerSettings.Settings.MeleeAboveArchers ? x.Troop.IsArcher : !x.Troop.IsArcher)
                       .ThenByDescending(x => PartyManagerSettings.Settings.CavalryAboveFootmen ? x.Troop.IsMounted : !x.Troop.IsMounted)
                       .ThenBy(x => x.Troop.Tier)
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());

            case SortType.Custom:
                return(flattenedRoster
                       .OrderBy(x => GetSortFieldValue(x, PartyManagerSettings.Settings.CustomSortOrderField1, partyVmUnits), new CustomComparer(PartyManagerSettings.Settings.CustomSortOrderField1))
                       .ThenBy(x => GetSortFieldValue(x, PartyManagerSettings.Settings.CustomSortOrderField2, partyVmUnits), new CustomComparer(PartyManagerSettings.Settings.CustomSortOrderField2))
                       .ThenBy(x => GetSortFieldValue(x, PartyManagerSettings.Settings.CustomSortOrderField3, partyVmUnits), new CustomComparer(PartyManagerSettings.Settings.CustomSortOrderField3))
                       .ThenBy(x => GetSortFieldValue(x, PartyManagerSettings.Settings.CustomSortOrderField4, partyVmUnits), new CustomComparer(PartyManagerSettings.Settings.CustomSortOrderField4))
                       .ThenBy(x => GetSortFieldValue(x, PartyManagerSettings.Settings.CustomSortOrderField5, partyVmUnits), new CustomComparer(PartyManagerSettings.Settings.CustomSortOrderField5))
                       .ToList());

            case SortType.Formation:
                return(flattenedRoster.OrderBy(
                           x => GetSortFieldValue(x, CustomSortOrder.FormationAsc, partyVmUnits),
                           new CustomComparer(CustomSortOrder.FormationAsc)).ToList());

            case SortType.CustomUpgrades:
                var unitNames = PartyManagerSettings.Settings.SavedTroopUpgradePaths.Select(x => x.UnitName);
                return(flattenedRoster.OrderByDescending(x => unitNames.Contains(x.Troop.Name.ToString()))
                       .ThenBy(x => x.Troop.Name.ToString()).ToList());
            }

            return(flattenedRoster.OrderByDescending(x => x.Troop.Tier).ThenBy(x => x.Troop.Name.ToString()).ToList());
        }
Ejemplo n.º 3
0
        public static MBBindingList <PartyCharacterVM> SortVMTroops(MBBindingList <PartyCharacterVM> input, bool sortRecruitUpgrade = false)
        {
            List <PartyCharacterVM> list = null;

            if (sortRecruitUpgrade)
            {
                list = (from x in input
                        where !x.IsHero
                        orderby x.IsTroopRecruitable || (x.IsUpgrade1Available && !x.IsUpgrade1Insufficient) || (x.IsUpgrade2Available && !x.IsUpgrade2Insufficient)descending, (x.IsUpgrade1Available && x.IsUpgrade1Insufficient) || (x.IsUpgrade2Available && x.IsUpgrade2Insufficient)descending, x.Character.Tier descending, x.Character.Name.ToString()
                        select x).ToList();
            }
            else
            {
                switch (SortPartyConfig.SortOrder)
                {
                case TroopSortType.TierDesc:
                    list = (from x in input
                            where !x.IsHero
                            orderby x.Character.Tier descending, x.Character.Name.ToString()
                            select x).ToList();
                    break;

                case TroopSortType.TierAsc:
                    list = (from x in input
                            where !x.IsHero
                            orderby x.Character.Tier, x.Character.Name.ToString()
                            select x).ToList();
                    break;

                case TroopSortType.TierDescType:
                    list = (from x in input
                            where !x.IsHero
                            orderby x.Character.Tier descending, IsMountedUnit(x.Character), IsRangedUnit(x.Character), x.Character.Name.ToString()
                            select x).ToList();
                    break;

                case TroopSortType.TierAscType:
                    list = (from x in input
                            where !x.IsHero
                            orderby x.Character.Tier, IsMountedUnit(x.Character), IsRangedUnit(x.Character), x.Character.Name.ToString()
                            select x).ToList();
                    break;

                case TroopSortType.MountRangeTierDesc:
                    list = (from x in input
                            where !x.IsHero
                            orderby IsMountedUnit(x.Character) descending, IsRangedUnit(x.Character), x.Character.Tier descending, x.Character.Name.ToString()
                            select x).ToList();
                    break;

                case TroopSortType.MountRangeTierAsc:
                    list = (from x in input
                            where !x.IsHero
                            orderby IsMountedUnit(x.Character) descending, IsRangedUnit(x.Character), x.Character.Tier, x.Character.Name.ToString()
                            select x).ToList();
                    break;

                case TroopSortType.CultureTierDesc:
                    list = (from x in input
                            where !x.IsHero
                            orderby x.Character.Culture.Name.ToString(), x.Character.Tier descending, x.Character.Name.ToString()
                            select x).ToList();
                    break;

                case TroopSortType.CultureTierAsc:
                    list = (from x in input
                            where !x.IsHero
                            orderby x.Character.Culture.Name.ToString(), x.Character.Tier, x.Character.Name.ToString()
                            select x).ToList();
                    break;
                }
            }
            if (list != null)
            {
                MBBindingList <PartyCharacterVM> mBBindingList = new MBBindingList <PartyCharacterVM>();
                foreach (PartyCharacterVM item in input.Where((PartyCharacterVM x) => x.IsHero))
                {
                    mBBindingList.Add(item);
                }
                foreach (PartyCharacterVM item2 in list)
                {
                    mBBindingList.Add(item2);
                }
                return(mBBindingList);
            }
            return(input);
        }