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); }
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); }
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); }