Naming consistency improvements

This commit is contained in:
Chomp 2021-09-05 12:27:17 +01:00
parent dd72a6e5e2
commit 7547f3379f
5 changed files with 38 additions and 39 deletions

View File

@ -15,24 +15,24 @@ namespace Generator
public static class BaseBotGenerator public static class BaseBotGenerator
{ {
//TODO: pass in bot types and use those to create the classes in rawBots list //TODO: pass in bot types and use those to create the classes in rawBots list
public static IEnumerable<Bot> GenerateBaseDetails(IEnumerable<Datum> parsedBots, string workingPath, IEnumerable<string> botTypes) public static IEnumerable<Bot> GenerateBaseDetails(IEnumerable<Datum> rawBots, string workingPath, IEnumerable<string> botTypes)
{ {
var stopwatch = Stopwatch.StartNew(); var stopwatch = Stopwatch.StartNew();
LoggingHelpers.LogToConsole("Started processing bot base"); LoggingHelpers.LogToConsole("Started processing bot base");
// Create a list of bot objects ready to be hydrated // Create a list of bot objects ready to be hydrated
var rawBots = new List<Bot>(); var baseBots = new List<Bot>();
foreach (var botType in botTypes) foreach (var botType in botTypes)
{ {
var typeToAdd = (BotType)Enum.Parse(typeof(BotType), botType); var typeToAdd = (BotType)Enum.Parse(typeof(BotType), botType);
rawBots.Add(new Bot(typeToAdd)); baseBots.Add(new Bot(typeToAdd));
} }
// Iterate over each bot type wejust made and put some data into them // Iterate over each bot type wejust made and put some data into them
foreach (var botToUpdate in rawBots) foreach (var botToUpdate in baseBots)
{ {
var rawBotsOfSameType = parsedBots var rawBotsOfSameType = rawBots.Where(x => string.Equals(x.Info.Settings.Role, botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase))
.Where(x => string.Equals(x.Info.Settings.Role, botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)).ToList(); .ToList();
if (rawBotsOfSameType.Count == 0) if (rawBotsOfSameType.Count == 0)
{ {
@ -59,7 +59,7 @@ namespace Generator
stopwatch.Stop(); stopwatch.Stop();
LoggingHelpers.LogToConsole($"Finished processing bot base. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); LoggingHelpers.LogToConsole($"Finished processing bot base. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds");
return rawBots; return baseBots;
} }
private static void AddSkills(Bot botToUpdate, IEnumerable<Datum> rawBotsOfSameType) private static void AddSkills(Bot botToUpdate, IEnumerable<Datum> rawBotsOfSameType)
@ -88,9 +88,9 @@ namespace Generator
botToUpdate.experience.reward.max = firstBotOfDesiredType.Info.Settings.Experience; botToUpdate.experience.reward.max = firstBotOfDesiredType.Info.Settings.Experience;
} }
private static void AddVoice(Bot bot, Datum rawParsedBot) private static void AddVoice(Bot bot, Datum rawBot)
{ {
bot.appearance.voice.AddUnique(rawParsedBot.Info.Voice); bot.appearance.voice.AddUnique(rawBot.Info.Voice);
} }
private static void AddDifficulties(Bot bot, string workingPath) private static void AddDifficulties(Bot bot, string workingPath)
@ -103,9 +103,9 @@ namespace Generator
DifficultyHelper.AddDifficultySettings(bot, botFiles); DifficultyHelper.AddDifficultySettings(bot, botFiles);
} }
private static void UpdateBodyPartHealth(Bot botToUpdate, List<Datum> rawParsedBots) private static void UpdateBodyPartHealth(Bot botToUpdate, List<Datum> rawBots)
{ {
var firstBotOfDesiredType = rawParsedBots.FirstOrDefault(); var firstBotOfDesiredType = rawBots.FirstOrDefault();
if (firstBotOfDesiredType == null) if (firstBotOfDesiredType == null)
{ {
LoggingHelpers.LogToConsole($"bot type of: {botToUpdate.botType} not found, unable to update body part health."); LoggingHelpers.LogToConsole($"bot type of: {botToUpdate.botType} not found, unable to update body part health.");

View File

@ -11,14 +11,14 @@ namespace Generator
{ {
public static class BotChancesGenerator public static class BotChancesGenerator
{ {
public static IEnumerable<Bot> AddChances(this IEnumerable<Bot> botsWithGear, IEnumerable<Datum> parsedBots) public static IEnumerable<Bot> AddChances(this IEnumerable<Bot> botsToUpdate, IEnumerable<Datum> rawBots)
{ {
var stopwatch = Stopwatch.StartNew(); var stopwatch = Stopwatch.StartNew();
LoggingHelpers.LogToConsole("Started processing bot gear"); LoggingHelpers.LogToConsole("Started processing bot gear");
foreach (var botToUpdate in botsWithGear) foreach (var botToUpdate in botsToUpdate)
{ {
var rawParsedBotOfCurrentType = parsedBots var rawParsedBotOfCurrentType = rawBots
.Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)) .Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase))
.ToList(); .ToList();
@ -36,7 +36,7 @@ namespace Generator
stopwatch.Stop(); stopwatch.Stop();
LoggingHelpers.LogToConsole($"Finished processing bot chances. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); LoggingHelpers.LogToConsole($"Finished processing bot chances. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds");
return botsWithGear; return botsToUpdate;
} }
} }
} }

View File

@ -11,15 +11,14 @@ namespace Generator
{ {
public static class BotGearGenerator public static class BotGearGenerator
{ {
public static IEnumerable<Bot> AddGear(this IEnumerable<Bot> baseBots, IEnumerable<Datum> parsedBots) public static IEnumerable<Bot> AddGear(this IEnumerable<Bot> baseBots, IEnumerable<Datum> rawBots)
{ {
var stopwatch = Stopwatch.StartNew(); var stopwatch = Stopwatch.StartNew();
LoggingHelpers.LogToConsole("Started processing bot gear"); LoggingHelpers.LogToConsole("Started processing bot gear");
foreach (var botToUpdate in baseBots) foreach (var botToUpdate in baseBots)
{ {
var rawParsedBotOfCurrentType = parsedBots var rawParsedBotOfCurrentType = rawBots.Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase))
.Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase))
.ToList(); .ToList();
if (rawParsedBotOfCurrentType.Count == 0) if (rawParsedBotOfCurrentType.Count == 0)

View File

@ -13,7 +13,7 @@ namespace Generator
{ {
public static class BotLootGenerator public static class BotLootGenerator
{ {
internal static IEnumerable<Bot> AddLoot(this IEnumerable<Bot> botsWithGear, IEnumerable<Datum> parsedBots) internal static IEnumerable<Bot> AddLoot(this IEnumerable<Bot> botsWithGear, IEnumerable<Datum> rawBots)
{ {
var stopwatch = Stopwatch.StartNew(); var stopwatch = Stopwatch.StartNew();
LoggingHelpers.LogToConsole("Started processing bot loot"); LoggingHelpers.LogToConsole("Started processing bot loot");
@ -21,7 +21,7 @@ namespace Generator
// Iterate over assault/raider etc // Iterate over assault/raider etc
Parallel.ForEach(botsWithGear, botToUpdate => Parallel.ForEach(botsWithGear, botToUpdate =>
{ {
var rawBotsOfSameType = parsedBots var rawBotsOfSameType = rawBots
.Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)) .Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase))
.ToList(); .ToList();
@ -47,22 +47,22 @@ namespace Generator
return botsWithGear; return botsWithGear;
} }
private static void AddPocketLoot(Bot botToUpdate, Datum bot) private static void AddPocketLoot(Bot botToUpdate, Datum rawBot)
{ {
// pocket loot // pocket loot
foreach (var lootItem in bot.Inventory.items.Where(x => x?.slotId?.StartsWith("pocket") == true)) foreach (var lootItem in rawBot.Inventory.items.Where(x => x?.slotId?.StartsWith("pocket") == true))
{ {
botToUpdate.inventory.items.Pockets.AddUnique(lootItem._tpl); botToUpdate.inventory.items.Pockets.AddUnique(lootItem._tpl);
} }
} }
private static void AddTacticalVestLoot(Bot botToUpdate, IEnumerable<Datum> bots) private static void AddTacticalVestLoot(Bot botToUpdate, IEnumerable<Datum> rawBots)
{ {
var tacVestItems = GetItemsStoredInEquipmentItem(bots, "TacticalVest"); var tacVestItems = GetItemsStoredInEquipmentItem(rawBots, "TacticalVest");
botToUpdate.inventory.items.TacticalVest.AddRange(tacVestItems); botToUpdate.inventory.items.TacticalVest.AddRange(tacVestItems);
} }
private static void AddBackpackLoot(Bot botToUpdate, IEnumerable<Datum> bots) private static void AddBackpackLoot(Bot botToUpdate, IEnumerable<Datum> rawBots)
{ {
// add generic keys to bosses // add generic keys to bosses
if (botToUpdate.botType.IsBoss()) if (botToUpdate.botType.IsBoss())
@ -70,13 +70,13 @@ namespace Generator
botToUpdate.inventory.items.Backpack.AddRange(SpecialLootHelper.GetGenericBossKeys()); botToUpdate.inventory.items.Backpack.AddRange(SpecialLootHelper.GetGenericBossKeys());
} }
var backpackItems = GetItemsStoredInEquipmentItem(bots, "Backpack"); var backpackItems = GetItemsStoredInEquipmentItem(rawBots, "Backpack");
botToUpdate.inventory.items.Backpack.AddRange(backpackItems); botToUpdate.inventory.items.Backpack.AddRange(backpackItems);
} }
private static void AddSecureContainerLoot(Bot botToUpdate, IEnumerable<Datum> bots) private static void AddSecureContainerLoot(Bot botToUpdate, IEnumerable<Datum> rawBots)
{ {
var tacVestItems = GetItemsStoredInEquipmentItem(bots, "SecuredContainer"); var tacVestItems = GetItemsStoredInEquipmentItem(rawBots, "SecuredContainer");
botToUpdate.inventory.items.SecuredContainer.AddRange(tacVestItems); botToUpdate.inventory.items.SecuredContainer.AddRange(tacVestItems);
} }
@ -85,11 +85,11 @@ namespace Generator
botToUpdate.inventory.items.SpecialLoot.AddRange(SpecialLootHelper.GetSpecialLootForBotType(botToUpdate.botType)); botToUpdate.inventory.items.SpecialLoot.AddRange(SpecialLootHelper.GetSpecialLootForBotType(botToUpdate.botType));
} }
private static IEnumerable<string> GetItemsStoredInEquipmentItem(IEnumerable<Datum> bots, string containerName) private static IEnumerable<string> GetItemsStoredInEquipmentItem(IEnumerable<Datum> rawBots, string containerName)
{ {
var itemsStoredInContainer = new List<string>(); var itemsStoredInContainer = new List<string>();
var containers = new List<string>(); var containers = new List<string>();
foreach (var bot in bots) foreach (var bot in rawBots)
{ {
// find the container type we want on this bot (backpack etc) // find the container type we want on this bot (backpack etc)
// Add to list // Add to list

View File

@ -11,12 +11,12 @@ namespace Generator.Helpers
{ {
private static readonly string[] _difficulties = new[] { "easy", "normal", "hard", "impossible" }; private static readonly string[] _difficulties = new[] { "easy", "normal", "hard", "impossible" };
public static void AddDifficultySettings(Bot bot, List<string> difficultyFilePaths) public static void AddDifficultySettings(Bot botToUpdate, List<string> difficultyFilePaths)
{ {
// Read bot setting files from assets folder that match this bots type // Read bot setting files from assets folder that match this bots type
// Save into dictionary with difficulty as key // Save into dictionary with difficulty as key
var difficultySettingsJsons = new Dictionary<string, DifficultySettings>(); var difficultySettingsJsons = new Dictionary<string, DifficultySettings>();
foreach (var path in difficultyFilePaths.Where(x=>x.Contains($"_{bot.botType}", System.StringComparison.InvariantCultureIgnoreCase))) foreach (var path in difficultyFilePaths.Where(x=>x.Contains($"_{botToUpdate.botType}", System.StringComparison.InvariantCultureIgnoreCase)))
{ {
var json = File.ReadAllText(path); var json = File.ReadAllText(path);
var serialisedObject = JsonConvert.DeserializeObject<DifficultySettings>(json); var serialisedObject = JsonConvert.DeserializeObject<DifficultySettings>(json);
@ -37,7 +37,7 @@ namespace Generator.Helpers
settings = difficultySettingsJsons.FirstOrDefault(x => x.Key != null); settings = difficultySettingsJsons.FirstOrDefault(x => x.Key != null);
} }
SaveSettingsIntoBotFile(bot, difficulty, settings.Value); SaveSettingsIntoBotFile(botToUpdate, difficulty, settings.Value);
} }
} }
@ -49,21 +49,21 @@ namespace Generator.Helpers
return splitPath.Last().Split("_")[0]; return splitPath.Last().Split("_")[0];
} }
private static void SaveSettingsIntoBotFile(Bot bot, string difficulty, DifficultySettings settings) private static void SaveSettingsIntoBotFile(Bot botToUpdate, string difficulty, DifficultySettings settings)
{ {
switch (difficulty) switch (difficulty)
{ {
case "easy": case "easy":
bot.difficulty.easy = settings; botToUpdate.difficulty.easy = settings;
break; break;
case "normal": case "normal":
bot.difficulty.normal = settings; botToUpdate.difficulty.normal = settings;
break; break;
case "hard": case "hard":
bot.difficulty.hard = settings; botToUpdate.difficulty.hard = settings;
break; break;
case "impossible": case "impossible":
bot.difficulty.impossible = settings; botToUpdate.difficulty.impossible = settings;
break; break;
} }
} }