This commit is contained in:
CortexCore
2025-08-05 23:34:30 +08:00
parent 519c93d651
commit dbc223be46
14 changed files with 156 additions and 5 deletions

View File

@@ -22,13 +22,15 @@ namespace Net.Project.B.Inventory
public class PlayerEquipmentInventory : IPlayerEquipmentInventory
{
private readonly ILogger<PlayerEquipmentInventory> _logger;
private readonly IPlayerInventory _playerInventory;
public IReadOnlyDictionary<int, IRuntimeItem> Items => _items;
private readonly ConcurrentDictionary<int, IRuntimeItem> _items = new();
public PlayerEquipmentInventory(ILogger<PlayerEquipmentInventory> logger)
public PlayerEquipmentInventory(ILogger<PlayerEquipmentInventory> logger, IPlayerInventory playerInventory)
{
_logger = logger;
_playerInventory = playerInventory;
}
public event Action<int, IRuntimeItem> OnItemAdded;
@@ -69,12 +71,23 @@ namespace Net.Project.B.Inventory
try
{
OnItemConsumed?.Invoke(slot, item);
foreach (var (id, runtimeItem) in _playerInventory.Container.ItemDictionary)
{
if (runtimeItem.ScriptableId != item.ScriptableId) continue;
if (!_playerInventory.Container.Remove(id)) continue;
if (AddOrUpdate(slot, item))
{
break;
}
throw new InvalidOperationException("内部错误,无法从背包补充物品");
}
}
catch (Exception e)
{
_logger.LogCritical(e,e.Message);
}
return true;
}