152 lines
4.8 KiB
C#
152 lines
4.8 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)
|
|
{
|
|
if (!self.aoiSet.Add(unit.Id))
|
|
{
|
|
Log.Error($"set has the element");
|
|
}
|
|
}
|
|
public static void Add(this BrocastComponent self, IEnumerable<Unit> list)
|
|
{
|
|
foreach (var 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 var listComponent = ListComponent<long>.Create();
|
|
foreach (var id in self.aoiSet)
|
|
{
|
|
var unit = MapUnitComponent.Instance.Get(id);
|
|
if (!unit)
|
|
{
|
|
listComponent.List.Add(id);
|
|
continue;
|
|
}
|
|
MessageHelper.SendActor(unit, message);
|
|
}
|
|
foreach (var 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<Unit> list)
|
|
{
|
|
foreach (var 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;
|
|
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 var listComponent = ListComponent<long>.Create();
|
|
foreach (var id in self.aoiSetInternal)
|
|
{
|
|
var unit = MapUnitComponent.Instance.Get(id);
|
|
if (!unit)
|
|
{
|
|
listComponent.List.Add(id);
|
|
continue;
|
|
}
|
|
MessageHelper.SendActor(unit, message);
|
|
}
|
|
foreach (var item in listComponent.List)
|
|
{
|
|
self.RemoveInternal(item);
|
|
}
|
|
}
|
|
}
|
|
}
|