Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SellList.Java
- /*
- * Copyright (C) 2004-2015 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server 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.
- *
- * L2J Server 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 l2r.gameserver.network.serverpackets;
- import java.util.ArrayList;
- import java.util.List;
- import l2r.gameserver.model.actor.instance.L2MerchantInstance;
- import l2r.gameserver.model.actor.instance.L2PcInstance;
- import l2r.gameserver.model.items.instance.L2ItemInstance;
- public class SellList extends L2GameServerPacket
- {
- private final L2PcInstance _activeChar;
- private final L2MerchantInstance _lease;
- private final long _money;
- private final List<L2ItemInstance> _selllist = new ArrayList<>();
- public SellList(L2PcInstance player)
- {
- _activeChar = player;
- _lease = null;
- _money = _activeChar.getAdena();
- doLease();
- }
- public SellList(L2PcInstance player, L2MerchantInstance lease)
- {
- _activeChar = player;
- _lease = lease;
- _money = _activeChar.getAdena();
- doLease();
- }
- private void doLease()
- {
- if (_lease == null)
- {
- for (L2ItemInstance item : _activeChar.getInventory().getItems())
- {
- if (!item.isEquipped() && item.isSellable() && (!_activeChar.hasSummon() || (item.getObjectId() != _activeChar.getSummon().getControlObjectId()))) // Pet is summoned and not the item that summoned the pet
- {
- _selllist.add(item);
- }
- }
- }
- }
- @Override
- protected final void writeImpl()
- {
- writeC(0x06);
- writeQ(_money);
- writeD(_lease == null ? 0x00 : 1000000 + _lease.getTemplate().getId());
- writeH(_selllist.size());
- for (L2ItemInstance item : _selllist)
- {
- writeH(item.getItem().getType1());
- writeD(item.getObjectId());
- writeD(item.getDisplayId());
- writeQ(item.getCount());
- writeH(item.getItem().getType2());
- writeH(item.isEquipped() ? 0x01 : 0x00);
- writeD(item.getItem().getBodyPart());
- writeH(item.getEnchantLevel());
- writeH(0x00); // TODO: Verify me
- writeH(item.getCustomType2());
- writeQ(1);
- // T1
- writeH(item.getAttackElementType());
- writeH(item.getAttackElementPower());
- for (byte i = 0; i < 6; i++)
- {
- writeH(item.getElementDefAttr(i));
- }
- // Enchant Effects
- for (int op : item.getEnchantOptions())
- {
- writeH(op);
- }
- }
- }
- }
- RequestSellItem.java
- /*
- * Copyright (C) 2004-2015 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server 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.
- *
- * L2J Server 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 l2r.gameserver.network.clientpackets;
- import static l2r.gameserver.model.actor.L2Npc.INTERACTION_DISTANCE;
- import static l2r.gameserver.model.itemcontainer.Inventory.MAX_ADENA;
- import java.util.ArrayList;
- import java.util.List;
- import l2r.Config;
- import l2r.gameserver.data.xml.impl.BuyListData;
- import l2r.gameserver.model.L2Object;
- import l2r.gameserver.model.actor.L2Character;
- import l2r.gameserver.model.actor.instance.L2MerchantInstance;
- import l2r.gameserver.model.actor.instance.L2PcInstance;
- import l2r.gameserver.model.buylist.L2BuyList;
- import l2r.gameserver.model.holders.UniqueItemHolder;
- import l2r.gameserver.model.items.instance.L2ItemInstance;
- import l2r.gameserver.network.serverpackets.ActionFailed;
- import l2r.gameserver.network.serverpackets.ExBuySellList;
- import l2r.gameserver.network.serverpackets.StatusUpdate;
- import l2r.gameserver.util.Util;
- /**
- * RequestSellItem client packet class.
- */
- public final class RequestSellItem extends L2GameClientPacket
- {
- private static final String _C__37_REQUESTSELLITEM = "[C] 37 RequestSellItem";
- private static final int BATCH_LENGTH = 16;
- private int _listId;
- private List<UniqueItemHolder> _items = null;
- @Override
- protected void readImpl()
- {
- _listId = readD();
- int size = readD();
- if ((size <= 0) || (size > Config.MAX_ITEM_IN_PACKET) || ((size * BATCH_LENGTH) != _buf.remaining()))
- {
- return;
- }
- _items = new ArrayList<>(size);
- for (int i = 0; i < size; i++)
- {
- int objectId = readD();
- int itemId = readD();
- long count = readQ();
- if ((objectId < 1) || (itemId < 1) || (count < 1))
- {
- _items = null;
- return;
- }
- _items.add(new UniqueItemHolder(itemId, objectId, count));
- }
- }
- @Override
- protected void runImpl()
- {
- processSell();
- }
- protected void processSell()
- {
- L2PcInstance player = getClient().getActiveChar();
- if (player == null)
- {
- return;
- }
- if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("buy"))
- {
- player.sendMessage("You are buying too fast.");
- return;
- }
- if (_items == null)
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- // Alt game - Karma punishment
- if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && (player.getKarma() > 0))
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- L2Object target = player.getTarget();
- L2Character merchant = null;
- if (!player.isGM() && !player.isAioMultisell())
- {
- if ((target == null) || (!player.isInsideRadius(target, INTERACTION_DISTANCE, true, false)) // Distance is too far)
- || (player.getInstanceId() != target.getInstanceId()))
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- if (target instanceof L2MerchantInstance)
- {
- merchant = (L2Character) target;
- }
- else
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- }
- double taxRate = 0;
- if (_listId != -1)
- {
- final L2BuyList buyList = BuyListData.getInstance().getBuyList(_listId);
- if ((buyList == null))
- {
- Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId, Config.DEFAULT_PUNISH);
- return;
- }
- if ((merchant != null))
- {
- if (merchant instanceof L2MerchantInstance)
- {
- if (!buyList.isNpcAllowed(((L2MerchantInstance) merchant).getId()))
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- }
- }
- }
- long totalPrice = 0;
- // Proceed the sell
- for (UniqueItemHolder i : _items)
- {
- L2ItemInstance item = player.checkItemManipulation(i.getObjectId(), i.getCount(), "sell");
- if ((item == null) || (!item.isSellable()))
- {
- continue;
- }
- long price = item.getReferencePrice() / 1;
- totalPrice += price * i.getCount();
- if (((MAX_ADENA / i.getCount()) < price) || (totalPrice > MAX_ADENA))
- {
- Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + MAX_ADENA + " adena worth of goods.", Config.DEFAULT_PUNISH);
- return;
- }
- if (Config.ALLOW_REFUND)
- {
- item = player.getInventory().transferItem("Sell", i.getObjectId(), i.getCount(), player.getRefund(), player, merchant);
- }
- else
- {
- item = player.getInventory().destroyItem("Sell", i.getObjectId(), i.getCount(), player, merchant);
- }
- }
- player.addAdena("Sell", 1, merchant, false);
- // Update current load as well
- StatusUpdate su = player.makeStatusUpdate(StatusUpdate.CUR_LOAD);
- player.sendPacket(su);
- player.sendPacket(new ExBuySellList(player, taxRate, true));
- }
- @Override
- public String getType()
- {
- return _C__37_REQUESTSELLITEM;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement