refactor code to perform metric calculations last

This commit is contained in:
Chomp 2021-08-27 21:34:12 +01:00
parent f3975badac
commit ec25fdd058
4 changed files with 56 additions and 13 deletions

View File

@ -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<Bot> _bots;
private readonly List<Datum> _rawParsedBots;
public BotChancesGenerator(List<Bot> botsWithGearAndLoot, List<Datum> parsedBots)
{
_bots = botsWithGearAndLoot;
_rawParsedBots = parsedBots;
}
internal List<Bot> 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;
}
}
}

View File

@ -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);

View File

@ -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<Datum> baseBots)

View File

@ -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);
}
}
}