예제 #1
0
        static void FlyTo(Level lvl, ref Check C, int x, int y, int z)
        {
            int index = lvl.PosToInt((ushort)x, (ushort)y, (ushort)z);

            if (index < 0)
            {
                return;
            }

            switch (lvl.blocks[index])
            {
            case Block.air:
                lvl.AddUpdate(index, lvl.blocks[C.b]);
                break;

            case Block.op_air:
                break;

            default:
                PhysicsArgs args = default(PhysicsArgs);
                args.Type1 = PhysicsArgs.Dissipate; args.Value1 = 25;
                lvl.AddUpdate(C.b, Block.red, false, args);
                break;
            }
        }
예제 #2
0
        static void Firework(ushort x, ushort y, ushort z, int size, Level lvl, Random rand)
        {
            if (lvl.physics < 1 || lvl.physics == 5)
            {
                return;
            }
            int rand1 = rand.Next(Block.red, Block.white);
            int rand2 = rand.Next(Block.red, Block.white);
            int min = Math.Min(rand1, rand2), max = Math.Max(rand1, rand2);

            // Not using override, since override = true makes it more likely that a colored block will be
            // generated with no extraInfo, because it sets a Check for that position with no extraInfo.
            lvl.AddUpdate(lvl.PosToInt(x, y, z), Block.air);

            for (ushort yy = (ushort)(y - (size + 1)); yy <= (ushort)(y + (size + 1)); ++yy)
            {
                for (ushort zz = (ushort)(z - (size + 1)); zz <= (ushort)(z + (size + 1)); ++zz)
                {
                    for (ushort xx = (ushort)(x - (size + 1)); xx <= (ushort)(x + (size + 1)); ++xx)
                    {
                        int index = lvl.PosToInt(xx, yy, zz);
                        if (index >= 0 && lvl.blocks[index] == Block.air && rand.Next(1, 40) < 2)
                        {
                            PhysicsArgs args = default(PhysicsArgs);
                            args.Type1 = PhysicsArgs.Drop; args.Value1 = 100;
                            args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 25;
                            lvl.AddUpdate(index, (byte)rand.Next(min, max), false, args);
                        }
                    }
                }
            }
        }
예제 #3
0
        static bool MoveSnake(Level lvl, ref Check C, int index)
        {
            if (
                lvl.GetTile(lvl.IntOffset(index, 0, -1, 0)) == Block.air &&
                lvl.GetTile(index) == Block.air)
            {
                index = lvl.IntOffset(index, 0, -1, 0);
            }
            else if (
                lvl.GetTile(index) == Block.air &&
                lvl.GetTile(lvl.IntOffset(index, 0, 1, 0)) == Block.air)
            {
            }
            else if (
                lvl.GetTile(lvl.IntOffset(index, 0, 2, 0)) == Block.air &&
                lvl.GetTile(lvl.IntOffset(index, 0, 1, 0)) == Block.air)
            {
                index = lvl.IntOffset(index, 0, 1, 0);
            }

            if (lvl.AddUpdate(index, lvl.blocks[C.b]))
            {
                PhysicsArgs args = default(PhysicsArgs);
                args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
                args.Type2 = PhysicsArgs.Revert; args.Value2 = Block.air;
                lvl.AddUpdate(C.b, Block.snaketail, true, args);
                return(true);
            }
            return(false);
        }
예제 #4
0
        static void Explode(Level lvl, ushort x, ushort y, ushort z,
                            int size, Random rand, int prob, TntWarsGame game)
        {
            for (int xx = (x - size); xx <= (x + size); ++xx)
            {
                for (int yy = (y - size); yy <= (y + size); ++yy)
                {
                    for (int zz = (z - size); zz <= (z + size); ++zz)
                    {
                        int index = lvl.PosToInt((ushort)xx, (ushort)yy, (ushort)zz);
                        if (index < 0)
                        {
                            continue;
                        }
                        byte b = lvl.blocks[index];

                        bool doDestroy = prob < 0 || rand.Next(1, 10) < prob;
                        if (doDestroy && Block.Convert(b) != Block.tnt)
                        {
                            if (game != null && b != Block.air)
                            {
                                if (game.InZone((ushort)xx, (ushort)yy, (ushort)zz, false))
                                {
                                    continue;
                                }
                            }

                            int mode = rand.Next(1, 11);
                            if (mode <= 4)
                            {
                                lvl.AddUpdate(index, Block.tntexplosion);
                            }
                            else if (mode <= 8)
                            {
                                lvl.AddUpdate(index, Block.air);
                            }
                            else
                            {
                                PhysicsArgs args = default(PhysicsArgs);
                                args.Type1 = PhysicsArgs.Drop; args.Value1 = 50;
                                args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 8;
                                lvl.AddCheck(index, false, args);
                            }
                        }
                        else if (b == Block.tnt)
                        {
                            lvl.AddUpdate(index, Block.smalltnt);
                        }
                        else if (b == Block.smalltnt || b == Block.bigtnt || b == Block.nuketnt)
                        {
                            lvl.AddCheck(index);
                        }
                    }
                }
            }
        }
