using System.Collections.Generic; using ET; namespace ET { public class BuffComponentAwakeSystem : AwakeSystem { public override void Awake(BuffComponent self) { BuffComponent.instance = self; } } public class BuffComponentUpdateSystem : UpdateSystem { public override void Update(BuffComponent self) { self.Update(); } } public class BuffComponent:Entity { public static BuffComponent instance; public readonly MultiMap buffDic = new MultiMap(); 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 needRemoveList = new List(); private void CheckTimeOut(long now, SortedDictionary> 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 list) { foreach (var buff in list) { #if TEST Test.Log($"{buff.unitId} 失去{(buff.isBuff?"增益":"减益")}:【 {buff.iconDesc} 】"); #endif } } } }