예제 #1
0
파일: Weapon.cs 프로젝트: rdebath/MCGalaxy
        static void PlayerClickCallback(Player p, MouseButton btn, MouseAction action,
                                        ushort yaw, ushort pitch, byte entity,
                                        ushort x, ushort y, ushort z, TargetBlockFace face)
        {
            Weapon weapon = p.weapon;

            if (weapon == null || action != MouseAction.Pressed)
            {
                return;
            }

            if (!(btn == MouseButton.Left || btn == MouseButton.Right))
            {
                return;
            }
            if (!p.level.Config.Guns)
            {
                weapon.Disable(); return;
            }

            BlockID held = p.ClientHeldBlock;

            if (!CommandParser.IsBlockAllowed(p, "use", held))
            {
                return;
            }

            Vec3F32 dir = DirUtils.GetDirVectorExt(yaw, pitch);

            weapon.OnActivated(dir, held);
        }
        // The possible values of the Enums used in HandlePlayerClick
        //public enum MouseButton { Left, Right, Middle }
        //public enum MouseAction { Pressed, Released }
        //public enum TargetBlockFace { AwayX, TowardsX, AwayY, TowardsY, AwayZ, TowardsZ, None }


        static void HandlePlayerClick
        (
            Player p,
            MouseButton button, MouseAction action,
            ushort yaw, ushort pitch,
            byte entity, ushort x, ushort y, ushort z,
            TargetBlockFace face
        )
        {
            //you can uncomment this to make it only work in maps that have both buildable and deletable off
            // if (p.level.Config.Deletable && p.level.Config.Buildable) { return; }

            // as an example of using the above enums, you can uncomment this to do nothing and quit if the player just used pick-block button.
            // if (button == MouseButton.Middle) { return; }


            BlockID clickedBlock;

            clickedBlock = p.level.GetBlock(x, y, z);
            //clickedBlock is now the block ID that was clicked.
            //This ID is MCGalaxy block ID, which means it's not mapped the same as client block ID.
            //However, 0-65 are still identical.

            //Example of running /place to put a stone block at the coordinates the player has clicked.
            Command.Find("place").Use(p, "stone " + x + " " + y + " " + z + "");
        }
예제 #3
0
        int HandlePlayerClicked(byte[] buffer, int offset, int left)
        {
            const int size = 1 + 1 + 1 + 2 + 2 + 1 + 2 + 2 + 2 + 1;

            if (left < size)
            {
                return(0);
            }

            MouseButton Button   = (MouseButton)buffer[offset + 1];
            MouseAction Action   = (MouseAction)buffer[offset + 2];
            ushort      yaw      = NetUtils.ReadU16(buffer, offset + 3);
            ushort      pitch    = NetUtils.ReadU16(buffer, offset + 5);
            byte        entityID = buffer[offset + 7];
            ushort      x        = NetUtils.ReadU16(buffer, offset + 8);
            ushort      y        = NetUtils.ReadU16(buffer, offset + 10);
            ushort      z        = NetUtils.ReadU16(buffer, offset + 12);

            TargetBlockFace face = (TargetBlockFace)buffer[offset + 14];

            if (face > TargetBlockFace.None)
            {
                face = TargetBlockFace.None;
            }
            OnPlayerClickEvent.Call(this, Button, Action, yaw, pitch, entityID, x, y, z, face);
            return(size);
        }
예제 #4
0
 public static void Call(Player p, MouseButton btn, MouseAction action,
                         ushort yaw, ushort pitch, byte entityID,
                         ushort x, ushort y, ushort z, TargetBlockFace face)
 {
     IEvent <OnPlayerClick>[] items = handlers.Items;
     for (int i = 0; i < items.Length; i++)
     {
         try { items[i].method(p, btn, action, yaw, pitch, entityID, x, y, z, face); }
         catch (Exception ex) { LogHandlerException(ex, items[i]); }
     }
 }
예제 #5
0
        public IPacketWithSize ReadPacket(IProtocolDataReader reader)
        {
            Button              = (Button)reader.ReadByte();
            Action              = (Action)reader.ReadByte();
            Yaw                 = reader.ReadShort();
            Pitch               = reader.ReadShort();
            TargetEntityID      = reader.ReadByte();
            TargetBlockLocation = Position.FromReaderShort(reader);
            TargetBlockFace     = (TargetBlockFace)reader.ReadByte();

            return(this);
        }
