Beispiel #1
0
        static void GenerateMapFile(int posX, int posY, int posZ, string outDirectory)
        {
            string filename = GetMapFileName(posX, posY, posZ);

            string[] files;
            string   file;

            // The map to be filled.
            MapView Maps  = new MapView(posX, posY, posZ);
            Bitmap  image = MapImages[posZ];

            // Go backward across all the stores; last = most recent.
            for (int s = stores.Length - 1; s >= 0; s--)
            {
                if (Directory.Exists(stores[s] + "\\MapJson") && Directory.Exists(stores[s] + "\\MapJson\\" + filename))
                {
                    files = Directory.GetFiles(stores[s] + "\\MapJson\\" + filename);
                    for (int f = files.Length - 1; f >= 0; f--)
                    {
                        file = files[f];

                        Console.WriteLine("Loading " + filename + " : " + stores[s]);

                        ReadMapFile(file, Maps);
                    }
                }
            }

            if (!Maps.IsEmpty())
            {
                if (!Directory.Exists(outDirectory))
                {
                    Directory.CreateDirectory(outDirectory);
                }

                for (int x = 0; x < SIZE_X; x++)
                {
                    for (int y = 0; y < SIZE_Y; y++)
                    {
                        MapTile t = Maps.GetTile(x, y);
                        if (t != null)
                        {
                            for (int i = 0; i < t.Items.Count; i++)
                            {
                                int     id   = t.Items[i].ID;
                                DatItem item = DatContext.GetItem(id);
                                if (item.HasMapColor)
                                {
                                    image.SetPixel((posX + x) - START_X, (posY + y) - START_Y, GetMapColor(item.MapColor));
                                }
                            }
                        }
                    }
                }
                using (FileStream fs = new FileStream(outDirectory + "\\" + filename + ".json", FileMode.Create, FileAccess.Write))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.Write(Maps.ToJSON());
                    }
                }
            }
        }
Beispiel #2
0
        static TibiaMapFile ParseOdysseyMap(int baseX, int baseY, int baseZ)
        {
            TibiaMapFile  mapFile    = new TibiaMapFile(baseX, baseY, baseZ);
            List <string> filesToUse = new List <string>();

            // Construct the map.
            filesToUse = new List <string>();
            if (File.Exists(@"C:\Users\Reece\Recordings\JsonMaps\" + ((baseZ << 16) + (baseY << 8) + (baseX << 0)).ToString() + ".json"))
            {
                filesToUse.Add(@"C:\Users\Reece\Recordings\JsonMaps\" + ((baseZ << 16) + (baseY << 8) + (baseX << 0)).ToString() + ".json");
            }

            for (int n = 0; n < filesToUse.Count; n++)
            {
                MapView view = MapView.FromJSON(File.ReadAllText(filesToUse[n]));
                for (int x = 0; x < 256; x++)
                {
                    for (int y = 0; y < 256; y++)
                    {
                        MapTile tile = view.GetTile(x, y);
                        if (tile != null)
                        {
                            for (int i = 0; i < tile.Items.Count; i++)
                            {
                                DatItem dItem = dat.GetItem(tile.Items[i].ID);
                                if (dItem.IsStackable)
                                {
                                    // Map files don't care for stack count.
                                }
                                if (dItem.IsFluid)
                                {
                                    // Map files don't care for fluids.
                                }
                                if (dItem.IsFluidContainer)
                                {
                                    // Map files don't care for fluid containers.
                                }
                                if (dItem.IsAnimated)
                                {
                                    // Map files don't care for sprite animations.
                                }

                                if (dItem.HasMapColor)
                                {
                                    // Set the map color for the position.
                                    mapFile.SetMapColor(x, y, dItem.MapColor);
                                }

                                if (dItem.IsGround)
                                {
                                    mapFile.SetSpeed(x, y, dItem.Speed);
                                    mapFile.SetHasTile(x, y, true);
                                }

                                if (dItem.IsBlocking || dItem.BlocksPath)
                                {
                                    mapFile.SetIsUnwalkable(x, y, true);
                                }
                            }
                        }
                    }
                }
            }

            Console.WriteLine("Done " + TibiaMapFile.GetTibiaMapFileName(baseX, baseY, baseZ));

            return(mapFile);
        }