调整目录结构
This commit is contained in:
3
Assets/Scripts/Model/Module/Numeric.meta
Normal file
3
Assets/Scripts/Model/Module/Numeric.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ddc41e806352498aad45983600bdce6d
|
||||
timeCreated: 1756310441
|
||||
138
Assets/Scripts/Model/Module/Numeric/NumericComponent.cs
Normal file
138
Assets/Scripts/Model/Module/Numeric/NumericComponent.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System.Collections.Generic;
|
||||
using NBC;
|
||||
using NBC.Entitas;
|
||||
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据组件
|
||||
/// </summary>
|
||||
public class NumericComponent : Entity
|
||||
{
|
||||
public Dictionary<int, long> NumericDic = new Dictionary<int, long>();
|
||||
|
||||
public long this[int numericType]
|
||||
{
|
||||
get { return this.GetByKey(numericType); }
|
||||
set { this.Insert(numericType, value); }
|
||||
}
|
||||
}
|
||||
|
||||
public struct NumericChange
|
||||
{
|
||||
public Unit Unit;
|
||||
public int NumericType;
|
||||
public long Old;
|
||||
public long New;
|
||||
}
|
||||
|
||||
public static class NumericComponentSystem
|
||||
{
|
||||
public static float GetAsFloat(this NumericComponent self, int numericType)
|
||||
{
|
||||
return (float)self.GetByKey(numericType) / 10000;
|
||||
}
|
||||
|
||||
public static int GetAsInt(this NumericComponent self, int numericType)
|
||||
{
|
||||
return (int)self.GetByKey(numericType);
|
||||
}
|
||||
|
||||
public static long GetAsLong(this NumericComponent self, int numericType)
|
||||
{
|
||||
return self.GetByKey(numericType);
|
||||
}
|
||||
|
||||
public static void Set(this NumericComponent self, int nt, float value)
|
||||
{
|
||||
self[nt] = (long)(value * 10000);
|
||||
}
|
||||
|
||||
public static void Set(this NumericComponent self, int nt, int value)
|
||||
{
|
||||
self[nt] = value;
|
||||
}
|
||||
|
||||
public static void Set(this NumericComponent self, int nt, long value)
|
||||
{
|
||||
self[nt] = value;
|
||||
}
|
||||
|
||||
public static void Add(this NumericComponent self, int nt, float value)
|
||||
{
|
||||
self[nt] += (long)(value * 10000);
|
||||
}
|
||||
|
||||
public static void Add(this NumericComponent self, int nt, int value)
|
||||
{
|
||||
self[nt] += value;
|
||||
}
|
||||
|
||||
public static void Add(this NumericComponent self, int nt, long value)
|
||||
{
|
||||
self[nt] += value;
|
||||
}
|
||||
|
||||
public static void SetNoEvent(this NumericComponent self, int numericType, long value)
|
||||
{
|
||||
self.Insert(numericType, value, false);
|
||||
}
|
||||
|
||||
public static void Insert(this NumericComponent self, int numericType, long value, bool isPublicEvent = true)
|
||||
{
|
||||
long oldValue = self.GetByKey(numericType);
|
||||
if (oldValue == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self.NumericDic[numericType] = value;
|
||||
|
||||
if (numericType >= NumericType.Max)
|
||||
{
|
||||
self.Update(numericType, isPublicEvent);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPublicEvent)
|
||||
{
|
||||
App.Main.EventComponent.Publish(new NumericChange()
|
||||
{ Unit = self.GetParent<Unit>(), New = value, Old = oldValue, NumericType = numericType });
|
||||
}
|
||||
}
|
||||
|
||||
public static long GetByKey(this NumericComponent self, int key)
|
||||
{
|
||||
long value = 0;
|
||||
self.NumericDic.TryGetValue(key, out value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void Update(this NumericComponent self, int numericType, bool isPublicEvent)
|
||||
{
|
||||
int final = numericType / 10;
|
||||
int bas = final * 10 + 1;
|
||||
int add = final * 10 + 2;
|
||||
int pct = final * 10 + 3;
|
||||
int finalAdd = final * 10 + 4;
|
||||
int finalPct = final * 10 + 5;
|
||||
|
||||
// 一个数值可能会多种情况影响,比如速度,加个buff可能增加速度绝对值100,也有些buff增加10%速度,所以一个值可以由5个值进行控制其最终结果
|
||||
// final = (((base + add) * (100 + pct) / 100) + finalAdd) * (100 + finalPct) / 100;
|
||||
long result = (long)(((self.GetByKey(bas) + self.GetByKey(add)) * (100 + self.GetAsFloat(pct)) / 100f +
|
||||
self.GetByKey(finalAdd)) *
|
||||
(100 + self.GetAsFloat(finalPct)) / 100f);
|
||||
self.Insert(final, result, isPublicEvent);
|
||||
}
|
||||
|
||||
public static Dictionary<int, long> CopyDict(this NumericComponent self)
|
||||
{
|
||||
return new Dictionary<int, long>(self.NumericDic);
|
||||
}
|
||||
|
||||
public static void Clear(this NumericComponent self)
|
||||
{
|
||||
self.NumericDic.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 737675ae567e412aa2ec234c3fa62ed5
|
||||
timeCreated: 1756114955
|
||||
8
Assets/Scripts/Model/Module/Numeric/NumericType.cs
Normal file
8
Assets/Scripts/Model/Module/Numeric/NumericType.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public static class NumericType
|
||||
{
|
||||
public const int Max = 10000;
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Model/Module/Numeric/NumericType.cs.meta
Normal file
3
Assets/Scripts/Model/Module/Numeric/NumericType.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 257e38cf2fa2457087822886699e3276
|
||||
timeCreated: 1756115154
|
||||
3
Assets/Scripts/Model/Module/ObjectWait.meta
Normal file
3
Assets/Scripts/Model/Module/ObjectWait.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c2510352b1145bcaedaddbce324c10d
|
||||
timeCreated: 1756310429
|
||||
144
Assets/Scripts/Model/Module/ObjectWait/ObjectWait.cs
Normal file
144
Assets/Scripts/Model/Module/ObjectWait/ObjectWait.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NBC;
|
||||
using NBC.Entitas;
|
||||
using NBC.Entitas.Interface;
|
||||
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public static class WaitTypeError
|
||||
{
|
||||
public const int Success = 0;
|
||||
public const int Destroy = 1;
|
||||
public const int Cancel = 2;
|
||||
public const int Timeout = 3;
|
||||
}
|
||||
|
||||
public interface IWaitType
|
||||
{
|
||||
int Error { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class ObjectWait : Entity
|
||||
{
|
||||
public Dictionary<Type, List<object>> tcsDict = new();
|
||||
}
|
||||
|
||||
|
||||
public static class ObjectWaitSystem
|
||||
{
|
||||
public class ObjectWaitAwakeSystem : AwakeSystem<ObjectWait>
|
||||
{
|
||||
protected override void Awake(ObjectWait self)
|
||||
{
|
||||
self.tcsDict.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class ObjectWaitDestroySystem : DestroySystem<ObjectWait>
|
||||
{
|
||||
protected override void Destroy(ObjectWait self)
|
||||
{
|
||||
foreach (var p in self.tcsDict)
|
||||
{
|
||||
foreach (object v in p.Value)
|
||||
{
|
||||
((IDestroyRun)v).SetResult();
|
||||
}
|
||||
}
|
||||
|
||||
self.tcsDict.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private interface IDestroyRun
|
||||
{
|
||||
void SetResult();
|
||||
}
|
||||
|
||||
private class ResultCallback<K> : IDestroyRun where K : struct, IWaitType
|
||||
{
|
||||
private FTask<K> tcs;
|
||||
|
||||
public ResultCallback()
|
||||
{
|
||||
this.tcs = FTask<K>.Create(true);
|
||||
}
|
||||
|
||||
public bool IsDisposed
|
||||
{
|
||||
get { return this.tcs == null; }
|
||||
}
|
||||
|
||||
public FTask<K> Task => this.tcs;
|
||||
|
||||
public void SetResult(K k)
|
||||
{
|
||||
var t = tcs;
|
||||
this.tcs = null;
|
||||
t.SetResult(k);
|
||||
}
|
||||
|
||||
public void SetResult()
|
||||
{
|
||||
var t = tcs;
|
||||
this.tcs = null;
|
||||
t.SetResult(new K() { Error = WaitTypeError.Destroy });
|
||||
}
|
||||
}
|
||||
|
||||
public static async FTask<T> Wait<T>(this ObjectWait self) where T : struct, IWaitType
|
||||
{
|
||||
ResultCallback<T> tcs = new ResultCallback<T>();
|
||||
FCancellationToken cancellationToken = FCancellationToken.ToKen;
|
||||
self.Add(typeof(T), tcs);
|
||||
|
||||
T ret;
|
||||
try
|
||||
{
|
||||
cancellationToken?.Add(CancelAction);
|
||||
ret = await tcs.Task;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cancellationToken?.Remove(CancelAction);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
void CancelAction()
|
||||
{
|
||||
self.Notify(new T() { Error = WaitTypeError.Cancel });
|
||||
}
|
||||
}
|
||||
|
||||
public static void Notify<T>(this ObjectWait self, T obj) where T : struct, IWaitType
|
||||
{
|
||||
Type type = typeof(T);
|
||||
if (!self.tcsDict.TryGetValue(type, out var tcsList) || tcsList.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var tcs in tcsList)
|
||||
{
|
||||
((ResultCallback<T>)tcs).SetResult(obj);
|
||||
}
|
||||
|
||||
tcsList.Clear();
|
||||
}
|
||||
|
||||
private static void Add(this ObjectWait self, Type type, object obj)
|
||||
{
|
||||
if (self.tcsDict.TryGetValue(type, out var list))
|
||||
{
|
||||
list.Add(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.tcsDict.Add(type, new List<object> { obj });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a79150f39b424a1c82eef6b04bc0a7c1
|
||||
timeCreated: 1756310098
|
||||
Reference in New Issue
Block a user