示例#1
0
        private void DigBlock(int x, int y, Player player, float digStrength, bool mining)
        {
            if (digHardness == null)
            {
                resetDigHardness();
            }

            if (!(x > 0 && y > 0 && x < bot.room.Width && y < bot.room.Height))
            {
                return;
            }

            if (digHardness[x, y] <= 0)
            {
                return;
            }

            Block block   = bot.room.getBlock(0, x, y);
            int   blockId = -1;

            if (mining)
            {
                if (DigBlockMap.blockTranslator.ContainsKey(block.blockId))
                {
                    blockId = 4;
                    BlockItem temp = (BlockItem)DigBlockMap.blockTranslator[block.blockId];
                    if (player.digLevel + 5 >= temp.Hardness)
                    {
                        if (digHardness[x, y] <= digStrength)
                        {
                            BlockItem newsak = new BlockItem(temp);
                            player.inventory.AddItem(newsak, 1);
                            player.digXp += (int)Math.Round((float)temp.XPGain * (float)player.Pickaxe.XPModifier);
                        }
                        if (player.hasPickaxe())
                        {
                            player.Pickaxe.onDamage(temp.Hardness);
                            if (player.Pickaxe.Durability <= 0)
                            {
                                PickaxeItem bestPick = null;
                                for (int slot = 0; slot < player.inventory.capacity; slot++)
                                {
                                    InventoryItem item = player.inventory.GetItem(slot);
                                    if (item != null && item.ItemType == (int)ItemType.Pickaxe)
                                    {
                                        PickaxeItem pick = (PickaxeItem)item;
                                        if (bestPick == null || (pick.Hardness > bestPick.Hardness && pick.Hardness <= player.Pickaxe.Hardness && pick != player.Pickaxe))
                                        {
                                            bestPick = pick;
                                        }
                                    }
                                }
                                if (bestPick != null)
                                {
                                    player.Pickaxe = bestPick;
                                    bot.connection.Send("say", player.name + ": Pickaxe broke! You now use an other one in your inventory.");
                                }
                                else
                                {
                                    bot.connection.Send("say", player.name + ": Pickaxe broke! Get another one!");
                                }
                                player.inventory.RemoveItem(player.Pickaxe, 1);
                                return;
                            }
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }

            switch (block.blockId)
            {
            case 142:
                blockId = 4;
                break;

            case 197:
                blockId = 119;
                break;

            case 21:
                blockId = 369;
                break;

            default:
                if (blockId == -1)
                {
                    return;
                }
                else
                {
                    break;
                }
            }

            digHardness[x, y] -= digStrength;

            if (digHardness[x, y] <= 0)
            {
                bot.room.DrawBlock(Block.CreateBlock(0, x, y, blockId, -1));
                lock (dugBlocksToPlaceQueueLock)
                    dugBlocksToPlaceQueue.Enqueue(block);
            }
        }
        //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;
            }
        }