null guard when bot type cant be found. Log error.

This commit is contained in:
Chomp 2021-08-12 22:17:40 +01:00
parent 9b3278a2f9
commit b9e6cdd49e

View File

@ -73,10 +73,7 @@ namespace Generator
private void AddDifficulties(Bot bot, List<Datum> rawParsedBots) private void AddDifficulties(Bot bot, List<Datum> rawParsedBots)
{ {
var botType = bot.botType; switch (bot.botType)
var firstBotOfDesiredType = rawParsedBots.First(x => x.Info.Settings.Role == botType.ToString());
switch (botType)
{ {
case BotType.assault: case BotType.assault:
DifficultyHelper.AddAssaultDifficulties(bot); DifficultyHelper.AddAssaultDifficulties(bot);
@ -92,7 +89,13 @@ namespace Generator
private void UpdateBodyPartHealth(Bot botToUpdate, List<Datum> rawParsedBots) private void UpdateBodyPartHealth(Bot botToUpdate, List<Datum> rawParsedBots)
{ {
var firstBotOfDesiredType = rawParsedBots.First(x => x.Info.Settings.Role == botToUpdate.botType.ToString()); var firstBotOfDesiredType = rawParsedBots.FirstOrDefault(x => x.Info.Settings.Role == botToUpdate.botType.ToString());
if (firstBotOfDesiredType == null)
{
LoggingHelpers.LogToConsole($"bottype 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.min = firstBotOfDesiredType.Health.BodyParts.Head.Health.Current;
botToUpdate.health.BodyParts.Head.max = firstBotOfDesiredType.Health.BodyParts.Head.Health.Maximum; botToUpdate.health.BodyParts.Head.max = firstBotOfDesiredType.Health.BodyParts.Head.Health.Maximum;