RequestDropItem.java 7.3 KB

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