示例#1
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);
        }