RequestDropItem.java 8.2 KB

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