예제 #6
0
        void PlayerClickCallback(Player p, MouseButton btn, MouseAction action,
                                 ushort yaw, ushort pitch, byte entity,
                                 ushort x, ushort y, ushort z, TargetBlockFace face)
        {
            if (!p.aiming || btn != MouseButton.Left || action != MouseAction.Pressed)
            {
                return;
            }
            if (!p.level.Config.Guns)
            {
                Disable(p); return;
            }

            BlockID held = p.GetHeldBlock();

            if (!CommandParser.IsBlockAllowed(p, "use", held))
            {
                return;
            }
            OnActivated(p, (byte)(yaw >> 8), (byte)(pitch >> 8), held);
        }
예제 #7
0
        internal static void HandlePlayerClick(Player p, MouseButton button, MouseAction action, ushort yaw, ushort pitch,
                                               byte entity, ushort x, ushort y, ushort z, TargetBlockFace face)
        {
            if (action != MouseAction.Pressed)
            {
                return;
            }
            if (entity != Entities.SelfID && ClickOnBot(p, entity))
            {
                return;
            }

            if (p.level.Config.Deletable || !p.level.IsValidPos(x, y, z))
            {
                return;
            }
            BlockID block    = p.level.GetBlock(x, y, z);
            bool    isMB     = p.level.Props[block].IsMessageBlock;
            bool    isPortal = p.level.Props[block].IsPortal;

            if (isMB)
            {
                MessageBlock.Handle(p, x, y, z, true);
            }
            if (isPortal)
            {
                Portal.Handle(p, x, y, z);
            }
        }
예제 #8
0
 //Clean this stuff up later
 static void OnClick(Player player, MouseButton Button, MouseAction Action, ushort Yaw, ushort Pitch, byte EntityID, ushort X, ushort Y, ushort Z, TargetBlockFace target)
 {
     if ((bool)player.ExtraData["Spec"] || !Core.Match.started)
     {
         return;
     }
     if (Button == MouseButton.Right && Action == MouseAction.Pressed)
     {
         KickBall(player, Yaw, Pitch);
     }
     if (Button == MouseButton.Left && Action == MouseAction.Pressed && Core.Ball.PickedUp == null && Core.Match.State == MatchState.InGame)
     {
         if (EntityID == PlayerBot.Find("ball").id&& DistanceFromBall(player.pos[0], player.pos[1], player.pos[2]) <= 128)
         {
             var team = Team.FindPlayer(player);
             if (team != null && team.Goalie == player)
             {
                 if (Core.Ball.LastTouchPlayer == player)
                 {
                     if (Team.FindPlayer(Core.Ball.SecondLastTouchPlayer) == team)
                     {
                         return;
                     }
                 }
                 else if (Team.FindPlayer(Core.Ball.LastTouchPlayer) == team)
                 {
                     return;
                 }
                 bool insideBox = false;
                 if (team == Core.Match.TeamLeft)
                 {
                     if (player.pos[0] <= Constants.BoxLeft && player.pos[2] <= Constants.BoxBottom && player.pos[2] >= Constants.BoxTop)
                     {
                         if (Core.Ball.Position3d.X <= Constants.BoxLeft && Core.Ball.Position3d.Y <= Constants.BoxBottom && Core.Ball.Position3d.Y >= Constants.BoxTop)
                         {
                             insideBox = true;
                         }
                     }
                 }
                 if (team == Core.Match.TeamRight)
                 {
                     if (player.pos[0] >= Constants.BoxRight && player.pos[2] <= Constants.BoxBottom && player.pos[2] >= Constants.BoxTop)
                     {
                         if (Core.Ball.Position3d.X >= Constants.BoxRight && Core.Ball.Position3d.Y <= Constants.BoxBottom && Core.Ball.Position3d.Y >= Constants.BoxTop)
                         {
                             insideBox = true;
                         }
                     }
                 }
                 if (insideBox)
                 {
                     Chat.MessageAll(player.ColoredName + Server.DefaultColor + " picks up the ball");
                     Core.Ball._velocity.X = 0;
                     Core.Ball._velocity.Y = 0;
                     Core.Ball._velocity.Z = 0;
                     Core.Ball.PickedUp    = player;
                     player.ExtraData.ChangeOrCreate("Saves", (int)player.ExtraData["Saves"] + 1);
                 }
                 else
                 {
                     player.SendMessage("You need to be in the box to pick up the ball");
                 }
             }
         }
     }
 }
예제 #9
0
 public static void Call(Player p, MouseButton button, MouseAction action, ushort yaw, ushort pitch, byte entity, ushort x, ushort y, ushort z, TargetBlockFace face)
 {
     if (handlers.Count == 0)
     {
         return;
     }
     CallImpl(pl => pl(p, button, action, yaw,
                       pitch, entity, x, y, z, face));
 }