예제 #5
0
        static void ActivateNeighbours(Level lvl, ref Check C, ushort x, ushort y, ushort z)
        {
            for (int xx = -1; xx <= 1; xx++)
            {
                for (int yy = -1; yy <= 1; yy++)
                {
                    for (int zz = -1; zz <= 1; zz++)
                    {
                        byte b = lvl.GetTile(lvl.IntOffset(C.b, xx, yy, zz));
                        if (b == Block.rocketstart)
                        {
                            int  b1        = lvl.IntOffset(C.b, xx * 3, yy * 3, zz * 3);
                            int  b2        = lvl.IntOffset(C.b, xx * 2, yy * 2, zz * 2);
                            bool unblocked = lvl.GetTile(b1) == Block.air && lvl.GetTile(b2) == Block.air &&
                                             !lvl.listUpdateExists.Get(x + xx * 3, y + yy * 3, z + zz * 3) &&
                                             !lvl.listUpdateExists.Get(x + xx * 2, y + yy * 2, z + zz * 2);

                            if (unblocked)
                            {
                                lvl.AddUpdate(b1, Block.rockethead);
                                lvl.AddUpdate(b2, Block.fire);
                            }
                        }
                        else if (b == Block.firework)
                        {
                            int  b1        = lvl.IntOffset(C.b, xx, yy + 1, zz);
                            int  b2        = lvl.IntOffset(C.b, xx, yy + 2, zz);
                            bool unblocked = lvl.GetTile(b1) == Block.air && lvl.GetTile(b2) == Block.air &&
                                             !lvl.listUpdateExists.Get(x + xx, y + yy + 1, z + zz) &&
                                             !lvl.listUpdateExists.Get(x + xx, y + yy + 2, z + zz);

                            if (unblocked)
                            {
                                lvl.AddUpdate(b2, Block.firework);
                                PhysicsArgs args = default(PhysicsArgs);
                                args.Type1 = PhysicsArgs.Dissipate; args.Value1 = 100;
                                lvl.AddUpdate(b1, Block.lavastill, false, args);
                            }
                        }
                        else if (b == Block.tnt)
                        {
                            lvl.MakeExplosion((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz), 0);
                        }
                    }
                }
            }
        }
예제 #6
0
        static void Checktdoor(Level lvl, int index)
        {
            if (index < 0 || index >= lvl.blocks.Length)
            {
                return;
            }
            byte block = lvl.blocks[index];

            if (Block.Properties[block].IsTDoor)
            {
                PhysicsArgs args = default(PhysicsArgs);
                args.Type1 = PhysicsArgs.Wait; args.Value1 = 10;
                args.Type2 = PhysicsArgs.Revert; args.Value2 = block;
                args.Door  = true;
                lvl.AddUpdate(index, Block.air, false, args);
            }
        }
예제 #7
0
        static Player GetPlayer(ref PhysicsArgs args)
        {
            if (args.Type1 != PhysicsArgs.TntWars)
            {
                return(null);
            }

            int id = args.Value1 | args.Value2 << 8 | args.Data << 16;

            Player[] players = PlayerInfo.Online.Items;
            for (int i = 0; i < players.Length; i++)
            {
                if (players[i].tntWarsUuid == id)
                {
                    return(players[i]);
                }
            }
            return(null);
        }
예제 #8
0
        static bool MoveSnakeY(Level lvl, ref Check C, int index)
        {
            byte block       = lvl.GetTile(index);
            byte blockAbove  = lvl.GetTile(lvl.IntOffset(index, 0, 1, 0));
            byte block2Above = lvl.GetTile(lvl.IntOffset(index, 0, 2, 0));

            if (block == Block.air &&
                (blockAbove == Block.grass ||
                 blockAbove == Block.dirt && block2Above == Block.air))
            {
                if (lvl.AddUpdate(index, lvl.blocks[C.b]))
                {
                    PhysicsArgs args = default(PhysicsArgs);
                    args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
                    args.Type2 = PhysicsArgs.Revert; args.Value2 = Block.air;
                    lvl.AddUpdate(C.b, Block.snaketail, true, args);
                    return(true);
                }
            }
            return(false);
        }
