public virtual bool Teleport(MapNeighbour mapNeighbour) { var neighbour = Position.Map.GetNeighbouringMap(mapNeighbour); if (neighbour == null) { return(false); } var cell = Position.Map.GetCellAfterChangeMap(Position.Cell.Id, mapNeighbour); if (cell < 0 || cell >= 560) { logger.Error("Cell {0} out of range, current={1} neighbour={2}", cell, Cell.Id, mapNeighbour); return(false); } var destination = new ObjectPosition(neighbour, cell, Position.Direction); if (!destination.Cell.Walkable) { var cells = MapPoint.GetBorderCells(mapNeighbour).Select(x => neighbour.Cells[x.CellId]).Where(x => x.Walkable); var walkableCell = cells.Select(x => new MapPoint(x)).OrderBy(x => x.EuclideanDistanceTo(destination.Point)).FirstOrDefault(); if (walkableCell != null) { destination.Cell = neighbour.Cells[walkableCell.CellId]; } } return(Teleport(destination)); }