using System; using System.Collections.Generic; namespace ET { public class DelaySendSyncAttributeComponentAwakeSystem: AwakeSystem { public override void Awake(DelaySendSyncAttributeComponent self) { DelaySendSyncAttributeComponent.instance = self; } } public class DelaySendSyncAttributeComponentUpdateSystem: UpdateSystem { private HashSet needRemoveSet = new HashSet(); public override void Update(DelaySendSyncAttributeComponent self) { foreach (KeyValuePair>> item in self.dic.GetDictionary()) { try { needRemoveSet.Add(item.Key); List> 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 kv in item.Value) { Log.Error($"k = {(NumericType) kv.Key}, v ={kv.Value}"); } } continue; } if (list.Count == 0) continue; IActorMessage message = null; switch (list.Count) { case > 1: { M2C_SyncUnitAttributeList newMessage = new() { UnitId = unit.Id }; foreach (KeyValuePair kv in list) { newMessage.NumericMap.Add(new AttributeMap { Key = kv.Key, Value = kv.Value }); } message = newMessage; break; } case 1: { KeyValuePair kv = list[0]; message = new M2C_SyncUnitAttribute { UnitId = unit.Id, NumericType = kv.Key, Value = kv.Value }; break; } } if (message != null) unit.GetComponent().BrocastInterval(message); } catch (Exception e) { Log.Error(e); } } 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)); } } }