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; } }
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; } }
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) { 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; } }
//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; } }