RequestMoveToLocationInVehicle.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.TaskPriority;
  17. import com.l2jserver.gameserver.instancemanager.BoatManager;
  18. import com.l2jserver.gameserver.model.actor.instance.L2BoatInstance;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  22. import com.l2jserver.gameserver.network.serverpackets.MoveToLocationInVehicle;
  23. import com.l2jserver.gameserver.network.serverpackets.StopMoveInVehicle;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. import com.l2jserver.gameserver.templates.item.L2WeaponType;
  26. import com.l2jserver.util.Point3D;
  27. public final class RequestMoveToLocationInVehicle extends L2GameClientPacket
  28. {
  29. private static final String _C__75_MOVETOLOCATIONINVEHICLE = "[C] 75 RequestMoveToLocationInVehicle";
  30. private int _boatId;
  31. private int _targetX;
  32. private int _targetY;
  33. private int _targetZ;
  34. private int _originX;
  35. private int _originY;
  36. private int _originZ;
  37. public TaskPriority getPriority() { return TaskPriority.PR_HIGH; }
  38. @Override
  39. protected void readImpl()
  40. {
  41. _boatId = readD(); //objectId of boat
  42. _targetX = readD();
  43. _targetY = readD();
  44. _targetZ = readD();
  45. _originX = readD();
  46. _originY = readD();
  47. _originZ = readD();
  48. }
  49. /* (non-Javadoc)
  50. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#runImpl()
  51. */
  52. @Override
  53. protected
  54. void runImpl()
  55. {
  56. final L2PcInstance activeChar = getClient().getActiveChar();
  57. if (activeChar == null)
  58. return;
  59. if (_targetX == _originX && _targetY == _originY && _targetZ == _originZ)
  60. {
  61. activeChar.sendPacket(new StopMoveInVehicle(activeChar, _boatId));
  62. return;
  63. }
  64. if (activeChar.isAttackingNow()
  65. && activeChar.getActiveWeaponItem() != null
  66. && (activeChar.getActiveWeaponItem().getItemType() == L2WeaponType.BOW))
  67. {
  68. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  69. return;
  70. }
  71. if (activeChar.isSitting() || activeChar.isMovementDisabled())
  72. {
  73. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  74. return;
  75. }
  76. if (activeChar.getPet() != null)
  77. {
  78. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.RELEASE_PET_ON_BOAT));
  79. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  80. return;
  81. }
  82. if (activeChar.isTransformed())
  83. {
  84. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANT_POLYMORPH_ON_BOAT));
  85. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  86. return;
  87. }
  88. final L2BoatInstance boat;
  89. if (activeChar.isInBoat())
  90. {
  91. boat = activeChar.getBoat();
  92. if (boat.getObjectId() != _boatId)
  93. {
  94. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  95. return;
  96. }
  97. }
  98. else
  99. {
  100. boat = BoatManager.getInstance().getBoat(_boatId);
  101. if (boat == null || !boat.isInsideRadius(activeChar, 300, true, false))
  102. {
  103. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  104. return;
  105. }
  106. activeChar.setVehicle(boat);
  107. }
  108. final Point3D pos = new Point3D(_targetX, _targetY, _targetZ);
  109. final Point3D originPos = new Point3D(_originX, _originY, _originZ);
  110. activeChar.setInVehiclePosition(pos);
  111. activeChar.broadcastPacket(new MoveToLocationInVehicle(activeChar, pos, originPos));
  112. }
  113. /* (non-Javadoc)
  114. * @see com.l2jserver.gameserver.BasePacket#getType()
  115. */
  116. @Override
  117. public String getType()
  118. {
  119. return _C__75_MOVETOLOCATIONINVEHICLE;
  120. }
  121. }