Exemple #1
0
 public static void placeBlock(Level l, Player p, ushort x, ushort y, ushort z, byte type)
 {
     if (p == null)
         l.Blockchange(x, y, z, type);
     else
         l.Blockchange(p, x, y, z, type);
 }
Exemple #2
0
        public PlayerBot(string n, Level l)
        {
            Server.s.Log("adding " + n + " bot");
            name = n;
            color = "&1";
            id = FreeId();

            level = l;
            ushort x = (ushort)((0.5 + level.spawnx) * 32);
            ushort y = (ushort)((1 + level.spawny) * 32);
            ushort z = (ushort)((0.5 + level.spawnz) * 32);
            pos = new ushort[3] { x, y, z }; rot = new byte[2] { level.rotx, level.roty };
            GlobalSpawn();
        }
Exemple #3
0
        public static Level Load(string givenName, byte phys)
        {
            MySQL.executeQuery("CREATE TABLE if not exists `Block" + givenName + "` (Username CHAR(20), TimePerformed DATETIME, X SMALLINT UNSIGNED, Y SMALLINT UNSIGNED, Z SMALLINT UNSIGNED, Type TINYINT UNSIGNED, Deleted BOOL)");
            MySQL.executeQuery("CREATE TABLE if not exists `Portals" + givenName + "` (EntryX SMALLINT UNSIGNED, EntryY SMALLINT UNSIGNED, EntryZ SMALLINT UNSIGNED, ExitMap CHAR(20), ExitX SMALLINT UNSIGNED, ExitY SMALLINT UNSIGNED, ExitZ SMALLINT UNSIGNED)");
            MySQL.executeQuery("CREATE TABLE if not exists `Messages" + givenName + "` (X SMALLINT UNSIGNED, Y SMALLINT UNSIGNED, Z SMALLINT UNSIGNED, Message CHAR(255));");
            MySQL.executeQuery("CREATE TABLE if not exists `Zone" + givenName + "` (SmallX SMALLINT UNSIGNED, SmallY SMALLINT UNSIGNED, SmallZ SMALLINT UNSIGNED, BigX SMALLINT UNSIGNED, BigY SMALLINT UNSIGNED, BigZ SMALLINT UNSIGNED, Owner VARCHAR(20));");

            string path = "levels/" + givenName + ".lvl";
            if (File.Exists(path))
            {
                FileStream fs = File.OpenRead(path);
                try
                {
                    GZipStream gs = new GZipStream(fs, CompressionMode.Decompress);
                    byte[] ver = new byte[2];
                    gs.Read(ver, 0, ver.Length);
                    ushort version = BitConverter.ToUInt16(ver, 0);
                    Level level;
                    if (version == 1874)
                    {
                        byte[] header = new byte[16]; gs.Read(header, 0, header.Length);
                        ushort width = BitConverter.ToUInt16(header, 0);
                        ushort height = BitConverter.ToUInt16(header, 2);
                        ushort depth = BitConverter.ToUInt16(header, 4);
                        level = new Level("temp", width, depth, height, "empty");
                        level.spawnx = BitConverter.ToUInt16(header, 6);
                        level.spawnz = BitConverter.ToUInt16(header, 8);
                        level.spawny = BitConverter.ToUInt16(header, 10);
                        level.rotx = header[12]; level.roty = header[13];
                        //level.permissionvisit = (LevelPermission)header[14];
                        //level.permissionbuild = (LevelPermission)header[15];
                    }
                    else
                    {
                        byte[] header = new byte[12]; gs.Read(header, 0, header.Length);
                        ushort width = version;
                        ushort height = BitConverter.ToUInt16(header, 0);
                        ushort depth = BitConverter.ToUInt16(header, 2);
                        level = new Level("temp", width, depth, height, "grass");
                        level.spawnx = BitConverter.ToUInt16(header, 4);
                        level.spawnz = BitConverter.ToUInt16(header, 6);
                        level.spawny = BitConverter.ToUInt16(header, 8);
                        level.rotx = header[10]; level.roty = header[11];
                    }
                    level.permissionbuild = (LevelPermission)11;

                    level.name = givenName;
                    level.setPhysics(phys);

                    byte[] blocks = new byte[level.width * level.height * level.depth];
                    gs.Read(blocks, 0, blocks.Length);
                    level.blocks = blocks;
                    gs.Close();

                    level.backedup = true;

                    DataTable ZoneDB = MySQL.fillData("SELECT * FROM `Zone" + givenName + "`");

                    Zone Zn;
                    for (int i = 0; i < ZoneDB.Rows.Count; ++i)
                    {
                        Zn.smallX = (ushort)ZoneDB.Rows[i]["SmallX"];
                        Zn.smallY = (ushort)ZoneDB.Rows[i]["SmallY"];
                        Zn.smallZ = (ushort)ZoneDB.Rows[i]["SmallZ"];
                        Zn.bigX = (ushort)ZoneDB.Rows[i]["BigX"];
                        Zn.bigY = (ushort)ZoneDB.Rows[i]["BigY"];
                        Zn.bigZ = (ushort)ZoneDB.Rows[i]["BigZ"];
                        Zn.Owner = ZoneDB.Rows[i]["Owner"].ToString();
                        level.ZoneList.Add(Zn);
                    }

                    ZoneDB.Dispose();

                    level.jailx = (ushort)(level.spawnx * 32); level.jaily = (ushort)(level.spawny * 32); level.jailz = (ushort)(level.spawnz * 32);
                    level.jailrotx = level.rotx; level.jailroty = level.roty;

                    level.physThread = new Thread(new ThreadStart(level.Physics));

                    try
                    {
                        DataTable foundDB = MySQL.fillData("SELECT * FROM `Portals" + givenName + "`");

                        for (int i = 0; i < foundDB.Rows.Count; ++i)
                        {
                            if (!Block.portal(level.GetTile((ushort)foundDB.Rows[i]["EntryX"], (ushort)foundDB.Rows[i]["EntryY"], (ushort)foundDB.Rows[i]["EntryZ"])))
                            {
                                MySQL.executeQuery("DELETE FROM `Portals" + givenName + "` WHERE EntryX=" + foundDB.Rows[i]["EntryX"] + " AND EntryY=" + foundDB.Rows[i]["EntryY"] + " AND EntryZ=" + foundDB.Rows[i]["EntryZ"]);
                            }
                        }

                        foundDB = MySQL.fillData("SELECT * FROM `Messages" + givenName + "`");

                        for (int i = 0; i < foundDB.Rows.Count; ++i)
                        {
                            if (!Block.mb(level.GetTile((ushort)foundDB.Rows[i]["X"], (ushort)foundDB.Rows[i]["Y"], (ushort)foundDB.Rows[i]["Z"])))
                            {
                                MySQL.executeQuery("DELETE FROM `Messages" + givenName + "` WHERE X=" + foundDB.Rows[i]["X"] + " AND Y=" + foundDB.Rows[i]["Y"] + " AND Z=" + foundDB.Rows[i]["Z"]);
                            }
                        }
                        foundDB.Dispose();
                    }
                    catch (Exception e) { Server.ErrorLog(e); }

                    try
                    {
                        string foundLocation;
                        foundLocation = "levels/level properties/" + level.name + ".properties";
                        if (!File.Exists(foundLocation))
                        {
                            foundLocation = "levels/level properties/" + level.name;
                        }

                        foreach (string line in File.ReadAllLines(foundLocation))
                        {
                            try
                            {
                                if (line[0] != '#')
                                {
                                    string value = line.Substring(line.IndexOf(" = ") + 3);

                                    switch (line.Substring(0, line.IndexOf(" = ")).ToLower())
                                    {
                                        case "theme": level.theme = value; break;
                                        case "physics": level.setPhysics(int.Parse(value)); break;
                                        case "physics speed": level.speedPhysics = int.Parse(value); break;
                                        case "physics overload": level.overload = int.Parse(value); break;
                                        case "finite mode": level.finite = bool.Parse(value); break;
                                        case "animal ai": level.ai = bool.Parse(value); break;
                                        case "edge water": level.edgeWater = bool.Parse(value); break;
                                        case "survival death": level.Death = bool.Parse(value); break;
                                        case "fall": level.fall = int.Parse(value); break;
                                        case "drown": level.drown = int.Parse(value); break;
                                        case "motd": level.motd = value; break;
                                        case "jailx": level.jailx = ushort.Parse(value); break;
                                        case "jaily": level.jaily = ushort.Parse(value); break;
                                        case "jailz": level.jailz = ushort.Parse(value); break;
                                        case "unload": level.unload = bool.Parse(value); break;

                                        case "perbuild":
                                            if (PermissionFromName(value) != LevelPermission.Null) level.permissionbuild = PermissionFromName(value);
                                            break;
                                        case "pervisit":
                                            if (PermissionFromName(value) != LevelPermission.Null) level.permissionvisit = PermissionFromName(value);
                                            break;
                                    }
                                }
                            }
                            catch (Exception e) { Server.ErrorLog(e); }
                        }
                    } catch { }

                    Server.s.Log("Level \"" + level.name + "\" loaded.");
                    level.ctfgame.mapOn = level;
                    return level;
                }
                catch (Exception ex) { Server.ErrorLog(ex); return null; }
                finally { fs.Close(); }
            }
            else { Server.s.Log("ERROR loading level."); return null; }
        }
