MoveBackwardToLocation.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 java.nio.BufferUnderflowException;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.TaskPriority;
  19. import com.l2jserver.gameserver.ai.CtrlIntention;
  20. import com.l2jserver.gameserver.model.L2CharPosition;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  23. import com.l2jserver.gameserver.network.serverpackets.PartyMemberPosition;
  24. /**
  25. * This class ...
  26. *
  27. * @version $Revision: 1.11.2.4.2.4 $ $Date: 2005/03/27 15:29:30 $
  28. */
  29. public class MoveBackwardToLocation extends L2GameClientPacket
  30. {
  31. //private static Logger _log = Logger.getLogger(MoveBackwardToLocation.class.getName());
  32. // cdddddd
  33. private int _targetX;
  34. private int _targetY;
  35. private int _targetZ;
  36. @SuppressWarnings("unused")
  37. private int _originX;
  38. @SuppressWarnings("unused")
  39. private int _originY;
  40. @SuppressWarnings("unused")
  41. private int _originZ;
  42. private int _moveMovement;
  43. //For geodata
  44. private int _curX;
  45. private int _curY;
  46. @SuppressWarnings("unused")
  47. private int _curZ;
  48. public TaskPriority getPriority() { return TaskPriority.PR_HIGH; }
  49. private static final String _C__01_MOVEBACKWARDTOLOC = "[C] 01 MoveBackwardToLoc";
  50. @Override
  51. protected void readImpl()
  52. {
  53. _targetX = readD();
  54. _targetY = readD();
  55. _targetZ = readD();
  56. _originX = readD();
  57. _originY = readD();
  58. _originZ = readD();
  59. try
  60. {
  61. _moveMovement = readD(); // is 0 if cursor keys are used 1 if mouse is used
  62. }
  63. catch (BufferUnderflowException e)
  64. {
  65. // ignore for now
  66. }
  67. }
  68. @Override
  69. protected void runImpl()
  70. {
  71. L2PcInstance activeChar = getClient().getActiveChar();
  72. if (activeChar == null)
  73. return;
  74. // Correcting targetZ from floor level to head level (?)
  75. // Client is giving floor level as targetZ but that floor level doesn't
  76. // match our current geodata and teleport coords as good as head level!
  77. // L2J uses floor, not head level as char coordinates. This is some
  78. // sort of incompatibility fix.
  79. // Validate position packets sends head level.
  80. _targetZ += activeChar.getTemplate().collisionHeight;
  81. _curX = activeChar.getX();
  82. _curY = activeChar.getY();
  83. _curZ = activeChar.getZ();
  84. if(activeChar.isInBoat())
  85. {
  86. activeChar.setInBoat(false);
  87. }
  88. if (activeChar.getTeleMode() > 0)
  89. {
  90. if (activeChar.getTeleMode() == 1)
  91. activeChar.setTeleMode(0);
  92. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  93. activeChar.teleToLocation(_targetX, _targetY, _targetZ, false);
  94. return;
  95. }
  96. if (_moveMovement == 0 && Config.GEODATA < 1) // cursor movement without geodata is disabled
  97. {
  98. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  99. }
  100. else
  101. {
  102. double dx = _targetX-_curX;
  103. double dy = _targetY-_curY;
  104. // Can't move if character is confused, or trying to move a huge distance
  105. if (activeChar.isOutOfControl() || ((dx*dx+dy*dy) > 98010000)) // 9900*9900
  106. {
  107. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  108. return;
  109. }
  110. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO,
  111. new L2CharPosition(_targetX, _targetY, _targetZ, 0));
  112. if(activeChar.getParty() != null)
  113. activeChar.getParty().broadcastToPartyMembers(activeChar,new PartyMemberPosition(activeChar));
  114. }
  115. }
  116. /* (non-Javadoc)
  117. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  118. */
  119. @Override
  120. public String getType()
  121. {
  122. return _C__01_MOVEBACKWARDTOLOC;
  123. }
  124. @Override
  125. protected boolean triggersOnActionRequest()
  126. {
  127. return true;
  128. }
  129. }