From ec25fdd0582b141100e55d0893551d06526d9efa Mon Sep 17 00:00:00 2001 From: Chomp Date: Fri, 27 Aug 2021 21:34:12 +0100 Subject: [PATCH] refactor code to perform metric calculations last --- Generator/BotChancesGenerator.cs | 50 +++++++++++++++++++++ Generator/BotGearGenerator.cs | 4 -- Generator/Helpers/Gear/GearChanceHelpers.cs | 9 +--- Generator/Program.cs | 6 ++- 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 Generator/BotChancesGenerator.cs diff --git a/Generator/BotChancesGenerator.cs b/Generator/BotChancesGenerator.cs new file mode 100644 index 0000000..cc9de51 --- /dev/null +++ b/Generator/BotChancesGenerator.cs @@ -0,0 +1,50 @@ +using Common; +using Generator.Helpers.Gear; +using Generator.Models.Input; +using Generator.Models.Output; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; + +namespace Generator +{ + internal class BotChancesGenerator + { + private readonly List _bots; + private readonly List _rawParsedBots; + + public BotChancesGenerator(List botsWithGearAndLoot, List parsedBots) + { + _bots = botsWithGearAndLoot; + _rawParsedBots = parsedBots; + } + + internal List AddChances() + { + var stopwatch = Stopwatch.StartNew(); + LoggingHelpers.LogToConsole("Started processing bot gear"); + + foreach (var botToUpdate in _bots) + { + var rawParsedBotOfCurrentType = _rawParsedBots + .Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)) + .ToList(); + + if (rawParsedBotOfCurrentType.Count == 0) + { + continue; + } + + GearChanceHelpers.CalculateEquipmentChances(botToUpdate, rawParsedBotOfCurrentType); + GearChanceHelpers.AddGenerationChances(botToUpdate); + GearChanceHelpers.CalculateModChances(botToUpdate, rawParsedBotOfCurrentType); + } + + stopwatch.Stop(); + LoggingHelpers.LogToConsole($"Finished processing bot chances. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); + + return _bots; + } + } +} \ No newline at end of file diff --git a/Generator/BotGearGenerator.cs b/Generator/BotGearGenerator.cs index 8f383e6..1957c5d 100644 --- a/Generator/BotGearGenerator.cs +++ b/Generator/BotGearGenerator.cs @@ -37,10 +37,6 @@ namespace Generator continue; } - GearChanceHelpers.CalculateEquipmentChances(botToUpdate, rawParsedBotOfCurrentType); - GearChanceHelpers.AddGenerationChances(botToUpdate); - GearChanceHelpers.CalculateModChances(botToUpdate, rawParsedBotOfCurrentType); - foreach (var rawParsedBot in rawParsedBotOfCurrentType) { GearHelpers.AddEquippedGear(botToUpdate, rawParsedBot); diff --git a/Generator/Helpers/Gear/GearChanceHelpers.cs b/Generator/Helpers/Gear/GearChanceHelpers.cs index e6e5ed8..257f435 100644 --- a/Generator/Helpers/Gear/GearChanceHelpers.cs +++ b/Generator/Helpers/Gear/GearChanceHelpers.cs @@ -109,14 +109,7 @@ namespace Generator.Helpers.Gear public static void AddGenerationChances(Bot bot) { - switch (bot.botType) - { - case BotType.assault: - case BotType.pmcBot: - case BotType.marksman: - bot.generation = new GenerationChances(0, 1, 1, 2, 0, 3, 2, 4, 0, 5); //TODO get dynamically - break; - } + bot.generation = new GenerationChances(bot.specialLoot.Count, bot.specialLoot.Count, 1, 2, 0, 3, 2, 4, 0, 5); //TODO get dynamically } public static void CalculateEquipmentChances(Bot bot, List baseBots) diff --git a/Generator/Program.cs b/Generator/Program.cs index 82bc573..22c0bea 100644 --- a/Generator/Program.cs +++ b/Generator/Program.cs @@ -59,9 +59,13 @@ namespace Generator var botLootGenerator = new BotLootGenerator(botsWithGear, parsedBots); var botsWithGearAndLoot = botLootGenerator.AddLoot(); + // Add mod/equipment chances + var botChancesGenerator = new BotChancesGenerator(botsWithGearAndLoot, parsedBots); + var botsWithGearAndLootAndChances = botChancesGenerator.AddChances(); + // Output bot to json file var jsonWriter = new JsonWriter(workingPath, "output"); - jsonWriter.WriteJson(botsWithGearAndLoot); + jsonWriter.WriteJson(botsWithGearAndLootAndChances); } } }