internal PhysicsHandler(Level l, bool enabled)
        {
            level = l;
            isEnabled = enabled;

            if (PhysicsTypes.Count == 0) return;

            if (enabled)
            {
                Server.Log("Initializing Physics on " + l.name + ", physics is currently ENABLED", LogTypesEnum.info);
            }
            else
            {
                Server.Log("Initializing Physics on " + l.name + ", physics is currently DISABLED", LogTypesEnum.info);
            }

            new System.Threading.Thread(new System.Threading.ThreadStart(TickTimer)).Start();
        }
Beispiel #2
0
 public LevelHandler()
 {
     lobby = new Level("test", 128, 64, 128);
 }
        static void Dirt(Level level, int pos)
        {
            BlockPos blockPos = level.IntToPos(pos);

            //This code works, but in order to change dirt into grass we have to check below every block in the same way, so we wont use it for now
            //if (level.physics.realistic)
            //{
            //    for (int y = blockPos.y + 1; y < level.sizeY; ++y)
            //    {
            //        BlockPos currentBlockPos = new BlockPos(blockPos.x, (ushort)y, blockPos.z);
            //        int currentPos = level.PosToInt(currentBlockPos);

            //        byte type = level.blocks[currentPos];

            //        if (!Block.LightPass.Contains(type)) { return; }
            //    }
            //}
            //else
            {
                BlockPos currentBlockPos = blockPos.diff(0, 1, 0);
                int currentPos = level.PosToInt(currentBlockPos);

                byte type = level.blocks[currentPos];

                if (!Block.lightPass.Contains(type)) return;
            }
            if (level.blocks[pos] != (byte)Blocks.Dirt) return;
            level.PhysicsBlockChange(blockPos, Blocks.Grass);
        }
        static void Water(Level level, int pos)
        {
            BlockPos blockPos = level.IntToPos(pos);
            BlockPos belowBlockPos = blockPos.diff(0, -1, 0);

            int belowPos = level.PosToInt(belowBlockPos);
            byte type = level.blocks[belowPos];

            if (type == (byte)Blocks.WaterStill)
            {
                level.physics.OtherData.Remove(belowPos);
                level.physics.OtherData.Add(belowPos, level.physics.waterCurrent);
            }
            else if (Block.crushable.Contains(type))
            {
                level.physics.OtherData.Remove(belowPos);
                level.physics.OtherData.Add(belowPos, level.physics.waterCurrent);
                level.PhysicsBlockChange(belowBlockPos, Blocks.WaterStill);
            }
            else
            {
                for (int _X = -1; _X < 2; ++_X)
                    for (int _Z = -1; _Z < 2; ++_Z)
                    {
                        if (Math.Abs(_X) == 1 && Math.Abs(_Z) == 1) continue;
                        if (blockPos.x + _X < 0 || blockPos.z + _Z < 0) continue;

                        BlockPos aroundPos = blockPos.diff(_X, 0, _Z);

                        if (level.NotInBounds(aroundPos)) continue;

                        int newPos = level.PosToInt(aroundPos);

                        if (level.blocks[newPos] == (byte)Blocks.WaterStill)
                        {
                            level.physics.OtherData.Remove(newPos);
                            level.physics.OtherData.Add(newPos, level.physics.waterCurrent);
                        }
                        else if (Block.crushable.Contains(level.blocks[newPos]))
                        {
                            level.physics.OtherData.Remove(newPos);
                            level.physics.OtherData.Add(newPos, level.physics.waterCurrent);
                            level.PhysicsBlockChange(aroundPos, Blocks.WaterStill);
                            //if (level.physics.PhysicsUpdates.Contains(level.PosToInt(aroundBelowPos))) return;
                            //level.physics.PhysicsUpdates.Add(level.PosToInt(aroundBelowPos));
                            return;
                        }
                        else
                        {
                            continue;
                        }
                    }
            }
        }
        static void Sand(Level level, int pos)
        {
            BlockPos blockPos = level.IntToPos(pos);
            BlockPos belowBlockPos = blockPos.diff(0, -1, 0);

            Blocks below = level.GetTile(belowBlockPos);

            if (below == Blocks.Zero)
            {
                return;
            }
            else if (Block.crushable.Contains((byte)below))
            {
                level.PhysicsBlockChange(belowBlockPos, Blocks.Sand);
                level.PhysicsBlockChange(blockPos, Blocks.Air);
                //if(level.physics.PhysicsUpdates.Contains(level.PosToInt(belowPos))) return;
                //level.physics.PhysicsUpdates.Add(level.PosToInt(belowPos));
            }
            else if (level.physics.realistic)
            {
                for(int _X = -1;_X<2;++_X)
                    for (int _Z = -1; _Z < 2; ++_Z)
                    {
                        if (Math.Abs(_X) == 1 && Math.Abs(_Z) == 1) continue;
                        if (belowBlockPos.x + _X < 0 || belowBlockPos.z + _Z < 0) continue;
                        BlockPos aroundPos = blockPos.diff(_X, 0, _Z);
                        BlockPos aroundBelowPos = belowBlockPos.diff(_X, 0, _Z);
                        if (level.NotInBounds(aroundBelowPos)) continue;

                        int testPos = level.PosToInt(aroundPos);
                        int newPos = level.PosToInt(aroundBelowPos);
                        if (Block.crushable.Contains(level.blocks[newPos]) && level.blocks[testPos] == 0)
                        {
                            level.PhysicsBlockChange(aroundBelowPos, Blocks.Sand);
                            level.PhysicsBlockChange(blockPos, Blocks.Air);
                            //if (level.physics.PhysicsUpdates.Contains(level.PosToInt(aroundBelowPos))) return;
                            //level.physics.PhysicsUpdates.Add(level.PosToInt(aroundBelowPos));
                            return;
                        }
                        else
                        {
                            continue;
                        }
                    }
            }
        }
        static void Sponge(Level level, int pos)
        {
            BlockPos blockPos = level.IntToPos(pos);

            for (int _x = -1; _x < 2; ++_x)
            {
                for (int _y = -1; _y < 2; ++_y)
                {
                    for (int _z = -1; _z < 2; ++_z)
                    {
                        BlockPos currentBlockPos = blockPos.diff(_x, _y, _z);
                        int currentPos = level.PosToInt(currentBlockPos);

                        if (level.NotInBounds(currentBlockPos)) continue;

                        Blocks type = (Blocks)level.blocks[currentPos];

                        if (type == Blocks.Water || type == Blocks.WaterStill || type == Blocks.Lava || type == Blocks.LavaStill)
                        {
                            level.PhysicsBlockChange(currentBlockPos, Blocks.Air);
                        }
                    }
                }
            }
        }
        static void HalfStair(Level level, int pos)
        {
            BlockPos blockPos = level.IntToPos(pos);

            BlockPos belowBlockPos = blockPos.diff(0, -1, 0);
            int belowPos = level.PosToInt(belowBlockPos);

            if (level.blocks[belowPos] == (byte)Blocks.Staircasestep)
            {
                level.PhysicsBlockChange(belowBlockPos, Blocks.Staircasefull);
                level.PhysicsBlockChange(blockPos, Blocks.Air);
            }
        }
        static void Grass(Level level, int pos)
        {
            BlockPos blockPos = level.IntToPos(pos);
            BlockPos aboveBlockPos = blockPos.diff(0, 1, 0);

            int abovePos = level.PosToInt(aboveBlockPos);
            byte type = level.blocks[abovePos];

            if (Block.lightPass.Contains(type)) return;

            level.PhysicsBlockChange(blockPos, Blocks.Dirt);
        }
