AttackRequest.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 com.l2jserver.gameserver.model.L2Object;
  17. import com.l2jserver.gameserver.model.L2World;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  20. /**
  21. * This class ...
  22. *
  23. * @version $Revision: 1.7.2.1.2.2 $ $Date: 2005/03/27 15:29:30 $
  24. */
  25. public final class AttackRequest extends L2GameClientPacket
  26. {
  27. // cddddc
  28. private int _objectId;
  29. @SuppressWarnings("unused")
  30. private int _originX;
  31. @SuppressWarnings("unused")
  32. private int _originY;
  33. @SuppressWarnings("unused")
  34. private int _originZ;
  35. @SuppressWarnings("unused")
  36. private int _attackId;
  37. private static final String _C__0A_ATTACKREQUEST = "[C] 0A AttackRequest";
  38. @Override
  39. protected void readImpl()
  40. {
  41. _objectId = readD();
  42. _originX = readD();
  43. _originY = readD();
  44. _originZ = readD();
  45. _attackId = readC(); // 0 for simple click 1 for shift-click
  46. }
  47. @Override
  48. protected void runImpl()
  49. {
  50. final L2PcInstance activeChar = getClient().getActiveChar();
  51. if (activeChar == null) return;
  52. // avoid using expensive operations if not needed
  53. final L2Object target;
  54. if (activeChar.getTargetId() == _objectId)
  55. target = activeChar.getTarget();
  56. else
  57. target = L2World.getInstance().findObject(_objectId);
  58. if (target == null)
  59. return;
  60. // Players can't attack objects in the other instances
  61. // except from multiverse
  62. if (target.getInstanceId() != activeChar.getInstanceId()
  63. && activeChar.getInstanceId() != -1)
  64. return;
  65. // Only GMs can directly attack invisible characters
  66. if (target instanceof L2PcInstance
  67. && ((L2PcInstance)target).getAppearance().getInvisible()
  68. && !activeChar.isGM())
  69. return;
  70. if (activeChar.getTarget() != target)
  71. {
  72. target.onAction(activeChar);
  73. }
  74. else
  75. {
  76. if ((target.getObjectId() != activeChar.getObjectId())
  77. && activeChar.getPrivateStoreType() ==0
  78. && activeChar.getActiveRequester() ==null)
  79. {
  80. //_log.config("Starting ForcedAttack");
  81. target.onForcedAttack(activeChar);
  82. //_log.config("Ending ForcedAttack");
  83. }
  84. else
  85. {
  86. sendPacket(ActionFailed.STATIC_PACKET);
  87. }
  88. }
  89. }
  90. /* (non-Javadoc)
  91. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  92. */
  93. @Override
  94. public String getType()
  95. {
  96. return _C__0A_ATTACKREQUEST;
  97. }
  98. @Override
  99. protected boolean triggersOnActionRequest()
  100. {
  101. return true;
  102. }
  103. }