RequestUnEquipItem.java 4.0 KB

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