コード例 #1
0
        private void CheckRevoltProgress(Settlement settlement)
        {
            SettlementInfo info = GetSettlementInformation(settlement);

            if (info.OriginalFaction.Name == settlement.MapFaction.Name)
            {
                return;
            }

            if (!GetFactionInformation(info.CurrentFaction).RevoltCanHappen() || OwnedByRevoltKingdom(info))
            {
                info.RevoltProgress = 0;
                return;
            }

            info.RevoltProgress = info.RevoltProgress + (MinimumObedianceLoyalty - settlement.Town.Loyalty);

            if (info.RevoltProgress >= 100 && !info.Settlement.IsUnderSiege)
            {
                RevoltLogic(info, settlement);
            }

            if (info.RevoltProgress < 0)
            {
                info.RevoltProgress = 0;
            }
        }
コード例 #2
0
 private void RegisterSettlements()
 {
     foreach (var settlement in Settlement.All)
     {
         SettlementInfo settInf = new SettlementInfo(settlement);
         SettlementInformation.Add(settInf);
     }
 }
コード例 #3
0
        private void OnSettlementOwnerChangedEvent(Settlement settlement, bool bl, Hero hero1, Hero hero2, Hero hero3, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail detail)
        {
            SettlementInfo settlementInfo = GetSettlementInformation(settlement);

            if (settlementInfo != null)
            {
                settlementInfo.ResetOwnership();
            }
        }
コード例 #4
0
        private bool OwnedByRevoltKingdom(SettlementInfo info)
        {
            string kingdomSettlementId = GetClanKingdomId(info.Settlement);

            if (info.CurrentFaction.StringId == kingdomSettlementId)
            {
                return(true);
            }

            return(false);
        }
コード例 #5
0
        private void CreateLoyaltyMenu(CampaignGameStarter obj)
        {
            TextObject menuName = GameTexts.FindText("str_GM_TownLoyalty");

            obj.AddGameMenuOption("town", "town_enter_entr_option", menuName.ToString(), (MenuCallbackArgs args) =>
            {
                args.optionLeaveType = GameMenuOption.LeaveType.Submenu;
                return(true);
            }, (MenuCallbackArgs args) =>
            {
                SettlementInfo setinf = GetSettlementInformation(Settlement.CurrentSettlement);
                FactionInfo factinfo  = GetFactionInformation(Settlement.CurrentSettlement.MapFaction);
                ScreenManager.PushScreen(new TownRevolutionScreen(setinf, factinfo));
            }, false, 4);
        }
コード例 #6
0
        public SettlementInfo GetSettlementInformation(Settlement settlement)
        {
            foreach (var settlementInfo in SettlementInformation)
            {
                if (settlementInfo.Settlement.StringId == settlement.StringId)
                {
                    return(settlementInfo);
                }
            }

            SettlementInfo missingSettlement = new SettlementInfo(settlement);

            SettlementInformation.Add(missingSettlement);

            return(missingSettlement);
        }
コード例 #7
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);
        }
コード例 #8
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;
        }
コード例 #9
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);
        }