Exemple #4
0
 //return true if tree is near
 private bool TreeCheck(Level Lvl, ushort x, ushort z, ushort y, short dist)
 {
     for (short xx = (short)-dist; xx <= +dist; ++xx)
     {
         for (short yy = (short)-dist; yy <= +dist; ++yy)
         {
             for (short zz = (short)-dist; zz <= +dist; ++zz)
             {
                 byte foundTile = Lvl.GetTile((ushort)(x + xx), (ushort)(z + zz), (ushort)(y + yy));
                 if (foundTile == Block.trunk || foundTile == Block.green)
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Exemple #5
0
        //Forces the edge of a map to slope lower for island map types
        float NegateEdge(ushort x, ushort y, Level Lvl)
        {
            float tempx = 0.0f, tempy = 0.0f;
            float temp;
            if (x != 0) { tempx = ((float)x / (float)Lvl.width) * 0.5f; }
            if (y != 0) { tempy = ((float)y / (float)Lvl.height) * 0.5f; }
            tempx = Math.Abs(tempx - 0.25f);
            tempy = Math.Abs(tempy - 0.25f);
            if (tempx > tempy)
            {
                temp = tempx - 0.15f;
            }
            else
            {
                temp = tempy - 0.15f;
            }

            //s.Log("temp = " + temp.ToString());
            if (temp > 0.0f) { return temp; }
            return 0.0f;
        }
Exemple #6
0
        public static Level Load(Stream lvlStream, string fileName)
        {
            byte[] temp = new byte[8];
            Level lvl = new Level(fileName, 0, 0, 0, "empty");
            byte[] data;
            int length;
            try {
                lvlStream.Seek( -4, SeekOrigin.End );
                lvlStream.Read( temp, 0, sizeof( int ) );
                lvlStream.Seek( 0, SeekOrigin.Begin );
                length = BitConverter.ToInt32( temp, 0 );
                data = new byte[length];
                using( GZipStream reader = new GZipStream( lvlStream, CompressionMode.Decompress, true ) ) {
                    reader.Read( data, 0, length );
                }

                for( int i = 0; i < length - 1; i++ ) {
                    if( data[i] == 0xAC && data[i + 1] == 0xED ) {

                        // bypassing the header crap
                        int pointer = i + 6;
                        Array.Copy( data, pointer, temp, 0, sizeof( short ) );
                        pointer += IPAddress.HostToNetworkOrder( BitConverter.ToInt16( temp, 0 ) );
                        pointer += 13;

                        int headerEnd = 0;
                        // find the end of serialization listing
                        for( headerEnd = pointer; headerEnd < data.Length - 1; headerEnd++ ) {
                            if( data[headerEnd] == 0x78 && data[headerEnd + 1] == 0x70 ) {
                                headerEnd += 2;
                                break;
                            }
                        }

                        // start parsing serialization listing
                        int offset = 0;
                        while( pointer < headerEnd ) {
                            if( data[pointer] == 'Z' ) offset++;
                            else if( data[pointer] == 'I' || data[pointer] == 'F' ) offset += 4;
                            else if( data[pointer] == 'J' ) offset += 8;

                            pointer += 1;
                            Array.Copy( data, pointer, temp, 0, sizeof( short ) );
                            short skip = IPAddress.HostToNetworkOrder( BitConverter.ToInt16( temp, 0 ) );
                            pointer += 2;

                            // look for relevant variables
                            Array.Copy( data, headerEnd + offset - 4, temp, 0, sizeof( int ) );
                            if( MemCmp( data, pointer, "width" ) ) {
                                lvl.width = (ushort)IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) );
                            } else if( MemCmp( data, pointer, "depth" ) ) {
                                lvl.depth = (ushort)IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) );
                            } else if( MemCmp( data, pointer, "height" ) ) {
                                lvl.height = (ushort)IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) );
                            }

                            pointer += skip;
                        }

                        lvl.spawnx = (ushort)(lvl.width / 1.3);
                        lvl.spawny = (ushort)(lvl.depth / 1.3);
                        lvl.spawnz = (ushort)(lvl.height / 1.3);

                        // find the start of the block array
                        bool foundBlockArray = false;
                        offset = Array.IndexOf<byte>( data, 0x00, headerEnd );
                        while( offset != -1 && offset < data.Length - 2 ) {
                            if( data[offset] == 0x00 && data[offset + 1] == 0x78 && data[offset + 2] == 0x70 ) {
                                foundBlockArray = true;
                                pointer = offset + 7;
                            }
                            offset = Array.IndexOf<byte>( data, 0x00, offset + 1 );
                        }

                        // copy the block array... or fail
                        if( foundBlockArray ) {
                            lvl.CopyBlocks( data, pointer );
                            lvl.Save(true);
                        } else {
                            throw new Exception( "Could not locate block array." );
                        }
                        break;
                    }
                }

            } catch( Exception ex ) {
                Server.s.Log("Conversion failed");
                Server.ErrorLog(ex);
                return null;
            }

            return lvl;
        }
