Beispiel #1
0
        public void TestLoadMethod()
        {
            Stream stream = File.OpenRead(TEST_FILE);

            stream.Seek(0, SeekOrigin.End);
            long fileSize = stream.Position;

            stream.Seek(0, SeekOrigin.Begin);

            ZoneFile zoneFile = new ZoneFile();

            zoneFile.Load(stream);

            long streamPosition = stream.Position;

            stream.Close();

            Assert.AreEqual(fileSize, streamPosition, "Not all of the file was read");
        }
Beispiel #2
0
        public void Load(string filePath = null, int mapId = 0)
        {
            if (filePath == null)
            {
                return;
            }

            var directoryPath = Path.GetDirectoryName(filePath);
            var fileName      = Path.GetFileNameWithoutExtension(filePath);
            var zoneFile      = new ZoneFile();

            try
            {
                zoneFile.Load(filePath);
            }
            catch (FileNotFoundException)
            {
                Console.Write("Failed!\n");
                return;
            }

            Console.Write("Successful!\n");

            // Do the data conversion here
            var mapDataFile = new MapDataFile[65, 65];

            for (var x = 0; x < zoneFile.Width; x++)
            {
                for (var y = 0; y < zoneFile.Height; y++)
                {
                    if (!zoneFile.Positions[x, y].IsUsed)
                    {
                        continue;
                    }

                    mapDataFile[x, y] = new MapDataFile();
                    try
                    {
                        mapDataFile[x, y].Load(directoryPath + "\\" + y + "_" + x + ".ifo");
                    }
                    catch (FileNotFoundException)
                    {
                        continue;
                    }
                }
            }

            var mobList   = new List <string>();
            var npcList   = new List <string>();
            var spawnList = new List <string>();
            var warpList  = new List <string>();

            ExtractSpawnPoints(mapId, zoneFile, spawnList);

            foreach (var ifo in mapDataFile)
            {
                if (ifo == null)
                {
                    continue;
                }

                var blockX = ifo.ZonePosition.X * PostionModifier;
                var blockY = ifo.ZonePosition.Y * PostionModifier;

                ExtractNpcs(npcList, mapId, ifo);
                ExtractMobs(mobList, mapId, ifo);
                ExtractWarpGates(warpList, mapId, ifo);
            }

            WriteLua(fileName, mobList, npcList, spawnList, warpList);

            Console.Write("\n\n");
        }
