Exemplo n.º 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());
        }
Exemplo n.º 2
0
        internal static void TrySplitParty(MobileParty mobileParty)
        {
            if (MilitiaPowerPercent > Globals.Settings.GlobalPowerPercent ||
                mobileParty.MemberRoster.TotalManCount < MinSplitSize ||
                !mobileParty.IsBM() ||
                mobileParty.IsTooBusyToMerge())
            {
                return;
            }


            var roll = Rng.Next(0, 101);

            if (roll > Globals.Settings.RandomSplitChance ||
                mobileParty.Party.MemberRoster.TotalManCount > Math.Max(1, CalculatedMaxPartySize * ReductionFactor))
            {
                return;
            }

            var party1     = TroopRoster.CreateDummyTroopRoster();
            var party2     = TroopRoster.CreateDummyTroopRoster();
            var prisoners1 = TroopRoster.CreateDummyTroopRoster();
            var prisoners2 = TroopRoster.CreateDummyTroopRoster();
            var inventory1 = new ItemRoster();
            var inventory2 = new ItemRoster();

            SplitRosters(mobileParty, party1, party2, prisoners1, prisoners2, inventory1, inventory2);
            CreateSplitMilitias(mobileParty, party1, party2, prisoners1, prisoners2, inventory1, inventory2);
        }
Exemplo n.º 3
0
        public static void Prefix(ref TroopRoster rightMemberRoster)
        {
            if (Settings.Instance.Enabled && Settings.Instance.ApplyInventoryPatch && rightMemberRoster.Contains(Hero.MainHero.CharacterObject))
            {
                //TroopRoster newRoster = new TroopRoster();
                TroopRoster newRoster = TroopRoster.CreateDummyTroopRoster();
                newRoster.Add(rightMemberRoster);
                PatchInventoryDefaults.DefaultCharacterEquipments.Clear();

                foreach (Hero hero in Clan.PlayerClan.Heroes)
                {
                    if (hero.IsAlive && !hero.IsChild && hero != Hero.MainHero && !newRoster.Contains(hero.CharacterObject))
                    {
                        newRoster.AddToCounts(hero.CharacterObject, 1);
                        PatchInventoryDefaults.SetDefault(hero.CharacterObject);
                    }
                }

                foreach (Hero hero in Clan.PlayerClan.Companions)
                {
                    if (hero.IsAlive && hero.IsPlayerCompanion && !newRoster.Contains(hero.CharacterObject))
                    {
                        newRoster.AddToCounts(hero.CharacterObject, 1);
                        PatchInventoryDefaults.SetDefault(hero.CharacterObject);
                    }
                }

                rightMemberRoster = newRoster;
            }
        }
Exemplo n.º 4
0
        private static void SynthesizeBM()
        {
            if (!Globals.Settings.MilitiaSpawn ||
                CalculatedMaxPartySize < Globals.Settings.MinPartySize)
            {
                return;
            }

            for (var i = 0; i < (Globals.Settings.GlobalPowerPercent - MilitiaPowerPercent) / 24f; i++)
            {
                var settlement  = Settlement.All.Where(s => !s.IsVisible).GetRandomElementInefficiently();
                var clan        = Clan.BanditFactions.ToList()[Rng.Next(0, Clan.BanditFactions.Count())];
                var mobileParty = settlement.IsHideout
                    ? BanditPartyComponent.CreateBanditParty("Bandit_Militia", clan, settlement.Hideout, false)
                    : BanditPartyComponent.CreateLooterParty("Bandit_Militia", clan, settlement, false);
                mobileParty.InitializeMobilePartyAroundPosition(clan.DefaultPartyTemplate, settlement.GatePosition, 0);
                var simulatedMergedRoster = TroopRoster.CreateDummyTroopRoster();
                for (var count = 0;
                     count < CalculatedMaxPartySize / Globals.Settings.MinPartySize &&
                     simulatedMergedRoster.TotalManCount < CalculatedMaxPartySize &&
                     NumMountedTroops(simulatedMergedRoster) <= simulatedMergedRoster.TotalManCount / 2;
                     count++)
                {
                    simulatedMergedRoster.Add(mobileParty.MemberRoster);
                }

                var _ = new Militia(mobileParty.Position2D, simulatedMergedRoster, TroopRoster.CreateDummyTroopRoster());
                Trash(mobileParty);
                DoPowerCalculations();
            }
        }
Exemplo n.º 5
0
        internal static void TrySplitParty(MobileParty mobileParty)
        {
            if (GlobalMilitiaPower + mobileParty.Party.TotalStrength > CalculatedGlobalPowerLimit ||
                mobileParty.MemberRoster.TotalManCount < MinSplitSize ||
                !IsBM(mobileParty) ||
                mobileParty.IsTooBusyToMerge())
            {
                return;
            }

            var roll = Rng.NextDouble();

            if (roll <= Globals.Settings.RandomSplitChance ||
                !IsBM(mobileParty) ||
                mobileParty.Party.TotalStrength <= CalculatedMaxPartyStrength * Globals.Settings.StrengthSplitFactor * Variance ||
                mobileParty.Party.MemberRoster.TotalManCount <= CalculatedMaxPartySize * Globals.Settings.SizeSplitFactor * Variance)
            {
                return;
            }

            var party1     = TroopRoster.CreateDummyTroopRoster();
            var party2     = TroopRoster.CreateDummyTroopRoster();
            var prisoners1 = TroopRoster.CreateDummyTroopRoster();
            var prisoners2 = TroopRoster.CreateDummyTroopRoster();
            var inventory1 = new ItemRoster();
            var inventory2 = new ItemRoster();

            SplitRosters(mobileParty, party1, party2, prisoners1, prisoners2, inventory1, inventory2);
            CreateSplitMilitias(mobileParty, party1, party2, prisoners1, prisoners2, inventory1, inventory2);
        }
