diff --git a/Generator/BaseBotGenerator.cs b/Generator/BaseBotGenerator.cs index cde18ee..9bc9838 100644 --- a/Generator/BaseBotGenerator.cs +++ b/Generator/BaseBotGenerator.cs @@ -12,28 +12,17 @@ using System.Linq; namespace Generator { - public class BaseBotGenerator + public static class BaseBotGenerator { - private readonly List _rawParsedBots; - private readonly string _workingPath; - private readonly string[] _botTypes; - - //TODO: pass in bot types and use those to create the clases in rawBots list - public BaseBotGenerator(List parsedBots, string workingPath, string[] botTypes) - { - _rawParsedBots = parsedBots; - _workingPath = workingPath; - _botTypes = botTypes; - } - - public List AddBaseDetails() + //TODO: pass in bot types and use those to create the classes in rawBots list + public static IEnumerable GenerateBaseDetails(IEnumerable parsedBots, string workingPath, IEnumerable botTypes) { var stopwatch = Stopwatch.StartNew(); LoggingHelpers.LogToConsole("Started processing bot base"); // Create a list of bot objects ready to be hydrated var rawBots = new List(); - foreach (var botType in _botTypes) + foreach (var botType in botTypes) { var typeToAdd = (BotType)Enum.Parse(typeof(BotType), botType); rawBots.Add(new Bot(typeToAdd)); @@ -42,7 +31,7 @@ namespace Generator // Iterate over each bot type wejust made and put some data into them foreach (var botToUpdate in rawBots) { - var rawBotsOfSameType = _rawParsedBots + var rawBotsOfSameType = parsedBots .Where(x => string.Equals(x.Info.Settings.Role, botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)).ToList(); if (rawBotsOfSameType.Count == 0) @@ -54,7 +43,7 @@ namespace Generator LoggingHelpers.LogToConsole($"Found {rawBotsOfSameType.Count} bots of type: {botToUpdate.botType}"); UpdateBodyPartHealth(botToUpdate, rawBotsOfSameType); - AddDifficulties(botToUpdate, _workingPath); + AddDifficulties(botToUpdate, workingPath); AddExperience(botToUpdate, rawBotsOfSameType); AddStandingForKill(botToUpdate, rawBotsOfSameType); AddSkills(botToUpdate, rawBotsOfSameType); @@ -73,7 +62,7 @@ namespace Generator return rawBots; } - private void AddSkills(Bot botToUpdate, List rawBotsOfSameType) + private static void AddSkills(Bot botToUpdate, IEnumerable rawBotsOfSameType) { var firstBotOfDesiredType = rawBotsOfSameType.FirstOrDefault(); @@ -83,7 +72,7 @@ namespace Generator } } - private void AddStandingForKill(Bot botToUpdate, List rawBotsOfSameType) + private static void AddStandingForKill(Bot botToUpdate, IEnumerable rawBotsOfSameType) { var firstBotOfDesiredType = rawBotsOfSameType.FirstOrDefault(); @@ -91,7 +80,7 @@ namespace Generator botToUpdate.experience.aggressorBonus = firstBotOfDesiredType.Info.Settings.AggressorBonus; } - private void AddExperience(Bot botToUpdate, List rawBotsOfSameType) + private static void AddExperience(Bot botToUpdate, IEnumerable rawBotsOfSameType) { var firstBotOfDesiredType = rawBotsOfSameType.FirstOrDefault(); @@ -99,12 +88,12 @@ namespace Generator botToUpdate.experience.reward.max = firstBotOfDesiredType.Info.Settings.Experience; } - private void AddVoice(Bot bot, Datum rawParsedBot) + private static void AddVoice(Bot bot, Datum rawParsedBot) { bot.appearance.voice.AddUnique(rawParsedBot.Info.Voice); } - private void AddDifficulties(Bot bot, string workingPath) + private static void AddDifficulties(Bot bot, string workingPath) { var botFiles = Directory .GetFiles($"{workingPath}//Assets", "*.txt", SearchOption.TopDirectoryOnly) @@ -114,7 +103,7 @@ namespace Generator DifficultyHelper.AddDifficultySettings(bot, botFiles); } - private void UpdateBodyPartHealth(Bot botToUpdate, List rawParsedBots) + private static void UpdateBodyPartHealth(Bot botToUpdate, List rawParsedBots) { var firstBotOfDesiredType = rawParsedBots.FirstOrDefault(); if (firstBotOfDesiredType == null) @@ -145,7 +134,7 @@ namespace Generator botToUpdate.health.BodyParts.RightLeg.max = firstBotOfDesiredType.Health.BodyParts.RightLeg.Health.Maximum; } - private void AddVisualAppearanceItems(Bot botToUpdate, Datum rawBot) + private static void AddVisualAppearanceItems(Bot botToUpdate, Datum rawBot) { botToUpdate.appearance.head.AddUnique(rawBot.Customization.Head); botToUpdate.appearance.body.AddUnique(rawBot.Customization.Body); @@ -153,7 +142,7 @@ namespace Generator botToUpdate.appearance.feet.AddUnique(rawBot.Customization.Feet); } - private void AddName(Bot botToUpdate, Datum rawBot) + private static void AddName(Bot botToUpdate, Datum rawBot) { var name = rawBot.Info.Nickname.Split(); botToUpdate.firstName.AddUnique(name[0]); diff --git a/Generator/BotChancesGenerator.cs b/Generator/BotChancesGenerator.cs index cc9de51..b72cbf9 100644 --- a/Generator/BotChancesGenerator.cs +++ b/Generator/BotChancesGenerator.cs @@ -9,25 +9,16 @@ using System.Linq; namespace Generator { - internal class BotChancesGenerator + public static class BotChancesGenerator { - private readonly List _bots; - private readonly List _rawParsedBots; - - public BotChancesGenerator(List botsWithGearAndLoot, List parsedBots) - { - _bots = botsWithGearAndLoot; - _rawParsedBots = parsedBots; - } - - internal List AddChances() + public static IEnumerable AddChances(this IEnumerable botsWithGear, IEnumerable parsedBots) { var stopwatch = Stopwatch.StartNew(); LoggingHelpers.LogToConsole("Started processing bot gear"); - foreach (var botToUpdate in _bots) + foreach (var botToUpdate in botsWithGear) { - var rawParsedBotOfCurrentType = _rawParsedBots + var rawParsedBotOfCurrentType = parsedBots .Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)) .ToList(); @@ -36,6 +27,7 @@ namespace Generator continue; } + // TODO: Add check to make sure incoming bot list has gear GearChanceHelpers.CalculateEquipmentChances(botToUpdate, rawParsedBotOfCurrentType); GearChanceHelpers.AddGenerationChances(botToUpdate); GearChanceHelpers.CalculateModChances(botToUpdate, rawParsedBotOfCurrentType); @@ -44,7 +36,7 @@ namespace Generator stopwatch.Stop(); LoggingHelpers.LogToConsole($"Finished processing bot chances. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); - return _bots; + return botsWithGear; } } } \ No newline at end of file diff --git a/Generator/BotGearGenerator.cs b/Generator/BotGearGenerator.cs index 1957c5d..9c4fc89 100644 --- a/Generator/BotGearGenerator.cs +++ b/Generator/BotGearGenerator.cs @@ -1,5 +1,4 @@ using Common; -using Generator.Helpers; using Generator.Helpers.Gear; using Generator.Models.Input; using Generator.Models.Output; @@ -10,25 +9,16 @@ using System.Linq; namespace Generator { - public class BotGearGenerator + public static class BotGearGenerator { - private readonly List _baseBots; - private readonly List _rawParsedBots; - - public BotGearGenerator(List baseBots, List parsedBots) - { - _baseBots = baseBots; - _rawParsedBots = parsedBots; - } - - internal List AddGear() + public static IEnumerable AddGear(this IEnumerable baseBots, IEnumerable parsedBots) { var stopwatch = Stopwatch.StartNew(); LoggingHelpers.LogToConsole("Started processing bot gear"); - foreach (var botToUpdate in _baseBots) + foreach (var botToUpdate in baseBots) { - var rawParsedBotOfCurrentType = _rawParsedBots + var rawParsedBotOfCurrentType = parsedBots .Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)) .ToList(); @@ -48,7 +38,7 @@ namespace Generator stopwatch.Stop(); LoggingHelpers.LogToConsole($"Finished processing bot gear. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); - return _baseBots; + return baseBots; } } } diff --git a/Generator/BotLootGenerator.cs b/Generator/BotLootGenerator.cs index eeb470d..3dd5a0e 100644 --- a/Generator/BotLootGenerator.cs +++ b/Generator/BotLootGenerator.cs @@ -1,6 +1,5 @@ using Common; using Common.Extensions; -using Generator.Helpers; using Generator.Helpers.Gear; using Generator.Models.Input; using Generator.Models.Output; @@ -12,26 +11,17 @@ using System.Threading.Tasks; namespace Generator { - public class BotLootGenerator + public static class BotLootGenerator { - private readonly List _botsWithGear; - private readonly List _rawParsedBots; - - public BotLootGenerator(List botsWithGear, List rawParsedBots) - { - _botsWithGear = botsWithGear; - _rawParsedBots = rawParsedBots; - } - - internal List AddLoot() + internal static IEnumerable AddLoot(this IEnumerable botsWithGear, IEnumerable parsedBots) { var stopwatch = Stopwatch.StartNew(); LoggingHelpers.LogToConsole("Started processing bot loot"); // Iterate over assault/raider etc - Parallel.ForEach(_botsWithGear, botToUpdate => + Parallel.ForEach(botsWithGear, botToUpdate => { - var rawBotsOfSameType = _rawParsedBots + var rawBotsOfSameType = parsedBots .Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)) .ToList(); @@ -54,10 +44,10 @@ namespace Generator stopwatch.Stop(); LoggingHelpers.LogToConsole($"Finished processing bot loot. Took: {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); - return _botsWithGear; + return botsWithGear; } - private void AddPocketLoot(Bot finalBot, Datum bot) + private static void AddPocketLoot(Bot finalBot, Datum bot) { // pocket loot foreach (var lootItem in bot.Inventory.items.Where(x => x?.slotId?.StartsWith("pocket") == true)) @@ -66,13 +56,13 @@ namespace Generator } } - private void AddTacticalVestLoot(Bot finalBot, List bots) + private static void AddTacticalVestLoot(Bot finalBot, IEnumerable bots) { var tacVestItems = GetItemsStoredInEquipmentItem(bots, "TacticalVest"); finalBot.inventory.items.TacticalVest.AddRange(tacVestItems); } - private void AddBackpackLoot(Bot finalBot, List bots) + private static void AddBackpackLoot(Bot finalBot, IEnumerable bots) { // add generic keys to bosses if (finalBot.botType.IsBoss()) @@ -84,18 +74,18 @@ namespace Generator finalBot.inventory.items.Backpack.AddRange(backpackItems); } - private void AddSecureContainerLoot(Bot finalAssaultBot, List bots) + private static void AddSecureContainerLoot(Bot finalAssaultBot, IEnumerable bots) { var tacVestItems = GetItemsStoredInEquipmentItem(bots, "SecuredContainer"); finalAssaultBot.inventory.items.SecuredContainer.AddRange(tacVestItems); } - private void AddSpecialLoot(Bot botToUpdate) + private static void AddSpecialLoot(Bot botToUpdate) { botToUpdate.inventory.items.SpecialLoot.AddRange(SpecialLootHelper.GetSpecialLootForBotType(botToUpdate.botType)); } - private List GetItemsStoredInEquipmentItem(List bots, string containerName) + private static IEnumerable GetItemsStoredInEquipmentItem(IEnumerable bots, string containerName) { var itemsStoredInContainer = new List(); var containers = new List(); @@ -120,8 +110,5 @@ namespace Generator return itemsStoredInContainer; } - - - } } diff --git a/Generator/Helpers/Gear/GearChanceHelpers.cs b/Generator/Helpers/Gear/GearChanceHelpers.cs index c9c5b03..7f4b98a 100644 --- a/Generator/Helpers/Gear/GearChanceHelpers.cs +++ b/Generator/Helpers/Gear/GearChanceHelpers.cs @@ -1,4 +1,5 @@ -using Generator.Models.Input; +using System; +using Generator.Models.Input; using Generator.Models.Output; using System.Collections.Generic; using System.Linq; @@ -129,7 +130,7 @@ namespace Generator.Helpers.Gear private static int GetPercent(int total, int count) { - return ((200 * count) + 1) / (total * 2); + return (int)Math.Ceiling((double)(((200 * count) + 1) / (total * 2))); } } } diff --git a/Generator/Program.cs b/Generator/Program.cs index 8bc5cce..62c36d2 100644 --- a/Generator/Program.cs +++ b/Generator/Program.cs @@ -1,11 +1,12 @@ using Common; using System.IO; +using System.Linq; namespace Generator { - class Program + internal static class Program { - static void Main(string[] args) + internal static void Main(string[] args) { // Create list of bots we want to process string[] botTypes = { @@ -48,25 +49,15 @@ namespace Generator return; } - // Generate the base bot class and add basic details (health/body part hp etc) - var baseBotGenerator = new BaseBotGenerator(parsedBots, workingPath, botTypes); - var baseBots = baseBotGenerator.AddBaseDetails(); - - // Add weapons/armor to bots - var botGearGenerator = new BotGearGenerator(baseBots, parsedBots); - var botsWithGear = botGearGenerator.AddGear(); - - // Add loot to bots - var botLootGenerator = new BotLootGenerator(botsWithGear, parsedBots); - var botsWithGearAndLoot = botLootGenerator.AddLoot(); - - // Add mod/equipment chances - var botChancesGenerator = new BotChancesGenerator(botsWithGearAndLoot, parsedBots); - var botsWithGearAndLootAndChances = botChancesGenerator.AddChances(); + // Generate the base bot class with basic details (health/body part hp etc) and then append everything else + var bots = BaseBotGenerator.GenerateBaseDetails(parsedBots, workingPath, botTypes) + .AddGear(parsedBots) // Add weapons/armor + .AddLoot(parsedBots) + .AddChances(parsedBots); // Add mod/equipment chances // Output bot to json file var jsonWriter = new JsonWriter(workingPath, "output"); - jsonWriter.WriteJson(botsWithGearAndLootAndChances); + jsonWriter.WriteJson(bots.ToList()); } } }