BotGenerator/Generator/BaseBotGenerator.cs

193 lines
8.9 KiB
C#
Raw Normal View History

2021-08-24 12:08:30 +01:00
using Common;
using Common.Extensions;
using Common.Models;
using Common.Models.Input;
using Common.Models.Output;
2021-08-24 12:08:30 +01:00
using Generator.Helpers;
2021-08-12 16:52:06 +01:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
2021-08-12 16:52:06 +01:00
using System.Linq;
namespace Generator
{
2021-09-01 19:19:44 +03:00
public static class BaseBotGenerator
2021-08-12 16:52:06 +01:00
{
2021-09-01 19:19:44 +03:00
//TODO: pass in bot types and use those to create the classes in rawBots list
2021-09-05 12:27:17 +01:00
public static IEnumerable<Bot> GenerateBaseDetails(IEnumerable<Datum> rawBots, string workingPath, IEnumerable<string> botTypes)
2021-08-12 16:52:06 +01:00
{
var stopwatch = Stopwatch.StartNew();
LoggingHelpers.LogToConsole("Started processing bot base");
// Create a list of bot objects ready to be hydrated
2021-09-05 12:27:17 +01:00
var baseBots = new List<Bot>();
2021-09-01 19:19:44 +03:00
foreach (var botType in botTypes)
2021-08-12 16:52:06 +01:00
{
var typeToAdd = (BotType)Enum.Parse(typeof(BotType), botType);
2021-09-05 12:27:17 +01:00
baseBots.Add(new Bot(typeToAdd));
}
2021-08-12 16:52:06 +01:00
// Iterate over each bot type wejust made and put some data into them
2021-09-05 12:27:17 +01:00
foreach (var botToUpdate in baseBots)
2021-08-12 16:52:06 +01:00
{
2021-09-05 12:27:17 +01:00
var rawBotsOfSameType = rawBots.Where(x => string.Equals(x.Info.Settings.Role, botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase))
.ToList();
2021-08-12 16:52:06 +01:00
if (rawBotsOfSameType.Count == 0)
{
2021-08-17 18:33:55 +01:00
LoggingHelpers.LogToConsole($"no bots of type {botToUpdate.botType}", ConsoleColor.DarkRed);
continue;
}
2021-08-17 18:33:55 +01:00
LoggingHelpers.LogToConsole($"Found {rawBotsOfSameType.Count} bots of type: {botToUpdate.botType}");
UpdateBodyPartHealth(botToUpdate, rawBotsOfSameType);
2021-09-01 19:19:44 +03:00
AddDifficulties(botToUpdate, workingPath);
AddExperience(botToUpdate, rawBotsOfSameType);
AddStandingForKill(botToUpdate, rawBotsOfSameType);
AddSkills(botToUpdate, rawBotsOfSameType);
foreach (var rawParsedBot in rawBotsOfSameType)
2021-08-12 16:52:06 +01:00
{
AddVisualAppearanceItems(botToUpdate, rawParsedBot);
AddName(botToUpdate, rawParsedBot);
AddVoice(botToUpdate, rawParsedBot);
2021-08-12 16:52:06 +01:00
}
}
stopwatch.Stop();
2021-08-12 21:31:15 +01:00
LoggingHelpers.LogToConsole($"Finished processing bot base. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds");
2021-08-12 16:52:06 +01:00
2021-09-05 12:27:17 +01:00
return baseBots;
2021-08-12 16:52:06 +01:00
}
2021-09-01 19:19:44 +03:00
private static void AddSkills(Bot botToUpdate, IEnumerable<Datum> rawBotsOfSameType)
{
var firstBotOfDesiredType = rawBotsOfSameType.FirstOrDefault();
foreach (var skill in firstBotOfDesiredType.Skills.Common)
{
botToUpdate.skills.Common.Add(skill.Id, new MinMax(skill.Progress, skill.Progress));
}
}
2021-09-01 19:19:44 +03:00
private static void AddStandingForKill(Bot botToUpdate, IEnumerable<Datum> rawBotsOfSameType)
{
var firstBotOfDesiredType = rawBotsOfSameType.FirstOrDefault();
botToUpdate.experience.standingForKill = firstBotOfDesiredType.Info.Settings.StandingForKill;
2021-08-17 16:33:31 +01:00
botToUpdate.experience.aggressorBonus = firstBotOfDesiredType.Info.Settings.AggressorBonus;
}
2021-09-01 19:19:44 +03:00
private static void AddExperience(Bot botToUpdate, IEnumerable<Datum> rawBotsOfSameType)
{
var firstBotOfDesiredType = rawBotsOfSameType.FirstOrDefault();
botToUpdate.experience.reward.min = firstBotOfDesiredType.Info.Settings.Experience;
botToUpdate.experience.reward.max = firstBotOfDesiredType.Info.Settings.Experience;
}
2021-09-05 12:27:17 +01:00
private static void AddVoice(Bot bot, Datum rawBot)
{
2021-09-05 12:27:17 +01:00
bot.appearance.voice.AddUnique(rawBot.Info.Voice);
}
2021-09-01 19:19:44 +03:00
private static void AddDifficulties(Bot bot, string workingPath)
2021-08-12 16:52:06 +01:00
{
var botFiles = Directory
.GetFiles($"{workingPath}//Assets", "*.txt", SearchOption.TopDirectoryOnly)
.Where(x => x.Contains(bot.botType.ToString(), StringComparison.InvariantCultureIgnoreCase))
.ToList();
DifficultyHelper.AddDifficultySettings(bot, botFiles);
2021-08-12 16:52:06 +01:00
}
2021-09-05 12:27:17 +01:00
private static void UpdateBodyPartHealth(Bot botToUpdate, List<Datum> rawBots)
2021-08-12 16:52:06 +01:00
{
var uniqueHealthSetups = new Dictionary<int, Common.Models.Output.BodyParts>();
foreach (var bot in rawBots)
{
var healthTotal = bot.Health.BodyParts.GetHpMaxTotal();
var alreadyExists = uniqueHealthSetups.ContainsKey(healthTotal);
if (!alreadyExists)
{
var bodyPartHpToAdd = new Common.Models.Output.BodyParts();
bodyPartHpToAdd.Head.min = bot.Health.BodyParts.Head.Health.Current;
bodyPartHpToAdd.Head.max = bot.Health.BodyParts.Head.Health.Maximum;
bodyPartHpToAdd.Chest.min = bot.Health.BodyParts.Chest.Health.Current;
bodyPartHpToAdd.Chest.max = bot.Health.BodyParts.Chest.Health.Maximum;
bodyPartHpToAdd.Stomach.min = bot.Health.BodyParts.Stomach.Health.Current;
bodyPartHpToAdd.Stomach.max = bot.Health.BodyParts.Stomach.Health.Maximum;
bodyPartHpToAdd.LeftArm.min = bot.Health.BodyParts.LeftArm.Health.Current;
bodyPartHpToAdd.LeftArm.max = bot.Health.BodyParts.LeftArm.Health.Maximum;
bodyPartHpToAdd.RightArm.min = bot.Health.BodyParts.RightArm.Health.Current;
bodyPartHpToAdd.RightArm.max = bot.Health.BodyParts.RightArm.Health.Maximum;
bodyPartHpToAdd.LeftLeg.min = bot.Health.BodyParts.LeftLeg.Health.Current;
bodyPartHpToAdd.LeftLeg.max = bot.Health.BodyParts.LeftLeg.Health.Maximum;
bodyPartHpToAdd.RightLeg.min = bot.Health.BodyParts.RightLeg.Health.Current;
bodyPartHpToAdd.RightLeg.max = bot.Health.BodyParts.RightLeg.Health.Maximum;
uniqueHealthSetups.Add(healthTotal, bodyPartHpToAdd);
}
}
botToUpdate.health.BodyParts = uniqueHealthSetups.Values.ToList();
//var firstBotOfDesiredType = rawBots.FirstOrDefault();
//if (firstBotOfDesiredType == null)
//{
// string botType = botToUpdate.botType.ToString();
// LoggingHelpers.LogToConsole($"bot type of: {botType} not found, unable to update body part health.");
// return;
//}
//botToUpdate.health.BodyParts.Head.min = firstBotOfDesiredType.Health.BodyParts.Head.Health.Current;
//botToUpdate.health.BodyParts.Head.max = firstBotOfDesiredType.Health.BodyParts.Head.Health.Maximum;
2021-08-12 16:52:06 +01:00
//botToUpdate.health.BodyParts.Chest.min = firstBotOfDesiredType.Health.BodyParts.Chest.Health.Current;
//botToUpdate.health.BodyParts.Chest.max = firstBotOfDesiredType.Health.BodyParts.Chest.Health.Maximum;
2021-08-12 16:52:06 +01:00
//botToUpdate.health.BodyParts.Stomach.min = firstBotOfDesiredType.Health.BodyParts.Stomach.Health.Current;
//botToUpdate.health.BodyParts.Stomach.max = firstBotOfDesiredType.Health.BodyParts.Stomach.Health.Maximum;
2021-08-12 16:52:06 +01:00
//botToUpdate.health.BodyParts.LeftArm.min = firstBotOfDesiredType.Health.BodyParts.LeftArm.Health.Current;
//botToUpdate.health.BodyParts.LeftArm.max = firstBotOfDesiredType.Health.BodyParts.LeftArm.Health.Maximum;
2021-08-12 16:52:06 +01:00
//botToUpdate.health.BodyParts.RightArm.min = firstBotOfDesiredType.Health.BodyParts.RightArm.Health.Current;
//botToUpdate.health.BodyParts.RightArm.max = firstBotOfDesiredType.Health.BodyParts.RightArm.Health.Maximum;
2021-08-12 16:52:06 +01:00
//botToUpdate.health.BodyParts.LeftLeg.min = firstBotOfDesiredType.Health.BodyParts.LeftLeg.Health.Current;
//botToUpdate.health.BodyParts.LeftLeg.max = firstBotOfDesiredType.Health.BodyParts.LeftLeg.Health.Maximum;
2021-08-12 16:52:06 +01:00
//botToUpdate.health.BodyParts.RightLeg.min = firstBotOfDesiredType.Health.BodyParts.RightLeg.Health.Current;
//botToUpdate.health.BodyParts.RightLeg.max = firstBotOfDesiredType.Health.BodyParts.RightLeg.Health.Maximum;
2021-08-12 16:52:06 +01:00
}
2021-09-01 19:19:44 +03:00
private static void AddVisualAppearanceItems(Bot botToUpdate, Datum rawBot)
2021-08-12 16:52:06 +01:00
{
botToUpdate.appearance.head.AddUnique(rawBot.Customization.Head);
botToUpdate.appearance.body.AddUnique(rawBot.Customization.Body);
botToUpdate.appearance.hands.AddUnique(rawBot.Customization.Hands);
botToUpdate.appearance.feet.AddUnique(rawBot.Customization.Feet);
2021-08-12 16:52:06 +01:00
}
2021-09-01 19:19:44 +03:00
private static void AddName(Bot botToUpdate, Datum rawBot)
2021-08-12 16:52:06 +01:00
{
var name = rawBot.Info.Nickname.Split();
botToUpdate.firstName.AddUnique(name[0]);
2021-08-12 16:52:06 +01:00
if (name.Length > 1)
{
botToUpdate.lastName.AddUnique(name[1]);
2021-08-12 16:52:06 +01:00
}
}
}
}