AttackRequest.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 net.sf.l2j.gameserver.model.L2Object;
  17. import net.sf.l2j.gameserver.model.L2World;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  19. import net.sf.l2j.gameserver.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. L2PcInstance activeChar = getClient().getActiveChar();
  51. if (activeChar == null) return;
  52. // avoid using expensive operations if not needed
  53. L2Object target;
  54. if (activeChar.getTargetId() == _objectId)
  55. target = activeChar.getTarget();
  56. else
  57. target = L2World.getInstance().findObject(_objectId);
  58. if (target == null) return;
  59. if (activeChar.getTarget() != target)
  60. {
  61. target.onAction(activeChar);
  62. }
  63. else
  64. {
  65. if ((target.getObjectId() != activeChar.getObjectId())
  66. && activeChar.getPrivateStoreType() ==0
  67. && activeChar.getActiveRequester() ==null)
  68. {
  69. //_log.config("Starting ForcedAttack");
  70. target.onForcedAttack(activeChar);
  71. //_log.config("Ending ForcedAttack");
  72. }
  73. else
  74. {
  75. sendPacket(new ActionFailed());
  76. }
  77. }
  78. }
  79. /* (non-Javadoc)
  80. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  81. */
  82. @Override
  83. public String getType()
  84. {
  85. return _C__0A_ATTACKREQUEST;
  86. }
  87. }