Esempio n. 1
0
    private static List <MapGrid> Search(MapGrid startN, MapGrid endN)
    {
        //同层则互为SpecialsStation,同时计算权值
        if (startN.GridPos.Layer == endN.GridPos.Layer && MapGrid.CheckLink(startN, endN))
        {
            startN.pNearestSpecialStation = endN;
            startN.fNearestSpecialscoreG  = Mathf.Abs(startN.GridPos.Unit - endN.GridPos.Unit) * 0.5f;
        }
        MapGrid currentNode = AstarSearch(startN, endN);
        //trace back the path through closeList
        List <MapGrid> listMapgrid = new List <MapGrid>();

        if (currentNode != null)
        {
            while (currentNode != null)
            {
                listMapgrid.Add(currentNode);
                MapGrid preGrid = currentNode.preNode;
                if (null != preGrid && currentNode.GridPos.Layer == preGrid.GridPos.Layer)
                {
                    if (currentNode.GridPos.Unit < preGrid.GridPos.Unit)
                    {
                        currentNode = currentNode.Right;
                        while (currentNode != null && currentNode != preGrid)
                        {
                            listMapgrid.Add(currentNode);
                            currentNode = currentNode.Right;
                        }
                    }
                    else
                    {
                        currentNode = currentNode.Left;
                        while (currentNode != null && currentNode != preGrid)
                        {
                            listMapgrid.Add(currentNode);
                            currentNode = currentNode.Left;
                        }
                    }
                }
                else
                {
                    currentNode = preGrid;
                }
            }
            listMapgrid.Reverse();
        }
        ResetGraph();
        return(listMapgrid);
    }
Esempio n. 2
0
    public virtual bool CheckDoAttackTarget(Life target, int Sort, int distant, bool isusedir = true)
    {
        if (target == null || target.isDead)
        {
            return(false);
        }
        //确认目标在行走路线上。
        Life life = CM.GetAllLifeM(m_SceneID, LifeMType.SOLDIER | LifeMType.SUMMONPET) as Role;

        if (life == null)
        {
            return(false);
        }

        float radius = distant;//PropSkillInfo.m_distance/MapGrid.m_Pixel;

        //攻击距离为0的时候是全屏攻击范围
        if (radius <= 0)
        {
            return(true);
        }
        if (!life.m_Attr.IsHide && isusedir && (life as Role).run.CheckInRoad(target.GetMapPos()) == false)
        {
            return(false);
        }
        //单人
        //if (Sort == 1)
        {
            Life l = CM.GetAllLifeM(m_SceneID, LifeMType.SOLDIER | LifeMType.SUMMONPET);
            if (l is Role)
            {
                Role    parent = l as Role;
                WalkDir pdir   = parent.WalkDir;

                List <MapGrid> allg = target.GetAllMapGrid();
                if (!NdUtil.IsLifeSampMapLayer(target, parent.GetMapPos()))
                {
                    bool link = false;
                    foreach (MapGrid g in allg)
                    {
                        if (MapGrid.CheckLink(parent.GetMapGrid(), g))
                        {
                            link = true;
                        }
                    }
                    if (!link)
                    {
                        return(false);
                    }
                }
                List <IggWall> lw = new List <IggWall>();
                MapGrid.GetWallList(ref lw, parent.GetMapPos(), target.GetMapPos());
                foreach (IggWall w in lw)
                {
                    if (!w.Open)
                    {
                        return(false);
                    }
                }
                //radius += parent.m_Attr.Radius;
                float x1 = parent.m_thisT.localPosition.x;

                /*MapGrid g = MapGrid.GetMG(target.GetMapPos());
                 * if (g == null)
                 * {
                 *      //Debug.LogError(target + "," + target.GetMapPos() + "," + target.InBoat);
                 *      return false;
                 * }*/
                //float x2 = 0;//g.pos.x;
                List <float> lx2 = new List <float>();
                foreach (MapGrid g in allg)
                {
                    lx2.Add(g.pos.x);
                }
                if (target is Role)
                {
                    //radius += (int)(target as Role).m_Attr.Radius;
                    lx2[0] = target.m_thisT.localPosition.x;

                    /*if (target.WalkDir == WalkDir.WALKLEFT)
                     *  x2 -= target.RankDeep * Role.s_deepoffset;
                     * else
                     *  x2 += target.RankDeep * Role.s_deepoffset;*/

                    if (target.RankDeep > 0)
                    {
                        lx2[0] = target.GetMapGrid().pos.x;
                    }
                    if (distant == 3 && target.WalkDir != l.WalkDir)
                    {
                        if ((target as Role).RoleWalk != null)
                        {
                            lx2[0] = (target as Role).RoleWalk.run.GetAttackStationMapGrid().pos.x;
                        }
                    }
                }
                if (parent.m_Attr.IsHide && target is Role)
                {
                    if (target.WalkDir == WalkDir.WALKLEFT)
                    {
                        MapGrid lg = target.GetMapGrid().Right;
                        while (lg != null)
                        {
                            if (lg.Type == GridType.GRID_NORMAL)
                            {
                                if (lg.IsAttackStations())
                                {
                                    List <int> samelist   = new List <int>();
                                    List <int> unsamelist = new List <int>();
                                    lg.GetCampRoleList(parent.m_Core.m_Camp, ref samelist, ref unsamelist);
                                    if (unsamelist.Count <= 0)
                                    {
                                        pdir    = target.WalkDir;
                                        lx2[0] += 1f;
                                    }
                                    break;
                                }
                                else
                                {
                                    lg = lg.Right;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    else if (target.WalkDir == WalkDir.WALKRIGHT)
                    {
                        MapGrid rg = target.GetMapGrid().Left;
                        while (rg != null)
                        {
                            if (rg.Type == GridType.GRID_NORMAL)
                            {
                                if (rg.IsAttackStations())
                                {
                                    List <int> samelist   = new List <int>();
                                    List <int> unsamelist = new List <int>();
                                    rg.GetCampRoleList(parent.m_Core.m_Camp, ref samelist, ref unsamelist);
                                    if (unsamelist.Count <= 0)
                                    {
                                        pdir    = target.WalkDir;
                                        lx2[0] -= 1f;
                                    }
                                    break;
                                }
                                else
                                {
                                    rg = rg.Left;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                if (l.RankDeep > 0)
                {
                    x1 = l.GetMapGrid().pos.x;
                }
                radius += target.RankDeep * Role.s_deepoffset + l.RankDeep * Role.s_deepoffset;
                if (target is IggWall)
                {
                    radius += 1;
                }
                radius += 0.5f;
                if (isusedir)
                {
                    if (pdir == WalkDir.WALKLEFT)
                    {
                        foreach (float x2 in lx2)
                        {
                            if (x1 >= x2 && (x1 - x2) <= (radius * MapGrid.m_width))
                            {
                                return(true);
                            }
                        }
                    }
                    else if (pdir == WalkDir.WALKRIGHT)
                    {
                        foreach (float x2 in lx2)
                        {
                            if (x1 <= x2 && (x2 - x1) <= (radius * MapGrid.m_width))
                            {
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        foreach (float x2 in lx2)
                        {
                            if (Mathf.Abs(x1 - x2) < radius * MapGrid.m_width)
                            {
                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    foreach (float x2 in lx2)
                    {
                        if (Mathf.Abs(x1 - x2) < radius * MapGrid.m_width)
                        {
                            return(true);
                        }
                    }
                }
            }
        }
        return(false);
    }