예제 #1
0
        private Kingdom GoRebelKingdom(Clan clan, IEnumerable <Settlement> settlements)
        {
            var capital = settlements.First();
            var owner   = capital.OwnerClan;
            // create a new kingdom for the clan
            TextObject kingdomIntroText = new TextObject("{=Separatism_Kingdom_Intro_Anarchy}{RebelKingdom} was found in {Year} as a result of anarchy in fiefs of the {ClanName} when people of {Settlement} have called {Ruler} on rulership.", null);

            kingdomIntroText.SetTextVariable("Year", CampaignTime.Now.GetYear);
            kingdomIntroText.SetTextVariable("ClanName", owner.Name);
            kingdomIntroText.SetTextVariable("Settlement", capital.Name);
            kingdomIntroText.SetTextVariable("Ruler", clan.Leader.Name);
            var kingdom = clan.CreateKingdom(kingdomIntroText);

            // keep policies from the old settlement kingdom
            foreach (var policy in owner.Kingdom.ActivePolicies)
            {
                kingdom.AddPolicy(policy);
            }
            // move the clan out of its current kingdom
            clan.ChangeKingdom(null, false);
            // change settlement ownership
            foreach (var s in settlements)
            {
                ChangeOwnerOfSettlementAction.ApplyByRevolt(clan.Leader, s);
            }
            // move the clan into the new kingdom
            clan.ChangeKingdom(kingdom, false);
            // declare wars
            kingdom.InheritsWarsFromKingdom(owner.Kingdom);
            DeclareWarAction.Apply(owner.Kingdom, kingdom);

            return(kingdom);
        }
        private static void DeclareWarBetweenHeros(Hero assassin, Hero victim, out string declareWarMessage)
        {
            declareWarMessage = string.Empty;

            if (victim.MapFaction.IsAtWarWith(assassin.MapFaction))
            {
                return;
            }

            if (assassin.Clan == victim.Clan)
            {
                throw new NotImplementedException("Assassinating members of the same clan is not supported.");
            }

            if (assassin.Clan.Kingdom != null && assassin.Clan.Kingdom == victim.Clan.Kingdom)
            {
                if (assassin.IsFactionLeader)
                {
                    throw new NotImplementedException("Assassinating members of the kingdom you own is not supported.");
                }

                ChangeKingdomAction.ApplyByLeaveKingdom(assassin.Clan);
            }

            DeclareWarAction.ApplyDeclareWarOverProvocation(victim.MapFaction, assassin.MapFaction);

            GameTexts.SetVariable("FACTION1_NAME", victim.MapFaction.Name);
            GameTexts.SetVariable("FACTION2_NAME", assassin.MapFaction.Name);

            declareWarMessage = $"\n{GameTexts.FindText("str_factions_declare_war_news", null)}.";
        }
예제 #3
0
        protected virtual void ExecuteExecutiveAction()
        {
            float influenceCost = DiplomacyCostCalculator.DetermineInfluenceCostForDeclaringWar(Faction1 as Kingdom);

            DiplomacyCostManager.deductInfluenceFromPlayerClan(influenceCost);
            DeclareWarAction.Apply(Faction1, Faction2);
        }
예제 #4
0
 public static void InheritsWarsFromKingdom(this Kingdom dest, Kingdom src)
 {
     if (SeparatismConfig.Settings.KeepOriginalKindomWars)
     {
         var oldKingdomEnemies = FactionManager.GetEnemyKingdoms(src).ToArray();
         foreach (var enemy in oldKingdomEnemies)
         {
             DeclareWarAction.Apply(enemy, dest);
         }
     }
 }
