diff --git a/Libraries/SPTarkov.Server.Core/Services/BotLootCacheService.cs b/Libraries/SPTarkov.Server.Core/Services/BotLootCacheService.cs index 24c9ff60..6e1059f0 100644 --- a/Libraries/SPTarkov.Server.Core/Services/BotLootCacheService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/BotLootCacheService.cs @@ -227,12 +227,9 @@ public class BotLootCacheService( } // Assign whitelisted special items to bot if any exist - var specialLootItems = - botJsonTemplate.BotGeneration?.Items?.SpecialItems?.Whitelist?.Count > 0 - ? botJsonTemplate.BotGeneration?.Items?.SpecialItems?.Whitelist - : new Dictionary(); + var specialLootItems = GetGenerationWeights(botJsonTemplate.BotGeneration?.Items?.SpecialItems?.Whitelist); - // no whitelist, find and assign from combined item pool + // No whitelist, find and assign from combined item pool if (!specialLootItems.Any()) // key = tpl, value = weight { @@ -247,10 +244,7 @@ public class BotLootCacheService( } // Assign whitelisted healing items to bot if any exist - var healingItems = - botJsonTemplate.BotGeneration?.Items?.Healing?.Whitelist?.Count > 0 - ? botJsonTemplate.BotGeneration?.Items?.Healing?.Whitelist - : new Dictionary(); + var healingItems = GetGenerationWeights(botJsonTemplate.BotGeneration?.Items?.Healing?.Whitelist); // No whitelist, find and assign from combined item pool if (!healingItems.Any()) @@ -271,7 +265,8 @@ public class BotLootCacheService( } // Assign whitelisted drugs to bot if any exist - var drugItems = botJsonTemplate.BotGeneration?.Items?.Drugs?.Whitelist ?? new Dictionary(); + var drugItems = GetGenerationWeights(botJsonTemplate.BotGeneration?.Items?.Drugs?.Whitelist); + // no drugs whitelist, find and assign from combined item pool if (!drugItems.Any()) { @@ -292,7 +287,7 @@ public class BotLootCacheService( } // Assign whitelisted food to bot if any exist - var foodItems = botJsonTemplate.BotGeneration?.Items?.Food?.Whitelist ?? new Dictionary(); + var foodItems = GetGenerationWeights(botJsonTemplate.BotGeneration?.Items?.Food?.Whitelist); // No food whitelist, find and assign from combined item pool if (!foodItems.Any()) { @@ -313,7 +308,8 @@ public class BotLootCacheService( } // Assign whitelisted drink to bot if any exist - var drinkItems = botJsonTemplate.BotGeneration?.Items?.Food?.Whitelist ?? new Dictionary(); + var drinkItems = GetGenerationWeights(botJsonTemplate.BotGeneration?.Items?.Food?.Whitelist); + // No drink whitelist, find and assign from combined item pool if (!drinkItems.Any()) { @@ -334,7 +330,8 @@ public class BotLootCacheService( } // Assign whitelisted currency to bot if any exist - var currencyItems = botJsonTemplate.BotGeneration?.Items?.Currency?.Whitelist ?? new Dictionary(); + var currencyItems = GetGenerationWeights(botJsonTemplate.BotGeneration?.Items?.Currency?.Whitelist); + // No currency whitelist, find and assign from combined item pool if (!currencyItems.Any()) { @@ -354,7 +351,7 @@ public class BotLootCacheService( } // Assign whitelisted stims to bot if any exist - var stimItems = botJsonTemplate.BotGeneration?.Items?.Stims?.Whitelist ?? new Dictionary(); + var stimItems = GetGenerationWeights(botJsonTemplate.BotGeneration?.Items?.Stims?.Whitelist); // No whitelist, find and assign from combined item pool if (!stimItems.Any()) { @@ -374,7 +371,7 @@ public class BotLootCacheService( } // Assign whitelisted grenades to bot if any exist - var grenadeItems = botJsonTemplate.BotGeneration?.Items?.Grenades?.Whitelist ?? new Dictionary(); + var grenadeItems = GetGenerationWeights(botJsonTemplate.BotGeneration?.Items?.Grenades?.Whitelist); // no whitelist, find and assign from combined item pool if (!grenadeItems.Any()) { @@ -511,6 +508,16 @@ public class BotLootCacheService( cacheForRole.SecureLoot = filteredSecureLoot; } + /// + /// Return provided weights or an empty dictionary + /// + /// Weights to return + /// Dictionary + protected static Dictionary GetGenerationWeights(Dictionary? weights) + { + return weights ?? []; + } + protected void AddItemsToPool(Dictionary poolToAddTo, Dictionary poolOfItemsToAdd) { foreach (var tpl in poolOfItemsToAdd) @@ -627,7 +634,7 @@ public class BotLootCacheService( } /// - /// Compares two item prices by their flea (or handbook if that doesnt exist) price + /// Compares two item prices by their flea (or handbook if that doesn't exist) price /// /// ///