might or might not fix negative item issue

This commit is contained in:
rfi 2024-01-16 14:56:25 +07:00
parent 9fe8270817
commit 0e36d06214
1 changed files with 16 additions and 3 deletions

View File

@ -76,10 +76,23 @@ namespace AscNet.Common.Database
Item? item = Items.FirstOrDefault(x => x.Id == itemId); Item? item = Items.FirstOrDefault(x => x.Id == itemId);
ItemTable? itemTable = TableReaderV2.Parse<ItemTable>().Find(x => x.Id == itemId); ItemTable? itemTable = TableReaderV2.Parse<ItemTable>().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; if (itemTable.MaxCount <= item.Count + amount && item.Count + amount >= 0)
item.RefreshTime = DateTimeOffset.Now.ToUnixTimeSeconds(); {
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 else
{ {