public static MapleShop createFromDB(int id, boolean isShopId) {
MapleShop ret = null;
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement(isShopId ? "SELECT * FROM shops WHERE shopid = ?" : "SELECT * FROM shops WHERE npcid = ?");
int shopId;
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
shopId = rs.getInt("shopid");
ret = new MapleShop(shopId, rs.getInt("npcid"));
rs.close();
ps.close();
} else {
rs.close();
ps.close();
return null;
}
ps = con.prepareStatement("SELECT * FROM shopitems WHERE shopid = ? ORDER BY position ASC");
ps.setInt(1, shopId);
rs = ps.executeQuery();
List<Integer> recharges = new ArrayList(rechargeableItems);
while (rs.next()) {
if (ii.itemExists(rs.getInt("itemid"))) {
if ((GameConstants.isThrowingStar(rs.getInt("itemid"))) || (GameConstants.isBullet(rs.getInt("itemid")))) {
MapleShopItem starItem = new MapleShopItem((short) rs.getShort("buyable"), ii.getSlotMax(rs.getInt("itemid")), rs.getInt("itemid"), rs.getInt("price"), (short) rs.getInt("position"), rs.getInt("reqitem"), rs.getInt("reqitemq"), rs.getByte("rank"), rs.getInt("category"), rs.getInt("minLevel"), rs.getInt("expiration"), false);
ret.addItem(starItem);
if (rechargeableItems.contains(Integer.valueOf(starItem.getItemId()))) {
recharges.remove(Integer.valueOf(starItem.getItemId()));
}
} else {
ret.addItem(new MapleShopItem((short) rs.getShort("buyable"), rs.getShort("quantity"), rs.getInt("itemid"), rs.getInt("price"), (short) rs.getInt("position"), rs.getInt("reqitem"), rs.getInt("reqitemq"), rs.getByte("rank"), rs.getInt("category"), rs.getInt("minLevel"), rs.getInt("expiration"), false)); //todo potential
}
}
}
for (Integer recharge : recharges) {
ret.addItem(new MapleShopItem((short) 1, ii.getSlotMax(recharge.intValue()), recharge.intValue(), 0, (short) 0, 0, 0, (byte) 0, 0, 0, 0, false));
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT * FROM shopranks WHERE shopid = ? ORDER BY rank ASC");
ps.setInt(1, shopId);
rs = ps.executeQuery();
while (rs.next()) {
if (ii.itemExists(rs.getInt("itemid"))) {
ret.ranks.add(new Pair(Integer.valueOf(rs.getInt("itemid")), rs.getString("name")));
}
}
rs.close();
ps.close();
} catch (SQLException e) {
System.err.println("Could not load shop");
}
return ret;
}