From c84754bd2db3f00a85ae76e2bf1edc0c9bff05f2 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sun, 26 Jan 2025 17:48:31 +0000 Subject: [PATCH] Implemented `ItemFilterService` --- Libraries/Core/Services/ItemFilterService.cs | 38 +++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Libraries/Core/Services/ItemFilterService.cs b/Libraries/Core/Services/ItemFilterService.cs index affd997e..6ad30f38 100644 --- a/Libraries/Core/Services/ItemFilterService.cs +++ b/Libraries/Core/Services/ItemFilterService.cs @@ -10,14 +10,13 @@ namespace Core.Services; public class ItemFilterService( ISptLogger _logger, ICloner _cloner, - DatabaseServer _databaseServer, ConfigServer _configServer ) { protected ItemConfig _itemConfig = _configServer.GetConfig(); - protected HashSet? _lootableItemBlacklistCache = new HashSet(); - protected HashSet? _itemBlacklistCache = new HashSet(); + protected HashSet? _lootableItemBlacklistCache = []; + protected HashSet? _itemBlacklistCache = []; /** * Check if the provided template id is blacklisted in config/item.json/blacklist @@ -26,7 +25,14 @@ public class ItemFilterService( */ public bool ItemBlacklisted(string tpl) { - throw new NotImplementedException(); + if (_itemBlacklistCache.Count == 0) + { + foreach (var item in _itemConfig.Blacklist) { + _itemBlacklistCache.Add(item); + } + } + + return _itemBlacklistCache.Contains(tpl); } /** @@ -36,7 +42,14 @@ public class ItemFilterService( */ public bool LootableItemBlacklisted(string tpl) { - throw new NotImplementedException(); + if (_lootableItemBlacklistCache.Count == 0) + { + foreach (var item in _itemConfig.LootableItemBlacklist) { + _itemBlacklistCache.Add(item); + } + } + + return _lootableItemBlacklistCache.Contains(tpl); } /** @@ -46,7 +59,7 @@ public class ItemFilterService( */ public bool ItemRewardBlacklisted(string tpl) { - throw new NotImplementedException(); + return _itemConfig.RewardItemBlacklist.Contains(tpl); } /** @@ -55,7 +68,7 @@ public class ItemFilterService( */ public List GetItemRewardBlacklist() { - throw new NotImplementedException(); + return _cloner.Clone(_itemConfig.RewardItemBlacklist).ToList(); } /** @@ -64,7 +77,7 @@ public class ItemFilterService( */ public List GetItemRewardBaseTypeBlacklist() { - throw new NotImplementedException(); + return _cloner.Clone(_itemConfig.RewardItemTypeBlacklist).ToList(); } /** @@ -73,7 +86,7 @@ public class ItemFilterService( */ public List GetBlacklistedItems() { - return _cloner.Clone(_itemConfig.Blacklist); + return _cloner.Clone(_itemConfig.Blacklist).ToList(); } /** @@ -82,7 +95,7 @@ public class ItemFilterService( */ public List GetBlacklistedLootableItems() { - throw new NotImplementedException(); + return _cloner.Clone(_itemConfig.LootableItemBlacklist).ToList(); } /** @@ -92,7 +105,7 @@ public class ItemFilterService( */ public bool BossItem(string tpl) { - throw new NotImplementedException(); + return _itemConfig.BossItems.Contains(tpl); } /** @@ -101,7 +114,8 @@ public class ItemFilterService( */ public List GetBossItems() { - throw new NotImplementedException(); + + return _cloner.Clone(_itemConfig.BossItems).ToList(); } /**