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