internal void RemoveFactionLeader(Hero hero) { if ((hero.Clan?.Leader) == hero) { if (hero != Hero.MainHero && hero.Clan.Heroes.Any((Hero x) => !x.IsChild && x != hero && x.IsAlive && (x.IsNoble || x.IsMinorFactionHero))) { ChangeClanLeaderAction.ApplyWithoutSelectedNewLeader(hero.Clan); } if (hero.Clan.Kingdom != null && hero.Clan.Kingdom.RulingClan == hero.Clan) { List <Clan> list = (from t in hero.Clan.Kingdom.Clans where !t.IsEliminated && t.Leader != hero select t).ToList(); if (list.IsEmpty()) { DestroyKingdomAction.Apply(hero.Clan.Kingdom); } else if (list.Count > 1) { Clan clanToExclude = (hero.Clan.Leader == hero || hero.Clan.Leader == null) ? hero.Clan : null; hero.Clan.Kingdom.AddDecision(new KingSelectionKingdomDecision(hero.Clan, clanToExclude), true); } else { hero.Clan.Kingdom.RulingClan = list.First <Clan>(); } } } }
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; }
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); }
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); } }