forked from PGR/ascnet
1
0
Fork 0

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,11 +76,24 @@ 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)
{
if (itemTable.MaxCount <= item.Count + amount && item.Count + amount >= 0)
{ {
item.Count += amount; item.Count += amount;
item.RefreshTime = DateTimeOffset.Now.ToUnixTimeSeconds(); 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
{ {
item = new Item() item = new Item()