69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using ET;
|
|
namespace ET
|
|
{
|
|
public class BuffComponentAwakeSystem : AwakeSystem<BuffComponent>
|
|
{
|
|
public override void Awake(BuffComponent self)
|
|
{
|
|
BuffComponent.instance = self;
|
|
}
|
|
}
|
|
public class BuffComponentUpdateSystem : UpdateSystem<BuffComponent>
|
|
{
|
|
public override void Update(BuffComponent self)
|
|
{
|
|
self.Update();
|
|
}
|
|
}
|
|
public class BuffComponent:Entity
|
|
{
|
|
public static BuffComponent instance;
|
|
public readonly MultiMap<long,BuffStateInfo> buffDic = new MultiMap<long, BuffStateInfo>();
|
|
|
|
public void AddBuff(int continueTime,BuffStateInfo buff)
|
|
{
|
|
var now = TimeHelper.ClientNow();
|
|
long leastTime = now + continueTime;
|
|
buffDic.Add(leastTime, buff);
|
|
|
|
#if TEST
|
|
Test.Log($"{buff.unitId} 获得{(buff.isBuff ? "增益" : "减益")}:【 {buff.iconDesc} 】,持续{buff.time/1000f:f1}s");
|
|
#endif
|
|
}
|
|
public void Update()
|
|
{
|
|
var now = TimeHelper.ClientNow();
|
|
CheckTimeOut(now,buffDic);
|
|
}
|
|
|
|
List<long> needRemoveList = new List<long>();
|
|
private void CheckTimeOut(long now, SortedDictionary<long, List<BuffStateInfo>> sortedDictionaries)
|
|
{
|
|
needRemoveList.Clear();
|
|
foreach (var kv in sortedDictionaries)
|
|
{
|
|
long leastTime = kv.Key;
|
|
if (leastTime <= now)
|
|
{
|
|
needRemoveList.Add(leastTime);
|
|
RemoveBuff(kv.Value);
|
|
}
|
|
}
|
|
foreach (var item in needRemoveList)
|
|
{
|
|
buffDic.Remove(item);
|
|
}
|
|
}
|
|
|
|
private void RemoveBuff(List<BuffStateInfo> list)
|
|
{
|
|
foreach (var buff in list)
|
|
{
|
|
#if TEST
|
|
Test.Log($"{buff.unitId} 失去{(buff.isBuff?"增益":"减益")}:【 {buff.iconDesc} 】");
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
} |