Beispiel #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 void OnSettlementOwnerChangedEvent(Settlement settlement, bool openToClaim, Hero newOwner, Hero oldOwner, Hero capturedHero, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail detail)
        {
            var settlementInfo = Managers.Settlement.Get(settlement);

            settlementInfo.UpdateOwnerRevolt(newOwner.MapFaction);

            if (capturedHero?.PartyBelongedTo?.Party != null)
            {
                var revolt = RevoltManager.Instance.GetRevoltByParty(capturedHero.PartyBelongedTo.Party);
                if (revolt != null && !RevolutionsSettings.Instance.RevoltsMinorFactionsMechanic && revolt.IsMinorFaction)
                {
                    if (revolt.SettlementInfo.CurrentFaction == revolt.SettlementInfo.LoyalFaction)
                    {
                        var previousFactionOwner = BaseManagers.Faction.GetLordWithLeastFiefs(revolt.SettlementInfo.PreviousFaction).HeroObject;
                        ChangeOwnerOfSettlementAction.ApplyByRevolt(previousFactionOwner, settlement);
                    }
                    else
                    {
                        var loyalFactionOwner = BaseManagers.Faction.GetLordWithLeastFiefs(revolt.SettlementInfo.LoyalFaction).HeroObject;
                        ChangeOwnerOfSettlementAction.ApplyByRevolt(loyalFactionOwner, settlement);
                    }

                    Managers.Kingdom.DestroyKingdom(capturedHero.Clan.Kingdom);
                    Managers.Clan.DestroyClan(capturedHero.Clan);
                    capturedHero.PartyBelongedTo.RemoveParty();
                    KillCharacterAction.ApplyByRemove(capturedHero);

                    RevoltManager.Instance.Revolts.Remove(revolt);
                }
            }
        }
 private static void OnSettlementOwnerChanged(Settlement settlement, bool openToClaim, Hero newOwner, Hero oldOwner, Hero capturerHero, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail detail)
 {
     if (settlement.IsFortification &&
         newOwner != capturerHero &&
         detail == ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail.BySiege)
     {
         ChangeOwnerOfSettlementAction.ApplyBySiege(capturerHero, capturerHero, settlement);
     }
 }
Beispiel #4
0
 private void TransferSettlementAction(Clan clan)
 {
     ChangeOwnerOfSettlementAction.ApplyByBarter(clan.Leader, Settlement.CurrentSettlement);
     if (Settlement.CurrentSettlement.IsTown)
     {
         ChangeRelationAction.ApplyPlayerRelation(clan.Leader, 40);
     }
     else if (Settlement.CurrentSettlement.IsCastle)
     {
         ChangeRelationAction.ApplyPlayerRelation(clan.Leader, 20);
     }
 }
Beispiel #5
0
 static bool Prefix(KingdomSettlementItemVM ____currentSelectedSettlement)
 {
     if (____currentSelectedSettlement.Settlement.OwnerClan == Clan.PlayerClan)
     {
         var name = ____currentSelectedSettlement.Settlement.Name;
         InformationManager.DisplayMessage(new InformationMessage($"You have given away {name}"));
         ChangeOwnerOfSettlementAction.ApplyBySiege(Clan.PlayerClan.MapFaction.Leader,
                                                    null, ____currentSelectedSettlement.Settlement);
         return(false);
     }
     return(true);
 }
