private async void SyncFromServer() { var snapshot = await EditorZoneSystem.Instance.ClientRequestZoneData(this.ProtoZone); this.lastClientSnapshot = this.lastServerSnapshot = snapshot; this.quadTree = QuadTreeNodeFactory.Create(snapshot); this.ZoneReset?.Invoke(); }
private void ServerRemote_ApplyWorldSizeSliceExpansion(BoundsUshort insertedArea) { Logger.Info("Slice-expanding the world map - inserting an area: " + insertedArea); var oldWorldBounds = Server.World.WorldBounds; var oldOffset = oldWorldBounds.Offset; var oldSize = oldWorldBounds.Size; var oldMap = new Tile[oldSize.X, oldSize.Y]; for (var x = 0; x < oldSize.X; x++) { for (var y = 0; y < oldSize.Y; y++) { oldMap[x, y] = Server.World.GetTile(x + oldOffset.X, y + oldOffset.Y); } } Logger.Info("Tile height data gathered"); var oldStaticObjects = Server.World.EditorEnumerateAllStaticObjects() .Select(o => new EditorStaticObjectsRemovalHelper.RestoreObjectRequest(o)) .ToList(); Logger.Info("Static objects gathered"); // gather zones var oldZones = (from protoZone in Api.FindProtoEntities <IProtoZone>() select new { protoZone, snapshot = protoZone.ServerZoneInstance.QuadTree.SaveQuadTree() }) .ToList(); // create new world var newWorldBounds = CalculateNewWorldBounds(insertedArea, oldWorldBounds); Server.World.CreateWorld(protoTile: Api.GetProtoEntity <TileWaterSea>(), newWorldBounds); Logger.Info("Server zones data gathered"); // copy old map data to the new world for (var x = 0; x < oldSize.X; x++) { for (var y = 0; y < oldSize.Y; y++) { var oldData = oldMap[x, y]; var oldX = (ushort)(x + oldOffset.X); var oldY = (ushort)(y + oldOffset.Y); var newPosition = ConvertPosition(insertedArea, oldX, oldY); Server.World.SetTileData(newPosition, oldData.ProtoTile, oldData.Height, oldData.IsSlope, oldData.IsCliff); } } Server.World.FixMapTilesAll(); Logger.Info("Map slice-expansion finished"); // restore old static objects to the new world foreach (var request in oldStaticObjects) { var newPosition = ConvertPosition(insertedArea, request.TilePosition.X, request.TilePosition.Y); Server.World.CreateStaticWorldObject( request.Prototype, newPosition); } Logger.Info("Static objects restored after the slice-expansion"); // restore zones foreach (var oldZoneSnapshot in oldZones) { var oldQuadTree = QuadTreeNodeFactory.Create(oldZoneSnapshot.snapshot); var newQuadTree = oldZoneSnapshot.protoZone.ServerZoneInstance.QuadTree; foreach (var oldPosition in oldQuadTree) { var newPosition = ConvertPosition(insertedArea, oldPosition.X, oldPosition.Y); newQuadTree.SetFilledPosition(newPosition); } } Logger.Info("Server zones data restored after the slice-expansion"); }