コード例 #1
0
ファイル: BlackMarketMgr.cpp プロジェクト: Diyvol/TrinityCore
void BlackMarketMgr::LoadAuctions()
{
    uint32 oldMSTime = getMSTime();

    // Clear in case we are reloading
    if (!_auctions.empty())
    {
        for (BlackMarketEntryMap::iterator itr = _auctions.begin(); itr != _auctions.end(); ++itr)
            delete itr->second;

        _auctions.clear();
    }

    PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BLACKMARKET_AUCTIONS);
    PreparedQueryResult result = CharacterDatabase.Query(stmt);
    if (!result)
    {
        TC_LOG_INFO("server.loading", ">> Loaded 0 black market auctions. DB table `blackmarket_auctions` is empty.");
        return;
    }

    _lastUpdate = time(nullptr); //Set update time before loading

    SQLTransaction trans = CharacterDatabase.BeginTransaction();
    do
    {
        Field* fields = result->Fetch();
        BlackMarketEntry* auction = new BlackMarketEntry();

        if (!auction->LoadFromDB(fields))
        {
            auction->DeleteFromDB(trans);
            delete auction;
            continue;
        }

        if (auction->IsCompleted())
        {
            auction->DeleteFromDB(trans);
            delete auction;
            continue;
        }

        AddAuction(auction);
    } while (result->NextRow());

    CharacterDatabase.CommitTransaction(trans);

    TC_LOG_INFO("server.loading", ">> Loaded %u black market auctions in %u ms.", uint32(_auctions.size()), GetMSTimeDiffToNow(oldMSTime));
}
コード例 #2
0
ファイル: BlackMarketMgr.cpp プロジェクト: Diyvol/TrinityCore
void BlackMarketMgr::RefreshAuctions()
{
    SQLTransaction trans = CharacterDatabase.BeginTransaction();
    // Delete completed auctions
    for (BlackMarketEntryMap::iterator itr = _auctions.begin(); itr != _auctions.end();)
    {
        BlackMarketEntry* entry = itr->second;
        if (!entry->IsCompleted())
        {
            ++itr;
            continue;
        }

        entry->DeleteFromDB(trans);
        itr = _auctions.erase(itr);
        delete entry;
    }

    CharacterDatabase.CommitTransaction(trans);
    trans = CharacterDatabase.BeginTransaction();

    std::list<BlackMarketTemplate const*> templates;
    for (auto const& pair : _templates)
    {
        if (GetAuctionByID(pair.second->MarketID))
            continue;
        if (!roll_chance_f(pair.second->Chance))
            continue;

        templates.push_back(pair.second);
    }

    Trinity::Containers::RandomResizeList(templates, sWorld->getIntConfig(CONFIG_BLACKMARKET_MAXAUCTIONS));

    for (BlackMarketTemplate const* templat : templates)
    {
        BlackMarketEntry* entry = new BlackMarketEntry();
        entry->Initialize(templat->MarketID, templat->Duration);
        entry->SaveToDB(trans);
        AddAuction(entry);
    }

    CharacterDatabase.CommitTransaction(trans);

    Update(true);
}
コード例 #3
0
ファイル: BlackMarketMgr.cpp プロジェクト: Diyvol/TrinityCore
void BlackMarketMgr::Update(bool updateTime)
{
    SQLTransaction trans = CharacterDatabase.BeginTransaction();
    time_t now = time(nullptr);
    for (BlackMarketEntryMap::iterator itr = _auctions.begin(); itr != _auctions.end(); ++itr)
    {
        BlackMarketEntry* entry = itr->second;

        if (entry->IsCompleted() && entry->GetBidder())
            SendAuctionWonMail(entry, trans);

        if (updateTime)
            entry->Update(now);
    }

    if (updateTime)
        _lastUpdate = now;

    CharacterDatabase.CommitTransaction(trans);
}