Beispiel #6
0
 public static void ShowKeepFiefInquiry(Settlement settlement, Action declineAction)
 {
     InformationManager.ShowInquiry(
         new InquiryData(
             new TextObject("{=N06wk0dB}Settlement Captured").ToString(),
             GetKeepFiefText(settlement).ToString(),
             true, true,
             new TextObject("{=Y94H6XnK}Accept").ToString(),
             new TextObject("{=cOgmdp9e}Decline").ToString(), delegate()
     {
         ChangeOwnerOfSettlementAction.ApplyByDefault(Hero.MainHero, settlement);
     }, declineAction, ""), true);
 }
        public static void DealLordForClan(Hero hero)
        {
            Clan clan = hero.Clan;

            if (clan.Leader == hero)
            {
                List <Hero> others = clan.Heroes.Where((obj) => (obj != hero && obj.IsAlive)).ToList();
                if (others.Count() > 0)
                {
                    Hero target = others.GetRandomElement();
                    ChangeClanLeaderAction.ApplyWithSelectedNewLeader(clan, target);

                    TextObject textObject = GameTexts.FindText("sue_more_spouses_clan_leave", null);
                    StringHelpers.SetCharacterProperties("SUE_HERO", hero.CharacterObject, null, textObject);
                    InformationManager.AddQuickInformation(textObject, 0, null, "event:/ui/notification/quest_finished");

                    textObject = GameTexts.FindText("sue_more_spouses_clan_change", null);
                    StringHelpers.SetCharacterProperties("SUE_HERO", target.CharacterObject, null, textObject);
                    InformationManager.AddQuickInformation(textObject, 0, null, "event:/ui/notification/quest_finished");
                }
                else
                {
                    List <Settlement> settlements = clan.Settlements.ToList();
                    settlements.ForEach((settlement) => ChangeOwnerOfSettlementAction.ApplyByDestroyClan(settlement, Hero.MainHero));
                    List <Hero> deadHeros = clan.Heroes.Where((obj) => (obj != hero && obj.IsDead)).ToList();
                    Hero        target    = null;
                    if (deadHeros.Count > 0)
                    {
                        target = deadHeros.GetRandomElement();
                        clan.SetLeader(target);
                    }
                    else
                    {
                        CharacterObject character = CharacterObject.FindFirst(obj => obj.Culture == hero.Culture && obj.Occupation == Occupation.Lord);
                        target = HeroCreator.CreateSpecialHero(character, hero.HomeSettlement, null, null, -1);
                        target.ChangeState(CharacterStates.Dead);
                        target.Clan = clan;
                        CampaignEventDispatcher.Instance.OnHeroCreated(target, false);
                        clan.SetLeader(target);
                    }

                    if (null != GameComponent.CampaignEventDispatcher())
                    {
                        GameComponent.CampaignEventDispatcher().OnClanLeaderChanged(hero, target);
                    }
                    DestroyClanAction.Apply(clan);
                    dealKindomLeader(clan, hero);
                }
            }
            hero.Clan = Clan.PlayerClan;
        }
Beispiel #8
0
        public static void Apply(Settlement settlement, Clan grantedClan)
        {
            ChangeOwnerOfSettlementAction.ApplyByDefault(grantedClan.Leader, settlement);

            int relationChange = CalculateBaseRelationChange(settlement);

            ChangeRelationAction.ApplyPlayerRelation(grantedClan.Leader, relationChange);

            foreach (Clan clan in Clan.PlayerClan.Kingdom.Clans.Where(clan => clan != grantedClan && clan != Clan.PlayerClan))
            {
                ChangeRelationAction.ApplyPlayerRelation(clan.Leader, Settings.Instance.GrantFiefRelationPenalty);
            }

            Events.Instance.OnFiefGranted(settlement.Town);
        }