Exemplo n.º 6
0
        private static void Postfix(Clan clan, ref ExplainedNumber goldChange, bool applyWithdrawals = false)
        {
            foreach (var pair in SlaveEstateBehavior.SlaveEstates)
            {
                int         wage        = 0;
                SlaveEstate slaveEstate = pair.Value;
                Village     village     = pair.Key;
                if (slaveEstate.Guards == null)
                {
                    slaveEstate.Guards = TroopRoster.CreateDummyTroopRoster();
                }
                else
                {
                    foreach (TroopRosterElement troop in slaveEstate.Guards)
                    {
                        wage += troop.Number * troop.Character.TroopWage;
                    }
                }

                if (wage > 0)
                {
                    goldChange.Add(-1 * wage, new TextObject("Wage of slave estate guards at " + village.Name.ToString()));
                }
            }
        }
Exemplo n.º 7
0
 public SlaveEstate()
 {
     _village                    = Settlement.CurrentSettlement.Village;
     _prisoners                  = TroopRoster.CreateDummyTroopRoster();
     _stockpile                  = new ItemRoster();
     _product                    = FindProduct(_village);
     _logs                       = new List <DailyLog>();
     _surgeon_house_level        = 0;
     _overseer_house_level       = 0;
     _tool_repair_workshop_level = 0;
 }
Exemplo n.º 8
0
        private void ExecuteDone()
        {
            TroopRoster troopRoster = TroopRoster.CreateDummyTroopRoster();

            foreach (SpousesSelectTroopsItemVM current in this.Troops)
            {
                if (current.CurrentAmount > 0)
                {
                    troopRoster.AddToCounts(current.Troop.Character, current.CurrentAmount, false, 0, 0, true, -1);
                }
            }
            this.IsEnabled = false;
            this._onDone.DynamicInvokeWithLog(new object[]
            {
                troopRoster
            });
        }
Exemplo n.º 9
0
        private void SelectMainPartyMember(MenuCallbackArgs args, Action nextStep, int maxNum)
        {
            if (null == this._tempMainMobile)
            {
                this._tempMainMobile = MBObjectManager.Instance.CreateObject <MobileParty>("sms_sneak_temp_party");
            }
            else
            {
                this._tempMainMobile.MemberRoster.Reset();
            }

            int count = MobileParty.MainParty.MemberRoster.Count;

            TroopRoster strongestTroopRoster = TroopRoster.CreateDummyTroopRoster();
            List <Hero> includeHeros         = new List <Hero>();

            includeHeros.Add(Hero.MainHero);

            FlattenedTroopRoster strongestAndPriorTroops = GameComponent.GetStrongestAndPriorTroops(MobileParty.MainParty, maxNum, includeHeros);

            strongestTroopRoster.Add(strongestAndPriorTroops);
            bool execueted = OpenSlelectTroops(args, strongestTroopRoster, maxNum, new Func <CharacterObject, bool>(this.CanChangeStatusOfTroop), new Action <TroopRoster>((troop) => {
                DealPatyTroop(troop);
                nextStep();
            }));

            if (!execueted)
            {               //如果没有执行,就走随机筛选
                TroopRoster troopRosters       = MobileParty.MainParty.MemberRoster;
                List <TroopRosterElement> list = troopRosters.GetTroopRoster();
                TroopRoster battleTroopRoster  = TroopRoster.CreateDummyTroopRoster();
                foreach (TroopRosterElement element in list)
                {
                    if (element.Character.IsHero && !element.Character.IsPlayerCharacter)
                    {
                        if (battleTroopRoster.Count < maxNum)
                        {
                            battleTroopRoster.AddToCounts(element.Character, element.Number);
                        }
                    }
                }
                ;
                DealPatyTroop(battleTroopRoster);
                nextStep();
            }
        }
Exemplo n.º 10
0
        internal static TroopRoster[] MergeRosters(MobileParty sourceParty, PartyBase targetParty)
        {
            var troopRoster    = TroopRoster.CreateDummyTroopRoster();
            var prisonerRoster = TroopRoster.CreateDummyTroopRoster();
            var rosters        = new List <TroopRoster>
            {
                sourceParty.MemberRoster,
                targetParty.MemberRoster
            };

            var prisoners = new List <TroopRoster>
            {
                sourceParty.PrisonRoster,
                targetParty.PrisonRoster
            };

            // dumps all bandit heroes (shouldn't be more than 2 though...)
            foreach (var roster in rosters)
            {
                foreach (var troopRosterElement in roster.GetTroopRoster().Where(x => x.Character?.HeroObject == null))
                {
                    troopRoster.AddToCounts(troopRosterElement.Character, troopRosterElement.Number,
                                            woundedCount: troopRosterElement.WoundedNumber, xpChange: troopRosterElement.Xp);
                }
            }

            foreach (var roster in prisoners)
            {
                foreach (var troopRosterElement in roster.GetTroopRoster().Where(x => x.Character?.HeroObject == null))
                {
                    prisonerRoster.AddToCounts(troopRosterElement.Character, troopRosterElement.Number,
                                               woundedCount: troopRosterElement.WoundedNumber, xpChange: troopRosterElement.Xp);
                }
            }

            return(new[]
            {
                troopRoster,
                prisonerRoster
            });
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
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);
            }
        }
Exemplo n.º 13
0
 public ToolMaker()
 {
     _town       = Settlement.CurrentSettlement.Town;
     _assistants = TroopRoster.CreateDummyTroopRoster();
     _stockpile  = new ItemRoster();
 }