RequestUnEquipItem.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 java.util.Arrays;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.model.PcCondOverride;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.items.L2EtcItem;
  25. import com.l2jserver.gameserver.model.items.L2Item;
  26. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. /**
  31. * @author Zoey76
  32. */
  33. public class RequestUnEquipItem extends L2GameClientPacket
  34. {
  35. private static final String _C__16_REQUESTUNEQUIPITEM = "[C] 16 RequestUnequipItem";
  36. private int _slot;
  37. /**
  38. * Packet type id 0x16 format: cd
  39. */
  40. @Override
  41. protected void readImpl()
  42. {
  43. _slot = readD();
  44. }
  45. @Override
  46. protected void runImpl()
  47. {
  48. if (Config.DEBUG)
  49. {
  50. _log.fine("Request unequip slot " + _slot);
  51. }
  52. final L2PcInstance activeChar = getClient().getActiveChar();
  53. if (activeChar == null)
  54. {
  55. return;
  56. }
  57. final L2ItemInstance item = activeChar.getInventory().getPaperdollItemByL2ItemId(_slot);
  58. // Wear-items are not to be unequipped.
  59. if (item == null)
  60. {
  61. return;
  62. }
  63. // The English system message say weapon, but it's applied to any equipped item.
  64. if (activeChar.isAttackingNow() || activeChar.isCastingNow() || activeChar.isCastingSimultaneouslyNow())
  65. {
  66. activeChar.sendPacket(SystemMessageId.CANNOT_CHANGE_WEAPON_DURING_AN_ATTACK);
  67. return;
  68. }
  69. // Arrows and bolts.
  70. if ((_slot == L2Item.SLOT_L_HAND) && (item.getItem() instanceof L2EtcItem))
  71. {
  72. return;
  73. }
  74. // Prevent of unequipping a cursed weapon.
  75. if ((_slot == L2Item.SLOT_LR_HAND) && (activeChar.isCursedWeaponEquipped() || activeChar.isCombatFlagEquipped()))
  76. {
  77. return;
  78. }
  79. // Prevent player from unequipping items in special conditions.
  80. if (activeChar.isStunned() || activeChar.isSleeping() || activeChar.isParalyzed() || activeChar.isAlikeDead())
  81. {
  82. return;
  83. }
  84. if (!activeChar.getInventory().canManipulateWithItemId(item.getId()))
  85. {
  86. activeChar.sendPacket(SystemMessageId.ITEM_CANNOT_BE_TAKEN_OFF);
  87. return;
  88. }
  89. if (item.isWeapon() && item.getWeaponItem().isForceEquip() && !activeChar.canOverrideCond(PcCondOverride.ITEM_CONDITIONS))
  90. {
  91. activeChar.sendPacket(SystemMessageId.ITEM_CANNOT_BE_TAKEN_OFF);
  92. return;
  93. }
  94. final L2ItemInstance[] unequipped = activeChar.getInventory().unEquipItemInBodySlotAndRecord(_slot);
  95. activeChar.broadcastUserInfo();
  96. // This can be 0 if the user pressed the right mouse button twice very fast.
  97. if (unequipped.length > 0)
  98. {
  99. SystemMessage sm = null;
  100. if (unequipped[0].getEnchantLevel() > 0)
  101. {
  102. sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
  103. sm.addInt(unequipped[0].getEnchantLevel());
  104. }
  105. else
  106. {
  107. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED);
  108. }
  109. sm.addItemName(unequipped[0]);
  110. activeChar.sendPacket(sm);
  111. InventoryUpdate iu = new InventoryUpdate();
  112. iu.addItems(Arrays.asList(unequipped));
  113. activeChar.sendPacket(iu);
  114. }
  115. }
  116. @Override
  117. public String getType()
  118. {
  119. return _C__16_REQUESTUNEQUIPITEM;
  120. }
  121. }