BotGenerator/Generator/BaseBotGenerator.cs

182 lines
7.6 KiB
C#
Raw Normal View History

2021-08-12 16:52:06 +01:00
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;
2021-08-12 16:52:06 +01:00
using System.Linq;
namespace Generator
{
public class BaseBotGenerator
{
private readonly List<Datum> _rawParsedBots;
private readonly string _workingPath;
2021-08-12 16:52:06 +01:00
2021-08-17 17:35:18 +01:00
//TODO: pass in bot types and use those to create the clases in rawBots list
public BaseBotGenerator(List<Datum> parsedBots, string workingPath)
2021-08-12 16:52:06 +01:00
{
_rawParsedBots = parsedBots;
_workingPath = workingPath;
2021-08-12 16:52:06 +01:00
}
public List<Bot> AddBaseDetails()
{
var stopwatch = Stopwatch.StartNew();
LoggingHelpers.LogToConsole("Started processing bot base");
var rawBots = new List<Bot>
{
2021-08-18 21:41:59 +01:00
new Bot(BotType.assault),
new Bot(BotType.pmcBot),
new Bot(BotType.marksman),
new Bot(BotType.bossbully),
new Bot(BotType.bossgluhar),
new Bot(BotType.bosskilla),
new Bot(BotType.bosskojaniy),
new Bot(BotType.bosssanitar),
new Bot(BotType.bossstormtrooper),
new Bot(BotType.followerbully),
new Bot(BotType.followergluharassault),
new Bot(BotType.followergluharscout),
new Bot(BotType.followergluharsecurity),
new Bot(BotType.followergluharsnipe),
new Bot(BotType.followerkojaniy),
new Bot(BotType.followersanitar),
new Bot(BotType.followerstormtrooper),
2021-08-17 17:32:03 +01:00
2021-08-18 21:41:59 +01:00
new Bot(BotType.cursedassault),
new Bot(BotType.sectantpriest),
new Bot(BotType.sectantwarrior),
};
2021-08-12 16:52:06 +01:00
foreach (var botToUpdate in rawBots)
{
var rawBotsOfSameType = _rawParsedBots
2021-08-12 16:52:06 +01:00
.Where(x => string.Equals(x.Info.Settings.Role, botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)).ToList();
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);
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
return rawBots;
}
private void AddSkills(Bot botToUpdate, List<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));
}
}
private void AddStandingForKill(Bot botToUpdate, List<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;
}
private void AddExperience(Bot botToUpdate, List<Datum> rawBotsOfSameType)
{
var firstBotOfDesiredType = rawBotsOfSameType.FirstOrDefault();
botToUpdate.experience.reward.min = firstBotOfDesiredType.Info.Settings.Experience;
botToUpdate.experience.reward.max = firstBotOfDesiredType.Info.Settings.Experience;
}
private void AddVoice(Bot bot, Datum rawParsedBot)
{
bot.appearance.voice.AddUnique(rawParsedBot.Info.Voice);
}
private 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
}
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;
}
2021-08-12 16:52:06 +01:00
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)
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
}
private 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
}
}
}
}