Esempio n. 1
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);
            }
        }
Esempio n. 2
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"
        }
Esempio n. 3
0
        private void Generate(int width, int height, int seed)
        {
            int centerHoleDiameter = 10;

            generatorDrawer = bot.Room.BlockDrawerPool.CreateBlockDrawer(1);
            Random random = new Random();
            Graphics.Tools.Noise.Primitive.SimplexPerlin noise = new Graphics.Tools.Noise.Primitive.SimplexPerlin(seed, NoiseQuality.Best);
            BlockMap blockMap = new BlockMap(bot, width, height);

            for (int x = 1; x < width - 1; x++)
            {
                for (int y = 1; y < height - 1; y++)
                {
                    double distanceFromCenter = Math.Sqrt(Math.Pow(x - width / 2, 2) + Math.Pow(y - height / 2, 2)) / ((width > height) ? width : height) * 2;
                    double distanceFromCenterPow = Math.Pow(distanceFromCenter, 1.5);

                    //if (noise.GetValue(x * 0.015625F, y * 0.015625F, 0) > 1 - 0.25F * distanceFromCenterPow)                 // slimy mud
                    //    blockMap.setBlock(x, y, new NormalBlock(21, 0));

                    //else if (noise.GetValue(x * 0.03125F, y * 0.03125F, 32) > 1 - 0.75 * distanceFromCenter)      // slimy mud
                    //    blockMap.setBlock(x, y, new NormalBlock(21, 0));

                    //else if (noise.GetValue(x * 0.015625F, y * 0.015625F, 48) > 1 - 0.5 * distanceFromCenter) // Water
                    //    blockMap.setBlock(x, y, new NormalBlock(197, 0));

                    //else if (noise.GetValue(x * 0.03125F, y * 0.03125F, 64) > 1 - 0.75 * distanceFromCenter) //wet stones
                    //    blockMap.setBlock(x, y, new NormalBlock(197, 0));

                     if (noise.GetValue(x * 0.0078125F, y * 0.0078125F, 96) > 1 - 0.75 * distanceFromCenterPow)
                        blockMap.setBlock(x, y, new NormalBlock((int)Blocks.Stone, 0));

                    else if (noise.GetValue(x * 0.015625F, y * 0.015625F, 128) > 1 - 0.75 * distanceFromCenter)
                        blockMap.setBlock(x, y, new NormalBlock((int)Blocks.Stone, 0));

                    else if (distanceFromCenter + 0.33 * noise.GetValue(x * 0.015625F, y * 0.015625F, 48) > 1)
                        blockMap.setBlock(x, y, new NormalBlock((int)1022, 0));

                    else if (distanceFromCenter + 0.33 * noise.GetValue(x * 0.015625F, y * 0.015625F, 48) > 0.5)
                        blockMap.setBlock(x, y, new NormalBlock((int)Skylight.BlockIds.Blocks.Sand.GRAY, 0));

                    else// if (noise.GetValue(x * 0.015625F, y * 0.015625F, 160) > 0)
                        blockMap.setBlock(x, y, new NormalBlock(Skylight.BlockIds.Blocks.Sand.BROWN, 0));

                }
            }

            Queue<BlockWithPos> blockQueue = new Queue<BlockWithPos>();

            for (int i = 0; i < 64; i++)
                blockQueue.Enqueue(new BlockWithPos(random.Next(1, width - 1), random.Next(1, height - 1), new NormalBlock((int)Blocks.Stone, 0)));
            for (int i = 0; i < 64; i++)
                blockQueue.Enqueue(new BlockWithPos(random.Next(1, width - 1), random.Next(1, height - 1), new NormalBlock((int)Blocks.Copper, 0)));
            for (int i = 0; i < 32; i++)
                blockQueue.Enqueue(new BlockWithPos(random.Next(1, width - 1), random.Next(1, height - 1), new NormalBlock((int)Blocks.Iron, 0)));
            for (int i = 0; i < 16; i++)
                blockQueue.Enqueue(new BlockWithPos(random.Next(1, width - 1), random.Next(1, height - 1), new NormalBlock((int)Blocks.Gold, 0)));
            for (int i = 0; i < 8; i++)
                blockQueue.Enqueue(new BlockWithPos(random.Next(1, width - 1), random.Next(1, height - 1), new NormalBlock((int)Blocks.Emerald, 0)));

            int amount = 1536;//2048 later

            while (blockQueue.Count > 0 && amount > 0)
            {
                BlockWithPos block = blockQueue.Dequeue();

                blockMap.setBlock(block.X, block.Y, block.Block);

                if (random.Next(8) == 0)
                {
                    BlockWithPos block2 = null;

                    switch (random.Next(4))
                    {
                        case 0: block2 = new BlockWithPos(block.X + 1, block.Y, block.Block); break;
                        case 1: block2 = new BlockWithPos(block.X, block.Y + 1, block.Block); break;
                        case 2: block2 = new BlockWithPos(block.X - 1, block.Y, block.Block); break;
                        case 3: block2 = new BlockWithPos(block.X, block.Y - 1, block.Block); break;
                    }

                    Console.WriteLine("s");

                    if (block2 != blockMap.getBlock(0, block2.X, block2.Y) && block2.X > 1 && block2.Y > 1 && block2.X < width - 1 && block2.Y < height - 1)
                    {
                        blockQueue.Enqueue(block2);
                        blockMap.setBlock(block2.X, block2.Y, block2.Block);
                        amount--;
                    }
                }

                blockQueue.Enqueue(block);
            }

            //Make hole in center for the shop
            for (int x = width / 2 - (centerHoleDiameter / 2 + 1); x < width / 2 + centerHoleDiameter / 2; x++)
            {
                for (int y = height / 2 - (centerHoleDiameter / 2 + 1); y < height / 2 + centerHoleDiameter / 2; y++)
                {
                    blockMap.setBlock(x, y, new NormalBlock(414, 0));

                }
            }

            blockMap.setBlock(width / 2 - 1, height / 2 - 1, new NormalBlock(255, 0));
            Shop.SetLocation(width / 2 - 1, height / 2 - 2);
            blockMap.setBlock(width / 2 - 1, height / 2 - 2, new NormalBlock(Skylight.BlockIds.Blocks.Pirate.CHEST, 0));

            for (int x = 1; x < width - 1; x++)
            {
                for (int y = 1; y < height - 1; y++)
                {
                    if (blockMap.getBlock(0, x, y) != null)
                    {
                        IBlock block = blockMap.getBlock(0, x, y);
                        generatorDrawer.PlaceBlock(x, y, block);
                        IBlock background = null;
                        switch (block.Id)
                        {
                            case 197:
                                background = new NormalBlock(574, 1);
                                break;
                            case 21:
                                background = new NormalBlock(630, 1);
                                break;
                            default:
                                background = new NormalBlock(584, 1);
                                break;
                        }
                        //generatorDrawer.PlaceBlock(x, y, background);
                        resetBlockHardness(x, y, blockMap.getBlock(0, x, y).Id);
                    }
                }
            }
            generatorDrawer.Start();
        }