public bool CheckIfInsideBlock() { ushort x = (ushort)(pos[0] / 32), y = (ushort)(pos[1] / 32), z = (ushort)(pos[2] / 32); byte head = level.GetTile(x, y, z); byte feet = level.GetTile(x, (ushort)(y - 1), z); return(!(Block.Walkthrough(Block.Convert(head)) || head == Block.Zero) && !(Block.Walkthrough(Block.Convert(feet)) || feet == Block.Zero)); }
public void AddCactus(Level Lvl, ushort x, ushort y, ushort z, Random Rand, bool blockChange = false, bool overwrite = true, Player p = null) { byte height = (byte)Rand.Next(3, 6); ushort yy; for (yy = 0; yy <= height; yy++) { if (overwrite || Lvl.GetTile(z, (ushort)(y + yy), z) == Block.air) if (blockChange) if (p == null) Lvl.Blockchange(x, (ushort)(y + yy), z, Block.green); else Lvl.Blockchange(p, x, (ushort)(y + yy), z, Block.green); else 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++) { if (overwrite || Lvl.GetTile((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ)) == Block.air) if (blockChange) if (p == null) Lvl.Blockchange((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ), Block.green); else Lvl.Blockchange(p, (ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ), Block.green); else Lvl.skipChange((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ), Block.green); } for (yy = height; yy <= Rand.Next(height + 2, height + 5); yy++) { if (overwrite || Lvl.GetTile((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ)) == Block.air) if (blockChange) if (p == null) Lvl.Blockchange((ushort)(x - inX), (ushort)(y + yy), (ushort)(z - inZ), Block.green); else Lvl.Blockchange(p, (ushort)(x - inX), (ushort)(y + yy), (ushort)(z - inZ), Block.green); else Lvl.skipChange((ushort)(x - inX), (ushort)(y + yy), (ushort)(z - inZ), Block.green); } }
protected void PlaceBlock(Player p, Level lvl, ushort x, ushort y, ushort z, byte type, byte extType) { switch (method) { case MethodBlockQueue: BlockQueue.Addblock(p, x, y, z, type, extType); break; case MethodBlockChange: p.level.Blockchange(p, x, y, z, type, extType); break; case MethodSetTile: byte old = lvl.GetTile(x, y, z); if (old == Block.Zero || !lvl.CheckAffectPermissions(p, x, y, z, old, type)) return; p.level.SetTile(x, y, z, type, p, extType); break; } }
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2, Player p, Level lvl, Brush brush) { ReplaceBlock[] toReplace = ToReplace; ReplaceBlock target = Target; for (ushort y = y1; y <= y2; y++) for (ushort z = z1; z <= z2; z++) for (ushort x = x1; x <= x2; x++) { byte tile = lvl.GetTile(x, y, z), extTile = 0; if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z); for (int i = 0; i < toReplace.Length; i++) { ReplaceBlock block = toReplace[i]; if (tile != block.Type || (tile == Block.custom_block && extTile != block.ExtType)) { PlaceBlock(p, lvl, x, y, z, target.Type, target.ExtType); break; } } } }
internal static void LoadMessages(Level level, string name) { level.hasMessageBlocks = Database.TableExists("Messages" + name); if (!level.hasMessageBlocks) { return; } using (DataTable table = Database.Backend.GetRows("Messages" + name, "*")) { foreach (DataRow row in table.Rows) { ushort x = ushort.Parse(row["X"].ToString()); ushort y = ushort.Parse(row["Y"].ToString()); ushort z = ushort.Parse(row["Z"].ToString()); byte block = level.GetTile(x, y, z); if (block == Block.custom_block) { block = level.GetExtTile(x, y, z); if (level.CustomBlockProps[block].IsMessageBlock) { continue; } } else { if (Block.Props[block].IsMessageBlock) { continue; } } Database.Backend.DeleteRows("Messages" + name, "WHERE X=@0 AND Y=@1 AND Z=@2", x, y, z); } } }
void GenNonLavaColumn(ushort x, ushort y, ushort z, Level Lvl, int index) { if (y > LiquidLevel) { int pos = x + Lvl.Width * (z + y * Lvl.Length); for (ushort yy = 0; y - yy >= 0; yy++) { if (genParams.SimpleColumns) { Lvl.blocks[pos] = Block.sand; } else if (overlay[index] < 0.72f) { if (genParams.IslandColumns) //increase sand height for island { if (y > LiquidLevel + 2) { if (yy == 0) { Lvl.blocks[pos] = Block.grass; //top layer } else if (yy < 3) { Lvl.blocks[pos] = Block.dirt; //next few } else { Lvl.blocks[pos] = Block.rock; //ten rock it } } else { Lvl.blocks[pos] = Block.sand; //SAAAND extra for islands } } else { if (yy == 0) { Lvl.blocks[pos] = Block.grass; } else if (yy < 3) { Lvl.blocks[pos] = Block.dirt; } else { Lvl.blocks[pos] = Block.rock; } } } else { Lvl.blocks[pos] = Block.rock; } pos -= Lvl.Width * Lvl.Length; } if (genParams.GenFlowers && overlay[index] < 0.25f) { switch (rand.Next(12)) { case 10: Lvl.SetTile(x, (ushort)(y + 1), z, Block.redflower); break; case 11: Lvl.SetTile(x, (ushort)(y + 1), z, Block.yellowflower); break; default: break; } } if (genParams.GenTrees && overlay[index] < 0.65f && overlay2[index] < treeDens) { if (Lvl.GetTile(x, (ushort)(y + 1), z) == Block.air) { if (Lvl.GetTile(x, y, z) == Block.grass || genParams.UseCactus) { if (rand.Next(13) == 0 && !TreeDrawOp.TreeCheck(Lvl, x, y, z, treeDist)) { treeDrawer.Type = genParams.UseCactus ? TreeDrawOp.T_Cactus : TreeDrawOp.T_Tree; treeCoords[0].X = x; treeCoords[0].Y = (ushort)(y + 1); treeCoords[0].Z = z; treeDrawer.Perform(treeCoords, null, Lvl, null); } } } } } else //Must be on/under the water line then { int pos = x + Lvl.Width * (z + LiquidLevel * Lvl.Length); for (ushort yy = 0; LiquidLevel - yy >= 0; yy++) { if (LiquidLevel - yy > y) { Lvl.blocks[pos] = Block.water; //better fill the water above me } else if (LiquidLevel - yy > y - 3) { byte block = overlay[index] < 0.75f ? Block.sand : Block.gravel; // sand on top Lvl.blocks[pos] = block; } else { Lvl.blocks[pos] = Block.rock; } pos -= Lvl.Width * Lvl.Length; } } }
void MoveTimerFunc(object sender, ElapsedEventArgs e) { 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)); } ushort x = (ushort)Math.Round((decimal)(pos[0] - 16) / 32); ushort y = (ushort)((pos[1] - 64) / 32); ushort z = (ushort)Math.Round((decimal)(pos[2] - 16) / 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]))); * } * }*/ }
void DoMove() { if ((pos[1] - 19) % 32 != 0 && !jumping) { pos[1] = (ushort)((pos[1] + 19) - (pos[1] % 32)); } ushort x = (ushort)Math.Round((decimal)(pos[0] - 16) / 32); ushort y = (ushort)((pos[1] - 64) / 32); ushort z = (ushort)Math.Round((decimal)(pos[2] - 16) / 32); int dx = Math.Sign(foundPos[0] - pos[0]), dz = Math.Sign(foundPos[2] - pos[2]); byte b = Block.Convert(level.GetTile(x, y, z)); byte b1, b2, b3; if (Block.Walkthrough(b) && !jumping) { pos[1] = (ushort)(pos[1] - 32); } y = (ushort)((pos[1] - 64) / 32); //Block below feet int index = level.PosToInt((ushort)(x + dx), y, (ushort)(z + dz)); b = Block.Convert(level.GetTile(index)); b1 = Block.Convert(level.GetTile(level.IntOffset(index, 0, 1, 0))); b2 = Block.Convert(level.GetTile(level.IntOffset(index, 0, 2, 0))); b3 = Block.Convert(level.GetTile(level.IntOffset(index, 0, 3, 0))); if (Block.Walkthrough(b2) && Block.Walkthrough(b3) && !Block.Walkthrough(b1)) { pos[0] += (ushort)dx; // Get ready to go up step pos[1] += (ushort)32; pos[2] += (ushort)dz; } else if (Block.Walkthrough(b1) && Block.Walkthrough(b2)) { pos[0] += (ushort)dx; // Stay on current level pos[2] += (ushort)dz; } else if (Block.Walkthrough(b) && Block.Walkthrough(b1)) { pos[0] += (ushort)dx; // Drop a level pos[1] -= (ushort)32; pos[2] += (ushort)dz; } /*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]))); * } * }*/ }
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(); }
//givenName is safe against SQL injections, it gets checked in CmdLoad.cs public static Level Load(string givenName, byte phys) { if (LevelLoad != null) { LevelLoad(givenName); } OnLevelLoadEvent.Call(givenName); if (cancelload) { cancelload = false; return(null); } CreateLeveldb(givenName); string path = LevelInfo.LevelPath(givenName); if (File.Exists(path)) { try { Level level = LvlFile.Load(givenName, path); level.setPhysics(phys); level.backedup = true; using (DataTable ZoneDB = Database.fillData("SELECT * FROM `Zone" + givenName + "`")) { Zone Zn; for (int i = 0; i < ZoneDB.Rows.Count; ++i) { DataRow row = ZoneDB.Rows[i]; Zn.smallX = ushort.Parse(row["SmallX"].ToString()); Zn.smallY = ushort.Parse(row["SmallY"].ToString()); Zn.smallZ = ushort.Parse(row["SmallZ"].ToString()); Zn.bigX = ushort.Parse(row["BigX"].ToString()); Zn.bigY = ushort.Parse(row["BigY"].ToString()); Zn.bigZ = ushort.Parse(row["BigZ"].ToString()); Zn.Owner = row["Owner"].ToString(); level.ZoneList.Add(Zn); } } 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.StartPhysics(); //level.physChecker.Elapsed += delegate //{ // if (!level.physicssate && level.physics > 0) // level.StartPhysics(); //}; //level.physChecker.Start(); try { DataTable foundDB = Database.fillData("SELECT * FROM `Portals" + givenName + "`"); for (int i = 0; i < foundDB.Rows.Count; ++i) { DataRow row = foundDB.Rows[i]; if ( !Block.portal(level.GetTile(ushort.Parse(row["EntryX"].ToString()), ushort.Parse(row["EntryY"].ToString()), ushort.Parse(row["EntryZ"].ToString())))) { Database.executeQuery("DELETE FROM `Portals" + givenName + "` WHERE EntryX=" + row["EntryX"] + " AND EntryY=" + row["EntryY"] + " AND EntryZ=" + row["EntryZ"]); } } foundDB = Database.fillData("SELECT * FROM `Messages" + givenName + "`"); for (int i = 0; i < foundDB.Rows.Count; ++i) { DataRow row = foundDB.Rows[i]; if ( !Block.mb(level.GetTile(ushort.Parse(row["X"].ToString()), ushort.Parse(row["Y"].ToString()), ushort.Parse(row["Z"].ToString())))) { //givenName is safe against SQL injections, it gets checked in CmdLoad.cs Database.executeQuery("DELETE FROM `Messages" + givenName + "` WHERE X=" + row["X"] + " AND Y=" + row["Y"] + " AND Z=" + row["Z"]); } } foundDB.Dispose(); } catch (Exception e) { Server.ErrorLog(e); } try { string propsPath = LevelInfo.GetPropertiesPath(level.name); if (propsPath != null) { LvlProperties.Load(level, propsPath); } else { Server.s.Log(".properties file for level " + level.name + " was not found."); } LvlProperties.LoadEnv(level, level.name); } catch (Exception e) { Server.ErrorLog(e); } BlockDefinition[] defs = BlockDefinition.Load(false, level); for (int i = 0; i < defs.Length; i++) { if (defs[i] == null) { continue; } level.CustomBlockDefs[i] = defs[i]; } Server.s.Log(string.Format("Level \"{0}\" loaded.", level.name)); if (LevelLoaded != null) { LevelLoaded(level); } OnLevelLoadedEvent.Call(level); return(level); } catch (Exception ex) { Server.ErrorLog(ex); return(null); } } Server.s.Log("ERROR loading level."); return(null); }
public void SendToSpawn(Level mainlevel, Auto_CTF game, Player p1) { Random rand = new Random(); if (spawnx == 0 && spawny == 0 && spawnz == 0) { ushort xx = (ushort)(rand.Next(0, mainlevel.Width)); ushort yy = (ushort)(rand.Next(0, mainlevel.Height)); ushort zz = (ushort)(rand.Next(0, mainlevel.Length)); while (mainlevel.GetTile(xx, yy, zz) != Block.air && game.OnSide((ushort)(zz * 32), this)) { xx = (ushort)(rand.Next(0, mainlevel.Width)); yy = (ushort)(rand.Next(0, mainlevel.Height)); zz = (ushort)(rand.Next(0, mainlevel.Length)); } unchecked { p1.SendPos((byte)-1, (ushort)(xx * 32), (ushort)(yy * 32), (ushort)(zz * 32), p1.rot[0], p1.rot[1]); } } else unchecked { p1.SendPos((byte)-1, spawnx, spawny, spawnz, p1.rot[0], p1.rot[1]); } }
private bool TreeCheck(Level Lvl, ushort x, ushort z, ushort y, short dist) //return true if tree is near { byte foundTile; for (short xx = (short)-dist; xx <= +dist; ++xx) { for (short yy = (short)-dist; yy <= +dist; ++yy) { for (short zz = (short)-dist; zz <= +dist; ++zz) { foundTile = Lvl.GetTile((ushort)(x + xx), (ushort)(z + zz), (ushort)(y + yy)); if (foundTile == Block.trunk || foundTile == Block.green) { return true; } } } } return false; }
public void AddNotchSwampTree(Level Lvl, ushort x, ushort y, ushort z, Random Rand, bool blockChange = false, bool overwrite = true, Player p = null) { byte dist, tile; byte height = (byte)Rand.Next(4, 8); byte top = (byte)(height - 2); short xx, yy, zz; ushort xxx, yyy, zzz; for (yy = 0; yy <= height; yy++) { yyy = (ushort)(y + yy); tile = Lvl.GetTile(x, yyy, z); if (overwrite || tile == Block.air || (yyy == y && tile == Block.shrub)) if (blockChange) if (p == null) Lvl.Blockchange(x, yyy, z, Block.trunk); else Lvl.Blockchange(p, x, yyy, z, Block.trunk); else Lvl.SetTile(x, yyy, z, Block.trunk); } for (yy = top; yy <= height + 1; yy++) { dist = yy > height - 1 ? (byte)2 : (byte)3; for (xx = (short)-dist; xx <= dist; xx++) { for (zz = (short)-dist; zz <= dist; zz++) { xxx = (ushort)(x + xx); yyy = (ushort)(y + yy); zzz = (ushort)(z + zz); tile = Lvl.GetTile(xxx, yyy, zzz); //Server.s.Log(String.Format("{0} {1} {2}", xxx, yyy, zzz)); if ((xxx == x && zzz == z && yy <= height) || (!overwrite && tile != Block.air)) continue; if (Math.Abs(xx) == dist && Math.Abs(zz) == dist) { if (yy > height) continue; if (Rand.Next(2) == 0) { if (blockChange) if (p == null) Lvl.Blockchange(xxx, yyy, zzz, Block.leaf); else Lvl.Blockchange(p, xxx, yyy, zzz, Block.leaf); else Lvl.SetTile(xxx, yyy, zzz, Block.leaf); } } else { if (blockChange) if (p == null) Lvl.Blockchange(xxx, yyy, zzz, Block.leaf); else Lvl.Blockchange(p, xxx, yyy, zzz, Block.leaf); else Lvl.SetTile(xxx, yyy, zzz, Block.leaf); } } } } }
// public void AddTree(Level Lvl, ushort x, ushort y, ushort z, Random Rand, bool blockChange = false, bool overwrite = true, Player p = null) { byte height = (byte)Rand.Next(5, 8); short top = (short)(height - Rand.Next(2, 4)); ushort xxx, yyy, zzz; for (ushort yy = 0; yy < top + height - 1; yy++) { if (overwrite || Lvl.GetTile(x, (ushort)(y + yy), z) == Block.air || (y + yy == y && Lvl.GetTile(x, (ushort)(y + yy), z) == Block.shrub)) if (blockChange) if (p == null) Lvl.Blockchange(x, (ushort)(y + yy), z, Block.trunk); else Lvl.Blockchange(p, x, (ushort)(y + yy), z, Block.trunk); else Lvl.SetTile(x, (ushort)(y + yy), z, Block.trunk); } 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 { xxx = (ushort)(x + xx); yyy = (ushort)(y + yy + height); zzz = (ushort)(z + zz); if ((xxx != x || zzz != z || yy >= top - 1) && (overwrite || Lvl.GetTile(xxx, yyy, zzz) == Block.air)) if (blockChange) if (p == null) Lvl.Blockchange(xxx, yyy, zzz, Block.leaf); else Lvl.Blockchange(p, xxx, yyy, zzz, Block.leaf); else Lvl.SetTile(xxx, yyy, zzz, Block.leaf); } catch { } } } } } } }
public bool GenerateMap(Level Lvl, string type, int seed = 0, bool useSeed = false) { DateTime startTime = DateTime.Now; Server.s.Log("Attempting map gen"); if (Inuse) { Server.s.Log("Generator in use"); return false; } Random rand = useSeed ? new System.Random(seed) : new System.Random(); try { Inuse = true; terrain = new float[Lvl.Width * Lvl.Length]; //hmm overlay = new float[Lvl.Width * Lvl.Length]; if (!type.Equals("ocean")) { overlay2 = new float[Lvl.Width * Lvl.Length]; } //float dispAux, pd; ushort WaterLevel = (ushort)(Lvl.Height / 2 + 2); ushort LavaLevel = 5; if (type.Equals("ocean")) { WaterLevel = (ushort)(Lvl.Height * 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 "hell": RangeLow = .3f; RangeHigh = 1.3f; break; 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 (type != "hell") { #region nonLavaWorld if (z > WaterLevel) { for (ushort zz = 0; z - zz >= 0; zz++) { if (type == "desert") { Lvl.SetTile(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.SetTile(x, (ushort)(z - zz), y, Block.grass); } //top layer else if (zz < 3) { Lvl.SetTile(x, (ushort)(z - zz), y, Block.dirt); } //next few else { Lvl.SetTile(x, (ushort)(z - zz), y, Block.rock); } //ten rock it } else { Lvl.SetTile(x, (ushort)(z - zz), y, Block.sand); //SAAAND extra for islands } } else if (type == "desert") { Lvl.SetTile(x, (ushort)(z - zz), y, Block.sand); } else { if (zz == 0) { Lvl.SetTile(x, (ushort)(z - zz), y, Block.grass); } else if (zz < 3) { Lvl.SetTile(x, (ushort)(z - zz), y, Block.dirt); } else { Lvl.SetTile(x, (ushort)(z - zz), y, Block.rock); } } } else { Lvl.SetTile(x, (ushort)(z - zz), y, Block.rock); } } if (overlay[bb] < 0.25f && type != "desert") //Zoned for flowers { switch (rand.Next(12)) { case 10: Lvl.SetTile(x, (ushort)(z + 1), y, Block.redflower); break; case 11: Lvl.SetTile(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.SetTile(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.SetTile(x, (ushort)(WaterLevel - zz), y, Block.sand); //sand top } else { Lvl.SetTile(x, (ushort)(WaterLevel - zz), y, Block.gravel); //zoned for gravel } } else { Lvl.SetTile(x, (ushort)(WaterLevel - zz), y, Block.rock); } } } #endregion } else //all of lava world generation { if (z > LavaLevel) { for (ushort zz = 0; z - zz >= 0; zz++) { if (z > (LavaLevel - 1)) { if (zz == 0) { Lvl.SetTile(x, (ushort)(z - zz), y, Block.rock); } //top layer else if (zz < 3) { Lvl.SetTile(x, (ushort)(z - zz), y, Block.rock); } else if (zz < 2) { Lvl.SetTile(x, (ushort)(z - zz), y, Block.lava); }//next few else { Lvl.SetTile(x, (ushort)(z - zz), y, Block.obsidian); } } else { Lvl.SetTile(x, (ushort)(z - zz), y, Block.lava); } if (overlay[bb] < 0.3f) { switch (rand.Next(13)) { case 9: case 10: case 11: case 12: Lvl.SetTile(x, (ushort)(z + 1), y, Block.lava); //change to lava when time break; default: break; } } // if (zz == z) Lvl.skipChange(x, (ushort)(z - zz), y, Block.opsidian); Lvl.SetTile(x, (ushort)(z), y, (rand.Next(100) % 3 == 1 ? Block.darkgrey : Block.obsidian)); } } else { for (ushort zz = 0; LavaLevel - zz >= 0; zz++) { if (LavaLevel - zz > z - 1) { /*if (Lvl.GetTile(x, z, y) == Block.air)*/ Lvl.SetTile(x, (ushort)(LavaLevel - zz), y, Block.lava); } //better fill the water aboce me else if (LavaLevel - zz > z - 3) { if (overlay[bb] < .9f) { if (zz < z) Lvl.SetTile(x, (ushort)(z - zz), (ushort)(y), Block.lava); else Lvl.SetTile(x, (ushort)(z - zz), y, Block.rock); } else { Lvl.SetTile(x, (ushort)(LavaLevel - zz), (ushort)(y - 5), Block.lava); //killer lava } } else { Lvl.SetTile(x, (ushort)(LavaLevel - zz), y, Block.stone); //and just make the rest cobblestone } } } } } Server.s.Log("Total time was " + (DateTime.Now - startTime).TotalSeconds.ToString() + " seconds."); } 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; }