Cleaned up ItemFilterService:
Removed dupe methods Removed use of clone Added `AddItemToBlacklistCache` and `AddItemToLootableBlacklistCache`
This commit is contained in:
@@ -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<MongoId>();
|
||||
blacklist.UnionWith(itemFilterService.GetBlacklistedItems());
|
||||
if (
|
||||
botEquipBlacklist?.Equipment is not null
|
||||
&& botEquipBlacklist.Equipment.TryGetValue(modSlot, out var equipmentBlacklistValues)
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class ItemFilterService(
|
||||
ISptLogger<ItemFilterService> logger,
|
||||
ICloner cloner,
|
||||
ConfigServer configServer
|
||||
)
|
||||
public class ItemFilterService(ISptLogger<ItemFilterService> logger, ConfigServer configServer)
|
||||
{
|
||||
protected readonly HashSet<MongoId>? _itemBlacklistCache = [];
|
||||
protected readonly ItemConfig _itemConfig = configServer.GetConfig<ItemConfig>();
|
||||
|
||||
protected readonly HashSet<MongoId>? _itemBlacklistCache = [];
|
||||
protected readonly HashSet<MongoId>? _lootableItemBlacklistCache = [];
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <param name="tpl"> Template id</param>
|
||||
/// <returns> True if blacklisted </returns>
|
||||
public bool ItemBlacklisted(MongoId tpl)
|
||||
/// <returns>HashSet of item tpls</returns>
|
||||
public HashSet<MongoId> GetItemRewardBlacklist()
|
||||
{
|
||||
if (_itemBlacklistCache.Count == 0)
|
||||
return _itemConfig.RewardItemBlacklist;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get an HashSet of item types that should never be given as a reward to player
|
||||
/// </summary>
|
||||
/// <returns>HashSet of item base ids</returns>
|
||||
public HashSet<MongoId> GetItemRewardBaseTypeBlacklist()
|
||||
{
|
||||
return _itemConfig.RewardItemTypeBlacklist;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return every template id blacklisted in config/item.json
|
||||
/// </summary>
|
||||
/// <returns>HashSet of blacklisted template ids</returns>
|
||||
public HashSet<MongoId> GetBlacklistedItems()
|
||||
{
|
||||
return _itemConfig.Blacklist;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return every template id blacklisted in config/item.json/lootableItemBlacklist
|
||||
/// </summary>
|
||||
/// <returns>HashSet of blacklisted template ids</returns>
|
||||
public HashSet<MongoId> GetBlacklistedLootableItems()
|
||||
{
|
||||
return _itemConfig.LootableItemBlacklist;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return boss items in config/item.json
|
||||
/// </summary>
|
||||
/// <returns>HashSet of boss item template ids</returns>
|
||||
public HashSet<MongoId> GetBossItems()
|
||||
{
|
||||
return _itemConfig.BossItems;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add MongoIds to the global lootable item blacklist cache
|
||||
/// </summary>
|
||||
/// <param name="itemTplsToBlacklist">Tpls to blacklist</param>
|
||||
public void AddItemToLootableBlacklistCache(IEnumerable<MongoId> itemTplsToBlacklist)
|
||||
{
|
||||
_lootableItemBlacklistCache.UnionWith(itemTplsToBlacklist);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the provided template id is blacklisted in config/item.json/lootableItemBlacklist
|
||||
/// </summary>
|
||||
/// <param name="itemKey"> Template id</param>
|
||||
/// <returns>True if blacklisted</returns>
|
||||
public bool IsLootableItemBlacklisted(MongoId itemKey)
|
||||
{
|
||||
if (!_lootableItemBlacklistCache.Any())
|
||||
{
|
||||
_lootableItemBlacklistCache.UnionWith(_itemConfig.LootableItemBlacklist);
|
||||
}
|
||||
|
||||
return _lootableItemBlacklistCache.Contains(itemKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add MongoIds to the global blacklist cache
|
||||
/// </summary>
|
||||
/// <param name="itemTplsToBlacklist">Tpls to blacklist</param>
|
||||
public void AddItemToBlacklistCache(IEnumerable<MongoId> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if item is blacklisted from being a reward for player
|
||||
/// </summary>
|
||||
/// <param name="tpl"> Item tpl to check is on blacklist </param>
|
||||
/// <returns> True when blacklisted </returns>
|
||||
public bool ItemRewardBlacklisted(MongoId tpl)
|
||||
{
|
||||
return _itemConfig.RewardItemBlacklist.Contains(tpl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get an HashSet of items that should never be given as a reward to player
|
||||
/// </summary>
|
||||
/// <returns> HashSet of item tpls </returns>
|
||||
public HashSet<MongoId> GetItemRewardBlacklist()
|
||||
{
|
||||
return cloner.Clone(_itemConfig.RewardItemBlacklist);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get an HashSet of item types that should never be given as a reward to player
|
||||
/// </summary>
|
||||
/// <returns> HashSet of item base ids </returns>
|
||||
public HashSet<MongoId> GetItemRewardBaseTypeBlacklist()
|
||||
{
|
||||
return cloner.Clone(_itemConfig.RewardItemTypeBlacklist);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return every template id blacklisted in config/item.json
|
||||
/// </summary>
|
||||
/// <returns> HashSet of blacklisted template ids </returns>
|
||||
public HashSet<MongoId> GetBlacklistedItems()
|
||||
{
|
||||
return cloner.Clone(_itemConfig.Blacklist);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return every template id blacklisted in config/item.json/lootableItemBlacklist
|
||||
/// </summary>
|
||||
/// <returns> HashSet of blacklisted template ids </returns>
|
||||
public HashSet<MongoId> GetBlacklistedLootableItems()
|
||||
{
|
||||
return cloner.Clone(_itemConfig.LootableItemBlacklist);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the provided template id is boss item in config/item.json
|
||||
/// </summary>
|
||||
/// <param name="tpl"> template id </param>
|
||||
/// <returns> True if boss item </returns>
|
||||
public bool BossItem(MongoId tpl)
|
||||
{
|
||||
return _itemConfig.BossItems.Contains(tpl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return boss items in config/item.json
|
||||
/// </summary>
|
||||
/// <returns> HashSet of boss item template ids </returns>
|
||||
public HashSet<MongoId> GetBossItems()
|
||||
{
|
||||
return cloner.Clone(_itemConfig.BossItems).ToHashSet();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the provided template id is blacklisted in config/item.json/lootableItemBlacklist
|
||||
/// </summary>
|
||||
/// <param name="itemKey"> Template id</param>
|
||||
/// <returns> True if blacklisted </returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the provided template id is boss item in config/item.json
|
||||
/// </summary>
|
||||
/// <param name="tpl"> Template id</param>
|
||||
/// <returns> True if boss item </returns>
|
||||
/// <returns>True if boss item</returns>
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="tpl"> Item tpl to check is on blacklist </param>
|
||||
/// <returns> true when blacklisted </returns>
|
||||
/// <returns>true when blacklisted</returns>
|
||||
public bool IsItemRewardBlacklisted(MongoId tpl)
|
||||
{
|
||||
return _itemConfig.RewardItemBlacklist.Contains(tpl);
|
||||
|
||||
Reference in New Issue
Block a user