1
This commit is contained in:
@@ -16,7 +16,7 @@ namespace BITFALL
|
||||
{
|
||||
[CustomType(typeof(IEntityInventory))]
|
||||
[CustomType(typeof(IBasicItemContainer))]
|
||||
public abstract class EntityInventory : EntityComponent, IEntityInventory
|
||||
public abstract class EntityInventory : EntityComponent, IEntityInventory,IBasicItemContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据字典
|
||||
@@ -41,20 +41,30 @@ namespace BITFALL
|
||||
public event Func<IBasicItem, bool> DropFactory;
|
||||
// 回调
|
||||
public event Action<IBasicItem> OnAdd;
|
||||
public event Action<IBasicItem> OnUsed;
|
||||
public event Action<IBasicItem> OnUsedItem;
|
||||
public event Action<IBasicItem> OnRemove;
|
||||
public event Func<IBasicItem, bool> TryUseItemFactory;
|
||||
public event Action<IBasicItem> OnSet;
|
||||
public event Action<IBasicItem> OnDrop;
|
||||
public event Action<IBasicItemContainer> OnRebuild;
|
||||
public bool UseItem(IBasicItem item)
|
||||
public bool Clear(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool TryUseItem(IBasicItem item)
|
||||
{
|
||||
if (dictionary.ContainsKey(item.Id) is false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
dictionary.Remove(item.Id);
|
||||
OnUsed?.Invoke(item);
|
||||
return true;
|
||||
return TryUseItemFactory is not null && TryUseItemFactory.CastAsFunc().Any(x => x.Invoke(item));
|
||||
}
|
||||
|
||||
public void UseItem(IBasicItem item)
|
||||
{
|
||||
OnUsedItem?.Invoke(item);
|
||||
dictionary.TryRemove(item.Id);
|
||||
}
|
||||
|
||||
[Inject]
|
||||
|
Reference in New Issue
Block a user