当前位置: 首页>>代码示例>>C#>>正文


C# Objects.FindPath方法代码示例

本文整理汇总了C#中System.Objects.FindPath方法的典型用法代码示例。如果您正苦于以下问题:C# Objects.FindPath方法的具体用法?C# Objects.FindPath怎么用?C# Objects.FindPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Objects的用法示例。


在下文中一共展示了Objects.FindPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTilesToLocation

        /// <summary>
        /// Gets a collection of pathfinder nodes to a given location. Returns 0 elements if unsuccessful.
        /// </summary>
        /// <param name="c">The client to perform the operation on.</param>
        /// <param name="loc">The location to reach.</param>
        /// <param name="tiles">A list of tiles to use for pathfinding.</param>
        /// <param name="pathFinder">The pathfinder to use.</param>
        /// <param name="considerPlayerWalkable">Whether to consider the player as walkable.</param>
        /// <param name="considerCreatureOnLocationWalkable">Whether to consider any creatures on the target location as walkable.</param>
        /// <returns></returns>
        public IEnumerable<Objects.PathFinder.Node> GetTilesToLocation(Objects.Client c,
            Location loc, Map.TileCollection tiles, Objects.PathFinder pathFinder,
            bool considerPlayerWalkable = false, bool considerCreatureOnLocationWalkable = false)
        {
            if (pathFinder == null) return Enumerable.Empty<Objects.PathFinder.Node>();
            //return pathFinder.

            if (!this.IsOnScreen(c.Player.Location)) return Enumerable.Empty<Objects.PathFinder.Node>();

            uint playerId = c.Player.ID;
            Map.Tile playerTile = tiles.GetTile(count: playerId);
            Map.Tile fromTile = tiles.GetTile(this);
            Map.Tile targetTile = tiles.GetTile(loc);
            if (playerTile == null || fromTile == null || targetTile == null) return Enumerable.Empty<Objects.PathFinder.Node>();

            // check if target tile is walkable
            if (!targetTile.IsWalkable() && (!considerPlayerWalkable || targetTile != playerTile)) return Enumerable.Empty<Objects.PathFinder.Node>();
            if (fromTile == targetTile) return Enumerable.AsEnumerable(new Objects.PathFinder.Node[] { new Objects.PathFinder.Node() });
            lock (pathFinder)
            {
                pathFinder.ResetGrid();
                foreach (Map.Tile tile in tiles.GetTiles())
                {
                    if (tile == null) continue;

                    if ((considerPlayerWalkable && tile == playerTile) || tile.IsWalkable()) pathFinder.Grid[tile.MemoryLocation.X, tile.MemoryLocation.Y] = 1;
                    else pathFinder.Grid[tile.MemoryLocation.X, tile.MemoryLocation.Y] = (byte)Enums.MiniMapSpeedValues.Unwalkable;
                }
                pathFinder.Grid[fromTile.MemoryLocation.X, fromTile.MemoryLocation.Y] = 1;
                return pathFinder.FindPath(fromTile.MemoryLocation, targetTile.MemoryLocation);
            }
        }
开发者ID:KyLuaa,项目名称:bot,代码行数:42,代码来源:Location.cs


注:本文中的System.Objects.FindPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。