RequestMoveToLocationInVehicle.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.instancemanager.BoatManager;
  22. import com.l2jserver.gameserver.model.Location;
  23. import com.l2jserver.gameserver.model.actor.instance.L2BoatInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.items.type.WeaponType;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  28. import com.l2jserver.gameserver.network.serverpackets.MoveToLocationInVehicle;
  29. import com.l2jserver.gameserver.network.serverpackets.StopMoveInVehicle;
  30. public final class RequestMoveToLocationInVehicle extends L2GameClientPacket
  31. {
  32. private static final String _C__75_MOVETOLOCATIONINVEHICLE = "[C] 75 RequestMoveToLocationInVehicle";
  33. private int _boatId;
  34. private int _targetX;
  35. private int _targetY;
  36. private int _targetZ;
  37. private int _originX;
  38. private int _originY;
  39. private int _originZ;
  40. @Override
  41. protected void readImpl()
  42. {
  43. _boatId = readD(); // objectId of boat
  44. _targetX = readD();
  45. _targetY = readD();
  46. _targetZ = readD();
  47. _originX = readD();
  48. _originY = readD();
  49. _originZ = readD();
  50. }
  51. @Override
  52. protected void runImpl()
  53. {
  54. final L2PcInstance activeChar = getClient().getActiveChar();
  55. if (activeChar == null)
  56. {
  57. return;
  58. }
  59. if ((Config.PLAYER_MOVEMENT_BLOCK_TIME > 0) && !activeChar.isGM() && (activeChar.getNotMoveUntil() > System.currentTimeMillis()))
  60. {
  61. activeChar.sendPacket(SystemMessageId.CANNOT_MOVE_WHILE_SPEAKING_TO_AN_NPC);
  62. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  63. return;
  64. }
  65. if ((_targetX == _originX) && (_targetY == _originY) && (_targetZ == _originZ))
  66. {
  67. activeChar.sendPacket(new StopMoveInVehicle(activeChar, _boatId));
  68. return;
  69. }
  70. if (activeChar.isAttackingNow() && (activeChar.getActiveWeaponItem() != null) && (activeChar.getActiveWeaponItem().getItemType() == WeaponType.BOW))
  71. {
  72. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  73. return;
  74. }
  75. if (activeChar.isSitting() || activeChar.isMovementDisabled())
  76. {
  77. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  78. return;
  79. }
  80. if (activeChar.hasSummon())
  81. {
  82. activeChar.sendPacket(SystemMessageId.RELEASE_PET_ON_BOAT);
  83. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  84. return;
  85. }
  86. if (activeChar.isTransformed())
  87. {
  88. activeChar.sendPacket(SystemMessageId.CANT_POLYMORPH_ON_BOAT);
  89. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  90. return;
  91. }
  92. final L2BoatInstance boat;
  93. if (activeChar.isInBoat())
  94. {
  95. boat = activeChar.getBoat();
  96. if (boat.getObjectId() != _boatId)
  97. {
  98. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  99. return;
  100. }
  101. }
  102. else
  103. {
  104. boat = BoatManager.getInstance().getBoat(_boatId);
  105. if ((boat == null) || !boat.isInsideRadius(activeChar, 300, true, false))
  106. {
  107. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  108. return;
  109. }
  110. activeChar.setVehicle(boat);
  111. }
  112. final Location pos = new Location(_targetX, _targetY, _targetZ);
  113. final Location originPos = new Location(_originX, _originY, _originZ);
  114. activeChar.setInVehiclePosition(pos);
  115. activeChar.broadcastPacket(new MoveToLocationInVehicle(activeChar, pos, originPos));
  116. }
  117. @Override
  118. public String getType()
  119. {
  120. return _C__75_MOVETOLOCATIONINVEHICLE;
  121. }
  122. }