61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using ET;
|
|
namespace ET
|
|
{
|
|
public class BuffComponentAwakeSystem : AwakeSystem<BuffComponent>
|
|
{
|
|
public override void Awake(BuffComponent self)
|
|
{
|
|
self.timerId = TimerComponent.Instance.NewRepeatedTimer(500, self.Update);
|
|
}
|
|
}
|
|
public class BuffComponentDestroySystem : DestroySystem<BuffComponent>
|
|
{
|
|
public override void Destroy(BuffComponent self)
|
|
{
|
|
self.buffList.Clear();
|
|
TimerComponent.Instance.Remove(ref self.timerId);
|
|
}
|
|
}
|
|
public class BuffComponent : Entity
|
|
{
|
|
public long timerId;
|
|
public readonly Dictionary<long, BuffStateInfo> buffList = new Dictionary<long, BuffStateInfo>();
|
|
|
|
public void AddBuff(BuffStateInfo buff)
|
|
{
|
|
buffList[buff.Id] = buff;
|
|
Game.EventSystem.Publish(new ET.EventType.RefreshBuff
|
|
{
|
|
zoneScene = this.ZoneScene(),
|
|
unitId=this.Id,
|
|
}).Coroutine();
|
|
}
|
|
public void RemoveBuff(long Id)
|
|
{
|
|
if (!buffList.Remove(Id))
|
|
{
|
|
Log.Error($"can't remove buff where id is {Id}");
|
|
}
|
|
Game.EventSystem.Publish(new ET.EventType.RefreshBuff
|
|
{
|
|
zoneScene = this.ZoneScene(),
|
|
unitId = this.Id,
|
|
}).Coroutine();
|
|
}
|
|
|
|
internal void Update()
|
|
{
|
|
long now = TimeHelper.ServerNow();
|
|
using var listComponent = ListComponent<long>.Create();
|
|
listComponent.List.AddRange(buffList.Keys);
|
|
foreach (long key in listComponent.List)
|
|
{
|
|
BuffStateInfo buff = buffList[key];
|
|
if (now > buff.leastTime)
|
|
RemoveBuff(buff.Id);
|
|
}
|
|
}
|
|
}
|
|
} |