private static void UpdateCastleNobleRecruit(Settlement settlement)
        {
            bool isUnderSiege = settlement.IsUnderSiege;

            if (!isUnderSiege)
            {
                int dailyCastleNobleRecruitCount = UpdateVolunteersOfNotablesPatch.GetDailyCastleNobleRecruitCount(settlement);
                if (dailyCastleNobleRecruitCount > 0)
                {
                    CharacterObject eliteBasicTroop = settlement.Culture.EliteBasicTroop;
                    if (settlement.Town.GarrisonParty == null)
                    {
                        settlement.AddGarrisonParty(false);
                    }
                    if (settlement.Town.GarrisonParty is not null)
                    {
                        int val = settlement.Town.GarrisonParty.Party.PartySizeLimit - settlement.Town.GarrisonParty.Party.NumberOfAllMembers;
                        int num = Math.Min(dailyCastleNobleRecruitCount, val);
                        if (num > 0)
                        {
                            settlement.Town.GarrisonParty.MemberRoster.AddToCounts(eliteBasicTroop, num, false, 0, 0, true, -1);
                            settlement.Prosperity -= SubModule.Settings.CastleRecruitProsperityCost * (float)num;
                        }
                    }
                }
            }
        }
 public static bool Prefix(ref bool initialRunning)
 {
     foreach (Settlement settlement in Campaign.Current.Settlements)
     {
         if ((settlement.IsTown && !settlement.Town.InRebelliousState) || (settlement.IsVillage && !settlement.Village.Bound.Town.InRebelliousState))
         {
             foreach (Hero hero in settlement.Notables)
             {
                 try
                 {
                     if (hero.CanHaveRecruits)
                     {
                         bool flag2 = false;
                         int  i     = 0;
                         while (i < 6)
                         {
                             if ((double)MBRandom.RandomFloat < (double)Campaign.Current.Models.VolunteerProductionModel.GetDailyVolunteerProductionProbability(hero, i, settlement))
                             {
                                 flag2 = true;
                                 if (!UpdateVolunteersOfNotablesPatch.IsBitSet(hero, i))
                                 {
                                     bool flag5 = UpdateVolunteersOfNotablesPatch.GenerateBasicTroop(hero, i);
                                     bool flag6 = !flag5;
                                     if (!flag6)
                                     {
                                         for (int j = 0; j < 3; j++)
                                         {
                                             if ((double)MBRandom.RandomFloat < UpdateVolunteersOfNotablesPatch.GetTroopUpgradeChance(hero, i))
                                             {
                                                 UpdateVolunteersOfNotablesPatch.UpgradeTroop(hero, i);
                                             }
                                         }
                                     }
                                 }
                                 else
                                 {
                                     if ((double)MBRandom.RandomFloat < UpdateVolunteersOfNotablesPatch.GetTroopUpgradeChance(hero, i))
                                     {
                                         UpdateVolunteersOfNotablesPatch.UpgradeTroop(hero, i);
                                     }
                                 }
                             }
                             i++;
                         }
                         if (flag2)
                         {
                             UpdateVolunteersOfNotablesPatch.SortNotableVolunteers(hero);
                         }
                     }
                 }
                 catch (IndexOutOfRangeException)
                 {
                 }
             }
         }
         if (settlement.IsCastle && !settlement.InRebelliousState)
         {
             UpdateVolunteersOfNotablesPatch.UpdateCastleNobleRecruit(settlement);
         }
     }
     return(false);
 }