Exemple #7
0
        public void Start()
        {
            shuttingDown = false;
            Log("Starting Your Server");

            if (!Directory.Exists("properties")) Directory.CreateDirectory("properties");
            if (!Directory.Exists("bots")) Directory.CreateDirectory("bots");
            if (!Directory.Exists("text")) Directory.CreateDirectory("text");

            if (!Directory.Exists("extra")) Directory.CreateDirectory("extra");
            if (!Directory.Exists("extra/undo")) Directory.CreateDirectory("extra/undo");
            if (!Directory.Exists("extra/undoPrevious")) Directory.CreateDirectory("extra/undoPrevious");
            if (!Directory.Exists("extra/copy/")) { Directory.CreateDirectory("extra/copy/"); }
            if (!Directory.Exists("extra/copyBackup/")) { Directory.CreateDirectory("extra/copyBackup/"); }

            try
            {
                if (File.Exists("server.properties")) File.Move("server.properties", "properties/server.properties");
                if (File.Exists("rules.txt")) File.Move("rules.txt", "text/rules.txt");
                if (File.Exists("welcome.txt")) File.Move("welcome.txt", "text/welcome.txt");
                if (File.Exists("messages.txt")) File.Move("messages.txt", "text/messages.txt");
                if (File.Exists("externalurl.txt")) File.Move("externalurl.txt", "text/externalurl.txt");
                if (File.Exists("autoload.txt")) File.Move("autoload.txt", "text/autoload.txt");
                if (File.Exists("IRC_Controllers.txt")) File.Move("IRC_Controllers.txt", "ranks/IRC_Controllers.txt");
                if (Server.useWhitelist) if (File.Exists("whitelist.txt")) File.Move("whitelist.txt", "ranks/whitelist.txt");
            } catch { }

            Properties.Load("properties/server.properties");
            Updater.Load("properties/update.properties");

            Group.InitAll();
            Command.InitAll();
            GrpCommands.fillRanks();
            Block.SetBlocks();
            Awards.Load();

            if (File.Exists("text/emotelist.txt"))
            {
                foreach (string s in File.ReadAllLines("text/emotelist.txt"))
                {
                    Player.emoteList.Add(s);
                }
            }
            else
            {
                File.Create("text/emotelist.txt");
            }

            timeOnline = DateTime.Now;

            try
            {
                MySQL.executeQuery("CREATE DATABASE if not exists `" + MySQLDatabaseName + "`", true);
            }
            catch (Exception e)
            {
                Server.s.Log("MySQL password has not been set! Please reference the MySQL_Setup.txt file on setting up MySQL!");
                Server.ErrorLog(e);
                //process.Kill();
                return;
            }

            MySQL.executeQuery("CREATE TABLE if not exists Players (ID MEDIUMINT not null auto_increment, Name VARCHAR(20), IP CHAR(15), FirstLogin DATETIME, LastLogin DATETIME, totalLogin MEDIUMINT, Title CHAR(20), TotalDeaths SMALLINT, Money MEDIUMINT UNSIGNED, totalBlocks BIGINT, totalKicked MEDIUMINT, color VARCHAR(6), title_color VARCHAR(6), PRIMARY KEY (ID));");

            // Check if the color column exists.
            DataTable colorExists = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='color'");

            if (colorExists.Rows.Count == 0)
            {
                MySQL.executeQuery("ALTER TABLE Players ADD COLUMN color VARCHAR(6) AFTER totalKicked");
            }
            colorExists.Dispose();

            // Check if the title color column exists.
            DataTable tcolorExists = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='title_color'");

            if (tcolorExists.Rows.Count == 0)
            {
                MySQL.executeQuery("ALTER TABLE Players ADD COLUMN title_color VARCHAR(6) AFTER color");
            }
            tcolorExists.Dispose();

            if (levels != null)
                foreach (Level l in levels) { l.Unload(); }
            ml.Queue(delegate
            {
                try
                {
                    levels = new List<Level>(Server.maps);
                    MapGen = new MapGenerator();

                    Random random = new Random();

                    if (File.Exists("levels/" + Server.level + ".lvl"))
                    {
                        mainLevel = Level.Load(Server.level);
                        mainLevel.unload = false;
                        if (mainLevel == null)
                        {
                            if (File.Exists("levels/" + Server.level + ".lvl.backup"))
                            {
                                Log("Attempting to load backup.");
                                File.Copy("levels/" + Server.level + ".lvl.backup", "levels/" + Server.level + ".lvl", true);
                                mainLevel = Level.Load(Server.level);
                                if (mainLevel == null)
                                {
                                    Log("BACKUP FAILED!");
                                    Console.ReadLine(); return;
                                }
                            }
                            else
                            {
                                Log("Your main level was not found");
                                mainLevel = new Level(Server.level, 128, 128, 128, "flat");

                                mainLevel.permissionvisit = LevelPermission.Guest;
                                mainLevel.permissionbuild = LevelPermission.Guest;
                                mainLevel.Save();
                            }
                        }
                    }
                    else
                    {
                        Log("You need a main level, creating one for you now");
                        mainLevel = new Level(Server.level, 128, 128, 128, "flat");

                        mainLevel.permissionvisit = LevelPermission.Guest;
                        mainLevel.permissionbuild = LevelPermission.Guest;
                        mainLevel.Save();
                    }
                    addLevel(mainLevel);
                    mainLevel.physThread.Start();
                } catch (Exception e) { Server.ErrorLog(e); }
            });

            ml.Queue(delegate
            {
                bannedIP = PlayerList.Load("banned-ip.txt", null);
                ircControllers = PlayerList.Load("IRC_Controllers.txt", null);

                foreach (Group grp in Group.GroupList)
                    grp.playerList = PlayerList.Load(grp.fileName, grp);
                if (Server.useWhitelist)
                    whiteList = PlayerList.Load("whitelist.txt", null);
            });

            ml.Queue(delegate
            {
                if (File.Exists("text/autoload.txt"))
                {
                    try
                    {
                        string[] lines = File.ReadAllLines("text/autoload.txt");
                        foreach (string line in lines)
                        {
                            //int temp = 0;
                            string _line = line.Trim();
                            try
                            {
                                if (_line == "") { continue; }
                                if (_line[0] == '#') { continue; }
                                int index = _line.IndexOf("=");

                                string key = _line.Split('=')[0].Trim();
                                string value;
                                try
                                {
                                    value = _line.Split('=')[1].Trim();
                                }
                                catch
                                {
                                    value = "0";
                                }

                                if (!key.Equals(mainLevel.name))
                                {
                                    Command.all.Find("load").Use(null, key + " " + value);
                                    Level l = Level.FindExact(key);
                                }
                                else
                                {
                                    try
                                    {
                                        int temp = int.Parse(value);
                                        if (temp >= 0 && temp <= 3)
                                        {
                                            mainLevel.setPhysics(temp);
                                        }
                                    }
                                    catch
                                    {
                                        Server.s.Log("Physics variable invalid");
                                    }
                                }

                            }
                            catch
                            {
                                Server.s.Log(_line + " failed.");
                            }
                        }
                    }
                    catch
                    {
                        Server.s.Log("autoload.txt error");
                    }
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                else
                {
                    Log("autoload.txt does not exist");
                }
            });

            ml.Queue(delegate
            {
                Log("Creating listening socket on port " + Server.port + "... ");
                if (Setup())
                {
                    s.Log("Done.");
                }
                else
                {
                    s.Log("Could not create socket connection.  Shutting down.");
                    return;
                }
            });

            ml.Queue(delegate
            {
                updateTimer.Elapsed += delegate
                {
                    Player.GlobalUpdate();
                    PlayerBot.GlobalUpdatePosition();
                };

                updateTimer.Start();
            });

            // Heartbeat code here:

            ml.Queue(delegate
            {
                try
                {
                    Heartbeat.Init();
                }
                catch (Exception e)
                {
                    Server.ErrorLog(e);
                }
            });

            // END Heartbeat code

            /*
            Thread processThread = new Thread(new ThreadStart(delegate
            {
                try
                {
                    PCCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
                    ProcessCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName);
                    PCCounter.BeginInit();
                    ProcessCounter.BeginInit();
                    PCCounter.NextValue();
                    ProcessCounter.NextValue();
                }
                catch { }
            }));
            processThread.Start();
            */

            ml.Queue(delegate
            {
                messageTimer.Elapsed += delegate
                {
                    RandomMessage();
                };
                messageTimer.Start();

                process = System.Diagnostics.Process.GetCurrentProcess();

                if (File.Exists("text/messages.txt"))
                {
                    StreamReader r = File.OpenText("text/messages.txt");
                    while (!r.EndOfStream)
                        messages.Add(r.ReadLine());
                    r.Dispose();
                }
                else File.Create("text/messages.txt").Close();

                if (Server.irc)
                {
                    new IRCBot();
                }

                //      string CheckName = "FROSTEDBUTTS";

                //       if (Server.name.IndexOf(CheckName.ToLower())!= -1){ Server.s.Log("FROSTEDBUTTS DETECTED");}
                new AutoSaver(Server.backupInterval);     //2 and a half mins

                blockThread = new Thread(new ThreadStart(delegate
                {
                    while (true)
                    {
                        Thread.Sleep(blockInterval * 1000);
                        foreach (Level l in levels)
                        {
                            l.saveChanges();
                        }
                    }
                }));
                blockThread.Start();

                locationChecker = new Thread(new ThreadStart(delegate
                {
                    while (true)
                    {
                        Thread.Sleep(3);
                        for (int i = 0; i < Player.players.Count; i++)
                        {
                            try
                            {
                                Player p = Player.players[i];

                                if (p.frozen)
                                {
                                    unchecked { p.SendPos((byte)-1, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]); } continue;
                                }
                                else if (p.following != "")
                                {
                                    Player who = Player.Find(p.following);
                                    if (who == null || who.level != p.level)
                                    {
                                        p.following = "";
                                        if (!p.canBuild)
                                        {
                                            p.canBuild = true;
                                        }
                                        if (who != null && who.possess == p.name)
                                        {
                                            who.possess = "";
                                        }
                                        continue;
                                    }
                                    if (p.canBuild)
                                    {
                                        unchecked { p.SendPos((byte)-1, who.pos[0], (ushort)(who.pos[1] - 16), who.pos[2], who.rot[0], who.rot[1]); }
                                    }
                                    else
                                    {
                                        unchecked { p.SendPos((byte)-1, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1]); }
                                    }
                                } else if (p.possess != "") {
                                    Player who = Player.Find(p.possess);
                                    if (who == null || who.level != p.level)
                                        p.possess = "";
                                }

                                ushort x = (ushort)(p.pos[0] / 32);
                                ushort y = (ushort)(p.pos[1] / 32);
                                ushort z = (ushort)(p.pos[2] / 32);

                                if (p.level.Death)
                                    p.RealDeath(x, y, z);
                                p.CheckBlock(x, y, z);

                                p.oldBlock = (ushort)(x + y + z);
                            } catch (Exception e) { Server.ErrorLog(e); }
                        }
                    }
                }));

                locationChecker.Start();

                Log("Finished setting up " + Server.name + ".");
            });
        }
