From b9e6cdd49e814b210b36a540eeda94bcf1bb5438 Mon Sep 17 00:00:00 2001 From: Chomp Date: Thu, 12 Aug 2021 22:17:40 +0100 Subject: [PATCH] null guard when bot type cant be found. Log error. --- Generator/BaseBotGenerator.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Generator/BaseBotGenerator.cs b/Generator/BaseBotGenerator.cs index b278b2e..b069a57 100644 --- a/Generator/BaseBotGenerator.cs +++ b/Generator/BaseBotGenerator.cs @@ -73,10 +73,7 @@ namespace Generator private void AddDifficulties(Bot bot, List rawParsedBots) { - var botType = bot.botType; - var firstBotOfDesiredType = rawParsedBots.First(x => x.Info.Settings.Role == botType.ToString()); - - switch (botType) + switch (bot.botType) { case BotType.assault: DifficultyHelper.AddAssaultDifficulties(bot); @@ -92,7 +89,13 @@ namespace Generator private void UpdateBodyPartHealth(Bot botToUpdate, List 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.max = firstBotOfDesiredType.Health.BodyParts.Head.Health.Maximum;