コード例 #1
0
        private void ParseTowns(FileReader reader, BinaryNode otbNode)
        {
            BinaryNode nodeTown = otbNode.Child;

            while (nodeTown != null)
            {
                PropertyReader props = reader.GetPropertyReader(nodeTown);

                uint   townid         = props.ReadUInt32();
                string townName       = props.GetString();
                var    templeLocation = props.ReadPosition();

                // var town = new OtTown { Id = townid, Name = townName, TempleLocation = templeLocation };
                //towns[townid] = town;

                nodeTown = nodeTown.Next;
            }
        }
コード例 #2
0
        private void LoadOtbm()
        {
            if (!File.Exists(FileName))
            {
                throw new Exception(string.Format("File not found {0}.", FileName));
            }

            // FileName = fileName;
            MapName = Path.GetFileName(FileName);
            var tileLocations = new HashSet <ulong>();

            using (var reader = new FileReader(FileName))
            {
                BinaryNode node = reader.GetRootNode();

                PropertyReader props = reader.GetPropertyReader(node);

                props.ReadByte(); // junk?

                version = props.ReadUInt32();
                Width   = props.ReadUInt16();
                Height  = props.ReadUInt16();

                majorVersionItems = props.ReadUInt32();
                minorVersionItems = props.ReadUInt32();

                if (minorVersionItems != 40)
                {
                    if (Settings.GetBoolean(Key.BLOCKING_VERSION))
                    {
                        MessageBox.Show("O mapa não esta na versão 9.6. favor converter o mesmo para 9.6 no RME");
                        ReadOnly      = true;
                        this.FileName = "";
                        this.MapName  = "";
                        Generic.Abort();
                    }
                }

                if (version <= 0)
                {
                    //In otbm version 1 the count variable after splashes/fluidcontainers and stackables
                    //are saved as attributes instead, this solves alot of problems with items
                    //that is changed (stackable/charges/fluidcontainer/splash) during an update.
                    throw new Exception(
                              "This map needs to be upgraded by using the latest map editor version to be able to load correctly.");
                }


                Items = Global.items;

                if (version > 3)
                {
                    throw new Exception("Unknown OTBM version detected.");
                }

                if (majorVersionItems < 3)
                {
                    throw new Exception(
                              "This map needs to be upgraded by using the latest map editor version to be able to load correctly.");
                }

                if (majorVersionItems > Items.MajorVersion)
                {
                    throw new Exception("The map was saved with a different items.otb version, an upgraded items.otb is required.");
                }

                if (minorVersionItems > Items.MinorVersion)
                {
                    //Trace.WriteLine("This map needs an updated items.otb.");
                }

                node = node.Child;

                reader.clearRootNode();


                if ((OtMapNodeTypes)node.Type != OtMapNodeTypes.MAP_DATA)
                {
                    throw new Exception("Could not read data node.");
                }

                props = reader.GetPropertyReader(node);

                while (props.PeekChar() != -1)
                {
                    byte attribute = props.ReadByte();
                    switch ((OtMapAttribute)attribute)
                    {
                    case OtMapAttribute.DESCRIPTION:
                        var description = props.GetString();
                        //Descriptions.Add(description);
                        break;

                    case OtMapAttribute.EXT_SPAWN_FILE:
                        spawnFile = props.GetString();
                        break;

                    case OtMapAttribute.EXT_HOUSE_FILE:
                        houseFile = props.GetString();
                        break;

                    default:
                        throw new Exception("Unknown header node.");
                    }
                }

                BinaryNode nodeMapData = node.Child;
                while (nodeMapData != null)
                {
                    switch ((OtMapNodeTypes)nodeMapData.Type)
                    {
                    case OtMapNodeTypes.TILE_AREA:
                        ParseTileArea(reader, nodeMapData, replaceTiles, tileLocations);
                        break;

                    case OtMapNodeTypes.TOWNS:
                        ParseTowns(reader, nodeMapData);
                        break;
                    }
                    nodeMapData = nodeMapData.Next;
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            //LoadSpawn(Path.Combine(Path.GetDirectoryName(fileName), spawnFile), tileLocations);
        }