Exemple #8
0
        void GenerateFault(float[] array, Level Lvl, string type, Random rand)
        {
            float startheight = 0.5f;
            float dispAux;
            ushort i, j, k, halfX, halfZ;
            float a, b, c, w, d;

            float DispMax, DispMin, DispChange;
            DispMax = 0.01f;
            DispChange = -0.0025f;
            if (type.Equals("mountains"))
            {
                DispMax = 0.02f;
                startheight = 0.6f;
            }
            else if (type.Equals("overlay"))
            {
                DispMax = 0.02f;
                DispChange = -0.01f;
            }

            for (int x = 0; x < array.Length; x++)
            {
                array[x] = startheight;
                //overlay[x] = 0.5f;
            }
            DispMin = -DispMax;
            float disp = DispMax;
            //if (terrainHeights == NULL)
            //    return (TERRAIN_ERROR_NOT_INITIALISED);

            halfX = (ushort)(Lvl.width / 2);
            halfZ = (ushort)(Lvl.height / 2);
            int numIterations = (int)((Lvl.width + Lvl.height));
            Server.s.Log("Iterations = " + numIterations.ToString());
            for (k = 0; k < numIterations; k++)
            {
                //s.Log("itteration " + k.ToString());
                d = (float)Math.Sqrt(halfX * halfX + halfZ * halfZ);
                w = (float)(rand.NextDouble() * 360);
                //w = (float)(rand.NextDouble()*90);
                a = (float)Math.Cos(w);
                b = (float)Math.Sin(w);

                c = ((float)rand.NextDouble()) * 2 * d - d;
                //c = ((float)rand.NextDouble() / 1) * 2 * d - d;
                //float disp = (float)(rand.NextDouble()* 0.02f - 0.01f);
                //iterationsDone++;
                //if (iterationsDone < itMinDisp)
                //    disp = maxDisp + (iterationsDone / (itMinDisp + 0.0)) * (minDisp - maxDisp);
                //else
                //    disp = minDisp;
                for (i = 0; i < Lvl.height; i++)
                {
                    for (j = 0; j < Lvl.width; j++)
                    {
                        //switch (terrainFunction)
                        //{
                        //case STEP:
                        if ((i - halfZ) * a + (j - halfX) * b + c > 0)
                            dispAux = disp;
                        else
                            dispAux = -disp;
                        //    break;
                        /*case SIN:
                            pd = ((i - halfZ) * a + (j - halfX) * b + c) / terrainWaveSize;
                            if (pd > 1.57) pd = 1.57;
                            else if (pd < 0) pd = 0;
                            dispAux = -disp / 2 + sin(pd) * disp;
                            break;
                        case COS:
                            pd = ((i - halfZ) * a + (j - halfX) * b + c) / terrainWaveSize;
                            if (pd > 3.14) pd = 3.14;
                            else if (pd < -3.14) pd = -3.14;
                            dispAux = disp - (terrainWaveSize / (terrainGridWidth + 0.0)) + cos(pd) * disp;
                            break;
                    }*/
                        //s.Log("adding " + dispAux.ToString());
                        AddTerrainHeight(array, j, i, Lvl.width, dispAux);
                        //terrainHeights[i * terrainGridWidth + j] += dispAux;
                    }
                }

                disp += DispChange;
                if (disp < DispMin) { disp = DispMax; }
            }
        }
Exemple #9
0
 void GeneratePerlinNoise(float[] array, Level Lvl, string type, Random rand)
 {
     GenerateNormalized(array, 0.7f, 8, Lvl.width, Lvl.height, rand.Next(), 64);
 }
Exemple #10
0
 //converts the float into a ushort for map height
 ushort Evaluate(Level lvl, float height)
 {
     ushort temp = (ushort)(height * lvl.depth);
     if (temp < 0) return 0;
     if (temp > lvl.depth - 1) return (ushort)(lvl.depth - 1);
     return temp;
 }
Exemple #11
0
        //applys the average filter
        void FilterAverage(Level Lvl)
        {
            Server.s.Log("Applying average filtering");

            float[] filtered = new float[terrain.Length];

            for (int bb = 0; bb < terrain.Length; bb++)
            {
                ushort x = (ushort)(bb % Lvl.width);
                ushort y = (ushort)(bb / Lvl.width);
                filtered[bb] = GetAverage9(x, y, Lvl);
            }

            for (int bb = 0; bb < terrain.Length; bb++)
            {
                terrain[bb] = filtered[bb];
            }
        }
