Esempio n. 1
0
        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"
        }