Beispiel #3
0
        private static void ExtractWarpGates(List <string> warpList, int mapId, MapDataFile ifo)
        {
            const string warpStb         = "./3DDATA/stb/warp.stb";
            const string zoneStb         = "./3DDATA/stb/list_zone.stb";
            const string warpGateModel   = "./3DDATA/special/warp_gate01/warp.zms";
            const string decoSpecialList = "./3DDATA/special/list_deco_special.zsc";

            var zoneDataFile = new DataFile();

            zoneDataFile.Load(zoneStb);

            var warpDataFile = new DataFile();

            warpDataFile.Load(warpStb);
            var destCoords = Vector3.Zero;

            ModelListFile modelListFile = new ModelListFile();

            modelListFile.Load(decoSpecialList);

            ModelFile modelFile = new ModelFile();

            modelFile.Load(warpGateModel);
            var vertices = modelFile.Vertices;

            foreach (var warpGate in ifo.WarpPoints)
            {
                var destMapId = int.Parse(warpDataFile[warpGate.WarpID][2]);
                if (zoneDataFile[destMapId][2].ToString().Contains(".zon"))
                {
                    ZoneFile zoneFile = new ZoneFile();
                    zoneFile.Load(zoneDataFile[destMapId][2].ToString()); // Load the zon file

                    foreach (var spawnPoint in zoneFile.SpawnPoints)
                    {
                        if (spawnPoint.Name != warpDataFile[warpGate.WarpID][3].ToString())
                        {
                            continue;
                        }

                        // rose is stupid and we need to do this to get the right coords
                        destCoords = new Vector3(((spawnPoint.Position.X + 520000.00f) / 100.0f), ((spawnPoint.Position.Z + 520000.00f) / 100.0f), ((spawnPoint.Position.Y) / 100.0f));
                        break;
                    }
                }

                var position = new Vector3(((warpGate.Position.X + 520000.00f) / 100.0f), ((warpGate.Position.Y + 520000.00f) / 100.0f), ((warpGate.Position.Z) / 100.0f));

                var rot   = Matrix.RotationQuaternion(modelListFile.Objects[1].Parts[0].Rotation);
                var scale = Matrix.Scaling(modelListFile.Objects[1].Parts[0].Scale);
                var trans = Matrix.Translation(modelListFile.Objects[1].Parts[0].Position);

                var world    = rot * scale * trans;
                var objRot   = Matrix.RotationQuaternion(warpGate.Rotation);
                var objScale = Matrix.Scaling(warpGate.Scale);
                var objTrans = Matrix.Translation(position);

                var objectWorld = objRot * objScale * objTrans;

                Vector3[] vectorPositions = new Vector3[vertices.Count];
                for (int i = 0; i < vertices.Count; i++)
                {
                    vectorPositions[i] = (Vector3)Vector3.Transform(vertices[i].Position, world * objectWorld);
                }

                var boundingBox = BoundingBox.FromPoints(vectorPositions);

                warpList.Add("warp_gate(\"\", "
                             + warpDataFile[warpGate.WarpID][2].ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (destCoords.X).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (destCoords.Y).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (destCoords.Z).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + mapId.ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Minimum.X).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Minimum.Y).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Minimum.Z).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Maximum.X).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Maximum.Y).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Maximum.Z).ToString("G", CultureInfo.InvariantCulture) + ");\n");
            }
        }
