From 2d780eb791b68244f084b34d6a3505f69c50a2ee Mon Sep 17 00:00:00 2001 From: Chomp Date: Wed, 13 Aug 2025 12:41:29 +0100 Subject: [PATCH] Fixed `GetLootFromCache` filtering out valid loot items --- .../SPT_Data/configs/pmc.json | 12 ++++----- .../Services/BotLootCacheService.cs | 27 +++++++++---------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Libraries/SPTarkov.Server.Assets/SPT_Data/configs/pmc.json b/Libraries/SPTarkov.Server.Assets/SPT_Data/configs/pmc.json index 127584ea..3165a135 100644 --- a/Libraries/SPTarkov.Server.Assets/SPT_Data/configs/pmc.json +++ b/Libraries/SPTarkov.Server.Assets/SPT_Data/configs/pmc.json @@ -339,15 +339,15 @@ "max": 64, "backpack": { "min": 5000, - "max": 0 + "max": -1 }, "pocket": { "min": 5000, - "max": 0 + "max": -1 }, "vest": { "min": 5000, - "max": 0 + "max": -1 } }, { @@ -355,15 +355,15 @@ "max": 100, "backpack": { "min": 10000, - "max": 0 + "max": -1 }, "pocket": { "min": 10000, - "max": 0 + "max": -1 }, "vest": { "min": 10000, - "max": 0 + "max": -1 } } ], diff --git a/Libraries/SPTarkov.Server.Core/Services/BotLootCacheService.cs b/Libraries/SPTarkov.Server.Core/Services/BotLootCacheService.cs index 0b00cb3a..2e4f2b22 100644 --- a/Libraries/SPTarkov.Server.Core/Services/BotLootCacheService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/BotLootCacheService.cs @@ -1,5 +1,6 @@ using System.Collections.Concurrent; using SPTarkov.DI.Annotations; +using SPTarkov.Server.Core.Extensions; using SPTarkov.Server.Core.Generators; using SPTarkov.Server.Core.Helpers; using SPTarkov.Server.Core.Models.Common; @@ -133,30 +134,26 @@ public class BotLootCacheService( if (itemPriceMinMax is null) { - // No filtering requested, exit + // No filtering requested, return all results return cloner.Clone(result); } - // Filter the loot pool prior to returning + // Filter the loot pool by item value prior to returning var filteredResult = result.Where(i => { var itemPrice = itemHelper.GetItemPrice(i.Key); - if (itemPriceMinMax?.Min is not null && itemPriceMinMax?.Max is not null) + + var priceLimitMin = itemPriceMinMax.Min; + var priceLimitMax = itemPriceMinMax.Max; + + // Treat -1 as no limit + if (priceLimitMax.Approx(-1)) { - return itemPrice >= itemPriceMinMax?.Min && itemPrice <= itemPriceMinMax?.Max; + // only check min limit value + return itemPrice >= priceLimitMin; } - if (itemPriceMinMax?.Min is not null && itemPriceMinMax?.Max is null) - { - return itemPrice >= itemPriceMinMax?.Min; - } - - if (itemPriceMinMax?.Min is null && itemPriceMinMax?.Max is not null) - { - return itemPrice <= itemPriceMinMax?.Max; - } - - return false; + return itemPrice >= priceLimitMin && itemPrice <= priceLimitMax; }); return cloner.Clone(filteredResult.ToDictionary(pair => pair.Key, pair => pair.Value));