📄 c_shop.java
字号:
/*
* 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 2, 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package l1j.server.server.clientpackets;
import java.util.ArrayList;
import java.util.logging.Logger;
import l1j.server.server.ActionCodes;
import l1j.server.server.ClientThread;
import l1j.server.server.model.L1World;
import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.model.Instance.L1PetInstance;
import l1j.server.server.serverpackets.S_DoActionGFX;
import l1j.server.server.serverpackets.S_DoActionShop;
import l1j.server.server.serverpackets.S_ServerMessage;
import l1j.server.server.templates.L1PrivateShopBuyList;
import l1j.server.server.templates.L1PrivateShopSellList;
// Referenced classes of package l1j.server.server.clientpackets:
// ClientBasePacket
public class C_Shop extends ClientBasePacket {
private static final String C_SHOP = "[C] C_Shop";
private static l1j.eric.EricLogger _log = l1j.eric.EricLogger.getLogger2(C_Shop.class.getName());
public C_Shop(byte abyte0[], ClientThread clientthread) {
super(abyte0);
L1PcInstance pc = clientthread.getActiveChar();
if (pc.isGhost()) {
return;
}
int mapId = pc.getMapId();
if (mapId != 340 && mapId != 350 && mapId != 360 && mapId != 370) {
pc.sendPackets(new S_ServerMessage(876)); // この場所では個人商店を開けません。
return;
}
ArrayList sellList = pc.getSellList();
ArrayList buyList = pc.getBuyList();
L1ItemInstance checkItem;
boolean tradable = true;
int type = readC();
if (type == 0) { // 開始
int sellTotalCount = readH();
int sellObjectId;
int sellPrice;
int sellCount;
for (int i = 0; i < sellTotalCount; i++) {
sellObjectId = readD();
sellPrice = readD();
sellCount = readD();
// 取引可能なアイテムかチェック
checkItem = pc.getInventory().getItem(sellObjectId);
if (!checkItem.getItem().isTradable()) {
tradable = false;
pc.sendPackets(new S_ServerMessage(166, // \f1%0が%4%1%3%2
checkItem.getItem().getName(), " 無法交易。"));
}
Object[] petlist = pc.getPetList().values().toArray();
for (Object petObject : petlist) {
if (petObject instanceof L1PetInstance) {
L1PetInstance pet = (L1PetInstance) petObject;
if (checkItem.getId() == pet.getItemObjId()) {
tradable = false;
pc.sendPackets(new S_ServerMessage(166, // \f1%0が%4%1%3%2
checkItem.getItem().getName(),
" 無法交易。"));
break;
}
}
}
L1PrivateShopSellList pssl = new L1PrivateShopSellList();
pssl.setItemObjectId(sellObjectId);
pssl.setSellPrice(sellPrice);
pssl.setSellTotalCount(sellCount);
sellList.add(pssl);
}
int buyTotalCount = readH();
int buyObjectId;
int buyPrice;
int buyCount;
for (int i = 0; i < buyTotalCount; i++) {
buyObjectId = readD();
buyPrice = readD();
buyCount = readD();
// 取引可能なアイテムかチェック
checkItem = pc.getInventory().getItem(buyObjectId);
if (!checkItem.getItem().isTradable()) {
tradable = false;
pc.sendPackets(new S_ServerMessage(166, // \f1%0が%4%1%3%2
checkItem.getItem().getName(), " 無法交易。"));
}
Object[] petlist = pc.getPetList().values().toArray();
for (Object petObject : petlist) {
if (petObject instanceof L1PetInstance) {
L1PetInstance pet = (L1PetInstance) petObject;
if (checkItem.getId() == pet.getItemObjId()) {
tradable = false;
pc.sendPackets(new S_ServerMessage(166, // \f1%0が%4%1%3%2
checkItem.getItem().getName(),
" 無法交易。"));
break;
}
}
}
L1PrivateShopBuyList psbl = new L1PrivateShopBuyList();
psbl.setItemObjectId(buyObjectId);
psbl.setBuyPrice(buyPrice);
psbl.setBuyTotalCount(buyCount);
buyList.add(psbl);
}
if (!tradable) { // 取引不可能なアイテムが含まれている場合、個人商店終了
sellList.clear();
buyList.clear();
pc.setPrivateShop(false);
pc.sendPackets(new S_DoActionGFX(pc.getId(),
ActionCodes.ACTION_Idle));
pc.broadcastPacket(new S_DoActionGFX(pc.getId(),
ActionCodes.ACTION_Idle));
return;
}
byte[] chat = readByte();
pc.setShopChat(chat);
pc.setPrivateShop(true);
pc.sendPackets(new S_DoActionShop(pc.getId(),
ActionCodes.ACTION_Shop, chat));
pc.broadcastPacket(new S_DoActionShop(pc.getId(),
ActionCodes.ACTION_Shop, chat));
} else if (type == 1) { // 終了
sellList.clear();
buyList.clear();
pc.setPrivateShop(false);
pc.sendPackets(new S_DoActionGFX(pc.getId(),
ActionCodes.ACTION_Idle));
pc.broadcastPacket(new S_DoActionGFX(pc.getId(),
ActionCodes.ACTION_Idle));
}
}
@Override
public String getType() {
return C_SHOP;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -