public static DataChunk[] Parse(PlayerIOClient.Message m) { if (m == null) throw new ArgumentNullException("m"); if (m.Type != "init" && m.Type != "reset") throw new ArgumentException("Invalid message type.", "m"); // Get world data var p = 0u; var data = new Stack<object>(); while (m[p] as string != "ws") { ++p; } while (m[p] as string != "we") { data.Push(m[++p]); } // Parse world data var chunks = new List<DataChunk>(); while (data.Count > 0) { var args = new Stack<object>(); while (!(data.Peek() is byte[])) args.Push(data.Pop()); var ys = (byte[])data.Pop(); var xs = (byte[])data.Pop(); var layer = (int)data.Pop(); var type = (uint)data.Pop(); chunks.Add(new DataChunk(layer, type, xs, ys, args.ToArray())); } return chunks.ToArray(); }
void handlemessage(object sender, PlayerIOClient.Message m) { msgList.Add(m); Debug.Log(m.Type); if(m.Type.Equals("TurnEnd") || m.Type.Equals("PlayerName") || m.Type.Equals("EnemyName")) { Debug.Log("ProcessMessages : "+ m.Type); ProcessMessages(); } }
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 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; } }
public override void onMessage(object sender, PlayerIOClient.Message m, Bot bot) { }
public abstract void onMessage(PlayerIOClient.Message m);
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; } }
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 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 static void Write(PlayerIOClient.Connection con, Midi m) { //If calling from multiple threads, ensure the existing one aborts. if (stop == 2) { stop = 1; while (stop == 1) { System.Threading.Thread.Sleep (100); } } stop = 2; con.Send ("clear"); System.Threading.Thread.Sleep (100); long x = 1; long y = 2; long offset = 0; int distance = WorldHeight - 6; int id = 1; long xprev = 1; long tempo = 60000000 / 120; //Default microseconds per beat (120 bpm) long tempobase = 0; // long tempooffset = 0; // while (stop == 2) { if (Console.KeyAvailable) { if (Console.ReadKey ().KeyChar == 'q') { break; } } Midi.Event e = m.NextEvent (); if (!e.Valid) { break; } long timestamp = (e.Time - tempobase) * tempo / m.TicksPerQuarter / (1000000L / 85L) + tempooffset; if (e.Status == 0xFF) { //On meta event, I only really care about tempo here. if (e.Arg1 == 0x51 && e.Arg2 == 3) { tempooffset = timestamp; tempobase = e.Time; tempo = (e.Data [0] << 16 ) + (e.Data[1] << 8 ) + e.Data[2]; } } if ((e.Status >> 4) == 9) { int note = e.Arg1; for (int i = 3; i < e.Arg2; i += 805) { //If the note volume is 3 or less, don't emit a note. //If the note volume is 88 or higher, emit two notes. //e.Time is in ticks, tempo is in microseconds per tick. //e.Time * tempo / m.TicksPerQuarter = the event time in microseconds. //Divide that by how long each block should represent (I use 1/85th of a second) if (timestamp <= offset) { offset++; } else { offset = timestamp; } //Calculate the X/Y coordinates based on time. This does NOT account for time spent in portals. //Someone whould probably fix that. x = offset / distance + 2; y = offset % distance + 3; if (chans [(e.Status & 0xF)]) { //If the channel is 9 (AKA MIDI channel 10) if ((e.Status & 0xF) == 9) { //Deal with drums if (note >= 35 && note <= 81) { con.Send ("b",0, x, y, 83, percussion [note - 35]); System.Threading.Thread.Sleep (30); break; } } else { //C3 is note 48 in MIDI, and note 0 in EE con.Send ("b",0, x, y, 77, note - 48); System.Threading.Thread.Sleep (30); } } } } //If there's space missing portals... if (x > xprev) { for (long i = xprev; i < x; ++i) { //Add in portals to the slack space con.Send ("b",0, i, 2, 242, 1, id, id - 1); System.Threading.Thread.Sleep (30); con.Send ("b",0, i, WorldHeight - 3, 242, 1, id + 1, id + 2); System.Threading.Thread.Sleep (30); id += 2; } } xprev = x; } //Fill in the last column of portals con.Send ("b",0, x, 2, 242, 1, id, id - 1); System.Threading.Thread.Sleep (30); con.Send ("b",0, x, WorldHeight - 3, 242, 1, id + 1, 3); stop = 0; }
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); } }
public void onMessage(object sender, PlayerIOClient.Message m, Bot bot) { //lock (subBots) { foreach (SubBot o in subBots.Values) { if (o != null && o.Enabled) { o.onMessage(sender, m, bot); } } } }
void handlemessage(object sender, PlayerIOClient.Message m) { msgList.Add(m); }
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 "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; } }
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; } }
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) { }
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) { //throw new NotImplementedException(); }
public void onMessage(object sender, PlayerIOClient.Message m) { subBotHandler.onMessage(m); }
private static void HandleConnection(PlayerIOClient.Connection con) { con.OnMessage += new MessageReceivedEventHandler (onMessage); con.Send ("init"); con.Send ("init2"); int dots = 0; while (WorldHeight == 0) { Console.Write ("Connecting"); for (int i = 0; i < dots; ++i) { Console.Write ("."); } Console.Write ("\r"); System.Threading.Thread.Sleep (250); dots = (dots + 1) % 4; } Console.Write ("\n"); Console.WriteLine ("Connected to room"); Midi m = new Midi (); while (true) { Console.Write ("Command: "); string cmd = Console.ReadLine (); string[] cmds = cmd.Split (' '); switch (cmds [0]) { case "midi": try{ for( int i = 0; i < 16; ++i ){ chans[i] = true; } m = new Midi (); Console.WriteLine ("Successfully loaded."); if (!m.Read (cmd.Substring(5))) { Console.WriteLine ("Failed to load file. Reason:"); Console.WriteLine (m.LastError); } } catch( Exception e ){ Console.WriteLine (e.Message); } break; case "write": Console.WriteLine ("Writing to world (This will take a while...)\nPress q to abort."); m.Rewind (); Write (con, m); Console.WriteLine ("Done!"); break; case "quit": case "exit": case "close": throw new Exception ("Exiting..."); case "strip": foreach (string s in cmds) { try { chans [Convert.ToInt16 (s)] = false; } catch { } } break; case "unstrip": foreach (string s in cmds) { try { chans [Convert.ToInt16 (s)] = true; } catch { } } break; case "help": Console.WriteLine("Available commands are:\n" + " midi [path to midi file] - Load a midi file\n" + " write - Save the midi file to the level\n" + " strip [0-15] - Remove a channel from the midi file (9 is drums)\n" + " unstrip [0-15] - Add a channel back to the midi\n" + " help - Display this message.\n"); break; default: Console.WriteLine("Unknown command. Try `help`."); break; } } }
public abstract void onMessage(object sender, PlayerIOClient.Message m, Bot bot);
public Worker(PlayerIOClient.Connection othercon, Midi otherm) { con = othercon; m = otherm; }
public override void onMessage(object sender, PlayerIOClient.Message m, Bot bot) { switch (m.Type) { case "init": { ResetRed(); } break; case "b": { Block block = new Block(m); Block oldBlock = bot.room.getBlock(block.layer, block.x, block.y, 1); BlockPos position = new BlockPos(block.x, block.y, block.layer); if (wireTypes.ContainsKey(oldBlock.blockId) || (block.blockId >= 9 && block.blockId <= 15)) { if (!wireTypes.ContainsKey(block.blockId)) { lock (this) ResetPowerSources(); break; } } else if (powerSourceTypes.ContainsKey(oldBlock.blockId)) { if (!powerSourceTypes.ContainsKey(block.blockId)) { lock (this) { RemoveWiresFromPowerSource(new KeyValuePair<BlockPos, PowerSource>( position, powerSourceTypes[oldBlock.blockId])); powerSources.Remove(position); } } } else if (destinationTypes.ContainsKey(oldBlock.blockId)) { if (!destinationTypes.ContainsKey(block.blockId)) { lock (this) { if (destinations.ContainsKey(position)) { destinations.Remove(position); ResetPowerSources(); } } break; /*lock (this) RemoveWiresFromDestination(new KeyValuePair<BlockPos, Destination>( new BlockPos(block.x, block.y, block.layer), destinationTypes[oldBlock.blockId]));*/ } } if (wireTypes.ContainsKey(block.blockId)) { lock (this) ResetPowerSources(); } else if (powerSourceTypes.ContainsKey(block.blockId)) { lock (this) { if (!powerSources.ContainsKey(new BlockPos(block.x, block.y, block.layer))) { KeyValuePair<BlockPos, PowerSource> powerSourceKeyValuePair = new KeyValuePair<BlockPos, PowerSource>(new BlockPos(block.x, block.y, block.layer), powerSourceTypes[block.blockId].Clone() as PowerSource); powerSources.Add(powerSourceKeyValuePair.Key, powerSourceKeyValuePair.Value); ResetPowerSources();//ResetPowerSourceWires(powerSourceKeyValuePair); } } } else if (destinationTypes.ContainsKey(block.blockId)) { lock (this) { if (!destinations.ContainsKey(new BlockPos(block.x, block.y, block.layer))) { destinations.Add(new BlockPos(block.x, block.y, block.layer), destinationTypes[block.blockId].Clone() as Destination); ResetPowerSources(); } } } } break; } }
public override void onMessage(PlayerIOClient.Message m) { lock (subBots) { foreach (ASubBot subBot in subBots.Values) { if (subBot.Enabled) subBot.onMessage(m); } } }
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; } }
//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; } }
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" }