1
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user