int price = rset.getInt("price");
int count = rset.getInt("count");
int currentCount = rset.getInt("currentCount");
int time = rset.getInt("time");
L2ItemInstance item = ItemTable.getInstance().createDummyItem(itemId);
if(item == null)
{
rset.close();
statement.close();
rset = null;
statement = null;
continue;
}
if(count > -1)
{
item.setCountDecrease(true);
LimitedItem = true;
}
item.setPriceToSell(price);
item.setTime(time);
item.setInitCount(count);
if(currentCount > -1)
{
item.setCount(currentCount);
}
else
{
item.setCount(count);
}
buy1.addItem(item);
item = null;
buy1.setNpcId(rset1.getString("npc_id"));
try
{
while(rset.next()) //TODO aici
{
dummyItemCount++;
itemId = rset.getInt("item_id");
price = rset.getInt("price");
count = rset.getInt("count");
time = rset.getInt("time");
currentCount = rset.getInt("currentCount");
L2ItemInstance item2 = ItemTable.getInstance().createDummyItem(itemId);
if(item2 == null)
{
continue;
}
if(count > -1)
{
item2.setCountDecrease(true);
LimitedItem = true;
}
item2.setPriceToSell(price);
item2.setTime(time);
item2.setInitCount(count);
if(currentCount > -1)
{
item2.setCount(currentCount);
}
else
{
item2.setCount(count);
}
buy1.addItem(item2);
}
}
catch(Exception e)
{
if(Config.ENABLE_ALL_EXCEPTIONS)
e.printStackTrace();
_log.warning("TradeController: Problem with buylist " + buy1.getListId() + " item " + itemId);
}
if(LimitedItem)
{
_listsTaskItem.put(new Integer(buy1.getListId()), buy1);
}
else
{
_lists.put(new Integer(buy1.getListId()), buy1);
}
_nextListId = Math.max(_nextListId, buy1.getListId() + 1);
buy1 = null;
}
rset.close();
statement.close();
rset = null;
statement = null;
}
rset1.close();
statement1.close();
rset1 = null;
statement1 = null;
if(Config.DEBUG)
{
_log.fine("created " + dummyItemCount + " Dummy-Items for buylists");
}
_log.config("TradeController: Loaded " + _lists.size() + " Buylists.");
_log.config("TradeController: Loaded " + _listsTaskItem.size() + " Limited Buylists.");
/*
* Restore Task for reinitialyze count of buy item
*/
try
{
int time = 0;
long savetimer = 0;
long currentMillis = System.currentTimeMillis();
PreparedStatement statement2 = con.prepareStatement("SELECT DISTINCT time, savetimer FROM merchant_buylists WHERE time <> 0 ORDER BY time");
ResultSet rset2 = statement2.executeQuery();
while(rset2.next())
{
time = rset2.getInt("time");
savetimer = rset2.getLong("savetimer");
if(savetimer - currentMillis > 0)
{
ThreadPoolManager.getInstance().scheduleGeneral(new RestoreCount(time), savetimer - System.currentTimeMillis());
}
else
{
ThreadPoolManager.getInstance().scheduleGeneral(new RestoreCount(time), 0);
}
}
rset2.close();
statement2.close();
rset2 = null;
statement2 = null;
}
catch(Exception e)
{
_log.warning("TradeController: Could not restore Timer for Item count.");
e.printStackTrace();
}
}
catch(Exception e)
{
// problem with initializing spawn, go to next one
_log.warning("TradeController: Buylists could not be initialized.");
e.printStackTrace();
}
finally
{
CloseUtil.close(con);
con = null;
}
/*
* If enabled, initialize the custom buylist
*/
if(Config.CUSTOM_MERCHANT_TABLES)// Custom merchat Tabels
{
try
{
int initialSize = _lists.size();
con = L2DatabaseFactory.getInstance().getConnection(false);
PreparedStatement statement1 = con.prepareStatement("SELECT " + L2DatabaseFactory.getInstance().safetyString(new String[]
{
"shop_id", "npc_id"
}) + " FROM custom_merchant_shopids");
ResultSet rset1 = statement1.executeQuery();
while(rset1.next())
{
PreparedStatement statement = con.prepareStatement("SELECT " + L2DatabaseFactory.getInstance().safetyString(new String[]
{
"item_id", "price", "shop_id", "order", "count", "time", "currentCount"
}) + " FROM custom_merchant_buylists WHERE shop_id=? ORDER BY " + L2DatabaseFactory.getInstance().safetyString(new String[]
{
"order"
}) + " ASC");
statement.setString(1, String.valueOf(rset1.getInt("shop_id")));
ResultSet rset = statement.executeQuery();
if(rset.next())
{
LimitedItem = false;
dummyItemCount++;
L2TradeList buy1 = new L2TradeList(rset1.getInt("shop_id"));
int itemId = rset.getInt("item_id");
int price = rset.getInt("price");
int count = rset.getInt("count");
int currentCount = rset.getInt("currentCount");
int time = rset.getInt("time");
L2ItemInstance item = ItemTable.getInstance().createDummyItem(itemId);
if(item == null)
{
rset.close();
statement.close();
rset = null;
statement = null;
continue;
}
if(count > -1)
{
item.setCountDecrease(true);
LimitedItem = true;
}
item.setPriceToSell(price);
item.setTime(time);
item.setInitCount(count);
if(currentCount > -1)
{
item.setCount(currentCount);
}
else
{
item.setCount(count);
}
buy1.addItem(item);
item = null;
buy1.setNpcId(rset1.getString("npc_id"));
try
{
while(rset.next())
{
dummyItemCount++;
itemId = rset.getInt("item_id");
price = rset.getInt("price");
count = rset.getInt("count");
time = rset.getInt("time");
currentCount = rset.getInt("currentCount");
L2ItemInstance item2 = ItemTable.getInstance().createDummyItem(itemId);
if(item2 == null)
{
continue;
}
if(count > -1)
{
item2.setCountDecrease(true);
LimitedItem = true;
}
item2.setPriceToSell(price);
item2.setTime(time);
item2.setInitCount(count);
if(currentCount > -1)
{
item2.setCount(currentCount);
}
else
{
item2.setCount(count);
}
buy1.addItem(item2);
item2 = null;
}