示例#1
0
        public static byte[] GetLandData(Point2D blockCoordinates, Int32 mapNumber)
        {
            byte[] landData = new byte[192];

            Map        map = Map.Maps[mapNumber];
            TileMatrix tm  = map.Tiles;

            LandTile[] land = tm.GetLandBlock(blockCoordinates.X, blockCoordinates.Y);
            for (int i = 0; i < land.Length; i++) //64 * 3 = 192 bytes
            {
                landData[(i * 3)]     = (byte)(((ushort)land[i].ID) & 0x00FF);
                landData[(i * 3) + 1] = (byte)((((ushort)land[i].ID) & 0xFF00) >> 8);
                landData[(i * 3) + 2] = (byte)land[i].Z;
            }
            return(landData);
        }
示例#2
0
        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();
            }
        }