Esempio n. 1
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,
                clan,
                oldKingdom,
                newKingdom,
                newKingdom == null || rebellion);
            clan.EndMercenaryService(true);
            if (oldKingdom != null)
            {
                clan.ClanLeaveKingdom(false);
            }
            if (newKingdom != null)
            {
                clan.Kingdom = 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);
        }