Beispiel #9
0
        private void AddScaHeroesToWorld(MBReadOnlyList <MobileParty> mobileParties)
        {
            if (mobileParties == null)
            {
                InformationManager.DisplayMessage(new InformationMessage("SCA3: mobileParties was null! Abandoning SCA3 party setup...", Color.FromUint(4278255360U)));
                return;
            }

            var parties = mobileParties.ToList();

            InformationManager.DisplayMessage(
                new InformationMessage($"SCA3: Mobile parties has {parties.Count } parties in it. Filtering for SCA heroes...", Color.FromUint(4278255360U)));

            foreach (var scaHero in _heroLocations)
            {
                InformationManager.DisplayMessage(
                    new InformationMessage($"SCA3: Looping through SCA hero list. We see { scaHero.HeroName}.", Color.FromUint(4278255360U)));

                try
                {
                    var party = parties
                                .Where(p => p.Leader?.Name != null && p.Leader.Name.ToString() == scaHero.HeroName)
                                .SingleOrDefault();

                    if (party == null)
                    {
                        InformationManager.DisplayMessage(
                            new InformationMessage($"SCA3: party lead by SCA hero '{scaHero.HeroName} ({scaHero.HeroId})' not found in mobileParties! Skipping hero.", Color.FromUint(4278255360U)));
                        continue;
                    }

                    InformationManager.DisplayMessage(
                        new InformationMessage($"SCA3: Found party lead by SCA hero {scaHero.HeroName}! (It is {party.Id})", Color.FromUint(4278255360U)));

                    var settlement = Settlement.Find(scaHero.SettlementId);
                    ChangeOwnerOfSettlementAction.ApplyByDefault(party.LeaderHero, settlement);
                    party.Position2D = new Vec2(
                        settlement.Position2D.X + scaHero.XOffset,
                        settlement.Position2D.Y + scaHero.YOffset);
                    party.SetMovePatrolAroundSettlement(settlement);
                }
                catch (Exception ex)
                {
                    InformationManager.DisplayMessage(
                        new InformationMessage($"SCA3: Error looping through hero locations on hero: {scaHero.HeroName}! Message: {ex.Message}"));
                }
            }
        }
        public static void Apply(Settlement settlement, Clan grantedClan)
        {
            ChangeOwnerOfSettlementAction.ApplyByDefault(grantedClan.Leader, settlement);

            var relationChange = CalculateBaseRelationChange(settlement);

            ChangeRelationAction.ApplyPlayerRelation(grantedClan.Leader, relationChange);

            foreach (var clan in Clan.PlayerClan.Kingdom.Clans.Where(c => c != grantedClan && c != Clan.PlayerClan))
            {
                ChangeRelationAction.ApplyPlayerRelation(clan.Leader, Settings.Instance !.GrantFiefRelationPenalty);
            }

            // gain generosity when granting fief
            PlayerCharacterTraitEventExperience.FiefGranted.Apply();

            Events.Instance.OnFiefGranted(settlement.Town);
        }
Beispiel #11
0
        private void SetPlayerStartingConditions()
        {
            string PlayerCulture = Hero.MainHero.Culture.Name.ToString();

            DebugConsole.Log(this, "Player culture is: " + PlayerCulture);
            switch (PlayerCulture)
            {
            case "Vlandia":
                ChangeOwnerOfSettlementAction.ApplyByDefault(Hero.MainHero, Settlement.Find("town_V7"));
                DebugConsole.Log(this, "Giving player city Charas town_V7");
                break;

            case "Sturgia":
                ChangeOwnerOfSettlementAction.ApplyByDefault(Hero.MainHero, Settlement.Find("town_S5"));
                DebugConsole.Log(this, "Giving player city Tyal town_S5");
                break;

            case "Empire":
                ChangeOwnerOfSettlementAction.ApplyByDefault(Hero.MainHero, Settlement.Find("town_ES4"));
                DebugConsole.Log(this, "Giving player city Lycaron town_ES4");
                break;

            case "Aserai":
                ChangeOwnerOfSettlementAction.ApplyByDefault(Hero.MainHero, Settlement.Find("town_A3"));
                DebugConsole.Log(this, "Giving player city Iyakis town_A3");
                break;

            case "Khuzait":
                ChangeOwnerOfSettlementAction.ApplyByDefault(Hero.MainHero, Settlement.Find("town_K2"));
                DebugConsole.Log(this, "Giving player city Akkalat town_K2");
                break;

            case "Battania":
                ChangeOwnerOfSettlementAction.ApplyByDefault(Hero.MainHero, Settlement.Find("town_B4"));
                DebugConsole.Log(this, "Giving player city Seonon town_B4");
                break;

            default:
                DebugConsole.Log(this, "Default");
                break;
            }
            InformationManager.DisplayMessage(new InformationMessage("Your Clan's benefactors supplied you with some money to aid in completing your mission", TaleWorlds.Library.Color.White, ""));
            Hero.MainHero.ChangeHeroGold(30000);
        }