Beispiel #4
0
        public void TestSaveMethod()
        {
            ZoneFile zoneFile = new ZoneFile();

            zoneFile.Load(TEST_FILE);

            MemoryStream savedStream = new MemoryStream();

            zoneFile.Save(savedStream);

            savedStream.Seek(0, SeekOrigin.Begin);

            ZoneFile savedZoneFile = new ZoneFile();

            savedZoneFile.Load(savedStream);

            savedStream.Close();

            Assert.AreEqual(zoneFile.Type, savedZoneFile.Type, "Type values do not match");
            Assert.AreEqual(zoneFile.Width, savedZoneFile.Width, "Width values do not match");
            Assert.AreEqual(zoneFile.Height, savedZoneFile.Height, "Height values do not match");
            Assert.AreEqual(zoneFile.GridCount, savedZoneFile.GridCount, "Grid count values do not match");
            Assert.AreEqual(zoneFile.GridSize, savedZoneFile.GridSize, "Grid size values do not match");
            Assert.AreEqual(zoneFile.StartPosition, savedZoneFile.StartPosition, "Start position values do not match");

            for (int x = 0; x < zoneFile.Width; x++)
            {
                for (int y = 0; y < zoneFile.Height; y++)
                {
                    Assert.AreEqual(zoneFile.Positions[x, y].IsUsed, savedZoneFile.Positions[x, y].IsUsed, "Is used values do not match");
                    Assert.AreEqual(zoneFile.Positions[x, y].Position, savedZoneFile.Positions[x, y].Position, "Positions do not match");
                }
            }

            Assert.AreEqual(zoneFile.SpawnPoints.Count, savedZoneFile.SpawnPoints.Count, "Spawn counts do not match");

            for (int i = 0; i < zoneFile.SpawnPoints.Count; i++)
            {
                Assert.AreEqual(zoneFile.SpawnPoints[i].Position, savedZoneFile.SpawnPoints[i].Position, "Spawn point positions do not match");
                Assert.AreEqual(zoneFile.SpawnPoints[i].Name, savedZoneFile.SpawnPoints[i].Name, "Spawn point names do not match");
            }

            Assert.AreEqual(zoneFile.Textures.Count, savedZoneFile.Textures.Count, "Texture counts do not match");

            for (int i = 0; i < zoneFile.Textures.Count; i++)
            {
                Assert.AreEqual(zoneFile.Textures[i], savedZoneFile.Textures[i], "Texture file paths do not match");
            }

            Assert.AreEqual(zoneFile.Tiles.Count, savedZoneFile.Tiles.Count, "Tile counts do not match");

            for (int i = 0; i < zoneFile.Tiles.Count; i++)
            {
                Assert.AreEqual(zoneFile.Tiles[i].Layer1, savedZoneFile.Tiles[i].Layer1, "Tile layer 1 values do not match");
                Assert.AreEqual(zoneFile.Tiles[i].Layer2, savedZoneFile.Tiles[i].Layer2, "Tile layer 2 values do not match");
                Assert.AreEqual(zoneFile.Tiles[i].Offset1, savedZoneFile.Tiles[i].Offset1, "Tile offset 1 values do not match");
                Assert.AreEqual(zoneFile.Tiles[i].Offset2, savedZoneFile.Tiles[i].Offset2, "Tile offset 2 values do not match");
                Assert.AreEqual(zoneFile.Tiles[i].BlendingEnabled, savedZoneFile.Tiles[i].BlendingEnabled, "Tile blending enabled values do not match");
                Assert.AreEqual(zoneFile.Tiles[i].Rotation, savedZoneFile.Tiles[i].Rotation, "Tile rotation values do not match");
                Assert.AreEqual(zoneFile.Tiles[i].TileType, savedZoneFile.Tiles[i].TileType, "Tile type values do not match");
            }

            Assert.AreEqual(zoneFile.Name, savedZoneFile.Name, "Name values do not match");
            Assert.AreEqual(zoneFile.IsUnderground, savedZoneFile.IsUnderground, "Is underground values do not match");
            Assert.AreEqual(zoneFile.BackgroundMusicFilePath, savedZoneFile.BackgroundMusicFilePath, "Background music file paths do not match");
            Assert.AreEqual(zoneFile.SkyFilePath, savedZoneFile.SkyFilePath, "Sky file paths do not match");
            Assert.AreEqual(zoneFile.EconomyCheckRate, savedZoneFile.EconomyCheckRate, "Economy check rate values do not match");
            Assert.AreEqual(zoneFile.PopulationBase, savedZoneFile.PopulationBase, "Population base values do not match");
            Assert.AreEqual(zoneFile.PopulationGrowthRate, savedZoneFile.PopulationGrowthRate, "Population growth rate values do not match");
            Assert.AreEqual(zoneFile.MetalConsumption, savedZoneFile.MetalConsumption, "Metal consumption values do not match");
            Assert.AreEqual(zoneFile.StoneConsumption, savedZoneFile.StoneConsumption, "Stone consumption values do not match");
            Assert.AreEqual(zoneFile.WoodConsumption, savedZoneFile.WoodConsumption, "Wood consumption values do not match");
            Assert.AreEqual(zoneFile.LeatherConsumption, savedZoneFile.LeatherConsumption, "Leather consumption values do not match");
            Assert.AreEqual(zoneFile.ClothConsumption, savedZoneFile.ClothConsumption, "Cloth consumption values do not match");
            Assert.AreEqual(zoneFile.AlchemyConsumption, savedZoneFile.AlchemyConsumption, "Alchemy consumption values do not match");
            Assert.AreEqual(zoneFile.ChemicalConsumption, savedZoneFile.ChemicalConsumption, "Chemical consumption values do not match");
            Assert.AreEqual(zoneFile.IndustrialConsumption, savedZoneFile.IndustrialConsumption, "Industrial consumption values do not match");
            Assert.AreEqual(zoneFile.MedicineConsumption, savedZoneFile.MedicineConsumption, "Medicine consumption values do not match");
            Assert.AreEqual(zoneFile.FoodConsumption, savedZoneFile.FoodConsumption, "Food consumption values do not match");
        }