private void ClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, bool byRebellion, bool showNotification)
        {
            foreach (var settlement in clan.Settlements)
            {
                var settlementInfo = Managers.Settlement.Get(settlement);
                settlementInfo.PreviousFactionId = settlementInfo.CurrentFactionId;
                settlementInfo.CurrentFactionId  = clan.MapFaction.StringId;
            }

            var clanInfo = Managers.Clan.Get(clan);

            if (clan.StringId == Clan.PlayerClan.StringId || clanInfo.CanChangeKingdom || !clanInfo.IsRevoltClan || clan.StringId == newKingdom.RulingClan.StringId ||
                clan.Culture.Name.ToString().ToLower().Contains("empire") && newKingdom.Culture.Name.ToString().ToLower().Contains("empire") ||
                clan.Culture.Name.ToString() == newKingdom.Culture.Name.ToString())
            {
                return;
            }

            clan.ClanLeaveKingdom(false);
        }
Beispiel #2
0
        private void ClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, bool byRebellion, bool showNotification)
        {
            if (oldKingdom == null)
            {
                return;
            }

            var kingdomInfo = Managers.Kingdom.Get(oldKingdom);

            if (kingdomInfo == null || !kingdomInfo.IsCivilWarKingdom)
            {
                return;
            }

            var clans = oldKingdom.Clans.Where(go => !go.IsUnderMercenaryService && !go.IsClanTypeMercenary);

            if (clans.Count() > 0)
            {
                return;
            }

            foreach (var currentClan in oldKingdom.Clans.ToList())
            {
                foreach (var enemyFaction in Campaign.Current.Factions.Where(go => go.IsAtWarWith(currentClan)))
                {
                    if (clan.IsAtWarWith(enemyFaction))
                    {
                        FactionHelper.FinishAllRelatedHostileActionsOfFactionToFaction(enemyFaction, currentClan);
                        FactionHelper.FinishAllRelatedHostileActionsOfFactionToFaction(currentClan, enemyFaction);
                    }
                }

                clan.ClanLeaveKingdom(false);
            }

            Managers.Kingdom.DestroyKingdom(oldKingdom);
        }
        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);
        }
Beispiel #4
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);
        }