MoveBackwardToLocation.java 4.5 KB

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