Esempio n. 1
0
    /// <summary>
    /// 生成行为节点
    /// </summary>
    /// <param name="paramsPacker">数据包装类</param>
    /// <returns>行为节点</returns>
    public override IFormula GetFormula(FormulaParamsPacker paramsPacker)
    {
        IFormula result = null;


        // 替换替换符数据
        ReplaceData(paramsPacker);

        // 数据本地化
        var myFormulaType = FormulaType;
        var myLoopTime    = LoopTime;

        result = new Formula((callback, scope) =>
        {
            if (SubFormulaItem != null)
            {
                var counter = 0;
                // 子集调用
                Action subCallback = null;
                subCallback        = () =>
                {
                    if (counter < myLoopTime)
                    {
                        // 执行子行为链
                        var subSkill = new SkillInfo(paramsPacker.SkillNum);
                        FormulaParamsPackerFactroy.Single.CopyPackerData(paramsPacker, paramsPacker);
                        subSkill.DataList = paramsPacker.DataList;
                        subSkill.AddActionFormulaItem(SubFormulaItem);
                        SkillManager.Single.DoSkillInfo(subSkill, paramsPacker, true, subCallback);
                        counter++;
                    }
                    else
                    {
                        // 结束执行
                        callback();
                    }
                };
                subCallback();
            }
            else
            {
                callback();
            }
        },
                             myFormulaType);

        return(result);
    }
Esempio n. 2
0
    /// <summary>
    /// 生成行为节点
    /// </summary>
    /// <param name="paramsPacker">行为数据</param>
    /// <returns>行为节点类</returns>
    public override IFormula GetFormula(FormulaParamsPacker paramsPacker)
    {
        IFormula result = null;

        // 数据本地化
        var myCondition     = Condition;
        var myConditionArgs = ConditionArgs.Replace(" ", "").Split('_');

        var check = registerCondition[myCondition];

        // 创建行为
        result = new Formula((callback, scope) =>
        {
            // 如果符合条件则执行子级技能
            // 否则继续
            if (check(paramsPacker, myConditionArgs))
            {
                // 获取子级技能
                if (SubFormulaItem != null)
                {
                    // 执行子级技能
                    var subSkill      = new SkillInfo(paramsPacker.SkillNum);
                    subSkill.DataList = paramsPacker.DataList;
                    subSkill.AddActionFormulaItem(SubFormulaItem);
                    SkillManager.Single.DoSkillInfo(subSkill, paramsPacker, true);
                }
            }
            else if (IsBreak > 0)
            {
                // 跳出其后面的所有流程
                result.CanMoveNext = false;
            }
        }, FormulaType);


        return(result);
    }
Esempio n. 3
0
    /// <summary>
    /// 复制技能信息
    /// </summary>
    /// <param name="skillInfo">被复制信息</param>
    /// <returns>复制数据</returns>
    public SkillInfo CopySkillInfo(SkillInfo skillInfo)
    {
        SkillInfo result = null;

        if (skillInfo != null)
        {
            result = new SkillInfo(skillInfo.Num)
            {
                CDGroup           = skillInfo.CDGroup,
                CDTime            = skillInfo.CDTime,
                DataList          = skillInfo.DataList,
                ChangeData        = skillInfo.ChangeData,
                ChangeDataTypeDic = skillInfo.ChangeDataTypeDic,
                Description       = skillInfo.Description,
                Icon                    = skillInfo.Icon,
                ReleaseMember           = skillInfo.ReleaseMember,
                IntervalTime            = skillInfo.IntervalTime,
                ReleaseTime             = skillInfo.ReleaseTime,
                TickTime                = skillInfo.TickTime,
                TriggerLevel1           = skillInfo.TriggerLevel1,
                TriggerLevel2           = skillInfo.TriggerLevel2,
                TriggerProbability      = skillInfo.TriggerProbability,
                DemageChange            = skillInfo.DemageChange,
                DemageChangeProbability = skillInfo.DemageChangeProbability,
                DemageChangeTargetType  = skillInfo.DemageChangeTargetType,
                DemageChangeType        = skillInfo.DemageChangeType,
                IsActive                = skillInfo.IsActive,
                IsDone                  = skillInfo.IsDone,
                ReplaceSourceDataDic    = skillInfo.ReplaceSourceDataDic,
                SkillName               = skillInfo.SkillName
            };
            result.AddActionFormulaItem(skillInfo.GetActionFormulaItem());
        }

        return(result);
    }
