예제 #1
0
static void addNewAuctions(Player *AHBplayer, AHBConfig *config)
{
	if (!AHBSeller)
		return;
	AuctionHouseObject* auctionHouse = objmgr.GetAuctionsMap(config->GetAHID());
	uint32 items = 0;
	uint32 minItems = config->GetMinItems();
	uint32 maxItems = config->GetMaxItems();
	uint32 auctions = auctionHouse->Getcount();

	if (auctions >= minItems)
	  return;
	if (auctions <= maxItems)
	{
		if ((maxItems - auctions) > ItemsPerCycle)
			items = ItemsPerCycle;
		else
			items = (maxItems - auctions);
	}
	uint32 wtgbin = config->GetPercents(AHB_WHITE_TG);
	uint32 gtgbin = config->GetPercents(AHB_GREEN_TG);
	uint32 btgbin = config->GetPercents(AHB_BLUE_TG);
	uint32 ptgbin = config->GetPercents(AHB_PURPLE_TG);
	uint32 wibin = config->GetPercents(AHB_WHITE_I);
	uint32 gibin = config->GetPercents(AHB_GREEN_I);
	uint32 bibin = config->GetPercents(AHB_BLUE_I);
	uint32 pibin = config->GetPercents(AHB_PURPLE_I);
	uint32 total = wtgbin + gtgbin + btgbin + ptgbin + wibin + gibin + bibin + pibin;

	uint32 pItems = 0;
	uint32 bItems = 0;
	uint32 gItems = 0;
	uint32 wItems = 0;
	uint32 pTGoods = 0;
	uint32 bTGoods = 0;
	uint32 gTGoods = 0;
	uint32 wTGoods = 0;
	for (AuctionHouseObject::AuctionEntryMap::iterator itr = auctionHouse->GetAuctionsBegin();itr != auctionHouse->GetAuctionsEnd();++itr)
	{
		AuctionEntry *Aentry = itr->second;
		Item *item = objmgr.GetAItem(Aentry->item_guidlow);
		if( item )
		{
			ItemPrototype const *prototype = item->GetProto();
			if( prototype )
			{
				switch (prototype->Quality)
				{
				 case 0:
					if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
					   wTGoods = wTGoods + 1;
					else
					   wItems = wItems + 1;
					break;

				 case 1:
					if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
					   wTGoods = wTGoods + 1;
					else
					   wItems = wItems + 1;
					break;

				 case 2:
					if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
					   gTGoods = gTGoods + 1;
					else
					   gItems = gItems + 1;
					break;

				 case 3:
					if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
					   bTGoods = bTGoods + 1;
					else
					   bItems = bItems + 1;
					break;

				 case 4:
					if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
					   pTGoods = pTGoods + 1;
					else
					   pItems = pItems + 1;
					break;
				}
			}
		}
	}
	// only insert a few at a time, so as not to peg the processor
	for (uint32 cnt = 1;cnt <= items;cnt++)
	{
		uint32 itemID = 0;
		while (itemID == 0)
		{
			uint32 choice = urand(1, 8);
			switch (choice)
			{
			case 1:
				{
					if ((purpleItems.size() > 0) && (pItems < pibin))
					{
						itemID = purpleItems[urand(0, purpleItems.size() - 1)];
						pItems = pItems + 1;
						break;
					}
				}
			case 2:
				{
					if ((blueItems.size() > 0) && (bItems < bibin))
					{
						 itemID = blueItems[urand(0, blueItems.size() - 1)];
						 bItems = bItems + 1;
						 break;
					}
				}
			case 3:
				{
					if ((greenItems.size() > 0) && (gItems < gibin))
					{
						 itemID = greenItems[urand(0, greenItems.size() - 1)];
						 gItems = gItems + 1;
						 break;
					}
				}
			case 4:
				{
					if ((whiteItems.size() > 0) && (wItems < wibin))
					{
						 itemID = whiteItems[urand(0, whiteItems.size() - 1)];
						 wItems = wItems + 1;
						 break;
					}
				}
			case 5:
				{
					if ((purpleTradeGoods.size() > 0) && (pTGoods < ptgbin))
					{
						 itemID = purpleTradeGoods[urand(0, purpleTradeGoods.size() - 1)];
						 pTGoods = pTGoods + 1;
						 break;
					}
				}
			case 6:
				{
					if ((blueTradeGoods.size() > 0) && (bTGoods < btgbin))
					{
						 itemID = blueTradeGoods[urand(0, blueTradeGoods.size() - 1)];
						 bTGoods = bTGoods + 1;
						 break;
					}
				}
			case 7:
				{
					if ((greenTradeGoods.size() > 0) && (gTGoods < gtgbin))
					{
						 itemID = greenTradeGoods[urand(0, greenTradeGoods.size() - 1)];
						 gTGoods = gTGoods + 1;
						 break;
					}
				}
			case 8:
				{
					if ((whiteTradeGoods.size() > 0) && (wTGoods < wtgbin))
					{
						 itemID = whiteTradeGoods[urand(0, whiteTradeGoods.size() - 1)];
						 wTGoods = wTGoods + 1;
						 break;
					}
				}
			default:
				{
					break;
				}
			}
		}

		ItemPrototype const* prototype = objmgr.GetItemPrototype(itemID);
		if (prototype == NULL)
		{
		 sLog.outString("AuctionHouseBot: Huh?!?! prototype == NULL");
		 continue;
		}

		Item* item = Item::CreateItem(itemID, 1, AHBplayer);
		item->AddToUpdateQueueOf(AHBplayer);
		if (item == NULL)
		{
			sLog.outString("AuctionHouseBot: Item::CreateItem() returned NULL");
			break;
		}

		uint32 randomPropertyId = Item::GenerateItemRandomPropertyId(itemID);
		if (randomPropertyId != 0)
		 item->SetItemRandomProperties(randomPropertyId);

		uint32 buyoutPrice;
		uint32 bidPrice = 0;
		uint32 stackCount = urand(1, item->GetMaxStackCount());

		switch (SellMethod)
		{
		case 0:
			buyoutPrice  = prototype->SellPrice * item->GetCount();
			break;
		case 1:
			buyoutPrice  = prototype->BuyPrice * item->GetCount();
			break;
		default:
			buyoutPrice = 0;
			break;
		}

		switch (prototype->Quality)
		{
		 case 1:
			if (config->GetMaxStack(AHB_WHITE) != 0)
			{
			   stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_WHITE)));
			}
			buyoutPrice *= urand(config->GetMinPrice(AHB_WHITE), config->GetMaxPrice(AHB_WHITE)) * stackCount;
			buyoutPrice /= 100;
			bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_WHITE), config->GetMaxBidPrice(AHB_WHITE));
			bidPrice /= 100;
			break;

		 case 2:
			if (config->GetMaxStack(AHB_GREEN) != 0)
			{
			   stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_GREEN)));
			}
			buyoutPrice *= urand(config->GetMinPrice(AHB_GREEN), config->GetMaxPrice(AHB_GREEN)) * stackCount;
			buyoutPrice /= 100;
			bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_GREEN), config->GetMaxBidPrice(AHB_GREEN));
			bidPrice /= 100;
			break;

		 case 3:
			if (config->GetMaxStack(AHB_BLUE) != 0)
			{
			   stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_BLUE)));
			}
			buyoutPrice *= urand(config->GetMinPrice(AHB_BLUE), config->GetMaxPrice(AHB_BLUE)) * stackCount;
			buyoutPrice /= 100;
			bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_BLUE), config->GetMaxBidPrice(AHB_BLUE));
			bidPrice /= 100;
			break;

		 case 4:
			if (config->GetMaxStack(AHB_PURPLE) != 0)
			{
			   stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_PURPLE)));
			}
			buyoutPrice *= urand(config->GetMinPrice(AHB_PURPLE), config->GetMaxPrice(AHB_PURPLE)) * stackCount;
			buyoutPrice /= 100;
			bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_PURPLE), config->GetMaxBidPrice(AHB_PURPLE));
			bidPrice /= 100;
			break;
		}

		item->SetCount(stackCount);

		AuctionEntry* auctionEntry = new AuctionEntry;
		auctionEntry->Id = objmgr.GenerateAuctionID();
		auctionEntry->auctioneer = 0;
		auctionEntry->item_guidlow = item->GetGUIDLow();
		auctionEntry->item_template = item->GetEntry();
		auctionEntry->owner = AHBplayer->GetGUIDLow();
		auctionEntry->startbid = bidPrice;
		auctionEntry->buyout = buyoutPrice;
		auctionEntry->bidder = 0;
		auctionEntry->bid = 0;
		auctionEntry->deposit = 0;
		auctionEntry->location = config->GetAHID();
		auctionEntry->time = (time_t) (urand(config->GetMinTime(), config->GetMaxTime()) * 60 * 60 + time(NULL));
		item->SaveToDB();
		item->RemoveFromUpdateQueueOf(AHBplayer);
		objmgr.AddAItem(item);
		auctionHouse->AddAuction(auctionEntry);

		CharacterDatabase.PExecute("INSERT INTO `auctionhouse` (`id`,"
								 "`auctioneerguid`,`itemguid`,`item_template`,"
								 "`itemowner`,`buyoutprice`,`time`,`buyguid`,"
								 "`lastbid`,`startbid`,`deposit`,`location`) "
								 "VALUES ('%u', '%u', '%u', '%u', '%u', '%u', "
								 "'" I64FMTD "', '%u', '%u', '%u', '%u', '%u')",
								 auctionEntry->Id,
								 auctionEntry->auctioneer,
								 auctionEntry->item_guidlow,
								 auctionEntry->item_template,
								 auctionEntry->owner,
								 auctionEntry->buyout,
								 (uint64) auctionEntry->time,
								 auctionEntry->bidder,
								 auctionEntry->bid,
								 auctionEntry->startbid,
								 auctionEntry->deposit,
								 auctionEntry->location);
	}
}