예제 #9
0
        static void PhysDoor(Level lvl, ushort x, ushort y, ushort z, bool instaUpdate)
        {
            int index = lvl.PosToInt(x, y, z);

            if (index < 0)
            {
                return;
            }
            byte rawBlock = lvl.blocks[index];

            byte airDoor = Block.DoorAirs(rawBlock);

            if (airDoor != 0)
            {
                if (!instaUpdate)
                {
                    lvl.AddUpdate(index, airDoor);
                }
                else
                {
                    lvl.Blockchange(x, y, z, airDoor);
                }
                return;
            }

            if (Block.Properties[rawBlock].IsTDoor)
            {
                PhysicsArgs args = default(PhysicsArgs);
                args.Type1 = PhysicsArgs.Wait; args.Value1 = 16;
                args.Type2 = PhysicsArgs.Revert; args.Value2 = rawBlock;
                args.Door  = true;
                lvl.AddUpdate(index, Block.air, false, args);
            }
            byte oDoor = Block.odoor(rawBlock);

            if (oDoor != Block.Zero)
            {
                lvl.AddUpdate(index, oDoor, true);
            }
        }
예제 #10
0
        public static void Do(Level lvl, ref Check C)
        {
            Random rand = lvl.physRandom;
            ushort x, y, z;

            lvl.IntToPos(C.b, out x, out y, out z);

            if (lvl.GetTile(x, (ushort)(y - 1), z) != Block.lavastill)
            {
                return;
            }

            if (lvl.GetTile(x, (ushort)(y + 1), z) == Block.air)
            {
                bool keepGoing = true;
                if ((lvl.Height * 80 / 100) < y)
                {
                    keepGoing = rand.Next(1, 20) > 1;
                }

                if (keepGoing)
                {
                    int  bAbove    = lvl.PosToInt(x, (ushort)(y + 1), z);
                    bool unblocked = bAbove < 0 || !lvl.listUpdateExists.Get(x, y + 1, z);
                    if (unblocked)
                    {
                        PhysicsArgs args = default(PhysicsArgs);
                        args.Type1 = PhysicsArgs.Wait; args.Value1 = 1;
                        args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 100;

                        lvl.AddUpdate(bAbove, Block.firework, false);
                        lvl.AddUpdate(C.b, Block.lavastill, false, args);
                        args.Data = C.data.Data;
                        C.data    = args;
                        return;
                    }
                }
            }
            Firework(x, y, z, 4, lvl, rand);
        }
예제 #11
0
        public static void Do(Level lvl, ref Check C)
        {
            Random rand = lvl.physRandom;
            int    dirX = rand.Next(1, 10) <= 5 ? 1 : -1;
            int    dirY = rand.Next(1, 10) <= 5 ? 1 : -1;
            int    dirZ = rand.Next(1, 10) <= 5 ? 1 : -1;
            ushort x, y, z;

            lvl.IntToPos(C.b, out x, out y, out z);

            for (int cx = -dirX; cx != 2 * dirX; cx += dirX)
            {
                for (int cy = -dirY; cy != 2 * dirY; cy += dirY)
                {
                    for (int cz = -dirZ; cz != 2 * dirZ; cz += dirZ)
                    {
                        byte tileBelow = lvl.GetTile((ushort)(x + cx), (ushort)(y + cy - 1), (ushort)(z + cz));
                        byte tile      = lvl.GetTile((ushort)(x + cx), (ushort)(y + cy), (ushort)(z + cz));

                        if ((tileBelow == Block.red || tileBelow == Block.op_air) &&
                            (tile == Block.air || tile == Block.water))
                        {
                            lvl.AddUpdate(lvl.PosToInt((ushort)(x + cx),
                                                       (ushort)(y + cy), (ushort)(z + cz)), Block.train);
                            lvl.AddUpdate(C.b, Block.air);

                            byte        newBlock = tileBelow == Block.red ? Block.obsidian : Block.glass;
                            PhysicsArgs args     = default(PhysicsArgs);
                            args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
                            args.Type2 = PhysicsArgs.Revert; args.Value2 = tileBelow;
                            lvl.AddUpdate(lvl.IntOffset(C.b, 0, -1, 0), newBlock, true, args);
                            return;
                        }
                    }
                }
            }
        }