Action.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.model.L2Object;
  19. import com.l2jserver.gameserver.model.L2World;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. /**
  26. * This class ...
  27. *
  28. * @version $Revision: 1.7.4.4 $ $Date: 2005/03/27 18:46:19 $
  29. */
  30. public final class Action extends L2GameClientPacket
  31. {
  32. private static final String ACTION__C__04 = "[C] 04 Action";
  33. private static final Logger _log = Logger.getLogger(Action.class.getName());
  34. // cddddc
  35. private int _objectId;
  36. @SuppressWarnings("unused")
  37. private int _originX;
  38. @SuppressWarnings("unused")
  39. private int _originY;
  40. @SuppressWarnings("unused")
  41. private int _originZ;
  42. private int _actionId;
  43. // player can select object as a target but can't interact,
  44. // or spawn protection will be removed
  45. private boolean _removeSpawnProtection = false;
  46. @Override
  47. protected void readImpl()
  48. {
  49. _objectId = readD(); // Target object Identifier
  50. _originX = readD();
  51. _originY = readD();
  52. _originZ = readD();
  53. _actionId = readC(); // Action identifier : 0-Simple click, 1-Shift click
  54. }
  55. @Override
  56. protected void runImpl()
  57. {
  58. if (Config.DEBUG)
  59. _log.fine("Action:" + _actionId);
  60. if (Config.DEBUG)
  61. _log.fine("oid:" + _objectId);
  62. // Get the current L2PcInstance of the player
  63. final L2PcInstance activeChar = getClient().getActiveChar();
  64. if (activeChar == null)
  65. return;
  66. if (activeChar.inObserverMode())
  67. {
  68. getClient().sendPacket(new SystemMessage(SystemMessageId.OBSERVERS_CANNOT_PARTICIPATE));
  69. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  70. return;
  71. }
  72. final L2Object obj;
  73. if (activeChar.getTargetId() == _objectId)
  74. {
  75. obj = activeChar.getTarget();
  76. _removeSpawnProtection = true;
  77. }
  78. else
  79. obj = L2World.getInstance().findObject(_objectId);
  80. // If object requested does not exist, add warn msg into logs
  81. if (obj == null)
  82. {
  83. // pressing e.g. pickup many times quickly would get you here
  84. // _log.warning("Character: " + activeChar.getName() + " request action with non existent ObjectID:" + _objectId);
  85. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  86. return;
  87. }
  88. // Players can't interact with objects in the other instances
  89. // except from multiverse
  90. if (obj.getInstanceId() != activeChar.getInstanceId()
  91. && activeChar.getInstanceId() != -1)
  92. {
  93. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  94. return;
  95. }
  96. // Only GMs can directly interact with invisible characters
  97. if (obj instanceof L2PcInstance
  98. && (((L2PcInstance)obj).getAppearance().getInvisible())
  99. && !activeChar.isGM())
  100. {
  101. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  102. return;
  103. }
  104. // 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...)
  105. if (activeChar.getActiveRequester() == null)
  106. {
  107. switch (_actionId)
  108. {
  109. case 0:
  110. obj.onAction(activeChar);
  111. break;
  112. case 1:
  113. if (!activeChar.isGM() && !((obj instanceof L2Npc) && Config.ALT_GAME_VIEWNPC))
  114. obj.onAction(activeChar, false);
  115. else
  116. obj.onActionShift(activeChar);
  117. break;
  118. default:
  119. // Ivalid action detected (probably client cheating), log this
  120. _log.warning("Character: " + activeChar.getName() + " requested invalid action: " + _actionId);
  121. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  122. break;
  123. }
  124. }
  125. else
  126. // Actions prohibited when in trade
  127. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  128. }
  129. @Override
  130. protected boolean triggersOnActionRequest()
  131. {
  132. return _removeSpawnProtection;
  133. }
  134. /* (non-Javadoc)
  135. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  136. */
  137. @Override
  138. public String getType()
  139. {
  140. return ACTION__C__04;
  141. }
  142. }