Attack.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. /**
  31. * TODO: This class is a copy of AttackRequest, we should get proper structure for both.
  32. */
  33. public final class Attack extends L2GameClientPacket
  34. {
  35. private static final String _C__01_ATTACK = "[C] 01 Attack";
  36. // cddddc
  37. private int _objectId;
  38. @SuppressWarnings("unused")
  39. private int _originX;
  40. @SuppressWarnings("unused")
  41. private int _originY;
  42. @SuppressWarnings("unused")
  43. private int _originZ;
  44. @SuppressWarnings("unused")
  45. private int _attackId;
  46. @Override
  47. protected void readImpl()
  48. {
  49. _objectId = readD();
  50. _originX = readD();
  51. _originY = readD();
  52. _originZ = readD();
  53. _attackId = readC(); // 0 for simple click 1 for shift-click
  54. }
  55. @Override
  56. protected void runImpl()
  57. {
  58. final L2PcInstance activeChar = getActiveChar();
  59. if (activeChar == null)
  60. {
  61. return;
  62. }
  63. // Avoid Attacks in Boat.
  64. if (activeChar.isPlayable() && activeChar.isInBoat())
  65. {
  66. activeChar.sendPacket(SystemMessageId.NOT_ALLOWED_ON_BOAT);
  67. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  68. return;
  69. }
  70. final BuffInfo info = activeChar.getEffectList().getBuffInfoByAbnormalType(AbnormalType.BOT_PENALTY);
  71. if (info != null)
  72. {
  73. for (AbstractEffect effect : info.getEffects())
  74. {
  75. if (!effect.checkCondition(-1))
  76. {
  77. activeChar.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REPORTED_SO_ACTIONS_NOT_ALLOWED);
  78. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  79. return;
  80. }
  81. }
  82. }
  83. // avoid using expensive operations if not needed
  84. final L2Object target;
  85. if (activeChar.getTargetId() == _objectId)
  86. {
  87. target = activeChar.getTarget();
  88. }
  89. else
  90. {
  91. target = L2World.getInstance().findObject(_objectId);
  92. }
  93. if (target == null)
  94. {
  95. return;
  96. }
  97. if (!target.isTargetable() && !activeChar.canOverrideCond(PcCondOverride.TARGET_ALL))
  98. {
  99. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  100. return;
  101. }
  102. // Players can't attack objects in the other instances
  103. // except from multiverse
  104. else if ((target.getInstanceId() != activeChar.getInstanceId()) && (activeChar.getInstanceId() != -1))
  105. {
  106. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  107. return;
  108. }
  109. // Only GMs can directly attack invisible characters
  110. else if (!target.isVisibleFor(activeChar))
  111. {
  112. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  113. return;
  114. }
  115. if (activeChar.getTarget() != target)
  116. {
  117. target.onAction(activeChar);
  118. }
  119. else
  120. {
  121. if ((target.getObjectId() != activeChar.getObjectId()) && (activeChar.getPrivateStoreType() == PrivateStoreType.NONE) && (activeChar.getActiveRequester() == null))
  122. {
  123. target.onForcedAttack(activeChar);
  124. }
  125. else
  126. {
  127. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  128. }
  129. }
  130. }
  131. @Override
  132. public String getType()
  133. {
  134. return _C__01_ATTACK;
  135. }
  136. }