BotGenerator/Generator/BaseBotGenerator.cs
Chomp 1b22e9d01b pass working path to class
pass a list of bot files to difficulty helper
2021-08-14 09:53:00 +01:00

127 lines
5.2 KiB
C#

using Generator.Helpers;
using Generator.Models;
using Generator.Models.Input;
using Generator.Models.Output;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace Generator
{
public class BaseBotGenerator
{
private readonly List<Datum> _rawParsedBots;
private readonly string _workingPath;
public BaseBotGenerator(List<Datum> parsedBots, string workingPath)
{
_rawParsedBots = parsedBots;
_workingPath = workingPath;
}
public List<Bot> AddBaseDetails()
{
var stopwatch = Stopwatch.StartNew();
LoggingHelpers.LogToConsole("Started processing bot base");
var assaultBot = new Bot(BotType.assault);
var raiderBot = new Bot(BotType.pmcBot);
var marksmanBot = new Bot(BotType.marksman);
var rawBots = new List<Bot>
{
assaultBot,
raiderBot,
marksmanBot
};
foreach (var botToUpdate in rawBots)
{
var rawBotsOfSameType = _rawParsedBots
.Where(x => string.Equals(x.Info.Settings.Role, botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)).ToList();
UpdateBodyPartHealth(botToUpdate, rawBotsOfSameType);
AddDifficulties(botToUpdate, _workingPath);
foreach (var rawParsedBot in rawBotsOfSameType)
{
AddVisualAppearanceItems(botToUpdate, rawParsedBot);
AddName(botToUpdate, rawParsedBot);
AddVoice(botToUpdate, rawParsedBot);
}
}
stopwatch.Stop();
LoggingHelpers.LogToConsole($"Finished processing bot base. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds");
return rawBots;
}
private void AddVoice(Bot bot, Datum rawParsedBot)
{
bot.appearance.voice.AddUnique(rawParsedBot.Info.Voice);
}
private void AddDifficulties(Bot bot, string workingPath)
{
var botFiles = Directory
.GetFiles($"{workingPath}//Assets", "*.txt", SearchOption.TopDirectoryOnly)
.Where(x => x.Contains(bot.botType.ToString()))
.ToList();
DifficultyHelper.AddDifficultySettings(bot, botFiles);
}
private void UpdateBodyPartHealth(Bot botToUpdate, List<Datum> rawParsedBots)
{
var firstBotOfDesiredType = rawParsedBots.FirstOrDefault();
if (firstBotOfDesiredType == null)
{
LoggingHelpers.LogToConsole($"bot type of: {botToUpdate.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;
botToUpdate.health.BodyParts.Chest.min = firstBotOfDesiredType.Health.BodyParts.Chest.Health.Current;
botToUpdate.health.BodyParts.Chest.max = firstBotOfDesiredType.Health.BodyParts.Chest.Health.Maximum;
botToUpdate.health.BodyParts.Stomach.min = firstBotOfDesiredType.Health.BodyParts.Stomach.Health.Current;
botToUpdate.health.BodyParts.Stomach.max = firstBotOfDesiredType.Health.BodyParts.Stomach.Health.Maximum;
botToUpdate.health.BodyParts.LeftArm.min = firstBotOfDesiredType.Health.BodyParts.LeftArm.Health.Current;
botToUpdate.health.BodyParts.LeftArm.max = firstBotOfDesiredType.Health.BodyParts.LeftArm.Health.Maximum;
botToUpdate.health.BodyParts.RightArm.min = firstBotOfDesiredType.Health.BodyParts.RightArm.Health.Current;
botToUpdate.health.BodyParts.RightArm.max = firstBotOfDesiredType.Health.BodyParts.RightArm.Health.Maximum;
botToUpdate.health.BodyParts.LeftLeg.min = firstBotOfDesiredType.Health.BodyParts.LeftLeg.Health.Current;
botToUpdate.health.BodyParts.LeftLeg.max = firstBotOfDesiredType.Health.BodyParts.LeftLeg.Health.Maximum;
botToUpdate.health.BodyParts.RightLeg.min = firstBotOfDesiredType.Health.BodyParts.RightLeg.Health.Current;
botToUpdate.health.BodyParts.RightLeg.max = firstBotOfDesiredType.Health.BodyParts.RightLeg.Health.Maximum;
}
private void AddVisualAppearanceItems(Bot botToUpdate, Datum rawBot)
{
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);
}
private void AddName(Bot botToUpdate, Datum rawBot)
{
var name = rawBot.Info.Nickname.Split();
botToUpdate.firstName.AddUnique(name[0]);
if (name.Length > 1)
{
botToUpdate.lastName.AddUnique(name[1]);
}
}
}
}