예제 #1
0
    /// <summary>
    /// 是否可以技能攻击
    /// </summary>
    /// <param name="fsm"></param>
    /// <param name="res">目标列表</param>
    /// <returns></returns>
    public static bool CheckSkill(SoldierFSMSystem fsm, IList <PositionObject> res)
    {
        var result = false;

        // 判断主动技能是否可释放, 可释放则释放技能, 否则普通攻击
        var skillInfoList = fsm.Display.ClusterData.AllData.SkillInfoList;

        if (skillInfoList.Count > 0)
        {
            // 判断技能CD的长短, 释放技能最长的
            foreach (var skill in skillInfoList)
            {
                // 技能目标选择器
                // 是否为主动技能
                // 技能没有在CD中
                if (!skill.IsActive ||
                    CDTimer.Instance().IsInCD(skill.Num, fsm.Display.ClusterData.AllData.MemberData.ObjID.ID, skill.CDGroup))
                {
                    continue;
                }
                // 判断技能是否符合释放条件(范围内有适合的单位)
                if (skill.WeightData != null)
                {
                    res = TargetSelecter.TargetFilter(skill.WeightData, skill.ReleaseMember.ClusterData, res);
                }

                if (res != null && res.Count > 0)
                {
                    fsm.Skill = skill;
                    result    = true;
                    break;
                }
            }
        }

        if (result)
        {
            // 确定释放技能, 设置目标
            //System.Random ran = new System.Random();
            var target = res[0];
            fsm.EnemyTarget = DisplayerManager.Single.GetElementByPositionObject(target);
        }

        return(result);
    }
예제 #2
0
    ///// <summary>
    ///// 检测条件
    ///// </summary>
    ///// <param name="fsm"></param>
    ///// <returns></returns>
    //public override bool CheckTrigger(SoldierFSMSystem fsm)
    //{
    //    return Check(fsm);
    //}



    public static bool Check(SoldierFSMSystem fsm)
    {
        switch (fsm.CurrentStateID)
        {
        // 行进切追击
        case SoldierStateID.Xingjin:
        {
            // 如果正在技能攻击或普通攻击则不进入追击状态
            if (fsm.IsCanInJinenggongji || fsm.IsCanInPutonggongji)
            {
                return(false);
            }
            var clusterData = fsm.Display.ClusterData;
            //var objId = clusterData.MemberData.ObjID;
            // 视野范围内是否有敌人
            var pos = new Vector2(clusterData.X, clusterData.Y);
            // 范围内符合阵营条件的单位列表
            var scopeMemberList = ClusterManager.Single.CheckRange(pos, clusterData.AllData.MemberData.SightRange,
                                                                   clusterData.AllData.MemberData.Camp, true);
            // 按照权重与是否可攻击单位选择
            var filtedlist = TargetSelecter.TargetFilter(clusterData, scopeMemberList);
            Utils.DrawGraphics(new CircleGraphics(pos, clusterData.AllData.MemberData.SightRange), Color.yellow);
            //fsm.Display.ClusterData.MemberData.SightRange
            if (filtedlist != null && filtedlist.Count > 0)
            {
                // 追击目标
                // 设置状态 切追击状态
                fsm.IsZhuiJi = true;
                return(SetTarget(fsm, filtedlist));
            }

            return(fsm.IsZhuiJi);
        }
        }

        return(false);
    }
예제 #3
0
    /// <summary>
    /// 检查普通攻击
    /// </summary>
    /// <param name="fsm"></param>
    /// <returns></returns>
    public static bool CheckNormalAttack(SoldierFSMSystem fsm)
    {
        var searchData = fsm.Display.ClusterData;
        // 攻击范围内是否有敌人
        var checkPos = new Vector2(fsm.Display.ClusterData.X, fsm.Display.ClusterData.Y);
        // 目标选择器选择目标列表
        var list = TargetSelecter.TargetFilter(searchData,
                                               ClusterManager.Single.CheckRange(checkPos, searchData.AllData.MemberData.AttackRange, searchData.AllData.MemberData.Camp, true));

        Utils.DrawGraphics(new CircleGraphics(checkPos, searchData.AllData.MemberData.AttackRange), Color.yellow);
        if (list != null && list.Count > 0)
        {
            // 攻击目标
            fsm.TargetIsLoseEfficacy = false;
            // 检测普通攻击
            if (SetTarget(fsm, list))
            {
                fsm.IsCanInJinenggongji = false;
                fsm.IsCanInPutonggongji = true;
                return(true);
            }
        }
        return(false);
    }
예제 #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);
    }