diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotEquipmentModGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotEquipmentModGenerator.cs index 34fe472b..02291009 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/BotEquipmentModGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/BotEquipmentModGenerator.cs @@ -197,7 +197,8 @@ public class BotEquipmentModGenerator( ); switch (plateSlotFilteringOutcome.Result) { - case Result.UNKNOWN_FAILURE or Result.NO_DEFAULT_FILTER: + case Result.UNKNOWN_FAILURE + or Result.NO_DEFAULT_FILTER: if (logger.IsLogEnabled(LogLevel.Debug)) { logger.Debug( @@ -1910,7 +1911,8 @@ public class BotEquipmentModGenerator( } // Get item blacklist and mod equipment blacklist as one Set - var blacklist = itemFilterService.GetBlacklistedItems(); + var blacklist = new HashSet(); + blacklist.UnionWith(itemFilterService.GetBlacklistedItems()); if ( botEquipBlacklist?.Equipment is not null && botEquipBlacklist.Equipment.TryGetValue(modSlot, out var equipmentBlacklistValues) diff --git a/Libraries/SPTarkov.Server.Core/Services/ItemFilterService.cs b/Libraries/SPTarkov.Server.Core/Services/ItemFilterService.cs index de2e26ab..9a690fbb 100644 --- a/Libraries/SPTarkov.Server.Core/Services/ItemFilterService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/ItemFilterService.cs @@ -3,7 +3,6 @@ using SPTarkov.Server.Core.Models.Common; using SPTarkov.Server.Core.Models.Spt.Config; using SPTarkov.Server.Core.Models.Utils; using SPTarkov.Server.Core.Servers; -using SPTarkov.Server.Core.Utils.Cloners; namespace SPTarkov.Server.Core.Services; @@ -11,25 +10,94 @@ namespace SPTarkov.Server.Core.Services; /// Centralise the handling of blacklisting items, uses blacklist found in config/item.json, stores items that should not be used by players / broken items /// [Injectable(InjectionType.Singleton)] -public class ItemFilterService( - ISptLogger logger, - ICloner cloner, - ConfigServer configServer -) +public class ItemFilterService(ISptLogger logger, ConfigServer configServer) { - protected readonly HashSet? _itemBlacklistCache = []; protected readonly ItemConfig _itemConfig = configServer.GetConfig(); + protected readonly HashSet? _itemBlacklistCache = []; protected readonly HashSet? _lootableItemBlacklistCache = []; /// - /// Check if the provided template id is blacklisted in config/item.json/blacklist + /// Get an HashSet of items that should never be given as a reward to player /// - /// Template id - /// True if blacklisted - public bool ItemBlacklisted(MongoId tpl) + /// HashSet of item tpls + public HashSet GetItemRewardBlacklist() { - if (_itemBlacklistCache.Count == 0) + return _itemConfig.RewardItemBlacklist; + } + + /// + /// Get an HashSet of item types that should never be given as a reward to player + /// + /// HashSet of item base ids + public HashSet GetItemRewardBaseTypeBlacklist() + { + return _itemConfig.RewardItemTypeBlacklist; + } + + /// + /// Return every template id blacklisted in config/item.json + /// + /// HashSet of blacklisted template ids + public HashSet GetBlacklistedItems() + { + return _itemConfig.Blacklist; + } + + /// + /// Return every template id blacklisted in config/item.json/lootableItemBlacklist + /// + /// HashSet of blacklisted template ids + public HashSet GetBlacklistedLootableItems() + { + return _itemConfig.LootableItemBlacklist; + } + + /// + /// Return boss items in config/item.json + /// + /// HashSet of boss item template ids + public HashSet GetBossItems() + { + return _itemConfig.BossItems; + } + + /// + /// Add MongoIds to the global lootable item blacklist cache + /// + /// Tpls to blacklist + public void AddItemToLootableBlacklistCache(IEnumerable itemTplsToBlacklist) + { + _lootableItemBlacklistCache.UnionWith(itemTplsToBlacklist); + } + + /// + /// Check if the provided template id is blacklisted in config/item.json/lootableItemBlacklist + /// + /// Template id + /// True if blacklisted + public bool IsLootableItemBlacklisted(MongoId itemKey) + { + if (!_lootableItemBlacklistCache.Any()) + { + _lootableItemBlacklistCache.UnionWith(_itemConfig.LootableItemBlacklist); + } + + return _lootableItemBlacklistCache.Contains(itemKey); + } + + /// + /// Add MongoIds to the global blacklist cache + /// + /// Tpls to blacklist + public void AddItemToBlacklistCache(IEnumerable itemTplsToBlacklist) + { + _itemBlacklistCache.UnionWith(itemTplsToBlacklist); + } + + public bool IsItemBlacklisted(MongoId tpl) + { + if (!_itemBlacklistCache.Any()) { _itemBlacklistCache.UnionWith(_itemConfig.Blacklist); } @@ -37,117 +105,11 @@ public class ItemFilterService( return _itemBlacklistCache.Contains(tpl); } - /// - /// Check if item is blacklisted from being a reward for player - /// - /// Item tpl to check is on blacklist - /// True when blacklisted - public bool ItemRewardBlacklisted(MongoId tpl) - { - return _itemConfig.RewardItemBlacklist.Contains(tpl); - } - - /// - /// Get an HashSet of items that should never be given as a reward to player - /// - /// HashSet of item tpls - public HashSet GetItemRewardBlacklist() - { - return cloner.Clone(_itemConfig.RewardItemBlacklist); - } - - /// - /// Get an HashSet of item types that should never be given as a reward to player - /// - /// HashSet of item base ids - public HashSet GetItemRewardBaseTypeBlacklist() - { - return cloner.Clone(_itemConfig.RewardItemTypeBlacklist); - } - - /// - /// Return every template id blacklisted in config/item.json - /// - /// HashSet of blacklisted template ids - public HashSet GetBlacklistedItems() - { - return cloner.Clone(_itemConfig.Blacklist); - } - - /// - /// Return every template id blacklisted in config/item.json/lootableItemBlacklist - /// - /// HashSet of blacklisted template ids - public HashSet GetBlacklistedLootableItems() - { - return cloner.Clone(_itemConfig.LootableItemBlacklist); - } - - /// - /// Check if the provided template id is boss item in config/item.json - /// - /// template id - /// True if boss item - public bool BossItem(MongoId tpl) - { - return _itemConfig.BossItems.Contains(tpl); - } - - /// - /// Return boss items in config/item.json - /// - /// HashSet of boss item template ids - public HashSet GetBossItems() - { - return cloner.Clone(_itemConfig.BossItems).ToHashSet(); - } - - /// - /// Check if the provided template id is blacklisted in config/item.json/lootableItemBlacklist - /// - /// Template id - /// True if blacklisted - public bool IsLootableItemBlacklisted(MongoId itemKey) - { - if (!_lootableItemBlacklistCache.Any()) - { - HydrateLootableItemBlacklist(); - } - - return _lootableItemBlacklistCache.Contains(itemKey); - } - - public bool IsItemBlacklisted(MongoId tpl) - { - if (!_itemBlacklistCache.Any()) - { - HydrateBlacklist(); - } - - return _itemBlacklistCache.Contains(tpl); - } - - protected void HydrateLootableItemBlacklist() - { - foreach (var item in _itemConfig.LootableItemBlacklist) - { - _lootableItemBlacklistCache.Add(item); - } - } - - protected void HydrateBlacklist() - { - foreach (var item in _itemConfig.Blacklist) - { - _itemBlacklistCache.Add(item); - } - } - /// /// Check if the provided template id is boss item in config/item.json /// /// Template id - /// True if boss item + /// True if boss item public bool IsBossItem(MongoId tpl) { return _itemConfig.BossItems.Contains(tpl); @@ -157,7 +119,7 @@ public class ItemFilterService( /// Check if item is blacklisted from being a reward for player /// /// Item tpl to check is on blacklist - /// true when blacklisted + /// true when blacklisted public bool IsItemRewardBlacklisted(MongoId tpl) { return _itemConfig.RewardItemBlacklist.Contains(tpl);