MoveBackwardToLocation.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 java.nio.BufferUnderflowException;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.ai.CtrlIntention;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  27. import com.l2jserver.gameserver.network.serverpackets.StopMove;
  28. import com.l2jserver.gameserver.util.Util;
  29. /**
  30. * This class ...
  31. * @version $Revision: 1.11.2.4.2.4 $ $Date: 2005/03/27 15:29:30 $
  32. */
  33. public class MoveBackwardToLocation extends L2GameClientPacket
  34. {
  35. private static final String _C__0F_MOVEBACKWARDTOLOC = "[C] 0F MoveBackwardToLoc";
  36. // cdddddd
  37. private int _targetX;
  38. private int _targetY;
  39. private int _targetZ;
  40. private int _originX;
  41. private int _originY;
  42. private int _originZ;
  43. @SuppressWarnings("unused")
  44. private int _moveMovement;
  45. @Override
  46. protected void readImpl()
  47. {
  48. _targetX = readD();
  49. _targetY = readD();
  50. _targetZ = readD();
  51. _originX = readD();
  52. _originY = readD();
  53. _originZ = readD();
  54. try
  55. {
  56. _moveMovement = readD(); // is 0 if cursor keys are used 1 if mouse is used
  57. }
  58. catch (BufferUnderflowException e)
  59. {
  60. if (Config.L2WALKER_PROTECTION)
  61. {
  62. L2PcInstance activeChar = getClient().getActiveChar();
  63. Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " is trying to use L2Walker and got kicked.", Config.DEFAULT_PUNISH);
  64. }
  65. }
  66. }
  67. @Override
  68. protected void runImpl()
  69. {
  70. L2PcInstance activeChar = getClient().getActiveChar();
  71. if (activeChar == null)
  72. {
  73. return;
  74. }
  75. if ((Config.PLAYER_MOVEMENT_BLOCK_TIME > 0) && !activeChar.isGM() && (activeChar.getNotMoveUntil() > System.currentTimeMillis()))
  76. {
  77. activeChar.sendPacket(SystemMessageId.CANNOT_MOVE_WHILE_SPEAKING_TO_AN_NPC);
  78. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  79. return;
  80. }
  81. if ((_targetX == _originX) && (_targetY == _originY) && (_targetZ == _originZ))
  82. {
  83. activeChar.sendPacket(new StopMove(activeChar));
  84. return;
  85. }
  86. // Correcting targetZ from floor level to head level (?)
  87. // Client is giving floor level as targetZ but that floor level doesn't
  88. // match our current geodata and teleport coords as good as head level!
  89. // L2J uses floor, not head level as char coordinates. This is some
  90. // sort of incompatibility fix.
  91. // Validate position packets sends head level.
  92. _targetZ += activeChar.getTemplate().getCollisionHeight();
  93. if (activeChar.getTeleMode() > 0)
  94. {
  95. if (activeChar.getTeleMode() == 1)
  96. {
  97. activeChar.setTeleMode(0);
  98. }
  99. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  100. activeChar.teleToLocation(new Location(_targetX, _targetY, _targetZ));
  101. return;
  102. }
  103. double dx = _targetX - activeChar.getX();
  104. double dy = _targetY - activeChar.getY();
  105. // Can't move if character is confused, or trying to move a huge distance
  106. if (activeChar.isOutOfControl() || (((dx * dx) + (dy * dy)) > 98010000)) // 9900*9900
  107. {
  108. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  109. return;
  110. }
  111. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(_targetX, _targetY, _targetZ));
  112. }
  113. @Override
  114. public String getType()
  115. {
  116. return _C__0F_MOVEBACKWARDTOLOC;
  117. }
  118. }