2023-09-18 17:15:30 +01:00
|
|
|
|
using Common.Models.Input;
|
2021-09-18 22:36:59 +01:00
|
|
|
|
using Common.Models.Output;
|
2021-08-13 16:24:05 +01:00
|
|
|
|
using Generator.Helpers.Gear;
|
2021-08-12 16:52:06 +01:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace Generator
|
|
|
|
|
{
|
2021-09-01 19:19:44 +03:00
|
|
|
|
public static class BotGearGenerator
|
2021-08-12 16:52:06 +01:00
|
|
|
|
{
|
2023-09-18 17:15:30 +01:00
|
|
|
|
public static IEnumerable<Bot> AddGear(this IEnumerable<Bot> baseBots, Dictionary<string, List<Datum>> rawBots)
|
2021-08-12 16:52:06 +01:00
|
|
|
|
{
|
|
|
|
|
var stopwatch = Stopwatch.StartNew();
|
|
|
|
|
LoggingHelpers.LogToConsole("Started processing bot gear");
|
|
|
|
|
|
2023-09-18 17:15:30 +01:00
|
|
|
|
var dictionaryLock = new object();
|
|
|
|
|
var tasks = new List<Task>();
|
|
|
|
|
|
2021-09-01 19:19:44 +03:00
|
|
|
|
foreach (var botToUpdate in baseBots)
|
2021-08-12 16:52:06 +01:00
|
|
|
|
{
|
2023-09-18 17:15:30 +01:00
|
|
|
|
tasks.Add(Task.Factory.StartNew(() =>
|
2021-08-17 18:33:55 +01:00
|
|
|
|
{
|
2023-09-18 17:15:30 +01:00
|
|
|
|
var botType = botToUpdate.botType.ToString().ToLower();
|
|
|
|
|
List<Datum> rawBotsOfSameType;
|
|
|
|
|
lock (dictionaryLock)
|
|
|
|
|
{
|
|
|
|
|
if (!rawBots.TryGetValue(botType, out rawBotsOfSameType))
|
|
|
|
|
{
|
2023-12-28 09:12:54 +00:00
|
|
|
|
Console.WriteLine($"(gear) Unable to find {botType} on rawBots data");
|
2023-09-18 17:15:30 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-17 18:33:55 +01:00
|
|
|
|
|
2023-09-18 17:15:30 +01:00
|
|
|
|
if (rawBotsOfSameType.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var rawParsedBot in rawBotsOfSameType)
|
|
|
|
|
{
|
|
|
|
|
GearHelpers.AddEquippedGear(botToUpdate, rawParsedBot);
|
|
|
|
|
GearHelpers.AddAmmo(botToUpdate, rawParsedBot);
|
|
|
|
|
GearHelpers.AddEquippedMods(botToUpdate, rawParsedBot);
|
|
|
|
|
//GearHelpers.AddCartridges(botToUpdate, rawParsedBot);
|
|
|
|
|
}
|
2023-10-31 19:35:32 +00:00
|
|
|
|
|
|
|
|
|
GearHelpers.ReduceAmmoWeightValues(botToUpdate);
|
|
|
|
|
GearHelpers.ReduceEquipmentWeightValues(botToUpdate.inventory.equipment);
|
2023-09-18 17:15:30 +01:00
|
|
|
|
}));
|
2021-08-12 16:52:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-18 17:15:30 +01:00
|
|
|
|
Task.WaitAll(tasks.ToArray());
|
2021-08-12 16:52:06 +01:00
|
|
|
|
stopwatch.Stop();
|
2021-08-12 21:31:15 +01:00
|
|
|
|
LoggingHelpers.LogToConsole($"Finished processing bot gear. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds");
|
2021-08-12 16:52:06 +01:00
|
|
|
|
|
2021-09-01 19:19:44 +03:00
|
|
|
|
return baseBots;
|
2021-08-12 16:52:06 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|