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;
        }
예제 #2
0
        static bool Prefix(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail actionDetail, bool showNotification)
        {
            bool mapEvent;
            bool siegeEvent;

            if (!victim.IsAlive)
            {
                return(false);
            }
            victim.EncyclopediaText = (TextObject)typeof(KillCharacterAction).GetMethod("CreateObituary", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly).Invoke(null, new object[] { victim, actionDetail });
            MobileParty partyBelongedTo = victim.PartyBelongedTo;

            if (partyBelongedTo != null)
            {
                mapEvent = partyBelongedTo.MapEvent != null;
            }
            else
            {
                mapEvent = false;
            }
            if (!mapEvent)
            {
                MobileParty mobileParty = victim.PartyBelongedTo;
                if (mobileParty != null)
                {
                    siegeEvent = mobileParty.SiegeEvent != null;
                }
                else
                {
                    siegeEvent = false;
                }
                if (!siegeEvent)
                {
                    if (victim.IsHumanPlayerCharacter && victim.DeathMark == KillCharacterAction.KillCharacterActionDetail.None)
                    {
                        victim.MakeWounded(killer, actionDetail);
                        typeof(CampaignEventDispatcher).GetMethod("OnBeforeMainCharacterDied", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly).Invoke(CampaignEventDispatcher.Instance, null);
                        //CampaignEventDispatcher.Instance.OnBeforeMainCharacterDied();
                        return(false);
                    }
                    StatisticsDataLogHelper.AddLog(StatisticsDataLogHelper.LogAction.KillCharacterAction, new Object[] { victim });
                    if (victim.Clan.Leader == victim && victim != Hero.MainHero)
                    {
                        if (victim.Clan.Heroes.Any <Hero>((Hero x) => {
                            if (x.IsChild || x == victim || !x.IsAlive)
                            {
                                return(false);
                            }
                            return(x.IsNoble);
                        }))
                        {
                            ChangeClanLeaderAction.ApplyWithoutSelectedNewLeader(victim.Clan);
                        }
                        else if (victim.Clan.Kingdom != null && victim.Clan.Kingdom.RulingClan == victim.Clan)
                        {
                            Clan clan = (Clan)typeof(KillCharacterAction).GetMethod("SelectHeirClanForKingdom", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly).Invoke(null, new object[] { victim.Clan.Kingdom, true });
                            //Clan clan = KillCharacterAction.SelectHeirClanForKingdom(victim.Clan.Kingdom, true);
                            if (clan == null)
                            {
                                DestroyKingdomAction.Apply(victim.Clan.Kingdom);
                            }
                            else
                            {
                                victim.Clan.Kingdom.RulingClan = clan;
                            }
                        }
                    }
                    if (victim.PartyBelongedTo != null && victim.PartyBelongedTo.Leader == victim.CharacterObject)
                    {
                        if (victim.PartyBelongedTo.Army != null)
                        {
                            if (victim.PartyBelongedTo.Army.LeaderParty != victim.PartyBelongedTo)
                            {
                                victim.PartyBelongedTo.Army = null;
                            }
                            else
                            {
                                victim.PartyBelongedTo.Army.DisperseArmy(Army.ArmyDispersionReason.ArmyLeaderIsDead);
                            }
                        }
                        victim.PartyBelongedTo.SetMoveModeHold();
                    }
                    typeof(KillCharacterAction).GetMethod("MakeDead", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly).Invoke(null, new object[] { victim, true });
                    //KillCharacterAction.MakeDead(victim, true);
                    if (victim.GovernorOf != null)
                    {
                        ChangeGovernorAction.ApplyByGiveUpCurrent(victim);
                    }
                    if (actionDetail != KillCharacterAction.KillCharacterActionDetail.Executed)
                    {
                        if (killer != null && !victim.Clan.IsMapFaction)
                        {
                            foreach (Hero all in Hero.All)
                            {
                                if (!all.IsAlive || all == victim || all.IsNoble && all.Clan.Leader != all)
                                {
                                    continue;
                                }
                                if (all.Clan != victim.Clan)
                                {
                                    if (!victim.IsFriend(all))
                                    {
                                        continue;
                                    }
                                    ChangeRelationAction.ApplyRelationChangeBetweenHeroes(killer, all, -10, all.IsNoble);
                                }
                                else
                                {
                                    ChangeRelationAction.ApplyRelationChangeBetweenHeroes(killer, all, -40, true);
                                }
                            }
                        }
                    }
                    else if (actionDetail == KillCharacterAction.KillCharacterActionDetail.Executed && killer == Hero.MainHero)
                    {
                        if (victim.GetTraitLevel(DefaultTraits.Honor) >= 0)
                        {
                            //TraitLevelingHelper.OnLordExecuted();
                            foreach (Hero hero in Hero.All)
                            {
                                if (!hero.IsAlive || hero == victim || hero.IsNoble && hero.Clan.Leader != hero)
                                {
                                    continue;
                                }
                                if (hero.Clan == victim.Clan)
                                {
                                    ChangeRelationAction.ApplyPlayerRelation(hero, -60, true, true);
                                }
                                else if (victim.IsFriend(hero))
                                {
                                    ChangeRelationAction.ApplyPlayerRelation(hero, -30, true, hero.IsNoble);
                                }
                                else if (hero.MapFaction != victim.MapFaction || hero.CharacterObject.Occupation != Occupation.Lord)
                                {
                                    if (hero.GetTraitLevel(DefaultTraits.Honor) <= 0 || !hero.IsNoble)
                                    {
                                        continue;
                                    }
                                    ChangeRelationAction.ApplyPlayerRelation(hero, -10, true, hero.IsNoble);
                                }
                                else
                                {
                                    ChangeRelationAction.ApplyPlayerRelation(hero, -10, true, false);
                                }
                            }
                        }
                        else
                        {
                            foreach (Hero all1 in Hero.All)
                            {
                                if (!all1.IsAlive || all1 == victim || all1.IsNoble && all1.Clan.Leader != all1)
                                {
                                    continue;
                                }
                                if (all1.Clan == victim.Clan)
                                {
                                    ChangeRelationAction.ApplyPlayerRelation(all1, -30, true, true);
                                }
                                else if (!victim.IsFriend(all1))
                                {
                                    if (all1.MapFaction != victim.MapFaction || all1.CharacterObject.Occupation != Occupation.Lord)
                                    {
                                        continue;
                                    }
                                    ChangeRelationAction.ApplyPlayerRelation(all1, -5, true, all1.IsNoble);
                                }
                                else
                                {
                                    ChangeRelationAction.ApplyPlayerRelation(all1, -15, true, all1.IsNoble);
                                }
                            }
                        }
                    }
                    if (!victim.Clan.IsDeactivated && !victim.Clan.Heroes.Any <Hero>((Hero x) => {
                        if (x.IsChild || x == victim)
                        {
                            return(false);
                        }
                        //return x.IsAlive;
                        return(false);
                    }))
                    {
                        DestroyClanAction.Apply(victim.Clan);
                    }

                    typeof(CampaignEventDispatcher).GetMethod("OnHeroKilled", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly).Invoke(CampaignEventDispatcher.Instance, new object[] { victim, killer, actionDetail, showNotification });
                    //CampaignEventDispatcher.Instance.OnHeroKilled(victim, killer, actionDetail, showNotification);
                    if (victim.CurrentSettlement != null && victim.StayingInSettlementOfNotable != null)
                    {
                        victim.StayingInSettlementOfNotable = null;
                    }
                    return(false);
                }
            }
            victim.MakeWounded(killer, actionDetail);
            return(false);
        }