Beispiel #12
0
        internal static void EndSucceededRevolt(Revolt revolt)
        {
            var textObject = new TextObject(GameTexts.RevoltsRevoltEnd);

            textObject.SetTextVariable("SETTLEMENT", revolt.Settlement.Name);
            InformationManager.AddQuickInformation(textObject);

            revolt.SettlementInfo.CurrentFactionInfo.CityRevoltionSucceeded(revolt.Settlement);

            if (RevolutionsSettings.Instance.RevoltsImperialLoyaltyMechanic && revolt.SettlementInfo.IsCurrentFactionOfImperialCulture && !revolt.SettlementInfo.IsLoyalFactionOfImperialCulture)
            {
                revolt.Settlement.OwnerClan.AddRenown(-RevolutionsSettings.Instance.RevoltsImperialRenownLoss);
            }

            if (RevolutionsSettings.Instance.RevoltsMinorFactionsMechanic && revolt.IsMinorFaction)
            {
                ChangeOwnerOfSettlementAction.ApplyByLeaveFaction(revolt.Party.LeaderHero, revolt.Settlement);
                revolt.Party.LeaderHero.Clan.AddRenown(RevolutionsSettings.Instance.RevoltsMinorFactionsRenownGainOnWin);

                foreach (var notable in revolt.Settlement.Notables.Concat(revolt.Settlement.BoundVillages.SelectMany(s => s.Settlement.Notables)))
                {
                    notable.SetPersonalRelation(revolt.Party.Leader.HeroObject, new Random().Next(5, 25));
                }

                var amountOTroops = (RevolutionsSettings.Instance.RevoltsGeneralBaseSize + (int)(revolt.Settlement.Prosperity * RevolutionsSettings.Instance.RevoltsGeneralProsperityMulitplier)) / 3;
                var eliteUnits    = new TroopRoster(revolt.Party);
                eliteUnits.AddToCounts(revolt.Party.Leader.Culture.RangedEliteMilitiaTroop, amountOTroops);
                eliteUnits.AddToCounts(revolt.Party.Leader.Culture.MeleeEliteMilitiaTroop, amountOTroops * 2);
                revolt.Party.MobileParty.MemberRoster.Add(eliteUnits);

                SetPartyAiAction.GetActionForPatrollingAroundSettlement(revolt.Party.MobileParty, revolt.Settlement);
                revolt.Party.MobileParty.Ai.SetDoNotMakeNewDecisions(false);

                Managers.Revolt.Revolts.Remove(revolt);
            }

            if (!RevolutionsSettings.Instance.RevoltsMinorFactionsMechanic || revolt.IsMinorFaction)
            {
                return;
            }

            revolt.Party.MobileParty.Ai.SetDoNotMakeNewDecisions(false);
            Managers.Revolt.Revolts.Remove(revolt);
        }
Beispiel #13
0
        private void ShowKeepFiefInquiry(Settlement settlement)
        {
            InformationManager.ShowInquiry(
                new InquiryData(
                    new TextObject("{=N06wk0dB}Settlement Captured").ToString(),
                    GetKeepFiefText(settlement).ToString(),
                    true, true,
                    new TextObject(StringConstants.Accept).ToString(),
                    new TextObject(StringConstants.Decline).ToString(),
                    () =>
            {
                settlement.Town.IsOwnerUnassigned = false;
                ChangeOwnerOfSettlementAction.ApplyByDefault(Hero.MainHero, settlement);

                // lose generosity when keeping fief
                PlayerCharacterTraitEventExperience.FiefClaimed.Apply();
            },
                    () => settlement.Town.IsOwnerUnassigned = true),
                true);
        }
 public static void CSGiveCastle(out Settlement Castle)
 {
     Castle = (from settlement in Settlement.All
               where settlement.Culture == Hero.MainHero.Culture && settlement.IsCastle
               select settlement).GetRandomElementInefficiently <Settlement>();
     if (Castle == null) //Adding this for custom cultures that don't have any land to start
     {
         Castle = (from settlement in Settlement.All
                   where settlement.IsCastle
                   select settlement).GetRandomElementInefficiently <Settlement>();
     }
     ChangeOwnerOfSettlementAction.ApplyByKingDecision(Hero.MainHero, Castle);
     if (CSCharCreationOption.CSLocationOption == 8)
     {
         MobileParty.MainParty.Position2D = Castle.GatePosition;
         MapState mapstate;
         mapstate = (GameStateManager.Current.ActiveState as MapState);
         mapstate.Handler.TeleportCameraToMainParty();
     }
 }
 private void ShowKeepFiefInquiry(Settlement settlement)
 {
     InformationManager.ShowInquiry(
         new InquiryData(
             new TextObject("{=N06wk0dB}Settlement Captured").ToString(),
             GetKeepFiefText(settlement).ToString(),
             true, true,
             new TextObject(StringConstants.Accept).ToString(),
             new TextObject(StringConstants.Decline).ToString(),
             () =>
     {
         settlement.Town.IsOwnerUnassigned = false;
         ChangeOwnerOfSettlementAction.ApplyByDefault(Hero.MainHero, settlement);
     },
             () =>
     {
         settlement.Town.IsOwnerUnassigned = true;
     },
             ""),
         true);
 }
        private static void ConsiderFiefGiveAway(Clan clan)
        {
            if (clan == Clan.PlayerClan || clan.Kingdom == null || clan.Kingdom.RulingClan != clan)
            {
                return;
            }

            if (clan.Settlements == null || clan.Settlements.Count(s => s.IsFortification) < 2)
            {
                return;
            }

            Kingdom kingdom = clan.Kingdom;

            if (kingdom.UnresolvedDecisions.FirstOrDefault((KingdomDecision x) => x is SettlementClaimantDecision) != null)
            {
                return;
            }

            Clan bomzh = kingdom.Clans.FirstOrDefault(c => !c.IsUnderMercenaryService &&
                                                      c.Heroes.Count(h => h.IsAlive) > 0 &&
                                                      (c.Settlements == null || c.Settlements.Count() == 0));

            if (bomzh == null)
            {
                return;
            }

            SettlementValueModel model = Campaign.Current.Models.SettlementValueModel;

            Settlement settlement = clan.Settlements
                                    .Where(s => s.IsFortification)
                                    .MaxBy(s => model.CalculateValueForFaction(s, kingdom));

            ChangeOwnerOfSettlementAction.ApplyByKingDecision(bomzh.Leader, settlement);
        }
