MoveBackwardToLocation.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 net.sf.l2j.gameserver.clientpackets;
  16. import java.nio.BufferUnderflowException;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.TaskPriority;
  19. import net.sf.l2j.gameserver.ai.CtrlIntention;
  20. import net.sf.l2j.gameserver.model.L2CharPosition;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  23. import net.sf.l2j.gameserver.serverpackets.PartyMemberPosition;
  24. import net.sf.l2j.gameserver.templates.L2WeaponType;
  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() { return TaskPriority.PR_HIGH; }
  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. // ignore for now
  67. }
  68. }
  69. @Override
  70. protected void runImpl()
  71. {
  72. L2PcInstance activeChar = getClient().getActiveChar();
  73. if (activeChar == null)
  74. return;
  75. _curX = activeChar.getX();
  76. _curY = activeChar.getY();
  77. _curZ = activeChar.getZ();
  78. if(activeChar.isInBoat())
  79. {
  80. activeChar.setInBoat(false);
  81. }
  82. if (activeChar.getTeleMode() > 0)
  83. {
  84. if (activeChar.getTeleMode() == 1)
  85. activeChar.setTeleMode(0);
  86. activeChar.sendPacket(new ActionFailed());
  87. activeChar.teleToLocation(_targetX, _targetY, _targetZ, false);
  88. return;
  89. }
  90. if (_moveMovement == 0 && Config.GEODATA < 1) // cursor movement without geodata is disabled
  91. {
  92. activeChar.sendPacket(new ActionFailed());
  93. }
  94. else if (activeChar.isAttackingNow() && activeChar.getActiveWeaponItem() != null && ((activeChar.getActiveWeaponItem().getItemType() == L2WeaponType.BOW) || (activeChar.getActiveWeaponItem().getItemType() == L2WeaponType.CROSSBOW)))
  95. {
  96. activeChar.sendPacket(new ActionFailed());
  97. }
  98. else
  99. {
  100. double dx = _targetX-_curX;
  101. double dy = _targetY-_curY;
  102. // Can't move if character is confused, or trying to move a huge distance
  103. if (activeChar.isOutOfControl() || ((dx*dx+dy*dy) > 98010000)) // 9900*9900
  104. {
  105. activeChar.sendPacket(new ActionFailed());
  106. return;
  107. }
  108. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO,
  109. new L2CharPosition(_targetX, _targetY, _targetZ, 0));
  110. if(activeChar.getParty() != null)
  111. activeChar.getParty().broadcastToPartyMembers(activeChar,new PartyMemberPosition(activeChar));
  112. }
  113. }
  114. /* (non-Javadoc)
  115. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  116. */
  117. @Override
  118. public String getType()
  119. {
  120. return _C__01_MOVEBACKWARDTOLOC;
  121. }
  122. }