CTT/Server/Hotfix/Game/System/Other/DelaySendSyncAttributeCompo...

81 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
namespace ET
{
public class DelaySendSyncAttributeComponentAwakeSystem : AwakeSystem<DelaySendSyncAttributeComponent>
{
public override void Awake(DelaySendSyncAttributeComponent self)
{
DelaySendSyncAttributeComponent.instance = self;
}
}
public class DelaySendSyncAttributeComponentUpdateSystem : UpdateSystem<DelaySendSyncAttributeComponent>
{
private HashSet<long> needRemoveSet = new HashSet<long>();
public override void Update(DelaySendSyncAttributeComponent self)
{
foreach (KeyValuePair<long, List<KeyValuePair<int, float>>> item in self.dic.GetDictionary())
{
needRemoveSet.Add(item.Key);
List<KeyValuePair<int, float>> list = item.Value;
Unit unit = MapUnitComponent.Instance.Get(item.Key);
if (!unit)
{
if (unit!=null && Math.Abs(unit.Id) < 100000)
{
Log.Error($"unit is invalid where id = {item.Key} ");
foreach (KeyValuePair<int, float> kv in item.Value)
{
Log.Error($"k = {(NumericType)kv.Key}, v ={kv.Value}");
}
}
continue;
}
IActorMessage message = null;
if (list.Count > 1)
{
M2C_SyncUnitAttributeList newMessage = new M2C_SyncUnitAttributeList
{
UnitId = unit.Id
};
foreach (KeyValuePair<int, float> kv in list)
{
newMessage.NumericMap.Add(new AttributeMap
{
Key = kv.Key,
Value = kv.Value
});
}
message = newMessage;
}
else if (list.Count == 1)
{
KeyValuePair<int, float> kv = list[0];
message = new M2C_SyncUnitAttribute
{
UnitId = unit.Id,
NumericType = kv.Key,
Value = kv.Value
};
}
if (message != null)
unit.GetComponent<BrocastComponent>().BrocastInterval(message);
}
foreach (long item in needRemoveSet)
{
self.dic.Remove(item);
}
needRemoveSet.Clear();
}
}
public static class DelaySendSyncAttributeComponentSystem
{
public static void Add(this DelaySendSyncAttributeComponent self, Unit unit, NumericType numericType, float value)
{
self.dic.Add(unit.Id, KeyValuePair.Create((int)numericType, value));
}
}
}