// Actual Hiring from Tavern
        private void HireCustomMercenariesInTavern(bool buyOne, bool pastPartyLimit = false)
        {
            if (MobileParty.MainParty.CurrentSettlement == null || !MobileParty.MainParty.CurrentSettlement.IsTown)
            {
                return;
            }
            CustomMercData customMercData = GetCustomMercDataOfPlayerEncounter();

            if (customMercData == null)
            {
                return;
            }

            int troopRecruitmentCost = this.troopRecruitmentCost(customMercData);
            int numberOfMercsToHire  = 0;

            if (buyOne)
            {
                numberOfMercsToHire = 1;
            }
            else
            {
                int numOfTroopSlotsOpen = PartyBase.MainParty.PartySizeLimit - PartyBase.MainParty.NumberOfAllMembers;
                while (Hero.MainHero.Gold > troopRecruitmentCost * (numberOfMercsToHire + 1) && customMercData.Number > numberOfMercsToHire && (pastPartyLimit || numOfTroopSlotsOpen > numberOfMercsToHire))
                {
                    numberOfMercsToHire++;
                }
            }
            customMercData.ChangeMercenaryCount(-numberOfMercsToHire);
            MobileParty.MainParty.AddElementToMemberRoster(customMercData.TroopInfoCharObject(), numberOfMercsToHire, false);
            int amount = numberOfMercsToHire * troopRecruitmentCost;

            GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, null, amount, false);
            CampaignEventDispatcher.Instance.OnUnitRecruited(customMercData.TroopInfoCharObject(), numberOfMercsToHire);
        }
        private void HireCustomMecenariesViaGameMenu(bool buyingOne, bool toPartyLimit)
        {
            if (MobileParty.MainParty.CurrentSettlement == null || !MobileParty.MainParty.CurrentSettlement.IsTown)
            {
                return;
            }
            CustomMercData customMercData = GetCustomMercDataOfPlayerEncounter();

            if (customMercData == null)
            {
                return;
            }
            int numOfTroopSlotsOpen  = PartyBase.MainParty.PartySizeLimit - PartyBase.MainParty.NumberOfAllMembers;
            int troopRecruitmentCost = this.troopRecruitmentCost(customMercData);

            if (customMercData.Number > 0 && Hero.MainHero.Gold >= troopRecruitmentCost && (!toPartyLimit || numOfTroopSlotsOpen > 0))
            {
                int numOfMercs = 1;
                if (!buyingOne)
                {
                    int numOfTroopPlayerCanBuy = (troopRecruitmentCost == 0) ? customMercData.Number : Hero.MainHero.Gold / troopRecruitmentCost;
                    numOfMercs = Math.Min(customMercData.Number, numOfTroopPlayerCanBuy);
                    if (toPartyLimit)
                    {
                        numOfMercs = Math.Min(numOfTroopSlotsOpen, numOfMercs);
                    }
                }
                MobileParty.MainParty.MemberRoster.AddToCounts(customMercData.TroopInfoCharObject(), numOfMercs, false, 0, 0, true, -1);
                GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, -(numOfMercs * troopRecruitmentCost), false);
                customMercData.ChangeMercenaryCount(-numOfMercs);
                GameMenu.SwitchToMenu("town_backstreet");
            }
        }
        private bool HireCustomMercsViaMenuConditionToPartyLimit(MenuCallbackArgs args)
        {
            if (MobileParty.MainParty.CurrentSettlement == null || !MobileParty.MainParty.CurrentSettlement.IsTown)
            {
                return(false);
            }
            CustomMercData customMercData = GetCustomMercDataOfPlayerEncounter();

            if (customMercData != null && customMercData.Number > 0)
            {
                int troopRecruitmentCost   = this.troopRecruitmentCost(customMercData);
                int numOfTroopSlotsOpen    = PartyBase.MainParty.PartySizeLimit - PartyBase.MainParty.NumberOfAllMembers;
                int numOfTroopPlayerCanBuy = (troopRecruitmentCost == 0) ? customMercData.Number : Hero.MainHero.Gold / troopRecruitmentCost;
                if (numOfTroopSlotsOpen > 0 && Hero.MainHero.Gold >= troopRecruitmentCost && numOfTroopSlotsOpen < customMercData.Number && numOfTroopSlotsOpen < numOfTroopPlayerCanBuy)
                {
                    int numOfMercs = Math.Min(customMercData.Number, numOfTroopPlayerCanBuy);
                    numOfMercs = Math.Min(numOfTroopSlotsOpen, numOfMercs);
                    MBTextManager.SetTextVariable("C_MEN_COUNT_PL", numOfMercs);
                    MBTextManager.SetTextVariable("C_MERCENARY_NAME_PL", customMercData.TroopInfoCharObject().Name);
                    MBTextManager.SetTextVariable("C_TOTAL_AMOUNT_PL", numOfMercs * troopRecruitmentCost);
                    args.optionLeaveType = GameMenuOption.LeaveType.RansomAndBribe;
                    return(true);
                }
            }
            return(false);
        }
 private bool CustomMercIsInTavern(CustomMercData customMercData)
 {
     if (CampaignMission.Current == null || CampaignMission.Current.Location == null || customMercData.TroopInfo == null || customMercData.TroopInfoCharObject() == null)
     {
         return(false);
     }
     return(CampaignMission.Current.Location.StringId == "tavern" && customMercData.TroopInfoCharObject().Name == CharacterObject.OneToOneConversationCharacter.Name);
 }
        private bool HireCustomMercsViaMenuConditionHireOne(MenuCallbackArgs args)
        {
            if (MobileParty.MainParty.CurrentSettlement == null || !MobileParty.MainParty.CurrentSettlement.IsTown)
            {
                return(false);
            }
            CustomMercData customMercData = GetCustomMercDataOfPlayerEncounter();

            if (customMercData != null && customMercData.Number > 1)
            {
                int troopRecruitmentCost   = this.troopRecruitmentCost(customMercData);
                int numOfTroopPlayerCanBuy = Hero.MainHero.Gold / troopRecruitmentCost;
                if (numOfTroopPlayerCanBuy > 1)
                {
                    MBTextManager.SetTextVariable("C_MERCENARY_NAME_ONLY_ONE", customMercData.TroopInfoCharObject().Name);
                    MBTextManager.SetTextVariable("C_TOTAL_AMOUNT_ONLY_ONE", troopRecruitmentCost);
                    args.optionLeaveType = GameMenuOption.LeaveType.RansomAndBribe;
                    return(true);
                }
            }
            return(false);
        }