Esempio n. 4
0
    /// <summary>
    /// 生成行为单元
    /// </summary>
    /// <returns>行为单元对象</returns>
    public override IFormula GetFormula(FormulaParamsPacker paramsPacker)
    {
        if (paramsPacker == null)
        {
            return(null);
        }
        IFormula result = null;

        // 替换替换符的数据
        ReplaceData(paramsPacker);

        // 数据本地化
        var myReceivePos  = ReceivePos;
        var myTargetCamps = TargetCamps;
        var clusterData   = paramsPacker.ReleaseMember.ClusterData;
        var myFormulaType = FormulaType;
        var myScopeType   = ScopeType;
        var myTargetCount = TargetCount;
        var myIsFollowDir = IsFollowDir;

        // 目标权重筛选数据
        var targetSelectData = TargetSelectDataId > 0 ? new SelectWeightData(SData_armyaim_c.Single.GetDataOfID(TargetSelectDataId)) : null;

        result = new Formula((callback, scope) =>
        {
            // 检测范围
            ICollisionGraphics graphics = null;

            var pos       = Utils.V3ToV2WithouY(GetPosByType(myReceivePos, paramsPacker, scope));
            var plusAngle = 0f;
            if (myIsFollowDir)
            {
                plusAngle = Utils.GetAngleWithZ(clusterData.Direction);
            }
            // 获取图形对象
            switch (myScopeType)
            {
            case GraphicType.Circle:
                // 圆形
                graphics = new CircleGraphics(pos, Arg1);
                break;

            case GraphicType.Rect:
                // 矩形
                graphics = new RectGraphics(pos, Arg1, Arg2, Arg3 + plusAngle);
                break;

            case GraphicType.Sector:
                // 扇形
                graphics = new SectorGraphics(pos, Arg3 + plusAngle, Arg1, Arg2);
                break;
            }

            // 获取周围单位DisplayOwner列表
            var packerList = FormulaParamsPackerFactroy.Single.GetFormulaParamsPackerList(graphics,
                                                                                          paramsPacker.StartPos,
                                                                                          myTargetCamps,
                                                                                          paramsPacker.Skill,
                                                                                          paramsPacker.TargetMaxCount);

            // 根据权重数据筛选目标
            if (targetSelectData != null)
            {
                packerList = TargetSelecter.TargetFilter(targetSelectData, clusterData, packerList);

                // 对他们释放技能(技能编号)
                if (packerList != null)
                {
                    var counter       = 0;
                    var completeCount = 0;
                    var allCount      = packerList.Count;
                    foreach (var packer in packerList)
                    {
                        // 如果设置了数量上限, 并且超过数量上限则跳出
                        if (myTargetCount > 0 && counter >= myTargetCount)
                        {
                            break;
                        }
                        // 执行子行为链
                        if (SubFormulaItem != null)
                        {
                            var subSkill = new SkillInfo(packer.SkillNum);
                            FormulaParamsPackerFactroy.Single.CopyPackerData(paramsPacker, packer);
                            subSkill.DataList = packer.DataList;
                            subSkill.AddActionFormulaItem(SubFormulaItem);
                            //subSkill.GetFormula(packer);
                            SkillManager.Single.DoSkillInfo(subSkill, packer, true, () =>
                            {
                                // 执行完成, 回调
                                completeCount++;
                                if (completeCount >= myTargetCount || completeCount >= allCount)
                                {
                                    callback();
                                }
                            });
                        }
                        counter++;
                    }
                }
            }
        }, myFormulaType);


        return(result);
    }
