/*
* Ascent MMORPG Server
* Copyright (C) 2005-2007 Ascent Team
*
* 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
* 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 .
*
*/
#include "StdAfx.h"
initialiseSingleton( AuctionMgr );
void AuctionMgr::LoadAuctionHouses()
{
Log.Notice("AuctionMgr", "Loading Auction Houses...");
QueryResult * res = CharacterDatabase.Query("SELECT MAX(auctionId) FROM auctions");
if(res)
{
maxId = res->Fetch()[0].GetUInt32();
delete res;
}
res = WorldDatabase.Query("SELECT DISTINCT AHid FROM auctionhouse ORDER BY AHid");
AuctionHouse * ah;
map tempmap;
if(res)
{
do
{
ah = new AuctionHouse(res->Fetch()[0].GetUInt32());
ah->LoadAuctions();
auctionHouses.push_back(ah);
tempmap.insert( make_pair( res->Fetch()[0].GetUInt32(), ah ) );
}while(res->NextRow());
delete res;
}
res = WorldDatabase.Query("SELECT auctioneer, AHid FROM auctionhouse");
if(res)
{
do
{
auctionHouseEntryMap.insert( make_pair( res->Fetch()[0].GetUInt32(), tempmap[res->Fetch()[1].GetUInt32()] ) );
} while(res->NextRow());
delete res;
}
}
AuctionHouse * AuctionMgr::GetAuctionHouse(uint32 Entry)
{
HM_NAMESPACE::hash_map::iterator itr = auctionHouseEntryMap.find(Entry);
if(itr == auctionHouseEntryMap.end()) return NULL;
return itr->second;
}
void AuctionMgr::Update()
{
if((++loopcount % 100))
return;
vector::iterator itr = auctionHouses.begin();
for(; itr != auctionHouses.end(); ++itr)
{
(*itr)->UpdateDeletionQueue();
// Actual auction loop is on a seperate timer.
if(!(loopcount % 1200))
(*itr)->UpdateAuctions();
}
}