public void LoadEffectPlaceholders(RoMapData mapData, RagnarokWorld worldData)
        {
            data  = mapData;
            world = worldData;

            var findObject = GameObject.Find($"{world.MapName} resources");

            if (findObject != null)
            {
                baseObject = findObject;
            }
            else
            {
                baseObject = new GameObject($"{world.MapName} resources");
                baseObject.transform.position = new Vector3(data.InitialSize.x, 0, data.InitialSize.y);
                baseObject.isStatic           = true;
            }

            var effectContainer = new GameObject("effects");

            effectContainer.transform.SetParent(baseObject.transform, false);

            foreach (var effect in world.Effects)
            {
                var obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                //var obj2 = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Effects/Smoke/SmokeEmitter.prefab");
                //var obj = PrefabUtility.InstantiatePrefab(obj2) as GameObject;
                obj.name = effect.Id + " - " + effect.Name;
                obj.transform.SetParent(effectContainer.transform, false);
                obj.transform.localPosition = new Vector3(effect.Position.x / 5, -effect.Position.y / 5, effect.Position.z / 5);
            }
        }
        public void Load(RoMapData mapData, RagnarokWorld worldData)
        {
            data  = mapData;
            world = worldData;

            modelCache = new Dictionary <string, GameObject>();

            var oldBox = GameObject.Find($"{world.MapName} resources");

            if (oldBox != null)
            {
                GameObject.DestroyImmediate(oldBox);
            }

            baseObject = new GameObject($"{world.MapName} resources");
            baseObject.transform.position = new Vector3(data.InitialSize.x, 0, data.InitialSize.y);
            baseObject.isStatic           = true;

            SetWorldLighting();
            LoadLights();
            LoadModels();
            LoadEffects();
            LoadSounds();
            LoadWater();
            LoadFog();
        }
Example #3
0
        private RagnarokWorld Load(string path)
        {
            var filename = path;
            var basename = Path.GetFileNameWithoutExtension(filename);
            var basedir  = Path.GetDirectoryName(path);

            fs = new FileStream(filename, FileMode.Open);
            br = new BinaryReader(fs);

            var header = new string(br.ReadChars(4));

            if (header != "GRSW")
            {
                throw new Exception("Not world resource");
            }

            Debug.Log("Loading ragnarok world resource file " + basename);

            world = ScriptableObject.CreateInstance <RagnarokWorld>();

            world.MapName = basename;

            var majorVersion = br.ReadByte();
            var minorVersion = br.ReadByte();

            world.Version = majorVersion * 10 + minorVersion;

            var oldBox = GameObject.Find($"{basename} resources");

            if (oldBox != null)
            {
                GameObject.DestroyImmediate(oldBox);
            }


            Debug.Log("Version: " + world.Version);

            world.IniFileName = br.ReadKoreanString(40);
            world.GndFileName = br.ReadKoreanString(40);
            world.GatFileName = br.ReadKoreanString(40);
            if (world.Version >= 14)
            {
                world.SrcFileName = br.ReadKoreanString(40);
            }

            //Debug.Log("Ini: " + world.IniFileName);
            //Debug.Log("Gnd: " + world.GndFileName);
            //Debug.Log("Gat: " + world.GatFileName);
            //Debug.Log("Src: " + world.SrcFileName);

            //water stuff
            if (world.Version >= 13)
            {
                var water = new RoWater();

                water.Level = br.ReadSingle() / 5f;

                if (world.Version >= 18)
                {
                    water.Type       = br.ReadInt32();
                    water.WaveHeight = br.ReadSingle();
                    water.WaveSpeed  = br.ReadSingle();
                    water.WavePitch  = br.ReadSingle();

                    if (world.Version >= 19)
                    {
                        water.AnimSpeed = br.ReadInt32();
                    }
                }

                world.Water = water;

                Debug.Log($"Water: Level {water.Level} Type: {water.Type} Height: {water.WaveHeight} Speed: {water.WaveSpeed} Pitch: {water.WavePitch} AnimSpeed: {water.AnimSpeed}");
            }

            //lightmap stuff
            if (world.Version >= 15)
            {
                var light = new RoLightSetup();
                light.Latitude  = br.ReadInt32();
                light.Longitude = br.ReadInt32();
                light.Diffuse   = br.ReadColorNoAlpha();
                light.Ambient   = br.ReadColorNoAlpha();

                if (world.Version >= 17)
                {
                    light.Opacity = br.ReadSingle();
                }

                Debug.Log($"Lightmap: lat:{light.Latitude} lng:{light.Longitude} diff:{light.Diffuse} Ambient:{light.Ambient} Opacity:{light.Opacity}");

                world.LightSetup = light;
            }

            //ground stuff?
            if (world.Version >= 15)
            {
                var top    = br.ReadInt32();              //top
                var bottom = br.ReadInt32();              //bottom
                var left   = br.ReadInt32();              //left
                var right  = br.ReadInt32();              //right

                Debug.Log($"Ground: {top} {bottom} {left} {right}");
            }

            var objCount = br.ReadInt32();

            Debug.Log("Objects: " + objCount);

            for (var i = 0; i < objCount; i++)
            {
                var type = br.ReadInt32();

                switch (type)
                {
                case 1:
                    LoadModel(i);
                    break;

                case 2:
                    LoadLight(i);
                    break;

                case 3:
                    LoadSound(i);
                    break;

                case 4:
                    LoadEffect(i);
                    break;

                default:
                    Debug.LogWarning("Unhandled type " + type);
                    return(null);
                }
            }

            Debug.Log($"Loaded rsw world data {fs.Position} out of {fs.Length}");

            world.FogSetup = LoadFogData(basedir, basename);

            return(world);
        }