RequestGetOnVehicle.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.network.clientpackets;
  16. import com.l2jserver.gameserver.instancemanager.BoatManager;
  17. import com.l2jserver.gameserver.model.actor.instance.L2BoatInstance;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  20. import com.l2jserver.gameserver.network.serverpackets.GetOnVehicle;
  21. import com.l2jserver.util.Point3D;
  22. /**
  23. * This class ...
  24. *
  25. * @version $Revision: 1.1.4.3 $ $Date: 2005/03/27 15:29:30 $
  26. */
  27. public final class RequestGetOnVehicle extends L2GameClientPacket
  28. {
  29. private static final String _C__5C_GETONVEHICLE = "[C] 5C GetOnVehicle";
  30. private int _boatId;
  31. private Point3D _pos;
  32. @Override
  33. protected void readImpl()
  34. {
  35. int x, y, z;
  36. _boatId = readD();
  37. x = readD();
  38. y = readD();
  39. z = readD();
  40. _pos = new Point3D(x, y, z);
  41. }
  42. @Override
  43. protected void runImpl()
  44. {
  45. final L2PcInstance activeChar = getClient().getActiveChar();
  46. if (activeChar == null)
  47. return;
  48. L2BoatInstance boat;
  49. if (activeChar.isInBoat())
  50. {
  51. boat = activeChar.getBoat();
  52. if (boat.getObjectId() != _boatId)
  53. {
  54. sendPacket(ActionFailed.STATIC_PACKET);
  55. return;
  56. }
  57. }
  58. else
  59. {
  60. boat = BoatManager.getInstance().getBoat(_boatId);
  61. if (boat == null
  62. || boat.isMoving()
  63. || !activeChar.isInsideRadius(boat, 1000, true, false))
  64. {
  65. sendPacket(ActionFailed.STATIC_PACKET);
  66. return;
  67. }
  68. }
  69. activeChar.setInVehiclePosition(_pos);
  70. activeChar.setVehicle(boat);
  71. activeChar.broadcastPacket(new GetOnVehicle(activeChar.getObjectId(), boat.getObjectId(), _pos));
  72. activeChar.setXYZ(boat.getX(), boat.getY(), boat.getZ());
  73. activeChar.revalidateZone(true);
  74. }
  75. /* (non-Javadoc)
  76. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  77. */
  78. @Override
  79. public String getType()
  80. {
  81. return _C__5C_GETONVEHICLE;
  82. }
  83. }