示例#1
0
        public static void HandlePacketUseEntity(Client client, UseEntityPacket packet)
        {
            //Console.WriteLine(e.Packet.Target);
            //this.SendMessage("You are interacting with " + e.Packet.Target + " " + e.Packet.LeftClick);
            Player handledPlayer = client.Owner;
            foreach (EntityBase eb in handledPlayer.Server.GetNearbyEntities(handledPlayer.World, handledPlayer.Position.X, handledPlayer.Position.Y, handledPlayer.Position.Z))
            {
                if (eb.EntityId != packet.Target)
                    continue;

                if (eb is Player)
                {
                    Player player = (Player)eb;

                    if (packet.LeftClick)
                    {
                        if (player.Health > 0)
                            player.Client.DamageClient(DamageCause.EntityAttack, handledPlayer, 0);
                    }
                    else
                    {
                        // TODO: Store the object being ridden, so we can update player movement.
                        // This will ride the entity, sends -1 to dismount.
                        foreach (Client cl in handledPlayer.Server.GetNearbyPlayers(handledPlayer.World, handledPlayer.Position.X, handledPlayer.Position.Y, handledPlayer.Position.Z))
                        {
                            cl.SendPacket(new AttachEntityPacket
                            {
                                EntityId = handledPlayer.EntityId,
                                VehicleId = player.EntityId
                            });
                        }
                    }
                }
                else if (eb is Mob)
                {
                    Mob m = (Mob)eb;

                    if (packet.LeftClick)
                    {
                        if (m.Health > 0)
                            m.DamageMob(handledPlayer);
                    }
                    else
                    {
                        // We are interacting with a Mob - tell it what we are using to interact with it
                        m.InteractWith(handledPlayer.Client, handledPlayer.Inventory.ActiveItem);

                        // TODO: move the following to appropriate mob locations
                        // TODO: Check Entity has saddle set.
                        //// This will ride the entity, sends -1 to dismount.
                        //foreach (Client c in Server.GetNearbyPlayers(World, Position.X, Position.Y, Position.Z))
                        //{
                        //    c.PacketHandler.SendPacket(new AttachEntityPacket
                        //    {
                        //        EntityId = this.EntityId,
                        //        VehicleId = c.EntityId
                        //    });
                        //}
                    }
                }
                /*else
                {
                    this.SendMessage(e.Packet.Target + " has no interaction handler!");
                }*/
            }
        }
示例#2
0
 private void OnUseEntity(UseEntityPacket p)
 {
     if (UseEntity != null) UseEntity.Invoke(this, new PacketEventArgs<UseEntityPacket>(p));
 }
示例#3
0
        public static void ReadUseEntity(Client client, PacketReader reader)
        {
            UseEntityPacket ue = new UseEntityPacket();
            ue.Read(reader);

            if (!reader.Failed)
                Client.HandlePacketUseEntity(client, ue);
        }