142 lines
3.7 KiB
C#
142 lines
3.7 KiB
C#
|
using System;
|
||
|
using System.IO;
|
||
|
|
||
|
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 IBasicItem :IPropertable
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 唯一Id
|
||
|
/// </summary>
|
||
|
int Id { get; }
|
||
|
/// <summary>
|
||
|
/// 物品名,一般用于查找物品的主键
|
||
|
/// </summary>
|
||
|
string Name { get; }
|
||
|
/// <summary>
|
||
|
/// 可寻址路径,该路径用于查找物品
|
||
|
/// </summary>
|
||
|
string AdressablePath { get; }
|
||
|
/// <summary>
|
||
|
/// 物品描述
|
||
|
/// </summary>
|
||
|
string Description { get; }
|
||
|
/// <summary>
|
||
|
/// 物品品质
|
||
|
/// </summary>
|
||
|
ItemQuality Quality { get; }
|
||
|
bool CopyItemsFrom(IBasicItem item);
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 可配置化物品,通常用于配置
|
||
|
/// </summary>
|
||
|
public interface IAssetableItem: IBasicItem
|
||
|
{
|
||
|
}
|
||
|
#endregion
|
||
|
#region 物品实现
|
||
|
/// <summary>
|
||
|
/// 可序列化的物品
|
||
|
/// </summary>
|
||
|
[Serializable]
|
||
|
public record SerializableItem : IBasicItem
|
||
|
{
|
||
|
#region 字段
|
||
|
public int Id;
|
||
|
public string Name;
|
||
|
public string AdressablePath { get; set; }
|
||
|
public string Description;
|
||
|
public ItemQuality Quality;
|
||
|
/// <summary>
|
||
|
/// 本地属性
|
||
|
/// </summary>
|
||
|
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 T GetOrAddProperty<T>(Func<T> addFactory) => property.GetOrAddProperty<T>(addFactory);
|
||
|
|
||
|
public T GetOrCreateProperty<T>() => property.GetOrCreateProperty<T>();
|
||
|
|
||
|
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)
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
|
||
|
public void Write(BinaryWriter w)
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
|
||
|
public bool CopyItemsFrom(IBasicItem item)
|
||
|
{
|
||
|
Id=item.Id;
|
||
|
Name = item.Name;
|
||
|
AdressablePath = item.AdressablePath;
|
||
|
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
|
||
|
}
|
||
|
#endregion
|
||
|
}
|