Beispiel #1
0
void BlackMarketMgr::Update()
{
    SQLTransaction trans = CharacterDatabase.BeginTransaction();

    // Delete expired auctions
    for (auto itr = m_bmAuctionsMap.begin(); itr != m_bmAuctionsMap.end();)
    {
        BMAuctionEntry* auction = itr->second;
        if (auction->IsExpired())
        {
            if (auction->bidder)
                SendAuctionWon(auction, trans);
            auction->DeleteFromDB(trans);
            itr = m_bmAuctionsMap.erase(itr);
        }
        else
            ++itr;
    }

    // Add New Auctions
    int32 add = sWorld->getIntConfig(CONFIG_BLACKMARKET_MAX_AUCTIONS) - m_bmAuctionsMap.size();
    if (add > 0)
        CreateAuctions(add, trans);

    CharacterDatabase.CommitTransaction(trans);
}
Beispiel #2
0
void BlackMarketMgr::Update()
{
    uint32 curTime = time(NULL);
    SQLTransaction trans = CharacterDatabase.BeginTransaction();

    for (BMAuctionEntryMap::const_iterator itr = GetAuctionsBegin(); itr != GetAuctionsEnd();)
    {
        BMAuctionEntry* auction = itr->second;
        if (auction->IsExpired())
        {
            if (auction->bidder)
                SendAuctionWon(auction, trans);

            auction->DeleteFromDB(trans);
            BMAuctionsMap.erase((itr++)->first);
        } else
            ++itr;
    }

    int32 add = sWorld->getIntConfig(CONFIG_BLACKMARKET_MAX_AUCTIONS) - BMAuctionsMap.size();
    if (add > 0)
        CreateAuctions(add, trans);

    CharacterDatabase.CommitTransaction(trans);
}
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);
	}
}
void BlackMarketMgr::BuildBlackMarketAuctionsPacket(WorldPacket& data, uint32 guidLow)
{
    uint32 count = 0;
    ByteBuffer datas;

    data << uint32(time(NULL));

    for (BMAuctionEntryMap::const_iterator itr = GetAuctionsBegin(); itr != GetAuctionsEnd(); ++itr)
        if (itr->second->IsActive())
            ++count;

    data.WriteBits(count, 18);

    for (BMAuctionEntryMap::const_iterator itr = GetAuctionsBegin(); itr != GetAuctionsEnd(); ++itr)
    {
        BMAuctionEntry* auction = itr->second;

        if (!auction->IsActive())
            continue;

        data.WriteBit(guidLow == auction->bidder);          // Is owner

        uint64 currentBid = auction->bidder ? auction->bid : 0;
        uint64 nextBidPrice = auction->bidder ? auction->bid + GetAuctionOutBid(auction->bid) : auction->bid;
        uint64 upPrice = auction->bidder ? nextBidPrice - currentBid : 1;

        datas << uint32(auction->bm_template->itemEntry);
        datas << uint64(nextBidPrice);
        datas << uint64(currentBid);
        datas << uint32(0);                                 // Unk
        datas << uint32(auction->id);
        datas << uint32(auction->bm_template->seller);
        datas << uint64(upPrice);
        datas << uint32(auction->TimeLeft());
        datas << uint32(auction->bidderCount);
        datas << uint32(auction->bm_template->itemCount);
    }

    data.FlushBits();
    if (datas.size())
        data.append(datas);

    sLog->outInfo(LOG_FILTER_NETWORKIO, ">> Sent %u BlackMarket Auctions", count);
}
void BlackMarketMgr::BuildBlackMarketAuctionsPacket(WorldPacket& data, uint32 guidLow)
{
	uint32 count = 0;

	data << uint32(1); // unk
	data.WriteBits(count, 20); // placeholder

	for(BMAuctionEntryMap::const_iterator itr = GetAuctionsBegin(); itr != GetAuctionsEnd(); ++itr)
	{
		BMAuctionEntry* auction = itr->second;

		if (!auction->IsActive())
			continue;

		data.WriteBit((guidLow == auction->bidder));
		
		++count;
	}

	data.FlushBits();

	for(BMAuctionEntryMap::const_iterator itr = GetAuctionsBegin(); itr != GetAuctionsEnd(); ++itr)
	{
		BMAuctionEntry* auction = itr->second;

		if (!auction->IsActive())
			continue;

		data << uint32(auction->bm_template->seller); //seller
		data << uint32(auction->TimeLeft()); //time left
		data << uint64(0); //unk
		data << uint64(0); //unk
		data << uint64(auction->bid); // price
		data << uint32(auction->id); // auction id
		data << uint32(0); //unk
		data << uint32(auction->bm_template->itemCount); //stack count
		data << uint32(auction->bm_template->itemEntry); //item id
		data << uint32(0); //unk
	}

	data.PutBits<uint32>(32, count, 20);

	sLog->outInfo(LOG_FILTER_NETWORKIO, ">> Sent %u BlackMarket Auctions", count);
}
Beispiel #6
0
void BlackMarketMgr::CreateAuctions(uint32 number, SQLTransaction& trans)
{
    if (m_bmTemplatesMap.empty())
        return;

    for (uint32 i = 0; i < number; ++i)
    {
        // Select a template
        std::vector<uint32> templateList;
        uint32 rand = urand(1, 100);

        for (auto const &kvPair : m_bmTemplatesMap)
            if (kvPair.second.chance >= rand)
                templateList.push_back(kvPair.first);

        for (auto const &kvPair : m_bmAuctionsMap)
            templateList.erase(std::remove(templateList.begin(), templateList.end(), kvPair.second->bmTemplate->id), templateList.end());

        if (templateList.empty())
            continue;

        BMAuctionTemplate* selTemplate = GetTemplate(templateList[urand(0, (templateList.size() - 1))]);
        if (!selTemplate)
            continue;

        BMAuctionEntry* auction = new BMAuctionEntry;
        auction->id = GetNewAuctionId();
        auction->bid = selTemplate->startBid;
        auction->bidder = 0;
        auction->bidderCount = 0;
        auction->startTime = std::time(NULL)
                + sWorld->getIntConfig(CONFIG_BLACKMARKET_AUCTION_DELAY)
                + urand(0, sWorld->getIntConfig(CONFIG_BLACKMARKET_AUCTION_DELAY_MOD));

        auction->bmTemplate = selTemplate;

        m_bmAuctionsMap[auction->id] = auction;
        auction->SaveToDB(trans);
    }
}
void BlackMarketMgr::LoadAuctions()
{
	uint32 oldMSTime = getMSTime();

    PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BLACKMARKET_AUCTIONS);
    PreparedQueryResult result = CharacterDatabase.Query(stmt);

    if (!result)
    {
        sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 BlackMarket Auctions. DB table `blackmarket` is empty.");

        return;
    }

    uint32 count = 0;

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

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

		BMAuctionsMap[auction->id] = auction;

        ++count;

    } while (result->NextRow());

    CharacterDatabase.CommitTransaction(trans);

    sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u BlackMarket Auctions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));

}