Exemple #12
0
        //
        void AddTree(Level Lvl, ushort x, ushort y, ushort z, Random Rand)
        {
            byte height = (byte)Rand.Next(5, 8);
            for (ushort yy = 0; yy < height; yy++) Lvl.skipChange(x, (ushort)(y + yy), z, Block.trunk);

            short top = (short)(height - Rand.Next(2, 4));

            for (short xx = (short)-top; xx <= top; ++xx)
            {
                for (short yy = (short)-top; yy <= top; ++yy)
                {
                    for (short zz = (short)-top; zz <= top; ++zz)
                    {
                        short Dist = (short)(Math.Sqrt(xx * xx + yy * yy + zz * zz));
                        if (Dist < top + 1)
                        {
                            if (Rand.Next((int)(Dist)) < 2)
                            {
                                try
                                {
                                    Lvl.skipChange((ushort)(x + xx), (ushort)(y + yy + height), (ushort)(z + zz), Block.leaf);
                                }
                                catch { }
                            }
                        }
                    }
                }
            }
        }
Exemple #13
0
        void AddCactus(Level Lvl, ushort x, ushort y, ushort z, Random Rand)
        {
            byte height = (byte)Rand.Next(3, 6);
            ushort yy;

            for (yy = 0; yy <= height; yy++) Lvl.skipChange(x, (ushort)(y + yy), z, Block.green);

            int inX = 0, inZ = 0;

            switch (Rand.Next(1, 3))
            {
                case 1: inX = -1; break;
                case 2:
                default: inZ = -1; break;
            }

            for (yy = height; yy <= Rand.Next(height + 2, height + 5); yy++) Lvl.skipChange((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ), Block.green);
            for (yy = height; yy <= Rand.Next(height + 2, height + 5); yy++) Lvl.skipChange((ushort)(x - inX), (ushort)(y + yy), (ushort)(z - inZ), Block.green);
        }
