public bool AddBuff(ISkill skill, int buffId) { SkillUtil.LogWarning(string.Format(" [BUFFMANAGER] [NAME]->{0} AddBuff-> {1}", this.mContext.GetSelfActor().GetTransform().name, buffId)); IBuff buff = null; bool canModify = true; float life = 0; if (this.buffMap.ContainsKey(buffId)) { buff = this.buffMap[buffId]; canModify = buff is IOverLayBuff; /*Buff * 1.已经拥有 2.有持续时间 3.不可叠加 * -》直接刷新Buff的持续时间(Life) */ if (!canModify) { RefreshTimerLife(buff); } } else { var data = SkillUtil.GetSkillBuffData(buffId); bool isOverLay = data.Attributes.Contains((int)BuffAttributes.CanAdd); buff = isOverLay ? new OverlayBuff() : new Buff(); buff.Create(skill, mContext.GetSelfActor(), buffId); this.buffMap.Add(buffId, buff); } if (canModify) //只有新加的和可叠加的Buff才能触发Modify { this.BuffModify(buffId); //1.先判定这个Buff 是不是一个循环定时器 if (!this.TryAddLoopTimer(buffId)) { life = buff.GetDuringTime(); if (life > 0) { /* 可以执行到此处满足的条件: * 1.不是循环定时器 2.有效的Buff生命周期life 3.可以叠加效果的老BUFF或者刚刚添加的新BUFF * =》生成一个新的计时器 */ CreateNormalTimer(life, buffId); } } } this.OnBuffEventDispatch(BuffActionType.AddBuff); return(true); }
private void RefreshTimerLife(IBuff buff) { int buffId = buff.GetBuffId(); if (buffTimerMap.ContainsKey(buffId)) { int timerId = GetTimerId(buffId, true); float life = buff.GetDuringTime(); timerService.RefreshTimerLife(timerId, life); } }