mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace ET
|
||||
{
|
||||
public interface INumericWatcher
|
||||
{
|
||||
void Run(Unit unit, EventType.NumbericChange args);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d25ba9800f0a922459d8287d76d224d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,121 @@
|
||||
using System.Collections.Generic;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson.Serialization.Options;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
[FriendOf(typeof (NumericComponent))]
|
||||
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 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)
|
||||
{
|
||||
EventSystem.Instance.Publish(self.Scene(),
|
||||
new EventType.NumbericChange() { 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 = (int)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);
|
||||
}
|
||||
}
|
||||
|
||||
namespace EventType
|
||||
{
|
||||
public struct NumbericChange
|
||||
{
|
||||
public Unit Unit;
|
||||
public int NumericType;
|
||||
public long Old;
|
||||
public long New;
|
||||
}
|
||||
}
|
||||
|
||||
[ComponentOf(typeof (Unit))]
|
||||
public class NumericComponent: Entity, IAwake, ITransfer
|
||||
{
|
||||
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
|
||||
public Dictionary<int, long> NumericDic = new Dictionary<int, long>();
|
||||
|
||||
public long this[int numericType]
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetByKey(numericType);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.Insert(numericType, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 701bdb74115713a4bb6486a4bbc832ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,32 @@
|
||||
namespace ET
|
||||
{
|
||||
// 这个可弄个配置表生成
|
||||
public static class NumericType
|
||||
{
|
||||
public const int Max = 10000;
|
||||
|
||||
public const int Speed = 1000;
|
||||
public const int SpeedBase = Speed * 10 + 1;
|
||||
public const int SpeedAdd = Speed * 10 + 2;
|
||||
public const int SpeedPct = Speed * 10 + 3;
|
||||
public const int SpeedFinalAdd = Speed * 10 + 4;
|
||||
public const int SpeedFinalPct = Speed * 10 + 5;
|
||||
|
||||
public const int Hp = 1001;
|
||||
public const int HpBase = Hp * 10 + 1;
|
||||
|
||||
public const int MaxHp = 1002;
|
||||
public const int MaxHpBase = MaxHp * 10 + 1;
|
||||
public const int MaxHpAdd = MaxHp * 10 + 2;
|
||||
public const int MaxHpPct = MaxHp * 10 + 3;
|
||||
public const int MaxHpFinalAdd = MaxHp * 10 + 4;
|
||||
public const int MaxHpFinalPct = MaxHp * 10 + 5;
|
||||
|
||||
public const int AOI = 1003;
|
||||
public const int AOIBase = AOI * 10 + 1;
|
||||
public const int AOIAdd = AOI * 10 + 2;
|
||||
public const int AOIPct = AOI * 10 + 3;
|
||||
public const int AOIFinalAdd = AOI * 10 + 4;
|
||||
public const int AOIFinalPct = AOI * 10 + 5;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e48d074e33972034bad7ee8ba643edf5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class NumericWatcherAttribute : BaseAttribute
|
||||
{
|
||||
public SceneType SceneType { get; }
|
||||
|
||||
public int NumericType { get; }
|
||||
|
||||
public NumericWatcherAttribute(SceneType sceneType, int type)
|
||||
{
|
||||
this.SceneType = sceneType;
|
||||
this.NumericType = type;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96e98292e4df6684abad49fc0887b963
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
public class NumericWatcherInfo
|
||||
{
|
||||
public SceneType SceneType { get; }
|
||||
public INumericWatcher INumericWatcher { get; }
|
||||
|
||||
public NumericWatcherInfo(SceneType sceneType, INumericWatcher numericWatcher)
|
||||
{
|
||||
this.SceneType = sceneType;
|
||||
this.INumericWatcher = numericWatcher;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 监视数值变化组件,分发监听
|
||||
/// </summary>
|
||||
public class NumericWatcherComponent : SingletonLock<NumericWatcherComponent>, ISingletonAwake
|
||||
{
|
||||
private readonly Dictionary<int, List<NumericWatcherInfo>> allWatchers = new();
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
HashSet<Type> types = EventSystem.Instance.GetTypes(typeof(NumericWatcherAttribute));
|
||||
foreach (Type type in types)
|
||||
{
|
||||
object[] attrs = type.GetCustomAttributes(typeof(NumericWatcherAttribute), false);
|
||||
|
||||
foreach (object attr in attrs)
|
||||
{
|
||||
NumericWatcherAttribute numericWatcherAttribute = (NumericWatcherAttribute)attr;
|
||||
INumericWatcher obj = (INumericWatcher)Activator.CreateInstance(type);
|
||||
NumericWatcherInfo numericWatcherInfo = new(numericWatcherAttribute.SceneType, obj);
|
||||
if (!this.allWatchers.ContainsKey(numericWatcherAttribute.NumericType))
|
||||
{
|
||||
this.allWatchers.Add(numericWatcherAttribute.NumericType, new List<NumericWatcherInfo>());
|
||||
}
|
||||
this.allWatchers[numericWatcherAttribute.NumericType].Add(numericWatcherInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
World.Instance.AddSingleton<NumericWatcherComponent>(true);
|
||||
}
|
||||
|
||||
public void Run(Unit unit, EventType.NumbericChange args)
|
||||
{
|
||||
List<NumericWatcherInfo> list;
|
||||
if (!this.allWatchers.TryGetValue(args.NumericType, out list))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SceneType unitDomainSceneType = unit.IScene.SceneType;
|
||||
foreach (NumericWatcherInfo numericWatcher in list)
|
||||
{
|
||||
if (!numericWatcher.SceneType.HasSameFlag(unitDomainSceneType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
numericWatcher.INumericWatcher.Run(unit, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86c4a86a98102464b8bbe1bd9da800e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user