Exemple #14
0
        public override void Use(Player p, string message)
        {
            string path;

            if (message.Split(' ').Length == 1) path = "levels/" + message + ".lvl";
            else if (message.Split(' ').Length == 2) try { path = @Server.backupLocation + "/" + message.Split(' ')[0] + "/" + int.Parse(message.Split(' ')[1]) + "/" + message.Split(' ')[0] + ".lvl"; }
                catch { Help(p); return; }
            else { Help(p); return; }

            if (File.Exists(path))
            {
                FileStream fs = File.OpenRead(path);
                try
                {

                    GZipStream gs = new GZipStream(fs, CompressionMode.Decompress);
                    byte[] ver = new byte[2];
                    gs.Read(ver, 0, ver.Length);
                    ushort version = BitConverter.ToUInt16(ver, 0);
                    Level level;
                    if (version == 1874)
                    {
                        byte[] header = new byte[16]; gs.Read(header, 0, header.Length);
                        ushort width = BitConverter.ToUInt16(header, 0);
                        ushort height = BitConverter.ToUInt16(header, 2);
                        ushort depth = BitConverter.ToUInt16(header, 4);
                        level = new Level(name, width, depth, height, "empty");
                        level.spawnx = BitConverter.ToUInt16(header, 6);
                        level.spawnz = BitConverter.ToUInt16(header, 8);
                        level.spawny = BitConverter.ToUInt16(header, 10);
                        level.rotx = header[12]; level.roty = header[13];
                    }
                    else
                    {
                        byte[] header = new byte[12]; gs.Read(header, 0, header.Length);
                        ushort width = version;
                        ushort height = BitConverter.ToUInt16(header, 0);
                        ushort depth = BitConverter.ToUInt16(header, 2);
                        level = new Level(name, width, depth, height, "grass");
                        level.spawnx = BitConverter.ToUInt16(header, 4);
                        level.spawnz = BitConverter.ToUInt16(header, 6);
                        level.spawny = BitConverter.ToUInt16(header, 8);
                        level.rotx = header[10]; level.roty = header[11];
                    }

                    level.setPhysics(0);

                    byte[] blocks = new byte[level.width * level.height * level.depth];
                    gs.Read(blocks, 0, blocks.Length);
                    level.blocks = blocks;
                    gs.Close();

                    level.backedup = true;
                    level.permissionbuild = LevelPermission.Admin;

                    level.jailx = (ushort)(level.spawnx * 32); level.jaily = (ushort)(level.spawny * 32); level.jailz = (ushort)(level.spawnz * 32);
                    level.jailrotx = level.rotx; level.jailroty = level.roty;

                    p.Loading = true;
                    foreach (Player pl in Player.players) if (p.level == pl.level && p != pl) p.SendDie(pl.id);
                    foreach (PlayerBot b in PlayerBot.playerbots) if (p.level == b.level) p.SendDie(b.id);

                    Player.GlobalDie(p, true);

                    p.level = level;
                    p.SendMotd();

                    p.SendRaw(2);
                    byte[] buffer = new byte[level.blocks.Length + 4];
                    BitConverter.GetBytes(IPAddress.HostToNetworkOrder(level.blocks.Length)).CopyTo(buffer, 0);
                    //ushort xx; ushort yy; ushort zz;

                    for (int i = 0; i < level.blocks.Length; ++i)
                        buffer[4 + i] = Block.Convert(level.blocks[i]);

                    buffer = Player.GZip(buffer);
                    int number = (int)Math.Ceiling(((double)buffer.Length) / 1024);
                    for (int i = 1; buffer.Length > 0; ++i)
                    {
                        short length = (short)Math.Min(buffer.Length, 1024);
                        byte[] send = new byte[1027];
                        Player.HTNO(length).CopyTo(send, 0);
                        Buffer.BlockCopy(buffer, 0, send, 2, length);
                        byte[] tempbuffer = new byte[buffer.Length - length];
                        Buffer.BlockCopy(buffer, length, tempbuffer, 0, buffer.Length - length);
                        buffer = tempbuffer;
                        send[1026] = (byte)(i * 100 / number);
                        p.SendRaw(3, send);
                        Thread.Sleep(10);
                    } buffer = new byte[6];
                    Player.HTNO((short)level.width).CopyTo(buffer, 0);
                    Player.HTNO((short)level.depth).CopyTo(buffer, 2);
                    Player.HTNO((short)level.height).CopyTo(buffer, 4);
                    p.SendRaw(4, buffer);

                    ushort x = (ushort)((0.5 + level.spawnx) * 32);
                    ushort y = (ushort)((1 + level.spawny) * 32);
                    ushort z = (ushort)((0.5 + level.spawnz) * 32);

                    p.aiming = false;
                    Player.GlobalSpawn(p, x, y, z, level.rotx, level.roty, true);
                    p.ClearBlockchange();
                    p.Loading = false;

                    if (message.IndexOf(' ') == -1)
                        level.name = "&cMuseum " + Server.DefaultColor + "(" + message.Split(' ')[0] + ")";
                    else
                        level.name = "&cMuseum " + Server.DefaultColor + "(" + message.Split(' ')[0] + " " + message.Split(' ')[1] + ")";

                    if (!p.hidden)
                    {
                        Player.GlobalChat(null, p.color + p.prefix + p.name + Server.DefaultColor + " went to the " + level.name, false);
                    }

                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                catch (Exception ex) { Player.SendMessage(p, "Error loading level."); Server.ErrorLog(ex); return; }
                finally { fs.Close(); }
            }
            else { Player.SendMessage(p, "Level or backup could not be found."); return; }
        }
Exemple #15
0
        public PlayerBot(string n, Level l, ushort x, ushort y, ushort z, byte rotx, byte roty)
        {
            name = n;
            color = "&1";
            id = FreeId();

            level = l;
            pos = new ushort[3] { x, y, z }; rot = new byte[2] { rotx, roty };
            GlobalSpawn();

            foreach (Player p in Player.players)
            {
                if (p.level == level)
                {
                    Player.SendMessage(p, color + name + Server.DefaultColor + ", the bot, has been added.");
                }
            }

            botTimer.Elapsed += delegate
            {
                int currentNum, foundNum = (32 * 75);
                Random rand = new Random();

                x = (ushort)Math.Round((decimal)pos[0] / (decimal)32);
                y = (ushort)((pos[1] - 33) / 32);
                z = (ushort)Math.Round((decimal)pos[2] / (decimal)32);

                if (kill)
                {
                    foreach (Player p in Player.players)
                    {
                        if ((ushort)(p.pos[0] / 32) == x)
                        {
                            if (Math.Abs((ushort)(p.pos[1] / 32) - y) < 2)
                            {
                                if ((ushort)(p.pos[2] / 32) == z)
                                {
                                    p.HandleDeath(Block.Zero);
                                }
                            }
                        }
                    }
                }

                if (Waypoints.Count < 1)
                {
                    if (hunt)
                        Player.players.ForEach(delegate(Player p)
                        {
                            if (p.level == level && !p.invincible)
                            {
                                currentNum = Math.Abs(p.pos[0] - pos[0]) + Math.Abs(p.pos[1] - pos[1]) + Math.Abs(p.pos[2] - pos[2]);
                                if (currentNum < foundNum)
                                {
                                    foundNum = currentNum;
                                    foundPos = p.pos;
                                    foundRot = p.rot;
                                    movement = true;
                                    rot[1] = (byte)(255 - foundRot[1]);
                                    if (foundRot[0] < 128) rot[0] = (byte)(foundRot[0] + 128);
                                    else rot[0] = (byte)(foundRot[0] - 128);
                                }
                            }
                        });
                }
                else
                {
                    bool skip = false;
                    movement = false;

                retry: switch (Waypoints[currentPoint].type)
                    {
                        case "walk":
                            foundPos[0] = Waypoints[currentPoint].x;
                            foundPos[1] = Waypoints[currentPoint].y;
                            foundPos[2] = Waypoints[currentPoint].z;
                            movement = true;

                            if ((ushort)(pos[0] / 32) == (ushort)(Waypoints[currentPoint].x / 32))
                            {
                                if ((ushort)(pos[2] / 32) == (ushort)(Waypoints[currentPoint].z / 32))
                                {
                                    rot[0] = Waypoints[currentPoint].rotx;
                                    rot[1] = Waypoints[currentPoint].roty;
                                    currentPoint++;
                                    movement = false;

                                    if (currentPoint == Waypoints.Count) currentPoint = 0;
                                    if (!skip) { skip = true; goto retry; }
                                }
                            }
                            break;
                        case "teleport":
                            pos[0] = Waypoints[currentPoint].x;
                            pos[1] = Waypoints[currentPoint].y;
                            pos[2] = Waypoints[currentPoint].z;
                            rot[0] = Waypoints[currentPoint].rotx;
                            rot[1] = Waypoints[currentPoint].roty;
                            currentPoint++;
                            if (currentPoint == Waypoints.Count) currentPoint = 0;
                            return;
                        case "wait":
                            if (countdown != 0)
                            {
                                countdown--;
                                if (countdown == 0)
                                {
                                    currentPoint++;
                                    if (currentPoint == Waypoints.Count) currentPoint = 0;
                                    if (!skip) { skip = true; goto retry; }
                                }
                            }
                            else
                            {
                                countdown = Waypoints[currentPoint].seconds;
                            }
                            return;
                        case "nod":
                            if (countdown != 0)
                            {
                                countdown--;

                                if (nodUp)
                                {
                                    if (rot[1] > 32 && rot[1] < 128) nodUp = !nodUp;
                                    else
                                    {
                                        if (rot[1] + (byte)Waypoints[currentPoint].rotspeed > 255) rot[1] = 0;
                                        else rot[1] += (byte)Waypoints[currentPoint].rotspeed;
                                    }
                                }
                                else
                                {
                                    if (rot[1] > 128 && rot[1] < 224) nodUp = !nodUp;
                                    else
                                    {
                                        if (rot[1] - (byte)Waypoints[currentPoint].rotspeed < 0) rot[1] = 255;
                                        else rot[1] -= (byte)Waypoints[currentPoint].rotspeed;
                                    }
                                }

                                if (countdown == 0)
                                {
                                    currentPoint++;
                                    if (currentPoint == Waypoints.Count) currentPoint = 0;
                                    if (!skip) { skip = true; goto retry; }
                                }
                            }
                            else
                            {
                                countdown = Waypoints[currentPoint].seconds;
                            }
                            return;
                        case "spin":
                            if (countdown != 0)
                            {
                                countdown--;

                                if (rot[0] + (byte)Waypoints[currentPoint].rotspeed > 255) rot[0] = 0;
                                else if (rot[0] + (byte)Waypoints[currentPoint].rotspeed < 0) rot[0] = 255;
                                else rot[0] += (byte)Waypoints[currentPoint].rotspeed;

                                if (countdown == 0)
                                {
                                    currentPoint++;
                                    if (currentPoint == Waypoints.Count) currentPoint = 0;
                                    if (!skip) { skip = true; goto retry; }
                                }
                            }
                            else
                            {
                                countdown = Waypoints[currentPoint].seconds;
                            }
                            return;
                        case "speed":
                            movementSpeed = (int)Math.Round((decimal)((decimal)24 / (decimal)100 * (decimal)Waypoints[currentPoint].seconds));
                            if (movementSpeed == 0) movementSpeed = 1;

                            currentPoint++;
                            if (currentPoint == Waypoints.Count) currentPoint = 0;
                            if (!skip) { skip = true; goto retry; }
                            return;
                        case "reset":
                            currentPoint = 0;
                            return;
                        case "remove":
                            removeBot();
                            return;
                        case "linkscript":
                            if (File.Exists("bots/" + Waypoints[currentPoint].newscript))
                            {
                                Command.all.Find("botset").Use(null, this.name + " " + Waypoints[currentPoint].newscript);
                                return;
                            }

                            currentPoint++;
                            if (currentPoint == Waypoints.Count) currentPoint = 0;
                            if (!skip) { skip = true; goto retry; }
                            return;
                        case "jump":
                            jumpTimer.Elapsed += delegate
                            {
                                currentjump++;
                                switch (currentjump)
                                {
                                    case 1:
                                    case 2: pos[1] += 24; break;
                                    case 3: break;
                                    case 4: pos[1] -= 24; break;
                                    case 5: pos[1] -= 24; jumping = false; currentjump = 0; jumpTimer.Stop(); break;
                                }
                            };
                            jumpTimer.Start();

                            currentPoint++;
                            if (currentPoint == Waypoints.Count) currentPoint = 0;
                            if (!skip) { skip = true; goto retry; }
                            break;
                    }

                    if (currentPoint == Waypoints.Count) currentPoint = 0;
                }

                if (!movement)
                {
                    if (rot[0] < 245) rot[0] += 8;
                    else rot[0] = 0;

                    if (rot[1] > 32 && rot[1] < 64) rot[1] = 224;
                    else if (rot[1] > 250) rot[1] = 0;
                    else rot[1] += 4;
                }
            };

            botTimer.Start();

            moveTimer.Elapsed += delegate
            {
                moveTimer.Interval = Server.updateTimer.Interval / movementSpeed;
                if (!movement) return;
                int newNum; Random rand = new Random();

                if ((pos[1] - 19) % 32 != 0 && !jumping)
                {
                    pos[1] = (ushort)((pos[1] + 19) - (pos[1] % 32));
                }

                x = (ushort)Math.Round((decimal)(pos[0] - 16) / (decimal)32);
                y = (ushort)((pos[1] - 64) / 32);
                z = (ushort)Math.Round((decimal)(pos[2] - 16) / (decimal)32);

                byte b = Block.Convert(level.GetTile(x, y, z));
                byte b1, b2, b3;//, b4;

                if (Block.Walkthrough(b) && !jumping)
                {
                    pos[1] = (ushort)(pos[1] - 32);
                }

                y = (ushort)((pos[1] - 64) / 32);   //Block below feet

                newNum = level.PosToInt((ushort)(x + Math.Sign(foundPos[0] - pos[0])), y, (ushort)(z + Math.Sign(foundPos[2] - pos[2])));
                b = Block.Convert(level.GetTile(newNum));
                b1 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 1, 0)));
                b2 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 2, 0)));
                b3 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 3, 0)));

                if (Block.Walkthrough(b2) && Block.Walkthrough(b3) && !Block.Walkthrough(b1))
                {     //Get ready to go up step
                    pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]);
                    pos[1] += (ushort)32;
                    pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]);
                }
                else if (Block.Walkthrough(b1) && Block.Walkthrough(b2))
                {                        //Stay on current level
                    pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]);
                    pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]);
                }
                else if (Block.Walkthrough(b) && Block.Walkthrough(b1))
                {                         //Drop a level
                    pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]);
                    pos[1] -= (ushort)32;
                    pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]);
                }

                x = (ushort)Math.Round((decimal)(pos[0] - 16) / (decimal)32);
                y = (ushort)((pos[1] - 64) / 32);
                z = (ushort)Math.Round((decimal)(pos[2] - 16) / (decimal)32);

                b1 = Block.Convert(level.GetTile(x, (ushort)(y + 1), z));
                b2 = Block.Convert(level.GetTile(x, (ushort)(y + 2), z));
                b3 = Block.Convert(level.GetTile(x, y, z));

                /*
                if ((ushort)(foundPos[1] / 32) > y) {
                    if (b1 == Block.water || b1 == Block.waterstill || b1 == Block.lava || b1 == Block.lavastill) {
                        if (Block.Walkthrough(b2)) {
                            pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1])));
                        }
                    } else if (b2 == Block.water || b2 == Block.waterstill || b2 == Block.lava || b2 == Block.lavastill) {
                        pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1])));
                    }
                } else if ((ushort)(foundPos[1] / 32) < y) {
                    if (b3 == Block.water || b3 == Block.waterstill || b3 == Block.lava || b3 == Block.lavastill) {
                        pos[1] = (ushort)(pos[1] + (Math.Sign(foundPos[1] - pos[1])));
                    }
                }*/
            };
            moveTimer.Start();
        }
