This commit is contained in:
CortexCore
2025-08-03 02:28:22 +08:00
parent 87007c9c24
commit 519c93d651
26 changed files with 427 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using BITKit;
using Microsoft.Extensions.Logging;
namespace Net.Project.B.Inventory
{
@@ -20,8 +21,16 @@ namespace Net.Project.B.Inventory
public class PlayerEquipmentInventory : IPlayerEquipmentInventory
{
private readonly ILogger<PlayerEquipmentInventory> _logger;
public IReadOnlyDictionary<int, IRuntimeItem> Items => _items;
private readonly ConcurrentDictionary<int, IRuntimeItem> _items = new();
public PlayerEquipmentInventory(ILogger<PlayerEquipmentInventory> logger)
{
_logger = logger;
}
public event Action<int, IRuntimeItem> OnItemAdded;
public event Action<int, IRuntimeItem> OnItemUpdated;
public event Action<int, IRuntimeItem> OnItemConsumed;
@@ -55,8 +64,18 @@ namespace Net.Project.B.Inventory
public virtual bool Consume(int slot)
{
if (_items.TryRemove(slot, out _) is false) return false;
OnItemConsumed?.Invoke(slot, null);
if (_items.TryRemove(slot, out var item) is false) return false;
try
{
OnItemConsumed?.Invoke(slot, item);
}
catch (Exception e)
{
_logger.LogCritical(e,e.Message);
}
return true;
}
}