shoptable.java
以下原始碼,請自己核對一下
package l1j.server.server.datatables;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import l1j.server.L1DatabaseFactory;
import l1j.server.server.model.shop.L1Shop;
import l1j.server.server.templates.L1ShopItem;
import l1j.server.server.utils.SQLUtil;
import l1j.server.server.utils.collections.Lists;
import l1j.server.server.utils.collections.Maps;
public class ShopTable
{
private static final long serialVersionUID = 1L;
private static Logger _log = Logger.getLogger(ShopTable.class.getName());
private static ShopTable _instance;
private final Map <Integer, L1Shop> _allShops = Maps.newMap();
public static ShopTable getInstance() {
if (_instance == null) {
_instance = new ShopTable();
}
return _instance;
}
private ShopTable() {
loadShops();
}
private List<Integer> enumNpcIds() {
List <Integer> ids = Lists.newList();
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = L1DatabaseFactory.getInstance().getConnection();
pstm = con.prepareStatement("SELECT DISTINCT npc_id FROM shop");
rs = pstm.executeQuery();
while (rs.next())
ids.add(Integer.valueOf(rs.getInt("npc_id")));
}
catch (SQLException e)
{
_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
finally {
SQLUtil.close(rs, pstm, con);
}
return ids;
}
private L1Shop loadShop(int npcId, ResultSet rs) throws SQLException {
List <L1ShopItem> sellingList = Lists.newList();
List <L1ShopItem> purchasingList = Lists.newList();
while (rs.next()) {
int itemId = rs.getInt("item_id");
int sellingPrice = rs.getInt("selling_price");
int purchasingPrice = rs.getInt("purchasing_price");
int packCount = rs.getInt("pack_count");
int gashPrice = rs.getInt("gash_price");
int deleteDay = rs.getInt("delete_day");
int enchantlvl = rs.getInt("enchantlvl");
Timestamp deleteDate = rs.getTimestamp("delete_date");
packCount = packCount == 0 ? 1 : packCount;
if ((sellingPrice >= 0) && (gashPrice <= 0))
{
L1ShopItem item = new L1ShopItem(itemId, sellingPrice, packCount, deleteDay, enchantlvl, deleteDate);
sellingList.add(item);
}
if ((purchasingPrice >= 0) && (gashPrice <= 0))
{
L1ShopItem item = new L1ShopItem(itemId, purchasingPrice, packCount, deleteDay, enchantlvl, deleteDate);
purchasingList.add(item);
}
if ((gashPrice >= 0) && (sellingPrice <= 0) && (purchasingPrice <= 0)) {
L1ShopItem item = new L1ShopItem(itemId, gashPrice, packCount, deleteDay, enchantlvl, deleteDate);
sellingList.add(item);
}
}
return new L1Shop(npcId, sellingList, purchasingList);
}
private void loadShops() {
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = L1DatabaseFactory.getInstance().getConnection();
pstm = con.prepareStatement("SELECT * FROM shop WHERE npc_id=? ORDER BY order_id");
for (Iterator <Integer> localIterator = enumNpcIds().iterator(); localIterator.hasNext(); ) { int npcId = ((Integer)localIterator.next()).intValue();
pstm.setInt(1, npcId);
rs = pstm.executeQuery();
L1Shop shop = loadShop(npcId, rs);
_allShops.put(Integer.valueOf(npcId), shop);
rs.close(); }
}
catch (SQLException e)
{
_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
finally {
SQLUtil.close(rs, pstm, con);
}
}
public L1Shop get(int npcId) {
return (L1Shop)this._allShops.get(Integer.valueOf(npcId));
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
在尋找
L1shopItem
package l1j.server.server.templates;
import java.sql.Timestamp;
import l1j.server.server.datatables.ItemTable;
/*import l1j.server.server.model.Instance.L1NpcInstance;*/
import l1j.server.server.model.game.L1BugBearRace;
public class L1ShopItem
{
private static final long serialVersionUID = 1L;
private final int _itemId;
private L1Item _item;
private final int _price;
private final int _packCount;
private final int _deleteDay;
private final int _enchantlvl;
private final Timestamp _deleteDate;
public L1ShopItem(int itemId, int price, int packCount, int deleteDay, int enchantlvl, Timestamp deleteDate)
{
_itemId = itemId;
_item = ItemTable.getInstance().getTemplate(itemId);
_price = price;
_packCount = packCount;
_deleteDay = deleteDay;
_enchantlvl = enchantlvl;
_deleteDate = deleteDate;
}
public int getItemId() {
return _itemId;
}
public L1Item getItem() {
return _item;
}
public int getPrice() {
return _price;
}
public int getPackCount() {
return _packCount;
}
public int getDeleteDay() {
return _deleteDay;
}
public int getEnchantlvl() {
return _enchantlvl;
}
public Timestamp getDeleteDate() {
return _deleteDate;
}
public void setName(int num) {
int trueNum = L1BugBearRace.getInstance().getRunner(num).getNpcId() - 91350 + 1;
_item = (L1Item) _item.clone();
String temp = "" + _item.getIdentifiedNameId() + " "
+ L1BugBearRace.getInstance().getRound() + "-" + trueNum;
_item.setName(temp);
_item.setUnidentifiedNameId(temp);
_item.setIdentifiedNameId(temp);
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
在尋找
L1shopbuyorder
package l1j.server.server.model.shop;
import java.sql.Timestamp;
import l1j.server.server.templates.L1ShopItem;
class L1ShopBuyOrder
{
private final L1ShopItem _item;
private final int _count;
private final int _deleteDay;
private final Timestamp _deleteDate;
private final int _enchantlvl;
public L1ShopBuyOrder(L1ShopItem item, int count, int deleteDay, int enchantlvl, Timestamp deleteDate)
{
_item = item;
_count = count;
_deleteDay = deleteDay;
_enchantlvl = enchantlvl;
_deleteDate = deleteDate;
}
public L1ShopItem getItem() {
return this._item;
}
public int getCount() {
return this._count;
}
public int getDeleteDay() {
return this._deleteDay;
}
public int getEnchantlvl() {
return _enchantlvl;
}
public Timestamp getDeleteDate() {
return this._deleteDate;
}
}
在尋找
L1shopbuyorderlist
package l1j.server.server.model.shop;
import java.sql.Timestamp;
import java.util.List;
import l1j.server.Config;
import l1j.server.server.model.L1TaxCalculator;
import l1j.server.server.templates.L1Item;
import l1j.server.server.templates.L1ShopItem;
import l1j.server.server.utils.collections.Lists;
public class L1ShopBuyOrderList
{
private final L1Shop _shop;
private final List<L1ShopBuyOrder> _list = Lists.newList();
private final L1TaxCalculator _taxCalc;
private int _totalWeight = 0;
private int _totalPrice = 0;
private int _totalPriceTaxIncluded = 0;
L1ShopBuyOrderList(L1Shop shop) {
this._shop = shop;
this._taxCalc = new L1TaxCalculator(shop.getNpcId());
}
public void add(int orderNumber, int count) {
if (this._shop.getSellingItems().size() < orderNumber) {
return;
}
L1ShopItem shopItem = (L1ShopItem)this._shop.getSellingItems().get(orderNumber);
int price = (int)(shopItem.getPrice() * Config.RATE_SHOP_SELLING_PRICE);
int deleteDay = shopItem.getDeleteDay();
int enchantlvl = shopItem.getEnchantlvl();
Timestamp deleteDate = shopItem.getDeleteDate();
for (int j = 0; j < count; j++) {
if (price * j < 0) {
return;
}
}
if (this._totalPrice < 0) {
return;
}
_totalPrice += price * count;
_totalPriceTaxIncluded += _taxCalc.layTax(price) * count;
_totalWeight += shopItem.getItem().getWeight() * count * shopItem.getPackCount();
if (shopItem.getItem().isStackable()) {
_list.add(new L1ShopBuyOrder(shopItem, count * shopItem.getPackCount(), deleteDay, enchantlvl, deleteDate));
return;
}
for (int i = 0; i < count * shopItem.getPackCount(); i++)
_list.add(new L1ShopBuyOrder(shopItem, 1, deleteDay, enchantlvl,deleteDate));
}
List <L1ShopBuyOrder> getList()
{
return _list;
}
public int getTotalWeight() {
return this._totalWeight;
}
public int getTotalPrice() {
return this._totalPrice;
}
public int getTotalPriceTaxIncluded() {
return this._totalPriceTaxIncluded;
}
L1TaxCalculator getTaxCalculator() {
return this._taxCalc;
}
}
在尋找
LSHOP
請由NPC限定元寶交易NPC下面新增或修改
else
if ((_npcId >= Config.GASH_SHOP_MIN_ID) && (_npcId <= Config.GASH_SHOP_MAX_ID))
{
howpay = Config.GASH_SHOP_ITEM_ID;
} else {
howpay = 40308;
}
if (howpay == 40308)
{
if (!inv.consumeItem(howpay, orderList.getTotalPriceTaxIncluded()))
{
throw new IllegalStateException("不能消費為購買需要的金幣。");
}
}
else if (!inv.consumeItem(howpay, orderList.getTotalPrice()))
{
throw new IllegalStateException("不能消費為購買需要的商城專用貨幣。");
}
for (L1ShopBuyOrder order : orderList.getList()) {
int itemId = order.getItem().getItemId();
int amount = order.getCount();
L1ItemInstance item = ItemTable.getInstance().createItem(itemId);
int enchantlvl = order.getEnchantlvl();
int deleteDay = order.getDeleteDay();
Timestamp deleteDate = order.getDeleteDate();
if(enchantlvl != 0)
item.setEnchantLevel(enchantlvl);
if (deleteDay > 0) {
Timestamp delDay = new Timestamp(
System.currentTimeMillis() + 86400000 * deleteDay);
item.setDeleteDate(delDay);
}
db增加於shop





沒有留言:
張貼留言