Esempio n. 1
0
    ///特殊深度
    ///道具0 CSItem  public virtual Vector3 getPosition()
    ///火墙-10 CSRoundEffect
    ///阴影-20 CSSpriteAnimation SetShodowDepath
    /// <summary>
    /// 每个格子间距的深度距离是100(像素)
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="depthType">0:格子深度 1:格子下面 2:格子深度上面 3 最小格子深度 4:最大格子深度 100-110:最小格子深度下面(x-100)*100
    /// 200-210:最大格子深度上面(x-200)*100</param>
    /// <returns></returns>
    public static int GetDepth(ISfCell cell, int depthType, EAvatarType avatarType = EAvatarType.None)
    {
        //数字越大,层次越低
        if (cell == null)
        {
            return(0);
        }
        int depth = 0;

        if (depthType == 0)
        {
            depth = (int)cell.LocalPosition2.y;
            if (avatarType == EAvatarType.MainPlayer)
            {
                depth -= 10;
            }
            else if (avatarType == EAvatarType.NPC)
            {
                depth -= 8;
            }
            else if (avatarType == EAvatarType.Player)
            {
                depth -= 6;
            }
        }
        else if (depthType == 1)
        {
            depth = (int)cell.LocalPosition2.y + 25;
        }
        else if (depthType == 2)
        {
            depth = (int)cell.LocalPosition2.y - 25;
        }
        else
        {
            ISfCell ss_cell = SFOut.IScene.getiMesh.getCellByISfCell(0, 0);
            ISfCell e_cell  = SFOut.IScene.getiMesh.getCellByISfCell(0, SFOut.IGame.HorizontalCount - 1);
            int     maxY    = (int)Mathf.Min(ss_cell.LocalPosition2.y, e_cell.LocalPosition2.y);
            int     minY    = (int)Mathf.Max(ss_cell.LocalPosition2.y, e_cell.LocalPosition2.y);
            if (depthType == 3)
            {
                depth = minY + 25;
            }
            else if (depthType == 4)
            {
                depth = maxY - 25;
            }
            else if (depthType >= 100 && depthType <= 110)
            {
                depth = minY + (depthType - 100) * 100;
            }
            else if (depthType >= 200 && depthType <= 210)
            {
                depth = maxY - (depthType - 200) * 100;
            }
        }
        depth = depth - 10000;
        return(depth);
    }
Esempio n. 2
0
    /// <summary>
    /// 隔断区域技能寻路问题
    /// </summary>
    /// <param name="start"></param>
    /// <param name="goal"></param>
    /// <param name="isAssist"></param>
    /// <param name="isMainPlayer"></param>
    /// <param name="assistList"></param>
    /// <returns></returns>
    public static CSBetterList <Node> FindPathBySeparate(Node start, Node goal, bool isAssist = false, bool isMainPlayer = false, CSBetterList <Node> assistList = null)
    {
        //SFMisc.Dot2 startCoord = new SFMisc.Dot2(41, 67);
        //SFMisc.Dot2 targetCoord = new SFMisc.Dot2(45, 65);

        //start = CSScene.Sington.Mesh.getNode(startCoord);
        //goal = CSScene.Sington.Mesh.getNode(targetCoord);
        bool isCanCrossScene = SFOut.IGame.isCanCrossScene;
        //isCanCrossScene = false;
        CSBetterList <Node> list = isAssist ? assistList : normalList;

        if (assistList != null)
        {
            list = assistList;
        }
        if (goal == null || start == null || goal.bObstacle || start.bObstacle || goal.coord.Equal(start.coord))
        {
            //Debug.Log("开始或目的点有阻挡点");
            if (list != null)
            {
                list.Clear();
            }
            return(list);
        }
        if (start.cell == null)
        {
            start.cell = SFOut.IScene.getiMesh.getCellByISfCell(start.coord.x, start.coord.y);
        }
        if (goal.cell == null)
        {
            goal.cell = SFOut.IScene.getiMesh.getCellByISfCell(goal.coord.x, goal.coord.y);
        }

        //Debug.Log("start.position=" + start.coord.x + " " + start.coord.y+" goal.position = " + goal.coord.x + " " + goal.coord.y);
        start.parent = null;
        openList.Push(start);

        start.nodeTotalCost = 0.0f;
        start.estimatedCost = HeuristicEstimateCost(start, goal);
        Node node = null;
        CSBetterList <Node> neighbours = new CSBetterList <Node>();

        while (openList.Length != 0)
        {
            node = openList.First();
            node.isInOpenList = false;
            ISfCell cell = SFOut.IScene.getiMesh.getCellByISfCell(node.coord);
            if (cell != null && cell.isAttributesByISFCell((int)SFCellType.Separate))
            {
                string s = "";
            }
            if (node.coord.Equal(goal.coord))
            {
                Reset();
                return(CalculatePath(node));
            }
            neighbours.Clear();
            SFOut.IScene.getiMesh.GetNeighbours(node, neighbours);
            for (int i = 0; i < neighbours.Count; i++)
            {
                Node neighbourNode = (Node)neighbours[i];
                //if (isMainPlayer && isAssist)
                //{
                //    if (!neighbourNode.coord.Equal(goal.coord))
                //    {
                //        if (/*isAssist && */!neighbourNode.isCanCrossNpc) continue;
                //        //if (neighbourNode.avatarNum >= 2) continue;
                //        if (!isCanCrossScene && !neighbourNode.isProtect && neighbourNode.avatarNum > 0 && CSScene.IsLanuchMainPlayer && CSScene.Sington.MainPlayer.MoveState != EMoveState.YeManChongZhuang) continue;
                //    }
                //}
                //if (neighbourNode.bObstacle)
                //{
                //    CSCell cell = CSScene.Sington.Mesh.getCell(neighbourNode.coord);
                //    if (cell != null && cell.isAttributes(MapEditor.CellType.Separate))
                //    {
                //        string s = "";
                //    }
                //}

                if (!neighbourNode.isInClonseList && !neighbourNode.bObstacle)
                {
                    float cost                 = HeuristicCloselyCost(node, neighbourNode);
                    float totalCost            = node.nodeTotalCost + cost;
                    float neighbourNodeEstCost = HeuristicEstimateCost(neighbourNode, goal);

                    if (!neighbourNode.isInOpenList || totalCost < neighbourNode.nodeTotalCost)
                    {
                        neighbourNode.nodeTotalCost = totalCost;
                        neighbourNode.parent        = node;
                        neighbourNode.estimatedCost = totalCost + neighbourNodeEstCost;
                    }
                    if (!neighbourNode.isInOpenList)
                    {
                        neighbourNode.isInOpenList = true;
                        openList.Push(neighbourNode);
                    }
                }
            }
            node.isInClonseList = true;
            closedList.Push(node, false);
            //node.isInOpenList = false;
            //openList.Remove(node);
        }
        Reset();
        if (node.position != goal.position)
        {
            // Debug.LogError("Goal Not Found = " + start.coord.x + "," + start.coord.y + "|" + goal.coord.x + "," + goal.coord.y);
            if (list != null)
            {
                list.Clear();
            }
            return(list);
        }
        return(CalculatePath(node, isAssist));
    }