コード例 #1
0
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);
	}
}
コード例 #2
0
ファイル: BlackMarketMgr.cpp プロジェクト: Exodius/chuspi
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);
    }
}