public static byte[] GetRawStaticsData(Point2D blockCoordinates, Int32 mapNumber) { Map map = Map.Maps[mapNumber]; TileMatrix tm = map.Tiles; StaticTile[][][] staticTiles = tm.GetStaticBlock(blockCoordinates.X, blockCoordinates.Y); int staticCount = 0; for (int k = 0; k < staticTiles.Length; k++) { for (int l = 0; l < staticTiles[k].Length; l++) { staticCount += staticTiles[k][l].Length; } } byte[] blockBytes = new byte[staticCount * 7]; int blockByteIdx = 0; for (int i = 0; i < staticTiles.Length; i++) { for (int j = 0; j < staticTiles[i].Length; j++) { StaticTile[] sortedTiles = staticTiles[i][j]; //Array.Sort(sortedTiles, CompareStaticTiles); for (int k = 0; k < sortedTiles.Length; k++) { blockBytes[blockByteIdx + 0] = (byte)(((ushort)sortedTiles[k].ID) & 0x00FF); blockBytes[blockByteIdx + 1] = (byte)((((ushort)sortedTiles[k].ID) & 0xFF00) >> 8); blockBytes[blockByteIdx + 2] = (byte)i; blockBytes[blockByteIdx + 3] = (byte)j; blockBytes[blockByteIdx + 4] = (byte)sortedTiles[k].Z; blockBytes[blockByteIdx + 5] = (byte)(((ushort)sortedTiles[k].Hue) & 0x00FF); blockBytes[blockByteIdx + 6] = (byte)((((ushort)sortedTiles[k].Hue) & 0xFF00) >> 8); blockByteIdx += 7; } } } return(blockBytes); }
public static void LiveFreeze(Mobile from, Map targetMap, Point3D start3d, Point3D end3d) { Dictionary <Point2D, List <Item> > ItemsByBlockLocation = new Dictionary <Point2D, List <Item> >(); if (targetMap != null && start3d != NullP3D && end3d != NullP3D) { Point2D start = targetMap.Bound(new Point2D(start3d)); Point2D end = targetMap.Bound(new Point2D(end3d)); IPooledEnumerable eable = targetMap.GetItemsInBounds(new Rectangle2D(start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1)); Console.WriteLine(string.Format("Invoking live freeze from {0},{1} to {2},{3}", start.X, start.Y, end.X, end.Y)); foreach (Item item in eable) { if (item is Static || item is BaseFloor || item is BaseWall) { Map itemMap = item.Map; if (itemMap == null || itemMap == Map.Internal) { continue; } Point2D p = new Point2D(item.X >> 3, item.Y >> 3); if (!(ItemsByBlockLocation.ContainsKey(p))) { ItemsByBlockLocation.Add(p, new List <Item>()); } ItemsByBlockLocation[p].Add(item); } } eable.Free(); } else { from.SendMessage("That was not a proper area. Please retarget and reissue the command."); return; } TileMatrix matrix = targetMap.Tiles; foreach (KeyValuePair <Point2D, List <Item> > kvp in ItemsByBlockLocation) { StaticTile[][][] blockOfTiles = matrix.GetStaticBlock(kvp.Key.X, kvp.Key.Y); Dictionary <Point2D, List <StaticTile> > newBlockStatics = new Dictionary <Point2D, List <StaticTile> >(); foreach (Item item in kvp.Value) { int xOffset = item.X - (kvp.Key.X * 8); int yOffset = item.Y - (kvp.Key.Y * 8); if (xOffset < 0 || xOffset >= 8 || yOffset < 0 || yOffset >= 8) { continue; } StaticTile newTile = new StaticTile((ushort)item.ItemID, (byte)xOffset, (byte)yOffset, (sbyte)item.Z, (short)item.Hue); Point2D refPoint = new Point2D(xOffset, yOffset); if (!(newBlockStatics.ContainsKey(refPoint))) { newBlockStatics.Add(refPoint, new List <StaticTile>()); } newBlockStatics[refPoint].Add(newTile); item.Delete(); } for (int i = 0; i < blockOfTiles.Length; i++) { for (int j = 0; j < blockOfTiles[i].Length; j++) { for (int k = 0; k < blockOfTiles[i][j].Length; k++) { Point2D refPoint = new Point2D(i, j); if (!(newBlockStatics.ContainsKey(refPoint))) { newBlockStatics.Add(refPoint, new List <StaticTile>()); } newBlockStatics[refPoint].Add(blockOfTiles[i][j][k]); } } } StaticTile[][][] newblockOfTiles = new StaticTile[8][][]; for (int i = 0; i < 8; i++) { newblockOfTiles[i] = new StaticTile[8][]; for (int j = 0; j < 8; j++) { Point2D p = new Point2D(i, j); int length = 0; if (newBlockStatics.ContainsKey(p)) { length = newBlockStatics[p].Count; } newblockOfTiles[i][j] = new StaticTile[length]; for (int k = 0; k < length; k++) { if (newBlockStatics.ContainsKey(p)) { newblockOfTiles[i][j][k] = newBlockStatics[p][k]; } } } } matrix.SetStaticBlock(kvp.Key.X, kvp.Key.Y, newblockOfTiles); int blockNum = ((kvp.Key.X * matrix.BlockHeight) + kvp.Key.Y); List <Mobile> candidates = new List <Mobile>(); int bX = kvp.Key.X * 8; int bY = kvp.Key.Y * 8; IPooledEnumerable eable = targetMap.GetMobilesInRange(new Point3D(bX, bY, 0)); foreach (Mobile m in eable) { if (m.Player) { candidates.Add(m); } } eable.Free(); CRC.InvalidateBlockCRC(targetMap.MapID, blockNum); foreach (Mobile m in candidates) { m.Send(new UpdateStaticsPacket(new Point2D(kvp.Key.X, kvp.Key.Y), m)); } MapChangeTracker.MarkStaticsBlockForSave(targetMap.MapID, kvp.Key); } }
public static void OnSave(WorldSaveEventArgs e) { if (!Directory.Exists(UltimaLiveSettings.UltimaLiveMapChangesSavePath)) { Directory.CreateDirectory(UltimaLiveSettings.UltimaLiveMapChangesSavePath); } DateTime now = DateTime.Now; string Stamp = string.Format("{0}-{1}-{2}-{3}-{4}-{5}", now.Year, now.Month.ToString("00"), now.Day.ToString("00"), now.Hour.ToString("00"), now.Minute.ToString("00"), now.Second.ToString("00")); foreach (KeyValuePair <int, MapRegistry.MapDefinition> kvp in MapRegistry.Definitions) //for (int mapIndex = 0; mapIndex < Live.NumberOfMapFiles; mapIndex++) { try { Map CurrentMap = Server.Map.Maps[kvp.Key]; TileMatrix CurrentMatrix = CurrentMap.Tiles; ICollection keyColl = m_LandChanges[kvp.Key].Keys; if (keyColl.Count > 0) { string filename = string.Format("map{0}-{1}.live", kvp.Key, Stamp); Console.WriteLine(Path.Combine(UltimaLiveSettings.UltimaLiveMapChangesSavePath, filename)); GenericWriter writer = new BinaryFileWriter(Path.Combine(UltimaLiveSettings.UltimaLiveMapChangesSavePath, filename), true); writer.Write((UInt16)kvp.Key); foreach (Point2D p in keyColl) { writer.Write((UInt16)p.X); writer.Write((UInt16)p.Y); LandTile[] blocktiles = CurrentMatrix.GetLandBlock(p.X, p.Y); for (int j = 0; j < 64; j++) { writer.Write((UInt16)blocktiles[j].ID); writer.Write((sbyte)blocktiles[j].Z); } } writer.Close(); } m_LandChanges[kvp.Key].Clear(); keyColl = m_StaticsChanges[kvp.Key].Keys; if (keyColl.Count > 0) { string filename = string.Format("statics{0}-{1}.live", kvp.Key, Stamp); GenericWriter writer = new BinaryFileWriter(Path.Combine(UltimaLiveSettings.UltimaLiveMapChangesSavePath, filename), true); writer.Write((UInt16)kvp.Key); foreach (Point2D p in keyColl) { StaticTile[][][] staticTiles = CurrentMatrix.GetStaticBlock(p.X, p.Y); int staticCount = 0; for (int i = 0; i < staticTiles.Length; i++) { for (int j = 0; j < staticTiles[i].Length; j++) { staticCount += staticTiles[i][j].Length; } } writer.Write((UInt16)p.X); writer.Write((UInt16)p.Y); writer.Write((int)staticCount); for (int i = 0; i < staticTiles.Length; i++) { for (int j = 0; j < staticTiles[i].Length; j++) { for (int k = 0; k < staticTiles[i][j].Length; k++) { writer.Write((ushort)staticTiles[i][j][k].ID); writer.Write((byte)i); writer.Write((byte)j); writer.Write((sbyte)staticTiles[i][j][k].Z); writer.Write((short)staticTiles[i][j][k].Hue); } } } } writer.Close(); } m_StaticsChanges[kvp.Key].Clear(); } catch { Console.WriteLine("Key: " + kvp.Key); } } }
public static void OnSave(WorldSaveEventArgs e) { if (!ExportOnNextSave) { return; } ExportOnNextSave = false; if (!Directory.Exists(UltimaLiveSettings.UltimaLiveClientExportPath)) { Directory.CreateDirectory(UltimaLiveSettings.UltimaLiveClientExportPath); } Console.Write("Exporting Client Files..."); /* maps */ // public static Dictionary<int, MapDefinition> Definitions foreach (KeyValuePair <int, MapRegistry.MapDefinition> kvp in MapRegistry.Definitions) { if (!MapRegistry.MapAssociations.ContainsKey(kvp.Key)) { continue; } string filename = string.Format("map{0}.mul", kvp.Key); GenericWriter writer = new BinaryFileWriter(Path.Combine(UltimaLiveSettings.UltimaLiveClientExportPath, filename), true); m_WorkMap = Server.Map.Maps[kvp.Key]; TileMatrix CurrentMatrix = m_WorkMap.Tiles; int blocks = CurrentMatrix.BlockWidth * CurrentMatrix.BlockHeight; for (int xblock = 0; xblock < CurrentMatrix.BlockWidth; xblock++) { for (int yblock = 0; yblock < CurrentMatrix.BlockHeight; yblock++) { writer.Write((uint)0); LandTile[] blocktiles = CurrentMatrix.GetLandBlock(xblock, yblock); if (blocktiles.Length == 196) { Console.WriteLine("Invalid landblock! Save failed!"); return; } else { for (int j = 0; j < 64; j++) { writer.Write((short)blocktiles[j].ID); writer.Write((sbyte)blocktiles[j].Z); } } } } writer.Close(); } /* Statics */ foreach (KeyValuePair <int, MapRegistry.MapDefinition> kvp in MapRegistry.Definitions) { if (!MapRegistry.MapAssociations.ContainsKey(kvp.Key)) { continue; } string filename = string.Format("statics{0}.mul", kvp.Key); GenericWriter staticWriter = new BinaryFileWriter(Path.Combine(UltimaLiveSettings.UltimaLiveClientExportPath, filename), true); filename = string.Format("staidx{0}.mul", kvp.Key); GenericWriter staticIndexWriter = new BinaryFileWriter(Path.Combine(UltimaLiveSettings.UltimaLiveClientExportPath, filename), true); m_WorkMap = Server.Map.Maps[kvp.Key]; TileMatrix CurrentMatrix = m_WorkMap.Tiles; int blocks = CurrentMatrix.BlockWidth * CurrentMatrix.BlockHeight; int startBlock = 0; int finishBlock = 0; for (int xblock = 0; xblock < CurrentMatrix.BlockWidth; xblock++) { for (int yblock = 0; yblock < CurrentMatrix.BlockHeight; yblock++) { StaticTile[][][] staticTiles = CurrentMatrix.GetStaticBlock(xblock, yblock); //Static File for (int i = 0; i < staticTiles.Length; i++) { for (int j = 0; j < staticTiles[i].Length; j++) { StaticTile[] sortedTiles = staticTiles[i][j]; Array.Sort(sortedTiles, BlockUtility.CompareStaticTiles); for (int k = 0; k < sortedTiles.Length; k++) { staticWriter.Write((ushort)sortedTiles[k].ID); staticWriter.Write((byte)i); staticWriter.Write((byte)j); staticWriter.Write((sbyte)sortedTiles[k].Z); staticWriter.Write((short)sortedTiles[k].Hue); finishBlock += 7; } } } //Index File if (finishBlock != startBlock) { staticIndexWriter.Write((int)startBlock); //lookup staticIndexWriter.Write((int)(finishBlock - startBlock)); //length staticIndexWriter.Write((int)0); //extra startBlock = finishBlock; } else { staticIndexWriter.Write((uint)uint.MaxValue); //lookup staticIndexWriter.Write((uint)uint.MaxValue); //length staticIndexWriter.Write((uint)uint.MaxValue); //extra } } } staticWriter.Close(); staticIndexWriter.Close(); } }