Beispiel #17
0
        public void CreateVassal()
        {
            //Settlement settlement = GetCandidateSettlements().FirstOrDefault<Settlement>();
            if (targetSettlement == null)
            {
                return;
            }
            Hero hero = Hero.OneToOneConversationHero;

            if (hero == null)
            {
                return;
            }
            Kingdom kingdom = Hero.MainHero.MapFaction as Kingdom;

            if (kingdom == null)
            {
                return;
            }

            CultureObject culture  = targetSettlement.Culture;
            TextObject    clanName = NameGenerator.Current.GenerateClanName(culture, targetSettlement);
            string        str      = Guid.NewGuid().ToString().Replace("-", "");

            if (null == hero.LastSeenPlace)
            {
                hero.CacheLastSeenInformation(hero.HomeSettlement, true);
                hero.SyncLastSeenInformation();
            }
            //RemoveCompanionAction.ApplyByFire(Hero.MainHero.Clan, hero);
            //for  1.4.3 200815
            HeroOperation.DealApplyByFire(Hero.MainHero.Clan, hero);

            HeroOperation.SetOccupationToLord(hero);
            hero.ChangeState(Hero.CharacterStates.Active);
            Clan   clan   = TaleWorlds.ObjectSystem.MBObjectManager.Instance.CreateObject <Clan>("sue_clan_" + str);
            Banner banner = Banner.CreateRandomClanBanner(-1);

            clan.InitializeClan(clanName, clanName, culture, banner);
            clan.SetLeader(hero);

            //clan.Tier = 5; 修改家族等级
            FieldInfo fieldInfoId = clan.GetType().GetField("_tier", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            if (null != fieldInfoId)
            {
                fieldInfoId.SetValue(clan, selectClanTier);
            }
            //增加一些影响力
            clan.AddRenown(50 * selectClanTier, true);


            hero.Clan        = clan;
            hero.CompanionOf = null;
            hero.IsNoble     = true;
            hero.SetTraitLevel(DefaultTraits.Commander, 1);

            MobileParty mobileParty = clan.CreateNewMobileParty(hero);

            mobileParty.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
            mobileParty.ItemRoster.AddToCounts(DefaultItems.Meat, 5);

            ChangeOwnerOfSettlementAction.ApplyByKingDecision(hero, targetSettlement);
            clan.UpdateHomeSettlement(targetSettlement);


            int takeMoney = TakeMoneyByTier(selectClanTier);

            if (targetSpouse != null)
            {
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, hero, takeMoney / 2, false);
            }
            else
            {
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, hero, takeMoney, false);
            }

            //关系处理
            //新晋家族关系增加
            int shipIncreate = ShipIncreateByTier(selectClanTier);

            ChangeRelationAction.ApplyPlayerRelation(hero, shipIncreate, true, true);
            if (targetSpouse != null)
            {
                ChangeRelationAction.ApplyPlayerRelation(targetSpouse, shipIncreate, true, true);
            }

            //以前家族关系减低,
            int     shipReduce = ShipReduceByTier(selectClanTier);
            Kingdom kindom     = Hero.MainHero.MapFaction as Kingdom;

            if (null != kindom && shipReduce > 0)
            {
                kindom.Clans.ToList().ForEach((obj) =>
                {
                    if (obj != Clan.PlayerClan)
                    {
                        ChangeRelationAction.ApplyPlayerRelation(obj.Leader, shipReduce * -1, true, true);
                    }
                }
                                              );
            }

            if (targetSpouse != null)
            {
                targetSpouse.Spouse = hero;
                InformationManager.AddQuickInformation(new TextObject($"{hero.Name} marry with {targetSpouse.Name}"), 0, null, "event:/ui/notification/quest_finished");

                HeroOperation.DealApplyByFire(Hero.MainHero.Clan, targetSpouse);
                //RemoveCompanionAction.ApplyByFire(Hero.MainHero.Clan, targetSpouse);

                targetSpouse.ChangeState(Hero.CharacterStates.Active);
                targetSpouse.IsNoble = true;
                HeroOperation.SetOccupationToLord(targetSpouse);
                targetSpouse.CompanionOf = null;
                targetSpouse.Clan        = clan;
                targetSpouse.SetTraitLevel(DefaultTraits.Commander, 1);
                //AddCompanionAction.Apply(clan, targetSpouse);

                MobileParty targetSpouseMobileParty = clan.CreateNewMobileParty(targetSpouse);

                targetSpouseMobileParty.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
                targetSpouseMobileParty.ItemRoster.AddToCounts(DefaultItems.Meat, 5);
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, targetSpouse, takeMoney / 2, false);
            }

            // 他们孩子处理
            if (isTogetherWithThireChildren)
            {
                DealTheirChildren(hero, clan);
            }


            //加入王国
            ChangeKingdomAction.ApplyByJoinToKingdom(clan, kingdom, true);
        }
