Example #1
0
 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();
 }
Example #2
0
 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);
             }
         }
     }
 }
Example #3
0
 public void onMessage(object sender, OstBot ostBot, PlayerIOClient.Message m)
 {
     lock (botSystems)
     {
         foreach (var pair in botSystems)
         {
             if (pair.Value != null)
             {
                 new Task(() =>//new Thread(() =>
                 {
                     pair.Value.onMessage(sender, ostBot, m);
                 }).Start();
             }
         }
     }
 }
Example #4
0
        //string name;

        public Player(PlayerIOClient.Message m)
            : base(m.GetInt(0), m.GetString(1).ToLower(), m.GetInt(2), m.GetFloat(3), m.GetFloat(4), m.GetBoolean(5), m.GetBoolean(6), m.GetBoolean(7), m.GetInt(8), false, false, 0)
        {
        }
Example #5
0
 public abstract void onMessage(object sender, OstBot ostBot, PlayerIOClient.Message m);
 public override void onMessage(object sender, PlayerIOClient.Message m, Bot bot)
 {
 }
Example #7
0
 public MessageAdd(PlayerIOClient.Message message) : base(message)
 {
 }
Example #8
0
 public abstract void onMessage(object sender, PlayerIOClient.Message m, Bot bot);
Example #9
0
        public override void onMessage(object sender, OstBot ostBot, PlayerIOClient.Message m)
        {
            Console.WriteLine(m.Type);
            switch (m.Type)
            {
            case "b":
                new Task(() =>
                {
                    string name = "";
                    if (m.Count >= 5)
                    {
                        lock (ostBot.playerList)
                        {
                            if (ostBot.playerList.ContainsKey(m.GetInt(4)))
                            {
                                name = ostBot.playerList[m.GetInt(4)].Name;
                            }
                        }
                        if (name == "")     // else if
                        {
                            lock (ostBot.leftPlayerList)
                            {
                                if (ostBot.leftPlayerList.ContainsKey(m.GetInt(4)))
                                {
                                    name = ostBot.leftPlayerList[m.GetInt(4)].Name;
                                }
                            }
                        }
                    }

                    if (disabledPlayers.Contains(name))
                    {
                        /*return;
                         * }*/
                        Block trollBlock = new Block(m, ostBot);
                        Block block;
                        for (int i = 0; true; i++)
                        {
                            block = ostBot.room.getMapBlock(trollBlock.layer, trollBlock.x, trollBlock.y, i);

                            /*string name2 = "";
                             *
                             * lock (ostBot.playerList)
                             * {
                             *  if (ostBot.playerList.ContainsKey(block.placer.UserId))
                             *  {
                             *      name2 = ostBot.playerList[block.placer.UserId].Name;
                             *  }
                             * }
                             * if (name == "") //else if
                             * {
                             *  lock (ostBot.leftPlayerList)
                             *  {
                             *      if (ostBot.leftPlayerList.ContainsKey(block.placer.UserId))
                             *      {
                             *          name2 = ostBot.leftPlayerList[block.placer.UserId].Name;
                             *      }
                             *  }
                             * }*/
                            if (block.placer == null)
                            {
                                break;
                            }

                            lock (disabledPlayers)
                            {
                                if (!disabledPlayers.Contains(block.placer.Name))
                                {
                                    break;
                                }
                            }
                        }
                        ostBot.room.DrawBlock(block);
                    }
                    else if (!protectedPlayers.Contains(name))
                    {
                        Block trollBlock = new Block(m, ostBot);
                        Block oldBlock   = ostBot.room.getMapBlock(trollBlock.layer, trollBlock.x, trollBlock.y, 1);

                        lock (ostBot.playerList)
                        {
                            if (ostBot.playerList.ContainsKey(oldBlock.placer.UserId))
                            {
                                if (protectedPlayers.Contains(oldBlock.placer.Name))
                                {
                                    ostBot.room.DrawBlock(oldBlock);
                                }
                            }
                        }
                    }
                    if (getPlacerPlayers.Contains(name))
                    {
                        getPlacerPlayers.Remove(name);
                        string name2   = "[undefined]";
                        Block block    = new Block(m, ostBot);
                        Block oldBlock = ostBot.room.getMapBlock(block.layer, block.x, block.y, 1);

                        lock (ostBot.playerList)
                        {
                            if (ostBot.playerList.ContainsKey(oldBlock.placer.UserId))
                            {
                                name2 = oldBlock.placer.Name;
                            }
                        }
                        if (name2 == "[undefined]")
                        {
                            lock (ostBot.leftPlayerList)
                            {
                                if (ostBot.leftPlayerList.ContainsKey(oldBlock.placer.UserId))
                                {
                                    name2 = oldBlock.placer.Name;
                                }
                            }
                        }

                        ostBot.connection.Send("say", name + ": Block placed by " + name2);
                    }
                }).Start();
                break;
            }
        }
Example #10
0
 public override void onMessage(object sender, PlayerIOClient.Message m)
 {
     //throw new NotImplementedException();
 }
        //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;
            }
        }
Example #12
0
        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;
            }
        }
Example #13
0
        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;
            }
        }
Example #14
0
        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;
            }
        }
        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;
            }
        }