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