Ejemplo n.º 1
0
        public void Unload()
        {
            LevelHandler.Levels.Remove(this);

            foreach (Player p in PlayerHandler.Players.Values.ToArray())
            {
                if (p.OldLevel == this) p.OldLevel = null;
                if (p.Level == this) p.SwitchMap(LevelHandler.Lobby);
            }

            foreach (Player pl in Players.ToArray())
            {
                pl.SendKick("Internal Error (level has been unloaded)");
            }

            FullSave();

            Physics.ShouldStop = true;
            Physics = null;

            BlockData = new byte[0];
        }
Ejemplo n.º 2
0
        //todo add type
        public void Create(ushort inx, ushort iny, ushort inz)
        {
            SizeX = inx;
            SizeY = iny;
            SizeZ = inz;

            SpawnPos = new Pos
                           {
                               X = (ushort) ((SizeX*32)/2),
                               Y = (ushort) (((SizeY*32)/2) + 64),
                               Z = (ushort) ((SizeZ*32)/2),
                               Pitch = 0,
                               Yaw = 0
                           };

            BlockData = new byte[SizeX*SizeY*SizeZ];

            var half = (ushort) (SizeY/2);
            for (ushort x = 0; x < SizeX; ++x)
            {
                for (ushort z = 0; z < SizeZ; ++z)
                {
                    for (ushort y = 0; y < SizeY; ++y)
                    {
                        if (y != half)
                        {
                            SetTile(x, y, z, (byte) ((y >= half) ? MCBlocks.Air : MCBlocks.Dirt));
                        }
                        else
                        {
                            SetTile(x, y, z, (byte) MCBlocks.Grass);
                        }
                    }
                }
            }

            Physics = new PhysicsHandler(this, true);

            LevelHandler.Levels.Add(this);
        }
Ejemplo n.º 3
0
        public void Load(string name)
        {
            string tempPath = LevelFolder + "/" + name + CompressedExtension;
            if (!File.Exists(tempPath)) throw new FileNotFoundException("Could not find file!", tempPath);

            var fileStream = new FileStream(tempPath, FileMode.Open);
            var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress);

            var header = new byte[HeaderSize];
            gzipStream.Read(header, 0, HeaderSize);
            Name = _encode.GetString(header, 0, 64).Trim();
            SizeX = BitConverter.ToUInt16(header, 64);
            SizeY = BitConverter.ToUInt16(header, 66);
            SizeZ = BitConverter.ToUInt16(header, 68);
            Server.Log("Loading level " + Name + " which is " + SizeX + "x" + SizeY + "x" + SizeZ, LogTypesEnum.Debug);
            SpawnPos = new Pos
                           {
                               X = BitConverter.ToUInt16(header, 70),
                               Y = BitConverter.ToUInt16(header, 72),
                               Z = BitConverter.ToUInt16(header, 74),
                               Pitch = header[76]
                           };
            SpawnPos.Pitch = header[77];

            bool physics = BitConverter.ToBoolean(header, 78);
            bool realistic = BitConverter.ToBoolean(header, 79);

            BuildPermissions = header[80];
            VisitPermissions = header[81];

            Physics = new PhysicsHandler(this, physics) {Realistic = realistic};

            int blockCount = SizeX*SizeY*SizeZ;
            BlockData = new byte[blockCount];
            gzipStream.Read(BlockData, 0, blockCount);

            gzipStream.Close();
            fileStream.Close();

            LevelHandler.Levels.Add(this);
        }
Ejemplo n.º 4
0
        public void Create(ushort inx, ushort iny, ushort inz, string type)
        {
            SizeX = inx;
            SizeY = iny;
            SizeZ = inz;
            SizeXZmultiplied = SizeX * SizeZ;

            SpawnPos = new Pos
                           {
                               X = (ushort)((SizeX * 32) / 2),
                               Y = (ushort)(((SizeY * 32) / 2) + 64),
                               Z = (ushort)((SizeZ * 32) / 2),
                               Pitch = 0,
                               Yaw = 0
                           };

            BlockData = new byte[SizeX * SizeY * SizeZ];

            switch (type)
            { //TODO: Add more level types.
                case "flatgrass":
                    Generator = new FlatGrassGenerator(this);
                    break;
                default:
                    Generator = new FlatGrassGenerator(this);
                    break;
            }

            Physics = new PhysicsHandler(this, true);

            LevelHandler.Levels.Add(this);
        }