Esempio n. 5
0
    /// <summary>
    /// 获取行为节点
    /// </summary>
    /// <param name="paramsPacker">目标数据</param>
    /// <returns>滑动碰撞检测行为节点</returns>
    public override IFormula GetFormula(FormulaParamsPacker paramsPacker)
    {
        if (Speed < Utils.ApproachZero)
        {
            throw new Exception("滑动碰撞检测的速度不能小于等于0");
        }

        // 替换数据
        ReplaceData(paramsPacker);

        // 数据本地化
        var mySpeed       = Speed;
        var myCheckTime   = CheckTime;
        var myLength      = Length;
        var myTargetCamps = TargetCamps;
        var myFormulaType = FormulaType;
        var myTargetPos   = TargetPos;
        var myStartPos    = StartPos;

        var clusterData = paramsPacker.ReleaseMember.ClusterData;

        // 上一次列表
        List <FormulaParamsPacker>  prvPackerList = new List <FormulaParamsPacker>();
        IList <FormulaParamsPacker> tmpPackerList = null;

        IFormula result = new Formula((callback, scope) =>
        {
            // 当前长度
            var nowLength = 0f;

            // 目标点
            var targetPos = GetPosByType(myTargetPos, paramsPacker, scope);
            // 起始点
            var startPos = GetPosByType(myStartPos, paramsPacker, scope);

            // 计时器
            var timer = new Timer(myCheckTime, true);
            // 计时器行为
            Action completeCallback = () =>
            {
                // 是否到达目标
                if (nowLength < Length)
                {
                    // 搜索位置+1
                    nowLength += mySpeed;
                    // 从发射位置向目标位置一节一节搜索目标
                    // 速度影响单次搜索的长度
                    var diffPos = targetPos - startPos;
                    var pos     = (diffPos) * nowLength / myLength + startPos;
                    // 创建图形
                    var diffPosNoY = new Vector3(diffPos.x, 0, diffPos.z);
                    // 求旋转角度
                    var rotation = Vector3.Angle(Vector3.forward, diffPosNoY);
                    // 求旋转方向
                    float dir = (Vector3.Dot(Vector3.up, Vector3.Cross(Vector3.forward, diffPosNoY)) < 0 ? 1 : -1);
                    // 获得图形
                    var graphics = new RectGraphics(new Vector2(pos.x, pos.z), Width, mySpeed, rotation * dir);
                    Utils.DrawGraphics(graphics, Color.white);
                    // 搜索当前节范围内的单位
                    tmpPackerList = FormulaParamsPackerFactroy.Single.GetFormulaParamsPackerList(graphics,
                                                                                                 startPos,
                                                                                                 myTargetCamps,
                                                                                                 paramsPacker.Skill,
                                                                                                 paramsPacker.TargetMaxCount);

                    // 执行子技能
                    if (tmpPackerList != null && tmpPackerList.Count > 0 && SubFormulaItem != null)
                    {
                        // 排除不可选择目标
                        for (var i = 0; i < tmpPackerList.Count; i++)
                        {
                            var nowPacker = tmpPackerList[i];
                            if (!TargetSelecter.CouldSelectTarget(clusterData, nowPacker.ReceiverMenber.ClusterData))
                            {
                                tmpPackerList.RemoveAt(i);
                                i--;
                            }
                        }

                        // 排除上次被攻击过的目标
                        bool isExist;
                        for (var j = 0; j < prvPackerList.Count; j++)
                        {
                            isExist       = false;
                            var prvPacker = prvPackerList[j];
                            // 判断是否存在上次被攻击的对象
                            // 从列表中删除重复对象
                            for (var i = 0; i < tmpPackerList.Count; i++)
                            {
                                var nowPacker = tmpPackerList[i];
                                if (prvPacker.ReceiverMenber.Equals(nowPacker.ReceiverMenber))
                                {
                                    // 删除本次攻击中上次攻击存在的单位
                                    tmpPackerList.RemoveAt(i);
                                    i--;
                                    isExist = true;
                                    break;
                                }
                            }

                            // 删除上次攻击中本次攻击不存在的单位
                            if (!isExist)
                            {
                                prvPackerList.RemoveAt(j);
                                j--;
                            }
                        }

                        prvPackerList.AddRange(tmpPackerList);

                        foreach (var packer in tmpPackerList)
                        {
                            var subSkill = new SkillInfo(packer.SkillNum);
                            FormulaParamsPackerFactroy.Single.CopyPackerData(paramsPacker, packer);
                            subSkill.DataList = paramsPacker.DataList;
                            subSkill.AddActionFormulaItem(SubFormulaItem);
                            //subSkill.GetFormula(packer);
                            SkillManager.Single.DoSkillInfo(subSkill, packer, true);
                        }
                    }
                }
                else
                {
                    // 结束计时
                    timer.Kill();
                    // 完成回调
                    callback();
                }
            };

            timer.OnCompleteCallback(completeCallback);
            timer.Start();
        }, myFormulaType);

        return(result);
    }
