public void LoadWorld() { string zoneLocation = GlobalReference.GlobalValues.Settings.ZoneDirectory; string[] zones = GlobalReference.GlobalValues.FileIO.GetFilesFromDirectory(zoneLocation); if (zones.Length == 0) { throw new FileNotFoundException("No zone files found in " + zoneLocation); } foreach (string file in zones) { string filePath = Path.GetFullPath(file); GlobalReference.GlobalValues.Logger.Log(LogLevel.DEBUG, "Loading " + filePath); IZone zone = DeserializeZone(GlobalReference.GlobalValues.FileIO.ReadAllText(filePath)); zone.FinishLoad(); Zones.Add(zone.Id, zone); _zoneIdToFileMap.Add(zone.Id, file); } _zones = new List <IZone>(Zones.Values); _zonePartitioner = Partitioner.Create(0, _zones.Count); }
private void ReloadZones() { if (_lastZoneReload != GlobalReference.GlobalValues.GameDateTime.GameDateTime.Day) { lock (_zoneRefreshPadlock) { if (_lastZoneReload != GlobalReference.GlobalValues.GameDateTime.GameDateTime.Day) { _lastZoneReload = GlobalReference.GlobalValues.GameDateTime.GameDateTime.Day; //we can not load the zones into the list while iterating over the list //so we create a list of zones that will be reloaded List <Tuple <int, IZone> > zonesToReload = new List <Tuple <int, IZone> >(); foreach (IZone zone in Zones.Values) { if (zone.ResetTime.IsLessThan(GlobalReference.GlobalValues.GameDateTime.GameDateTime)) { string filePath = _zoneIdToFileMap[zone.Id]; GlobalReference.GlobalValues.Logger.Log(LogLevel.DEBUG, "Reloading " + filePath); IZone newZone = DeserializeZone(GlobalReference.GlobalValues.FileIO.ReadAllText(filePath)); newZone.FinishLoad(); zonesToReload.Add(new Tuple <int, IZone>(newZone.Id, newZone)); } } //now we update the zones that will be reset foreach (Tuple <int, IZone> zone in zonesToReload) { Zones[zone.Item1] = zone.Item2; } } } } }