Action.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 net.sf.l2j.gameserver.clientpackets;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.model.L2Character;
  19. import net.sf.l2j.gameserver.model.L2Object;
  20. import net.sf.l2j.gameserver.model.L2World;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  23. /**
  24. * This class ...
  25. *
  26. * @version $Revision: 1.7.4.4 $ $Date: 2005/03/27 18:46:19 $
  27. */
  28. public final class Action extends L2GameClientPacket
  29. {
  30. private static final String ACTION__C__04 = "[C] 04 Action";
  31. private static Logger _log = Logger.getLogger(Action.class.getName());
  32. // cddddc
  33. private int _objectId;
  34. @SuppressWarnings("unused")
  35. private int _originX;
  36. @SuppressWarnings("unused")
  37. private int _originY;
  38. @SuppressWarnings("unused")
  39. private int _originZ;
  40. private int _actionId;
  41. @Override
  42. protected void readImpl()
  43. {
  44. _objectId = readD(); // Target object Identifier
  45. _originX = readD();
  46. _originY = readD();
  47. _originZ = readD();
  48. _actionId = readC(); // Action identifier : 0-Simple click, 1-Shift click
  49. }
  50. @Override
  51. protected void runImpl()
  52. {
  53. if (Config.DEBUG) _log.fine("Action:" + _actionId);
  54. if (Config.DEBUG) _log.fine("oid:" + _objectId);
  55. // Get the current L2PcInstance of the player
  56. L2PcInstance activeChar = getClient().getActiveChar();
  57. if (activeChar == null)
  58. return;
  59. L2Object obj;
  60. if (activeChar.getTargetId() == _objectId)
  61. obj = activeChar.getTarget();
  62. else
  63. obj = L2World.getInstance().findObject(_objectId);
  64. // If object requested does not exist, add warn msg into logs
  65. if (obj == null)
  66. {
  67. // pressing e.g. pickup many times quickly would get you here
  68. // _log.warning("Character: " + activeChar.getName() + " request action with non existent ObjectID:" + _objectId);
  69. getClient().sendPacket(new ActionFailed());
  70. return;
  71. }
  72. // 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...)
  73. if (activeChar.getPrivateStoreType()==0 && activeChar.getActiveRequester()==null)
  74. {
  75. switch (_actionId)
  76. {
  77. case 0:
  78. obj.onAction(activeChar);
  79. break;
  80. case 1:
  81. if (obj instanceof L2Character && ((L2Character)obj).isAlikeDead())
  82. obj.onAction(activeChar);
  83. else
  84. obj.onActionShift(getClient());
  85. break;
  86. default:
  87. // Ivalid action detected (probably client cheating), log this
  88. _log.warning("Character: " + activeChar.getName() + " requested invalid action: " + _actionId);
  89. getClient().sendPacket(new ActionFailed());
  90. break;
  91. }
  92. }
  93. else
  94. // Actions prohibited when in trade
  95. getClient().sendPacket(new ActionFailed());
  96. }
  97. /* (non-Javadoc)
  98. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  99. */
  100. @Override
  101. public String getType()
  102. {
  103. return ACTION__C__04;
  104. }
  105. }