public PathFinding(string path, Map map, int startCell, int startDir) { _strPath = path; _map = map; _startCell = startCell; _startDir = startDir; }
private static void LoadMaps() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM maps_data", "Maps", (reader) => { while (reader.Read()) { var newMap = new Map { Id = reader.GetInt32("id"), Width = reader.GetInt32("width"), Height = reader.GetInt16("height"), PosX = reader.GetInt16("posX"), PosY = reader.GetInt16("posY"), MapData = reader.GetString("mapData"), Key = reader.GetString("decryptkey"), Time = reader.GetString("createTime"), Subarea = reader.GetInt16("subarea"), }; newMap.Cells = newMap.UncompressDatas(); Maps.Add(newMap); } return Maps.Count; }); task.Wait(); }
private static bool IsEmpty(int cell, Map map) { return !DatabaseProvider.InventoryItems.Any(x => x.Map == map && x.Cell == cell) && !DatabaseProvider.Characters.Any(x => x.Map == map && x.MapCell == cell); }
private static int FindCell(int cell, NearbyCells dir, Map map) { switch (dir) { case NearbyCells.BottomRight: return cell + 1; case NearbyCells.Bottom: return cell + map.Width; case NearbyCells.BottomLeft: return cell + (map.Width * 2) - 1; case NearbyCells.Left: return cell + map.Width - 1; case NearbyCells.TopLeft: return cell - 1; case NearbyCells.Top: return cell - map.Width; case NearbyCells.TopRight: return cell - (map.Width * 2) + 1; case NearbyCells.Right: return cell - map.Width + 1; } return -1; }
public static int GetNearbyCell(int cell, Map map) { for (var i = 0; i < 7; i++) { var newCell = FindCell(cell, (NearbyCells) i, map); if (map.Cells.All(x => x != newCell)) continue; if (IsEmpty(newCell, map)) return newCell; } return -1; }