CTT/Unity/Assets/Hotfix/Logic/Model/Game/Entity/Battle/BuffComponent.cs

69 lines
2.0 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
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} <20><><EFBFBD><EFBFBD>{(buff.isBuff ? "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" : "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")}<7D><><EFBFBD><EFBFBD> {buff.iconDesc} <20><>,<2C><><EFBFBD><EFBFBD>{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?"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>":"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")}<7D><><EFBFBD><EFBFBD> {buff.iconDesc} <20><>");
#endif
}
}
}
}