RequestUnEquipItem.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.model.L2ItemInstance;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  22. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  23. import com.l2jserver.gameserver.templates.item.L2EtcItem;
  24. import com.l2jserver.gameserver.templates.item.L2Item;
  25. /**
  26. * This class ...
  27. *
  28. * @version $Revision: 1.8.2.3.2.7 $ $Date: 2005/03/27 15:29:30 $
  29. */
  30. public class RequestUnEquipItem extends L2GameClientPacket
  31. {
  32. private static final String _C__11_REQUESTUNEQUIPITEM = "[C] 11 RequestUnequipItem";
  33. private static Logger _log = Logger.getLogger(RequestUnEquipItem.class.getName());
  34. // cd
  35. private int _slot;
  36. /**
  37. * packet type id 0x11
  38. * format: cd
  39. * @param decrypt
  40. */
  41. @Override
  42. protected void readImpl()
  43. {
  44. _slot = readD();
  45. }
  46. @Override
  47. protected void runImpl()
  48. {
  49. if (Config.DEBUG)
  50. _log.fine("request unequip slot " + _slot);
  51. L2PcInstance activeChar = getClient().getActiveChar();
  52. if (activeChar == null)
  53. return;
  54. L2ItemInstance item = activeChar.getInventory().getPaperdollItemByL2ItemId(_slot);
  55. if (item == null)
  56. {
  57. // Wear-items are not to be unequipped
  58. return;
  59. }
  60. // Prevent of unequiping a cursed weapon
  61. if (_slot == L2Item.SLOT_LR_HAND && (activeChar.isCursedWeaponEquipped() || activeChar.isCombatFlagEquipped()))
  62. {
  63. // Message ?
  64. return;
  65. }
  66. // arrows and bolts
  67. if (_slot == L2Item.SLOT_L_HAND && item.getItem() instanceof L2EtcItem)
  68. {
  69. // Message ?
  70. return;
  71. }
  72. // Prevent player from unequipping items in special conditions
  73. if (activeChar.isStunned() || activeChar.isSleeping()
  74. || activeChar.isParalyzed() || activeChar.isAlikeDead())
  75. {
  76. activeChar.sendMessage("Your status does not allow you to do that.");
  77. return;
  78. }
  79. if (activeChar.isCastingNow() || activeChar.isCastingSimultaneouslyNow())
  80. return;
  81. if (!activeChar.getInventory().canManipulateWithItemId(item.getItemId()))
  82. {
  83. activeChar.sendMessage("Cannot use this item.");
  84. return;
  85. }
  86. L2ItemInstance[] unequiped =
  87. activeChar.getInventory().unEquipItemInBodySlotAndRecord(_slot);
  88. // show the update in the inventory
  89. InventoryUpdate iu = new InventoryUpdate();
  90. for (L2ItemInstance itm: unequiped)
  91. {
  92. activeChar.checkSShotsMatch(null, itm);
  93. iu.addModifiedItem(itm);
  94. }
  95. activeChar.sendPacket(iu);
  96. // On retail you don't stop hitting if unequip something. REOMVED: activeChar.abortAttack();
  97. activeChar.broadcastUserInfo();
  98. // this can be 0 if the user pressed the right mousebutton twice very fast
  99. if (unequiped.length > 0)
  100. {
  101. SystemMessage sm = null;
  102. if (unequiped[0].getEnchantLevel() > 0)
  103. {
  104. sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
  105. sm.addNumber(unequiped[0].getEnchantLevel());
  106. sm.addItemName(unequiped[0]);
  107. }
  108. else
  109. {
  110. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED);
  111. sm.addItemName(unequiped[0]);
  112. }
  113. activeChar.sendPacket(sm);
  114. sm = null;
  115. }
  116. }
  117. /* (non-Javadoc)
  118. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  119. */
  120. @Override
  121. public String getType()
  122. {
  123. return _C__11_REQUESTUNEQUIPITEM;
  124. }
  125. }