Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 com.dream.game.network.clientpackets;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import com.dream.Config;
- import com.dream.game.model.ItemRequest;
- import com.dream.game.model.TradeList;
- import com.dream.game.model.actor.instance.L2PcInstance;
- import com.dream.game.model.world.L2World;
- import com.dream.game.taskmanager.OfflineManager;
- import com.dream.game.util.Util;
- public final class RequestPrivateStoreBuy extends L2GameClientPacket
- {
- private static final String _C__79_REQUESTPRIVATESTOREBUY = "[C] 79 RequestPrivateStoreBuy";
- private static final int BATCH_LENGTH = 12; // length of one item
- private int _storePlayerId;
- private Set<ItemRequest> _items = null;
- private List<int[]> _buffs = null;
- @Override
- protected void readImpl()
- {
- _storePlayerId = readD();
- int count = readD();
- if ((count <= 0) || (count > Config.MAX_ITEM_IN_PACKET) || ((count * BATCH_LENGTH) != _buf.remaining()))
- {
- return;
- }
- _items = new HashSet<>();
- _buffs = new ArrayList<>();
- for (int i = 0; i < count; i++)
- {
- int objectId = readD();
- long cnt = readD();
- int price = readD();
- if ((objectId < 1) || (cnt < 1) || (price < 0))
- {
- _items = null;
- return;
- }
- _items.add(new ItemRequest(objectId, (int) cnt, price));
- _buffs.add(new int[]
- {
- objectId,
- price
- });
- }
- }
- @Override
- protected void runImpl()
- {
- L2PcInstance player = getClient().getActiveChar();
- if (player == null)
- {
- return;
- }
- if (_items == null)
- {
- return;
- }
- L2PcInstance storePlayer = L2World.getInstance().getPlayer(_storePlayerId);
- if (storePlayer == null)
- {
- return;
- }
- if (player.isCursedWeaponEquipped())
- {
- return;
- }
- if (!player.isInsideRadius(storePlayer, 150, true, false))
- {
- return;
- }
- if (storePlayer.isBizy())
- {
- BuffShopManager.getInstance().broadcastBizy(storePlayer, player);
- return;
- }
- if (!((storePlayer.getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_SELL) || (storePlayer.getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_PACKAGE_SELL)))
- {
- return;
- }
- TradeList storeList = storePlayer.getSellList();
- if (storeList == null)
- {
- return;
- }
- Map<Integer, int[]> sellList = storePlayer.getBuffShopSellList();
- if ((storePlayer.isBuffShop()) && (sellList == null))
- {
- return;
- }
- if (storePlayer.getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_PACKAGE_SELL)
- {
- if (storeList.getItemCount() > _items.size())
- {
- Util.handleIllegalPlayerAction(getClient().getActiveChar(), "[RequestPrivateStoreBuy] " + player.getName() + " tried to buy less items than sold in package.", Config.DEFAULT_PUNISH);
- return;
- }
- }
- if (storePlayer.isBuffShop())
- {
- BuffShopManager.getInstance().processBuffs(storePlayer, player, _buffs);
- return;
- }
- if (storeList.getItemCount() == 0)
- {
- storePlayer.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_NONE);
- storePlayer.broadcastUserInfo();
- if (storePlayer.isOfflineTrade())
- {
- OfflineManager.getInstance().removeTrader(storePlayer);
- }
- }
- }
- @Override
- public String getType()
- {
- return _C__79_REQUESTPRIVATESTOREBUY;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement