Пример #1
0
        // Helpers.MobilePartyHelper
        public static FlattenedTroopRoster GetStrongestAndPriorTroops(MobileParty mobileParty, int maxTroopCount, List <Hero> includeList)
        {
            TroopRoster          troopRoster  = TroopRoster.CreateDummyTroopRoster();
            FlattenedTroopRoster memberRoster = mobileParty.MemberRoster.ToFlattenedRoster();

            memberRoster.RemoveIf((x) => x.IsWounded);
            List <CharacterObject> list = memberRoster.Select((x) => x.Troop).OrderByDescending((x) => x.Level).ToList <CharacterObject>();

            if (null != includeList && includeList.Count > 0)
            {
                foreach (Hero hero  in includeList)
                {
                    if (list.Any((x) => x == hero.CharacterObject))
                    {
                        list.Remove(hero.CharacterObject);
                        troopRoster.AddToCounts(hero.CharacterObject, 1, false, 0, 0, true, -1);
                        maxTroopCount--;
                    }
                }
            }
            List <CharacterObject> heroList = list.Where((x) => x.IsHero).ToList <CharacterObject>();
            int num = Math.Min(heroList.Count <CharacterObject>(), maxTroopCount);

            for (int i = 0; i < num; i++)
            {
                troopRoster.AddToCounts(heroList[i], 1, false, 0, 0, true, -1);
                list.Remove(heroList[i]);
            }
            return(troopRoster.ToFlattenedRoster());
        }
Пример #2
0
        public static List <FlattenedTroopRosterElement> CreateFlattenedRoster(TroopRoster roster)
        {
            IEnumerable <FlattenedTroopRosterElement> source = from x in roster.ToFlattenedRoster()
                                                               where !x.Troop.IsHero
                                                               select x;

            switch (SortPartyConfig.SortOrder)
            {
            case TroopSortType.TierDesc:
                return((from x in source
                        orderby x.Troop.Tier descending, x.Troop.Name.ToString()
                        select x).ToList());

            case TroopSortType.TierAsc:
                return((from x in source
                        orderby x.Troop.Tier, x.Troop.Name.ToString()
                        select x).ToList());

            case TroopSortType.TierDescType:
                return((from x in source
                        orderby x.Troop.Tier descending, IsMountedUnit(x.Troop), IsRangedUnit(x.Troop), x.Troop.Name.ToString()
                        select x).ToList());

            case TroopSortType.TierAscType:
                return((from x in source
                        orderby x.Troop.Tier, IsMountedUnit(x.Troop), IsRangedUnit(x.Troop), x.Troop.Name.ToString()
                        select x).ToList());

            case TroopSortType.MountRangeTierDesc:
                return((from x in source
                        orderby IsMountedUnit(x.Troop) descending, IsRangedUnit(x.Troop), x.Troop.Tier descending, x.Troop.Name.ToString()
                        select x).ToList());

            case TroopSortType.MountRangeTierAsc:
                return((from x in source
                        orderby IsMountedUnit(x.Troop) descending, IsRangedUnit(x.Troop), x.Troop.Tier, x.Troop.Name.ToString()
                        select x).ToList());

            case TroopSortType.CultureTierDesc:
                return((from x in source
                        orderby x.Troop.Culture.Name.ToString(), x.Troop.Tier descending, x.Troop.Name.ToString()
                        select x).ToList());

            case TroopSortType.CultureTierAsc:
                return((from x in source
                        orderby x.Troop.Culture.Name.ToString(), x.Troop.Tier, x.Troop.Name.ToString()
                        select x).ToList());

            default:
                return((from x in source
                        orderby x.Troop.Tier descending, x.Troop.Name.ToString()
                        select x).ToList());
            }
        }
Пример #3
0
        public static List <FlattenedTroopRosterElement> CreateFlattenedRoster(TroopRoster roster, PartyVM partyVM)
        {
            IEnumerable <FlattenedTroopRosterElement> source = roster.ToFlattenedRoster().Where(a => !a.Troop.IsHero);

            switch (TroopOrderEnum)
            {
            case TroopOrderEnum.rideRangeInfantry:
                source = source.OrderBy(a => a.Troop.IsMounted).ThenBy(a => a.Troop.IsArcher).ThenByDescending(a => a.Troop.Tier);

                break;
            }

            TroopOrderEnum = (TroopOrderEnum)(((int)TroopOrderEnum + 1) % 1);

            return(source.ToList());
        }
Пример #4
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());
        }
Пример #5
0
        internal void CECaptorHuntPrisoners(MenuCallbackArgs args, int amount = 20)
        {
            CEPersistence.animationPlayEvent = false;

            TroopRoster releasedPrisoners = TroopRoster.CreateDummyTroopRoster();

            if (CESettings.Instance != null)
            {
                amount = CESettings.Instance.AmountOfTroopsForHunt;
            }

            try
            {
                for (int i = 0; i < amount; i++)
                {
                    TroopRosterElement test = MobileParty.MainParty.PrisonRoster.GetTroopRoster().Where(troop => !troop.Character.IsHero).GetRandomElementInefficiently();

                    if (test.Character == null)
                    {
                        continue;
                    }

                    MobileParty.MainParty.PrisonRoster.RemoveTroop(test.Character);
                    releasedPrisoners.AddToCounts(test.Character, 1, true);
                }
            }
            catch (Exception)
            {
                CECustomHandler.LogToFile("Couldn't find anymore prisoners.");
            }

            if (!releasedPrisoners.GetTroopRoster().IsEmpty())
            {
                CECaptorContinue(args);

                try
                {
                    Clan clan = Clan.BanditFactions.First(clanLooters => clanLooters.StringId == "looters");
                    clan.Banner.SetBannerVisual(Banner.CreateRandomBanner().BannerVisual);

                    Settlement nearest = SettlementHelper.FindNearestSettlement(settlement => { return(true); });

                    MobileParty prisonerParty = BanditPartyComponent.CreateBanditParty("CustomPartyCE_Hunt_" + MBRandom.RandomInt(int.MaxValue), clan, nearest.Hideout, false);

                    PartyTemplateObject defaultPartyTemplate = clan.DefaultPartyTemplate;

                    prisonerParty.InitializeMobileParty(defaultPartyTemplate, MobileParty.MainParty.Position2D, 0.5f, 0.1f, -1);
                    prisonerParty.SetCustomName(new TextObject("{=CEEVENTS1107}Escaped Captives"));

                    prisonerParty.MemberRoster.Clear();
                    prisonerParty.MemberRoster.Add(releasedPrisoners.ToFlattenedRoster());

                    prisonerParty.RecentEventsMorale = -100;
                    prisonerParty.IsActive           = true;
                    prisonerParty.ActualClan         = clan;
                    prisonerParty.Party.Owner        = clan.Leader;
                    prisonerParty.Party.Visuals.SetMapIconAsDirty();

                    prisonerParty.HomeSettlement = nearest;
                    prisonerParty.InitializePartyTrade(0);

                    Hero.MainHero.HitPoints += 40;


                    CECustomHandler.LogToFile(prisonerParty.Leader.Name.ToString());
                    PlayerEncounter.RestartPlayerEncounter(prisonerParty.Party, MobileParty.MainParty.Party, true);
                    StartBattleAction.Apply(MobileParty.MainParty.Party, prisonerParty.Party);
                    PlayerEncounter.Update();

                    CEPersistence.huntState = CEPersistence.HuntState.StartHunt;
                    CampaignMission.OpenBattleMission(PlayerEncounter.GetBattleSceneForMapPosition(MobileParty.MainParty.Position2D));
                }
                catch (Exception)
                {
                    CECaptorKillPrisoners(args, amount);
                }
            }
            else
            {
                CECaptorContinue(args);
            }
        }