Exemple #16
0
        //Averages over 9 points
        float GetAverage9(ushort x, ushort y, Level Lvl)
        {
            divide = 0.0f;
            float temp = GetPixel(x, y, Lvl);
            temp += GetPixel((ushort)(x + 1), y, Lvl);
            temp += GetPixel((ushort)(x - 1), y, Lvl);
            temp += GetPixel(x, (ushort)(y + 1), Lvl);
            temp += GetPixel(x, (ushort)(y - 1), Lvl);

            temp += GetPixel((ushort)(x + 1), (ushort)(y + 1), Lvl);
            temp += GetPixel((ushort)(x - 1), (ushort)(y + 1), Lvl);
            temp += GetPixel((ushort)(x + 1), (ushort)(y - 1), Lvl);
            temp += GetPixel((ushort)(x - 1), (ushort)(y - 1), Lvl);

            return temp / divide;
        }
Exemple #17
0
 public static void addLevel(Level level)
 {
     levels.Add(level);
 }
Exemple #18
0
 //returns the valve of a x,y terrain coordinate
 float GetPixel(ushort x, ushort y, Level Lvl)
 {
     if (x < 0) { return 0.0f; }
     if (x >= Lvl.width) { return 0.0f; }
     if (y < 0) { return 0.0f; }
     if (y >= Lvl.height) { return 0.0f; }
     divide += 1.0f;
     return terrain[x + y * Lvl.width];
 }
Exemple #19
0
        public override void Use(Player p, string message)
        {
            if (message == "") { Help(p); return; }

            string[] parameters = message.Split(' '); // Grab the parameters from the player's message
            if (parameters.Length == 5) // make sure there are 5 params
            {
                switch (parameters[4])
                {
                    case "flat":
                    case "pixel":
                    case "island":
                    case "mountains":
                    case "ocean":
                    case "forest":
                    case "desert":
                        break;

                    default:
                        Player.SendMessage(p, "Valid types: island, mountains, forest, ocean, flat, pixel, desert"); return;
                }

                string name = parameters[0].ToLower();
                ushort x = 1, y = 1, z = 1;
                try
                {
                    x = Convert.ToUInt16(parameters[1]);
                    y = Convert.ToUInt16(parameters[2]);
                    z = Convert.ToUInt16(parameters[3]);
                }
                catch { Player.SendMessage(p, "Invalid dimensions."); return; }
                if (!isGood(x)) { Player.SendMessage(p, x + " is not a good dimension! Use a power of 2 next time."); }
                if (!isGood(y)) { Player.SendMessage(p, y + " is not a good dimension! Use a power of 2 next time."); }
                if (!isGood(z)) { Player.SendMessage(p, z + " is not a good dimension! Use a power of 2 next time."); }

                if (!Player.ValidName(name)) { Player.SendMessage(p, "Invalid name!"); return; }

                try
                {
                    if (p != null)
                    if (p.group.Permission < LevelPermission.Admin)
                    {
                        if (x * y * z > 30000000) { Player.SendMessage(p, "Cannot create a map with over 30million blocks"); return; }
                    }
                    else
                    {
                        if (x * y * z > 225000000) { Player.SendMessage(p, "You cannot make a map with over 225million blocks"); return; }
                    }
                }
                catch
                {
                    Player.SendMessage(p, "An error occured");
                }

                // create a new level...
                try
                {
                    Level lvl = new Level(name, x, y, z, parameters[4]);
                    lvl.Save(true); //... and save it.
                }
                finally
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                Player.GlobalMessage("Level " + name + " created"); // The player needs some form of confirmation.
            }
            else
                Help(p);
        }