예제 #5
0
        private void OnGameStarted()
        {
            if (!SeparatismConfig.Settings.ChaosStartEnabled)
            {
                return;
            }

            var kingdoms = Kingdom.All.ToArray();

            foreach (var oldKingdom in kingdoms)
            {
                var clans = oldKingdom.Clans.ReadyToGoAndNotEmpty().ToArray();
                foreach (var clan in clans)
                {
                    // create a new kingdom for the clan
                    TextObject kingdomIntroText = new TextObject("{=Separatism_Kingdom_Intro_Chaos}{RebelKingdom} was found in {Year} as a result of BIG separation of Calradia.", null);
                    kingdomIntroText.SetTextVariable("Year", CampaignTime.Now.GetYear);
                    var capital = clan.Settlements.OrderByDescending(x => x.Prosperity).First();
                    var kingdom = clan.CreateKingdom(capital, kingdomIntroText);
                    // keep policies from the old clan kingdom
                    foreach (var policy in clan.Kingdom.ActivePolicies)
                    {
                        kingdom.AddPolicy(policy);
                    }
                    // move the clan into its new kingdom
                    clan.ClanLeaveKingdom(false);
                    clan.Kingdom = kingdom;
                }
            }

            kingdoms = Kingdom.All.ToArray();
            foreach (var kingdom in kingdoms)
            {
                var closeKingdoms = kingdom.RulingClan.CloseKingdoms().Where(k => k != kingdom).ToArray();
                var wars          = FactionManager.GetEnemyKingdoms(kingdom).Count();

                foreach (var closeKingdom in closeKingdoms)
                {
                    if (wars < SeparatismConfig.Settings.MinimalNumberOfWarsPerChaosKindom)
                    {
                        DeclareWarAction.Apply(closeKingdom, kingdom);
                        wars++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
예제 #6
0
        public override void DoEnd()
        {
            var plot = Goal.Plot;

            var name         = new TextObject(plot.Target.ToKingdom().InformalName + " Seperatists");
            var informalName = new TextObject(plot.Leader.ToHero().Clan.InformalName.ToString());

            var oldKingdom = plot.Target.ToKingdom();
            var rebel      = KingdomHelper.CreateKingdom(plot.Leader.ToHero(), name, informalName, plot.Leader.ToHero().Clan.Banner, true);

            foreach (var member in plot.Members.Where(member => member.ToHero().Clan.Kingdom != rebel))
            {
                ChangeKingdomAction.ApplyByJoinToKingdom(member.ToHero().Clan, rebel);
            }

            DeclareWarAction.Apply(rebel, oldKingdom);

            foreach (var hero in oldKingdom.Lords)
            {
                var warRelationChange  = Settings.WarRelationshipChange;
                var allyRelationChange = Settings.AllyRelationshipChange / 2;

                if (hero.IsFactionLeader())
                {
                    warRelationChange  *= Settings.LeaderRelationshipChangeFactor;
                    allyRelationChange *= Settings.LeaderRelationshipChangeFactor;
                }

                foreach (var ally in oldKingdom.Lords)
                {
                    ChangeRelationAction.ApplyRelationChangeBetweenHeroes(hero, ally, (int)allyRelationChange);
                }

                foreach (var enemy in rebel.Lords)
                {
                    ChangeRelationAction.ApplyRelationChangeBetweenHeroes(hero, enemy, (int)warRelationChange);
                }

                foreach (var ally in rebel.Lords)
                {
                    ChangeRelationAction.ApplyRelationChangeBetweenHeroes(hero, ally, (int)allyRelationChange);
                }
            }

            InformationManager.AddNotice(new WarMapNotification(rebel, oldKingdom, new TextObject($"Civil War breaks out in {oldKingdom.Name}")));

            LogHelper.Log("Successful Revolt created: " + rebel.Name);
        }
예제 #7
0
        private Kingdom FormRebelKingdom(Clan clan, Settlement originSettlement, IFaction warOnFaction)
        {
            string kingdomId = GetClanKingdomId(originSettlement);
            var    kingdom   = Kingdom.All.SingleOrDefault(x => x.StringId == kingdomId);

            if (kingdom == null)
            {
                kingdom = Common.Instance.CreateKingdomFromSettlement(clan, kingdomId, originSettlement.Name.ToString());
                DeclareWarAction.Apply(kingdom, warOnFaction);
            }

            if (!Kingdom.All.Contains(kingdom))
            {
                Common.Instance.ModifyKingdomList(kingdoms => kingdoms.Add(kingdom));
            }

            return(kingdom);
        }
예제 #8
0
        private void SupportAlliedKingdom(Kingdom kingdom, Kingdom kingdomToDeclareWarOn)
        {
            IEnumerable <Kingdom> alliedKingdoms = Kingdom.All.Where(curKingdom => kingdom != curKingdom && FactionManager.IsAlliedWithFaction(kingdom, curKingdom));

            foreach (Kingdom alliedKingdom in alliedKingdoms)
            {
                if (!DeclareWarConditions.Instance.CanApply(alliedKingdom, kingdomToDeclareWarOn, bypassCosts: true))
                {
                    continue;
                }

                DeclareWarAction.ApplyDeclareWarOverProvocation(alliedKingdom, kingdomToDeclareWarOn);
                TextObject textObject = new TextObject("{=UDC8eW7s}{ALLIED_KINGDOM} is joining their ally, {KINGDOM}, in the war against {ENEMY_KINGDOM}.");
                textObject.SetTextVariable("ALLIED_KINGDOM", alliedKingdom.Name);
                textObject.SetTextVariable("KINGDOM", kingdom.Name);
                textObject.SetTextVariable("ENEMY_KINGDOM", kingdomToDeclareWarOn.Name);

                InformationManager.DisplayMessage(new InformationMessage(textObject.ToString()));
            }
        }
예제 #9
0
        private void SupportAlliedKingdom(Kingdom kingdom, Kingdom kingdomToDeclareWarOn)
        {
            var allies = Kingdom.All.Where(k => kingdom != k && FactionManager.IsAlliedWithFaction(kingdom, k));

            foreach (var ally in allies)
            {
                if (!DeclareWarConditions.Instance.CanApply(ally, kingdomToDeclareWarOn, bypassCosts: true))
                {
                    continue;
                }

                DeclareWarAction.ApplyDeclareWarOverProvocation(ally, kingdomToDeclareWarOn);
                var txt = new TextObject("{=UDC8eW7s}{ALLIED_KINGDOM} is joining their ally, {KINGDOM}, in the war against {ENEMY_KINGDOM}.");
                txt.SetTextVariable("ALLIED_KINGDOM", ally.Name);
                txt.SetTextVariable("KINGDOM", kingdom.Name);
                txt.SetTextVariable("ENEMY_KINGDOM", kingdomToDeclareWarOn.Name);

                InformationManager.DisplayMessage(new InformationMessage(txt.ToString(), SubModule.StdTextColor));
            }
        }
예제 #10
0
        private Clan CreateRebellionClan(SettlementInfo info)
        {
            Clan clan = MBObjectManager.Instance.CreateObject <Clan>(info.Settlement.Name.ToString() + "_rebels_" + MBRandom.RandomInt(100000).ToString());
            Hero hero = HeroCreator.CreateSpecialHero(CreateLordCharacter(info.OriginalCulture), info.Settlement, clan, clan, 30);

            TextObject name  = new TextObject(hero.Name.ToString());
            int        value = MBMath.ClampInt(1, DefaultTraits.Commander.MinValue, DefaultTraits.Commander.MaxValue);

            hero.SetTraitLevel(DefaultTraits.Commander, value);
            hero.ChangeState(Hero.CharacterStates.Active);
            hero.Initialize();
            clan.InitializeClan(name, name, info.OriginalCulture, Banner.CreateRandomClanBanner(MBRandom.RandomInt(100000)));
            hero.Clan = clan;
            clan.SetLeader(hero);
            clan.IsUnderMercenaryService = false;
            var kingdom = FormRebelKingdom(clan, info.Settlement, info.CurrentFaction);

            kingdom.ReactivateKingdom();
            DeclareWarAction.Apply(kingdom, info.CurrentFaction);
            clan.ClanJoinFaction(kingdom);
            kingdom.RulingClan = clan;
            return(clan);
        }
예제 #11
0
        private void AlliedKingdomDeclareWar(Kingdom kingdom, Kingdom kingdomToDeclareWarOn)
        {
            IEnumerable <Kingdom> alliedKingdoms         = Kingdom.All.Where(curKingdom => kingdom != curKingdom && FactionManager.IsAlliedWithFaction(kingdom, curKingdom));
            IEnumerable <Kingdom> kingdomsToDeclareWarOn = Kingdom.All.Where(curKingdom => FactionManager.IsAlliedWithFaction(kingdomToDeclareWarOn, curKingdom));

            foreach (Kingdom alliedKingdom in alliedKingdoms)
            {
                foreach (Kingdom enemyKingdom in kingdomsToDeclareWarOn)
                {
                    if (FactionManager.IsAlliedWithFaction(alliedKingdom, enemyKingdom) || FactionManager.IsAtWarAgainstFaction(alliedKingdom, enemyKingdom))
                    {
                        continue;
                    }

                    DeclareWarAction.Apply(alliedKingdom, enemyKingdom);
                    TextObject textObject = new TextObject("{ALLIED_KINGDOM} is joining their ally, {KINGDOM}, in the war against {ENEMY_KINGDOM}.");
                    textObject.SetTextVariable("ALLIED_KINGDOM", alliedKingdom.Name);
                    textObject.SetTextVariable("KINGDOM", kingdom.Name);
                    textObject.SetTextVariable("ENEMY_KINGDOM", kingdomToDeclareWarOn.Name);

                    InformationManager.DisplayMessage(new InformationMessage(textObject.ToString()));
                }
            }
        }
예제 #12
0
        internal static void StartRevolt(Settlement settlement)
        {
            var textObject = new TextObject(Localization.GameTexts.RevoltsRevoltStart);

            textObject.SetTextVariable("SETTLEMENT", settlement.Name);
            InformationManager.AddNotice(new SettlementRebellionMapNotification(settlement, textObject));
            InformationManager.AddQuickInformation(textObject);

            var settlementInfo        = Managers.Settlement.Get(settlement);
            var atWarWithLoyalFaction = settlementInfo.CurrentFaction.IsAtWarWith(settlementInfo.LoyalFaction);

            Hero leader;

            if (atWarWithLoyalFaction)
            {
                leader = Managers.Faction.GetLordWithLeastFiefs(settlementInfo.LoyalFaction).HeroObject;
            }
            else
            {
                leader = Managers.Character.CreateRandomLeader(settlementInfo.LoyalFaction?.Leader?.Clan ?? settlement.OwnerClan, settlementInfo);
                Managers.Character.Get(leader.CharacterObject).IsRevoltKingdomLeader = true;

                var bannerInfo = Managers.Banner.GetBanner(settlementInfo);
                var banner     = bannerInfo != null ? new Banner(bannerInfo.BannerId) : null;

                var clan = Managers.Clan.CreateClan(leader, null, null, banner);
                Managers.Clan.Get(leader.Clan).IsRevoltClan = true;

                textObject = new TextObject(Localization.GameTexts.RevoltsMinorFactionKingdom);
                textObject.SetTextVariable("SETTLEMENT", settlement.Name);
                Managers.Kingdom.CreateKingdom(leader, textObject, textObject, banner ?? clan.Banner, false);
                Managers.Kingdom.Get(leader.Clan.Kingdom).IsRevoltKingdom = true;
            }

            var mobileParty = Managers.Party.CreateMobileParty(leader, null, settlement.GatePosition, settlement, !atWarWithLoyalFaction, true);

            var amountOfTroops = (RevolutionsSettings.Instance.RevoltsGeneralBaseSize + (int)(settlement.Prosperity * RevolutionsSettings.Instance.RevoltsGeneralProsperityMulitplier)) / 3;
            var basicUnits     = new TroopRoster();

            basicUnits.AddToCounts(leader.Culture.RangedMilitiaTroop, amountOfTroops);
            basicUnits.AddToCounts(leader.Culture.MeleeMilitiaTroop, amountOfTroops * 2);
            mobileParty.MemberRoster.Add(basicUnits);

            if (settlement.MilitaParty != null && settlement.MilitaParty.CurrentSettlement == settlement && settlement.MilitaParty.MapEvent == null)
            {
                foreach (var troopRosterElement in settlement.MilitaParty.MemberRoster)
                {
                    mobileParty.AddElementToMemberRoster(troopRosterElement.Character, troopRosterElement.Number, false);
                }

                settlement.MilitaParty.RemoveParty();
            }

            mobileParty.ChangePartyLeader(mobileParty.Party.Owner.CharacterObject, false);

            if (!FactionManager.IsAtWarAgainstFaction(leader.MapFaction, settlement.MapFaction))
            {
                DeclareWarAction.Apply(leader.MapFaction, settlement.MapFaction);
            }

            var revolt = new Revolt(mobileParty.Party.Id, settlement, !atWarWithLoyalFaction);

            Managers.Revolt.Revolts.Add(revolt);
            settlementInfo.HasRebellionEvent = true;

            if (settlementInfo.Garrision == null || settlementInfo.Garrision.TotalStrength == 0)
            {
                RevoltBehavior.EndSucceededRevolt(revolt);
                return;
            }

            mobileParty.Ai.SetDoNotMakeNewDecisions(true);
            StartBattleAction.Apply(mobileParty.Party, settlementInfo.Garrision);
        }
예제 #13
0
        static bool Prefix(Clan clan, Kingdom kingdom, int detail, int awardMultiplier, bool byRebellion, bool showNotification)
        {
            //MessageBox.Show($"Detail: {detail}");
            //MessageBox.Show(SharedObjects.Instance.RebellionRelationsChange.ToString());

            var  onClanChangedKingdom          = typeof(CampaignEventDispatcher).GetMethod("OnClanChangedKingdom", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var  onMercenaryClanChangedKingdom = typeof(CampaignEventDispatcher).GetMethod("OnMercenaryClanChangedKingdom", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            Type type = typeof(ChangeKingdomAction).Assembly.GetType("TaleWorlds.CampaignSystem.Actions.ChangeKingdomAction+ChangeKingdomActionDetail");

            int joinMerc       = (int)Enum.ToObject(type, 0);
            int joinKingdom    = (int)Enum.ToObject(type, 1);
            int leaveKingdom   = (int)Enum.ToObject(type, 2);
            int leaveRebellion = (int)Enum.ToObject(type, 3);
            int leaveMerc      = (int)Enum.ToObject(type, 4);

            Kingdom oldKingdom = clan.Kingdom;

            if (kingdom != null)
            {
                foreach (Kingdom kingdom3 in Kingdom.All)
                {
                    if (object.ReferenceEquals(kingdom3, kingdom) || !kingdom.IsAtWarWith(kingdom3))
                    {
                        FactionHelper.FinishAllRelatedHostileActionsOfFactionToFaction(clan, kingdom3);
                        FactionHelper.FinishAllRelatedHostileActionsOfFactionToFaction(kingdom3, clan);
                    }
                }
                foreach (Clan clan2 in Clan.All)
                {
                    if (!object.ReferenceEquals(clan2, clan) && ((clan2.Kingdom == null) && !kingdom.IsAtWarWith(clan2)))
                    {
                        FactionHelper.FinishAllRelatedHostileActions(clan, clan2);
                    }
                }
            }
            if (detail == joinKingdom)   //ChangeKingdomActionDetail.JoinKingdom
            {
                object[] additionalArgs = new object[] { clan, oldKingdom, kingdom, false };
                StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.ChangeKingdomAction, additionalArgs);
                clan.IsUnderMercenaryService = false;
                if (oldKingdom != null)
                {
                    clan.ClanLeaveKingdom(!byRebellion);
                }
                clan.ClanJoinFaction(kingdom);
                onClanChangedKingdom.Invoke(CampaignEventDispatcher.Instance, new object[] { clan, oldKingdom, clan.Kingdom, byRebellion, showNotification });
            }
            else if (detail == joinMerc)   //ChangeKingdomActionDetail.JoinAsMercenary
            {
                object[] additionalArgs = new object[] { clan, oldKingdom, kingdom, false };
                StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.ChangeKingdomAction, additionalArgs);
                if (clan.IsUnderMercenaryService)
                {
                    clan.ClanLeaveKingdom(false);
                }
                clan.MercenaryAwardMultiplier = MathF.Round((float)awardMultiplier);
                clan.IsUnderMercenaryService  = true;
                clan.ClanJoinFaction(kingdom);
                //CampaignEventDispatcher.Instance.OnMercenaryClanChangedKingdom(clan, null, kingdom);
                onMercenaryClanChangedKingdom.Invoke(CampaignEventDispatcher.Instance, new object[] { clan, null, kingdom });
            }
            else if (detail == leaveRebellion || detail == leaveKingdom || detail == leaveMerc)   //ChangeKingdomActionDetail.LeaveAsMercenary = 4
            {
                object[] additionalArgs = new object[] { clan, oldKingdom, kingdom, true };
                StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.ChangeKingdomAction, additionalArgs);
                clan.ClanLeaveKingdom(false);
                if (detail == leaveMerc)   //ChangeKingdomActionDetail.LeaveAsMercenary
                {
                    onMercenaryClanChangedKingdom.Invoke(CampaignEventDispatcher.Instance, new object[] { clan, kingdom, null });
                    clan.IsUnderMercenaryService = false;
                }
                if (detail == leaveRebellion)   //ChangeKingdomActionDetail.LeaveWithRebellion
                {
                    if (object.ReferenceEquals(clan, Clan.PlayerClan))
                    {
                        foreach (Clan clan3 in oldKingdom.Clans)
                        {
                            ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan.Leader, clan3.Leader, SharedObjects.Instance.RebellionRelationsChange, true);
                        }
                        if (SharedObjects.Instance.DeclareWarOnRebellion)
                        {
                            DeclareWarAction.Apply(oldKingdom, clan);
                        }
                    }
                    onClanChangedKingdom.Invoke(CampaignEventDispatcher.Instance, new object[] { clan, oldKingdom, null, true, true });
                }
                else if (detail == leaveKingdom)   //ChangeKingdomActionDetail.LeaveKingdom
                {
                    if (object.ReferenceEquals(clan, Clan.PlayerClan))
                    {
                        foreach (Clan clan4 in oldKingdom.Clans)
                        {
                            ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan.Leader, clan4.Leader, SharedObjects.Instance.ForfeitSettlementsRelationsChange, true);
                        }
                    }
                    foreach (Settlement settlement in new List <Settlement>(clan.Settlements))
                    {
                        ChangeOwnerOfSettlementAction.ApplyByLeaveFaction(oldKingdom.Leader, settlement);
                        foreach (Hero hero in new List <Hero>((IEnumerable <Hero>)settlement.HeroesWithoutParty))
                        {
                            if ((hero.CurrentSettlement != null) && object.ReferenceEquals(hero.Clan, clan))
                            {
                                if (hero.PartyBelongedTo != null)
                                {
                                    LeaveSettlementAction.ApplyForParty(hero.PartyBelongedTo);
                                    EnterSettlementAction.ApplyForParty(hero.PartyBelongedTo, clan.Leader.HomeSettlement);
                                    continue;
                                }
                                LeaveSettlementAction.ApplyForCharacterOnly(hero);
                                EnterSettlementAction.ApplyForCharacterOnly(hero, clan.Leader.HomeSettlement);
                            }
                        }
                    }
                    onClanChangedKingdom.Invoke(CampaignEventDispatcher.Instance, new object[] { clan, oldKingdom, null, false, false });
                }
            }
            if (object.ReferenceEquals(clan, Clan.PlayerClan))
            {
                Campaign.Current.UpdateDecisions();
            }
            typeof(ChangeKingdomAction).GetMethod("CheckIfPartyIconIsDirty", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
            .Invoke(null, new object[] { clan, kingdom });
            return(false);
        }
예제 #14
0
        public static void ChangeKingdom(this Clan clan, Kingdom newKingdom, bool rebellion)
        {
            Kingdom oldKingdom = clan.Kingdom;

            if (newKingdom != null)
            {
                foreach (Kingdom k in Kingdom.All)
                {
                    if (k == newKingdom || !newKingdom.IsAtWarWith(k))
                    {
                        FactionHelper.FinishAllRelatedHostileActionsOfFactionToFaction(clan, k);
                        FactionHelper.FinishAllRelatedHostileActionsOfFactionToFaction(k, clan);
                    }
                }
                foreach (Clan c in Clan.All)
                {
                    if (c != clan && c.Kingdom == null && !newKingdom.IsAtWarWith(c))
                    {
                        FactionHelper.FinishAllRelatedHostileActions(clan, c);
                    }
                }
            }

            StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.ChangeKingdomAction, new object[]
            {
                clan,
                oldKingdom,
                newKingdom,
                newKingdom == null || rebellion
            });
            clan.IsUnderMercenaryService = false;
            if (oldKingdom != null)
            {
                clan.ClanLeaveKingdom(false);
            }
            if (newKingdom != null)
            {
                clan.ClanJoinFaction(newKingdom);
                NotifyClanChangedKingdom(clan, oldKingdom, newKingdom, rebellion, true);

                if (rebellion)
                {
                    foreach (Clan c in oldKingdom.Clans)
                    {
                        int relationChange = SeparatismConfig.Settings.RelationChangeRebelWithRulerVassals;
                        if (c.Leader == oldKingdom.Leader)
                        {
                            relationChange = SeparatismConfig.Settings.RelationChangeRebelWithRuler;
                        }
                        else if (c.Leader.IsFriend(oldKingdom.Leader))
                        {
                            relationChange = SeparatismConfig.Settings.RelationChangeRebelWithRulerFriendVassals;
                        }
                        else if (c.Leader.IsEnemy(oldKingdom.Leader))
                        {
                            relationChange = SeparatismConfig.Settings.RelationChangeRebelWithRulerEnemyVassals;
                        }

                        if (relationChange != 0)
                        {
                            ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan.Leader, c.Leader, relationChange, true);
                        }
                    }

                    newKingdom.InheritsWarsFromKingdom(oldKingdom);
                    DeclareWarAction.Apply(oldKingdom, newKingdom);
                }
                else
                {
                    int relationChange = SeparatismConfig.Settings.RelationChangeUnitedRulers;
                    if (relationChange != 0)
                    {
                        ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan.Leader, newKingdom.Leader, relationChange, true);
                    }
                    if (oldKingdom != null)
                    {
                        newKingdom.InheritsWarsFromKingdom(oldKingdom);
                    }
                }
            }
            if (oldKingdom != null && oldKingdom.Clans.Where(x => x.Leader.IsAlive).Count() == 0)             // old kingdom is empty so we destroy it
            {
                if (newKingdom == null)
                {
                    NotifyClanChangedKingdom(clan, oldKingdom, null, false, true);
                }
                Campaign.Current.RemoveEmptyKingdoms();
            }

            CheckIfPartyIconIsDirty(clan, oldKingdom);
        }
