MoveBackwardToLocation.java 4.4 KB

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