Action.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. @Override
  44. protected void readImpl()
  45. {
  46. _objectId = readD(); // Target object Identifier
  47. _originX = readD();
  48. _originY = readD();
  49. _originZ = readD();
  50. _actionId = readC(); // Action identifier : 0-Simple click, 1-Shift click
  51. }
  52. @Override
  53. protected void runImpl()
  54. {
  55. if (Config.DEBUG)
  56. _log.fine("Action:" + _actionId);
  57. if (Config.DEBUG)
  58. _log.fine("oid:" + _objectId);
  59. // Get the current L2PcInstance of the player
  60. final L2PcInstance activeChar = getClient().getActiveChar();
  61. if (activeChar == null)
  62. return;
  63. if (activeChar.inObserverMode())
  64. {
  65. getClient().sendPacket(SystemMessage.getSystemMessage(SystemMessageId.OBSERVERS_CANNOT_PARTICIPATE));
  66. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  67. return;
  68. }
  69. final L2Object obj;
  70. if (activeChar.getTargetId() == _objectId)
  71. obj = activeChar.getTarget();
  72. else if (activeChar.isInAirShip()
  73. && activeChar.getAirShip().getHelmObjectId() == _objectId)
  74. obj = activeChar.getAirShip();
  75. else
  76. obj = L2World.getInstance().findObject(_objectId);
  77. // If object requested does not exist, add warn msg into logs
  78. if (obj == null)
  79. {
  80. // pressing e.g. pickup many times quickly would get you here
  81. // _log.warning("Character: " + activeChar.getName() + " request action with non existent ObjectID:" + _objectId);
  82. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  83. return;
  84. }
  85. // Players can't interact with objects in the other instances
  86. // except from multiverse
  87. if (obj.getInstanceId() != activeChar.getInstanceId()
  88. && activeChar.getInstanceId() != -1)
  89. {
  90. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  91. return;
  92. }
  93. // Only GMs can directly interact with invisible characters
  94. if (obj instanceof L2PcInstance
  95. && (((L2PcInstance)obj).getAppearance().getInvisible())
  96. && !activeChar.isGM())
  97. {
  98. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  99. return;
  100. }
  101. // 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...)
  102. if (activeChar.getActiveRequester() == null)
  103. {
  104. switch (_actionId)
  105. {
  106. case 0:
  107. obj.onAction(activeChar);
  108. break;
  109. case 1:
  110. if (!activeChar.isGM() && !((obj instanceof L2Npc) && Config.ALT_GAME_VIEWNPC))
  111. obj.onAction(activeChar, false);
  112. else
  113. obj.onActionShift(activeChar);
  114. break;
  115. default:
  116. // Ivalid action detected (probably client cheating), log this
  117. _log.warning("Character: " + activeChar.getName() + " requested invalid action: " + _actionId);
  118. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  119. break;
  120. }
  121. }
  122. else
  123. // Actions prohibited when in trade
  124. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  125. }
  126. /* (non-Javadoc)
  127. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  128. */
  129. @Override
  130. public String getType()
  131. {
  132. return ACTION__C__04;
  133. }
  134. }