예제 #3
0
 public void DestroyClan(Clan clan)
 {
     DestroyClanAction.Apply(clan);
     this.RemoveClan(clan);
 }
예제 #4
0
        private void conversation_courtship_success_on_consequence()
        {
            ISettingsProvider settings = new MASettings();
            Hero hero          = Hero.MainHero;
            Hero spouse        = Hero.OneToOneConversationHero;
            Hero oldSpouse     = hero.Spouse;
            Hero cheatedSpouse = spouse.Spouse;

            // If you are marrying a kingdom ruler as a kingdom ruler yourself,
            // the kingdom ruler will have to give up being clan head.
            // Apparently causes issues if this is not done.
            if (spouse.IsFactionLeader && !spouse.IsMinorFactionHero)
            {
                if (hero.Clan.Kingdom != spouse.Clan.Kingdom)
                {
                    if (hero.Clan.Kingdom?.Leader != hero)
                    {
                        // Join kingdom due to lowborn status
                        if (hero.Clan.Leader == Hero.MainHero)
                        {
                            ChangeClanLeaderAction.ApplyWithoutSelectedNewLeader(hero.Clan);
                            if (hero.Clan.Leader == Hero.MainHero)
                            {
                                MAHelper.Print("No Heirs");
                                DestroyClanAction.Apply(hero.Clan);
                                MAHelper.Print("Eliminated Player Clan");
                            }
                        }
                        foreach (Hero companion in hero.Clan.Companions.ToList())
                        {
                            bool inParty = false;
                            if (companion.PartyBelongedTo == MobileParty.MainParty)
                            {
                                inParty = true;
                            }
                            RemoveCompanionAction.ApplyByFire(hero.Clan, companion);
                            AddCompanionAction.Apply(spouse.Clan, companion);
                            if (inParty)
                            {
                                AddHeroToPartyAction.Apply(companion, MobileParty.MainParty, true);
                            }
                        }
                        hero.Clan = spouse.Clan;
                        var current = Traverse.Create <Campaign>().Property("Current").GetValue <Campaign>();
                        Traverse.Create(current).Property("PlayerDefaultFaction").SetValue(spouse.Clan);
                        MAHelper.Print("Lowborn Player Married to Kingdom Ruler");
                    }
                    else
                    {
                        ChangeClanLeaderAction.ApplyWithoutSelectedNewLeader(spouse.Clan);
                        MAHelper.Print("Kingdom Ruler Stepped Down and Married to Player");
                    }
                }
            }
            // New nobility
            MAHelper.OccupationToLord(spouse.CharacterObject);
            if (!spouse.IsNoble)
            {
                spouse.IsNoble = true;
                MAHelper.Print("Spouse to Noble");
            }
            // Dodge the party crash for characters part 1
            bool dodge = false;

            if (spouse.PartyBelongedTo == MobileParty.MainParty)
            {
                AccessTools.Property(typeof(Hero), "PartyBelongedTo").SetValue(spouse, null, null);
                MAHelper.Print("Spouse Already in Player's Party");
                dodge = true;
            }
            // Apply marriage
            ChangeRomanticStateAction.Apply(hero, spouse, Romance.RomanceLevelEnum.Marriage);
            MAHelper.Print("Marriage Action Applied");
            if (oldSpouse is not null)
            {
                MAHelper.RemoveExSpouses(oldSpouse);
            }
            // Dodge the party crash for characters part 2
            if (dodge)
            {
                AccessTools.Property(typeof(Hero), "PartyBelongedTo").SetValue(spouse, MobileParty.MainParty, null);
            }
            // Activate character if not already activated
            if (!spouse.HasMet)
            {
                spouse.HasMet = true;
            }
            if (!spouse.IsActive)
            {
                spouse.ChangeState(Hero.CharacterStates.Active);
                MAHelper.Print("Activated Spouse");
            }
            if (spouse.IsPlayerCompanion)
            {
                spouse.CompanionOf = null;
                MAHelper.Print("Spouse No Longer Companion");
            }
            if (settings.Cheating && cheatedSpouse is not null)
            {
                MAHelper.RemoveExSpouses(cheatedSpouse, true);
                MAHelper.RemoveExSpouses(spouse, true);
                MAHelper.Print("Spouse Broke Off Past Marriage");
            }
            MAHelper.RemoveExSpouses(hero);
            MAHelper.RemoveExSpouses(spouse);
            PlayerEncounter.LeaveEncounter = true;
            // New fix to stop some kingdom rulers from disappearing
            if (spouse.PartyBelongedTo != MobileParty.MainParty)
            {
                AddHeroToPartyAction.Apply(spouse, MobileParty.MainParty, true);
            }
        }
