Example #1
0
 public PathFinding(string path, Map map, int startCell, int startDir)
 {
     _strPath = path;
     _map = map;
     _startCell = startCell;
     _startDir = startDir;
 }
Example #2
0
        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();
        }
Example #3
0
 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);
 }
Example #4
0
        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;
        }
Example #5
0
        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;
        }