public static void AutoAddBuff(this VTD_BuffInfo self, NP_DataSupportor npDataSupportor, long buffNodeId, Unit theUnitFrom, Unit theUnitBelongTo, NP_RuntimeTree theSkillCanvasBelongTo) { int Layers = 0; if (self.LayersDetermindByBBValue) { Layers = theSkillCanvasBelongTo.GetBlackboard().Get <int>(self.LayersThatDetermindByBBValue.BBKey); } else { Layers = self.Layers; } if (self.LayersIsAbs) { ABuffSystemBase nextBuffSystemBase = BuffFactory.AcquireBuff(npDataSupportor, buffNodeId, theUnitFrom, theUnitBelongTo, theSkillCanvasBelongTo); if (nextBuffSystemBase.CurrentOverlay < nextBuffSystemBase.BuffData.MaxOverlay && nextBuffSystemBase.CurrentOverlay < Layers) { Layers -= nextBuffSystemBase.CurrentOverlay; } else { return; } } for (int i = 0; i < Layers; i++) { BuffFactory.AcquireBuff(npDataSupportor, buffNodeId, theUnitFrom, theUnitBelongTo, theSkillCanvasBelongTo); } }
public void Update() { this.m_Current = m_Buffs.First; //轮询链表 while (this.m_Current != null) { ABuffSystemBase aBuff = this.m_Current.Value; if (aBuff.BuffState == BuffState.Waiting) { aBuff.OnExecute(); } else if (aBuff.BuffState == BuffState.Running) { aBuff.OnUpdate(); this.m_Current = this.m_Current.Next; } else { aBuff.OnFinished(); this.m_Next = this.m_Current.Next; m_Buffs.Remove(this.m_Current); m_BuffsForFind_BuffWorkType.Remove(this.m_Current.Value.BuffData.BuffWorkType); this.m_BuffsForFind_BuffId.Remove(this.m_Current.Value.BuffData.BuffId); // Log.Info( // $"移除一个Buff,Id为{this.m_Current.Value.BuffData.BuffId},BuffManager是否还有?:{this.FindBuffById(this.m_Current.Value.BuffData.BuffId)}"); this.m_Current = this.m_Next; } } }
public static void AutoAddBuff(this VTD_BuffInfo self, long dataId, long buffNodeId, Unit theUnitFrom, Unit theUnitBelongTo, NP_RuntimeTree theSkillCanvasBelongTo) { BuffPoolComponent buffPoolComponent = Game.Scene.GetComponent <BuffPoolComponent>(); int Layers = 0; if (self.LayersDetermindByBBValue) { Layers = theSkillCanvasBelongTo.GetBlackboard().Get <int>(self.LayersThatDetermindByBBValue.BBKey); } else { Layers = self.Layers; } if (self.LayersIsAbs) { ABuffSystemBase nextBuffSystemBase = buffPoolComponent.AcquireBuff(dataId, buffNodeId, theUnitFrom, theUnitBelongTo, theSkillCanvasBelongTo); if (nextBuffSystemBase.CurrentOverlay < nextBuffSystemBase.BuffData.MaxOverlay && nextBuffSystemBase.CurrentOverlay < Layers) { Layers -= nextBuffSystemBase.CurrentOverlay; } else { return; } } for (int i = 0; i < Layers; i++) { buffPoolComponent.AcquireBuff(dataId, buffNodeId, theUnitFrom, theUnitBelongTo, theSkillCanvasBelongTo); } }
/// <summary> /// 计算刷新的持续时间和层数 /// </summary> private static void CalculateTimerAndOverlayHelper(ABuffSystemBase targetBuffSystemBase, BuffDataBase targetBuffDataBase) { //可以叠加,并且当前层数加上要添加Buff的目标层数未达到最高层 if (targetBuffSystemBase.BuffData.CanOverlay) { if (targetBuffSystemBase.CurrentOverlay + targetBuffSystemBase.BuffData.TargetOverlay <= targetBuffSystemBase.BuffData.MaxOverlay) { targetBuffSystemBase.CurrentOverlay += targetBuffSystemBase.BuffData.TargetOverlay; } else { targetBuffSystemBase.CurrentOverlay = targetBuffSystemBase.BuffData.MaxOverlay; } } else { targetBuffSystemBase.CurrentOverlay = 1; } //如果是有限时长的 TODO:这里考虑处理持续时间和Buff层数挂钩的情况(比如磕了5瓶药,就是5*单瓶药的持续时间) if (targetBuffSystemBase.BuffData.SustainTime + 1 > 0) { //Log.Info($"原本结束时间:{temp.MaxLimitTime},续命之后的结束时间{TimeHelper.Now() + buffDataBase.SustainTime}"); targetBuffSystemBase.MaxLimitTime = TimeHelper.Now() + targetBuffDataBase.SustainTime; } }
/// <summary> /// 添加Buff到真实链表,禁止外部调用 /// </summary> /// <param name="aBuff"></param> public void AddBuff(ABuffSystemBase aBuff) { m_Buffs.AddLast(aBuff); this.m_BuffsForFind_BuffWorkType[aBuff.BuffData.BuffWorkType] = aBuff; this.m_BuffsForFind_BuffId[aBuff.BuffData.BuffId] = aBuff; // Log.Info($"把ID为{aBuff.BuffData.BuffId}的buff加入检索表"); }
/// <summary> /// 移除Buff(下一帧才真正移除) /// </summary> /// <param name="buffId">要移除的BuffId</param> public void RemoveBuff(long buffId) { ABuffSystemBase aBuffSystemBase = GetBuffById(buffId); if (aBuffSystemBase != null) { aBuffSystemBase.BuffState = BuffState.Finished; } }
/// <summary> /// 取得Buff,Buff流程是Acquire->OnInit(CalculateTimerAndOverlay)->AddTemp->经过筛选->AddReal /// </summary> /// <param name="buffDataBase">Buff数据</param> /// <param name="theUnitFrom">Buff来源者</param> /// <param name="theUnitBelongTo">Buff寄生者</param> /// <returns></returns> public static ABuffSystemBase AcquireBuff(BuffDataBase buffDataBase, Unit theUnitFrom, Unit theUnitBelongTo, NP_RuntimeTree theSkillCanvasBelongTo) { ABuffSystemBase resultBuff = ReferencePool.Acquire(AllBuffSystemTypes[buffDataBase.BelongBuffSystemType]) as ABuffSystemBase; resultBuff.BelongtoRuntimeTree = theSkillCanvasBelongTo; resultBuff.OnInit(buffDataBase, theUnitFrom, theUnitBelongTo); return(resultBuff); }
/// <summary> /// 回收一个Buff /// </summary> /// <param name="aBuffSystemBase"></param> public void RecycleBuff(ABuffSystemBase aBuffSystemBase) { if (this.BuffSystems.TryGetValue(aBuffSystemBase.GetType(), out Queue <ABuffSystemBase> temp)) { temp.Enqueue(aBuffSystemBase); } else { this.BuffSystems.Add(aBuffSystemBase.GetType(), new Queue <ABuffSystemBase>()); this.BuffSystems[aBuffSystemBase.GetType()].Enqueue(aBuffSystemBase); } }
public override void Run(ABuffSystemBase a) { //Log.Info($"层数判定_通过监听机制添加Buff"); if (a.CurrentOverlay == this.TargetOverlay) { //Log.Info($"直接添加_通过监听机制增加Buff"); foreach (var buffInfo in this.BuffInfoWillBeAdded) { buffInfo.AutoAddBuff(a.BuffData.BelongToBuffDataSupportorId, buffInfo.BuffNodeId.Value, a.TheUnitFrom, a.TheUnitBelongto, a.BelongtoRuntimeTree); } } }
/// <summary> /// 为Buff计算时间和层数 /// </summary> /// <param name="buffSystemBase">Buff逻辑类</param> /// <param name="buffDataBase">Buff数据类</param> /// <typeparam name="A"></typeparam> /// <typeparam name="B"></typeparam> public static void CalculateTimerAndOverlay <A, B>(A buffSystemBase, B buffDataBase) where A : ABuffSystemBase where B : BuffDataBase { BuffManagerComponent buffManagerComponent; buffManagerComponent = buffDataBase.BuffTargetTypes == BuffTargetTypes.Self ? buffSystemBase.TheUnitFrom.GetComponent <BuffManagerComponent>() : buffSystemBase.TheUnitBelongto.GetComponent <BuffManagerComponent>(); //先尝试从真正的Buff链表取得Buff ABuffSystemBase targetBuffSystemBase = buffManagerComponent.GetBuffById(buffDataBase.BuffId); if (targetBuffSystemBase != null) { CalculateTimerAndOverlayHelper(targetBuffSystemBase, buffDataBase); //Log.Info($"本次续命BuffID为{buffDataBase.FlagId},当前层数{temp.CurrentOverlay},最高层为{temp.MSkillBuffDataBase.MaxOverlay}"); buffSystemBase.CurrentOverlay = targetBuffSystemBase.CurrentOverlay; //刷新当前已有的Buff targetBuffSystemBase.OnRefresh(); //TODO 把这个临时的回收,因为已经用不到他了 } else { //尝试从临时Buff字典取 targetBuffSystemBase = buffManagerComponent.GetBuffById_FromTempDic(buffDataBase.BuffId); //如果有,那就计算层数与时间,并且替换临时字典中 if (targetBuffSystemBase != null) { CalculateTimerAndOverlayHelper(targetBuffSystemBase, buffDataBase); //Log.Info($"本次续命BuffID为{buffDataBase.FlagId},当前层数{temp.CurrentOverlay},最高层为{temp.MSkillBuffDataBase.MaxOverlay}"); buffSystemBase.CurrentOverlay = targetBuffSystemBase.CurrentOverlay; //刷新当前已有的Buff targetBuffSystemBase.OnRefresh(); //TODO 把这个临时的回收,因为已经用不到他了 } else//如果没有,那就说明确实没有这个Buff,需要重新加入 { CalculateTimerAndOverlayHelper(buffSystemBase, buffDataBase); //Log.Info($"本次新加BuffID为{buffDataBase.FlagId}"); buffSystemBase.BuffState = BuffState.Waiting; buffManagerComponent.TempBuffsToBeAdded.Add(buffDataBase.BuffId, buffSystemBase); } } }
/// <summary> /// 添加Buff到真是链表,禁止外部调用 /// </summary> /// <param name="aBuff"></param> private void AddBuff2Real(ABuffSystemBase aBuff) { m_Buffs.AddLast(aBuff); if (this.m_BuffsForFind_BuffWorkType.ContainsKey(aBuff.BuffData.BuffWorkType)) { m_BuffsForFind_BuffWorkType[aBuff.BuffData.BuffWorkType] = aBuff; } else { m_BuffsForFind_BuffWorkType.Add(aBuff.BuffData.BuffWorkType, aBuff); } if (this.m_BuffsForFind_BuffId.ContainsKey(aBuff.BuffData.BuffId)) { this.m_BuffsForFind_BuffId[aBuff.BuffData.BuffId] = aBuff; } else { this.m_BuffsForFind_BuffId.Add(aBuff.BuffData.BuffId, aBuff); } // Log.Info($"把ID为{aBuff.BuffData.BuffId}的buff加入检索表"); }
public void Update() { //把Buff从临时列表加入到正式列表 foreach (var tempBuff in this.TempBuffsToBeAdded) { this.AddBuff2Real(tempBuff.Value); } this.TempBuffsToBeAdded.Clear(); this.m_Current = m_Buffs.First; //轮询链表 while (this.m_Current != null) { ABuffSystemBase aBuff = this.m_Current.Value; if (aBuff.BuffState == BuffState.Waiting) { aBuff.OnExecute(); } else if (aBuff.BuffState == BuffState.Running) { aBuff.OnUpdate(); this.m_Current = this.m_Current.Next; } else { aBuff.OnFinished(); this.m_Next = this.m_Current.Next; m_Buffs.Remove(this.m_Current); m_BuffsForFind_BuffWorkType.Remove(this.m_Current.Value.BuffData.BuffWorkType); this.m_BuffsForFind_BuffId.Remove(this.m_Current.Value.BuffData.BuffId); // Log.Info( // $"移除一个Buff,Id为{this.m_Current.Value.BuffData.BuffId},BuffManager是否还有?:{this.FindBuffById(this.m_Current.Value.BuffData.BuffId)}"); this.m_Current = this.m_Next; } } }
/// <summary> /// 为Buff计算时间和层数 /// </summary> /// <param name="buffSystemBase">Buff逻辑类</param> /// <param name="buffDataBase">Buff数据类</param> /// <typeparam name="A"></typeparam> /// <typeparam name="B"></typeparam> public static void CalculateTimerAndOverlay<A, B>(A buffSystemBase, B buffDataBase) where A : ABuffSystemBase where B : BuffDataBase { BuffManagerComponent buffManagerComponent = buffSystemBase.GetBuffTarget().GetComponent<BuffManagerComponent>(); //先尝试从Buff链表取得Buff ABuffSystemBase targetBuffSystemBase = buffManagerComponent.GetBuffById(buffDataBase.BuffId); if (targetBuffSystemBase != null) { CalculateTimerAndOverlayHelper(targetBuffSystemBase, buffDataBase); //Log.Info($"本次续命BuffID为{buffDataBase.FlagId},当前层数{temp.CurrentOverlay},最高层为{temp.MSkillBuffDataBase.MaxOverlay}"); buffSystemBase.CurrentOverlay = targetBuffSystemBase.CurrentOverlay; //刷新当前已有的Buff targetBuffSystemBase.OnRefresh(); } else { CalculateTimerAndOverlayHelper(buffSystemBase, buffDataBase); //Log.Info($"本次新加BuffID为{buffDataBase.FlagId}"); buffSystemBase.BuffState = BuffState.Waiting; buffManagerComponent.AddBuff(buffSystemBase); } }
/// <summary> /// 回收一个Buff /// </summary> /// <param name="aBuffSystemBase"></param> public static void RecycleBuff(ABuffSystemBase aBuffSystemBase) { ReferencePool.Release(aBuffSystemBase); }