Esempio n. 6
0
    /// <summary>
    /// 生成行为节点
    /// </summary>
    /// <param name="paramsPacker"></param>
    /// <returns></returns>
    public override IFormula GetFormula(FormulaParamsPacker paramsPacker)
    {
        IFormula result = null;

        // 替换数据
        ReplaceData(paramsPacker);
        // 数据本地化
        var myFormulaType            = FormulaType;
        var myResistDemage           = ResistDemage;
        var myResistPercentage       = ResistPercentage;
        var myIsResistOverflowDemage = IsResistOverflowDemage;
        var mySkill   = paramsPacker.Skill;
        var myTrigger = paramsPacker.TriggerData;

        result = new Formula((callback, scope) =>
        {
            callback();
        },
                             myFormulaType);

        Debug.Log("构造伤害吸收行为");
        if (mySkill.DataScope.GetFloat("ResistDemage") == null)
        {
            // 缓存数据
            mySkill.DataScope.SetFloat("ResistDemage", myResistDemage);
            mySkill.DataScope.SetFloat("AllResistDemage", myResistDemage);
        }
        Debug.Log("当前生命值变动量:" + myTrigger.HealthChangeValue);

        // 无伤害可吸收
        if (myTrigger.HealthChangeValue <= 0)
        {
            return(result);
        }
        var nowCouldResistDemage = mySkill.DataScope.GetFloat("ResistDemage");

        // 伤害吸收结束
        if (nowCouldResistDemage <= 0)
        {
            return(result);
        }
        var needResistDemage    = myTrigger.HealthChangeValue * myResistPercentage;
        var absNeedRessitDemage = Math.Abs(needResistDemage);

        if (nowCouldResistDemage != null)
        {
            if (absNeedRessitDemage > nowCouldResistDemage)
            {
                if (myIsResistOverflowDemage)
                {
                    myTrigger.HealthChangeValue = 0;
                }
                else
                {
                    myTrigger.HealthChangeValue -= nowCouldResistDemage.Value;
                }
                // 清空伤害吸收
                mySkill.DataScope.SetFloat("ResistDemage", 0);
            }
            else
            {
                Debug.Log("吸收伤害");
                myTrigger.HealthChangeValue -= needResistDemage;
                nowCouldResistDemage        -= absNeedRessitDemage;

                Debug.Log("剩余伤害:" + myTrigger.HealthChangeValue);
                // 设置剩余伤害量
                mySkill.DataScope.SetFloat("ResistDemage", nowCouldResistDemage.Value);
            }

            // 判断是否到达伤害吸收上限
            if (nowCouldResistDemage == 0)
            {
                // 执行子级技能
                if (SubFormulaItem != null)
                {
                    var packer = new FormulaParamsPacker();
                    FormulaParamsPackerFactroy.Single.CopyPackerData(paramsPacker, packer);
                    var subSkill = new SkillInfo(packer.SkillNum);
                    subSkill.DataList = packer.DataList;
                    subSkill.AddActionFormulaItem(SubFormulaItem);
                    SkillManager.Single.DoSkillInfo(subSkill, packer, true);
                }
            }
            // 伤害被吸收
            myTrigger.IsAbsorption = true;
        }

        return(result);
    }