/*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If
* not, see <http://www.gnu.org/licenses/>.
*/
package silentium.gameserver.network.clientpackets;
import silentium.gameserver.model.L2ItemInstance;
import silentium.gameserver.model.actor.instance.L2PcInstance;
import silentium.gameserver.network.SystemMessageId;
import silentium.gameserver.network.serverpackets.InventoryUpdate;
import silentium.gameserver.network.serverpackets.SystemMessage;
import silentium.gameserver.templates.item.L2Item;
/**
* format: cd
*/
public class RequestUnEquipItem extends L2GameClientPacket
{
private int _slot;
@Override
protected void readImpl()
{
_slot = readD();
}
@Override
protected void runImpl()
{
final L2PcInstance activeChar = getClient().getActiveChar();
if (activeChar == null)
return;
log.trace(activeChar.getName() + "requests to unequip slot: " + _slot);
L2ItemInstance item = activeChar.getInventory().getPaperdollItemByL2ItemId(_slot);
if (item == null)
return;
// Prevent of unequiping a cursed weapon
if (_slot == L2Item.SLOT_LR_HAND && activeChar.isCursedWeaponEquipped())
return;
// Prevent player from unequipping items in special conditions
if (activeChar.isStunned() || activeChar.isSleeping() || activeChar.isParalyzed() || activeChar.isAfraid() || activeChar.isAlikeDead())
{
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addItemName(item));
return;
}
if (activeChar.isCastingNow() || activeChar.isCastingSimultaneouslyNow())
return;
if (!activeChar.getInventory().canManipulateWithItemId(item.getItemId()))
return;
L2ItemInstance[] unequipped = activeChar.getInventory().unEquipItemInBodySlotAndRecord(_slot);
// show the update in the inventory
InventoryUpdate iu = new InventoryUpdate();
for (L2ItemInstance itm : unequipped)
{
L2PcInstance.cleanWeaponShots(itm);
iu.addModifiedItem(itm);
}
activeChar.sendPacket(iu);
activeChar.broadcastUserInfo();
// this can be 0 if the user pressed the right mousebutton twice very fast
if (unequipped.length > 0)
{
SystemMessage sm = null;
if (unequipped[0].getEnchantLevel() > 0)
{
sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
sm.addNumber(unequipped[0].getEnchantLevel());
sm.addItemName(unequipped[0]);
}
else
{
sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED);
sm.addItemName(unequipped[0]);
}
activeChar.sendPacket(sm);
}
}
}