public static double GetDistanceBetween(Player player, int targetX, int targetY) { double a = player.blockX - targetX; double b = player.blockY - targetY; double distance = Math.Sqrt(a * a + b * b); return distance; }
public override void Update(Bot bot) { if (updateTimer.ElapsedMilliseconds >= 1000) { updateTimer.Restart(); double lowestDistance = 0; Player lowestDistancePlayer = null; lock (bot.playerList) { foreach (Player player in bot.playerList.Values) { if (player.isgod) continue; double currentDistance = GetDistanceBetween(player, xBlock, yBlock); if (currentDistance < lowestDistance || lowestDistance == 0) { lowestDistance = currentDistance; lowestDistancePlayer = player; } } } if (lowestDistancePlayer != null) { targetPlayer = lowestDistancePlayer; } } if (targetPlayer != null && xBlock != targetPlayer.x && yBlock != targetPlayer.y) { //pathFinding = null; //pathFinding = new PathFinding(); //lagTimer.Restart(); pathToGo = pathFinding.Start(xBlock, yBlock, targetPlayer.blockX, targetPlayer.blockY, bot); //Console.WriteLine("elapsed shitlagtime " + lagTimer.ElapsedMilliseconds + "MS"); if (pathToGo != null && pathToGo.Count != 0) { if (pathToGo.Count > 2) { pathToGo.Pop(); pathToGo.Pop(); } Square next = pathToGo.Pop(); xBlock = next.x; yBlock = next.y; } if (targetPlayer != null) { if (GetDistanceBetween(targetPlayer, xBlock, yBlock) <= 1 && !targetPlayer.isgod) { targetPlayer.killPlayer(); bot.connection.Send("say", "/kill " + targetPlayer.name); } } } base.Update(bot); }
public override void onCommand(object sender, string text, string[] args, Player player, bool isBotMod, Bot bot) { switch (args[0]) { case "resetredstone": if (isBotMod) ResetRed(); break; } }
public override void onCommand(object sender, string text, string[] args, Player player, bool isBotMod, Bot bot) { switch (args[0]) { case "zombie": if(isBotMod) { Zombie zombie = new Zombie(player.blockX * 16, player.blockY * 16); lock (zombieList) { zombieList.Add(zombie); } //bot.room.DrawBlock(Block.CreateBlock(0, bot.playerList[playerId].blockX, bot.playerList[playerId].blockY, 32, 0)); } break; case "zombies": { for (int i = 0; i < 3; i++) { int x = r.Next(1, bot.room.Width - 1); int y = r.Next(1, bot.room.Height - 1); Zombie zombie = new Zombie(x * 16, y * 16); lock (zombieList) { zombieList.Add(zombie); } } } break; case "removezombies": { lock (zombieList) { zombieList.Clear(); } } break; } }
public override void onCommand(object sender, string text, string[] args, Player player, bool isBotMod, Bot bot) { if (isBotMod) { switch (args[0]) { case "crash": Thread.Sleep(61000); throw new System.Exception("I'm a happy error in a sunny day."); break; case "roomname": if (args.Length > 1) bot.connection.Send("name", string.Join(" ", args).Replace("roomname ", "")); break; case "woot": bot.connection.Send("wootup"); break; case "reset": bot.connection.Send("say", "/reset"); break; case "load": bot.connection.Send("say", "/loadlevel"); break; case "save": bot.connection.Send("save"); break; case "clear": bot.connection.Send("clear"); break; case "ping": bot.connection.Send("say", "Pong!"); break; case "pos": bot.connection.Send("say", "Your position: X:" + player.blockX + " Y:" + player.blockY); break; } } }
public override void onCommand(object sender, string text, string[] args, Player player, bool isBotMod, Bot bot) { }
public override void onCommand(object sender, string text, string[] args, Player player, bool isBotMod, Bot bot) { if (isBotMod) { switch (args[0]) { case "genmaze": { Stack<BlockPos> points = new Stack<BlockPos>(); points.Push(new BlockPos(0, player.blockX & 0xFFFE, player.blockY & 0xFFFE)); points.Push(new BlockPos(0, player.blockX & 0xFFFE, player.blockY & 0xFFFE)); int maxLength; if (args.Count() >= 1) int.TryParse(args[1], out maxLength); else maxLength = 1; if (maxLength < 1) maxLength = 1; while (points.Count > 0) { BlockPos point = points.Pop(); BlockPos wallPoint = points.Pop(); if (point.x > 0 && point.x < bot.room.Width - 1 && point.y > 0 && point.y < bot.room.Height - 1) { Block block = bot.room.getBotBlock(0, point.x, point.y); if (block.blockId > 8 && block.blockId < 226) { bot.room.DrawBlock(Block.CreateBlock(0, point.x, point.y, 4, -1)); bot.room.DrawBlock(Block.CreateBlock(0, wallPoint.x, wallPoint.y, 4, -1)); List<BlockPos> namnpriblem = new List<BlockPos>(); for (int i = 0; i < moves.Length; i++) namnpriblem.Add(moves[i]); while(namnpriblem.Count > 0) { int index = random.Next(namnpriblem.Count); BlockPos newPoint = new BlockPos(0, point.x + namnpriblem[index].x * 2, point.y + namnpriblem[index].y * 2); BlockPos newWallPoint = new BlockPos(0, point.x + namnpriblem[index].x, point.y + namnpriblem[index].y); namnpriblem.RemoveAt(index); //BlockPos newWallPoint = new BlockPos(0, point.x + newPoint.x, point.y + newPoint.y); points.Push(newWallPoint); points.Push(newPoint); } } } } } break; case "genemaze2": { int maxLength; if (args.Count() >= 1) int.TryParse(args[1], out maxLength); else maxLength = 1; if (maxLength < 1) maxLength = 1; List<BlockPos> points = new List<BlockPos>(); points.Add(new BlockPos(0, player.blockX & 0xFFFE, player.blockY & 0xFFFE)); bot.room.DrawBlock(Block.CreateBlock(0, points[0].x, points[0].y, 4, -1)); while (points.Count > 0) { int i = random.Next(points.Count); BlockPos p = moves[random.Next(moves.Count())]; { BlockPos pointA, pointB; pointA = new BlockPos(0, points[i].x + p.x, points[i].y + p.y); // is between the previous point nad pointB pointB = new BlockPos(0, points[i].x, points[i].y); //"destination" for (int j = 0; j < random.Next(1,maxLength); j++) { pointB = new BlockPos(0, pointB.x + p.x * 2, pointB.y + p.y * 2); //pointB.y = p.y * 2; //pointB.x //BlockPos pointA = new BlockPos(0, points[i].x + p.x * 2, points[i].y + p.y * 2); //BlockPos pointB = new BlockPos(0, points[i].x + p.x * 2, points[i].y + p.y * 2); Block b = bot.room.getBotBlock(0, pointB.x, pointB.y); Block b2 = bot.room.getBotBlock(0, pointA.x, pointA.y); if (b.blockId > 8 && b.blockId < 218 && b2.blockId > 8 && b2.blockId < 218 && b.x > 1 && b.y > 1 && b.x < bot.room.Width-1 && b.y < bot.room.Height-1) { bot.room.DrawBlock(Block.CreateBlock(0, pointA.x, pointA.y, 4, -1)); bot.room.DrawBlock(Block.CreateBlock(0, pointB.x, pointB.y, 4, -1)); points.Add(pointB); pointA = new BlockPos(0, pointA.x + p.x * 2, pointA.y + p.y * 2); //pointA.x += p.x * 2; //pointA.y += p.y * 2; } else { break; } } } bool noWay = false; foreach (var m in moves) { BlockPos a = new BlockPos(0, points[i].x + m.x, points[i].y + m.y); BlockPos b = new BlockPos(0, points[i].x + m.x, points[i].y + m.y); Block bl = bot.room.getBotBlock(0, b.x, b.y); Block bl2 = bot.room.getBotBlock(0, a.x, a.y); if (!(bl.blockId > 8 && bl.blockId < 218 && bl2.blockId > 8 && bl2.blockId < 218 && bl.x > 1 && bl.y > 1 && bl.x < bot.room.Width - 1 && bl.y < bot.room.Height - 1)) { noWay = true; break; } } if (noWay) { points.RemoveAt(i); } } } break; } } }
protected virtual void OnMessage(object sender, PlayerIOClient.Message m) { switch (m.Type) { case "add": { int ID = m.GetInt(0); if (!playerList.ContainsKey(ID)) { Player temp = new Player((Bot)this, ID, m.GetString(1), m.GetInt(2), m.GetFloat(3), m.GetFloat(4), m.GetBoolean(5), m.GetBoolean(6), m.GetBoolean(7), m.GetInt(8), m.GetBoolean(10), m.GetBoolean(9), m.GetInt(11)); temp.x = m.GetDouble(3); temp.y = m.GetDouble(4); lock (playerList) { playerList.Add(ID, temp); } if (nameList.ContainsKey(temp.name)) nameList.Remove(temp.name); nameList.Add(temp.name, ID); } } break; case "left": { int tempKey = m.GetInt(0); if (playerList.ContainsKey(tempKey)) { nameList.Remove(playerList[tempKey].name); lock (playerList) { playerList.Remove(tempKey); } } } break; case "m": { int playerID = int.Parse(m[0].ToString()); float playerXPos = float.Parse(m[1].ToString()); float playerYPos = float.Parse(m[2].ToString()); float playerXSpeed = float.Parse(m[3].ToString()); float playerYSpeed = float.Parse(m[4].ToString()); float modifierX = float.Parse(m[5].ToString()); float modifierY = float.Parse(m[6].ToString()); int xDir = int.Parse(m[7].ToString()); int yDir = int.Parse(m[8].ToString()); if (playerList.ContainsKey(playerID)) { lock (playerList) { Player player = playerList[playerID]; player.x = playerXPos; player.y = playerYPos; player.speedX = playerXSpeed; player.speedY = playerYSpeed; player.modifierX = modifierX; player.modifierY = modifierY; player.horizontal = xDir; player.vertical = yDir; playerList[playerID] = player; } } } break; case "god": { int tempKey = m.GetInt(0); if (playerList.ContainsKey(tempKey)) { Player player = playerList[tempKey]; player.isgod = m.GetBoolean(1); lock (playerList) { playerList[tempKey] = player; } } } break; case "face": { int tempKey = m.GetInt(0); if (playerList.ContainsKey(tempKey)) { Player player = playerList[tempKey]; player.frame(m.GetInt(1)); lock (playerList) { playerList[tempKey] = player; } } } break; case "k": //player got crown { int userId = m.GetInt(0); if (playerList.ContainsKey(userId)) { lock (playerList) { foreach (Player p in playerList.Values) { p.hascrown = false; } playerList[userId].hascrown = true; } } } break; case "ks": //player got silver crown { int userId = m.GetInt(0); if (playerList.ContainsKey(userId)) { lock (playerList) playerList[userId].hascrownsilver = true; } } break; case "c": //player took coin { int userId = m.GetInt(0); int totalCoins = m.GetInt(1); if (playerList.ContainsKey(userId)) { lock (playerList) playerList[userId].coins = totalCoins; } } break; case "levelup": { int userId = m.GetInt(0); int level = m.GetInt(1); if (playerList.ContainsKey(userId)) { lock (playerList) playerList[userId].level = level; } } break; case "tele": //owner used reset/load { bool resetUsed = m.GetBoolean(0); for (int i = 1; i < m.Count; i += 3) { int userId = m.GetInt(1); int spawnPosX = m.GetInt(2); int spawnPosY = m.GetInt(3); if (playerList.ContainsKey(userId)) { lock (playerList) { Player p = playerList[userId]; p.setPosition(spawnPosX * 16, spawnPosY * 16); playerList[userId] = p; } } } } break; } }
public abstract void onCommand(object sender, string text, string[] args, Player player, bool isBotMod, Bot bot);