1
This commit is contained in:
@@ -1,155 +1,161 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
#region 物品枚举
|
||||
|
||||
public enum ItemQuality
|
||||
{
|
||||
/// <summary>
|
||||
/// 常见的
|
||||
/// </summary>
|
||||
Common,
|
||||
|
||||
/// <summary>
|
||||
/// 罕见的
|
||||
/// </summary>
|
||||
Uncommon,
|
||||
|
||||
/// <summary>
|
||||
/// 稀有的
|
||||
/// </summary>
|
||||
Rare,
|
||||
|
||||
/// <summary>
|
||||
/// 史诗的
|
||||
/// </summary>
|
||||
Epic,
|
||||
|
||||
/// <summary>
|
||||
/// 传奇的
|
||||
/// </summary>
|
||||
Legendary,
|
||||
|
||||
/// <summary>
|
||||
/// 神话的
|
||||
/// </summary>
|
||||
Mythical,
|
||||
|
||||
/// <summary>
|
||||
/// 开发者
|
||||
/// </summary>
|
||||
Develop,
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 物品接口
|
||||
|
||||
/// <summary>
|
||||
/// 物品属性
|
||||
/// </summary>
|
||||
public interface IScriptableItemProperty
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 基础物品
|
||||
/// </summary>
|
||||
public interface IBasicItem :IPropertable,ICloneable
|
||||
public interface IScriptableItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一Id
|
||||
/// </summary>
|
||||
int Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 物品名,一般用于查找物品的主键
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
// /// <summary>
|
||||
// /// 可寻址路径,该路径用于查找物品
|
||||
// /// </summary>
|
||||
// string AddressablePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 物品描述
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大堆叠数量
|
||||
/// </summary>
|
||||
public int MaxStack { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 物品品质
|
||||
/// </summary>
|
||||
ItemQuality Quality { get; }
|
||||
bool CopyItemsFrom(IBasicItem item);
|
||||
|
||||
/// <summary>
|
||||
/// 属性
|
||||
/// </summary>
|
||||
IReadOnlyDictionary<Type, IScriptableItemProperty> Properties { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 价值
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
int Value=>10;
|
||||
int Value => 10;
|
||||
}
|
||||
/// <summary>
|
||||
/// 可配置化物品,通常用于配置
|
||||
/// </summary>
|
||||
public interface IAssetableItem: IBasicItem
|
||||
|
||||
public interface IRuntimeItem : ICloneable
|
||||
{
|
||||
/// <summary>
|
||||
/// 运行时Id
|
||||
/// </summary>
|
||||
public int Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 配置Id
|
||||
/// </summary>
|
||||
public int ScriptableId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 数量
|
||||
/// </summary>
|
||||
public int Amount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 运行时属性
|
||||
/// </summary>
|
||||
IDictionary<Type, IScriptableItemProperty> RuntimeProperties { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当运行时属性改变时
|
||||
/// </summary>
|
||||
// ReSharper disable once EventNeverInvoked.Global
|
||||
event Action<IRuntimeItem> OnRuntimePropertiesChanged;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 物品实现
|
||||
|
||||
/// <summary>
|
||||
/// 被托管的物品
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ManagedItem : IBasicItem
|
||||
public record RuntimeItem : IRuntimeItem
|
||||
{
|
||||
#region 字段
|
||||
public int Id;
|
||||
public string Name;
|
||||
public string AddressablePath { get; set; }
|
||||
public string Description;
|
||||
public ItemQuality Quality;
|
||||
public int Value { get; set; }
|
||||
/// <summary>
|
||||
/// 本地属性
|
||||
/// </summary>
|
||||
private Property property = new();
|
||||
#endregion
|
||||
#region 接口的隐式实现
|
||||
int IBasicItem.Id => Id;
|
||||
string IBasicItem.Name => Name;
|
||||
string IBasicItem.Description => Description;
|
||||
ItemQuality IBasicItem.Quality => Quality;
|
||||
#endregion
|
||||
#region 接口的显式实现
|
||||
public bool Contains<T>() => property.Contains<T>();
|
||||
public int Id { get; set; } = new Random().Next();
|
||||
public int ScriptableId { get; set; }
|
||||
public int Amount { get; set; }
|
||||
|
||||
public T GetOrAddProperty<T>(Func<T> addFactory) => property.GetOrAddProperty<T>(addFactory);
|
||||
public IDictionary<Type, IScriptableItemProperty> RuntimeProperties { get; set; } =
|
||||
new Dictionary<Type, IScriptableItemProperty>();
|
||||
|
||||
public T GetOrCreateProperty<T>() => property.GetOrCreateProperty<T>();
|
||||
public event Action<IRuntimeItem> OnRuntimePropertiesChanged;
|
||||
|
||||
public object[] GetProperties() => property.GetProperties();
|
||||
|
||||
public bool TryGetProperty<T>(out T value) => property.TryGetProperty<T>(out value);
|
||||
|
||||
public bool TryRemoveProperty<T>() => property.TryRemoveProperty<T>();
|
||||
|
||||
public bool TrySetProperty<T>(T value) => property.TrySetProperty(value);
|
||||
|
||||
public void Read(BinaryReader r)
|
||||
object ICloneable.Clone()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Write(BinaryWriter w)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool CopyItemsFrom(IBasicItem item)
|
||||
{
|
||||
Value = item.Value;
|
||||
Id=item.Id;
|
||||
Name = item.Name;
|
||||
//AddressablePath = item.AddressablePath;
|
||||
Description = item.Description;
|
||||
Quality=item.Quality;
|
||||
CopyPropertiesFrom(item);
|
||||
return true;
|
||||
}
|
||||
public bool ClearProperties()=>property.ClearProperties();
|
||||
public bool CopyPropertiesFrom(IPropertable propertable)
|
||||
{
|
||||
return property.CopyPropertiesFrom(propertable);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
var item = MemberwiseClone() as ManagedItem;
|
||||
item!.Id = Id;
|
||||
return item;
|
||||
return new RuntimeItem
|
||||
{
|
||||
Id = new Random().Next(),
|
||||
ScriptableId = ScriptableId,
|
||||
Amount = Amount,
|
||||
RuntimeProperties = new Dictionary<Type, IScriptableItemProperty>(RuntimeProperties),
|
||||
OnRuntimePropertiesChanged = null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.SqlServer.Server;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
@@ -7,89 +8,63 @@ namespace BITKit
|
||||
/// 支持属性
|
||||
/// 支持回调
|
||||
/// </summary>
|
||||
public interface IBasicItemContainer
|
||||
public interface IRuntimeItemContainer:IBinarySerialize
|
||||
{
|
||||
/// <summary>
|
||||
/// 物品容器的唯一Id
|
||||
/// </summary>
|
||||
int Id { get; }
|
||||
/// <summary>
|
||||
/// 尝试获取指定Item
|
||||
/// </summary>
|
||||
bool TryGetItem(Func<IBasicItem, bool> func, out IBasicItem item);
|
||||
/// <summary>
|
||||
/// 获取所有Item的只读副本
|
||||
/// </summary>
|
||||
IBasicItem[] GetItems();
|
||||
IRuntimeItem[] GetItems();
|
||||
/// <summary>
|
||||
/// 添加物品的接口
|
||||
/// </summary>
|
||||
bool Add(IBasicItem item);
|
||||
/// <summary>
|
||||
/// 通过Item本身进行移除
|
||||
/// </summary>
|
||||
bool Remove(IBasicItem item);
|
||||
bool Add(IRuntimeItem item);
|
||||
/// <summary>
|
||||
/// 通过Id移除物品(推荐)
|
||||
/// </summary>
|
||||
bool Remove(int id);
|
||||
/// <summary>
|
||||
/// 通过工厂方法移除物品
|
||||
/// </summary>
|
||||
bool Remove(Func<IBasicItem, bool> removeFactory);
|
||||
/// <summary>
|
||||
/// 通过通过Id丢下物品
|
||||
/// </summary>
|
||||
bool Drop(int Id);
|
||||
bool DropOrSpawn(IBasicItem item);
|
||||
bool Drop(int id);
|
||||
/// <summary>
|
||||
/// 注册添加物品的工厂方法,
|
||||
/// </summary>
|
||||
event Func<IBasicItem, bool> AddFactory;
|
||||
event Func<IRuntimeItem, bool> AddFactory;
|
||||
/// <summary>
|
||||
/// 注册移除物品的工厂方法
|
||||
/// </summary>
|
||||
event Func<IBasicItem, bool> RemoveFactory;
|
||||
event Func<IRuntimeItem, bool> RemoveFactory;
|
||||
/// <summary>
|
||||
/// 注册丢下物品的工厂方法
|
||||
/// </summary>
|
||||
event Func<IBasicItem, bool> DropFactory;
|
||||
event Func<IRuntimeItem, bool> DropFactory;
|
||||
/// <summary>
|
||||
/// 已添加Item的回调
|
||||
/// </summary>
|
||||
event Action<IBasicItem> OnAdd;
|
||||
|
||||
event Action<IRuntimeItem> OnAdd;
|
||||
/// <summary>
|
||||
/// 已移除Item的回调
|
||||
/// </summary>
|
||||
event Action<IBasicItem> OnRemove;
|
||||
event Action<IRuntimeItem> OnRemove;
|
||||
/// <summary>
|
||||
/// 已设置Item的回调
|
||||
/// </summary>
|
||||
event Action<IBasicItem> OnSet;
|
||||
event Action<IRuntimeItem> OnSet;
|
||||
/// <summary>
|
||||
/// 已丢下Item的回调
|
||||
/// </summary>
|
||||
event Action<IBasicItem> OnDrop;
|
||||
event Action<IRuntimeItem> OnDrop;
|
||||
/// <summary>
|
||||
/// 已重构Items的回调
|
||||
/// </summary>
|
||||
event Action<IBasicItemContainer> OnRebuild;
|
||||
|
||||
event Action<IRuntimeItemContainer> OnRebuild;
|
||||
/// <summary>
|
||||
/// 是否已完成物品交换,例如false就是开始交换物品true就是已完成交换物品,可以处理物品了
|
||||
/// </summary>
|
||||
event Action<bool> OnRelease;
|
||||
/// <summary>
|
||||
/// 添加挂起句柄
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
void AddHandle(int id);
|
||||
/// <summary>
|
||||
/// 移除挂起句柄
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
void RemoveHandle(int id);
|
||||
|
||||
}
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public interface IWorldItemObject
|
||||
{
|
||||
public IBasicItem Item { get; set; }
|
||||
public event Action<IBasicItem> OnSetItem;
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0adbb35ce4784342a0ed37ac4a56200
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user