using ET.EventType; using System; using System.Collections.Generic; namespace ET { public class BrocastComponentAwakeSystem : AwakeSystem { public override void Awake(BrocastComponent self, bool canBrocast) { self.isPlayer = canBrocast; self.unit = self.GetParent(); self.aoiSet.Add(self.unit.Id); self.aoiSetInternal.Add(self.unit.Id); } } public class BrocastComponentDestroySystem : DestroySystem { public override void Destroy(BrocastComponent self) { self.aoiSet.Clear(); self.aoiSetInternal.Clear(); } } //class PrintAOISetPer10Second : AEvent //{ // public override async ETTask Run(UpdatePer1Second args) // { // var now = Game.TimeInfo.ToDateTime(args.now); // if (now.Second % 10 == 0) // { // foreach (var unit in MapUnitComponent.Instance.GetAll()) // { // var brocast = unit.GetComponent(); // Log.Info($"【{unit.Id}】 : \naoi:{brocast.aoiSet.ToCustomString()}\ninnerAoi:{brocast.aoiSetInternal.ToCustomString()}"); // } // } // await ETTask.CompletedTask; // } //} public static class BrocastComponentSystem { public static void Add(this BrocastComponent self, Unit unit) { if (!self.aoiSet.Add(unit.Id)) { Log.Error($"set has the element"); } } public static void Add(this BrocastComponent self, IEnumerable list) { foreach (Unit unit in list) { if (self.Id != unit.Id) self.Add(unit); } } public static void Remove(this BrocastComponent self, long id) { try { if (self.unit.Id == id) return; if (!self.aoiSet.Remove(id)) { Log.ErrorDetail($"set has not the unit where Id = {id}"); } } catch (Exception e) { Log.Error(e); } } public static void Clear(this BrocastComponent self) { self.aoiSet.Clear(); self.aoiSet.Add(self.Id); } public static void Brocast(this BrocastComponent self, IActorMessage message) { using ListComponent listComponent = ListComponent.Create(); foreach (long id in self.aoiSet) { Unit unit = MapUnitComponent.Instance.Get(id); if (!unit) { listComponent.List.Add(id); continue; } MessageHelper.SendActor(unit, message); } foreach (long item in listComponent.List) { self.Remove(item); } } public static void AddInternal(this BrocastComponent self, Unit unit) { if (!self.aoiSetInternal.Add(unit.Id)) { Log.Error($"set has the element"); } } public static void AddInternal(this BrocastComponent self, IEnumerable list) { foreach (Unit unit in list) { if (self.Id != unit.Id) self.AddInternal(unit); } } public static HashSet GetInternalAll(this BrocastComponent self) { return self.aoiSetInternal; } public static void RemoveInternal(this BrocastComponent self, long id) { if (self.unit.Id == id) return; if (!self.aoiSetInternal.Remove(id)) { Log.ErrorDetail($"aoiSetInternal has not the unit where Id = {id}"); } } public static void ClearInternal(this BrocastComponent self) { self.aoiSetInternal.Clear(); self.aoiSetInternal.Add(self.Id); } public static void BrocastInterval(this BrocastComponent self, IActorMessage message) { using ListComponent listComponent = ListComponent.Create(); foreach (long id in self.aoiSetInternal) { Unit unit = MapUnitComponent.Instance.Get(id); if (!unit) { listComponent.List.Add(id); continue; } MessageHelper.SendActor(unit, message); } foreach (long item in listComponent.List) { self.RemoveInternal(item); } } } }