예제 #5
0
        private void FreeClansFromKingdom()
        {
            try
            {
                foreach (Clan clan in Campaign.Current.Clans)
                {
                    if (clan?.Leader == null)
                    {
                        continue;
                    }

                    if (clan.Leader.IsHumanPlayerCharacter)
                    {
                        continue;
                    }

                    Kingdom kingdom = clan.Kingdom;

                    if (kingdom == null)
                    {
                        continue;
                    }

                    if (!kingdom.IsKingdomFaction || kingdom.IsMinorFaction || kingdom.IsBanditFaction)
                    {
                        continue;
                    }

                    if (clan.IsMinorFaction || clan.IsClanTypeMercenary || clan.IsBanditFaction)
                    {
                        continue;
                    }

                    if (clan.Fortifications.Count > 0)
                    {
                        continue;
                    }

                    if (clan.Leader?.PartyBelongedTo?.BesiegedSettlement != null)
                    {
                        continue;
                    }

                    bool otherClanHasForts = false;
                    foreach (Clan other in kingdom.Clans)
                    {
                        if (other.Fortifications.Count > 0)
                        {
                            otherClanHasForts = true;
                            break;
                        }
                    }

                    if (otherClanHasForts)
                    {
                        continue;
                    }

                    // We have now determined that the clan and possible other clans in the kingdom have no forts
                    // So we can go ahead an make the clan available to join other Kingdoms or die


                    int     lowestClanCount = int.MaxValue;
                    Kingdom newKingdom      = null;

                    Dictionary <string, Kingdom> allKingdoms = new Dictionary <string, Kingdom>();
                    foreach (Clan clan1 in Campaign.Current.Clans)
                    {
                        if (clan1?.Kingdom == null)
                        {
                            continue;
                        }

                        allKingdoms[clan1.Kingdom.StringId] = clan1.Kingdom;
                    }

                    foreach (KeyValuePair <string, Kingdom> weakest in allKingdoms)
                    {
                        if (lowestClanCount > weakest.Value.Clans.Count &&
                            !weakest.Value.StringId.Equals(kingdom.StringId) &&
                            weakest.Value.Clans.Count != 0 &&
                            weakest.Value.Fortifications.Count() != 0)
                        {
                            lowestClanCount = weakest.Value.Clans.Count;
                            newKingdom      = weakest.Value;
                        }
                    }

                    double surviveChance = 50;

                    float diceRoll = Rand.Next(0, 100);

                    if (diceRoll < surviveChance && newKingdom?.Clans.Count <= 3)
                    {
                        ChangeKingdomAction.ApplyByJoinToKingdom(clan, newKingdom, false);
                    }
                    else
                    {
                        clan.ClanLeaveKingdom(true);
                        KillCharacterAction.ApplyByRemove(clan.Leader);

                        // Forces so many annoying popups
                        DestroyClanAction.Apply(clan);
                    }

                    // Forces so many annoying popups
                    //if (kingdom.Clans.Count == 0)
                    //	DestroyKingdomAction.Apply(kingdom);
                }
            }
            catch (Exception e)
            {
                Log.Info("Exception in FreeClansFromKingdom");
                Log.Info(e);
            }
        }