コード例 #1
0
        public override void Serialize(OtFileWriter fileWriter, OtPropertyWriter writer)
        {
            base.Serialize(fileWriter, writer);

            if (items != null)
            {
                foreach (var item in Items)
                {
                    fileWriter.WriteNodeStart((byte)OtMap.OtMapNodeTypes.ITEM);

                    fileWriter.Write(item.Type.Id);
                    item.Serialize(fileWriter, fileWriter.GetPropertyWriter());

                    fileWriter.WriteNodeEnd();
                }
            }
        }
コード例 #2
0
        private void SaveOtbm(string fileName)
        {
            using (var writer = new OtFileWriter(fileName)) {
                //Header
                writer.Write((uint)0, false);

                writer.WriteNodeStart((byte)OtMapNodeTypes.ROOTV1);

                writer.Write(Version);
                writer.Write(Width);
                writer.Write(Height);
                writer.Write(Items.MajorVersion);
                writer.Write(Items.MinorVersion);

                //Map Data
                writer.WriteNodeStart((byte)OtMapNodeTypes.MAP_DATA);


                foreach (var description in Descriptions)
                {
                    writer.Write((byte)OtMapAttribute.DESCRIPTION);
                    writer.Write(description);
                }

                writer.Write((byte)OtMapAttribute.EXT_HOUSE_FILE);
                writer.Write(HouseFile);

                writer.Write((byte)OtMapAttribute.EXT_SPAWN_FILE);
                writer.Write(SpawnFile);

                foreach (var tile in Tiles)
                {
                    writer.WriteNodeStart((byte)OtMapNodeTypes.TILE_AREA);
                    writer.Write((ushort)(tile.Location.X & 0xFF00));
                    writer.Write((ushort)(tile.Location.Y & 0xFF00));
                    writer.Write((byte)tile.Location.Z);

                    if (tile.HouseId > 0)
                    {
                        writer.WriteNodeStart((byte)OtMapNodeTypes.HOUSETILE);
                    }
                    else
                    {
                        writer.WriteNodeStart((byte)OtMapNodeTypes.TILE);
                    }

                    writer.Write((byte)tile.Location.X);
                    writer.Write((byte)tile.Location.Y);

                    if (tile.HouseId > 0)
                    {
                        writer.Write(tile.HouseId);
                    }

                    if (tile.Flags > 0)
                    {
                        writer.Write((byte)OtMapAttribute.TILE_FLAGS);
                        writer.Write(tile.Flags);
                    }

                    if (tile.Ground != null)
                    {
                        writer.WriteNodeStart((byte)OtMapNodeTypes.ITEM);
                        writer.Write(tile.Ground.Type.Id);
                        tile.Ground.Serialize(writer, writer.GetPropertyWriter());
                        writer.WriteNodeEnd(); //Item
                    }

                    foreach (var item in tile.Items)
                    {
                        writer.WriteNodeStart((byte)OtMapNodeTypes.ITEM);

                        writer.Write(item.Type.Id);
                        item.Serialize(writer, writer.GetPropertyWriter());

                        writer.WriteNodeEnd(); //Item
                    }

                    writer.WriteNodeEnd(); //Tile
                    writer.WriteNodeEnd(); //Tile Area
                }

                writer.WriteNodeStart((byte)OtMapNodeTypes.TOWNS);

                foreach (var town in towns.Values)
                {
                    writer.WriteNodeStart((byte)OtMapNodeTypes.TOWN);
                    writer.Write(town.Id);
                    writer.Write(town.Name);
                    writer.Write(town.TempleLocation);
                    writer.WriteNodeEnd(); //Town
                }

                writer.WriteNodeEnd(); //Towns

                writer.WriteNodeEnd(); //Map Data
                writer.WriteNodeEnd(); //Root
            }
        }