예제 #15
0
 protected virtual void ExecuteExecutiveAction()
 {
     DiplomacyCostCalculator.DetermineCostForDeclaringWar(Faction1 as Kingdom, true).ApplyCost();
     DeclareWarAction.Apply(Faction1, Faction2);
 }
예제 #16
0
        private static bool Prefix(Settlement settlement)
        {
            bool        hadPlayerSupport          = false;
            List <Hero> NotablesSupportingReveolt = new List <Hero>();

            if (settlement.IsVillage)
            {
                return(true);
            }
            Town town = settlement.Town;

            foreach (var pair in NotableBehavior.RebelliousNotables)
            {
                if (town.Settlement.Notables.Contains(pair.Key))
                {
                    if (town.MapFaction == pair.Value)
                    {
                        hadPlayerSupport = true;
                        NotablesSupportingReveolt.Add(pair.Key);
                    }
                }
                foreach (Village village in town.Villages)
                {
                    if (village.Settlement.Notables.Contains(pair.Key))
                    {
                        hadPlayerSupport = true;
                        NotablesSupportingReveolt.Add(pair.Key);
                    }
                }
            }

            if (hadPlayerSupport)
            {
                InformationManager.ShowInquiry(new InquiryData("Rebellion", "Your supporters have started an uprising in " + settlement.Town.Name.ToString() + ".  Do you want to take direct control of the settlement or let them elect their own leader?  Taking control of the settlement will lead to a war with the previous owners", true, true, "take it", "let them decide", (Action)(() => {
                    DeclareWarAction.ApplyDeclareWarOverSettlement(settlement.MapFaction, Hero.MainHero.MapFaction);
                    ChangeOwnerOfSettlementAction.ApplyByRebellion(Hero.MainHero, settlement);
                }), (Action)(() => {
                    Random rng = new Random();
                    Hero newLeader = NotablesSupportingReveolt[rng.Next(0, NotablesSupportingReveolt.Count - 1)];
                    FieldInfo field2 = newLeader.GetType().GetField("Occupation", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    if ((FieldInfo)null != field2)
                    {
                        field2.SetValue((object)newLeader, Occupation.Lord);
                    }

                    Clan clan = MBObjectManager.Instance.CreateObject <Clan>();
                    Banner ClanBanner = Banner.CreateRandomClanBanner();
                    TextObject clanName = newLeader.Culture.ClanNameList[rng.Next(0, newLeader.Culture.ClanNameList.Count)];
                    clan.InitializeClan(clanName, clanName, newLeader.Culture, ClanBanner);
                    clan.SetLeader(newLeader);
                    FieldInfo field = clan.GetType().GetField("_tier", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    if ((FieldInfo)null != field)
                    {
                        field.SetValue((object)clan, rng.Next(2, 4));
                    }

                    newLeader.Clan = clan;
                    newLeader.IsNoble = true;
                    MobileParty newMobileParty1 = clan.CreateNewMobileParty(newLeader);
                    newMobileParty1.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
                    newMobileParty1.ItemRoster.AddToCounts(DefaultItems.Meat, 5);

                    List <Equipment> Lordgear = new List <Equipment>();
                    foreach (Hero hero in Campaign.Current.Heroes)
                    {
                        if (hero.Culture == newLeader.Culture && hero.IsNoble && hero.IsFemale == newLeader.IsFemale)
                        {
                            Lordgear.Add(hero.BattleEquipment);
                        }
                    }
                    EquipmentHelper.AssignHeroEquipmentFromEquipment(newLeader, Lordgear[rng.Next(0, Lordgear.Count - 1)]);

                    clan.UpdateHomeSettlement(settlement);

                    ChangeRelationAction.ApplyRelationChangeBetweenHeroes(newLeader, settlement.OwnerClan.Leader, -200);
                    if (settlement.OwnerClan.Leader != settlement.MapFaction.Leader)
                    {
                        ChangeRelationAction.ApplyRelationChangeBetweenHeroes(newLeader, settlement.MapFaction.Leader, -200);
                    }
                    DeclareWarAction.Apply(settlement.MapFaction, newLeader.MapFaction);
                    ChangeOwnerOfSettlementAction.ApplyByRebellion(newLeader, settlement);
                })));
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #17
0
        private void RevoltLogic(SettlementInfo info, Settlement settlement)
        {
            TextObject revoltNotification = GameTexts.FindText("str_GM_RevoltNotification");

            revoltNotification.SetTextVariable("SETTLEMENT", settlement.Name.ToString());
            InformationManager.DisplayMessage(new InformationMessage(revoltNotification.ToString()));

            Hero        selectedHero     = null;
            TextObject  revolutionaryMob = GameTexts.FindText("str_GM_RevolutionaryMob");
            MobileParty mob    = MobileParty.Create(revolutionaryMob.ToString());
            TroopRoster roster = new TroopRoster();

            TroopRoster infantry = new TroopRoster();

            infantry.FillMembersOfRoster(300, settlement.Culture.MeleeMilitiaTroop);
            roster.Add(infantry);

            TroopRoster archers = new TroopRoster();

            archers.FillMembersOfRoster(200, settlement.Culture.RangedMilitiaTroop);
            roster.Add(archers);

            TroopRoster prisonRoster = new TroopRoster();

            prisonRoster.IsPrisonRoster = true;

            if (info.CurrentFaction.IsAtWarWith(info.OriginalFaction))
            {
                Clan chosenClan       = null;
                int  leastSettlements = 100;
                foreach (var noble in info.OriginalFaction.Nobles)
                {
                    int currentSettlements = noble.Clan.Settlements.Count();
                    if (currentSettlements >= leastSettlements)
                    {
                        continue;
                    }
                    leastSettlements = currentSettlements;
                    chosenClan       = noble.Clan;
                }

                selectedHero = chosenClan != null?chosenClan.Nobles.GetRandomElement() : info.OriginalFaction.Leader;
            }
            else
            {
                var clan = CreateRebellionClan(info);
                clan.AddRenown(500);
                DeclareWarAction.Apply(clan, info.CurrentFaction);
                selectedHero    = clan.Leader;
                mob.IsLordParty = true;
            }

            mob.ChangePartyLeader(selectedHero.CharacterObject);
            mob.Party.Owner = selectedHero;

            if (!info.CurrentFaction.IsAtWarWith(info.OriginalFaction))
            {
                mob.MemberRoster.AddToCounts(mob.Party.Owner.CharacterObject, 1, false, 0, 0, true, -1);
            }

            mob.InitializeMobileParty(new TextObject(revolutionaryMob.ToString(), null), roster, prisonRoster, settlement.GatePosition, 2.0f, 2.0f);

            Revolutionaries.Add(new Tuple <PartyBase, SettlementInfo>(mob.Party, info));

            MobileParty garrison = settlement.Parties.FirstOrDefault(party => party.IsGarrison);

            if (garrison == null)
            {
                foreach (var party in settlement.Parties.Where(party => party.IsMilitia || party.MapFaction.StringId == settlement.OwnerClan.MapFaction.StringId))
                {
                    garrison = party;
                    break;
                }
            }

            if (garrison == null)
            {
                ChangeOwnerOfSettlementAction.ApplyByRevolt(selectedHero, settlement);
                GetFactionInformation(info.CurrentFaction).CityRevoltedSuccess(settlement);
            }
            else
            {
                Campaign.Current.MapEventManager.StartSiegeOutsideMapEvent(mob.Party, garrison.Party);
            }

            info.RevoltProgress = 0;
        }
예제 #18
0
 public static void DeclareWar(IFaction faction, IFaction provocator)
 {
     DeclareWarAction.Apply(faction, provocator);
 }
예제 #19
0
        private bool CheckWarState(KingdomInfo kingdomInfo, List <Clan> clans)
        {
            var loyalClans    = new List <Clan>();
            var plottingClans = new List <Clan>();

            foreach (var clan in clans)
            {
                var clanLeader     = clan.Leader;
                var clanLeaderInfo = Managers.Character.Get(clanLeader.CharacterObject);

                if (clanLeaderInfo.PlotState == PlotState.IsLoyal)
                {
                    loyalClans.Add(clan);
                }
                else if (clanLeaderInfo.PlotState == PlotState.IsPlotting)
                {
                    plottingClans.Add(clan);
                }
            }

            if (plottingClans.Count == 0)
            {
                if (RevolutionsSettings.Instance.DebugMode)
                {
                    InformationManager.DisplayMessage(new InformationMessage($"Revolutions.CivilWars: There are no plotting clans.", ColorHelper.Gray));
                }

                return(true);
            }

            var loyalTroopWeight = kingdomInfo.Kingdom.RulingClan.TotalStrength;

            foreach (var loyalClan in loyalClans)
            {
                loyalTroopWeight += loyalClan.TotalStrength;
            }

            var plottersTroopWeight = 0f;

            foreach (var plotterClan in plottingClans)
            {
                plottersTroopWeight += plotterClan.TotalStrength;
            }

            var plotLeadingClan = plottingClans.OrderByDescending(go => go.Tier).FirstOrDefault();

            if (plotLeadingClan == null)
            {
                return(true);
            }

            var kingdomLeader  = kingdomInfo.Kingdom.Leader;
            var plottingLeader = plotLeadingClan.Leader;

            var kingdomLeaderGenerosity  = kingdomLeader.GetHeroTraits().Generosity;
            var kingdomLeaderMercy       = kingdomLeader.GetHeroTraits().Mercy;
            var kingdomLeaderValor       = kingdomLeader.GetHeroTraits().Valor;
            var kingdomLeaderCalculating = kingdomLeader.GetHeroTraits().Calculating;

            var plottingLeaderGenerosity  = plottingLeader.GetHeroTraits().Generosity;
            var plottingLeaderMercy       = plottingLeader.GetHeroTraits().Mercy;
            var plottingLeaderValor       = plottingLeader.GetHeroTraits().Valor;
            var plottingLeaderCalculating = plottingLeader.GetHeroTraits().Calculating;

            float personalityTraits   = plottingLeaderGenerosity + kingdomLeaderGenerosity + plottingLeaderMercy + kingdomLeaderMercy;
            var   personalityWeight   = MathF.Pow(RevolutionsSettings.Instance.CivilWarsWarPersonalityMultiplier, -personalityTraits);
            var   troopWeight         = plottersTroopWeight / loyalTroopWeight;
            float valorModifier       = 1 + (plottingLeaderValor <= 0 ? 1 : plottingLeaderValor * 2);
            float clanCountModifier   = plottingClans.Count / (loyalClans.Count + 1);
            float calculatingModifier = 1 + (plottingLeaderCalculating <= 0 ? 1 : plottingLeaderCalculating);

            var warChance = RevolutionsSettings.Instance.CivilWarsWarBaseChance * personalityWeight * (troopWeight * valorModifier) * MathF.Pow(clanCountModifier, calculatingModifier);

            if (RevolutionsSettings.Instance.DebugMode)
            {
                InformationManager.DisplayMessage(new InformationMessage($"Revolutions.CivilWars: War Chance is {warChance}%.", ColorHelper.Gray));
            }

            if (warChance > new Random().Next(0, 100))
            {
                if (kingdomInfo.Id == Hero.MainHero.Clan.Kingdom?.StringId && EventManager.Instance.InEvent)
                {
                    return(true);
                }

                if (kingdomInfo.Id == Hero.MainHero.Clan.Kingdom?.StringId && kingdomLeader.StringId != Hero.MainHero.StringId)
                {
                    new WarEvent();
                }

                loyalClans.Clear();
                plottingClans.Clear();
                foreach (var clan in clans)
                {
                    var clanLeader     = clan.Leader;
                    var clanLeaderInfo = Managers.Character.Get(clanLeader.CharacterObject);

                    if (clanLeaderInfo.PlotState == PlotState.IsLoyal)
                    {
                        loyalClans.Add(clan);
                    }
                    else if (clanLeaderInfo.PlotState == PlotState.IsPlotting)
                    {
                        plottingClans.Add(clan);
                    }
                }

                if (plottingClans.Count == 0)
                {
                    if (RevolutionsSettings.Instance.DebugMode)
                    {
                        InformationManager.DisplayMessage(new InformationMessage($"Revolutions.CivilWars: There are no plotting clans.", ColorHelper.Gray));
                    }

                    return(true);
                }

                Managers.Character.Get(plottingLeader.CharacterObject).IsCivilWarKingdomLeader = true;

                var settlementInfo = Managers.Settlement.Get(plotLeadingClan.HomeSettlement);
                var bannerInfo     = Managers.Banner.GetBanner(settlementInfo);

                var textObject = new TextObject(Localization.GameTexts.CivilWarsKingdom);
                textObject.SetTextVariable("CLAN", plottingLeader.Name);
                var plotKingdom = Managers.Kingdom.CreateKingdom(plotLeadingClan.Leader, textObject, textObject, bannerInfo != null ? new Banner(bannerInfo.BannerId) : plotLeadingClan.Banner, false);
                Managers.Kingdom.Get(plotKingdom).IsCivilWarKingdom = true;

                ChangeRelationAction.ApplyRelationChangeBetweenHeroes(plottingLeader, kingdomLeader, -(int)(RevolutionsSettings.Instance.CivilWarsRelationshipChange * (RevolutionsSettings.Instance.CivilWarsRelationshipChangeMultiplier * 2)), false);

                foreach (var clan1 in clans.Where(c1 => c1.StringId != plotLeadingClan.StringId))
                {
                    var clanLeader1 = Managers.Character.Get(clan1.Leader.CharacterObject);
                    if (clanLeader1.PlotState == PlotState.IsLoyal)
                    {
                        ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan1.Leader, kingdomLeader, (int)(RevolutionsSettings.Instance.CivilWarsRelationshipChange * RevolutionsSettings.Instance.CivilWarsRelationshipChangeMultiplier), false);
                        ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan1.Leader, plottingLeader, -(int)(RevolutionsSettings.Instance.CivilWarsRelationshipChange * RevolutionsSettings.Instance.CivilWarsRelationshipChangeMultiplier), false);
                    }
                    else if (clanLeader1.PlotState == PlotState.IsPlotting)
                    {
                        ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan1.Leader, plottingLeader, (int)(RevolutionsSettings.Instance.CivilWarsRelationshipChange * RevolutionsSettings.Instance.CivilWarsRelationshipChangeMultiplier), false);
                        ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan1.Leader, kingdomLeader, -(int)(RevolutionsSettings.Instance.CivilWarsRelationshipChange * RevolutionsSettings.Instance.CivilWarsRelationshipChangeMultiplier), false);
                    }

                    foreach (var clan2 in clans.Where(c2 => c2.StringId != clan1.StringId && c2.StringId != plotLeadingClan.StringId))
                    {
                        var clanLeader2 = Managers.Character.Get(clan2.Leader.CharacterObject);

                        if (clanLeader1.PlotState == clanLeader2.PlotState)
                        {
                            ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan1.Leader, clan2.Leader, RevolutionsSettings.Instance.CivilWarsRelationshipChange, false);
                        }
                        else
                        {
                            ChangeRelationAction.ApplyRelationChangeBetweenHeroes(clan1.Leader, clan2.Leader, -RevolutionsSettings.Instance.CivilWarsRelationshipChange, false);
                        }
                    }
                }

                textObject = new TextObject(Localization.GameTexts.CivilWarsWarMapNotification);
                textObject.SetTextVariable("PLOTKINGDOM", plotKingdom.Name);
                textObject.SetTextVariable("KINGDOM", kingdomInfo.Kingdom.Name);
                InformationManager.AddNotice(new WarMapNotification(plotKingdom, kingdomInfo.Kingdom, textObject));

                textObject = new TextObject(Localization.GameTexts.CivilWarsQuickNotification);
                textObject.SetTextVariable("KINGDOM", kingdomInfo.Kingdom.Name);
                textObject.SetTextVariable("LEADER", plotLeadingClan.Leader.Name);
                textObject.SetTextVariable("CLAN", plotLeadingClan.Name);
                InformationManager.AddQuickInformation(textObject);

                var otherPlottingClans = plottingClans.Where(go => go.StringId != plotLeadingClan.StringId);
                if (otherPlottingClans.Count() == 0)
                {
                    textObject = new TextObject(Localization.GameTexts.CivilWarsLeaderAlone);
                    textObject.SetTextVariable("LEADER", plotLeadingClan.Leader.Name);
                    textObject.SetTextVariable("CLAN", plotLeadingClan.Name);
                    InformationManager.DisplayMessage(new InformationMessage(textObject.ToString(), ColorHelper.Orange));
                }

                foreach (var plottingClan in otherPlottingClans)
                {
                    textObject = new TextObject(Localization.GameTexts.CivilWarsJoinsConspirators);
                    textObject.SetTextVariable("LEADER", plottingClan.Leader.Name);
                    textObject.SetTextVariable("CLAN", plottingClan.Name);
                    InformationManager.DisplayMessage(new InformationMessage(textObject.ToString(), ColorHelper.Orange));

                    ChangeKingdomAction.ApplyByJoinToKingdom(plottingClan, plotKingdom, false);
                }

                foreach (var loyalClan in loyalClans)
                {
                    textObject = new TextObject(Localization.GameTexts.CivilWarsJoinsConspirators);
                    textObject.SetTextVariable("LEADER", loyalClan.Leader.Name);
                    textObject.SetTextVariable("CLAN", loyalClan.Name);
                    InformationManager.DisplayMessage(new InformationMessage(textObject.ToString(), ColorHelper.Orange));
                }

                DeclareWarAction.Apply(plotKingdom, kingdomInfo.Kingdom);

                if (RevolutionsSettings.Instance.CivilWarsKeepExistingWars)
                {
                    foreach (var enemyFaction in FactionManager.GetEnemyFactions(kingdomInfo.Kingdom).ToList())
                    {
                        if (!enemyFaction.Equals(plotKingdom))
                        {
                            DeclareWarAction.Apply(plotKingdom, enemyFaction);
                        }
                    }
                }

                Managers.CivilWar.CivilWars.Add(new CivilWar(kingdomInfo.Kingdom, clans));
                kingdomInfo.HasCivilWar = true;
            }

            return(false);
        }
        // [HarmonyPrefix]
        // [HarmonyPatch("ThinkAboutDeclaringWar")]
        private static bool ThinkAboutDeclaringWar(PoliticalStagnationAndBorderIncidentCampaignBehavior __instance, Kingdom kingdom)
        {
            var atWars = Kingdom.All.Where(a => a != kingdom && a.IsAtWarWith(kingdom)).ToList();

            if (atWars.Count > 1)
            {
                return(false);
            }

            List <IFaction> possibleKingdomsToDeclareWar = FactionHelper.GetPossibleKingdomsToDeclareWar(kingdom);


            var             nears   = DiplomacySetting.GetNearFactionsWithFaction(kingdom, Kingdom.All);
            var             results = nears.Intersect(possibleKingdomsToDeclareWar).ToList();
            float           num     = 0f;
            IFaction        faction = null;
            List <IFaction> occupy  = DiplomacySetting.GetAllFactionOccupyFactionSettlement(kingdom);

            foreach (IFaction item in results)
            {
                var factor1 = 1f;

                var atWars2 = Kingdom.All.Where(a => a != item && a.IsAtWarWith(item)).Count();
                if (occupy.Contains(item))
                {
                    if (DiplomacySetting.InTruce(kingdom, item))
                    {
                        if (atWars2 < 1)
                        {
                            continue;
                        }
                        if (atWars2 < 2 && MBRandom.RandomFloat < 0.5f)
                        {
                            continue;
                        }
                    }

                    factor1 = 1.5f;
                }
                else
                {
                    if (atWars2 > 2)
                    {
                        continue;
                    }
                    if (DiplomacySetting.InTruce(kingdom, item))
                    {
                        continue;
                    }
                }

                //float scoreOfDeclaringWar = factor1 * Campaign.Current.Models.DiplomacyModel.GetScoreOfDeclaringWar(kingdom, item);
                float scoreOfDeclaringWar = factor1 * 1f;

                if (kingdom.Culture == item.Culture)
                {
                    var factor = Math.Max(0.1f, 1 - Kingdom.All.Where(a => a.MapFaction != null && a.MapFaction.Settlements.Where(t => t.IsTown).Count() > 3 && (a.Culture != kingdom.Culture || a.Ruler == Hero.MainHero)).Count() * 0.15f);
                    scoreOfDeclaringWar *= factor * 0.5f;
                }

                if (scoreOfDeclaringWar > num)
                {
                    faction = item;
                    num     = scoreOfDeclaringWar;
                }
            }

            if (faction != null && MBRandom.RandomFloat < 0.2f)
            {
                DeclareWarAction.ApplyDeclareWarOverProvocation(kingdom, faction);
            }
            return(false);
        }