Beispiel #18
0
        private void RevoltMapEventEnd(MapEvent mapEvent)
        {
            PartyBase      revs        = null;
            SettlementInfo currentInfo = null;
            Settlement     settlement  = null;

            foreach (Tuple <PartyBase, SettlementInfo> pair in Revolutionaries)
            {
                if (mapEvent.InvolvedParties.Contains(pair.Item1))
                {
                    revs        = pair.Item1;
                    currentInfo = pair.Item2;
                    settlement  = currentInfo.Settlement;
                    break;
                }
            }

            if (revs == null)
            {
                return;
            }

            var winnerSide = mapEvent.BattleState == BattleState.AttackerVictory ? mapEvent.AttackerSide : mapEvent.DefenderSide;
            var loserSide  = winnerSide.MissionSide.GetOppositeSide();

            bool revVictory = false;

            foreach (var party in winnerSide.PartiesOnThisSide)
            {
                if (party.MobileParty.Id == revs.MobileParty.Id)
                {
                    revVictory = true;
                    break;
                }
            }

            if (!revVictory)
            {
                GetFactionInformation(settlement.MapFaction).CityRevoltedFailure(settlement);
                RemoveRevolutionaryPartyFromList(revs);
                return;
            }

            Hero selectedHero = null;

            selectedHero = GetNobleWithLeastFiefs(revs.Owner.MapFaction);
            RemoveRevolutionaryPartyFromList(revs);

            if (revs.Owner.MapFaction.StringId == currentInfo.OriginalFaction.StringId)
            {
                revs.MobileParty.RemoveParty();
                ChangeOwnerOfSettlementAction.ApplyByDefault(selectedHero, currentInfo.Settlement);
            }
            else
            {
                revs.MobileParty.IsLordParty = true;
                revs.MobileParty.Ai.EnableAi();;
                revs.MobileParty.Ai.SetDoNotMakeNewDecisions(false);
                revs.MobileParty.Name = revs.Owner.Name;
                Clan ownerClan = revs.Owner.Clan;
                ownerClan.AddParty(revs);

                if (!ModOptions.OptionsData.AllowMinorFactions)
                {
                    selectedHero = GetNobleWithLeastFiefs(currentInfo.OriginalFaction.MapFaction);
                    revs.MobileParty.RemoveParty();
                    DestroyKingdomAction.Apply(ownerClan.Kingdom);
                    Common.Instance.ModifyKingdomList(kingdoms => kingdoms.Remove(ownerClan.Kingdom));
                }
                else
                {
                    if (!selectedHero.Clan.IsKingdomFaction)
                    {
                        revs.MobileParty.RemoveParty();
                    }
                }

                ChangeOwnerOfSettlementAction.ApplyByDefault(selectedHero, currentInfo.Settlement);
            }

            GetFactionInformation(settlement.MapFaction).CityRevoltedSuccess(settlement);
            settlement.AddGarrisonParty(true);
        }
        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 #20
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);
            }
        }
