AttackRequest.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 com.l2jserver.gameserver.enums.PrivateStoreType;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.L2World;
  23. import com.l2jserver.gameserver.model.PcCondOverride;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  26. import com.l2jserver.gameserver.model.skills.AbnormalType;
  27. import com.l2jserver.gameserver.model.skills.BuffInfo;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  30. public final class AttackRequest extends L2GameClientPacket
  31. {
  32. private static final String _C__32_ATTACKREQUEST = "[C] 32 AttackRequest";
  33. // cddddc
  34. private int _objectId;
  35. @SuppressWarnings("unused")
  36. private int _originX;
  37. @SuppressWarnings("unused")
  38. private int _originY;
  39. @SuppressWarnings("unused")
  40. private int _originZ;
  41. @SuppressWarnings("unused")
  42. private int _attackId;
  43. @Override
  44. protected void readImpl()
  45. {
  46. _objectId = readD();
  47. _originX = readD();
  48. _originY = readD();
  49. _originZ = readD();
  50. _attackId = readC(); // 0 for simple click 1 for shift-click
  51. }
  52. @Override
  53. protected void runImpl()
  54. {
  55. final L2PcInstance activeChar = getActiveChar();
  56. if (activeChar == null)
  57. {
  58. return;
  59. }
  60. final BuffInfo info = activeChar.getEffectList().getBuffInfoByAbnormalType(AbnormalType.BOT_PENALTY);
  61. if (info != null)
  62. {
  63. for (AbstractEffect effect : info.getEffects())
  64. {
  65. if (!effect.checkCondition(-1))
  66. {
  67. activeChar.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REPORTED_SO_ACTIONS_NOT_ALLOWED);
  68. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  69. return;
  70. }
  71. }
  72. }
  73. // avoid using expensive operations if not needed
  74. final L2Object target;
  75. if (activeChar.getTargetId() == _objectId)
  76. {
  77. target = activeChar.getTarget();
  78. }
  79. else
  80. {
  81. target = L2World.getInstance().findObject(_objectId);
  82. }
  83. if (target == null)
  84. {
  85. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  86. return;
  87. }
  88. else if (!target.isTargetable() && !activeChar.canOverrideCond(PcCondOverride.TARGET_ALL))
  89. {
  90. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  91. return;
  92. }
  93. // Players can't attack objects in the other instances
  94. // except from multiverse
  95. else if ((target.getInstanceId() != activeChar.getInstanceId()) && (activeChar.getInstanceId() != -1))
  96. {
  97. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  98. return;
  99. }
  100. // Only GMs can directly attack invisible characters
  101. else if (!target.isVisibleFor(activeChar))
  102. {
  103. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  104. return;
  105. }
  106. if (activeChar.getTarget() != target)
  107. {
  108. target.onAction(activeChar);
  109. }
  110. else
  111. {
  112. if ((target.getObjectId() != activeChar.getObjectId()) && (activeChar.getPrivateStoreType() == PrivateStoreType.NONE) && (activeChar.getActiveRequester() == null))
  113. {
  114. target.onForcedAttack(activeChar);
  115. }
  116. else
  117. {
  118. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  119. }
  120. }
  121. }
  122. @Override
  123. public String getType()
  124. {
  125. return _C__32_ATTACKREQUEST;
  126. }
  127. }