Action.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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.Config;
  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 Action extends L2GameClientPacket
  31. {
  32. private static final String __C__1F_ACTION = "[C] 1F Action";
  33. private int _objectId;
  34. private int _originX;
  35. private int _originY;
  36. private int _originZ;
  37. private int _actionId;
  38. @Override
  39. protected void readImpl()
  40. {
  41. _objectId = readD(); // Target object Identifier
  42. _originX = readD();
  43. _originY = readD();
  44. _originZ = readD();
  45. _actionId = readC(); // Action identifier : 0-Simple click, 1-Shift click
  46. }
  47. @Override
  48. protected void runImpl()
  49. {
  50. if (Config.DEBUG)
  51. {
  52. _log.info(getType() + ": " + (_actionId == 0 ? "Simple-click" : "Shift-click") + " Target object ID: " + _objectId + " orignX: " + _originX + " orignY: " + _originY + " orignZ: " + _originZ);
  53. }
  54. // Get the current L2PcInstance of the player
  55. final L2PcInstance activeChar = getActiveChar();
  56. if (activeChar == null)
  57. {
  58. return;
  59. }
  60. if (activeChar.inObserverMode())
  61. {
  62. activeChar.sendPacket(SystemMessageId.OBSERVERS_CANNOT_PARTICIPATE);
  63. sendPacket(ActionFailed.STATIC_PACKET);
  64. return;
  65. }
  66. final BuffInfo info = activeChar.getEffectList().getBuffInfoByAbnormalType(AbnormalType.BOT_PENALTY);
  67. if (info != null)
  68. {
  69. for (AbstractEffect effect : info.getEffects())
  70. {
  71. if (!effect.checkCondition(-4))
  72. {
  73. activeChar.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REPORTED_SO_ACTIONS_NOT_ALLOWED);
  74. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  75. return;
  76. }
  77. }
  78. }
  79. final L2Object obj;
  80. if (activeChar.getTargetId() == _objectId)
  81. {
  82. obj = activeChar.getTarget();
  83. }
  84. else if (activeChar.isInAirShip() && (activeChar.getAirShip().getHelmObjectId() == _objectId))
  85. {
  86. obj = activeChar.getAirShip();
  87. }
  88. else
  89. {
  90. obj = L2World.getInstance().findObject(_objectId);
  91. }
  92. // If object requested does not exist, add warn msg into logs
  93. if (obj == null)
  94. {
  95. // pressing e.g. pickup many times quickly would get you here
  96. sendPacket(ActionFailed.STATIC_PACKET);
  97. return;
  98. }
  99. if (!obj.isTargetable() && !activeChar.canOverrideCond(PcCondOverride.TARGET_ALL))
  100. {
  101. sendPacket(ActionFailed.STATIC_PACKET);
  102. return;
  103. }
  104. // Players can't interact with objects in the other instances, except from multiverse
  105. if ((obj.getInstanceId() != activeChar.getInstanceId()) && (activeChar.getInstanceId() != -1))
  106. {
  107. sendPacket(ActionFailed.STATIC_PACKET);
  108. return;
  109. }
  110. // Only GMs can directly interact with invisible characters
  111. if (!obj.isVisibleFor(activeChar))
  112. {
  113. sendPacket(ActionFailed.STATIC_PACKET);
  114. return;
  115. }
  116. // Check if the target is valid, if the player haven't a shop or isn't the requester of a transaction (ex : FriendInvite, JoinAlly, JoinParty...)
  117. if (activeChar.getActiveRequester() != null)
  118. {
  119. // Actions prohibited when in trade
  120. sendPacket(ActionFailed.STATIC_PACKET);
  121. return;
  122. }
  123. switch (_actionId)
  124. {
  125. case 0:
  126. {
  127. obj.onAction(activeChar);
  128. break;
  129. }
  130. case 1:
  131. {
  132. if (!activeChar.isGM() && !(obj.isNpc() && Config.ALT_GAME_VIEWNPC))
  133. {
  134. obj.onAction(activeChar, false);
  135. }
  136. else
  137. {
  138. obj.onActionShift(activeChar);
  139. }
  140. break;
  141. }
  142. default:
  143. {
  144. // Invalid action detected (probably client cheating), log this
  145. _log.warning(getType() + ": Character: " + activeChar.getName() + " requested invalid action: " + _actionId);
  146. sendPacket(ActionFailed.STATIC_PACKET);
  147. break;
  148. }
  149. }
  150. }
  151. @Override
  152. protected boolean triggersOnActionRequest()
  153. {
  154. return false;
  155. }
  156. @Override
  157. public String getType()
  158. {
  159. return __C__1F_ACTION;
  160. }
  161. }