private static void ParseTileAreaNode(OTBNode tileAreaNode, World world)
        {
            if (tileAreaNode == null)
            {
                throw new ArgumentNullException(nameof(tileAreaNode));
            }
            if (tileAreaNode.Type != OTBNodeType.TileArea)
            {
                throw new TFSWorldLoadingException();
            }

            var stream = new ReadOnlyMemoryStream(tileAreaNode.Data.Span);

            var areaStartX = stream.ReadUInt16();
            var areaStartY = stream.ReadUInt16();
            var areaZ      = stream.ReadByte();

            var areaStartPosition = new Coordinate(
                x: areaStartX,
                y: areaStartY,
                z: (sbyte)areaZ);

            foreach (var tileNode in tileAreaNode.Children)
            {
                ParseTileNode(
                    tilesAreaStartPosition: areaStartPosition,
                    tileNode: tileNode,
                    world: world);
            }
        }
Exemple #2
0
        /// <summary>
        /// Logs the information embedded in the root node of the OTB tree.
        /// </summary>
        private static void ParseOTBTreeRootNode(OTBNode rootNode)
        {
            if (rootNode == null)
            {
                throw new ArgumentNullException(nameof(rootNode));
            }
            if (rootNode.Children.Count != 1)
            {
                throw new InvalidOperationException();
            }

            var parsingStream = new OTBParsingStream(rootNode.Data);

            var headerVersion = parsingStream.ReadUInt32();
            //if (headerVersion == 0 || headerVersion > 2)
            //	throw new InvalidOperationException();

            var worldWidth  = parsingStream.ReadUInt16();
            var worldHeight = parsingStream.ReadUInt16();

            var itemEncodingMajorVersion = parsingStream.ReadUInt32();
            //if (itemEncodingMajorVersion != SupportedItemEncodingMajorVersion)
            //	throw new InvalidOperationException();

            var itemEncodingMinorVersion = parsingStream.ReadUInt32();

            //if (itemEncodingMinorVersion < SupportedItemEncodingMinorVersion)
            //	throw new InvalidOperationException();

            _logger.Info($"OTBM header version: {headerVersion}.");
            _logger.Info($"World width: {worldWidth}.");
            _logger.Info($"World height: {worldHeight}.");
            _logger.Info($"Item encoding major version: {itemEncodingMajorVersion}.");
            _logger.Info($"Item encoding minor version: {itemEncodingMinorVersion}.");
        }
Exemple #3
0
        /// <summary>
        /// Updates the <paramref name="world"/> with the data contained
        /// in <paramref name="tileAreaNode"/>.
        /// </summary>
        private static void ParseTileAreaNode(OTBNode tileAreaNode, World world)
        {
            if (tileAreaNode == null)
            {
                throw new ArgumentNullException(nameof(tileAreaNode));
            }
            if (tileAreaNode.Type != OTBNodeType.TileArea)
            {
                throw new InvalidOperationException();
            }

            var stream = new OTBParsingStream(tileAreaNode.Data);

            var areaStartX = stream.ReadUInt16();
            var areaStartY = stream.ReadUInt16();
            var areaZ      = (sbyte)stream.ReadByte();

            var areaStartPosition = new Coordinate(
                x: areaStartX,
                y: areaStartY,
                z: areaZ);

            foreach (var tileNode in tileAreaNode.Children)
            {
                ParseTileNode(
                    tilesAreaStartPosition: areaStartPosition,
                    tileNode: tileNode,
                    world: world);
            }
        }
        public static int CountNodesInTree(OTBNode root)
        {
            if (root.Children.Count == 0)
            {
                return(1);
            }

            return(1 + root
                   .Children
                   .Select(node => CountNodesInTree(node))
                   .Sum());
        }
Exemple #5
0
        private static void ParseOTBTreeRootNode(OTBNode rootNode, World world)
        {
            if (rootNode == null)
            {
                throw new ArgumentNullException(nameof(rootNode));
            }
            if (world == null)
            {
                throw new ArgumentNullException(nameof(world));
            }
            if (rootNode.Children.Count != 1)
            {
                throw new TFSWorldLoadingException();
            }

            var parsingStream = new ReadOnlyMemoryStream(rootNode.Data.Span);             //new OTBParsingStream(rootNode.Data.Span);

            var headerVersion = parsingStream.ReadUInt32();

            if (headerVersion == 0 || headerVersion > 2)
            {
                throw new TFSWorldLoadingException();
            }

            var worldWidth  = parsingStream.ReadUInt16();
            var worldHeight = parsingStream.ReadUInt16();

            var itemEncodingMajorVersion = parsingStream.ReadUInt32();

            if (itemEncodingMajorVersion != SupportedItemEncodingMajorVersion)
            {
                throw new TFSWorldLoadingException();
            }

            var itemEncodingMinorVersion = parsingStream.ReadUInt32();

            if (itemEncodingMinorVersion < SupportedItemEncodingMinorVersion)
            {
                throw new TFSWorldLoadingException();
            }

            Console.WriteLine($"OTBM header version: {headerVersion}");
            Console.WriteLine($"World width: {worldWidth}");
            Console.WriteLine($"World height: {worldHeight}");
            Console.WriteLine($"Item encoding major version: {itemEncodingMajorVersion}");
            Console.WriteLine($"Item encoding minor version: {itemEncodingMinorVersion}");
        }
Exemple #6
0
        private static void Parse(OTBNode worldDataNode, World world)
        {
            if (worldDataNode == null)
            {
                throw new ArgumentNullException(nameof(worldDataNode));
            }
            if (world == null)
            {
                throw new ArgumentNullException(nameof(world));
            }
            if (worldDataNode.Type != OTBNodeType.WorldData)
            {
                throw new TFSWorldLoadingException();
            }

            foreach (var child in worldDataNode.Children)
            {
                switch (child.Type)
                {
                case OTBNodeType.TileArea:
                    ParseTileAreaNode(child, world);
                    break;

                case OTBNodeType.TownCollection:
                    // ParseTownCollectionNode(child, world);
                    break;

                case OTBNodeType.WayPointCollection:
                    // ParseWaypointCollectionNode(child, world);
                    break;

                case OTBNodeType.ItemDefinition:
                    throw new NotImplementedException("TFS didn't implement this. So didn't we.");

                default:
                    throw new TFSWorldLoadingException();
                }
            }
        }