import net.sf.l2j.Config;
import net.sf.l2j.gameserver.Shutdown;
import net.sf.l2j.gameserver.model.*;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.L2GameClient;
import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.serverpackets.*;
import net.sf.l2j.gameserver.templates.L2EtcItemType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.l2j.gameserver.util.IllegalPlayerAction;
import net.sf.l2j.gameserver.util.Util;
// Referenced classes of package net.sf.l2j.gameserver.clientpackets:
// L2GameClientPacket
public class SendWareHouseDepositList extends L2GameClientPacket
{
public SendWareHouseDepositList()
{
}
protected void readImpl()
{
_count = readD();
if(_count < 0 || _count * 8 > _buf.remaining() || _count > Config.MAX_ITEM_IN_PACKET)
_count = 0;
_items = new int[_count * 2];
for(int i = 0; i < _count; i++)
{
int objectId = readD();
_items[i * 2 + 0] = objectId;
long cnt = readD();
if(cnt > 0x7fffffffL || cnt < 0L)
{
_count = 0;
_items = null;
return;
}
_items[i * 2 + 1] = (int)cnt;
}
}
protected void runImpl()
{
L2PcInstance player = ((L2GameClient)getClient()).getActiveChar();
if(player == null)
return;
ItemContainer warehouse = player.getActiveWarehouse();
if(warehouse == null)
return;
net.sf.l2j.gameserver.model.actor.instance.L2FolkInstance manager = player.getLastFolkNPC();
if(Config.SAFE_REBOOT && Config.SAFE_REBOOT_DISABLE_TRANSACTION && Shutdown.getCounterInstance() != null && Shutdown.getCounterInstance().getCountdown() <= Config.SAFE_REBOOT_TIME)
{
player.sendMessage("Transactions are not allowed during restart/shutdown.");
sendPacket(new ActionFailed());
return;
}
if((manager == null || !player.isInsideRadius(manager, 150, false, false)) && !player.isGM())
return;
if((warehouse instanceof ClanWarehouse) && Config.GM_DISABLE_TRANSACTION && player.getAccessLevel() >= Config.GM_TRANSACTION_MIN && player.getAccessLevel() <= Config.GM_TRANSACTION_MAX)
{
player.sendMessage("Transactions are disabled for your access level.");
sendPacket(new ActionFailed());
return;
}
// If no or wrong channel is used - return
if (_type == SystemChatChannelId.Chat_None || _type == SystemChatChannelId.Chat_Announce || _type == SystemChatChannelId.Chat_Critical_Announce
|| _type == SystemChatChannelId.Chat_System || _type == SystemChatChannelId.Chat_Custom
|| (_type == SystemChatChannelId.Chat_GM_Pet && !activeChar.isGM()))
{
_log.warn("[Anti-Phx] Illegal chat channel was used.");
return;
}
if (activeChar == null)
{
_log.warn("[Say2.java] Active Character is null.");
return;
}
@Override
protected void runImpl()
{
L2PcInstance activeChar = getClient().getActiveChar();
}
if (player.getActiveEnchantItem() != null)
{
Util.handleIllegalPlayerAction(player,"Mofo "+player.getName()+" tried to use phx and got BANED! Peace :-h", IllegalPlayerAction.PUNISH_KICKBAN);
return;
}
// Alt game - Karma punishment
if(!Config.ALT_GAME_KARMA_PLAYER_CAN_USE_WAREHOUSE && player.getKarma() > 0)
return;
int fee = _count * 30;
int currentAdena = player.getAdena();
int slots = 0;
for(int i = 0; i < _count; i++)
{
int objectId = _items[i * 2 + 0];
int count = _items[i * 2 + 1];
L2ItemInstance item = player.checkItemManipulation(objectId, count, "deposit");
if(item == null)
{
_log.warn((new StringBuilder()).append("Error depositing a warehouse object for char ").append(player.getName()).append(" (validity check)").toString());
_items[i * 2 + 0] = 0;
_items[i * 2 + 1] = 0;
continue;
}
if(Config.ALT_STRICT_HERO_SYSTEM && item.isHeroitem())
continue;
if((warehouse instanceof ClanWarehouse) && !item.isTradeable() || item.getItemType() == L2EtcItemType.QUEST)
return;
if(item.getItemId() == 57)
currentAdena -= count;
if(!item.isStackable())
{
slots += count;
continue;
}
if(warehouse.getItemByItemId(item.getItemId()) == null)
slots++;
}
if(!warehouse.validateCapacity(slots))
{
sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
return;
}
if(currentAdena < fee || !player.reduceAdena("Warehouse", fee, player.getLastFolkNPC(), false))
{
sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
return;
}
InventoryUpdate playerIU = Config.FORCE_INVENTORY_UPDATE ? null : new InventoryUpdate();
for(int i = 0; i < _count; i++)
{
int objectId = _items[i * 2 + 0];
int count = _items[i * 2 + 1];
if(objectId == 0 && count == 0)
continue;
L2ItemInstance oldItem = player.getInventory().getItemByObjectId(objectId);
if(oldItem == null)
{
_log.warn((new StringBuilder()).append("Error depositing a warehouse object for char ").append(player.getName()).append(" (olditem == null)").toString());
continue;
}
if(Config.ALT_STRICT_HERO_SYSTEM && oldItem.isHeroitem())
continue;
L2ItemInstance newItem = player.getInventory().transferItem((warehouse instanceof ClanWarehouse) ? "ClanWarehouse" : "Warehouse", objectId, count, warehouse, player, player.getLastFolkNPC());
if(newItem == null)
{
_log.warn((new StringBuilder()).append("Error depositing a warehouse object for char ").append(player.getName()).append(" (newitem == null)").toString());
continue;
}
if(playerIU == null)
continue;
if(oldItem.getCount() > 0 && oldItem != newItem)
playerIU.addModifiedItem(oldItem);
else
playerIU.addRemovedItem(oldItem);
}
if(playerIU != null)
player.sendPacket(playerIU);
else
player.sendPacket(new ItemList(player, false));
StatusUpdate su = new StatusUpdate(player.getObjectId());
su.addAttribute(14, player.getCurrentLoad());
player.sendPacket(su);
}
public String getType()
{
return "[C] 31 SendWareHouseDepositList";
}
private static final String _C__31_SENDWAREHOUSEDEPOSITLIST = "[C] 31 SendWareHouseDepositList";
private static final Log _log = LogFactory.getLog(net/sf/l2j/gameserver/clientpackets/SendWareHouseDepositList.getName());
private int _count;
private int _items[];
}