This commit is contained in:
CortexCore
2024-04-16 04:06:46 +08:00
parent 37e7fcea51
commit c798b224be
67 changed files with 1305 additions and 425 deletions

View File

@@ -63,6 +63,11 @@ namespace BITKit
/// </summary>
ItemQuality Quality { get; }
bool CopyItemsFrom(IBasicItem item);
/// <summary>
/// 价值
/// </summary>
/// <returns></returns>
int Value=>10;
}
/// <summary>
/// 可配置化物品,通常用于配置
@@ -84,6 +89,7 @@ namespace BITKit
public string AddressablePath { get; set; }
public string Description;
public ItemQuality Quality;
public int Value { get; set; }
/// <summary>
/// 本地属性
/// </summary>
@@ -122,6 +128,7 @@ namespace BITKit
public bool CopyItemsFrom(IBasicItem item)
{
Value = item.Value;
Id=item.Id;
Name = item.Name;
AddressablePath = item.AddressablePath;

View File

@@ -75,6 +75,21 @@ namespace BITKit
/// 已重构Items的回调
/// </summary>
event Action<IBasicItemContainer> 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);
}
}

View File

@@ -7,6 +7,17 @@ namespace BITKit
{
public static class MathE
{
public static int GetHash<T>(IEnumerable<T> self)
{
var hash = 0;
foreach (var x in self)
{
if (x is not null)
hash += x.GetHashCode();
}
return hash;
}
public static bool IndexInRange<T>(this IEnumerable<T> self, int index)
{
return index >= 0 && index < self.Count();

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e517c312e735e1042b911efc79deb1f6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
{
"name": "BITKit.Probability",
"rootNamespace": "",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": true
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2f7d7f857f30f484ea163931f3bc4e0a
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
namespace BITKit.Probability
{
/// <summary>
/// 概率属性
/// </summary>
public interface IProbabilityProperty
{
}
/// <summary>
/// 概率服务
/// </summary>
public interface IProbabilityService
{
/// <summary>
/// 根据概率属性获取值
/// </summary>
/// <param name="properties"></param>
/// <returns></returns>
object GetValueObject(params IProbabilityProperty[] properties);
/// <summary>
/// 根据概率属性获取值
/// </summary>
/// <param name="properties"></param>
/// <returns></returns>
object[] GetValuesObject(params IProbabilityProperty[] properties);
}
/// <summary>
/// 泛型概率服务
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IProbabilityService<T>:IProbabilityService
{
/// <summary>
/// 根据概率属性获取值
/// </summary>
/// <param name="properties"></param>
/// <returns></returns>
T GetValue(params IProbabilityProperty[] properties);
/// <summary>
/// 根据概率属性获取值
/// </summary>
/// <param name="properties"></param>
/// <returns></returns>
T[] GetValues(params IProbabilityProperty[] properties);
}
}

View File

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

View File

@@ -70,87 +70,84 @@ namespace BITKit
{
foreach (var x in factory)
{
AddPropertyInternal(x);
properties.Add(x);
}
}
Dictionary<string, object> properties=new();
private readonly List<object> properties=new();
public T GetProperty<T>()
{
return (T)properties[typeof(T).FullName];
return properties.OfType<T>().First();
}
public void SetProperty<T>(T value)
{
properties.Insert(typeof(T).FullName, value);
for (var i = 0; i < properties.Count; i++)
{
if (properties[i] is T)
properties[i] = value;
}
}
public bool Contains<T>()
{
return properties.ContainsKey(typeof(T).FullName);
return properties.OfType<T>().FirstOrDefault() is not null;
}
public T GetOrCreateProperty<T>()
{
return GetOrAddProperty(Activator.CreateInstance<T>);
}
public T GetOrAddProperty<T>(Func<T> addFactory)
{
if (properties.TryGetValue(typeof(T).FullName, out var x))
foreach (var obj in properties)
{
return (T)x;
}
else
{
AddPropertyInternal(x =addFactory.Invoke());
//properties.Add(typeof(T).FullName, x = addFactory.Invoke());
return (T)x;
if (obj is T t) return t;
}
T x;
properties.Add(x = addFactory.Invoke());
return x;
}
public bool TryGetProperty<T>(out T value)
{
if (properties.TryGetValue(typeof(T).FullName, out var x))
try
{
value = (T)x;
value = properties.OfType<T>().First();
return true;
}
else
catch (InvalidOperationException)
{
value=default(T);
value = default;
return false;
}
}
public bool TryRemoveProperty<T>()
{
foreach (var pair in properties.Where(x=>x.Value is T))
var removed=false;
foreach (var value in properties.OfType<T>().ToArray())
{
properties.Remove(pair.Key);
return true;
properties.Remove(value);
removed = true;
}
// if(properties.TryGetValue(typeof(T).FullName, out var x))
// {
// properties.Remove(typeof(T).Name);
// return true;
// }
return false;
return removed;
}
public bool TrySetProperty<T>(T value)
{
bool result = false;
foreach (var pair in properties.Where(x=>x.Value is T).ToArray())
var current = properties.OfType<T>().FirstOrDefault();
if (current is not null)
{
properties[pair.Key] = value;
result = true;
properties.Remove(current);
return true;
}
return result;
// if (properties.TryGetValue(typeof(T).FullName, out var x))
// {
// properties[typeof(T).FullName] = value;
// return true;
// }
// else
// {
// return false;
// }
properties.Add(value);
return false;
}
public object[] GetProperties()=>properties.Values.Distinct().ToArray();
public object[] GetProperties() => properties.ToArray();
public void Read(BinaryReader r)
{
@@ -174,23 +171,8 @@ namespace BITKit
public bool CopyPropertiesFrom(IPropertable propertable)
{
ClearProperties();
foreach (var x in propertable.GetProperties())
{
AddPropertyInternal(x);
}
properties.AddRange( propertable.GetProperties());;
return true;
}
private void AddPropertyInternal(object value)
{
if (value is ICloneable cloneable)
{
value = cloneable.Clone();
}
properties.Set(value.GetType().FullName, value);
foreach (var att in value.GetType().GetCustomAttributes<CustomTypeAttribute>())
{
properties.Set(att.Type!.FullName, value);
}
}
}
}

View File

@@ -2,6 +2,7 @@ namespace BITKit
{
public interface ITag
{
int Hash { get; }
string[] GetTags();
}
}

View File

@@ -145,6 +145,13 @@ namespace BITKit
{
value = _directDirection.Get(key);
}
public T GetOrAddDirect<T>(int key,Func<T> factory)
{
if (_directDirection.TryGetValue(key, out var v)) return v is T t ? t : default;
var value = factory.Invoke();
_directDirection.Add(key, value);
return value;
}
public void GetDirect<T>(int key,out T value)
{
try