zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/System/Other/DelaySendSyncAttributeCompo...

89 lines
3.2 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System;
using System.Collections.Generic;
namespace ET
{
2021-05-14 15:28:23 +08:00
public class DelaySendSyncAttributeComponentAwakeSystem: AwakeSystem<DelaySendSyncAttributeComponent>
2021-04-08 20:09:59 +08:00
{
public override void Awake(DelaySendSyncAttributeComponent self)
{
DelaySendSyncAttributeComponent.instance = self;
}
}
2021-05-14 15:28:23 +08:00
public class DelaySendSyncAttributeComponentUpdateSystem: UpdateSystem<DelaySendSyncAttributeComponent>
2021-04-08 20:09:59 +08:00
{
private HashSet<long> needRemoveSet = new HashSet<long>();
2021-05-14 15:28:23 +08:00
2021-04-08 20:09:59 +08:00
public override void Update(DelaySendSyncAttributeComponent self)
{
2021-04-11 19:50:39 +08:00
foreach (KeyValuePair<long, List<KeyValuePair<int, float>>> item in self.dic.GetDictionary())
2021-04-08 20:09:59 +08:00
{
2021-05-14 15:28:23 +08:00
try
2021-04-08 20:09:59 +08:00
{
2021-05-14 15:28:23 +08:00
needRemoveSet.Add(item.Key);
List<KeyValuePair<int, float>> list = item.Value;
Unit unit = MapUnitComponent.Instance.Get(item.Key);
if (!unit)
2021-04-08 20:09:59 +08:00
{
2021-05-14 15:28:23 +08:00
if (unit != null && Math.Abs(unit.Id) < 100000)
2021-04-08 20:09:59 +08:00
{
2021-05-14 15:28:23 +08:00
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}");
}
2021-04-08 20:09:59 +08:00
}
2021-05-14 15:28:23 +08:00
continue;
2021-04-08 20:09:59 +08:00
}
2021-05-14 15:28:23 +08:00
if (list.Count == 0) continue;
IActorMessage message = null;
switch (list.Count)
2021-04-08 20:09:59 +08:00
{
2021-05-14 15:28:23 +08:00
case > 1:
2021-04-08 20:09:59 +08:00
{
2021-05-14 15:28:23 +08:00
M2C_SyncUnitAttributeList newMessage = new() { UnitId = unit.Id };
foreach (KeyValuePair<int, float> kv in list)
{
newMessage.NumericMap.Add(new AttributeMap { Key = kv.Key, Value = kv.Value });
}
message = newMessage;
break;
}
case 1:
{
KeyValuePair<int, float> kv = list[0];
message = new M2C_SyncUnitAttribute { UnitId = unit.Id, NumericType = kv.Key, Value = kv.Value };
break;
}
2021-04-08 20:09:59 +08:00
}
2021-05-14 15:28:23 +08:00
if (message != null)
unit.GetComponent<BrocastComponent>().BrocastInterval(message);
2021-04-08 20:09:59 +08:00
}
2021-05-14 15:28:23 +08:00
catch (Exception e)
2021-04-08 20:09:59 +08:00
{
2021-05-14 15:28:23 +08:00
Log.Error(e);
2021-04-08 20:09:59 +08:00
}
}
2021-05-14 15:28:23 +08:00
2021-04-11 19:50:39 +08:00
foreach (long item in needRemoveSet)
2021-04-08 20:09:59 +08:00
{
self.dic.Remove(item);
}
2021-05-14 15:28:23 +08:00
2021-04-08 20:09:59 +08:00
needRemoveSet.Clear();
}
}
2021-05-14 15:28:23 +08:00
2021-04-08 20:09:59 +08:00
public static class DelaySendSyncAttributeComponentSystem
{
public static void Add(this DelaySendSyncAttributeComponent self, Unit unit, NumericType numericType, float value)
{
2021-05-14 15:28:23 +08:00
self.dic.Add(unit.Id, KeyValuePair.Create((int) numericType, value));
2021-04-08 20:09:59 +08:00
}
}
2021-05-14 15:28:23 +08:00
}