RequestDropItem.java 8.3 KB

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