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 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");
            }
        }
        // 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 int troopRecruitmentCost(CustomMercData customMercData)
        {
            float recruitCostMultiplier = Settings.Settings.Instance.RecruitCostMultiplier;
            int   baseCost = customMercData.GetRecruitmentCost();

            return(MBRandom.RoundRandomized(baseCost * recruitCostMultiplier));
        }
 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);
 }
        // Conditions for Hiring options and functions that follow
        private bool custom_mercenary_hire_one_condition()
        {
            CustomMercData customMercData         = GetCustomMercDataOfPlayerEncounter();
            int            troopRecruitmentCost   = this.troopRecruitmentCost(customMercData);
            int            numOfTroopPlayerCanBuy = Hero.MainHero.Gold / troopRecruitmentCost;

            MBTextManager.SetTextVariable("CMERCS_GOLD_AMOUNT_FOR_ONE", troopRecruitmentCost);
            return(1 < customMercData.Number && numOfTroopPlayerCanBuy > 1);
        }
        // Conditions close Conversation
        private bool custom_mercenary_post_hire_start_condition()
        {
            if (MobileParty.MainParty.CurrentSettlement == null || !MobileParty.MainParty.CurrentSettlement.IsTown)
            {
                return(false);
            }
            CustomMercData mercData = GetCustomMercDataOfPlayerEncounter();

            return(CustomMercIsInTavern(mercData));
        }
        private bool custom_mercenary_hire_all_condition()
        {
            CustomMercData customMercData       = GetCustomMercDataOfPlayerEncounter();
            int            troopRecruitmentCost = this.troopRecruitmentCost(customMercData);
            int            numOfTroopSlotsOpen  = PartyBase.MainParty.PartySizeLimit - PartyBase.MainParty.NumberOfAllMembers;

            MBTextManager.SetTextVariable("CMERCS_PLURAL", (customMercData.Number > 1) ? 1 : 0);
            MBTextManager.SetTextVariable("CMERCS_GOLD_AMOUNT_ALL", troopRecruitmentCost * customMercData.Number);
            return(Hero.MainHero.Gold >= customMercData.Number * troopRecruitmentCost && numOfTroopSlotsOpen >= customMercData.Number);
        }
        private bool custom_mercenary_single_start_condition()
        {
            if (MobileParty.MainParty.CurrentSettlement == null || !MobileParty.MainParty.CurrentSettlement.IsTown)
            {
                return(false);
            }
            CustomMercData customMercData = GetCustomMercDataOfPlayerEncounter();
            bool           flag           = customMercData.Number == 1 && CustomMercIsInTavern(customMercData);

            if (flag)
            {
                int troopRecruitmentCost = this.troopRecruitmentCost(customMercData);
                MBTextManager.SetTextVariable("CMERCS_GOLD_AMOUNT", customMercData.Number * troopRecruitmentCost);
            }
            return(flag);
        }
        private bool custom_mercenary_hire_some_on_condition()
        {
            CustomMercData customMercData       = GetCustomMercDataOfPlayerEncounter();
            int            troopRecruitmentCost = this.troopRecruitmentCost(customMercData);
            int            numOfTroopSlotsOpen  = PartyBase.MainParty.PartySizeLimit - PartyBase.MainParty.NumberOfAllMembers;

            if (Hero.MainHero.Gold >= troopRecruitmentCost && numOfTroopSlotsOpen > 0 && (Hero.MainHero.Gold < customMercData.Number * troopRecruitmentCost || numOfTroopSlotsOpen < customMercData.Number))
            {
                int numberToHire = 0;
                while (Hero.MainHero.Gold > troopRecruitmentCost * (numberToHire + 1) && numOfTroopSlotsOpen > numberToHire)
                {
                    numberToHire++;
                }
                MBTextManager.SetTextVariable("CMERCS_MERCENARY_COUNT_SOME", numberToHire);
                MBTextManager.SetTextVariable("CMERCS_GOLD_AMOUNT_SOME", troopRecruitmentCost * numberToHire);
                return(true);
            }
            return(false);
        }
        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);
        }