示例#1
0
    /// <summary>
    /// buff的Attach事件
    /// </summary>
    /// <param name="buffInfo">buff数据</param>
    /// <param name="buffDoType">buff执行类型</param>
    /// <param name="paramsPacker"></param>
    public void DoBuff([NotNull] BuffInfo buffInfo, BuffDoType buffDoType, [NotNull] FormulaParamsPacker paramsPacker)
    {
        if (buffInfo.ReleaseMember == null || buffInfo.ReceiveMember == null)
        {
            throw new Exception("参数错误.");
        }

        IFormula formula = null;

        switch (buffDoType)
        {
        case BuffDoType.Action:
            formula = buffInfo.GetActionFormula(paramsPacker);
            break;

        case BuffDoType.Attach:

            // 互斥或叠加或共存的检测流程
            if (BuffAttachRule(buffInfo.ReceiveMember.ClusterData.AllData.BuffInfoList, buffInfo))
            {
                // 设置buff启动时间
                buffInfo.BuffStartTime = DateTime.Now.Ticks;
                formula = buffInfo.GetAttachFormula(paramsPacker);
                // 判断是否需要将buff放入TriggerTicker中
                if (buffInfo.BuffTime > Utils.ApproachZero)
                {
                    TriggerTicker.Single.Add(buffInfo);
                }
                buffInfo.ReceiveMember.ClusterData.AllData.BuffInfoList.Add(buffInfo);
                // 如果buff增加属性, 则将属性加入对象中
                SkillBase.AdditionAttribute(buffInfo.ReceiveMember.ClusterData.AllData.MemberData, buffInfo);
            }
            break;

        case BuffDoType.Detach:
            //Debug.Log("Buff Detach:" + buffInfo.AddtionId);
            buffInfo.ReceiveMember.ClusterData.AllData.BuffInfoList.Remove(buffInfo);
            formula = buffInfo.GetDetachFormula(paramsPacker);
            // 检查TriggerTicker中是否有该buff, 如果有则删除
            TriggerTicker.Single.Remove(buffInfo.AddtionId);

            // 如果buff增加了属性, 则将属性从对象属性中删除
            SkillBase.SubAttribute(buffInfo.ReceiveMember.ClusterData.AllData.MemberData, buffInfo.ChangedData);
            // 从buff列表中删除buff实例
            DelBuffInstance(buffInfo.AddtionId);
            break;
        }
        SkillManager.Single.DoFormula(formula);
    }