From 065b073f48aef55fad496190f2884c958a1b8663 Mon Sep 17 00:00:00 2001 From: CWX Date: Thu, 30 Jan 2025 09:37:01 +0000 Subject: [PATCH] HashSet is created on ctor, no need to recreate, change check to check count not null as its never null --- Libraries/Core/Services/FenceService.cs | 4 ++-- Libraries/Core/Services/ItemFilterService.cs | 23 ++------------------ 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/Libraries/Core/Services/FenceService.cs b/Libraries/Core/Services/FenceService.cs index 3317c832..23cb74e7 100644 --- a/Libraries/Core/Services/FenceService.cs +++ b/Libraries/Core/Services/FenceService.cs @@ -266,12 +266,12 @@ public class FenceService( // Is preset if (item.Upd?.SptPresetId != null) { - if (assort.BarterScheme?[item.Id] != null) + if (assort.BarterScheme?.ContainsKey(item.Id) ?? false) { assort.BarterScheme[item.Id][0][0].Count *= presetModifier; } } - else if (assort.BarterScheme?[item.Id] != null) + else if (assort.BarterScheme?.ContainsKey(item.Id) ?? false) { assort.BarterScheme[item.Id][0][0].Count *= modifier; } diff --git a/Libraries/Core/Services/ItemFilterService.cs b/Libraries/Core/Services/ItemFilterService.cs index 6ad30f38..7d8d9722 100644 --- a/Libraries/Core/Services/ItemFilterService.cs +++ b/Libraries/Core/Services/ItemFilterService.cs @@ -35,23 +35,6 @@ public class ItemFilterService( return _itemBlacklistCache.Contains(tpl); } - /** - * Check if the provided template id is blacklisted in config/item.json/lootableItemBlacklist - * @param tpl template id - * @returns true if blacklisted - */ - public bool LootableItemBlacklisted(string tpl) - { - if (_lootableItemBlacklistCache.Count == 0) - { - foreach (var item in _itemConfig.LootableItemBlacklist) { - _itemBlacklistCache.Add(item); - } - } - - return _lootableItemBlacklistCache.Contains(tpl); - } - /** * Check if item is blacklisted from being a reward for player * @param tpl item tpl to check is on blacklist @@ -125,7 +108,7 @@ public class ItemFilterService( */ public bool IsLootableItemBlacklisted(string itemKey) { - if (_lootableItemBlacklistCache is null) + if (!_lootableItemBlacklistCache.Any()) { HydrateLootableItemBlacklist(); } @@ -135,7 +118,7 @@ public class ItemFilterService( public bool IsItemBlacklisted(string tpl) { - if (_itemBlacklistCache is null) + if (!_itemBlacklistCache.Any()) { HydrateBlacklist(); } @@ -145,7 +128,6 @@ public class ItemFilterService( protected void HydrateLootableItemBlacklist() { - _lootableItemBlacklistCache = []; foreach (var item in _itemConfig.LootableItemBlacklist) { _lootableItemBlacklistCache.Add(item); @@ -154,7 +136,6 @@ public class ItemFilterService( protected void HydrateBlacklist() { - _itemBlacklistCache = []; foreach (var item in _itemConfig.Blacklist) { _itemBlacklistCache.Add(item); }