Beispiel #1
0
		/// <summary>
		///     Handles the interact.
		/// </summary>
		/// <param name="message">The message.</param>
		protected virtual void HandleInteract(McpeInteract message)
		{
			Entity target = Level.GetEntity(message.targetEntityId);

			//Log.DebugFormat("Interact Action ID: {0}", message.actionId);
			//Log.DebugFormat("Interact Target Entity ID: {0}", message.targetEntityId);

			if (target == null) return;

			Player player = target as Player;
			if (player != null)
			{
				int damage = Inventory.GetItemInHand().Item.GetDamage(); //Item Damage.
				player.HealthManager.TakeHit(this, CalculatePlayerDamage(player, damage), DamageCause.EntityAttack);
			}
			else
			{
				target.HealthManager.TakeHit(this, CalculateDamage(target), DamageCause.EntityAttack);
			}
		}
Beispiel #2
0
 public virtual void HandleMcpeInteract(McpeInteract message)
 {
 }
Beispiel #3
0
        /// <summary>
        ///     Handles the interact.
        /// </summary>
        /// <param name="message">The message.</param>
        protected virtual void HandleInteract(McpeInteract message)
        {
            Entity target = Level.GetEntity(message.targetEntityId);

            Log.DebugFormat("Interact Action ID: {0}", message.actionId);
            Log.DebugFormat("Interact Target Entity ID: {0}", message.targetEntityId);

            if (target == null) return;

            target.HealthManager.TakeHit(this, CalculateDamage(target), DamageCause.EntityAttack);
        }
 public abstract void HandleMcpeInteract(McpeInteract message);
Beispiel #5
0
 public override void HandleMcpeInteract(McpeInteract message)
 {
 }
Beispiel #6
0
        protected override void OnMessage(MessageEventArgs e)
        {
            try
            {
                var json = JObject.Parse(e.Data);
                if ((string)json["action"] == "send_packet")
                {
                    if (Client == null || !Client.HaveServer)
                    {
                        return;
                    }
                    var pk     = (string)json["pk"];
                    var packet = json["packet"];
                    switch (pk)
                    {
                    case "interact":
                        var interact = McpeInteract.CreateObject();
                        interact.actionId = (byte)packet["action"];
                        interact.targetRuntimeEntityId = (long)packet["entityId"];
                        Client.SendPackage(interact);
                        break;

                    case "move":
                        Client.CurrentLocation = new PlayerLocation((float)packet["x"], (float)packet["y"], (float)packet["z"]);
                        Console.WriteLine("move to " + Client.CurrentLocation);
                        Client.SendMcpeMovePlayer();
                        break;
                    }
                }
                else if ((string)json["action"] == "command")
                {
                    var args = ((string)json["message"]).Split(' ');
                    switch (args[0].ToLower())
                    {
                    case "chat":
                        Client.SendChat(string.Join(" ", args.Skip(1)));
                        break;

                    case "disconnect":
                        if (Client != null)
                        {
                            Client.SendDisconnectionNotification();
                            CommandResponse("Disconnected");
                        }
                        else
                        {
                            CommandResponse("Not connected");
                        }
                        break;

                    case "connect":
                        IPAddress ip;
                        if (args.Length <= 1)
                        {
                            ip = IPAddress.Loopback;
                        }
                        else
                        {
                            var addresses = Dns.GetHostEntry(args[1]).AddressList;
                            if (addresses.Length > 0)
                            {
                                ip = addresses[0];
                            }
                            else if (IPAddress.TryParse(args[1], out ip))
                            {
                                CommandResponse("Bad ip: " + args[1]);
                                return;
                            }
                        }

                        short port;
                        if (args.Length <= 2)
                        {
                            port = 19132;
                        }
                        else
                        {
                            if (!short.TryParse(args[2], out port))
                            {
                                CommandResponse("Bad port: " + args[2]);
                                return;
                            }
                        }

                        string username;
                        if (args.Length <= 3)
                        {
                            username = "******";
                        }
                        else
                        {
                            username = args[3];
                        }

                        CommandResponse("Connecting to " + ip + ":" + port);
                        var endpoint = new IPEndPoint(ip, port);
                        Connect(endpoint, username);
                        break;

                    default:
                        Send("Unknown command!");
                        break;
                    }
                }
                else if ((string)json["action"] == "chat")
                {
                    Client.SendChat((string)json["message"]);
                }
            } catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
 public override void HandleMcpeInteract(McpeInteract message)
 {
     UnhandledPackage(message);
 }
 public void HandleMcpeInteract(McpeInteract message)
 {
 }