public void handlemsg(object sender, PlayerIOClient.Message m) { if (m.Type == "init") { say("Connected."); } #region add if(m.Type == "add") { users.Add(m.GetInt(0), m.GetString(1)); } #endregion #region left if (m.Type == "left") { if (users.ContainsKey(m.GetInt(0))) { users.Remove(m.GetInt(0)); } } #endregion #region say if (m.Type == "say") { if (users.ContainsKey(m.GetInt(0))) { string msg = m.GetString(1); string username = users[m.GetInt(0)]; string[] split = msg.Split(' '); if (msg == "!test") { say(username + ": The bot is working properly."); } } } #endregion }
public override void onMessage(PlayerIOClient.Message m) { switch(m.Type) { case "face": { int playerId = m.GetInt(0); int faceId = m.GetInt(1); IPlayer player = bot.Room.getPlayer(playerId); if (player != null) { if (!isZombieFace(faceId)) { if (player.HasMetadata("isZombie")) { if (player.GetMetadata("isZombie").Equals(false)) force(player); } } if (player.HasMetadata("isZombie")) { if (player.GetMetadata("isZombie").Equals(true)) { if (player.GetMetadata("isForcing").Equals(true)) break; forceToZombie(player); } } } } break; } }
protected override void OnMessage(object sender, PlayerIOClient.Message m) { new System.Threading.Thread(() => { base.OnMessage(sender, m); subBotHandler.onMessage(sender, m, this); switch (m.Type) { case "say": { int player = m.GetInt(0); string message = m.GetString(1); if (message[0] == '!') { message = message.TrimStart('!'); if (playerList.ContainsKey(player)) subBotHandler.onCommand(sender, message, playerList[player], this); } } break; } }).Start(); }
public override void onMessage(PlayerIOClient.Message m) { switch (m.Type) { case "add": { IPlayer player = bot.Room.getPlayer(m.GetInt(0)); if (player != null) { player.SetMetadata("digplayer", new DigPlayer(player)); } } break; case "init": case "reset": digHardness = new float[bot.Room.Width, bot.Room.Height]; resetDigHardness(); break; case "m": { int userId = m.GetInt(0); float playerPosX = m.GetFloat(1); float playerPosY = m.GetFloat(2); float speedX = m.GetFloat(3); float speedY = m.GetFloat(4); float modifierX = m.GetFloat(5); float modifierY = m.GetFloat(6); float horizontal = m.GetFloat(7); float vertical = m.GetFloat(8); int Coins = m.GetInt(9); int blockX = (int)(playerPosX / 16 + 0.5); int blockY = (int)(playerPosY / 16 + 0.5); IPlayer player = bot.Room.getPlayer(userId); if (player == null || player.IsGod || player.IsMod) return; if (!player.HasMetadata("digplayer")) player.SetMetadata("digplayer", new DigPlayer(player)); DigPlayer digPlayer = (DigPlayer)player.GetMetadata("digplayer"); int digRange = digPlayer.digRange; int digStrength = digPlayer.digStrength; int blockId = (bot.Room.getBlock(0, blockX + (int)horizontal, blockY + (int)vertical).Id); if (isDigable(blockId))//(blockId >= Skylight.BlockIds.Blocks.Sand.BROWN - 5 && blockId <= Skylight.BlockIds.Blocks.Sand.BROWN) { if (digRange > 1) { for (int x = (horizontal == 1) ? -1 : -digRange + 1; x < ((horizontal == -1) ? 2 : digRange); x++) { for (int y = (vertical == 1) ? -1 : -digRange + 1; y < ((vertical == -1) ? 2 : digRange); y++) { float distance = (float)Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)); if (distance <= 1.41421357 * (digRange - 1) || distance < 1.4142) DigBlock(blockX + x + (int)Math.Ceiling(horizontal), blockY + y + (int)Math.Ceiling(vertical), player, (digRange - distance) * digStrength, false); } } AddUnsavedPlayer(player); return; } } { if (horizontal == 0 || vertical == 0) DigBlock(blockX + (int)horizontal, blockY + (int)vertical, player, digStrength, true); blockId = bot.Room.getBlock(0, blockX, blockY).Id; DigBlock(blockX, blockY, player, digStrength, true); AddUnsavedPlayer(player); } } break; case "b": { int layer = m.GetInt(0); int blockId = m.GetInt(3); int x = m.GetInt(1); int y = m.GetInt(2); if (layer == 0) resetBlockHardness(x, y, blockId); } break; } }
private static void onMessage(object sender, PlayerIOClient.Message m) { //Init is the only event we really care about for this bot. switch (m.Type) { case "init": { //WorldWidth = m.GetInt (18); WorldHeight = m.GetInt (19); } return; //Definitely not a smart thing to allow others to do... /* case "say": { if (m.GetString (1).Substring (0, 6) != "!midi ") { break; } try { for (int i = 0; i < 16; ++i) { chans [i] = true; } Midi mid = new Midi (); if (!mid.Read (m.GetString (1).Substring (6))) { Console.WriteLine ("Failed to load file. Reason:"); Console.WriteLine (mid.LastError); } mid.Rewind (); Worker args = new Worker(MyConnection, mid); System.Threading.Thread t = new System.Threading.Thread( args.DoWork ); t.Start(); } catch (Exception e) { Console.WriteLine (e.Message); } } break; */ } }
public override void onMessage(object sender, PlayerIOClient.Message m, Bot bot) { switch (m.Type) { case "init": { loadedWorld = false; owner = m.GetString(0); name = m.GetString(1); totalPlays = m.GetInt(2); woots = m.GetInt(3); totalWoots = m.GetInt(4); key = BotUtility.rot13(m.GetString(5)); int myId = m.GetInt(6); int myX = m.GetInt(7); int myY = m.GetInt(8); string myName = m.GetString(9); bool hasCode = m.GetBoolean(10); bool isOwner = m.GetBoolean(11); width = m.GetInt(12); height = m.GetInt(13); bool isTutorialRoom = m.GetBoolean(14); ResetMap(); DeSerialize(m); loadedWorld = true; if (isOwner || hasCode) StartDrawThread(); } break; case "reset": { loadedWorld = false; ResetMap(); DeSerialize(m); loadedWorld = true; } break; case "clear": { width = m.GetInt(0); height = m.GetInt(1); int borderId = m.GetInt(2); int workareaId = m.GetInt(3); ResetMap(); DrawBorder(); } break; case "access": StartDrawThread(); break; case "lostaccess": StopDrawThread(); break; case "b": case "bc": case "bs": case "pt": { Block b = new Block(m); this.OnBlockDraw(b); } break; case "updatemeta": { owner = m.GetString(0); name = m.GetString(1); totalPlays = m.GetInt(2); } 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 override void onMessage(PlayerIOClient.Message m) { switch (m.Type) { case "face": { int playerId = m.GetInt(0); int faceId = m.GetInt(1); Console.WriteLine(faceId); IPlayer player = bot.Room.getPlayer(playerId); if (player != null && !player.HasMetadata("forcing")) { //If player changed to other than zombie smiley but is zombie, put on hologram if (!isZombieFace(faceId)) { if (player.HasMetadata("ost.isZombie") && !player.HasMetadata("zombieForcing")) { ForceToZombie(player); player.Send("You're not allowed to change smiley!"); } } else { //If player changed to zombie smiley but isn't zombie, put on cake if (!player.HasMetadata("ost.isZombie") && !player.HasMetadata("humanForcing")) { ForceToNormal(player); player.Send("You're not allowed to change smiley!"); } } } } break; } }
public override void onMessage(object sender, PlayerIOClient.Message m, Bot bot) { switch (m.Type) { case "b": { int layer = m.GetInt(0); int x = m.GetInt(1); int y = m.GetInt(2); int previousBlock = bot.room.getBlock(layer, x, y).blockId; int blockId = m.GetInt(3); int placer = -1; if (m.Count > 4) placer = m.GetInt(4); if (bot.playerList.ContainsKey(placer)) { Player player = bot.playerList[placer]; if (blockId == 32) { if (player.hasVar("brush") && (bool)player.getVar("brush")) { if (player.hasVar("brushtype")) { int brushSize = player.getVar("brushsize") == null ? 1 : (int)player.getVar("brushsize"); int brushBlock = player.getVar("brushblock") == null ? 9 : (int)player.getVar("brushblock"); Brush brush = (Brush)player.getVar("brushtype"); brush.Draw(bot, player, this, x, y); } } else { if (editBlock1 != nullPoint && editBlock2 != nullPoint) { editBlock1 = nullPoint; editBlock2 = nullPoint; } if (editBlock1 == nullPoint) { editBlock1 = new Point(x, y); bothPointsSet = false; bot.connection.Send("say", x + y + " First block placed"); } else if (editBlock2 == nullPoint) { editBlock2 = new Point(x, y); bothPointsSet = true; bot.connection.Send("say", x + y + " Second block placed"); int temp; if (editBlock1.X > editBlock2.X) { temp = editBlock1.X; editBlock1.X = editBlock2.X; editBlock2.X = temp; } if (editBlock1.Y > editBlock2.Y) { temp = editBlock1.Y; editBlock1.Y = editBlock2.Y; editBlock2.Y = temp; } } bot.room.DrawBlock(Block.CreateBlock(0, x, y, previousBlock, player.id)); } } } } break; } }
public override void onMessage(PlayerIOClient.Message m) { switch (m.Type) { case "m": { int userId = m.GetInt(0); float playerPosX = m.GetFloat(1); float playerPosY = m.GetFloat(2); float speedX = m.GetFloat(3); float speedY = m.GetFloat(4); float modifierX = m.GetFloat(5); float modifierY = m.GetFloat(6); float horizontal = m.GetFloat(7); float vertical = m.GetFloat(8); int Coins = m.GetInt(9); int blockX = (int)(playerPosX / 16 + 0.5); int blockY = (int)(playerPosY / 16 + 0.5); IPlayer player = bot.Room.getPlayer(userId); if (player == null || player.IsGod || player.IsMod) return; int blockId = (bot.Room.getBlock(0, blockX + (int)horizontal, blockY + (int)vertical).Id); { int x1 = blockX; int y1 = blockY; int x2 = blockX + (int)horizontal; int y2 = blockY + (int)vertical; if (horizontal + vertical == 1 || horizontal + vertical == -1) { houseManager.OnPlayerMine(player, x1, y1, x2, y2); if (speedX * horizontal == 0 && speedY * vertical == 0) houseManager.OnPlayerPush(player, x1, y1, (int)horizontal, (int)vertical); } } } break; case "b": { int layer = m.GetInt(0); int x = m.GetInt(1); int y = m.GetInt(2); int blockId = m.GetInt(3); if (m.Count >= 5) { int userId = m.GetInt(4); houseManager.OnBlockPlace(bot.Room.getPlayer(userId), x, y, layer, blockId); } } break; default: break; } }
private void DeserializeInit(PlayerIOClient.Message m) { owner = m.GetString(0); title = m.GetString(1); plays = m.GetInt(2); woots = m.GetInt(3); totalWoots = m.GetInt(4); worldKey = rot13(m.GetString(5)); botId = m.GetInt(6); //irrelevant information /*int myId = m.GetInt(6); ======= public class Room : ASubBot, IRoom { BlockMap blockMap; SafeDictionary<int, IPlayer> players = new SafeDictionary<int, IPlayer>(); SafeDictionary<string, List<IPlayer>> namePlayers = new SafeDictionary<string, List<IPlayer>>(); SafeDictionary<string, List<IPlayer>> disconnectedPlayers = new SafeDictionary<string, List<IPlayer>>(); Stopwatch playerTickStopwatch = new Stopwatch(); SafeThread playerTickThread; //System.Timers.Timer playerTickTimer = new System.Timers.Timer(); Minimap.Minimap minimap = null; IBlockDrawerPool blockDrawerPool; IBlockDrawer blockDrawer; IPlayer botPlayer = null; #region EE_Variables string owner = ""; string title = ""; int plays = 0; int woots = 0; int totalWoots = 0; string worldKey = ""; int botId; bool isOwner = false; int width = 0; int height = 0; bool isTutorialRoom = false; float gravity = 0.0F; bool potionsAllowed = false; bool hasAccess = false; bool hideRed = false; bool hideGreen = false; bool hideBlue = false; System.Windows.Forms.Label labelBlocksToRepair; System.Windows.Forms.NumericUpDown numericUpDownBlocksToRepair; System.Windows.Forms.Label labelBlocksToPlace; System.Windows.Forms.NumericUpDown numericUpDownBlocksToPlace; System.Windows.Forms.Label labelWaitingBlocks; System.Windows.Forms.NumericUpDown numericUpDownWaitingBlocks; bool hideTimeDoor = false; #endregion public Room(IBot bot) : base(bot) { this.bot = bot; this.blockMap = new BlockMap(bot); this.blockDrawerPool = new BlockDrawerPool(bot, this); this.blockDrawer = blockDrawerPool.CreateBlockDrawer(15); this.blockDrawer.Start(); playerTickThread = new SafeThread(UpdatePhysics); EnableTick(50); } #region properties public string Owner { get { return owner; } } public string Title { get { return title; } } public int Plays { get { return plays; } } public int Woots { get { return woots; } } public int TotalWoots { get { return totalWoots; } } public string WorldKey { get { return worldKey; } } public int BotId { get { return botId; } } public bool IsOwner { get { return isOwner; } } public int Width { get { return width; } } public int Height { get { return height; } } public bool TutorialRoom { get { return TutorialRoom; } } public float Gravity { get { return gravity; } } public bool PotionsAllowed { get { return potionsAllowed; } } public bool HasCode { get { return isOwner || hasAccess; } } public bool HideRed { get { return hideRed; } } public bool HideGreen { get { return hideGreen; } } public bool HideBlue { get { return hideBlue; } } public bool HideTimeDoor { get { return hideTimeDoor; } } public ICollection<IPlayer> Players { get { return players.Values; } } public BlockMap BlockMap { get { return blockMap; } } public override bool HasTab { get { return true; } } public override string SubBotName { get { return "Room"; } } public IBlockDrawerPool BlockDrawerPool { get { return blockDrawerPool; } } public IBlockDrawer BlockDrawer { get { return blockDrawer; } } public IPlayer getPlayer(string name) { if (namePlayers.ContainsKey(name)) { List<IPlayer> players = namePlayers[name]; if (players != null && players.Count > 0) return players.First(); } else if (disconnectedPlayers.ContainsKey(name)) { List<IPlayer> players = disconnectedPlayers[name]; if (players != null && players.Count > 0) return players.First(); } return null; } #endregion private void UpdatePhysics() { long elapsed = playerTickStopwatch.ElapsedMilliseconds; if (elapsed >= Config.physics_ms_per_tick) { playerTickStopwatch.Restart(); foreach (Player player in players.Values) { if (player.Moved && minimap != null) minimap.DrawPlayer(player); player.tick(); } Thread.Sleep(9); } else if (elapsed > 2) Thread.Sleep((int)(Config.physics_ms_per_tick - elapsed) - 1); } private void HandleBlockPlace(PlayerIOClient.Message m) { int layer; int x; int y; int blockId; int playerId = -1; IBlock result = null; if (m.Type == "b") { layer = m.GetInt(0); x = m.GetInt(1); y = m.GetInt(2); blockId = m.GetInt(3); if (m.Count >= 5) playerId = m.GetInt(4); result = new NormalBlock(blockId, layer); } else { layer = 0; x = m.GetInt(0); y = m.GetInt(1); blockId = m.GetInt(2); if (m.Type != "pt" && m.Type != "bs" && m.Count >= 5) playerId = m.GetInt(4); switch (m.Type) { case "bc": { int coins = m.GetInt(3); if (blockId == 43) result = new BlockCoinDoor(coins); else if (blockId == 165) result = new BlockCoinGate(coins); break; } case "bs": { int note = m.GetInt(3); if (blockId == 77) result = new BlockPiano(note); else if (blockId == 83) result = new BlockDrums(note); break; } case "pt": { int rotation = m.GetInt(3); int portalId = m.GetInt(4); int targetId = m.GetInt(5); //playerId = m.GetInt(6); result = new BlockPortal(rotation, portalId, targetId); break; } case "lb": { string text = m.GetString(3); result = new BlockText(text); break; } case "br": { int rotation = m.GetInt(3); result = new BlockSpikes(rotation); break; } case "wp": { string destination = m.GetString(3); result = new BlockWorldPortal(destination); break; } case "ts": { string text = m.GetString(3); result = new BlockSign(text); break; } case "m": break; } } if (result != null && blockMap != null) { result.Placer = (players.ContainsKey(playerId) ? players[playerId] : null); result.OnReceive(bot, x, y); IBlock oldBlock = blockMap.getBlock(layer, x, y); blockMap.setBlock(x, y, result); bot.SubBotHandler.onBlockChange(x, y, result, oldBlock); BlockWithPos b = new BlockWithPos(x, y, result); blockDrawerPool.OnBlockPlace(b); } } private uint LoadWorld(PlayerIOClient.Message m, uint ws, int width, int height) { if (minimap != null) { minimap.Die(); minimap = new Minimap.Minimap(bot, width, height); foreach (Player player in players.Values) minimap.DrawPlayer(player); } else minimap = new Minimap.Minimap(bot, width, height); blockMap.setSize(width, height); blockMap.Clear(); //world start at 17 "ws" uint i = ws; for (; (int)(i - 2) <= ws || !(m[i - 2] is string); i++) { if (m[i] is byte[]) { int blockId = m.GetInt(i - 2); int layer = m.GetInt(i - 1); byte[] xArray = m.GetByteArray(i); byte[] yArray = m.GetByteArray(i + 1); uint toAdd = 0; for (int x = 0; x < xArray.Length; x += 2) { int xIndex = xArray[x] * 256 + xArray[x + 1]; int yIndex = yArray[x] * 256 + yArray[x + 1]; IBlock result = null; switch (blockId) { case 242: //portal case 381: //portal { int rotation = m.GetInt(i + 2); int id = m.GetInt(i + 3); int destination = m.GetInt(i + 4); result = new BlockPortal(rotation, id, destination); toAdd = 3; break; } case 43: //coin door { int coins = m.GetInt(i + 2); result = new BlockCoinDoor(coins); toAdd = 1; break; } case 165: //coin gate { int coins = m.GetInt(i + 2); result = new BlockCoinGate(coins); toAdd = 1; break; } case 361: //spikes { int rotation = m.GetInt(i + 2); result = new BlockSpikes(rotation); toAdd = 1; break; } case 77: //piano { int note = m.GetInt(i + 2); result = new BlockPiano(note); toAdd = 1; break; } case 83: //drums { int note = m.GetInt(i + 2); result = new BlockDrums(note); toAdd = 1; break; } case 1000: //text { string text = m.GetString(i + 2); result = new BlockText(text); toAdd = 1; break; } case 385: //sign { string text = m.GetString(i + 2); result = new BlockSign(text); toAdd = 1; break; } case 374: //world portal { string destination = m.GetString(i + 2); result = new BlockWorldPortal(destination); toAdd = 1; break; } default: { result = new NormalBlock(blockId, layer); break; } } if (result != null) { result.OnReceive(bot, xIndex, yIndex); blockMap.setBlock(xIndex, yIndex, result); bot.SubBotHandler.onBlockChange(xIndex, yIndex, blockMap.getBlock(layer, xIndex, yIndex), blockMap.getBlockHistory(layer, xIndex, yIndex).Count >= 2 ? blockMap.getBlockHistory(layer, xIndex, yIndex).ElementAt(1) : new NormalBlock(0, layer)); } } i += toAdd; i += 3; } } return i + 2; //world end "we" } private void DeserializeInit(PlayerIOClient.Message m) { owner = m.GetString(0); title = m.GetString(1); plays = m.GetInt(2); woots = m.GetInt(3); totalWoots = m.GetInt(4); worldKey = rot13(m.GetString(5)); botId = m.GetInt(6); //irrelevant information /*int myId = m.GetInt(6); >>>>>>> origin/master int myX = m.GetInt(7); int myY = m.GetInt(8); string myName = m.GetString(9); bool IHaveCode = m.GetBoolean(10);*/ isOwner = m.GetBoolean(11); width = m.GetInt(12); height = m.GetInt(13); isTutorialRoom = m.GetBoolean(14); gravity = m.GetFloat(15); potionsAllowed = m.GetBoolean(16); //int unknownValue = m.GetInt(17); //bool unknownBoolean = m.GetBoolean(18); uint we = LoadWorld(m, 19, width, height); botPlayer = new Player(bot, botId, "[bot]", 0, 0, 0, false, false, true, 0, false, true, 0); //potions start "ps" //not implemented //potions end "pe" }
public override void onMessage(PlayerIOClient.Message m) { //MessageBox.Show(m.ToString()); switch (m.Type) { case "init": { DeserializeInit(m); bot.Connection.Send("init2"); bot.Connection.Send("init2"); break; } case "reset": { LoadWorld(m, 0, width, height); break; } case "add": { int id = m.GetInt(0); if (!players.ContainsKey(id)) { Player player = new Player(bot, id, m.GetString(1), m.GetInt(2), m.GetDouble(3), m.GetDouble(4), m.GetBoolean(5), m.GetBoolean(6), m.GetBoolean(7), m.GetInt(8), m.GetBoolean(10), m.GetBoolean(11), m.GetInt(9)); //player.IsClubMember = m.GetBoolean(14); players.Add(id, player); if (!namePlayers.ContainsKey(player.Name)) namePlayers.Add(new KeyValuePair<string, List<IPlayer>>(player.Name, new List<IPlayer>())); namePlayers[player.Name].Add(player); if (disconnectedPlayers.ContainsKey(player.Name)) disconnectedPlayers.Remove(player.Name); } break; } case "left": { int id = m.GetInt(0); if (players.ContainsKey(id)) { IPlayer left = players[id]; if (left != null) { if (!disconnectedPlayers.ContainsKey(left.Name)) disconnectedPlayers.Add(new KeyValuePair<string, List<IPlayer>>(left.Name, new List<IPlayer>())); disconnectedPlayers[left.Name].Add(left); } namePlayers.Remove(players[id].Name); players.Remove(id); } break; } case "m": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].X = m.GetDouble(1); players[id].Y = m.GetDouble(2); players[id].SpeedX = m.GetDouble(3); players[id].SpeedY = m.GetDouble(4); players[id].ModifierX = m.GetInt(5); players[id].ModifierY = m.GetInt(6); players[id].Horizontal = m.GetInt(7); players[id].Vertical = m.GetInt(8); players[id].Coins = m.GetInt(9); players[id].Purple = m.GetBoolean(10); //players[id].Levitation = m.GetBoolean(11); } break; } case "c": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].Coins = m.GetInt(1); } break; } case "k": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].HasCrown = true; } break; } case "ks": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].HasCrownSilver = true; } break; } case "face": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].Smiley = m.GetInt(1); } break; } case "god": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].Respawn(); players[id].IsGod = m.GetBoolean(1); } break; } case "mod": { int id = m.GetInt(0); if (players.ContainsKey(id)) players[id].IsMod = m.GetBoolean(1); break; } case "lostaccess": { hasAccess = false; break; } case "access": { hasAccess = true; break; } case "info": break; case "p": break; case "upgrade": break; case "b": case "bc": case "bs": case "pt": case "lb": case "br": case "wp": case "ts": HandleBlockPlace(m); break; case "show": { string type = m.GetString(0); switch (type) { case "red": this.hideRed = false; break; case "green": this.hideGreen = false; break; case "blue": this.hideBlue = false; break; case "timedoor": this.hideTimeDoor = false; break; } } break; case "hide": { string type = m.GetString(0); switch (type) { case "red": this.hideRed = true; break; case "green": this.hideGreen = true; break; case "blue": this.hideBlue = true; break; case "timedoor": this.hideTimeDoor = true; break; } } break; case "allowpotions": break; case "wu": { int id = m.GetInt(0); if (isOwner && players.ContainsKey(id)) { players[id].Reply("Thank you!"); } } break; case "w": break; case "levelup": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].Level = m.GetInt(1); } } break; case "write": { if (m.GetString(0).Contains(" > you")) { string[] split = m.GetString(0).Split(' '); if (split.Length > 1) { string senderName = split[1]; if (namePlayers.ContainsKey(senderName)) { IPlayer sender = namePlayers[senderName].First(); string text = m.GetString(1); if (text.Length > 0 && text[0].Equals('!')) { string textCommandCharRemoved = text.Remove(0, 1); string[] textSplit = textCommandCharRemoved.Split(' '); string cmd = textSplit[0]; string[] args = new string[textSplit.Length - 1]; if (textSplit.Length > 0) Array.Copy(textSplit, 1, args, 0, textSplit.Length - 1); bot.SubBotHandler.onCommand(cmd, args, sender); } } } } } break; case "say": { int id = m.GetInt(0); string text = m.GetString(1); if (players.ContainsKey(id)) { IPlayer player = players[id]; if (text.Length > 0 && text[0].Equals('!')) { string textCommandCharRemoved = text.Remove(0, 1); string[] textSplit = textCommandCharRemoved.Split(' '); string cmd = textSplit[0]; string[] args = new string[textSplit.Length - 1]; if (textSplit.Length > 0) Array.Copy(textSplit, 1, args, 0, textSplit.Length - 1); bot.SubBotHandler.onCommand(cmd, args, player); } } } break; case "say_old": break; case "updatemeta": { owner = m.GetString(0); title = m.GetString(1); plays = m.GetInt(2); woots = m.GetInt(3); totalWoots = m.GetInt(4); } break; case "autotext": break; case "clear": { blockMap.Clear(); if (minimap != null) { minimap.Die(); minimap = new Minimap.Minimap(bot, width, height); foreach (Player player in players.Values) minimap.DrawPlayer(player); } else minimap = new Minimap.Minimap(bot, width, height); DrawBorder(); } break; case "tele": { bool usedReset = m.GetBoolean(0); for (int i = 1; i <= m.Count - 1; i += 3) { int playerId = m.GetInt(1); int x = m.GetInt(2); int y = m.GetInt(3); if (players.ContainsKey(playerId)) { players[playerId].X = x; players[playerId].Y = y; } } break; } case "saved": bot.ChatSayer.Say("World saved."); break; default: Console.WriteLine(m.Type); break; } }
private uint LoadWorld(PlayerIOClient.Message m, uint ws, int width, int height) { if (minimap != null) { minimap.Die(); minimap = new Minimap.Minimap(bot, width, height); foreach (Player player in players.Values) minimap.DrawPlayer(player); } else minimap = new Minimap.Minimap(bot, width, height); blockMap.setSize(width, height); blockMap.Clear(); //world start at 17 "ws" uint i = ws; for (; (int)(i - 2) <= ws || !(m[i - 2] is string); i++) { if (m[i] is byte[]) { int blockId = m.GetInt(i - 2); int layer = m.GetInt(i - 1); byte[] xArray = m.GetByteArray(i); byte[] yArray = m.GetByteArray(i + 1); uint toAdd = 0; for (int x = 0; x < xArray.Length; x += 2) { int xIndex = xArray[x] * 256 + xArray[x + 1]; int yIndex = yArray[x] * 256 + yArray[x + 1]; IBlock result = null; switch (blockId) { case 242: //portal case 381: //portal { int rotation = m.GetInt(i + 2); int id = m.GetInt(i + 3); int destination = m.GetInt(i + 4); result = new BlockPortal(rotation, id, destination); toAdd = 3; break; } case 43: //coin door { int coins = m.GetInt(i + 2); result = new BlockCoinDoor(coins); toAdd = 1; break; } case 165: //coin gate { int coins = m.GetInt(i + 2); result = new BlockCoinGate(coins); toAdd = 1; break; } case 361: //spikes { int rotation = m.GetInt(i + 2); result = new BlockSpikes(rotation); toAdd = 1; break; } case 77: //piano { int note = m.GetInt(i + 2); result = new BlockPiano(note); toAdd = 1; break; } case 83: //drums { int note = m.GetInt(i + 2); result = new BlockDrums(note); toAdd = 1; break; } case 1000: //text { string text = m.GetString(i + 2); result = new BlockText(text); toAdd = 1; break; } case 385: //sign { string text = m.GetString(i + 2); result = new BlockSign(text); toAdd = 1; break; } case 374: //world portal { string destination = m.GetString(i + 2); result = new BlockWorldPortal(destination); toAdd = 1; break; } default: { result = new NormalBlock(blockId, layer); break; } } if (result != null) { result.OnReceive(bot, xIndex, yIndex); blockMap.setBlock(xIndex, yIndex, result); bot.SubBotHandler.onBlockChange(xIndex, yIndex, blockMap.getBlock(layer, xIndex, yIndex), blockMap.getBlockHistory(layer, xIndex, yIndex).Count >= 2 ? blockMap.getBlockHistory(layer, xIndex, yIndex).ElementAt(1) : new NormalBlock(0, layer)); } } i += toAdd; i += 3; } } return i + 2; //world end "we" }
private void HandleBlockPlace(PlayerIOClient.Message m) { int layer; int x; int y; int blockId; int playerId = -1; IBlock result = null; if (m.Type == "b") { layer = m.GetInt(0); x = m.GetInt(1); y = m.GetInt(2); blockId = m.GetInt(3); if (m.Count >= 5) playerId = m.GetInt(4); result = new NormalBlock(blockId, layer); } else { layer = 0; x = m.GetInt(0); y = m.GetInt(1); blockId = m.GetInt(2); if (m.Type != "pt" && m.Type != "bs" && m.Count >= 5) playerId = m.GetInt(4); switch (m.Type) { case "bc": { int coins = m.GetInt(3); if (blockId == 43) result = new BlockCoinDoor(coins); else if (blockId == 165) result = new BlockCoinGate(coins); else if (blockId == 113) result = new BlockSwitch(coins); else if (blockId == 184) result = new BlockSwitchDoor(coins); else if (blockId == 185) result = new BlockSwitchGate(coins); break; } case "bs": { int note = m.GetInt(3); if (blockId == 77) result = new BlockPiano(note); else if (blockId == 83) result = new BlockDrums(note); break; } case "pt": { int rotation = m.GetInt(3); int portalId = m.GetInt(4); int targetId = m.GetInt(5); //playerId = m.GetInt(6); result = new BlockPortal(rotation, portalId, targetId); break; } case "lb": { string text = m.GetString(3); result = new BlockText(text); break; } case "br": { int rotation = m.GetInt(3); result = new BlockSpikes(rotation); break; } case "wp": { string destination = m.GetString(3); result = new BlockWorldPortal(destination); break; } case "ts": { string text = m.GetString(3); result = new BlockSign(text); break; } case "m": break; } } if (result != null && blockMap != null) { result.Placer = (players.ContainsKey(playerId) ? players[playerId] : null); result.OnReceive(bot, x, y); IBlock oldBlock = blockMap.getBlock(layer, x, y); blockMap.setBlock(x, y, result); bot.SubBotHandler.onBlockChange(x, y, result, oldBlock); BlockWithPos b = new BlockWithPos(x, y, result); blockDrawerPool.OnBlockPlace(b); } }
//Dictionary<int, Point> firstGodPositions = new Dictionary<int, Point>(); public override void onMessage(object sender, PlayerIOClient.Message m, Bot bot) { switch (m.Type) { case "add": { string name = m.GetString(1); //bot.connection.Send("say", "/giveedit " + name); } break; /*case "god": { int id = m.GetInt(0); bool god = m.GetBoolean(1); if (bot.playerList.ContainsKey(id)) { Player p = bot.playerList[id]; if (p.name != "gustav9797" && p.name != "ostkaka") { if (god) { if (!firstGodPositions.ContainsKey(id)) firstGodPositions.Add(id, new Point(p.blockX, p.blockY)); string name = bot.playerList[id].name; bot.connection.Send("say", "/removeedit " + name); bot.connection.Send("say", "/giveedit " + name); } else { if (firstGodPositions.ContainsKey(id)) { bot.connection.Send("say", "/teleport " + p.name + " " + firstGodPositions[id].X + " " + firstGodPositions[id].Y); firstGodPositions.Remove(id); } } } } } break;*/ case "init": digHardness = new float[bot.room.Width, bot.room.Height]; resetDigHardness(); break; case "reset": digHardness = new float[bot.room.Width, bot.room.Height]; resetDigHardness(); break; case "m": { int userId = m.GetInt(0); float playerPosX = m.GetFloat(1); float playerPosY = m.GetFloat(2); float speedX = m.GetFloat(3); float speedY = m.GetFloat(4); float modifierX = m.GetFloat(5); float modifierY = m.GetFloat(6); float horizontal = m.GetFloat(7); float vertical = m.GetFloat(8); int Coins = m.GetInt(9); int blockX = (int)(playerPosX / 16 + 0.5); int blockY = (int)(playerPosY / 16 + 0.5); int blockId = (bot.room.getBlock(0, blockX + (int)horizontal, blockY + (int)vertical).blockId); Player player; lock (bot.playerList) { if (!bot.playerList.ContainsKey(userId)) return; else player = bot.playerList[userId]; } if (isDigable(blockId)) { if (player.digRange > 1) { for (int x = (horizontal == 1) ? -1 : -player.digRange + 1; x < ((horizontal == -1) ? 2 : player.digRange); x++) { for (int y = (vertical == 1) ? -1 : -player.digRange + 1; y < ((vertical == -1) ? 2 : player.digRange); y++) { float distance = (float)Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)); if (distance <= 1.41421357 * (player.digRange - 1) || distance < 1.4142) { int cx = blockX + x + (int)Math.Ceiling(horizontal); int cy = blockY + y + (int)Math.Ceiling(vertical); if (player.hasPickaxe()) { PickaxeItem pick = player.Pickaxe; if (pick.Durability >= digHardness[cx, cy]) { DigBlock( cx, cy, player, (player.digRange - distance) * player.digStrength, false); } } } } } return; } } if (player.hasPickaxe()) { if (horizontal == 0 || vertical == 0) DigBlock(blockX + (int)horizontal, blockY + (int)vertical, player, player.digStrength, true); blockId = bot.room.getBlock(0, blockX, blockY).blockId; DigBlock(blockX, blockY, player, player.digStrength, true); } } break; case "b": { int layer = m.GetInt(0); int x = m.GetInt(1); int y = m.GetInt(2); int blockId = m.GetInt(3); resetBlockHardness(x, y, blockId); } break; } }