Exemple #20
0
        public bool GenerateMap(Level Lvl, string type)
        {
            Server.s.Log("Attempting map gen");
            if (Inuse) { Server.s.Log("Generator in use"); return false; }
            Random rand = new System.Random();
            try
            {
                Inuse = true;
                terrain = new float[Lvl.width * Lvl.height];
                overlay = new float[Lvl.width * Lvl.height];

                if (!type.Equals("ocean"))
                { overlay2 = new float[Lvl.width * Lvl.height]; }

                //float dispAux, pd;
                ushort WaterLevel = (ushort)(Lvl.depth / 2 + 2);

                if (type.Equals("ocean"))
                {
                    WaterLevel = (ushort)(Lvl.depth * 0.85f);
                }

                //Generate the level
                GenerateFault(terrain, Lvl, type, rand);

                //APPLY FILTER to terrain
                FilterAverage(Lvl);

                //CREATE OVERLAY
                //GenerateFault(overlay, Lvl, "overlay", rand);
                Server.s.Log("Creating overlay");
                GeneratePerlinNoise(overlay, Lvl, "", rand);

                if (!type.Equals("ocean") && type != "desert")
                {
                    Server.s.Log("Planning trees");
                    GeneratePerlinNoise(overlay2, Lvl, "", rand);
                }

                Server.s.Log("Converting height map");
                Server.s.Log("And applying overlays");
                float RangeLow = 0.2f;
                float RangeHigh = 0.8f;
                float TreeDens = 0.35f;
                short TreeDist = 3;
                //changes the terrain range based on type, also tree threshold
                switch (type)
                {
                    case "island":
                        RangeLow = 0.4f;
                        RangeHigh = 0.75f;
                        break;
                    case "forest":
                        RangeLow = 0.45f;
                        RangeHigh = 0.8f;
                        TreeDens = 0.7f;
                        TreeDist = 2;
                        break;
                    case "mountains":
                        RangeLow = 0.3f;
                        RangeHigh = 0.9f;
                        TreeDist = 4;
                        break;
                    case "ocean":
                        RangeLow = 0.1f;
                        RangeHigh = 0.6f;
                        break;
                    case "desert":
                        RangeLow = 0.5f;
                        RangeHigh = 0.85f;
                        WaterLevel = 0;
                        TreeDist = 24;
                        break;
                    default:
                        break;
                }

                //loops though evey X/Z coordinate
                for (int bb = 0; bb < terrain.Length; bb++)
                {
                    ushort x = (ushort)(bb % Lvl.width);
                    ushort y = (ushort)(bb / Lvl.width);
                    ushort z;
                    if (type.Equals("island"))
                    {
                        z = Evaluate(Lvl, Range(terrain[bb], RangeLow - NegateEdge(x, y, Lvl), RangeHigh - NegateEdge(x, y, Lvl)));
                    }
                    else
                    {
                        z = Evaluate(Lvl, Range(terrain[bb], RangeLow, RangeHigh));
                    }
                    if (z > WaterLevel)
                    {
                        for (ushort zz = 0; z - zz >= 0; zz++)
                        {
                            if (type == "desert")
                            {
                                Lvl.skipChange(x, (ushort)(z - zz), y, Block.sand);
                            }
                            else if (overlay[bb] < 0.72f)    //If not zoned for rocks or gravel
                            {
                                if (type.Equals("island"))      //increase sand height for island
                                {
                                    if (z > WaterLevel + 2)
                                    {
                                        if (zz == 0) { Lvl.skipChange(x, (ushort)(z - zz), y, Block.grass); }      //top layer
                                        else if (zz < 3) { Lvl.skipChange(x, (ushort)(z - zz), y, Block.dirt); }   //next few
                                        else { Lvl.skipChange(x, (ushort)(z - zz), y, Block.rock); }               //ten rock it
                                    }
                                    else
                                    {
                                        Lvl.skipChange(x, (ushort)(z - zz), y, Block.sand);                        //SAAAND extra for islands
                                    }
                                }
                                else if (type == "desert")
                                {
                                    Lvl.skipChange(x, (ushort)(z - zz), y, Block.sand);
                                }
                                else
                                {
                                    if (zz == 0) { Lvl.skipChange(x, (ushort)(z - zz), y, Block.grass); }
                                    else if (zz < 3) { Lvl.skipChange(x, (ushort)(z - zz), y, Block.dirt); }
                                    else { Lvl.skipChange(x, (ushort)(z - zz), y, Block.rock); }
                                }
                            }
                            else
                            {
                                Lvl.skipChange(x, (ushort)(z - zz), y, Block.rock);    //zoned for above sea level rock floor
                            }
                        }

                        if (overlay[bb] < 0.25f && type != "desert")    //Zoned for flowers
                        {
                            int temprand = rand.Next(12);

                            switch (temprand)
                            {
                                case 10:
                                    Lvl.skipChange(x, (ushort)(z + 1), y, Block.redflower);
                                    break;
                                case 11:
                                    Lvl.skipChange(x, (ushort)(z + 1), y, Block.yellowflower);
                                    break;
                                default:
                                    break;
                            }
                        }

                        if (!type.Equals("ocean"))
                        {
                            if (overlay[bb] < 0.65f && overlay2[bb] < TreeDens)
                            {
                                if (Lvl.GetTile(x, (ushort)(z + 1), y) == Block.air)
                                {
                                    if (Lvl.GetTile(x, z, y) == Block.grass || type == "desert")
                                    {
                                        if (rand.Next(13) == 0)
                                        {
                                            if (!TreeCheck(Lvl, x, z, y, TreeDist))
                                            {
                                                if (type == "desert")
                                                    AddCactus(Lvl, x, (ushort)(z + 1), y, rand);
                                                else
                                                    AddTree(Lvl, x, (ushort)(z + 1), y, rand);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                    }
                    else    //Must be on/under the water line then
                    {
                        for (ushort zz = 0; WaterLevel - zz >= 0; zz++)
                        {
                            if (WaterLevel - zz > z)
                            { Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.water); }    //better fill the water aboce me
                            else if (WaterLevel - zz > z - 3)
                            {
                                if (overlay[bb] < 0.75f)
                                {
                                    Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.sand);   //sand top
                                }
                                else
                                {
                                    Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.gravel);  //zoned for gravel
                                }
                            }
                            else
                            {
                                Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.rock);
                            }
                        }
                    }
                }

            }
            catch (Exception e)
            {
                Server.ErrorLog(e);
                Server.s.Log("Gen Fail");
                Inuse = false;
                return false;
            }

            terrain = new float[0]; //Derp
            overlay = new float[0]; //Derp
            overlay2 = new float[0]; //Derp

            Inuse = false;

            return true;
        }
Exemple #21
0
        public static ushort writeLetter(Level l, Player p, char c, ushort x, ushort y, ushort z, byte b, int directionToGo)
        {
            switch (c)
            {
                case 'A':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case 'B':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case 'C':
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'D':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case 'E':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'F':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'G':
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'H':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'I':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'J':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'K':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'L':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    break;
                case 'M':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'N':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'O':
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case 'P':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case 'Q':
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case 'R':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case 'S':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'T':
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'U':
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'V':
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'W':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'X':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'Y':
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case 'Z':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;

                case '0':
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case '1':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    break;
                case '2':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case '3':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case '4':
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    break;
                case '5':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case '6':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case '7':
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case '8':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case '9':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;

                case ':':
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case '\\':
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    break;
                case '/':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case '.':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    break;
                case '!':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    break;
                case ',':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    break;
                case '\'':
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case '"':
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 4), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;
                case ' ':
                    break;

                case '+':
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    break;
                case '-':
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 2), z, b);
                    break;
                case '_':
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 0), z, b);
                    break;
                case '=':
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    placeBlock(l, p, x, (ushort)(y + 1), z, b);
                    placeBlock(l, p, x, (ushort)(y + 3), z, b);
                    break;

                default:
                    Player.SendMessage(p, "\"" + c + "\" is currently not supported. Space left");
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    if (directionToGo == 0) x++; else if (directionToGo == 1) x--; else if (directionToGo == 2) z++; else z--;
                    break;
            }

            if (directionToGo == 0) return (ushort)(x + 2);
            else if (directionToGo == 1) return (ushort)(x - 2);
            else if (directionToGo == 2) return (ushort)(z + 2);
            else return (ushort)(z - 2);
        }
Exemple #22
0
 public byte GetTile(ushort x, ushort y, ushort z, Level l, byte[] blocks)
 {
     //if (PosToInt(x, y, z) >= blocks.Length) { return null; }
     //Avoid internal overflow
     if (x < 0) { return Block.Zero; }
     if (x >= l.width) { return Block.Zero; }
     if (y < 0) { return Block.Zero; }
     if (y >= l.depth) { return Block.Zero; }
     if (z < 0) { return Block.Zero; }
     if (z >= l.height) { return Block.Zero; }
     try
     {
         return blocks[l.PosToInt(x, y, z)];
     }
     catch (Exception e) { Server.ErrorLog(e); return Block.Zero; }
 }