Beispiel #9
0
        void HandleCommand(string message)
        {
            string[] command = message.Split(' ');
            command[0] = command[0].Remove(0, 1).ToLower();

            if (command[0] == "historymode")
            {
                enableWaterMode = false;
                enableLavaMode = false;

                enableHistoryMode = !enableHistoryMode;
                SendMessage("History mode is " + enableHistoryMode.ToString());
            }
            else if (command[0] == "water")
            {
                enableHistoryMode = false;
                enableLavaMode = false;

                enableWaterMode = !enableWaterMode;
                SendMessage("Water mode is " + enableWaterMode.ToString());
            }
            else if (command[0] == "lava")
            {
                enableHistoryMode = false;
                enableWaterMode = false;

                enableLavaMode = !enableLavaMode;
                SendMessage("Lava mode is " + enableLavaMode.ToString());
            }
            else if (command[0] == "level" || command[0] == "levels")
            {
                if (command.Length == 1)
                {
                    SendMessage("You are currently on: " + level.name);
                    SendMessage("Possible SubCommands:");
                    SendMessage("loaded");
                    SendMessage("new <name> (Size x,y,z) (type)");
                }
                else if (command[1].ToLower() == "loaded")
                {
                    SendMessage("Loaded Levels:");
                    foreach (Level l in LevelHandler.levels.ToArray())
                    {
                        SendMessage(l.name);
                    }
                }
                else if (command[1].ToLower() == "new")
                {
                    if (command.Length == 2)
                    {
                        SendMessage("You at least need to enter a name!");
                        return;
                    }
                    else if (command.Length > 6 || (command.Length > 3 && command.Length != 6))
                    {
                        SendMessage("Incorrect number of variables!");
                        return;
                    }
                    else if (command.Length == 6)
                    {
                        try
                        {
                            string levelName = command[2];

                            ushort levelSizeX = Convert.ToUInt16(command[3]);
                            ushort levelSizeY = Convert.ToUInt16(command[4]);
                            ushort levelSizeZ = Convert.ToUInt16(command[5]);

                            Level l = Level.Find(levelName);
                            if (l != null)
                            {
                                SendMessage("The level: " + levelName + " is already loaded!");
                                return;
                            }
                            else
                            {
                                SendMessage("Generating new level: " + levelName);
                                l = new Level(levelName, levelSizeX, levelSizeY, levelSizeZ);
                                Player.SendGlobalMessage("NEW LEVEL: " + l.name);
                            }
                        }
                        catch
                        {
                            SendMessage("New level create failed!");
                        }
                    }
                    else
                    {
                        Level l = Level.Find(command[2]);
                        if (l != null)
                        {
                            SendMessage("The level: " + command[2] + " is already loaded!");
                            return;
                        }
                        else
                        {
                            SendMessage("Generating new level: " + command[2]);
                            l = new Level(command[2], 64, 64, 64);
                            Player.SendGlobalMessage("NEW LEVEL: " + l.name);
                        }
                    }
                }
                else if (command[1].ToLower() == "load")
                {
                    if (command.Length == 2)
                    {
                        SendMessage("You at least need to enter a name!");
                        return;
                    }
                    else
                    {
                        Level l = Level.Find(command[2]);
                        if (l != null)
                        {
                            SendMessage("The level: " + command[2] + " is already loaded!");
                            return;
                        }
                        else
                        {
                            SendMessage("Loading level: " + command[2]);
                            try
                            {
                                l = new Level(command[2]);
                            }
                            catch(Exception e)
                            {
                                Console.WriteLine(e.Message);
                                SendMessage("Level load failed!");
                                return;
                            }
                            Player.SendGlobalMessage("LOADED LEVEL: " + l.name);
                        }
                    }
                }
                else if (command[1].ToLower() == "unload")
                {
                    if (command.Length == 1)
                    {
                        SendMessage("You have to enter a name!");
                        return;
                    }
                    else
                    {
                        Level l = Level.Find(command[2]);

                        if (l == null)
                        {
                            SendMessage("Level not found!");
                            return;
                        }
                        else if (l == LevelHandler.lobby)
                        {
                            SendMessage("You cannot unload the lobby.");
                            return;
                        }
                        else
                        {
                            SendMessage("Unloading: " + l.name);
                            l.Unload();

                            Server.historyController.SaveHistory(l.name);
                            Server.historyController.UnloadHistory(l.name);

                            SendMessage("Done!");
                        }
                    }
                }
            }
            else if (command[0] == "goto")
            {
                if (command.Length == 1)
                {
                    SendMessage("You have to enter a name to switch levels!");
                    return;
                }
                else
                {
                    Level l = Level.Find(command[1]);

                    if (l == null)
                    {
                        SendMessage("Level not found!");
                        return;
                    }
                    else
                    {
                        SwitchMap(l);
                    }

                    SendMessage("You are now on: " + level.name);
                }
            }
        }
Beispiel #10
0
        internal void SwitchMap(Level l)
        {
            oldLevel = level;
            level = l;

            SendMap();
        }
Beispiel #11
0
 internal void AddMapData(Level l)
 {
     for (int i = 0; i < l.blocks.Length; ++i)
     {
         bytes.Add(l.blocks[i]);
     }
 }