162 lines
5.9 KiB
C#
162 lines
5.9 KiB
C#
using ET.EventType;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ET
|
|
{
|
|
public class BrocastComponentAwakeSystem : AwakeSystem<BrocastComponent, bool>
|
|
{
|
|
public override void Awake(BrocastComponent self, bool canBrocast)
|
|
{
|
|
self.isPlayer = canBrocast;
|
|
self.unit = self.GetParent<Unit>();
|
|
self.aoiSet.Add(self.unit.Id);
|
|
self.aoiSetInternal.Add(self.unit.Id);
|
|
}
|
|
}
|
|
|
|
public class BrocastComponentDestroySystem : DestroySystem<BrocastComponent>
|
|
{
|
|
public override void Destroy(BrocastComponent self)
|
|
{
|
|
self.aoiSet.Clear();
|
|
self.aoiSetInternal.Clear();
|
|
}
|
|
}
|
|
|
|
//class PrintAOISetPer10Second : AEvent<ET.EventType.UpdatePer1Second>
|
|
//{
|
|
// 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<BrocastComponent>();
|
|
// 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)
|
|
{
|
|
// Log.Warning($"[{self.Id}][{self.aoiSet.ToCustomString()}]add:{unit.Id}");
|
|
if (!self.aoiSet.Add(unit.Id))
|
|
{
|
|
Log.ErrorDetail($"set has the element : {unit.Id} id= {self.Id} {self.aoiSet.ToCustomString()}");
|
|
}
|
|
}
|
|
public static void Add(this BrocastComponent self, IEnumerable<Unit> 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;
|
|
// Log.Warning($"[{self.Id}][{self.aoiSet.ToCustomString()}]remove:{id}");
|
|
if (!self.aoiSet.Remove(id))
|
|
{
|
|
Log.ErrorDetail($"set has not the unit where Id = {id} selfId= {self.Id} {self.aoiSet.ToCustomString()}");
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
public static void Clear(this BrocastComponent self)
|
|
{
|
|
|
|
// Log.Warning($"[{self.Id}][{self.aoiSet.ToCustomString()}]clear");
|
|
self.aoiSet.Clear();
|
|
self.aoiSet.Add(self.Id);
|
|
}
|
|
public static void Brocast(this BrocastComponent self, IActorMessage message)
|
|
{
|
|
// using ListComponent<long> listComponent = ListComponent<long>.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))
|
|
{
|
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|
Log.ErrorDetail($"set has the element : {unit.Id} id= {self.Id} {self.aoiSetInternal.ToCustomString()} =>{team.GetMemberName()}");
|
|
}
|
|
}
|
|
public static void AddInternal(this BrocastComponent self, IEnumerable<Unit> list)
|
|
{
|
|
foreach (Unit unit in list)
|
|
{
|
|
if (self.Id != unit.Id)
|
|
self.AddInternal(unit);
|
|
}
|
|
}
|
|
public static HashSet<long> GetInternalAll(this BrocastComponent self)
|
|
{
|
|
return self.aoiSetInternal;
|
|
}
|
|
public static void RemoveInternal(this BrocastComponent self, long id)
|
|
{
|
|
if (self.unit.Id == id)
|
|
return;
|
|
// Log.Warning($"{self.Id} =>{self.aoiSetInternal.ToCustomString()} removeInternal:{id} team=>{TeamComponent.Instance.Get(MapUnitComponent.Instance.Get(id).TeamLeaderId).GetMemberName()}");
|
|
if (!self.aoiSetInternal.Remove(id))
|
|
{
|
|
Unit unit = MapUnitComponent.Instance.Get(id);
|
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|
Log.ErrorDetail(
|
|
$"aoiSetInternal has not the unit where Id = {id} selfId= {self.Id} {self.aoiSet.ToCustomString()}=>{team.GetMemberName()}");
|
|
}
|
|
}
|
|
public static void ClearInternal(this BrocastComponent self)
|
|
{
|
|
// Log.Warning($"[{self.Id}][{self.aoiSetInternal.ToCustomString()}]clear");
|
|
self.aoiSetInternal.Clear();
|
|
self.aoiSetInternal.Add(self.Id);
|
|
}
|
|
public static void BrocastInterval(this BrocastComponent self, IActorMessage message)
|
|
{
|
|
// using ListComponent<long> listComponent = ListComponent<long>.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);
|
|
// }
|
|
}
|
|
}
|
|
}
|