BlackMarketMgr::~BlackMarketMgr() { for (BMAuctionEntryMap::const_iterator itr = GetAuctionsBegin(); itr != GetAuctionsEnd(); ++itr) delete itr->second; for (BMAuctionTemplateMap::const_iterator itr = GetTemplatesBegin(); itr != GetTemplatesEnd(); ++itr) delete itr->second; }
void BlackMarketMgr::CreateAuctions(uint32 number, SQLTransaction& trans) { if (BMTemplatesMap.empty()) return; for(uint32 i=0; i < number; ++i) { // Select a template std::vector<uint32> templateList; uint32 rand = urand(1, 100); for(BMAuctionTemplateMap::const_iterator itr = GetTemplatesBegin(); itr != GetTemplatesEnd(); ++itr) { if(itr->second->chance >= rand) { templateList.push_back(itr->first); } } for(BMAuctionEntryMap::const_iterator itr = GetAuctionsBegin(); itr != GetAuctionsEnd(); ++itr) templateList.erase(std::remove(templateList.begin(), templateList.end(), itr->second->templateId), templateList.end()); if(templateList.empty()) continue; BMAuctionTemplate *selTemplate = GetTemplate(templateList[urand(0, templateList.size())]); if(!selTemplate) continue; BMAuctionEntry* auction = new BMAuctionEntry; auction->id = GetNewAuctionId(); auction->bid = selTemplate->startBid; auction->bidder = 0; auction->startTime = time(NULL) + sWorld->getIntConfig(CONFIG_BLACKMARKET_AUCTION_DELAY) + urand(0, sWorld->getIntConfig(CONFIG_BLACKMARKET_AUCTION_DELAY_MOD)*2) - sWorld->getIntConfig(CONFIG_BLACKMARKET_AUCTION_DELAY_MOD) / 2; auction->bm_template = selTemplate; auction->templateId = selTemplate->id; BMAuctionsMap[auction->id] = auction; auction->SaveToDB(trans); } }