RequestDropItem.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.GmListTable;
  19. import com.l2jserver.gameserver.model.L2ItemInstance;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  23. import com.l2jserver.gameserver.network.serverpackets.ItemList;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. import com.l2jserver.gameserver.templates.item.L2EtcItemType;
  26. import com.l2jserver.gameserver.templates.item.L2Item;
  27. import com.l2jserver.gameserver.util.GMAudit;
  28. import com.l2jserver.gameserver.util.Util;
  29. /**
  30. * This class ...
  31. *
  32. * @version $Revision: 1.11.2.1.2.7 $ $Date: 2005/04/02 21:25:21 $
  33. */
  34. public final class RequestDropItem extends L2GameClientPacket
  35. {
  36. private static final String _C__12_REQUESTDROPITEM = "[C] 12 RequestDropItem";
  37. private static Logger _log = Logger.getLogger(RequestDropItem.class.getName());
  38. private int _objectId;
  39. private long _count;
  40. private int _x;
  41. private int _y;
  42. private int _z;
  43. @Override
  44. protected void readImpl()
  45. {
  46. _objectId = readD();
  47. _count = readQ();
  48. _x = readD();
  49. _y = readD();
  50. _z = readD();
  51. }
  52. @Override
  53. protected void runImpl()
  54. {
  55. L2PcInstance activeChar = getClient().getActiveChar();
  56. if (activeChar == null || activeChar.isDead())
  57. return;
  58. // Flood protect drop to avoid packet lag
  59. if (!getClient().getFloodProtectors().getDropItem().tryPerformAction("drop item"))
  60. return;
  61. L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
  62. if (item == null
  63. || _count == 0
  64. || !activeChar.validateItemManipulation(_objectId, "drop")
  65. || (!Config.ALLOW_DISCARDITEM && !activeChar.isGM())
  66. || (!item.isDropable() && !(activeChar.isGM() && Config.GM_TRADE_RESTRICTED_ITEMS)))
  67. {
  68. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISCARD_THIS_ITEM));
  69. return;
  70. }
  71. if (item.getItemType() == L2EtcItemType.QUEST && !(activeChar.isGM() && Config.GM_TRADE_RESTRICTED_ITEMS))
  72. {
  73. return;
  74. }
  75. if (_count > item.getCount())
  76. {
  77. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISCARD_THIS_ITEM));
  78. return;
  79. }
  80. if (Config.PLAYER_SPAWN_PROTECTION > 0 && activeChar.isInvul() && !activeChar.isGM())
  81. {
  82. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISCARD_THIS_ITEM));
  83. return;
  84. }
  85. if (_count < 0)
  86. {
  87. Util.handleIllegalPlayerAction(activeChar, "[RequestDropItem] Character " + activeChar.getName() + " of account " + activeChar.getAccountName() + " tried to drop item with oid " + _objectId + " but has count < 0!", Config.DEFAULT_PUNISH);
  88. return;
  89. }
  90. if (!item.isStackable() && _count > 1)
  91. {
  92. Util.handleIllegalPlayerAction(activeChar, "[RequestDropItem] Character " + activeChar.getName() + " of account " + activeChar.getAccountName() + " tried to drop non-stackable item with oid " + _objectId + " but has count > 1!", Config.DEFAULT_PUNISH);
  93. return;
  94. }
  95. if (Config.JAIL_DISABLE_TRANSACTION && activeChar.isInJail())
  96. {
  97. activeChar.sendMessage("You cannot drop items in Jail.");
  98. return;
  99. }
  100. if (!activeChar.getAccessLevel().allowTransaction())
  101. {
  102. activeChar.sendMessage("Transactions are disable for your Access Level");
  103. activeChar.sendPacket(new SystemMessage(SystemMessageId.NOTHING_HAPPENED));
  104. return;
  105. }
  106. if (activeChar.isProcessingTransaction() || activeChar.getPrivateStoreType() != 0)
  107. {
  108. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_TRADE_DISCARD_DROP_ITEM_WHILE_IN_SHOPMODE));
  109. return;
  110. }
  111. if (activeChar.isFishing())
  112. {
  113. //You can't mount, dismount, break and drop items while fishing
  114. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DO_WHILE_FISHING_2));
  115. return;
  116. }
  117. if (activeChar.isFlying())
  118. {
  119. return;
  120. }
  121. // Cannot discard item that the skill is consuming
  122. if (activeChar.isCastingNow())
  123. {
  124. if (activeChar.getCurrentSkill() != null && activeChar.getCurrentSkill().getSkill().getItemConsumeId() == item.getItemId())
  125. {
  126. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISCARD_THIS_ITEM));
  127. return;
  128. }
  129. }
  130. // Cannot discard item that the skill is consuming
  131. if (activeChar.isCastingSimultaneouslyNow())
  132. {
  133. if (activeChar.getLastSimultaneousSkillCast() != null && activeChar.getLastSimultaneousSkillCast().getItemConsumeId() == item.getItemId())
  134. {
  135. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISCARD_THIS_ITEM));
  136. return;
  137. }
  138. }
  139. if (L2Item.TYPE2_QUEST == item.getItem().getType2() && !activeChar.isGM())
  140. {
  141. if (Config.DEBUG)
  142. _log.finest(activeChar.getObjectId() + ":player tried to drop quest item");
  143. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISCARD_EXCHANGE_ITEM));
  144. return;
  145. }
  146. if (!activeChar.isInsideRadius(_x, _y, 150, false) || Math.abs(_z - activeChar.getZ()) > 50)
  147. {
  148. if (Config.DEBUG)
  149. _log.finest(activeChar.getObjectId() + ": trying to drop too far away");
  150. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISCARD_DISTANCE_TOO_FAR));
  151. return;
  152. }
  153. if (Config.DEBUG)
  154. _log.fine("requested drop item " + _objectId + "(" + item.getCount() + ") at " + _x + "/" + _y + "/" + _z);
  155. if (item.isEquipped())
  156. {
  157. L2ItemInstance[] unequiped = activeChar.getInventory().unEquipItemInBodySlotAndRecord(item.getItem().getBodyPart());
  158. InventoryUpdate iu = new InventoryUpdate();
  159. for (L2ItemInstance itm : unequiped)
  160. {
  161. activeChar.checkSShotsMatch(null, itm);
  162. iu.addModifiedItem(itm);
  163. }
  164. activeChar.sendPacket(iu);
  165. activeChar.broadcastUserInfo();
  166. ItemList il = new ItemList(activeChar, true);
  167. activeChar.sendPacket(il);
  168. }
  169. L2ItemInstance dropedItem = activeChar.dropItem("Drop", _objectId, _count, _x, _y, _z, null, false);
  170. if (Config.DEBUG)
  171. _log.fine("dropping " + _objectId + " item(" + _count + ") at: " + _x + " " + _y + " " + _z);
  172. // activeChar.broadcastUserInfo();
  173. if (activeChar.isGM())
  174. {
  175. String target = (activeChar.getTarget() != null ? activeChar.getTarget().getName() : "no-target");
  176. GMAudit.auditGMAction(activeChar.getName()+" ["+activeChar.getObjectId()+"]",
  177. "Drop", target, "(id: " + dropedItem.getItemId() + " name: " + dropedItem.getItemName() + " objId: " + dropedItem.getObjectId()
  178. + " x: " + activeChar.getX() + " y: " + activeChar.getY() + " z: " + activeChar.getZ() + ")");
  179. }
  180. if (dropedItem != null && dropedItem.getItemId() == 57 && dropedItem.getCount() >= 1000000)
  181. {
  182. String msg = "Character (" + activeChar.getName() + ") has dropped (" + dropedItem.getCount() + ")adena at (" + _x + "," + _y + "," + _z + ")";
  183. _log.warning(msg);
  184. GmListTable.broadcastMessageToGMs(msg);
  185. }
  186. }
  187. /* (non-Javadoc)
  188. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  189. */
  190. @Override
  191. public String getType()
  192. {
  193. return _C__12_REQUESTDROPITEM;
  194. }
  195. @Override
  196. protected boolean triggersOnActionRequest()
  197. {
  198. return false;
  199. }
  200. }