Пример #6
0
        internal void CECaptorPrisonerRebel(MenuCallbackArgs args)
        {
            CEPersistence.animationPlayEvent = false;

            TroopRoster releasedPrisoners = TroopRoster.CreateDummyTroopRoster();

            try
            {
                foreach (TroopRosterElement element in MobileParty.MainParty.PrisonRoster.GetTroopRoster())
                {
                    if (element.Character.IsHero)
                    {
                        element.Character.HeroObject.ChangeState(Hero.CharacterStates.Active);
                    }
                }
                releasedPrisoners.Add(MobileParty.MainParty.PrisonRoster.ToFlattenedRoster());
                MobileParty.MainParty.PrisonRoster.Clear();
            }
            catch (Exception)
            {
                CECustomHandler.LogToFile("Couldn't find anymore prisoners.");
            }

            if (!releasedPrisoners.GetTroopRoster().IsEmpty())
            {
                try
                {
                    TroopRosterElement leader = releasedPrisoners.GetTroopRoster().FirstOrDefault(hasHero => hasHero.Character.IsHero);

                    Clan        clan          = null;
                    Settlement  nearest       = null;
                    MobileParty prisonerParty = null;

                    if (leader.Character != null)
                    {
                        clan          = leader.Character.HeroObject.Clan;
                        nearest       = SettlementHelper.FindNearestSettlement(settlement => settlement.OwnerClan == clan) ?? SettlementHelper.FindNearestSettlement(settlement => true);
                        prisonerParty = LordPartyComponent.CreateLordParty("CustomPartyCE_" + MBRandom.RandomInt(int.MaxValue), leader.Character.HeroObject, MobileParty.MainParty.Position2D, 0.5f, nearest);
                    }
                    else
                    {
                        clan = Clan.BanditFactions.First(clanLooters => clanLooters.StringId == "looters");
                        clan.Banner.SetBannerVisual(Banner.CreateRandomBanner().BannerVisual);
                        nearest       = SettlementHelper.FindNearestSettlement(settlement => true);
                        prisonerParty = BanditPartyComponent.CreateBanditParty("CustomPartyCE_" + MBRandom.RandomInt(int.MaxValue), clan, nearest.Hideout, false);
                    }

                    PartyTemplateObject defaultPartyTemplate = clan.DefaultPartyTemplate;

                    prisonerParty.InitializeMobileParty(defaultPartyTemplate, MobileParty.MainParty.Position2D, 0.5f, 0.1f, -1);
                    prisonerParty.SetCustomName(new TextObject("{=CEEVENTS1107}Escaped Captives"));

                    prisonerParty.MemberRoster.Clear();
                    prisonerParty.ActualClan = clan;
                    prisonerParty.MemberRoster.Add(releasedPrisoners.ToFlattenedRoster());
                    prisonerParty.IsActive = true;

                    prisonerParty.HomeSettlement = nearest;
                    prisonerParty.SetMovePatrolAroundPoint(nearest.IsTown
                                       ? nearest.GatePosition
                                       : nearest.Position2D);

                    if (leader.Character != null)
                    {
                        prisonerParty.Party.Owner = leader.Character.HeroObject;
#if BETA
                        prisonerParty.ChangePartyLeader(leader.Character);
#else
                        prisonerParty.ChangePartyLeader(leader.Character, true);
#endif
                    }
                    else
                    {
                        prisonerParty.Party.Owner = clan.Leader;
                    }



                    prisonerParty.RecentEventsMorale = -100;
                    prisonerParty.Aggressiveness     = 0.2f;
                    prisonerParty.InitializePartyTrade(0);

                    Hero.MainHero.HitPoints += 40;

                    CECustomHandler.LogToFile(prisonerParty.Leader.Name.ToString());
                    PlayerEncounter.RestartPlayerEncounter(MobileParty.MainParty.Party, prisonerParty.Party);
                    GameMenu.SwitchToMenu("encounter");
                }
                catch (Exception)
                {
                    CECaptorContinue(args);
                }
            }
            else
            {
                CECaptorContinue(args);
            }
        }