public bool LoadTile(int x, int y, bool applyDanger = true) { lock (_threadLocker) { try { if (CheckDungeon()) { return(false); } // To check every 1 minute minimum and unload tiles loaded more than 15 minutes ago if (_loadTileCheck.IsReady) { //Logging.Write("Timer ready, checking loaded tile's age"); _loadTileCheck.Reset(); CheckTilesAgeAndUnload(); CheckFailedTilesAgeAndUnload(); } Tuple <int, int> coords = new Tuple <int, int>(x, y); if (_mesh.HasTileAt(x, y)) { _loadedTiles[coords] = Others.TimesSec; return(true); } if (_failedTiles.ContainsKey(coords)) { _failedTiles[coords] = Others.TimesSec; // don't retry to download that tile for another XX minutes. return(false); } string path = GetTilePath(x, y); string fName = GetTileName(x, y); if (!downloadTile(fName)) { return(false); } if (!File.Exists(path)) { return(false); } byte[] data = File.ReadAllBytes(path); if (!LoadTile(data)) { Others.DeleteFile(_meshPath + "\\" + fName); if (!forceDownloadTile(fName)) { return(false); } data = File.ReadAllBytes(path); if (!LoadTile(data)) { Logging.WriteError("Problem with Meshes tile " + fName + " , cannot load it."); if (!_loadedTiles.ContainsKey(coords)) { _failedTiles[coords] = Others.TimesSec; } return(false); } } // loaded if (applyDanger) { var dangers = new List <nManagerSetting.DangerousZone>(); foreach (var zone in nManagerSetting.DangerousZones) { if (Continent != zone.ContinentId) { continue; } if ((int)Math.Floor(zone.TileX) != x || (int)Math.Floor(zone.TileY) != y) { continue; } dangers.Add(zone); } if (dangers.Count > 0) { int addedDangers = ReportDanger(dangers); if (addedDangers > 0) { Logging.WriteNavigator(addedDangers + " dangers added."); } } } _loadedTilesString.Add(GetTileName(x, y, true)); if (_loadedTilesString.Count >= 10) { string output = ""; foreach (string s in _loadedTilesString) { output = s + ", " + output; } _loadedTilesString.Clear(); Logging.WriteNavigator(output + " loaded."); } if (!_loadedTiles.ContainsKey(coords)) // multi thread on the same path can cause a duplicate here { _loadedTiles.Add(coords, Others.TimesSec); } return(true); } catch (Exception exception) { Logging.WriteError("LoadTile(int x, int y): " + exception); return(false); } } }