BF2Statistics.ServerSettingsForm.SetBotSettings C# (CSharp) Method

SetBotSettings() protected method

Sets the bot settings based on whether the ForceBotCount is checked
protected SetBotSettings ( ) : void
return void
        protected void SetBotSettings()
        {
            // Save settings
            Settings.SetValue("coopBotDifficulty", BotDifficultyBar.Value.ToString());

            // If we are using global settings file, or not using the AiDefault.ai file
            if (UseGlobalSettings || !ForceBotCount.Checked)
            {
                Settings.SetValue("coopBotRatio", BotRatioBar.Value.ToString());
                Settings.SetValue("coopBotCount", BotCountBar.Value.ToString());

                // Stopping point for global settings
                if (UseGlobalSettings)
                    return;
            }
            else
            {
                // Forcing AIDefault, set ratio to 100 and the bot count for team 2
                Settings.SetValue("coopBotRatio", "100");
                Settings.SetValue("coopBotCount", BotCountBar2.Value.ToString());
            }

            // No need to write to the AiDefault file if we didnt have forced bot counts from the start
            if (!BotCountForced && !ForceBotCount.Checked)
                return;

            // Save Values in the AiDefault if there is changes to be made
            if (ForceBotCount.Checked)
            {
                // Create en-US culture formating for the float
                string formated = (BotDifficultyBar.Value / 100f).ToString("0.00", CultureInfo.InvariantCulture);
                AiDefaultText = AiDefaultText.Replace(AiMatches[0], "aiSettings.overrideMenuSettings 1")
                    .Replace(AiMatches[1], $"aiSettings.setMaxNBots {(BotCountBar2.Value + BotCountBar1.Value)}")
                    .Replace(AiMatches[2], $"aiSettings.setBotSkill {formated}")
                    .Replace(AiMatches[3], "aiSettings.maxBotsIncludeHumans 0");
            }
            else
            {
                // Make sure the AiDefault.ai settings are disabled
                AiDefaultText = AiDefaultText.Replace(AiMatches[0], "aiSettings.overrideMenuSettings 0");
            }

            // Save File
            File.WriteAllText(Path.Combine(MainForm.SelectedMod.RootPath, "ai", "AiDefault.ai"), AiDefaultText);
        }