From 0e36d062140b6ab18c4ce8fb553a8e5c9d8e36e5 Mon Sep 17 00:00:00 2001 From: rfi Date: Tue, 16 Jan 2024 14:56:25 +0700 Subject: [PATCH] might or might not fix negative item issue --- AscNet.Common/Database/Inventory.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/AscNet.Common/Database/Inventory.cs b/AscNet.Common/Database/Inventory.cs index 5fe346a3..8d4b5a53 100644 --- a/AscNet.Common/Database/Inventory.cs +++ b/AscNet.Common/Database/Inventory.cs @@ -76,10 +76,23 @@ namespace AscNet.Common.Database Item? item = Items.FirstOrDefault(x => x.Id == itemId); ItemTable? itemTable = TableReaderV2.Parse().Find(x => x.Id == itemId); - if (item is not null && itemTable is not null && itemTable.MaxCount <= item.Count + amount) + if (item is not null && itemTable is not null) { - item.Count += amount; - item.RefreshTime = DateTimeOffset.Now.ToUnixTimeSeconds(); + if (itemTable.MaxCount <= item.Count + amount && item.Count + amount >= 0) + { + item.Count += amount; + item.RefreshTime = DateTimeOffset.Now.ToUnixTimeSeconds(); + } + else if (itemTable.MaxCount <= item.Count + amount) + { + item.Count = itemTable.MaxCount ?? item.Count + amount; + item.RefreshTime = DateTimeOffset.Now.ToUnixTimeSeconds(); + } + else + { + item.Count = 0; + item.RefreshTime = DateTimeOffset.Now.ToUnixTimeSeconds(); + } } else {