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
|
||||
}
|
Reference in New Issue
Block a user