AHBot for 3.1.x
[AHbot.git] / src / game / AuctionHouseBot.cpp
blob6eee812f385cf37017798e983f1813f45ab726da
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.GetIntDefault("AuctionHouseBot.DEBUG", 0);
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 // Do we have anything to bid? If not, stop here.
507 if(possibleBids.empty())
509 return;
512 // Choose random auction from possible auctions
513 uint32 auctionID = possibleBids[urand(0, possibleBids.size() - 1)];
515 // from auctionhousehandler.cpp, creates auction pointer & player pointer
516 AuctionEntry* auction = auctionHouse->GetAuction(auctionID);
518 // get exact item information
519 Item *pItem = auctionmgr.GetAItem(auction->item_guidlow);
520 if (!pItem)
522 sLog.outError("Item doesn't exists, perhaps bought already?");
523 return;
526 // get item prototype
527 ItemPrototype const* prototype = objmgr.GetItemPrototype(auction->item_template);
529 // check which price we have to use, startbid or if it is bidded already
530 if(debug_Out)
532 sLog.outError("Auction Number: %u", auction->Id);
533 sLog.outError("Item Template: %u", auction->item_template);
534 sLog.outError("Buy Price: %u", prototype->BuyPrice);
535 sLog.outError("Sell Price: %u", prototype->SellPrice);
536 sLog.outError("Quality: %u", prototype->Quality);
538 uint32 currentprice;
539 if(auction->bid)
541 currentprice = auction->bid;
542 if(debug_Out)
543 {sLog.outError("Current Price: %u", auction->bid);}
545 else
547 currentprice = auction->startbid;
548 if(debug_Out)
549 {sLog.outError("Current Price: %u", auction->startbid);}
551 uint32 bidprice;
553 // Prepare portion from maximum bid
554 uint32 tmprate2 = urand(0, 100);
555 double tmprate = static_cast<double>(tmprate2);
556 if(debug_Out)
557 {sLog.outError("tmprate: %f", tmprate);}
558 double bidrate = tmprate / 100;
559 if(debug_Out)
560 {sLog.outError("bidrate: %f", bidrate);}
561 long double bidMax = 0;
563 // check that bid has acceptable value and take bid based on vendorprice, stacksize and quality
564 switch (BuyMethod)
566 case 0:
567 switch (prototype->Quality)
569 case 0:
570 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREY))
572 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREY);
574 break;
575 case 1:
576 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_WHITE))
578 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_WHITE);
580 break;
581 case 2:
582 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREEN))
584 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))
590 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_BLUE);
592 break;
593 case 4:
594 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_PURPLE))
596 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_PURPLE);
598 case 5:
599 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE))
601 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE);
603 case 6:
604 if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW))
606 bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW);
608 break;
609 default:
610 // quality is something it shouldn't be, let's get out of here
611 if(debug_Out)
612 {sLog.outError("bidMax(fail): %f", bidMax);}
613 return;
614 break;
616 break;
617 case 1:
618 switch (prototype->Quality)
620 case 0:
621 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREY))
623 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREY);
625 break;
626 case 1:
627 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_WHITE))
629 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_WHITE);
631 break;
632 case 2:
633 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREEN))
635 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_GREEN);
637 break;
638 case 3:
639 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_BLUE))
641 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_BLUE);
643 break;
644 case 4:
645 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_PURPLE))
647 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_PURPLE);
649 case 5:
650 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE))
652 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE);
654 case 6:
655 if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW))
657 bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW);
659 break;
660 default:
661 // quality is something it shouldn't be, let's get out of here
662 if(debug_Out)
663 {sLog.outError("bidMax(fail): %f", bidMax);}
664 return;
665 break;
667 break;
668 default:
669 bidMax = 0;
670 break;
672 if(debug_Out)
673 {sLog.outError("bidMax(succeed): %f", bidMax);}
675 // check some special items, and do recalculating to their prices
676 switch (prototype->Class)
678 // ammo
679 case 6:
680 bidMax = 0;
681 break;
682 default:
683 break;
686 if(bidMax == 0)
688 // quality check failed to get bidmax, let's get out of here
689 return;
692 // Calculate our bid
693 long double bidvalue = currentprice + ( (bidMax - currentprice) * bidrate);
694 if(debug_Out)
695 {sLog.outError("bidvalue: %f", bidvalue);}
696 // Convert to uint32
697 bidprice = static_cast<uint32>(bidvalue);
698 if(debug_Out)
699 {sLog.outError("bidprice: %u", bidprice);}
701 // Check our bid is high enough to be valid. If not, correct it to minimum.
702 if((currentprice + auction->GetAuctionOutBid()) > bidprice)
704 bidprice = currentprice + auction->GetAuctionOutBid();
705 if(debug_Out)
706 {sLog.outError("bidprice(>): %u", bidprice);}
709 // Check wether we do normal bid, or buyout
710 if ((bidprice < auction->buyout) || (auction->buyout == 0))
713 if (auction->bidder > 0)
715 if ( auction->bidder == AHBplayer->GetGUIDLow() )
717 //pl->ModifyMoney( -int32(price - auction->bid));
719 else
721 // mail to last bidder and return money
722 session->SendAuctionOutbiddedMail( auction , bidprice );
723 //pl->ModifyMoney( -int32(price) );
727 auction->bidder = AHBplayer->GetGUIDLow();
728 auction->bid = bidprice;
730 // Saving auction into database
731 CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id);
733 else
735 //buyout
736 if (AHBplayer->GetGUIDLow() == auction->bidder )
738 //pl->ModifyMoney(-int32(auction->buyout - auction->bid));
740 else
742 //pl->ModifyMoney(-int32(auction->buyout));
743 if ( auction->bidder )
745 session->SendAuctionOutbiddedMail( auction, auction->buyout );
748 auction->bidder = AHBplayer->GetGUIDLow();
749 auction->bid = auction->buyout;
751 // Send mails to buyer & seller
752 auctionmgr.SendAuctionSuccessfulMail( auction );
753 auctionmgr.SendAuctionWonMail( auction );
755 // Remove item from auctionhouse
756 auctionmgr.RemoveAItem(auction->item_guidlow);
757 // Remove auction
758 auctionHouse->RemoveAuction(auction->Id);
759 // Remove from database
760 auction->DeleteFromDB();
762 delete auction;
765 ///////////////////////////////////////////////////////////////////////////////
767 ///////////////////////////////////////////////////////////////////////////////
768 void AuctionHouseBot()
770 time_t _newrun = time(NULL);
771 if ((!AHBSeller) && (!AHBBuyer))
772 return;
774 WorldSession _session(AHBplayerAccount, NULL, SEC_PLAYER, true, 0, LOCALE_enUS);
775 Player _AHBplayer(&_session);
776 _AHBplayer.MinimalLoadFromDB(NULL, AHBplayerGUID);
777 ObjectAccessor::Instance().AddObject(&_AHBplayer);
779 if(!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
781 addNewAuctions(&_AHBplayer, &AllianceConfig);
782 if (((_newrun - _lastrun_a) > (AllianceConfig.GetBiddingInterval() * 60)) && (AllianceConfig.GetBidsPerInterval() > 0))
784 uint32 bids = AllianceConfig.GetBidsPerInterval();
785 for (uint32 count = 1;count <= bids;count++)
787 addNewAuctionBuyerBotBid(&_AHBplayer, &AllianceConfig, &_session);
788 _lastrun_a = _newrun;
791 addNewAuctions(&_AHBplayer, &HordeConfig);
792 if (((_newrun - _lastrun_h) > (HordeConfig.GetBiddingInterval() *60)) && (HordeConfig.GetBidsPerInterval() > 0))
794 uint32 bids = HordeConfig.GetBidsPerInterval();
795 for (uint32 count = 1;count <= bids;count++)
797 addNewAuctionBuyerBotBid(&_AHBplayer, &HordeConfig, &_session);
798 _lastrun_h = _newrun;
802 addNewAuctions(&_AHBplayer, &NeutralConfig);
803 if (((_newrun - _lastrun_n) > (NeutralConfig.GetBiddingInterval() * 60)) && (NeutralConfig.GetBidsPerInterval() > 0))
805 uint32 bids = NeutralConfig.GetBidsPerInterval();
806 for (uint32 count = 1;count <= bids;count++)
808 addNewAuctionBuyerBotBid(&_AHBplayer, &NeutralConfig, &_session);
809 _lastrun_n = _newrun;
812 ObjectAccessor::Instance().RemoveObject(&_AHBplayer);
814 ///////////////////////////////////////////////////////////////////////////////
816 ///////////////////////////////////////////////////////////////////////////////
817 void AuctionHouseBotInit()
819 AHBSeller = sConfig.GetBoolDefault("AuctionHouseBot.EnableSeller", 0);
820 AHBBuyer = sConfig.GetBoolDefault("AuctionHouseBot.EnableBuyer", 0);
821 No_Bind = sConfig.GetBoolDefault("AuctionHouseBot.No_Bind", 1);
822 Bind_When_Picked_Up = sConfig.GetBoolDefault("AuctionHouseBot.Bind_When_Picked_Up", 0);
823 Bind_When_Equipped = sConfig.GetBoolDefault("AuctionHouseBot.Bind_When_Equipped", 1);
824 Bind_When_Use = sConfig.GetBoolDefault("AuctionHouseBot.Bind_When_Use", 1);
825 Bind_Quest_Item = sConfig.GetBoolDefault("AuctionHouseBot.Bind_Quest_Item", 0);
827 if(!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
829 AuctionHouseBotLoadValues(&AllianceConfig);
830 AuctionHouseBotLoadValues(&HordeConfig);
832 AuctionHouseBotLoadValues(&NeutralConfig);
834 if (AHBSeller)
836 Vendor_Items = sConfig.GetBoolDefault("AuctionHouseBot.VendorItems", 0);
837 Loot_Items = sConfig.GetBoolDefault("AuctionHouseBot.LootItems", 1);
838 Other_Items = sConfig.GetBoolDefault("AuctionHouseBot.OtherItems", 0);
840 QueryResult* results = (QueryResult*) NULL;
841 char npcQuery[] = "SELECT distinct `item` FROM `npc_vendor`";
842 results = WorldDatabase.PQuery(npcQuery);
843 if (results != NULL)
847 Field* fields = results->Fetch();
848 npcItems.push_back(fields[0].GetUInt32());
850 } while (results->NextRow());
852 delete results;
854 else
856 sLog.outString("AuctionHouseBot: \"%s\" failed", npcQuery);
859 char lootQuery[] = "SELECT `item` FROM `creature_loot_template` UNION "
860 "SELECT `item` FROM `disenchant_loot_template` UNION "
861 "SELECT `item` FROM `fishing_loot_template` UNION "
862 "SELECT `item` FROM `gameobject_loot_template` UNION "
863 "SELECT `item` FROM `item_loot_template` UNION "
864 "SELECT `item` FROM `pickpocketing_loot_template` UNION "
865 "SELECT `item` FROM `prospecting_loot_template` UNION "
866 "SELECT `item` FROM `skinning_loot_template`";
868 results = WorldDatabase.PQuery(lootQuery);
869 if (results != NULL)
873 Field* fields = results->Fetch();
874 lootItems.push_back(fields[0].GetUInt32());
876 } while (results->NextRow());
878 delete results;
880 else
882 sLog.outString("AuctionHouseBot: \"%s\" failed", lootQuery);
885 for (uint32 itemID = 0; itemID < sItemStorage.MaxEntry; itemID++)
887 ItemPrototype const* prototype = objmgr.GetItemPrototype(itemID);
889 if (prototype == NULL)
890 continue;
892 switch (prototype->Bonding)
894 case 0:
895 if (!No_Bind)
896 continue;
897 break;
898 case 1:
899 if (!Bind_When_Picked_Up)
900 continue;
901 break;
902 case 2:
903 if (!Bind_When_Equipped)
904 continue;
905 break;
906 case 3:
907 if (!Bind_When_Use)
908 continue;
909 break;
910 case 4:
911 if (!Bind_Quest_Item)
912 continue;
913 break;
914 default:
915 continue;
916 break;
919 switch (SellMethod)
921 case 0:
922 if (prototype->SellPrice == 0)
923 continue;
924 break;
925 case 1:
926 if (prototype->BuyPrice == 0)
927 continue;
928 break;
929 default:
930 continue;
931 break;
934 if ((prototype->Quality < 0) || (prototype->Quality > 6))
935 continue;
937 if (Vendor_Items == 0)
939 bool isVendorItem = false;
941 for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorItem); i++)
943 if (itemID == npcItems[i])
944 isVendorItem = true;
947 if (isVendorItem)
948 continue;
951 if (Loot_Items == 0)
953 bool isLootItem = false;
955 for (unsigned int i = 0; (i < lootItems.size()) && (!isLootItem); i++)
957 if (itemID == lootItems[i])
958 isLootItem = true;
961 if (isLootItem)
962 continue;
965 if (Other_Items == 0)
967 bool isVendorItem = false;
968 bool isLootItem = false;
970 for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorItem); i++)
972 if (itemID == npcItems[i])
973 isVendorItem = true;
975 for (unsigned int i = 0; (i < lootItems.size()) && (!isLootItem); i++)
977 if (itemID == lootItems[i])
978 isLootItem = true;
980 if ((!isLootItem) && (!isVendorItem))
981 continue;
984 switch (prototype->Quality)
986 case 0:
987 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
988 greyTradeGoodsBin.push_back(itemID);
989 else
990 greyItemsBin.push_back(itemID);
991 break;
993 case 1:
994 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
995 whiteTradeGoodsBin.push_back(itemID);
996 else
997 whiteItemsBin.push_back(itemID);
998 break;
1000 case 2:
1001 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
1002 greenTradeGoodsBin.push_back(itemID);
1003 else
1004 greenItemsBin.push_back(itemID);
1005 break;
1007 case 3:
1008 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
1009 blueTradeGoodsBin.push_back(itemID);
1010 else
1011 blueItemsBin.push_back(itemID);
1012 break;
1014 case 4:
1015 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
1016 purpleTradeGoodsBin.push_back(itemID);
1017 else
1018 purpleItemsBin.push_back(itemID);
1019 break;
1021 case 5:
1022 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
1023 orangeTradeGoodsBin.push_back(itemID);
1024 else
1025 orangeItemsBin.push_back(itemID);
1026 break;
1028 case 6:
1029 if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
1030 yellowTradeGoodsBin.push_back(itemID);
1031 else
1032 yellowItemsBin.push_back(itemID);
1033 break;
1037 if (
1038 (greyTradeGoodsBin.size() == 0) &&
1039 (whiteTradeGoodsBin.size() == 0) &&
1040 (greenTradeGoodsBin.size() == 0) &&
1041 (blueTradeGoodsBin.size() == 0) &&
1042 (purpleTradeGoodsBin.size() == 0) &&
1043 (orangeTradeGoodsBin.size() == 0) &&
1044 (yellowTradeGoodsBin.size() == 0) &&
1045 (greyItemsBin.size() == 0) &&
1046 (whiteItemsBin.size() == 0) &&
1047 (greenItemsBin.size() == 0) &&
1048 (blueItemsBin.size() == 0) &&
1049 (purpleItemsBin.size() == 0) &&
1050 (orangeItemsBin.size() == 0) &&
1051 (yellowItemsBin.size() == 0)
1054 sLog.outString("AuctionHouseBot: No items");
1055 AHBSeller = 0;
1058 sLog.outString("AuctionHouseBot:");
1059 sLog.outString("loaded %d grey trade goods", greyTradeGoodsBin.size());
1060 sLog.outString("loaded %d white trade goods", whiteTradeGoodsBin.size());
1061 sLog.outString("loaded %d green trade goods", greenTradeGoodsBin.size());
1062 sLog.outString("loaded %d blue trade goods", blueTradeGoodsBin.size());
1063 sLog.outString("loaded %d purple trade goods", purpleTradeGoodsBin.size());
1064 sLog.outString("loaded %d orange trade goods", orangeTradeGoodsBin.size());
1065 sLog.outString("loaded %d yellow trade goods", yellowTradeGoodsBin.size());
1066 sLog.outString("loaded %d grey items", greyItemsBin.size());
1067 sLog.outString("loaded %d white items", whiteItemsBin.size());
1068 sLog.outString("loaded %d green items", greenItemsBin.size());
1069 sLog.outString("loaded %d blue items", blueItemsBin.size());
1070 sLog.outString("loaded %d purple items", purpleItemsBin.size());
1071 sLog.outString("loaded %d orange items", orangeItemsBin.size());
1072 sLog.outString("loaded %d yellow items", yellowItemsBin.size());
1074 sLog.outString("AuctionHouseBot by Paradox (original by ChrisK) has been loaded.");
1075 sLog.outString("AuctionHouseBot now includes AHBuyer by Kerbe and Paradox");
1078 void AuctionHouseBotCommands(uint32 command, uint32 ahMapID, uint32 col, char* args)
1080 AHBConfig *config;
1081 switch (ahMapID)
1083 case 2:
1084 config = &AllianceConfig;
1085 break;
1086 case 6:
1087 config = &HordeConfig;
1088 break;
1089 case 7:
1090 config = &NeutralConfig;
1091 break;
1093 std::string color;
1094 switch (col)
1096 case AHB_GREY:
1097 color = "grey";
1098 break;
1099 case AHB_WHITE:
1100 color = "white";
1101 break;
1102 case AHB_GREEN:
1103 color = "green";
1104 break;
1105 case AHB_BLUE:
1106 color = "blue";
1107 break;
1108 case AHB_PURPLE:
1109 color = "purple";
1110 break;
1111 case AHB_ORANGE:
1112 color = "orange";
1113 break;
1114 case AHB_YELLOW:
1115 color = "yellow";
1116 break;
1117 default:
1118 break;
1120 switch (command)
1122 case 0: //ahexpire
1124 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
1126 AuctionHouseObject::AuctionEntryMap::iterator itr;
1127 itr = auctionHouse->GetAuctionsBegin();
1129 while (itr != auctionHouse->GetAuctionsEnd())
1131 if (itr->second->owner == AHBplayerGUID)
1132 itr->second->expire_time = sWorld.GetGameTime();
1134 ++itr;
1136 }break;
1137 case 1: //min items
1139 char * param1 = strtok(args, " ");
1140 uint32 minItems = (uint32) strtoul(param1, NULL, 0);
1141 CharacterDatabase.PExecute("UPDATE auctionhousebot SET minitems = '%u' WHERE auctionhouse = '%u'", minItems, ahMapID);
1142 config->SetMinItems(minItems);
1143 }break;
1144 case 2: //max items
1146 char * param1 = strtok(args, " ");
1147 uint32 maxItems = (uint32) strtoul(param1, NULL, 0);
1148 CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxitems = '%u' WHERE auctionhouse = '%u'", maxItems, ahMapID);
1149 config->SetMaxItems(maxItems);
1150 }break;
1151 case 3: //min time
1153 char * param1 = strtok(args, " ");
1154 uint32 minTime = (uint32) strtoul(param1, NULL, 0);
1155 CharacterDatabase.PExecute("UPDATE auctionhousebot SET mintime = '%u' WHERE auctionhouse = '%u'", minTime, ahMapID);
1156 config->SetMinTime(minTime);
1157 }break;
1158 case 4: //max time
1160 char * param1 = strtok(args, " ");
1161 uint32 maxTime = (uint32) strtoul(param1, NULL, 0);
1162 CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxtime = '%u' WHERE auctionhouse = '%u'", maxTime, ahMapID);
1163 config->SetMaxTime(maxTime);
1164 }break;
1165 case 5: //percentages
1167 char * param1 = strtok(args, " ");
1168 char * param2 = strtok(NULL, " ");
1169 char * param3 = strtok(NULL, " ");
1170 char * param4 = strtok(NULL, " ");
1171 char * param5 = strtok(NULL, " ");
1172 char * param6 = strtok(NULL, " ");
1173 char * param7 = strtok(NULL, " ");
1174 char * param8 = strtok(NULL, " ");
1175 char * param9 = strtok(NULL, " ");
1176 char * param10 = strtok(NULL, " ");
1177 char * param11 = strtok(NULL, " ");
1178 char * param12 = strtok(NULL, " ");
1179 char * param13 = strtok(NULL, " ");
1180 char * param14 = strtok(NULL, " ");
1181 uint32 greytg = (uint32) strtoul(param1, NULL, 0);
1182 uint32 whitetg = (uint32) strtoul(param2, NULL, 0);
1183 uint32 greentg = (uint32) strtoul(param3, NULL, 0);
1184 uint32 bluetg = (uint32) strtoul(param4, NULL, 0);
1185 uint32 purpletg = (uint32) strtoul(param5, NULL, 0);
1186 uint32 orangetg = (uint32) strtoul(param6, NULL, 0);
1187 uint32 yellowtg = (uint32) strtoul(param7, NULL, 0);
1188 uint32 greyi = (uint32) strtoul(param8, NULL, 0);
1189 uint32 whitei = (uint32) strtoul(param9, NULL, 0);
1190 uint32 greeni = (uint32) strtoul(param10, NULL, 0);
1191 uint32 bluei = (uint32) strtoul(param11, NULL, 0);
1192 uint32 purplei = (uint32) strtoul(param12, NULL, 0);
1193 uint32 orangei = (uint32) strtoul(param13, NULL, 0);
1194 uint32 yellowi = (uint32) strtoul(param14, NULL, 0);
1196 CharacterDatabase.BeginTransaction();
1197 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreytradegoods = '%u' WHERE auctionhouse = '%u'", greytg, ahMapID);
1198 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentwhitetradegoods = '%u' WHERE auctionhouse = '%u'", whitetg, ahMapID);
1199 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreentradegoods = '%u' WHERE auctionhouse = '%u'", greentg, ahMapID);
1200 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentbluetradegoods = '%u' WHERE auctionhouse = '%u'", bluetg, ahMapID);
1201 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentpurpletradegoods = '%u' WHERE auctionhouse = '%u'", purpletg, ahMapID);
1202 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentorangetradegoods = '%u' WHERE auctionhouse = '%u'", orangetg, ahMapID);
1203 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentyellowtradegoods = '%u' WHERE auctionhouse = '%u'", yellowtg, ahMapID);
1204 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreyitems = '%u' WHERE auctionhouse = '%u'", greyi, ahMapID);
1205 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentwhiteitems = '%u' WHERE auctionhouse = '%u'", whitei, ahMapID);
1206 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreenitems = '%u' WHERE auctionhouse = '%u'", greeni, ahMapID);
1207 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentblueitems = '%u' WHERE auctionhouse = '%u'", bluei, ahMapID);
1208 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentpurpleitems = '%u' WHERE auctionhouse = '%u'", purplei, ahMapID);
1209 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentorangeitems = '%u' WHERE auctionhouse = '%u'", orangei, ahMapID);
1210 CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentyellowitems = '%u' WHERE auctionhouse = '%u'", yellowi, ahMapID);
1211 CharacterDatabase.CommitTransaction();
1212 config->SetPercentages(greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi);
1213 }break;
1214 case 6: //min prices
1216 char * param1 = strtok(args, " ");
1217 uint32 minPrice = (uint32) strtoul(param1, NULL, 0);
1218 CharacterDatabase.PExecute("UPDATE auctionhousebot SET minprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), minPrice, ahMapID);
1219 config->SetMinPrice(col, minPrice);
1220 }break;
1221 case 7: //max prices
1223 char * param1 = strtok(args, " ");
1224 uint32 maxPrice = (uint32) strtoul(param1, NULL, 0);
1225 CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), maxPrice, ahMapID);
1226 config->SetMaxPrice(col, maxPrice);
1227 }break;
1228 case 8: //min bid price
1230 char * param1 = strtok(args, " ");
1231 uint32 minBidPrice = (uint32) strtoul(param1, NULL, 0);
1232 CharacterDatabase.PExecute("UPDATE auctionhousebot SET minbidprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), minBidPrice, ahMapID);
1233 config->SetMinBidPrice(col, minBidPrice);
1234 }break;
1235 case 9: //max bid price
1237 char * param1 = strtok(args, " ");
1238 uint32 maxBidPrice = (uint32) strtoul(param1, NULL, 0);
1239 CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxbidprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), maxBidPrice, ahMapID);
1240 config->SetMaxBidPrice(col, maxBidPrice);
1241 }break;
1242 case 10: //max stacks
1244 char * param1 = strtok(args, " ");
1245 uint32 maxStack = (uint32) strtoul(param1, NULL, 0);
1246 CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxstack%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), maxStack, ahMapID);
1247 config->SetMaxStack(col, maxStack);
1248 }break;
1249 case 11: //buyer bid prices
1251 char * param1 = strtok(args, " ");
1252 uint32 buyerPrice = (uint32) strtoul(param1, NULL, 0);
1253 CharacterDatabase.PExecute("UPDATE auctionhousebot SET buyerprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), buyerPrice, ahMapID);
1254 config->SetBuyerPrice(col, buyerPrice);
1255 }break;
1256 case 12: //buyer bidding interval
1258 char * param1 = strtok(args, " ");
1259 uint32 bidInterval = (uint32) strtoul(param1, NULL, 0);
1260 CharacterDatabase.PExecute("UPDATE auctionhousebot SET buyerbiddinginterval = '%u' WHERE auctionhouse = '%u'", bidInterval, ahMapID);
1261 config->SetBiddingInterval(bidInterval);
1262 }break;
1263 case 13: //buyer bids per interval
1265 char * param1 = strtok(args, " ");
1266 uint32 bidsPerInterval = (uint32) strtoul(param1, NULL, 0);
1267 CharacterDatabase.PExecute("UPDATE auctionhousebot SET buyerbidsperinterval = '%u' WHERE auctionhouse = '%u'", bidsPerInterval, ahMapID);
1268 config->SetBidsPerInterval(bidsPerInterval);
1269 }break;
1270 default:
1271 break;
1274 void AuctionHouseBotLoadValues(AHBConfig *config)
1276 if (AHBSeller)
1278 //load min and max items
1279 config->SetMinItems(CharacterDatabase.PQuery("SELECT minitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1280 config->SetMaxItems(CharacterDatabase.PQuery("SELECT maxitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1281 if(debug_Out)
1282 {sLog.outError("minItems = %u", config->GetMinItems());
1283 sLog.outError("maxItems = %u", config->GetMaxItems());}
1284 //load min and max auction times
1285 config->SetMinTime(CharacterDatabase.PQuery("SELECT mintime FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1286 config->SetMaxTime(CharacterDatabase.PQuery("SELECT maxtime FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1287 if(debug_Out)
1288 {sLog.outError("minTime = %u", config->GetMinTime());
1289 sLog.outError("maxTime = %u", config->GetMaxTime());}
1290 //load percentages
1291 uint32 greytg = CharacterDatabase.PQuery("SELECT percentgreytradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1292 uint32 whitetg = CharacterDatabase.PQuery("SELECT percentwhitetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1293 uint32 greentg = CharacterDatabase.PQuery("SELECT percentgreentradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1294 uint32 bluetg = CharacterDatabase.PQuery("SELECT percentbluetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1295 uint32 purpletg = CharacterDatabase.PQuery("SELECT percentpurpletradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1296 uint32 orangetg = CharacterDatabase.PQuery("SELECT percentorangetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1297 uint32 yellowtg = CharacterDatabase.PQuery("SELECT percentyellowtradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1298 uint32 greyi = CharacterDatabase.PQuery("SELECT percentgreyitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1299 uint32 whitei = CharacterDatabase.PQuery("SELECT percentwhiteitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1300 uint32 greeni = CharacterDatabase.PQuery("SELECT percentgreenitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1301 uint32 bluei = CharacterDatabase.PQuery("SELECT percentblueitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1302 uint32 purplei = CharacterDatabase.PQuery("SELECT percentpurpleitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1303 uint32 orangei = CharacterDatabase.PQuery("SELECT percentorangeitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1304 uint32 yellowi = CharacterDatabase.PQuery("SELECT percentyellowitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32();
1305 config->SetPercentages(greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi);
1306 if(debug_Out)
1308 sLog.outError("percentGreyTradeGoods = %u", config->GetPercentages(AHB_GREY_TG));
1309 sLog.outError("percentWhiteTradeGoods = %u", config->GetPercentages(AHB_WHITE_TG));
1310 sLog.outError("percentGreenTradeGoods = %u", config->GetPercentages(AHB_GREEN_TG));
1311 sLog.outError("percentBlueTradeGoods = %u", config->GetPercentages(AHB_BLUE_TG));
1312 sLog.outError("percentPurpleTradeGoods = %u", config->GetPercentages(AHB_PURPLE_TG));
1313 sLog.outError("percentOrangeTradeGoods = %u", config->GetPercentages(AHB_ORANGE_TG));
1314 sLog.outError("percentYellowTradeGoods = %u", config->GetPercentages(AHB_YELLOW_TG));
1315 sLog.outError("percentGreyItems = %u", config->GetPercentages(AHB_GREY_I));
1316 sLog.outError("percentWhiteItems = %u", config->GetPercentages(AHB_WHITE_I));
1317 sLog.outError("percentGreenItems = %u", config->GetPercentages(AHB_GREEN_I));
1318 sLog.outError("percentBlueItems = %u", config->GetPercentages(AHB_BLUE_I));
1319 sLog.outError("percentPurpleItems = %u", config->GetPercentages(AHB_PURPLE_I));
1320 sLog.outError("percentOrangeItems = %u", config->GetPercentages(AHB_ORANGE_I));
1321 sLog.outError("percentYellowItems = %u", config->GetPercentages(AHB_YELLOW_I));
1323 //load min and max prices
1324 config->SetMinPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT minpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1325 config->SetMaxPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT maxpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1326 if(debug_Out)
1327 {sLog.outError("minPriceGrey = %u", config->GetMinPrice(AHB_GREY));
1328 sLog.outError("maxPriceGrey = %u", config->GetMaxPrice(AHB_GREY));}
1329 config->SetMinPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT minpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1330 config->SetMaxPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT maxpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1331 if(debug_Out)
1332 {sLog.outError("minPriceWhite = %u", config->GetMinPrice(AHB_WHITE));
1333 sLog.outError("maxPriceWhite = %u", config->GetMaxPrice(AHB_WHITE));}
1334 config->SetMinPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT minpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1335 config->SetMaxPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT maxpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1336 if(debug_Out)
1337 {sLog.outError("minPriceGreen = %u", config->GetMinPrice(AHB_GREEN));
1338 sLog.outError("maxPriceGreen = %u", config->GetMaxPrice(AHB_GREEN));}
1339 config->SetMinPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT minpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1340 config->SetMaxPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT maxpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1341 if(debug_Out)
1342 {sLog.outError("minPriceBlue = %u", config->GetMinPrice(AHB_BLUE));
1343 sLog.outError("maxPriceBlue = %u", config->GetMaxPrice(AHB_BLUE));}
1344 config->SetMinPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT minpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1345 config->SetMaxPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT maxpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1346 if(debug_Out)
1347 {sLog.outError("minPricePurple = %u", config->GetMinPrice(AHB_PURPLE));
1348 sLog.outError("maxPricePurple = %u", config->GetMaxPrice(AHB_PURPLE));}
1349 config->SetMinPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT minpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1350 config->SetMaxPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT maxpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1351 if(debug_Out)
1352 {sLog.outError("minPriceOrange = %u", config->GetMinPrice(AHB_ORANGE));
1353 sLog.outError("maxPriceOrange = %u", config->GetMaxPrice(AHB_ORANGE));}
1354 config->SetMinPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT minpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1355 config->SetMaxPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT maxpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1356 if(debug_Out)
1357 {sLog.outError("minPriceYellow = %u", config->GetMinPrice(AHB_YELLOW));
1358 sLog.outError("maxPriceYellow = %u", config->GetMaxPrice(AHB_YELLOW));}
1359 //load min and max bid prices
1360 config->SetMinBidPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT minbidpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1361 if(debug_Out)
1362 {sLog.outError(",minBidPriceGrey = %u", config->GetMinBidPrice(AHB_GREY));}
1363 config->SetMaxBidPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT maxbidpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1364 if(debug_Out)
1365 {sLog.outError("maxBidPriceGrey = %u", config->GetMaxBidPrice(AHB_GREY));}
1366 config->SetMinBidPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT minbidpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1367 if(debug_Out)
1368 {sLog.outError(",minBidPriceWhite = %u", config->GetMinBidPrice(AHB_WHITE));}
1369 config->SetMaxBidPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT maxbidpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1370 if(debug_Out)
1371 {sLog.outError("maxBidPriceWhite = %u", config->GetMaxBidPrice(AHB_WHITE));}
1372 config->SetMinBidPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT minbidpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1373 if(debug_Out)
1374 {sLog.outError("minBidPriceGreen = %u", config->GetMinBidPrice(AHB_GREEN));}
1375 config->SetMaxBidPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT maxbidpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1376 if(debug_Out)
1377 {sLog.outError("maxBidPriceGreen = %u", config->GetMaxBidPrice(AHB_GREEN));}
1378 config->SetMinBidPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT minbidpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1379 if(debug_Out)
1380 {sLog.outError("minBidPriceBlue = %u", config->GetMinBidPrice(AHB_BLUE));}
1381 config->SetMaxBidPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT maxbidpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1382 if(debug_Out)
1383 {sLog.outError("maxBidPriceBlue = %u", config->GetMinBidPrice(AHB_BLUE));}
1384 config->SetMinBidPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT minbidpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1385 if(debug_Out)
1386 {sLog.outError("minBidPricePurple = %u", config->GetMinBidPrice(AHB_PURPLE));}
1387 config->SetMaxBidPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT maxbidpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1388 if(debug_Out)
1389 {sLog.outError("maxBidPricePurple = %u", config->GetMaxBidPrice(AHB_PURPLE));}
1390 config->SetMinBidPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT minbidpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1391 if(debug_Out)
1392 {sLog.outError("minBidPriceOrange = %u", config->GetMinBidPrice(AHB_ORANGE));}
1393 config->SetMaxBidPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT maxbidpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1394 if(debug_Out)
1395 {sLog.outError("maxBidPriceOrange = %u", config->GetMaxBidPrice(AHB_ORANGE));}
1396 config->SetMinBidPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT minbidpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1397 if(debug_Out)
1398 {sLog.outError("minBidPriceYellow = %u", config->GetMinBidPrice(AHB_YELLOW));}
1399 config->SetMaxBidPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT maxbidpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1400 if(debug_Out)
1401 {sLog.outError("maxBidPriceYellow = %u", config->GetMaxBidPrice(AHB_YELLOW));}
1402 //load max stacks
1403 config->SetMaxStack(AHB_GREY, CharacterDatabase.PQuery("SELECT maxstackgrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1404 if(debug_Out)
1405 {sLog.outError("maxStackGrey = %u", config->GetMaxStack(AHB_GREY));}
1406 config->SetMaxStack(AHB_WHITE, CharacterDatabase.PQuery("SELECT maxstackwhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1407 if(debug_Out)
1408 {sLog.outError("maxStackWhite = %u", config->GetMaxStack(AHB_WHITE));}
1409 config->SetMaxStack(AHB_GREEN, CharacterDatabase.PQuery("SELECT maxstackgreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1410 if(debug_Out)
1411 {sLog.outError("maxStackGreen = %u", config->GetMaxStack(AHB_GREEN));}
1412 config->SetMaxStack(AHB_BLUE, CharacterDatabase.PQuery("SELECT maxstackblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1413 if(debug_Out)
1414 {sLog.outError("maxStackBlue = %u", config->GetMaxStack(AHB_BLUE));}
1415 config->SetMaxStack(AHB_PURPLE, CharacterDatabase.PQuery("SELECT maxstackpurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1416 if(debug_Out)
1417 {sLog.outError("maxStackPurple = %u", config->GetMaxStack(AHB_PURPLE));}
1418 config->SetMaxStack(AHB_ORANGE, CharacterDatabase.PQuery("SELECT maxstackorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1419 if(debug_Out)
1420 {sLog.outError("maxStackOrange = %u", config->GetMaxStack(AHB_ORANGE));}
1421 config->SetMaxStack(AHB_YELLOW, CharacterDatabase.PQuery("SELECT maxstackyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1422 if(debug_Out)
1423 {sLog.outError("maxStackYellow = %u", config->GetMaxStack(AHB_YELLOW));}
1425 if (AHBBuyer)
1427 //load buyer bid prices
1428 config->SetBuyerPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT buyerpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1429 config->SetBuyerPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT buyerpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1430 config->SetBuyerPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT buyerpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1431 config->SetBuyerPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT buyerpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1432 config->SetBuyerPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT buyerpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1433 config->SetBuyerPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT buyerpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1434 config->SetBuyerPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT buyerpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1435 if(debug_Out)
1437 sLog.outError("buyerPriceGrey = %u", config->GetBuyerPrice(AHB_GREY));
1438 sLog.outError("buyerPriceWhite = %u", config->GetBuyerPrice(AHB_WHITE));
1439 sLog.outError("buyerPriceGreen = %u", config->GetBuyerPrice(AHB_GREEN));
1440 sLog.outError("buyerPriceBlue = %u", config->GetBuyerPrice(AHB_BLUE));
1441 sLog.outError("buyerPricePurple = %u", config->GetBuyerPrice(AHB_PURPLE));
1442 sLog.outError("buyerPriceOrange = %u", config->GetBuyerPrice(AHB_ORANGE));
1443 sLog.outError("buyerPriceYellow = %u", config->GetBuyerPrice(AHB_YELLOW));
1445 //load bidding interval
1446 config->SetBiddingInterval(CharacterDatabase.PQuery("SELECT buyerbiddinginterval FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1447 if(debug_Out)
1448 {sLog.outError("buyerBiddingInterval = %u", config->GetBiddingInterval());}
1449 //load bids per interval
1450 config->SetBidsPerInterval(CharacterDatabase.PQuery("SELECT buyerbidsperinterval FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32());
1451 if(debug_Out)
1452 {sLog.outError("buyerBidsPerInterval = %u", config->GetBidsPerInterval());}