Esempio n. 1
0
        /// <summary>
        /// Gets a collection of pathfinder nodes to this creature. Returns an empty IEnumerable if unreachable.
        /// </summary>
        /// <param name="tileCollection">The list of tiles on screen to use for pathfinding.</param>
        /// <param name="pathFinder">The PathFinder object to use.</param>
        /// <returns></returns>
        public IEnumerable <Objects.PathFinder.Node> GetTilesToCreature(Map.TileCollection tileCollection,
                                                                        Objects.PathFinder pathFinder)
        {
            if (pathFinder == null)
            {
                return(Enumerable.Empty <Objects.PathFinder.Node>());
            }

            if (this.Location.IsAdjacentTo(this.Client.Player.Location))
            {
                return(new List <Objects.PathFinder.Node>()
                {
                    new Objects.PathFinder.Node()
                    {
                        X = 8, Y = 6
                    }
                });
            }
            if (!this.Location.IsOnScreen(this.Client.Player.Location))
            {
                return(Enumerable.Empty <Objects.PathFinder.Node>());
            }
            uint playerZ = this.Client.Player.Z;

            if (tileCollection.IsEmpty())
            {
                return(Enumerable.Empty <Objects.PathFinder.Node>());
            }
            Map.Tile playerTile   = tileCollection.GetTile(count: this.Client.Player.ID);
            Map.Tile creatureTile = tileCollection.GetTile(count: this.ID);
            if (playerTile == null || creatureTile == null)
            {
                return(Enumerable.Empty <Objects.PathFinder.Node>());
            }
            lock (pathFinder)
            {
                pathFinder.ResetGrid();
                foreach (Map.Tile tile in tileCollection.GetTiles())
                {
                    if (tile == null)
                    {
                        continue;
                    }

                    if (!tile.IsWalkable())
                    {
                        pathFinder.Grid[tile.MemoryLocation.X, tile.MemoryLocation.Y] = (byte)Enums.MiniMapSpeedValues.Unwalkable;
                    }
                    else
                    {
                        pathFinder.Grid[tile.MemoryLocation.X, tile.MemoryLocation.Y] = 1;
                    }
                }
                pathFinder.Grid[playerTile.MemoryLocation.X, playerTile.MemoryLocation.Y]     = 1;
                pathFinder.Grid[creatureTile.MemoryLocation.X, creatureTile.MemoryLocation.Y] = 1;
                return(pathFinder.FindPath(playerTile.MemoryLocation, creatureTile.MemoryLocation, true));
            }
        }
Esempio n. 2
0
        /// <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));
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Checks whether this location can reach another location.
 /// </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>
 /// <returns></returns>
 public bool CanReachLocation(Objects.Client c, Location loc,
                              Map.TileCollection tiles, Objects.PathFinder pathFinder)
 {
     return(this.GetTilesToLocation(c, loc, tiles, pathFinder, false).ToArray <Objects.PathFinder.Node>().Length > 0);
 }
Esempio n. 4
0
 /// <summary>
 /// Checks whether this creature is reachable.
 /// </summary>
 /// <param name="tileCollection">The tiles on screen to use for pathfinding.</param>
 /// <param name="pathFinder">The pathfinder to use.</param>
 /// <returns></returns>
 public bool IsReachable(Map.TileCollection tileCollection, Objects.PathFinder pathFinder)
 {
     return(this.GetTilesToCreature(tileCollection, pathFinder).ToList <Objects.PathFinder.Node>().Count > 0);
 }