Beispiel #21
0
        private void CastleAbandonSettlementMenuOption(CampaignGameStarter campaignGameStarter)
        {
            campaignGameStarter.AddGameMenuOption("ruler_castle_menu", "ruler_castle_abandon", "Abandon Rulership of Castle", (GameMenuOption.OnConditionDelegate)(args =>
            {
                args.optionLeaveType = GameMenuOption.LeaveType.Manage;
                if (Settlement.CurrentSettlement.OwnerClan.Kingdom != null && Settlement.CurrentSettlement.OwnerClan.Kingdom.Leader != Hero.MainHero)
                {
                    args.Tooltip   = new TextObject("You must be the faction leader to abandon a settlement");
                    args.IsEnabled = false;
                }

                args.Tooltip = new TextObject("A minor noble will take control of the settlement");

                return(true);
            }), (GameMenuOption.OnConsequenceDelegate)(args => {
                InformationManager.ShowInquiry(new InquiryData("Abandon Castle", "Are you sure you want to abandon this castle?", true, true, "Yes", "No", (Action)(() => {
                    List <CharacterObject> source = new List <CharacterObject>();
                    CultureObject culture = Settlement.CurrentSettlement.Culture;
                    foreach (CharacterObject characterObject in CharacterObject.Templates.Where <CharacterObject>((Func <CharacterObject, bool>)(x => x.Occupation == Occupation.Lord)).ToList <CharacterObject>())
                    {
                        if (characterObject.Culture == culture)
                        {
                            source.Add(characterObject);
                        }
                    }
                    CharacterObject template = source[rng.Next(0, source.Count - 1)];
                    Hero NewHero = HeroCreator.CreateSpecialHero(template, Settlement.CurrentSettlement, null, Hero.MainHero.Clan, rng.Next(25, 30));
                    NewHero.ChangeState(Hero.CharacterStates.Active);
                    HeroCreationCampaignBehavior herocreationbehavior = new HeroCreationCampaignBehavior();
                    herocreationbehavior.DeriveSkillsFromTraits(NewHero, template);

                    List <CharacterObject> source2 = new List <CharacterObject>();
                    foreach (CharacterObject characterObject in CharacterObject.Templates.Where <CharacterObject>((Func <CharacterObject, bool>)(x => x.Occupation == Occupation.Lord)).ToList <CharacterObject>())
                    {
                        if (characterObject.Culture == culture)
                        {
                            source2.Add(characterObject);
                        }
                    }
                    CharacterObject template2 = source2[rng.Next(0, source2.Count - 1)];
                    template2.IsFemale = true;
                    Hero NewHero2 = HeroCreator.CreateSpecialHero(template2, Settlement.CurrentSettlement, null, Hero.MainHero.Clan, rng.Next(25, 30));
                    NewHero2.ChangeState(Hero.CharacterStates.Active);
                    herocreationbehavior.DeriveSkillsFromTraits(NewHero2, template2);
                    template2.IsFemale = false;

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

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

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

                    ChangeOwnerOfSettlementAction.ApplyByKingDecision(NewHero, Settlement.CurrentSettlement);
                    clan.UpdateHomeSettlement(Settlement.CurrentSettlement);

                    MarriageAction.Apply(NewHero, NewHero2);
                    ChangeRelationAction.ApplyPlayerRelation(NewHero, 40);
                }), (Action)(() => {
                    GameMenu.SwitchToMenu("castle");
                })), true);
            }), index: 1);;;
        }
Beispiel #22
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;
        }