private static bool GenerateBasicTroop(Hero notable, int index) { CultureObject cultureObject = notable.CurrentSettlement != null ? notable.CurrentSettlement.Culture : notable.Clan.Culture; // chance = Math.Max(chance, 0); // chance = Math.Sqrt(chance); if (HeroHelper.HeroShouldGiveEliteTroop(notable)) { double notableMinPowerForNobleRecruit = 200; double chance = ((double)notable.Power - notableMinPowerForNobleRecruit) / (SubModule.Settings.notablePowerThresholdForNobleRecruit - notableMinPowerForNobleRecruit); if ((double)MBRandom.RandomFloat < chance) { notable.VolunteerTypes[index] = cultureObject.EliteBasicTroop; int powerMinus = Math.Min(notable.Power - 1, (int)SubModule.Settings.notableNobleRecruitPowerCost); notable.AddPower(-powerMinus); } else { return(false); } } else { notable.VolunteerTypes[index] = cultureObject.BasicTroop; } return(true); }
private static bool GenerateBasicTroop(Hero notable, int index) { CultureObject cultureObject = (notable.CurrentSettlement != null) ? notable.CurrentSettlement.Culture : notable.Clan.Culture; bool flag = HeroHelper.HeroShouldGiveEliteTroop(notable); if (flag) { double num = Math.Pow((double)notable.Power / (double)SubModule.Settings.NotablePowerThresholdForNobleRecruit, 1.5); bool flag2 = (double)MBRandom.RandomFloat < num; if (!flag2) { return(false); } notable.VolunteerTypes[index] = cultureObject.EliteBasicTroop; float num2 = Math.Min(notable.Power - 1, (int)SubModule.Settings.NotableNobleRecruitPowerCost); notable.AddPower(-num2); } else { notable.VolunteerTypes[index] = cultureObject.BasicTroop; } return(true); }
private static void HandlePlayerClanReplacements(Settlement settlement) { if ((settlement.IsTown && !settlement.Town.IsRebeling) || (settlement.IsVillage && !settlement.Village.Bound.Town.IsRebeling)) { foreach (Hero notable in settlement.Notables) { if (notable.CanHaveRecruits) { bool flag = false; CultureObject cultureObject = (notable.CurrentSettlement != null) ? notable.CurrentSettlement.Culture : notable.Clan.Culture; // Change cultureObject based on town's loyalty if (ATCSettings.Instance.EnableCCC) { if (settlement.IsTown) { if (MBRandom.RandomInt(0, 100) <= (ATCSettings.Instance.CCCAmount * notable.CurrentSettlement.Town.Loyalty / 100)) { cultureObject = (notable.CurrentSettlement != null) ? notable.CurrentSettlement.MapFaction.Culture : notable.Clan.Culture; } } else if (settlement.IsVillage) { if (MBRandom.RandomInt(0, 100) <= (ATCSettings.Instance.CCCAmount * notable.CurrentSettlement.Village.Bound.Town.Loyalty / 100)) { cultureObject = (notable.CurrentSettlement != null) ? notable.CurrentSettlement.MapFaction.Culture : notable.Clan.Culture; } } } CharacterObject basicTroop = cultureObject.BasicTroop; double num = (notable.IsRuralNotable && notable.Power >= 200) ? 1.0 : 0.5; float num2 = 200f; for (int i = 0; i < 6; i++) { if (MBRandom.RandomFloat < (Campaign.Current.Models.VolunteerProductionModel.GetDailyVolunteerProductionProbability(notable, i, settlement) * ATCSettings.Instance.RecruitSpawnFactor)) { if (notable.VolunteerTypes[i] == null) { notable.VolunteerTypes[i] = ATCconfig.GetReplacement("player_clan_basic", basicTroop); if (ATCSettings.Instance.DebugReplacementMsg && notable.CurrentSettlement.Culture.Name != notable.CurrentSettlement.MapFaction.Culture.Name) { SubModule.log.Add("UpdateVolunteersOfNotables -> Settlement " + notable.CurrentSettlement.Name + "(Culture: " + notable.CurrentSettlement.Culture.Name + ", Owner: " + notable.CurrentSettlement.MapFaction.Name + ") received new recruit: " + notable.VolunteerTypes[i].Name); } flag = true; } else { float num3 = num2 * num2 / (Math.Max(50f, (float)notable.Power) * Math.Max(50f, (float)notable.Power)); int level = notable.VolunteerTypes[i].Level; if (MBRandom.RandomInt((int)Math.Max(2.0, (double)((float)level * num3) * num * 1.5)) == 0 && notable.VolunteerTypes[i].UpgradeTargets != null && notable.VolunteerTypes[i].Level < 20) { if (notable.VolunteerTypes[i] == basicTroop && HeroHelper.HeroShouldGiveEliteTroop(notable)) { notable.VolunteerTypes[i] = ATCconfig.GetReplacement("player_clan_elite", cultureObject.EliteBasicTroop); flag = true; } else { notable.VolunteerTypes[i] = notable.VolunteerTypes[i].UpgradeTargets[MBRandom.RandomInt(notable.VolunteerTypes[i].UpgradeTargets.Length)]; flag = true; } } } } } if (flag) { SortVolunteers(notable.VolunteerTypes); } } } } }
static void Postfix(bool initialRunning) { if (BannerlordTweaksSettings.Instance is { } settings&& settings.BalancingUpgradeTroopsTweaksEnabled) { foreach (Settlement settlement in from settlement in Campaign.Current.Settlements where settlement.OwnerClan != null && settlement.OwnerClan.Kingdom != null && ((settlement.IsTown && !settlement.Town.InRebelliousState) || (settlement.IsVillage && !settlement.Village.Bound.Town.InRebelliousState)) select settlement) { float num = 0f; if (settings.KingdomBalanceStrengthVanEnabled) { num = settlement.OwnerClan.Kingdom.StringId switch { "vlandia" => settings.VlandiaBoost, "battania" => settings.BattaniaBoost, "empire" => settings.Empire_N_Boost, "empire_s" => settings.Empire_S_Boost, "empire_w" => settings.Empire_W_Boost, "sturgia" => settings.SturgiaBoost, "khuzait" => settings.KhuzaitBoost, "aserai" => settings.AseraiBoost, _ => 0f }; } if (settings.KingdomBalanceStrengthCEKEnabled) { num = settlement.OwnerClan.Kingdom.StringId switch { "nordlings" => settings.NordlingsBoost, "vagir" => settings.VagirBoost, "royalist_vlandia" => settings.RoyalistVlandiaBoost, "apolssaly" => settings.ApolssalyBoost, "lyrion" => settings.LyrionBoost, "rebel_khuzait" => settings.RebelKhuzaitBoost, "paleician" => settings.PaleicianBoost, "ariorum" => settings.AriorumBoost, "vlandia" => settings.Vlandia_CEK_Boost, "battania" => settings.Battania_CEK_Boost, "empire" => settings.Empire_CEK_Boost, "empire_s" => settings.Empire_S_CEK_Boost, "empire_w" => settings.Empire_W_CEK_Boost, "sturgia" => settings.Sturgia_CEK_Boost, "khuzait" => settings.Khuzait_CEK_Boost, "aserai" => settings.Aserai_CEK_Boost, _ => 0f }; } if (num == 0f && settlement.OwnerClan.Kingdom.Leader == Hero.MainHero) { num = (settings.KingdomBalanceStrengthCEKEnabled) ? settings.Player_CEK_Boost : settings.PlayerBoost; } foreach (Hero hero in settlement.Notables) { if (hero.CanHaveRecruits) { for (int i = 0; i < 6; i++) { if (hero.VolunteerTypes[i] != null && MBRandom.RandomFloat < (num * 0.5) && hero.VolunteerTypes[i].UpgradeTargets != null && hero.VolunteerTypes[i].Level < 20) { CultureObject cultureObject = (hero.CurrentSettlement != null) ? hero.CurrentSettlement.Culture : hero.Clan.Culture; CharacterObject basicTroop = cultureObject.BasicTroop; if (hero.VolunteerTypes[i] == basicTroop && HeroHelper.HeroShouldGiveEliteTroop(hero)) { hero.VolunteerTypes[i] = cultureObject.EliteBasicTroop; } else { hero.VolunteerTypes[i] = hero.VolunteerTypes[i].UpgradeTargets[MBRandom.RandomInt(hero.VolunteerTypes[i].UpgradeTargets.Length)]; } } } } } } } }
public SettlementIconState(Settlement settlement) { foreach (Hero hero in settlement.Notables) { bool flag = Settings.SettlementIcons.IsNobleTroopIconEnabled && HeroHelper.HeroShouldGiveEliteTroop(hero); if (flag) { this.IsPossibleNobleTroops = true; } bool flag2 = Settings.SettlementIcons.IsQuestIconEnabled && hero.Issue != null; if (flag2) { this.IsQuestAvailable = true; } } bool flag3 = Settings.SettlementIcons.IsTournamentIconEnabled && settlement.IsTown && Campaign.Current.TournamentManager.GetTournamentGame(settlement.Town) != null; if (flag3) { this.IsTournamentAvailable = true; } bool flag4 = Settings.SettlementIcons.IsResourceIconsEnabled && settlement.IsVillage && settlement.Village.VillageType != null; if (flag4) { string stringId = settlement.Village.VillageType.StringId; uint num = 0U; bool flag5 = stringId != null; if (flag5) { num = 2166136261U; string text = stringId; for (int i = 0; i < text.Length; i++) { num = ((uint)text[i] ^ num) * 16777619U; } } bool flag6 = num <= 1509806192U; if (flag6) { bool flag7 = num <= 612390094U; if (flag7) { bool flag8 = num <= 391430808U; if (flag8) { bool flag9 = num != 311137604U; if (flag9) { bool flag10 = num != 391430808U; if (!flag10) { bool flag11 = stringId != "swine_farm"; if (!flag11) { this.IsSwine = true; } } } else { bool flag12 = stringId != "fisherman"; if (!flag12) { this.IsFish = true; } } } else { bool flag13 = num != 447076191U; if (flag13) { bool flag14 = num != 584841567U; if (flag14) { bool flag15 = num != 612390094U; if (!flag15) { bool flag16 = stringId != "silk_plant"; if (!flag16) { this.IsSilk = true; } } } else { bool flag17 = stringId != "iron_mine"; if (!flag17) { this.IsIron = true; } } } else { bool flag18 = stringId != "desert_horse_ranch"; if (!flag18) { this.IsHorse = true; } } } } else { bool flag19 = num <= 1077548801U; if (flag19) { bool flag20 = num != 778525754U; if (flag20) { bool flag21 = num != 1077548801U; if (!flag21) { bool flag22 = stringId != "trapper"; if (!flag22) { this.IsHide = true; } } } else { bool flag23 = stringId != "battanian_horse_ranch"; if (!flag23) { this.IsHorse = true; } } } else { bool flag24 = num != 1294988078U; if (flag24) { bool flag25 = num != 1323181873U; if (flag25) { bool flag26 = num != 1509806192U; if (!flag26) { bool flag27 = stringId != "europe_horse_ranch"; if (!flag27) { this.IsHorse = true; } } } else { bool flag28 = stringId != "salt_mine"; if (!flag28) { this.IsSalt = true; } } } else { bool flag29 = stringId != "silver_mine"; if (!flag29) { this.IsSilver = true; } } } } } else { bool flag30 = num <= 3023816321U; if (flag30) { bool flag31 = num <= 1791522831U; if (flag31) { bool flag32 = num != 1770050989U; if (flag32) { bool flag33 = num != 1791522831U; if (!flag33) { bool flag34 = stringId != "cattle_farm"; if (!flag34) { this.IsCattle = true; } } } else { bool flag35 = stringId != "lumberjack"; if (!flag35) { this.IsHardwood = true; } } } else { bool flag36 = num != 2590604115U; if (flag36) { bool flag37 = num != 2685698454U; if (flag37) { bool flag38 = num != 3023816321U; if (!flag38) { bool flag39 = stringId != "wheat_farm"; if (!flag39) { this.IsGrain = true; } } } else { bool flag40 = stringId != "olive_trees"; if (!flag40) { this.IsOlive = true; } } } else { bool flag41 = stringId != "steppe_horse_ranch"; if (!flag41) { this.IsHorse = true; } } } } else { bool flag42 = num <= 3979548289U; if (flag42) { bool flag43 = num != 3120777606U; if (flag43) { bool flag44 = num != 3979548289U; if (!flag44) { bool flag45 = stringId != "vineyard"; if (!flag45) { this.IsGrape = true; } } } else { bool flag46 = stringId != "date_farm"; if (!flag46) { this.IsDate = true; } } } else { bool flag47 = num != 4007472742U; if (flag47) { bool flag48 = num != 4200144624U; if (flag48) { bool flag49 = num != 4237788325U; if (!flag49) { bool flag50 = stringId != "sheep_farm"; if (!flag50) { this.IsWool = true; } } } else { bool flag51 = stringId != "flax_plant"; if (!flag51) { this.IsFlax = true; } } } else { bool flag52 = stringId != "clay_mine"; if (!flag52) { this.IsClay = true; } } } } } } }