Example #1
0
        // Avoid re-defining the list every time your handler is called. Make it static!
        public static void PlayerClickingHandler(object sender, Events.PlayerClickingEventArgs e)
        {
            if (!e.Player.IsPropHuntSeeker)
            {
                return;
            }
            // if player clicked a non-air block
            if (e.Action != ClickAction.Delete)
            {
                return;
            }
            Block currentBlock = e.Player.WorldMap.GetBlock(e.Coords); // Gets the blocks coords

            // Check if currentBlock is on the list
            if (!clickableBlocks.Contains(currentBlock))
            {
                return;
            }
            foreach (Player p in PropHuntPlayers.Where(p => p.prophuntSolidPos == e.Coords && p.IsSolidBlock))
            {
                //Remove the players block
                const Block airBlock    = Block.Air;
                var         blockUpdate = new BlockUpdate(null, p.prophuntSolidPos, airBlock);
                if (p.World != null)
                {
                    if (p.World.Map != null)
                    {
                        p.World.Map.QueueUpdate(blockUpdate);
                    }
                }

                //Do the other stuff
                p.Message("&cA seeker has found you! Run away!");
                p.IsPropHuntTagged = true;
                p.ResetIdleTimer();
                p.IsSolidBlock  = false;
                p.Info.IsHidden = false;
                Player.RaisePlayerHideChangedEvent(p);
            }
        }
Example #2
0
        public static void towerRemove(object sender, Events.PlayerClickingEventArgs e)
        {
            World world = e.Player.World;

            if (e.Action == ClickAction.Delete)
            {
                if (e.Coords == e.Player.towerOrigin)
                {
                    if (e.Player.TowerCache != null)
                    {
                        if (e.Block == Block.Iron)
                        {
                            e.Player.towerOrigin = new Vector3I();
                            foreach (Vector3I block in e.Player.TowerCache.Values)
                            {
                                e.Player.Send(PacketWriter.MakeSetBlock(block, world.Map.GetBlock(block)));
                            }
                            e.Player.TowerCache.Clear();
                        }
                    }
                }
            }
        }
Example #3
0
        void ProcessSetBlockPacket() {
            BytesReceived += 9;
            if( World == null || World.Map == null ) return;
            ResetIdleTimer();
            short x = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
            short z = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
            short y = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
            ClickAction action = (reader.ReadByte() == 1) ? ClickAction.Build : ClickAction.Delete;
            byte type = reader.ReadByte();

            // if a player is using InDev or SurvivalTest client, they may try to
            // place blocks that are not found in MC Classic. Convert them!
            if( type > 49 ) {
                type = MapDat.MapBlock( type );
            }

            Vector3I coords = new Vector3I( x, y, z );

            // If block is in bounds, count the click.
            // Sometimes MC allows clicking out of bounds,
            // like at map transitions or at the top layer of the world.
            // Those clicks should be simply ignored.
            if( World.Map.InBounds( coords ) ) {
                var e = new PlayerClickingEventArgs( this, coords, action, (Block)type );
                if( RaisePlayerClickingEvent( e ) ) {
                    RevertBlockNow( coords );
                } else {
                    RaisePlayerClickedEvent( this, coords, e.Action, e.Block );
                    PlaceBlock( coords, e.Action, e.Block );
                }
            }
        }
Example #4
0
 public static void ClickedGlass(object sender, PlayerClickingEventArgs e)
 {
     if (e.Player.GunMode && !e.Player.Info.IsHidden && !e.Player.Info.IsFrozen)
     {
         World world = e.Player.World;
         Map map = e.Player.World.Map;
         if (e.Player.GunCache.Values.Contains(e.Coords))
         {
             if (world.gunPhysics)
             {
                 e.Player.Send(PacketWriter.MakeSetBlock(e.Coords.X, e.Coords.Y, e.Coords.Z, Block.Glass));
                 if (e.Block == Block.TNT && world.tntPhysics)
                 {
                     if (e.Player.CanFireTNT())
                     {
                         double ksi = 2.0 * Math.PI * (-e.Player.Position.L) / 256.0;
                         double r = Math.Cos(ksi);
                         double phi = 2.0 * Math.PI * (e.Player.Position.R - 64) / 256.0;
                         Vector3F dir = new Vector3F((float)(r * Math.Cos(phi)), (float)(r * Math.Sin(phi)), (float)(Math.Sin(ksi)));
                         world.AddPhysicsTask(new Particle(world, e.Coords, dir, e.Player, Block.TNT, _tntBulletBehavior), 0);
                     }
                 }
                 else
                 {
                     Block block = e.Block;
                     if (block == Block.Blue) block = Block.Water;
                     if (block == Block.Orange) block = Block.Lava;
                     double ksi = 2.0 * Math.PI * (-e.Player.Position.L) / 256.0;
                     double r = Math.Cos(ksi);
                     double phi = 2.0 * Math.PI * (e.Player.Position.R - 64) / 256.0;
                     Vector3F dir = new Vector3F((float)(r * Math.Cos(phi)), (float)(r * Math.Sin(phi)), (float)(Math.Sin(ksi)));
                     world.AddPhysicsTask(new Particle(world, e.Coords, dir, e.Player, block, _bulletBehavior), 0);
                 }
             }
         }
     }
 }
Example #5
0
 internal static bool RaisePlayerClickingEvent( PlayerClickingEventArgs e ) {
     var h = PlayerClicking;
     if( h == null ) return false;
     h( null, e );
     return e.Cancel;
 }
Example #6
0
        void ProcessSetBlockPacket() {
            bytesReceived += 9;
            if( Player.World == null || Player.World.Map == null ) return;
            Player.ResetIdleTimer();
            short x = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
            short h = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
            short y = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
            bool mode = (reader.ReadByte() == 1);
            byte type = reader.ReadByte();

            if( type > 49 ) {
                type = MapDat.MapBlock( type );
            }

            if( Player.World.Map.InBounds( x, y, h ) ) {
                var e = new PlayerClickingEventArgs( Player, x, y, h, mode, (Block)type );
                if( Server.RaisePlayerClickingEvent( e ) ) {
                    Player.RevertBlockNow( x, y, h );
                } else {
                    Server.RaisePlayerClickedEvent( Player, x, y, h, e.Mode, e.Block );
                    Player.PlaceBlock( x, y, h, e.Mode, e.Block );
                }
            }
        }