port over some changes from Trinity version including one possible memory leak fix
[AHbot.git] / src / game / AuctionHouseBot.cpp
blob27315f8e2e95b1fa034e82584d5e2ebfe7fca3d9
1 #include "AuctionHouseBot.h"
2 #include "Bag.h"
3 #include "Config/ConfigEnv.h"
4 #include "Database/DatabaseEnv.h"
5 #include "Item.h"
6 #include "Log.h"
7 #include "ObjectMgr.h"
8 #include "AuctionHouseMgr.h"
9 #include "Player.h"
10 #include "World.h"
11 #include "WorldSession.h"
12 #include "time.h"
13 #include <vector>
14 #include <iostream>
16 using namespace std;
18 static bool debug_Out = sConfig.GetBoolDefault("AuctionHouseBot.DEBUG", false);
20 static vector<uint32> npcItems;
21 static vector<uint32> lootItems;
22 static vector<uint32> greyTradeGoodsBin;
23 static vector<uint32> whiteTradeGoodsBin;
24 static vector<uint32> greenTradeGoodsBin;
25 static vector<uint32> blueTradeGoodsBin;
26 static vector<uint32> purpleTradeGoodsBin;
27 static vector<uint32> orangeTradeGoodsBin;
28 static vector<uint32> yellowTradeGoodsBin;
29 static vector<uint32> greyItemsBin;
30 static vector<uint32> whiteItemsBin;
31 static vector<uint32> greenItemsBin;
32 static vector<uint32> blueItemsBin;
33 static vector<uint32> purpleItemsBin;
34 static vector<uint32> orangeItemsBin;
35 static vector<uint32> yellowItemsBin;
37 static bool AHBSeller = 0;
38 static bool AHBBuyer = 0;
40 static bool Vendor_Items = 0;
41 static bool Loot_Items = 0;
42 static bool Other_Items = 0;
44 static bool No_Bind = 0;
45 static bool Bind_When_Picked_Up = 0;
46 static bool Bind_When_Equipped = 0;
47 static bool Bind_When_Use = 0;
48 static bool Bind_Quest_Item = 0;
50 static AHBConfig AllianceConfig = AHBConfig(2);
51 static AHBConfig HordeConfig = AHBConfig(6);
52 static AHBConfig NeutralConfig = AHBConfig(7);
53 time_t _lastrun_a;
54 time_t _lastrun_h;
55 time_t _lastrun_n;
57 ///////////////////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////////////////
60 static inline uint32 minValue(uint32 a, uint32 b)
62 return a <= b ? a : b;
65 ///////////////////////////////////////////////////////////////////////////////
67 ///////////////////////////////////////////////////////////////////////////////
68 static void addNewAuctions(Player *AHBplayer, AHBConfig *config)
70 if (!AHBSeller)
71 return;
72 AuctionHouseEntry const* ahEntry = auctionmgr.GetAuctionHouseEntry(config->GetAHFID());
73 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
74 uint32 items = 0;
75 uint32 minItems = config->GetMinItems();
76 uint32 maxItems = config->GetMaxItems();
77 uint32 auctions = auctionHouse->Getcount();
78 uint32 AuctioneerGUID = 0;
79 switch (config->GetAHID()){
80 case 2:
81 AuctioneerGUID = 79707; //Human in stormwind.
82 case 6:
83 AuctioneerGUID = 4656; //orc in Orgrimmar
84 case 7:
85 AuctioneerGUID = 23442; //goblin in GZ
86 default:
87 AuctioneerGUID = 23442; //default to neutral 7
90 if (auctions >= minItems)
91 return;
92 if (auctions <= maxItems)
94 if ((maxItems - auctions) > ItemsPerCycle)
95 items = ItemsPerCycle;
96 else
97 items = (maxItems - auctions);
99 uint32 greyTGcount = config->GetPercents(AHB_GREY_TG);
100 uint32 whiteTGcount = config->GetPercents(AHB_WHITE_TG);
101 uint32 greenTGcount = config->GetPercents(AHB_GREEN_TG);
102 uint32 blueTGcount = config->GetPercents(AHB_BLUE_TG);
103 uint32 purpleTGcount = config->GetPercents(AHB_PURPLE_TG);
104 uint32 orangeTGcount = config->GetPercents(AHB_ORANGE_TG);
105 uint32 yellowTGcount = config->GetPercents(AHB_YELLOW_TG);
106 uint32 greyIcount = config->GetPercents(AHB_GREY_I);
107 uint32 whiteIcount = config->GetPercents(AHB_WHITE_I);
108 uint32 greenIcount = config->GetPercents(AHB_GREEN_I);
109 uint32 blueIcount = config->GetPercents(AHB_BLUE_I);
110 uint32 purpleIcount = config->GetPercents(AHB_PURPLE_I);
111 uint32 orangeIcount = config->GetPercents(AHB_ORANGE_I);
112 uint32 yellowIcount = config->GetPercents(AHB_YELLOW_I);
113 uint32 total = greyTGcount + whiteTGcount + greenTGcount + blueTGcount
114 + purpleTGcount + orangeTGcount + yellowTGcount
115 + whiteIcount + greenIcount + blueIcount + purpleIcount
116 + orangeIcount + yellowIcount;
118 uint32 greyTGoods = 0;
119 uint32 whiteTGoods = 0;
120 uint32 greenTGoods = 0;
121 uint32 blueTGoods = 0;
122 uint32 purpleTGoods = 0;
123 uint32 orangeTGoods = 0;
124 uint32 yellowTGoods = 0;
126 uint32 greyItems = 0;
127 uint32 whiteItems = 0;
128 uint32 greenItems = 0;
129 uint32 blueItems = 0;
130 uint32 purpleItems = 0;
131 uint32 orangeItems = 0;
132 uint32 yellowItems = 0;
134 for (AuctionHouseObject::AuctionEntryMap::iterator itr = auctionHouse->GetAuctionsBegin();itr != auctionHouse->GetAuctionsEnd();++itr)
136 AuctionEntry *Aentry = itr->second;
137 Item *item = auctionmgr.GetAItem(Aentry->item_guidlow);
138 if( item )
140 ItemPrototype const *prototype = item->GetProto();
141 if( prototype )
143 switch (prototype->Quality)
145 case 0:
146 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
147 ++greyTGoods;
148 else
149 ++greyItems;
150 break;
152 case 1:
153 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
154 ++whiteTGoods;
155 else
156 ++whiteItems;
157 break;
159 case 2:
160 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
161 ++greenTGoods;
162 else
163 ++greenItems;
164 break;
166 case 3:
167 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
168 ++blueTGoods;
169 else
170 ++blueItems;
171 break;
173 case 4:
174 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
175 ++purpleTGoods;
176 else
177 ++purpleItems;
178 break;
180 case 5:
181 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
182 ++orangeTGoods;
183 else
184 ++orangeItems;
185 break;
187 case 6:
188 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
189 ++yellowTGoods;
190 else
191 ++yellowItems;
192 break;
197 // only insert a few at a time, so as not to peg the processor
198 for (uint32 cnt = 1;cnt <= items;cnt++)
200 uint32 itemID = 0;
201 while (itemID == 0)
203 uint32 choice = urand(0, 13);
204 switch (choice)
206 case 0:
208 if ((greyItemsBin.size() > 0) && (greyItems < greyIcount))
210 itemID = greyItemsBin[urand(0, greyItemsBin.size() - 1)];
211 ++greyItems;
212 break;
215 case 1:
217 if ((whiteItemsBin.size() > 0) && (whiteItems < whiteIcount))
219 itemID = whiteItemsBin[urand(0, whiteItemsBin.size() - 1)];
220 ++whiteItems;
221 break;
224 case 2:
226 if ((greenItemsBin.size() > 0) && (greenItems < greenIcount))
228 itemID = greenItemsBin[urand(0, greenItemsBin.size() - 1)];
229 ++greenItems;
230 break;
233 case 3:
235 if ((blueItemsBin.size() > 0) && (blueItems < blueIcount))
237 itemID = blueItemsBin[urand(0, blueItemsBin.size() - 1)];
238 ++blueItems;
239 break;
242 case 4:
244 if ((purpleItemsBin.size() > 0) && (purpleItems < purpleIcount))
246 itemID = purpleItemsBin[urand(0, purpleItemsBin.size() - 1)];
247 ++purpleItems;
248 break;
251 case 5:
253 if ((orangeItemsBin.size() > 0) && (orangeItems < orangeIcount))
255 itemID = orangeItemsBin[urand(0, orangeItemsBin.size() - 1)];
256 ++orangeItems;
257 break;
260 case 6:
262 if ((yellowItemsBin.size() > 0) && (yellowItems < yellowIcount))
264 itemID = yellowItemsBin[urand(0, yellowItemsBin.size() - 1)];
265 ++yellowItems;
266 break;
269 case 7:
271 if ((greyTradeGoodsBin.size() > 0) && (greyTGoods < greyTGcount))
273 itemID = whiteTradeGoodsBin[urand(0, whiteTradeGoodsBin.size() - 1)];
274 ++greyTGoods;
275 break;
278 case 8:
280 if ((whiteTradeGoodsBin.size() > 0) && (whiteTGoods < whiteTGcount))
282 itemID = whiteTradeGoodsBin[urand(0, whiteTradeGoodsBin.size() - 1)];
283 ++whiteTGoods;
284 break;
287 case 9:
289 if ((greenTradeGoodsBin.size() > 0) && (greenTGoods < greenTGcount))
291 itemID = greenTradeGoodsBin[urand(0, greenTradeGoodsBin.size() - 1)];
292 ++greenTGoods;
293 break;
296 case 10:
298 if ((blueTradeGoodsBin.size() > 0) && (blueTGoods < blueTGcount))
300 itemID = blueTradeGoodsBin[urand(0, blueTradeGoodsBin.size() - 1)];
301 ++blueTGoods;
302 break;
305 case 11:
307 if ((purpleTradeGoodsBin.size() > 0) && (purpleTGoods < purpleTGcount))
309 itemID = purpleTradeGoodsBin[urand(0, purpleTradeGoodsBin.size() - 1)];
310 ++purpleTGoods;
311 break;
314 case 12:
316 if ((orangeTradeGoodsBin.size() > 0) && (orangeTGoods < orangeTGcount))
318 itemID = orangeTradeGoodsBin[urand(0, orangeTradeGoodsBin.size() - 1)];
319 ++orangeTGoods;
320 break;
323 case 13:
325 if ((yellowTradeGoodsBin.size() > 0) && (yellowTGoods < yellowTGcount))
327 itemID = yellowTradeGoodsBin[urand(0, yellowTradeGoodsBin.size() - 1)];
328 ++yellowTGoods;
329 break;
332 default:
334 break;
339 ItemPrototype const* prototype = objmgr.GetItemPrototype(itemID);
340 if (prototype == NULL)
342 sLog.outString("AuctionHouseBot: Huh?!?! prototype == NULL");
343 continue;
346 Item* item = Item::CreateItem(itemID, 1, AHBplayer);
347 item->AddToUpdateQueueOf(AHBplayer);
348 if (item == NULL)
350 sLog.outString("AuctionHouseBot: Item::CreateItem() returned NULL");
351 break;
354 uint32 randomPropertyId = Item::GenerateItemRandomPropertyId(itemID);
355 if (randomPropertyId != 0)
356 item->SetItemRandomProperties(randomPropertyId);
358 uint32 buyoutPrice;
359 uint32 bidPrice = 0;
360 uint32 stackCount = urand(1, item->GetMaxStackCount());
362 switch (SellMethod)
364 case 0:
365 buyoutPrice = prototype->SellPrice * item->GetCount();
366 break;
367 case 1:
368 buyoutPrice = prototype->BuyPrice * item->GetCount();
369 break;
370 default:
371 buyoutPrice = 0;
372 break;
375 switch (prototype->Quality)
377 case 0:
378 if (config->GetMaxStack(AHB_GREY) != 0)
380 stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_GREY)));
382 buyoutPrice *= urand(config->GetMinPrice(AHB_GREY), config->GetMaxPrice(AHB_GREY)) * stackCount;
383 buyoutPrice /= 100;
384 bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_GREY), config->GetMaxBidPrice(AHB_GREY));
385 bidPrice /= 100;
386 break;
388 case 1:
389 if (config->GetMaxStack(AHB_WHITE) != 0)
391 stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_WHITE)));
393 buyoutPrice *= urand(config->GetMinPrice(AHB_WHITE), config->GetMaxPrice(AHB_WHITE)) * stackCount;
394 buyoutPrice /= 100;
395 bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_WHITE), config->GetMaxBidPrice(AHB_WHITE));
396 bidPrice /= 100;
397 break;
399 case 2:
400 if (config->GetMaxStack(AHB_GREEN) != 0)
402 stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_GREEN)));
404 buyoutPrice *= urand(config->GetMinPrice(AHB_GREEN), config->GetMaxPrice(AHB_GREEN)) * stackCount;
405 buyoutPrice /= 100;
406 bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_GREEN), config->GetMaxBidPrice(AHB_GREEN));
407 bidPrice /= 100;
408 break;
410 case 3:
411 if (config->GetMaxStack(AHB_BLUE) != 0)
413 stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_BLUE)));
415 buyoutPrice *= urand(config->GetMinPrice(AHB_BLUE), config->GetMaxPrice(AHB_BLUE)) * stackCount;
416 buyoutPrice /= 100;
417 bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_BLUE), config->GetMaxBidPrice(AHB_BLUE));
418 bidPrice /= 100;
419 break;
421 case 4:
422 if (config->GetMaxStack(AHB_PURPLE) != 0)
424 stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_PURPLE)));
426 buyoutPrice *= urand(config->GetMinPrice(AHB_PURPLE), config->GetMaxPrice(AHB_PURPLE)) * stackCount;
427 buyoutPrice /= 100;
428 bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_PURPLE), config->GetMaxBidPrice(AHB_PURPLE));
429 bidPrice /= 100;
430 break;
431 case 5:
432 if (config->GetMaxStack(AHB_ORANGE) != 0)
434 stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_ORANGE)));
436 buyoutPrice *= urand(config->GetMinPrice(AHB_ORANGE), config->GetMaxPrice(AHB_ORANGE)) * stackCount;
437 buyoutPrice /= 100;
438 bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_ORANGE), config->GetMaxBidPrice(AHB_ORANGE));
439 bidPrice /= 100;
440 break;
441 case 6:
442 if (config->GetMaxStack(AHB_YELLOW) != 0)
444 stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_YELLOW)));
446 buyoutPrice *= urand(config->GetMinPrice(AHB_YELLOW), config->GetMaxPrice(AHB_YELLOW)) * stackCount;
447 buyoutPrice /= 100;
448 bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_YELLOW), config->GetMaxBidPrice(AHB_YELLOW));
449 bidPrice /= 100;
450 break;
453 item->SetCount(stackCount);
455 AuctionEntry* auctionEntry = new AuctionEntry;
456 auctionEntry->Id = objmgr.GenerateAuctionID();
457 auctionEntry->auctioneer = AuctioneerGUID;
458 auctionEntry->item_guidlow = item->GetGUIDLow();
459 auctionEntry->item_template = item->GetEntry();
460 auctionEntry->owner = AHBplayer->GetGUIDLow();
461 auctionEntry->startbid = bidPrice;
462 auctionEntry->buyout = buyoutPrice;
463 auctionEntry->bidder = 0;
464 auctionEntry->bid = 0;
465 auctionEntry->deposit = 0;
466 auctionEntry->expire_time = (time_t) (urand(config->GetMinTime(), config->GetMaxTime()) * 60 * 60 + time(NULL));
467 auctionEntry->auctionHouseEntry = ahEntry;
468 item->SaveToDB();
469 item->RemoveFromUpdateQueueOf(AHBplayer);
470 auctionmgr.AddAItem(item);
471 auctionHouse->AddAuction(auctionEntry);
472 auctionEntry->SaveToDB();
476 static void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, WorldSession *session)
478 if (!AHBBuyer)
479 return;
481 // Fetches content of selected AH
482 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
483 AuctionHouseObject::AuctionEntryMap::iterator itr;
485 itr = auctionHouse->GetAuctionsBegin();
486 vector<uint32> possibleBids;
488 while (itr != auctionHouse->GetAuctionsEnd())
490 AuctionHouseObject::AuctionEntryMap::iterator tmp = itr;
491 ++itr;
492 // Check if the auction is ours
493 // if it is, we skip this iteration.
494 if(tmp->second->owner == AHBplayerGUID)
496 continue;
498 // Check that we haven't bidded in this auction already.
499 if(tmp->second->bidder != AHBplayerGUID)
501 uint32 tmpdata = tmp->second->Id;
502 possibleBids.push_back(tmpdata);
506 uint32 bids = config->GetBidsPerInterval();
507 for (uint32 count = 0; count < bids; ++count)
509 // Do we have anything to bid? If not, stop here.
510 if(possibleBids.empty())
511 return;
513 // Choose random auction from possible auctions
514 uint32 vectorPos = urand(0, possibleBids.size() - 1);
515 vector<uint32>::iterator iter = possibleBids.begin();
516 advance(iter, vectorPos);
517 // from auctionhousehandler.cpp, creates auction pointer & player pointer
518 AuctionEntry* auction = auctionHouse->GetAuction(*iter);
519 // Erase the auction from the vector to prevent bidding on item in next itteration.
520 possibleBids.erase(iter);
522 // get exact item information
523 Item *pItem = auctionmgr.GetAItem(auction->item_guidlow);
524 if (!pItem)
526 sLog.outError("Item doesn't exists, perhaps bought already?");
527 return;
530 // get item prototype
531 ItemPrototype const* prototype = objmgr.GetItemPrototype(auction->item_template);
533 // check which price we have to use, startbid or if it is bidded already
534 if(debug_Out)
536 sLog.outError("Auction Number: %u", auction->Id);
537 sLog.outError("Item Template: %u", auction->item_template);
538 sLog.outError("Buy Price: %u", prototype->BuyPrice);
539 sLog.outError("Sell Price: %u", prototype->SellPrice);
540 sLog.outError("Quality: %u", prototype->Quality);
543 uint32 currentprice;
544 if(auction->bid)
546 currentprice = auction->bid;
547 if(debug_Out)
548 {sLog.outError("Current Price: %u", auction->bid);}
550 else
552 currentprice = auction->startbid;
553 if(debug_Out)
554 {sLog.outError("Current Price: %u", auction->startbid);}
557 // Prepare portion from maximum bid
558 uint32 tmprate2 = urand(0, 100);
559 double tmprate = static_cast<double>(tmprate2);
560 double bidrate = tmprate / 100;
561 long double bidMax = 0;
562 if(debug_Out)
564 sLog.outError("tmprate: %f", tmprate);
565 sLog.outError("bidrate: %f", bidrate);
568 // check that bid has acceptable value and take bid based on vendorprice, stacksize and quality
569 switch (BuyMethod)
571 case 0:
573 switch (prototype->Quality)
575 case 0:
576 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREY))
577 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREY);
578 break;
579 case 1:
580 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_WHITE))
581 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_WHITE);
582 break;
583 case 2:
584 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREEN))
585 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREEN);
586 break;
587 case 3:
588 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_BLUE))
589 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_BLUE);
590 break;
591 case 4:
592 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_PURPLE))
593 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_PURPLE);
594 case 5:
595 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE))
596 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE);
597 case 6:
598 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW))
599 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW);
600 break;
601 default:
602 // quality is something it shouldn't be, let's get out of here
603 if(debug_Out)
604 sLog.outError("bidMax(fail): %f", bidMax);
605 return;
607 break;
609 case 1:
611 switch (prototype->Quality)
613 case 0:
614 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREY))
615 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREY);
616 break;
617 case 1:
618 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_WHITE))
619 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_WHITE);
620 break;
621 case 2:
622 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREEN))
623 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREEN);
624 break;
625 case 3:
626 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_BLUE))
627 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_BLUE);
628 break;
629 case 4:
630 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_PURPLE))
631 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_PURPLE);
632 case 5:
633 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE))
634 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE);
635 case 6:
636 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW))
637 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW);
638 break;
639 default:
640 // quality is something it shouldn't be, let's get out of here
641 if(debug_Out)
642 sLog.outError("bidMax(fail): %f", bidMax);
643 return;
645 break;
647 default:
648 bidMax = 0;
649 break;
652 if(debug_Out)
653 sLog.outError("bidMax(succeed): %f", bidMax);
655 // check some special items, and do recalculating to their prices
656 switch (prototype->Class)
658 // ammo
659 case 6:
660 bidMax = 0;
661 break;
662 default:
663 break;
666 if(bidMax == 0)
668 // quality check failed to get bidmax, let's get out of here
669 return;
672 // Calculate our bid
673 long double bidvalue = currentprice + ( (bidMax - currentprice) * bidrate);
674 // Convert to uint32
675 uint32 bidprice = static_cast<uint32>(bidvalue);
676 if(debug_Out)
678 sLog.outError("bidprice: %u", bidprice);
679 sLog.outError("bidvalue: %f", bidvalue);
682 // Check our bid is high enough to be valid. If not, correct it to minimum.
683 if((currentprice + auction->GetAuctionOutBid()) > bidprice)
685 bidprice = currentprice + auction->GetAuctionOutBid();
686 if(debug_Out)
687 sLog.outError("bidprice(>): %u", bidprice);
690 // Check wether we do normal bid, or buyout
691 if ((bidprice < auction->buyout) || (auction->buyout == 0))
694 if (auction->bidder > 0)
696 if ( auction->bidder == AHBplayer->GetGUIDLow() )
698 //pl->ModifyMoney( -int32(price - auction->bid));
700 else
702 // mail to last bidder and return money
703 session->SendAuctionOutbiddedMail( auction , bidprice );
704 //pl->ModifyMoney( -int32(price) );
708 auction->bidder = AHBplayer->GetGUIDLow();
709 auction->bid = bidprice;
711 // Saving auction into database
712 CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id);
714 else
716 //buyout
717 if (AHBplayer->GetGUIDLow() == auction->bidder )
719 //pl->ModifyMoney(-int32(auction->buyout - auction->bid));
721 else
723 //pl->ModifyMoney(-int32(auction->buyout));
724 if ( auction->bidder )
726 session->SendAuctionOutbiddedMail( auction, auction->buyout );
729 auction->bidder = AHBplayer->GetGUIDLow();
730 auction->bid = auction->buyout;
732 // Send mails to buyer & seller
733 auctionmgr.SendAuctionSuccessfulMail( auction );
734 auctionmgr.SendAuctionWonMail( auction );
736 // Remove item from auctionhouse
737 auctionmgr.RemoveAItem(auction->item_guidlow);
738 // Remove auction
739 auctionHouse->RemoveAuction(auction->Id);
740 // Remove from database
741 auction->DeleteFromDB();
742 delete auction;
746 ///////////////////////////////////////////////////////////////////////////////
748 ///////////////////////////////////////////////////////////////////////////////
749 void AuctionHouseBot()
751 time_t _newrun = time(NULL);
752 if ((!AHBSeller) && (!AHBBuyer))
753 return;
755 WorldSession _session(AHBplayerAccount, NULL, SEC_PLAYER, true, 0, LOCALE_enUS);
756 Player _AHBplayer(&_session);
757 _AHBplayer.MinimalLoadFromDB(NULL, AHBplayerGUID);
758 ObjectAccessor::Instance().AddObject(&_AHBplayer);
760 if(!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
762 addNewAuctions(&_AHBplayer, &AllianceConfig);
763 if (((_newrun - _lastrun_a) > (AllianceConfig.GetBiddingInterval() * 60)) && (AllianceConfig.GetBidsPerInterval() > 0))
765 addNewAuctionBuyerBotBid(&_AHBplayer, &AllianceConfig, &_session);
766 _lastrun_a = _newrun;
768 addNewAuctions(&_AHBplayer, &HordeConfig);
769 if (((_newrun - _lastrun_h) > (HordeConfig.GetBiddingInterval() *60)) && (HordeConfig.GetBidsPerInterval() > 0))
771 addNewAuctionBuyerBotBid(&_AHBplayer, &HordeConfig, &_session);
772 _lastrun_h = _newrun;
775 addNewAuctions(&_AHBplayer, &NeutralConfig);
776 if (((_newrun - _lastrun_n) > (NeutralConfig.GetBiddingInterval() * 60)) && (NeutralConfig.GetBidsPerInterval() > 0))
778 addNewAuctionBuyerBotBid(&_AHBplayer, &NeutralConfig, &_session);
779 _lastrun_n = _newrun;
781 ObjectAccessor::Instance().RemoveObject(&_AHBplayer);
783 ///////////////////////////////////////////////////////////////////////////////
785 ///////////////////////////////////////////////////////////////////////////////
786 void AuctionHouseBotInit()
788 AHBSeller = sConfig.GetBoolDefault("AuctionHouseBot.EnableSeller", false);
789 AHBBuyer = sConfig.GetBoolDefault("AuctionHouseBot.EnableBuyer", false);
790 No_Bind = sConfig.GetBoolDefault("AuctionHouseBot.No_Bind", true);
791 Bind_When_Picked_Up = sConfig.GetBoolDefault("AuctionHouseBot.Bind_When_Picked_Up", false);
792 Bind_When_Equipped = sConfig.GetBoolDefault("AuctionHouseBot.Bind_When_Equipped", true);
793 Bind_When_Use = sConfig.GetBoolDefault("AuctionHouseBot.Bind_When_Use", true);
794 Bind_Quest_Item = sConfig.GetBoolDefault("AuctionHouseBot.Bind_Quest_Item", false);
796 if(!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
798 AuctionHouseBotLoadValues(&AllianceConfig);
799 AuctionHouseBotLoadValues(&HordeConfig);
801 AuctionHouseBotLoadValues(&NeutralConfig);
803 if (AHBSeller)
805 Vendor_Items = sConfig.GetBoolDefault("AuctionHouseBot.VendorItems", false);
806 Loot_Items = sConfig.GetBoolDefault("AuctionHouseBot.LootItems", true);
807 Other_Items = sConfig.GetBoolDefault("AuctionHouseBot.OtherItems", false);
809 QueryResult* results = (QueryResult*) NULL;
810 char npcQuery[] = "SELECT distinct `item` FROM `npc_vendor`";
811 results = WorldDatabase.PQuery(npcQuery);
812 if (results != NULL)
816 Field* fields = results->Fetch();
817 npcItems.push_back(fields[0].GetUInt32());
819 } while (results->NextRow());
821 delete results;
823 else
825 sLog.outString("AuctionHouseBot: \"%s\" failed", npcQuery);
828 char lootQuery[] = "SELECT `item` FROM `creature_loot_template` UNION "
829 "SELECT `item` FROM `disenchant_loot_template` UNION "
830 "SELECT `item` FROM `fishing_loot_template` UNION "
831 "SELECT `item` FROM `gameobject_loot_template` UNION "
832 "SELECT `item` FROM `item_loot_template` UNION "
833 "SELECT `item` FROM `pickpocketing_loot_template` UNION "
834 "SELECT `item` FROM `prospecting_loot_template` UNION "
835 "SELECT `item` FROM `skinning_loot_template`";
837 results = WorldDatabase.PQuery(lootQuery);
838 if (results != NULL)
842 Field* fields = results->Fetch();
843 lootItems.push_back(fields[0].GetUInt32());
845 } while (results->NextRow());
847 delete results;
849 else
851 sLog.outString("AuctionHouseBot: \"%s\" failed", lootQuery);
854 for (uint32 itemID = 0; itemID < sItemStorage.MaxEntry; itemID++)
856 ItemPrototype const* prototype = objmgr.GetItemPrototype(itemID);
858 if (prototype == NULL)
859 continue;
861 switch (prototype->Bonding)
863 case 0:
864 if (!No_Bind)
865 continue;
866 break;
867 case 1:
868 if (!Bind_When_Picked_Up)
869 continue;
870 break;
871 case 2:
872 if (!Bind_When_Equipped)
873 continue;
874 break;
875 case 3:
876 if (!Bind_When_Use)
877 continue;
878 break;
879 case 4:
880 if (!Bind_Quest_Item)
881 continue;
882 break;
883 default:
884 continue;
885 break;
888 switch (SellMethod)
890 case 0:
891 if (prototype->SellPrice == 0)
892 continue;
893 break;
894 case 1:
895 if (prototype->BuyPrice == 0)
896 continue;
897 break;
898 default:
899 continue;
900 break;
903 if ((prototype->Quality < 0) || (prototype->Quality > 6))
904 continue;
906 if (Vendor_Items == 0)
908 bool isVendorItem = false;
910 for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorItem); i++)
912 if (itemID == npcItems[i])
913 isVendorItem = true;
916 if (isVendorItem)
917 continue;
920 if (Loot_Items == 0)
922 bool isLootItem = false;
924 for (unsigned int i = 0; (i < lootItems.size()) && (!isLootItem); i++)
926 if (itemID == lootItems[i])
927 isLootItem = true;
930 if (isLootItem)
931 continue;
934 if (Other_Items == 0)
936 bool isVendorItem = false;
937 bool isLootItem = false;
939 for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorItem); i++)
941 if (itemID == npcItems[i])
942 isVendorItem = true;
944 for (unsigned int i = 0; (i < lootItems.size()) && (!isLootItem); i++)
946 if (itemID == lootItems[i])
947 isLootItem = true;
949 if ((!isLootItem) && (!isVendorItem))
950 continue;
953 switch (prototype->Quality)
955 case 0:
956 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
957 greyTradeGoodsBin.push_back(itemID);
958 else
959 greyItemsBin.push_back(itemID);
960 break;
962 case 1:
963 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
964 whiteTradeGoodsBin.push_back(itemID);
965 else
966 whiteItemsBin.push_back(itemID);
967 break;
969 case 2:
970 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
971 greenTradeGoodsBin.push_back(itemID);
972 else
973 greenItemsBin.push_back(itemID);
974 break;
976 case 3:
977 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
978 blueTradeGoodsBin.push_back(itemID);
979 else
980 blueItemsBin.push_back(itemID);
981 break;
983 case 4:
984 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
985 purpleTradeGoodsBin.push_back(itemID);
986 else
987 purpleItemsBin.push_back(itemID);
988 break;
990 case 5:
991 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
992 orangeTradeGoodsBin.push_back(itemID);
993 else
994 orangeItemsBin.push_back(itemID);
995 break;
997 case 6:
998 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
999 yellowTradeGoodsBin.push_back(itemID);
1000 else
1001 yellowItemsBin.push_back(itemID);
1002 break;
1006 if (
1007 (greyTradeGoodsBin.size() == 0) &&
1008 (whiteTradeGoodsBin.size() == 0) &&
1009 (greenTradeGoodsBin.size() == 0) &&
1010 (blueTradeGoodsBin.size() == 0) &&
1011 (purpleTradeGoodsBin.size() == 0) &&
1012 (orangeTradeGoodsBin.size() == 0) &&
1013 (yellowTradeGoodsBin.size() == 0) &&
1014 (greyItemsBin.size() == 0) &&
1015 (whiteItemsBin.size() == 0) &&
1016 (greenItemsBin.size() == 0) &&
1017 (blueItemsBin.size() == 0) &&
1018 (purpleItemsBin.size() == 0) &&
1019 (orangeItemsBin.size() == 0) &&
1020 (yellowItemsBin.size() == 0)
1023 sLog.outString("AuctionHouseBot: No items");
1024 AHBSeller = 0;
1027 sLog.outString("AuctionHouseBot:");
1028 sLog.outString("loaded %u grey trade goods", greyTradeGoodsBin.size());
1029 sLog.outString("loaded %u white trade goods", whiteTradeGoodsBin.size());
1030 sLog.outString("loaded %u green trade goods", greenTradeGoodsBin.size());
1031 sLog.outString("loaded %u blue trade goods", blueTradeGoodsBin.size());
1032 sLog.outString("loaded %u purple trade goods", purpleTradeGoodsBin.size());
1033 sLog.outString("loaded %u orange trade goods", orangeTradeGoodsBin.size());
1034 sLog.outString("loaded %u yellow trade goods", yellowTradeGoodsBin.size());
1035 sLog.outString("loaded %u grey items", greyItemsBin.size());
1036 sLog.outString("loaded %u white items", whiteItemsBin.size());
1037 sLog.outString("loaded %u green items", greenItemsBin.size());
1038 sLog.outString("loaded %u blue items", blueItemsBin.size());
1039 sLog.outString("loaded %u purple items", purpleItemsBin.size());
1040 sLog.outString("loaded %u orange items", orangeItemsBin.size());
1041 sLog.outString("loaded %u yellow items", yellowItemsBin.size());
1043 sLog.outString("AuctionHouseBot by Paradox (original by ChrisK) has been loaded.");
1044 sLog.outString("AuctionHouseBot now includes AHBuyer by Kerbe and Paradox");
1047 void AuctionHouseBotCommands(uint32 command, uint32 ahMapID, uint32 col, char* args)
1049 AHBConfig *config;
1050 switch (ahMapID)
1052 case 2:
1053 config = &AllianceConfig;
1054 break;
1055 case 6:
1056 config = &HordeConfig;
1057 break;
1058 case 7:
1059 config = &NeutralConfig;
1060 break;
1062 std::string color;
1063 switch (col)
1065 case AHB_GREY:
1066 color = "grey";
1067 break;
1068 case AHB_WHITE:
1069 color = "white";
1070 break;
1071 case AHB_GREEN:
1072 color = "green";
1073 break;
1074 case AHB_BLUE:
1075 color = "blue";
1076 break;
1077 case AHB_PURPLE:
1078 color = "purple";
1079 break;
1080 case AHB_ORANGE:
1081 color = "orange";
1082 break;
1083 case AHB_YELLOW:
1084 color = "yellow";
1085 break;
1086 default:
1087 break;
1089 switch (command)
1091 case 0: //ahexpire
1093 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
1095 AuctionHouseObject::AuctionEntryMap::iterator itr;
1096 itr = auctionHouse->GetAuctionsBegin();
1098 while (itr != auctionHouse->GetAuctionsEnd())
1100 if (itr->second->owner == AHBplayerGUID)
1101 itr->second->expire_time = sWorld.GetGameTime();
1103 ++itr;
1105 }break;
1106 case 1: //min items
1108 char * param1 = strtok(args, " ");
1109 uint32 minItems = (uint32) strtoul(param1, NULL, 0);
1110 CharacterDatabase.PExecute("UPDATE auctionhousebot SET minitems = '%u' WHERE auctionhouse = '%u'", minItems, ahMapID);
1111 config->SetMinItems(minItems);
1112 }break;
1113 case 2: //max items
1115 char * param1 = strtok(args, " ");
1116 uint32 maxItems = (uint32) strtoul(param1, NULL, 0);
1117 CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxitems = '%u' WHERE auctionhouse = '%u'", maxItems, ahMapID);
1118 config->SetMaxItems(maxItems);
1119 }break;
1120 case 3: //min time
1122 char * param1 = strtok(args, " ");
1123 uint32 minTime = (uint32) strtoul(param1, NULL, 0);
1124 CharacterDatabase.PExecute("UPDATE auctionhousebot SET mintime = '%u' WHERE auctionhouse = '%u'", minTime, ahMapID);
1125 config->SetMinTime(minTime);
1126 }break;
1127 case 4: //max time
1129 char * param1 = strtok(args, " ");
1130 uint32 maxTime = (uint32) strtoul(param1, NULL, 0);
1131 CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxtime = '%u' WHERE auctionhouse = '%u'", maxTime, ahMapID);
1132 config->SetMaxTime(maxTime);
1133 }break;
1134 case 5: //percentages
1136 char * param1 = strtok(args, " ");
1137 char * param2 = strtok(NULL, " ");
1138 char * param3 = strtok(NULL, " ");
1139 char * param4 = strtok(NULL, " ");
1140 char * param5 = strtok(NULL, " ");
1141 char * param6 = strtok(NULL, " ");
1142 char * param7 = strtok(NULL, " ");
1143 char * param8 = strtok(NULL, " ");
1144 char * param9 = strtok(NULL, " ");
1145 char * param10 = strtok(NULL, " ");
1146 char * param11 = strtok(NULL, " ");
1147 char * param12 = strtok(NULL, " ");
1148 char * param13 = strtok(NULL, " ");
1149 char * param14 = strtok(NULL, " ");
1150 uint32 greytg = (uint32) strtoul(param1, NULL, 0);
1151 uint32 whitetg = (uint32) strtoul(param2, NULL, 0);
1152 uint32 greentg = (uint32) strtoul(param3, NULL, 0);
1153 uint32 bluetg = (uint32) strtoul(param4, NULL, 0);
1154 uint32 purpletg = (uint32) strtoul(param5, NULL, 0);
1155 uint32 orangetg = (uint32) strtoul(param6, NULL, 0);
1156 uint32 yellowtg = (uint32) strtoul(param7, NULL, 0);
1157 uint32 greyi = (uint32) strtoul(param8, NULL, 0);
1158 uint32 whitei = (uint32) strtoul(param9, NULL, 0);
1159 uint32 greeni = (uint32) strtoul(param10, NULL, 0);
1160 uint32 bluei = (uint32) strtoul(param11, NULL, 0);
1161 uint32 purplei = (uint32) strtoul(param12, NULL, 0);
1162 uint32 orangei = (uint32) strtoul(param13, NULL, 0);
1163 uint32 yellowi = (uint32) strtoul(param14, NULL, 0);
1165 CharacterDatabase.BeginTransaction();
1166 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreytradegoods = '%u' WHERE auctionhouse = '%u'", greytg, ahMapID);
1167 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentwhitetradegoods = '%u' WHERE auctionhouse = '%u'", whitetg, ahMapID);
1168 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreentradegoods = '%u' WHERE auctionhouse = '%u'", greentg, ahMapID);
1169 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentbluetradegoods = '%u' WHERE auctionhouse = '%u'", bluetg, ahMapID);
1170 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentpurpletradegoods = '%u' WHERE auctionhouse = '%u'", purpletg, ahMapID);
1171 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentorangetradegoods = '%u' WHERE auctionhouse = '%u'", orangetg, ahMapID);
1172 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentyellowtradegoods = '%u' WHERE auctionhouse = '%u'", yellowtg, ahMapID);
1173 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreyitems = '%u' WHERE auctionhouse = '%u'", greyi, ahMapID);
1174 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentwhiteitems = '%u' WHERE auctionhouse = '%u'", whitei, ahMapID);
1175 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreenitems = '%u' WHERE auctionhouse = '%u'", greeni, ahMapID);
1176 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentblueitems = '%u' WHERE auctionhouse = '%u'", bluei, ahMapID);
1177 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentpurpleitems = '%u' WHERE auctionhouse = '%u'", purplei, ahMapID);
1178 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentorangeitems = '%u' WHERE auctionhouse = '%u'", orangei, ahMapID);
1179 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentyellowitems = '%u' WHERE auctionhouse = '%u'", yellowi, ahMapID);
1180 CharacterDatabase.CommitTransaction();
1181 config->SetPercentages(greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi);
1182 }break;
1183 case 6: //min prices
1185 char * param1 = strtok(args, " ");
1186 uint32 minPrice = (uint32) strtoul(param1, NULL, 0);
1187 CharacterDatabase.PExecute("UPDATE auctionhousebot SET minprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), minPrice, ahMapID);
1188 config->SetMinPrice(col, minPrice);
1189 }break;
1190 case 7: //max prices
1192 char * param1 = strtok(args, " ");
1193 uint32 maxPrice = (uint32) strtoul(param1, NULL, 0);
1194 CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), maxPrice, ahMapID);
1195 config->SetMaxPrice(col, maxPrice);
1196 }break;
1197 case 8: //min bid price
1199 char * param1 = strtok(args, " ");
1200 uint32 minBidPrice = (uint32) strtoul(param1, NULL, 0);
1201 CharacterDatabase.PExecute("UPDATE auctionhousebot SET minbidprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), minBidPrice, ahMapID);
1202 config->SetMinBidPrice(col, minBidPrice);
1203 }break;
1204 case 9: //max bid price
1206 char * param1 = strtok(args, " ");
1207 uint32 maxBidPrice = (uint32) strtoul(param1, NULL, 0);
1208 CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxbidprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), maxBidPrice, ahMapID);
1209 config->SetMaxBidPrice(col, maxBidPrice);
1210 }break;
1211 case 10: //max stacks
1213 char * param1 = strtok(args, " ");
1214 uint32 maxStack = (uint32) strtoul(param1, NULL, 0);
1215 CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxstack%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), maxStack, ahMapID);
1216 config->SetMaxStack(col, maxStack);
1217 }break;
1218 case 11: //buyer bid prices
1220 char * param1 = strtok(args, " ");
1221 uint32 buyerPrice = (uint32) strtoul(param1, NULL, 0);
1222 CharacterDatabase.PExecute("UPDATE auctionhousebot SET buyerprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), buyerPrice, ahMapID);
1223 config->SetBuyerPrice(col, buyerPrice);
1224 }break;
1225 case 12: //buyer bidding interval
1227 char * param1 = strtok(args, " ");
1228 uint32 bidInterval = (uint32) strtoul(param1, NULL, 0);
1229 CharacterDatabase.PExecute("UPDATE auctionhousebot SET buyerbiddinginterval = '%u' WHERE auctionhouse = '%u'", bidInterval, ahMapID);
1230 config->SetBiddingInterval(bidInterval);
1231 }break;
1232 case 13: //buyer bids per interval
1234 char * param1 = strtok(args, " ");
1235 uint32 bidsPerInterval = (uint32) strtoul(param1, NULL, 0);
1236 CharacterDatabase.PExecute("UPDATE auctionhousebot SET buyerbidsperinterval = '%u' WHERE auctionhouse = '%u'", bidsPerInterval, ahMapID);
1237 config->SetBidsPerInterval(bidsPerInterval);
1238 }break;
1239 default:
1240 break;
1243 void AuctionHouseBotLoadValues(AHBConfig *config)
1245 if (AHBSeller)
1247 //load min and max items
1248 config->SetMinItems(CharacterDatabase.PQuery("SELECT minitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1249 config->SetMaxItems(CharacterDatabase.PQuery("SELECT maxitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1250 if(debug_Out)
1251 {sLog.outError("minItems = %u", config->GetMinItems());
1252 sLog.outError("maxItems = %u", config->GetMaxItems());}
1253 //load min and max auction times
1254 config->SetMinTime(CharacterDatabase.PQuery("SELECT mintime FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1255 config->SetMaxTime(CharacterDatabase.PQuery("SELECT maxtime FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1256 if(debug_Out)
1257 {sLog.outError("minTime = %u", config->GetMinTime());
1258 sLog.outError("maxTime = %u", config->GetMaxTime());}
1259 //load percentages
1260 uint32 greytg = CharacterDatabase.PQuery("SELECT percentgreytradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1261 uint32 whitetg = CharacterDatabase.PQuery("SELECT percentwhitetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1262 uint32 greentg = CharacterDatabase.PQuery("SELECT percentgreentradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1263 uint32 bluetg = CharacterDatabase.PQuery("SELECT percentbluetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1264 uint32 purpletg = CharacterDatabase.PQuery("SELECT percentpurpletradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1265 uint32 orangetg = CharacterDatabase.PQuery("SELECT percentorangetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1266 uint32 yellowtg = CharacterDatabase.PQuery("SELECT percentyellowtradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1267 uint32 greyi = CharacterDatabase.PQuery("SELECT percentgreyitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1268 uint32 whitei = CharacterDatabase.PQuery("SELECT percentwhiteitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1269 uint32 greeni = CharacterDatabase.PQuery("SELECT percentgreenitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1270 uint32 bluei = CharacterDatabase.PQuery("SELECT percentblueitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1271 uint32 purplei = CharacterDatabase.PQuery("SELECT percentpurpleitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1272 uint32 orangei = CharacterDatabase.PQuery("SELECT percentorangeitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1273 uint32 yellowi = CharacterDatabase.PQuery("SELECT percentyellowitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1274 config->SetPercentages(greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi);
1275 if(debug_Out)
1277 sLog.outError("percentGreyTradeGoods = %u", config->GetPercentages(AHB_GREY_TG));
1278 sLog.outError("percentWhiteTradeGoods = %u", config->GetPercentages(AHB_WHITE_TG));
1279 sLog.outError("percentGreenTradeGoods = %u", config->GetPercentages(AHB_GREEN_TG));
1280 sLog.outError("percentBlueTradeGoods = %u", config->GetPercentages(AHB_BLUE_TG));
1281 sLog.outError("percentPurpleTradeGoods = %u", config->GetPercentages(AHB_PURPLE_TG));
1282 sLog.outError("percentOrangeTradeGoods = %u", config->GetPercentages(AHB_ORANGE_TG));
1283 sLog.outError("percentYellowTradeGoods = %u", config->GetPercentages(AHB_YELLOW_TG));
1284 sLog.outError("percentGreyItems = %u", config->GetPercentages(AHB_GREY_I));
1285 sLog.outError("percentWhiteItems = %u", config->GetPercentages(AHB_WHITE_I));
1286 sLog.outError("percentGreenItems = %u", config->GetPercentages(AHB_GREEN_I));
1287 sLog.outError("percentBlueItems = %u", config->GetPercentages(AHB_BLUE_I));
1288 sLog.outError("percentPurpleItems = %u", config->GetPercentages(AHB_PURPLE_I));
1289 sLog.outError("percentOrangeItems = %u", config->GetPercentages(AHB_ORANGE_I));
1290 sLog.outError("percentYellowItems = %u", config->GetPercentages(AHB_YELLOW_I));
1292 //load min and max prices
1293 config->SetMinPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT minpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1294 config->SetMaxPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT maxpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1295 if(debug_Out)
1296 {sLog.outError("minPriceGrey = %u", config->GetMinPrice(AHB_GREY));
1297 sLog.outError("maxPriceGrey = %u", config->GetMaxPrice(AHB_GREY));}
1298 config->SetMinPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT minpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1299 config->SetMaxPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT maxpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1300 if(debug_Out)
1301 {sLog.outError("minPriceWhite = %u", config->GetMinPrice(AHB_WHITE));
1302 sLog.outError("maxPriceWhite = %u", config->GetMaxPrice(AHB_WHITE));}
1303 config->SetMinPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT minpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1304 config->SetMaxPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT maxpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1305 if(debug_Out)
1306 {sLog.outError("minPriceGreen = %u", config->GetMinPrice(AHB_GREEN));
1307 sLog.outError("maxPriceGreen = %u", config->GetMaxPrice(AHB_GREEN));}
1308 config->SetMinPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT minpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1309 config->SetMaxPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT maxpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1310 if(debug_Out)
1311 {sLog.outError("minPriceBlue = %u", config->GetMinPrice(AHB_BLUE));
1312 sLog.outError("maxPriceBlue = %u", config->GetMaxPrice(AHB_BLUE));}
1313 config->SetMinPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT minpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1314 config->SetMaxPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT maxpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1315 if(debug_Out)
1316 {sLog.outError("minPricePurple = %u", config->GetMinPrice(AHB_PURPLE));
1317 sLog.outError("maxPricePurple = %u", config->GetMaxPrice(AHB_PURPLE));}
1318 config->SetMinPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT minpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1319 config->SetMaxPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT maxpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1320 if(debug_Out)
1321 {sLog.outError("minPriceOrange = %u", config->GetMinPrice(AHB_ORANGE));
1322 sLog.outError("maxPriceOrange = %u", config->GetMaxPrice(AHB_ORANGE));}
1323 config->SetMinPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT minpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1324 config->SetMaxPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT maxpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1325 if(debug_Out)
1326 {sLog.outError("minPriceYellow = %u", config->GetMinPrice(AHB_YELLOW));
1327 sLog.outError("maxPriceYellow = %u", config->GetMaxPrice(AHB_YELLOW));}
1328 //load min and max bid prices
1329 config->SetMinBidPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT minbidpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1330 if(debug_Out)
1331 {sLog.outError(",minBidPriceGrey = %u", config->GetMinBidPrice(AHB_GREY));}
1332 config->SetMaxBidPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT maxbidpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1333 if(debug_Out)
1334 {sLog.outError("maxBidPriceGrey = %u", config->GetMaxBidPrice(AHB_GREY));}
1335 config->SetMinBidPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT minbidpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1336 if(debug_Out)
1337 {sLog.outError(",minBidPriceWhite = %u", config->GetMinBidPrice(AHB_WHITE));}
1338 config->SetMaxBidPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT maxbidpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1339 if(debug_Out)
1340 {sLog.outError("maxBidPriceWhite = %u", config->GetMaxBidPrice(AHB_WHITE));}
1341 config->SetMinBidPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT minbidpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1342 if(debug_Out)
1343 {sLog.outError("minBidPriceGreen = %u", config->GetMinBidPrice(AHB_GREEN));}
1344 config->SetMaxBidPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT maxbidpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1345 if(debug_Out)
1346 {sLog.outError("maxBidPriceGreen = %u", config->GetMaxBidPrice(AHB_GREEN));}
1347 config->SetMinBidPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT minbidpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1348 if(debug_Out)
1349 {sLog.outError("minBidPriceBlue = %u", config->GetMinBidPrice(AHB_BLUE));}
1350 config->SetMaxBidPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT maxbidpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1351 if(debug_Out)
1352 {sLog.outError("maxBidPriceBlue = %u", config->GetMinBidPrice(AHB_BLUE));}
1353 config->SetMinBidPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT minbidpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1354 if(debug_Out)
1355 {sLog.outError("minBidPricePurple = %u", config->GetMinBidPrice(AHB_PURPLE));}
1356 config->SetMaxBidPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT maxbidpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1357 if(debug_Out)
1358 {sLog.outError("maxBidPricePurple = %u", config->GetMaxBidPrice(AHB_PURPLE));}
1359 config->SetMinBidPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT minbidpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1360 if(debug_Out)
1361 {sLog.outError("minBidPriceOrange = %u", config->GetMinBidPrice(AHB_ORANGE));}
1362 config->SetMaxBidPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT maxbidpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1363 if(debug_Out)
1364 {sLog.outError("maxBidPriceOrange = %u", config->GetMaxBidPrice(AHB_ORANGE));}
1365 config->SetMinBidPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT minbidpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1366 if(debug_Out)
1367 {sLog.outError("minBidPriceYellow = %u", config->GetMinBidPrice(AHB_YELLOW));}
1368 config->SetMaxBidPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT maxbidpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1369 if(debug_Out)
1370 {sLog.outError("maxBidPriceYellow = %u", config->GetMaxBidPrice(AHB_YELLOW));}
1371 //load max stacks
1372 config->SetMaxStack(AHB_GREY, CharacterDatabase.PQuery("SELECT maxstackgrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1373 if(debug_Out)
1374 {sLog.outError("maxStackGrey = %u", config->GetMaxStack(AHB_GREY));}
1375 config->SetMaxStack(AHB_WHITE, CharacterDatabase.PQuery("SELECT maxstackwhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1376 if(debug_Out)
1377 {sLog.outError("maxStackWhite = %u", config->GetMaxStack(AHB_WHITE));}
1378 config->SetMaxStack(AHB_GREEN, CharacterDatabase.PQuery("SELECT maxstackgreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1379 if(debug_Out)
1380 {sLog.outError("maxStackGreen = %u", config->GetMaxStack(AHB_GREEN));}
1381 config->SetMaxStack(AHB_BLUE, CharacterDatabase.PQuery("SELECT maxstackblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1382 if(debug_Out)
1383 {sLog.outError("maxStackBlue = %u", config->GetMaxStack(AHB_BLUE));}
1384 config->SetMaxStack(AHB_PURPLE, CharacterDatabase.PQuery("SELECT maxstackpurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1385 if(debug_Out)
1386 {sLog.outError("maxStackPurple = %u", config->GetMaxStack(AHB_PURPLE));}
1387 config->SetMaxStack(AHB_ORANGE, CharacterDatabase.PQuery("SELECT maxstackorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1388 if(debug_Out)
1389 {sLog.outError("maxStackOrange = %u", config->GetMaxStack(AHB_ORANGE));}
1390 config->SetMaxStack(AHB_YELLOW, CharacterDatabase.PQuery("SELECT maxstackyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1391 if(debug_Out)
1392 {sLog.outError("maxStackYellow = %u", config->GetMaxStack(AHB_YELLOW));}
1394 if (AHBBuyer)
1396 //load buyer bid prices
1397 config->SetBuyerPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT buyerpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1398 config->SetBuyerPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT buyerpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1399 config->SetBuyerPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT buyerpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1400 config->SetBuyerPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT buyerpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1401 config->SetBuyerPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT buyerpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1402 config->SetBuyerPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT buyerpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1403 config->SetBuyerPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT buyerpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1404 if(debug_Out)
1406 sLog.outError("buyerPriceGrey = %u", config->GetBuyerPrice(AHB_GREY));
1407 sLog.outError("buyerPriceWhite = %u", config->GetBuyerPrice(AHB_WHITE));
1408 sLog.outError("buyerPriceGreen = %u", config->GetBuyerPrice(AHB_GREEN));
1409 sLog.outError("buyerPriceBlue = %u", config->GetBuyerPrice(AHB_BLUE));
1410 sLog.outError("buyerPricePurple = %u", config->GetBuyerPrice(AHB_PURPLE));
1411 sLog.outError("buyerPriceOrange = %u", config->GetBuyerPrice(AHB_ORANGE));
1412 sLog.outError("buyerPriceYellow = %u", config->GetBuyerPrice(AHB_YELLOW));
1414 //load bidding interval
1415 config->SetBiddingInterval(CharacterDatabase.PQuery("SELECT buyerbiddinginterval FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1416 if(debug_Out)
1417 {sLog.outError("buyerBiddingInterval = %u", config->GetBiddingInterval());}
1418 //load bids per interval
1419 config->SetBidsPerInterval(CharacterDatabase.PQuery("SELECT buyerbidsperinterval FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1420 if(debug_Out)
1421 {sLog.outError("buyerBidsPerInterval = %u", config->GetBidsPerInterval());}