Exemplo n.º 1
0
        public HashList <GraphNode> GetDistanceRange(Vector3 pos, float distance, Func <GraphNode, bool> filter = null)
        {
            BFSQueue.Clear();
            BFSResult.Clear();
            BFSRange.Clear();
            var       depth = distance / NodeSize;
            GraphNode seed  = GetNode(pos);
            Action <GraphNodeRange, GraphNode> callback = (parent, node) =>
            {
                if (node.Walkable && !BFSResult.Contains(node))
                {
                    if (filter != null && !filter(node))
                    {
                        return;
                    }
                    var nRangeItem = new GraphNodeRange(parent, node);
                    if (nRangeItem.Distance > distance)
                    {
                        return;
                    }
                    if (nRangeItem.Depth > depth)
                    {
                        return;
                    }

                    BFSResult.Add(node);
                    BFSQueue.Enqueue(node);
                    BFSRange.Add(node, nRangeItem);
                }
            };

            callback(null, seed);

            while (BFSQueue.Count > 0)
            {
                GraphNode      n          = BFSQueue.Dequeue();
                GraphNodeRange nRangeItem = BFSRange[n];
                if (nRangeItem.Distance > distance)
                {
                    break;
                }
                if (nRangeItem.Depth > depth)
                {
                    break;
                }
                n.GetConnections((x) =>
                {
                    callback(nRangeItem, x);
                });
            }
            return(BFSResult);
        }
Exemplo n.º 2
0
 public bool IsRope(string id)
 {
     if (Rope.Contains(id))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
 public bool IsBlocker(TNode node)
 {
     if (node == null)
     {
         return(false);
     }
     if (AllBlockers.Contains(node))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
        //移动范围是否可以链接到目标
        public bool IsCanConstantConnection(BaseUnit unit)
        {
            if (ConstantNodesMove == null || ConstantNodesMove.Count == 0)
            {
                return(false);
            }
            HashList <GraphNode> links = AStarMgr.GetConnectionsBlocker(unit);

            foreach (var item in links)
            {
                if (ConstantNodesMove.Contains(item))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        //当前Unit的node是否可以连接到目标Unit的Blocker范围内,一般可以用来做攻击检测
        public bool IsInBlockerRange(BaseUnit unit)
        {
            HashList <GraphNode> connection = new HashList <GraphNode>();

            CurNode.GetConnections(connection.Add);
            HashList <GraphNode> targetUnitBlocker = AStarMgr.GetBlocker(unit);

            if (targetUnitBlocker != null)
            {
                foreach (var item in targetUnitBlocker)
                {
                    if (connection.Contains(item))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                CLog.Error("{0}:目标单位没有Blocker", unit.BaseConfig.GetName());
            }
            return(false);
        }