private void OnGovernorSelectionOver(List <InquiryElement> element) { if (element.Count <= 0) { return; } ChangeGovernorAction.Apply(this.CurrentSelectedFief.Settlement.Town, (Hero)element[0].Identifier); this.RefreshFiefsList(); Action onRefresh = this._onRefresh; if (onRefresh == null) { return; } onRefresh(); }
private void OnChangeClanLeader(float dt) { MobileParty leaderParty = leader.PartyBelongedTo; MobileParty newLeaderParty = newLeader.PartyBelongedTo; Utils.Print($"[OnChangeClanLeader] current leader {leader.Name} new leader {newLeader.Name}"); if (leader == null || newLeader == null || leaderParty == null || newLeaderParty == null) { return; } if (newLeader.GovernorOf != null) { ChangeGovernorAction.ApplyByGiveUpCurrent(newLeader); } if (leader.GovernorOf != null) { ChangeGovernorAction.ApplyByGiveUpCurrent(leader); } string evt; while ((evt = newLeader.GetHeroOccupiedEvents().FirstOrDefault()) != default) { newLeader.RemoveEventFromOccupiedHero(evt); } while ((evt = leader.GetHeroOccupiedEvents().FirstOrDefault()) != default) { leader.RemoveEventFromOccupiedHero(evt); } GiveGoldAction.ApplyBetweenCharacters(leader, newLeader, leader.Gold, true); leader.Clan.SetLeader(newLeader); Settlement currentSettlement = newLeaderParty.CurrentSettlement; ChangePlayerCharacterAction.Apply(newLeader); if (newLeaderParty != leaderParty) { if (newLeaderParty.CurrentSettlement == null) { EnterSettlementAction.ApplyForParty(newLeaderParty, currentSettlement); } foreach (var troop in leaderParty.MemberRoster.GetTroopRoster()) { if (troop.Character == leader.CharacterObject) { continue; } leaderParty.MemberRoster.AddToCounts(troop.Character, -troop.Number); newLeaderParty.MemberRoster.AddToCounts(troop.Character, troop.Number); } foreach (var troop in leaderParty.PrisonRoster.GetTroopRoster()) { if (troop.Character == leader.CharacterObject) { continue; } leaderParty.PrisonRoster.AddToCounts(troop.Character, -troop.Number); newLeaderParty.PrisonRoster.AddToCounts(troop.Character, troop.Number); } ItemRosterElement i; while (leaderParty.ItemRoster.Count() > 0) { i = leaderParty.ItemRoster.First(); leaderParty.ItemRoster.AddToCounts(i.EquipmentElement, -i.Amount); newLeaderParty.ItemRoster.AddToCounts(i.EquipmentElement, i.Amount); } leaderParty.RemoveParty(); AddHeroToPartyAction.Apply(leader, newLeaderParty); } else { leaderParty.Party.Owner = newLeader; var partyList = leaderParty.Party.MemberRoster; partyList.RemoveTroop(newLeader.CharacterObject); partyList.AddToCounts(newLeader.CharacterObject, 1, true); var newPartyName = new TextObject("{=shL0WElC}{TROOP.NAME}'s Party"); newPartyName.SetCharacterProperties("TROOP", newLeader.CharacterObject); leaderParty.SetCustomName(newPartyName); } leader.HasMet = true; newLeader.Clan.Influence = Math.Max(0, newLeader.Clan.Influence - 100); HeroFixHelper.FixHeroStats(newLeader); HeroFixHelper.FixEquipment(newLeader); newLeaderParty.Party.Visuals.SetMapIconAsDirty(); CampaignEventDispatcher.Instance.OnArmyOverlaySetDirty(); newLeader = null; leader = null; CampaignEvents.RemoveListeners(this); Utils.Print($"[OnChangeClanLeader] changed over"); }
private void OnChangeClanLeader(float dt) { MobileParty leaderParty = leader.PartyBelongedTo; MobileParty newLeaderParty = newLeader.PartyBelongedTo; if (leader == null || newLeader == null || leaderParty == null || newLeaderParty == null || leaderParty == newLeaderParty) { return; } if (newLeader.GovernorOf != null) { ChangeGovernorAction.ApplyByGiveUpCurrent(newLeader); } if (leader.GovernorOf != null) { ChangeGovernorAction.ApplyByGiveUpCurrent(leader); } var qm = Campaign.Current.QuestManager; if (qm != null) { QuestBase q; while ((q = qm.Quests.FirstOrDefault(s => !s.IsSpecialQuest)) != null) { q.CompleteQuestWithFail(); } } string evt; while ((evt = newLeader.GetHeroOccupiedEvents().FirstOrDefault()) != default) { newLeader.RemoveEventFromOccupiedHero(evt); } while ((evt = leader.GetHeroOccupiedEvents().FirstOrDefault()) != default) { leader.RemoveEventFromOccupiedHero(evt); } GiveGoldAction.ApplyBetweenCharacters(leader, newLeader, leader.Gold, true); leader.Clan.SetLeader(newLeader); ChangePlayerCharacterAction.Apply(newLeader); TroopRosterElement t; while (leaderParty.MemberRoster.Count(x => x.Character != leader.CharacterObject) > 0) { t = leaderParty.MemberRoster.First(x => x.Character != leader.CharacterObject); leaderParty.MemberRoster.AddToCounts(t.Character, -t.Number); newLeaderParty.MemberRoster.AddToCounts(t.Character, t.Number); } while (leaderParty.PrisonRoster.Count() > 0) { t = leaderParty.PrisonRoster.First(); leaderParty.PrisonRoster.AddToCounts(t.Character, -t.Number); newLeaderParty.PrisonRoster.AddToCounts(t.Character, t.Number); } ItemRosterElement i; while (leaderParty.ItemRoster.Count() > 0) { i = leaderParty.ItemRoster.First(); leaderParty.ItemRoster.AddToCounts(i.EquipmentElement, -i.Amount); newLeaderParty.ItemRoster.AddToCounts(i.EquipmentElement, i.Amount); } leaderParty.RemoveParty(); AddHeroToPartyAction.Apply(leader, newLeaderParty); newLeader.Clan.Influence = Math.Max(0, newLeader.Clan.Influence - 100); HeroFixHelper.FixHeroStats(newLeader); HeroFixHelper.FixEquipment(newLeader); newLeader = null; leader = null; CampaignEvents.RemoveListeners(this); }
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); }