/*
* 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.configs.MainConfig;
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.ItemList;
import silentium.gameserver.templates.item.L2Item;
import silentium.gameserver.utils.IllegalPlayerAction;
import silentium.gameserver.utils.Util;
public final class RequestDropItem extends L2GameClientPacket
{
private int _objectId;
private int _count;
private int _x;
private int _y;
private int _z;
@Override
protected void readImpl()
{
_objectId = readD();
_count = readD();
_x = readD();
_y = readD();
_z = readD();
}
@Override
protected void runImpl()
{
final L2PcInstance activeChar = getClient().getActiveChar();
if (activeChar == null || activeChar.isDead())
return;
if (!getClient().getFloodProtectors().getDropItem().tryPerformAction("dropItem"))
return;
final L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
if (item == null || _count == 0 || !activeChar.validateItemManipulation(_objectId, "drop") || (!MainConfig.ALLOW_DISCARDITEM && !activeChar.isGM()) || !item.isDropable())
{
activeChar.sendPacket(SystemMessageId.CANNOT_DISCARD_THIS_ITEM);
return;
}
if (item.isQuestItem())
return;
if (_count > item.getCount())
{
activeChar.sendPacket(SystemMessageId.CANNOT_DISCARD_THIS_ITEM);
return;
}
if (_count < 0)
{
Util.handleIllegalPlayerAction(activeChar, "[RequestDropItem] count <= 0! ban! oid: " + _objectId + " owner: " + activeChar.getName(), IllegalPlayerAction.PUNISH_KICK);
return;
}
if (!item.isStackable() && _count > 1)
{
Util.handleIllegalPlayerAction(activeChar, "[RequestDropItem] count > 1 but item is not stackable! ban! oid: " + _objectId + " owner: " + activeChar.getName(), IllegalPlayerAction.PUNISH_KICK);
return;
}
if (!activeChar.getAccessLevel().allowTransaction())
{
activeChar.sendMessage("Transactions are disabled for your Access Level.");
activeChar.sendPacket(SystemMessageId.NOTHING_HAPPENED);
return;
}
if (activeChar.isProcessingTransaction() || activeChar.getPrivateStoreType() != 0)
{
activeChar.sendPacket(SystemMessageId.CANNOT_TRADE_DISCARD_DROP_ITEM_WHILE_IN_SHOPMODE);
return;
}
if (activeChar.isFishing())
{
// You can't mount, dismount, break and drop items while fishing
activeChar.sendPacket(SystemMessageId.CANNOT_DO_WHILE_FISHING_2);
return;
}
if (item.isAugmented())
{
activeChar.sendPacket(SystemMessageId.AUGMENTED_ITEM_CANNOT_BE_DISCARDED);
return;
}
// Cannot discard item that the skill is consumming
if (activeChar.isCastingNow())
{
if (activeChar.getCurrentSkill() != null && activeChar.getCurrentSkill().getSkill().getItemConsumeId() == item.getItemId())
{
activeChar.sendPacket(SystemMessageId.CANNOT_DISCARD_THIS_ITEM);
return;
}
}
// Cannot discard item that the skill is consuming
if (activeChar.isCastingSimultaneouslyNow())
{
if (activeChar.getLastSimultaneousSkillCast() != null && activeChar.getLastSimultaneousSkillCast().getItemConsumeId() == item.getItemId())
{
activeChar.sendPacket(SystemMessageId.CANNOT_DISCARD_THIS_ITEM);
return;
}
}
if (L2Item.TYPE2_QUEST == item.getItem().getType2() && !activeChar.isGM())
{
log.trace(activeChar.getName() + " tried to drop a quest item.");
activeChar.sendPacket(SystemMessageId.CANNOT_DISCARD_EXCHANGE_ITEM);
return;
}
if (!activeChar.isInsideRadius(_x, _y, 150, false) || Math.abs(_z - activeChar.getZ()) > 50)
{
log.trace(activeChar.getName() + " tried to drop too far away.");
activeChar.sendPacket(SystemMessageId.CANNOT_DISCARD_DISTANCE_TOO_FAR);
return;
}
log.trace("Requested drop item " + _objectId + "(" + item.getCount() + ") at " + _x + "/" + _y + "/" + _z);
if (item.isEquipped())
{
L2ItemInstance[] unequipped = activeChar.getInventory().unEquipItemInBodySlotAndRecord(item.getItem().getBodyPart());
InventoryUpdate iu = new InventoryUpdate();
for (L2ItemInstance itm : unequipped)
{
L2PcInstance.cleanWeaponShots(itm);
iu.addModifiedItem(itm);
}
activeChar.sendPacket(iu);
activeChar.broadcastUserInfo();
activeChar.sendPacket(new ItemList(activeChar, true));
}
activeChar.dropItem("Drop", _objectId, _count, _x, _y, _z, null, false, false);
log.trace("Successfully dropped " + _objectId + " item(" + _count + ") at: " + _x + " " + _y + " " + _z);
}
}