This commit is contained in:
CortexCore
2024-11-08 17:28:07 +08:00
parent 1650126d55
commit faf72b05e9
14 changed files with 196 additions and 379 deletions

View File

@@ -7,6 +7,7 @@ using Microsoft.SqlServer.Server;
namespace BITKit
{
/// <summary>
/// 支持二进制化的的物品容器,适用于网络化物品容器
/// 支持属性
@@ -74,7 +75,7 @@ namespace BITKit
public class RuntimeItemContainer : IRuntimeItemContainer
{
private readonly ConcurrentDictionary<int, IRuntimeItem> _items = new();
public readonly ConcurrentDictionary<int, IRuntimeItem> Items = new();
public void Read(BinaryReader r)
{
throw new NotImplementedException();
@@ -86,7 +87,7 @@ namespace BITKit
}
public int Id { get; set; }
public IRuntimeItem[] GetItems()=>_items.Values.ToArray();
public IRuntimeItem[] GetItems()=>Items.Values.ToArray();
public bool Add(IRuntimeItem item)
{
@@ -98,17 +99,17 @@ namespace BITKit
}
}
_items.Set(item.Id,item);
Items.Set(item.Id, item);
OnAdd?.Invoke(item);
//BIT4Log.Log<RuntimeItemContainer>($"添加了了:{item.Id}");
return true;
}
public bool Remove(int id)
{
if (_items.TryGetValue(id, out var item) is false) return false;
if (Items.TryGetValue(id, out var item) is false) return false;
foreach (var func in RemoveFactory.CastAsFunc())
{
@@ -117,7 +118,7 @@ namespace BITKit
return false;
}
}
_items.TryRemove(item.Id);
Items.TryRemove(item.Id);
OnRemove?.Invoke(item);
//BIT4Log.Log<RuntimeItemContainer>($"移除了:{id}");
return true;
@@ -125,8 +126,7 @@ namespace BITKit
public bool Drop(int id)
{
if (_items.TryGetValue(id, out var item) is false) return false;
if (Items.TryGetValue(id, out var item) is false) return false;
foreach (var func in DropFactory.CastAsFunc())
{
if (func.Invoke(item) is false)
@@ -134,7 +134,7 @@ namespace BITKit
return false;
}
}
_items.TryRemove(item.Id);
Items.TryRemove(item.Id);
OnDrop?.Invoke(item);
//BIT4Log.Log<RuntimeItemContainer>($"丢下了:{id}");
return true;

13
Src/Core/Item/ItemEx.cs Normal file
View File

@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
namespace BITKit
{
/// <summary>
/// 玩家向背包添加物品,但是被其他逻辑处理
/// </summary>
public sealed class PlayerInventoryAddItemOverridden : InGameException
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ebeadaca27f99904a87e52f3f63042f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: