Ejemplo n.º 1
0
        public Map(ulong id, ulong baseid, string path, bool dynamic)
        {
            if (!ServerBase.Kernel.Maps.ContainsKey(id))
                ServerBase.Kernel.Maps.Add(id, this);
            Npcs = new Dictionary<uint, INpc>();
            Npcs2 = new Dictionary<uint, table>();
            Entities = new List<Entity>();
            //Floor = new Floor(0, 0, id);
            Companions = new List<Entity>();
            ID = id;
            BaseID = baseid;
            Path = path;
            Floor = new Floor(0, 0, id);
            #region Loading floor.
            if (id != baseid && baseid == 700 && ArenaBaseFloor != null)
            {
                Floor = new Game.Floor(ArenaBaseFloor.Bounds.Width, ArenaBaseFloor.Bounds.Height, ID);
                for (ushort y = 0; y < ArenaBaseFloor.Bounds.Height; y = (ushort)(y + 1))
                {
                    for (ushort x = 0; x < ArenaBaseFloor.Bounds.Width; x = (ushort)(x + 1))
                    {
                        Floor[x, y, MapObjectType.Player, null] = ArenaBaseFloor[x, y, MapObjectType.Player, null];
                    }
                }
            }
            else
            {
                if (File.Exists(ServerBase.Constants.DMapsPath + "\\maps\\" + baseid.ToString() + ".map"))
                {
                    //Console.WriteLine("kim");
                    byte[] buff = File.ReadAllBytes(ServerBase.Constants.DMapsPath + "\\maps\\" + baseid.ToString() + ".map");
                    MemoryStream FS = new MemoryStream(buff);
                    BinaryReader BR = new BinaryReader(FS);
                    int Width = BR.ReadInt32();
                    int Height = BR.ReadInt32();

                    Floor = new Game.Floor(Width, Height, ID);

                    for (ushort y = 0; y < Height; y = (ushort)(y + 1))
                    {
                        for (ushort x = 0; x < Width; x = (ushort)(x + 1))
                        {
                            Floor[x, y, MapObjectType.InvalidCast, null] = !(BR.ReadByte() == 1 ? true : false);
                        }
                    }
                    BR.Close();
                    FS.Close();
                    BR.Dispose();
                    FS.Flush();
                    ////BR.Dispose();
                    //FS.Dispose();
                }
                else
                {
                    if (File.Exists(ServerBase.Constants.DMapsPath + Path))
                    {
                        FileStream FS = new FileStream(ServerBase.Constants.DMapsPath + Path, FileMode.Open);
                        BinaryReader BR = new BinaryReader(FS);
                        BR.ReadBytes(268);
                        int Width = BR.ReadInt32();
                        int Height = BR.ReadInt32();

                        Floor = new Game.Floor(Width, Height, ID);

                        for (ushort y = 0; y < Height; y = (ushort)(y + 1))
                        {
                            for (ushort x = 0; x < Width; x = (ushort)(x + 1))
                            {
                                Floor[x, y, MapObjectType.InvalidCast, null] = !Convert.ToBoolean(BR.ReadUInt16());

                                BR.BaseStream.Seek(4L, SeekOrigin.Current);
                            }
                            BR.BaseStream.Seek(4L, SeekOrigin.Current);
                        }
                        uint amount = BR.ReadUInt32();
                        BR.BaseStream.Seek(amount * 12, SeekOrigin.Current);

                        int num = BR.ReadInt32();
                        List<SceneFile> list = new List<SceneFile>();
                        for (int i = 0; i < num; i++)
                        {
                            switch (BR.ReadInt32())
                            {
                                case 10:
                                    BR.BaseStream.Seek(0x48L, SeekOrigin.Current);
                                    break;

                                case 15:
                                    BR.BaseStream.Seek(0x114L, SeekOrigin.Current);
                                    break;

                                case 1:
                                    list.Add(this.CreateSceneFile(BR));
                                    break;

                                case 4:
                                    BR.BaseStream.Seek(0x1a0L, SeekOrigin.Current);
                                    break;
                            }
                        }
                        Scenes = list.ToArray();

                        for (int i = 0; i < Scenes.Length; i++)
                        {
                            foreach (ScenePart part in Scenes[i].Parts)
                            {
                                for (int j = 0; j < part.Size.Width; j++)
                                {
                                    for (int k = 0; k < part.Size.Height; k++)
                                    {
                                        Point point = new Point();
                                        point.X = ((Scenes[i].Location.X + part.StartPosition.X) + j) - part.Size.Width;
                                        point.Y = ((Scenes[i].Location.Y + part.StartPosition.Y) + k) - part.Size.Height;
                                        Floor[(ushort)point.X, (ushort)point.Y, MapObjectType.InvalidCast, null] = part.NoAccess[j, k];
                                    }
                                }
                            }
                        }

                        BR.Close();
                        FS.Close();
                        ////BR.Dispose();
                        //FS.Dispose();
                        SaveMap();
                    }
                }
            }
            #endregion
            if (baseid == 3024)
            {//54 46
                INpc npc = new Network.GamePackets.NpcSpawn();
                npc.UID = 1765;
                npc.Mesh = 8200;
                npc.Type = Enums.NpcType.WareHouse;
                npc.X = 90 ;
                npc.Y = 67;
                npc.MapID = id;
                AddNpc(npc);
            }
            LoadNpcs();
               // LoadTables();
            LoadZones();
            LoadMonsters();
            //Loadtale();
            LoadPortals();
            //FloorItemTimerCallBack = new TimerCallback(_timerFloorItemCallBack);
            //_timerFloorItem = new Timer(FloorItemTimerCallBack, this, 10000, 2000);
        }
Ejemplo n.º 2
0
        public Map(ulong id, string path)
        {
            if (!ServerBase.Kernel.Maps.ContainsKey(id))
                ServerBase.Kernel.Maps.Add(id, this);
            Npcs = new Dictionary<uint, INpc>();
            Npcs2 = new Dictionary<uint, table>();
            Entities = new List<Entity>();
            Floor = new Floor(0, 0, id);
            Companions = new List<Entity>();
            ID = id;
            BaseID = id;
            if (path == "")
                path = Database.DMaps.MapPaths[(ushort)id];
            Path = path;
            #region Loading floor.

            if (File.Exists(ServerBase.Constants.DMapsPath + "\\maps\\" + id.ToString() + ".map"))
            {

                byte[] buff = File.ReadAllBytes(ServerBase.Constants.DMapsPath + "\\maps\\" + id.ToString() + ".map");

                MemoryStream FS = new MemoryStream(buff);
                BinaryReader BR = new BinaryReader(FS);
                int Width = BR.ReadInt32();
                int Height = BR.ReadInt32();
                Floor = new Game.Floor(Width, Height, ID);
                if (id == 700)
                    if (ArenaBaseFloor == null)
                        ArenaBaseFloor = new Game.Floor(Width, Height, ID);
                for (ushort y = 0; y < Height; y = (ushort)(y + 1))
                {
                    for (ushort x = 0; x < Width; x = (ushort)(x + 1))
                    {
                        Floor[x, y, MapObjectType.InvalidCast, null] = !(BR.ReadByte() == 1 ? true : false);
                        if (id == 700)
                            if (ArenaBaseFloor == null)
                                ArenaBaseFloor[x, y, MapObjectType.InvalidCast, null] = !(BR.ReadByte() == 1 ? true : false);
                    }
                }

                BR.Close();
                FS.Close();
            }
            else
            {
                Console.WriteLine(""+(ServerBase.Constants.DMapsPath + Path)+"");
                if (File.Exists(ServerBase.Constants.DMapsPath + Path))
                {
                    Console.WriteLine("Loll");
                    byte[] buff = File.ReadAllBytes(ServerBase.Constants.DMapsPath + Path);
                    MemoryStream FS = new MemoryStream(buff);
                    BinaryReader BR = new BinaryReader(FS);
                    BR.ReadBytes(268);
                    int Width = BR.ReadInt32();
                    int Height = BR.ReadInt32();
                    Floor = new Game.Floor(Width, Height, ID);
                    if (id == 700)
                        if (ArenaBaseFloor == null)
                            ArenaBaseFloor = new Game.Floor(Width, Height, ID);
                    for (ushort y = 0; y < Height; y = (ushort)(y + 1))
                    {
                        for (ushort x = 0; x < Width; x = (ushort)(x + 1))
                        {
                            Floor[x, y, MapObjectType.InvalidCast, null] = !Convert.ToBoolean(BR.ReadUInt16());
                            if (id == 700)
                                if (ArenaBaseFloor == null)
                                    ArenaBaseFloor[x, y, MapObjectType.InvalidCast, null] = !(BR.ReadByte() == 1 ? true : false);
                            BR.BaseStream.Seek(4L, SeekOrigin.Current);
                        }
                        BR.BaseStream.Seek(4L, SeekOrigin.Current);
                    }
                    uint amount = BR.ReadUInt32();
                    BR.BaseStream.Seek(amount * 12, SeekOrigin.Current);

                    int num = BR.ReadInt32();
                    List<SceneFile> list = new List<SceneFile>();
                    for (int i = 0; i < num; i++)
                    {
                        switch (BR.ReadInt32())
                        {
                            case 10:
                                BR.BaseStream.Seek(0x48L, SeekOrigin.Current);
                                break;

                            case 15:
                                BR.BaseStream.Seek(0x114L, SeekOrigin.Current);
                                break;

                            case 1:
                                list.Add(this.CreateSceneFile(BR));
                                break;

                            case 4:
                                BR.BaseStream.Seek(0x1a0L, SeekOrigin.Current);
                                break;
                        }
                    }
                    Scenes = list.ToArray();

                    for (int i = 0; i < Scenes.Length; i++)
                    {
                        foreach (ScenePart part in Scenes[i].Parts)
                        {
                            for (int j = 0; j < part.Size.Width; j++)
                            {
                                for (int k = 0; k < part.Size.Height; k++)
                                {
                                    Point point = new Point();
                                    point.X = ((Scenes[i].Location.X + part.StartPosition.X) + j) - part.Size.Width;
                                    point.Y = ((Scenes[i].Location.Y + part.StartPosition.Y) + k) - part.Size.Height;
                                    Floor[(ushort)point.X, (ushort)point.Y, MapObjectType.InvalidCast, null] = part.NoAccess[j, k];
                                }
                            }
                        }
                    }

                    BR.Close();
                    FS.Close();
                    ////BR.Dispose();
                    //FS.Dispose();
                    SaveMap();
                }
            }
            #endregion
            LoadNpcs();
               // LoadTables();
            LoadZones();
            LoadMonsters();
            //Loadtale();
            LoadPortals();
            /*if (Database.MapsTable.MapInformations[(ushort)id].Owner == id)
            {
                if (Database.MapsTable.MapInformations[(ushort)id].Box == 1)
                {
                    PhoenixProject.Interfaces.INpc npc = new Network.GamePackets.NpcSpawn();
                    npc.UID = 30657;
                    npc.Mesh = 8200;
                    //Console.WriteLine("ss");
                    npc.Type = (PhoenixProject.Game.Enums.NpcType)3;
                    npc.X = (ushort)Database.MapsTable.MapInformations[id].BoxX;
                    npc.Y = (ushort)Database.MapsTable.MapInformations[id].BoxY;
                    npc.MapID = (ushort)Database.MapsTable.MapInformations[id].Owner;
                    AddNpc(npc);
                }
            }*/
            //FloorItemTimerCallBack = new TimerCallback(_timerFloorItemCallBack);
            //_timerFloorItem = new Timer(FloorItemTimerCallBack, this, 10000, 2000);
            //Thread.Sleep(1000);
        }