private List <Point> GetPath(uint mapId, Difficulty difficulty, Area area, AreaMap map, MovementMode movementMode, Point fromLocation, Point toLocation) { if (!map.TryMapToPointInMap(fromLocation, out var fromPosition) || !map.TryMapToPointInMap(toLocation, out var toPosition)) { return(new List <Point>()); } if (movementMode == MovementMode.Teleport) { var teleportPath = new TeleportPather(map); var path = teleportPath.GetTeleportPath(fromLocation - map.LevelOrigin, toLocation - map.LevelOrigin); if (path.Found) { return(path.Points.Select(p => map.LevelOrigin + p).Skip(1).ToList()); } } else { var grid = _cache.GetOrCreate <Grid>(Tuple.Create("pathing", mapId, difficulty, area), (cacheEntry) => { cacheEntry.SlidingExpiration = TimeSpan.FromMinutes(2); return(map.MapToGrid()); }); var pathFinder = new PathFinder(); var fromGridPosition = new GridPosition(fromPosition.X, fromPosition.Y); var toGridPosition = new GridPosition(toPosition.X, toPosition.Y); var path = pathFinder.FindPath(fromGridPosition, toGridPosition, grid); var endPosition = path.Edges.LastOrDefault()?.End.Position; if (endPosition.HasValue && map.MapToPoint(endPosition.Value) == toLocation) { return(path.Edges.Where((p, i) => i % 3 == 0 || i == path.Edges.Count - 1).Select(e => map.MapToPoint(e.End.Position)).ToList()); } } return(new List <Point>()); }