TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AuctionBotBuyer Class Reference

#include <AuctionHouseBotBuyer.h>

Public Member Functions

 AuctionBotBuyer ()
 
 ~AuctionBotBuyer ()
 
bool Initialize () override
 
bool Update (AuctionHouseType houseType) override
 
void LoadConfig ()
 
void BuyAndBidItems (BuyerConfiguration &config)
 
- Public Member Functions inherited from AuctionBotAgent
 AuctionBotAgent ()
 
virtual ~AuctionBotAgent ()
 

Private Member Functions

void LoadBuyerValues (BuyerConfiguration &config)
 
bool RollBuyChance (const BuyerItemInfo *ahInfo, const Item *item, const AuctionEntry *auction, uint32 bidPrice)
 
bool RollBidChance (const BuyerItemInfo *ahInfo, const Item *item, const AuctionEntry *auction, uint32 bidPrice)
 
void PlaceBidToEntry (AuctionEntry *auction, uint32 bidPrice)
 
void BuyEntry (AuctionEntry *auction, AuctionHouseObject *auctionHouse)
 
void PrepareListOfEntry (BuyerConfiguration &config)
 
uint32 GetItemInformation (BuyerConfiguration &config)
 
uint32 GetVendorPrice (uint32 quality)
 
uint32 GetChanceMultiplier (uint32 quality)
 

Private Attributes

uint32 _checkInterval
 
BuyerConfiguration _houseConfig [MAX_AUCTION_HOUSE_TYPE]
 

Constructor & Destructor Documentation

AuctionBotBuyer::AuctionBotBuyer ( )
23  : _checkInterval(20 * MINUTE)
24 {
25  // Define faction for our main data class.
26  for (int i = 0; i < MAX_AUCTION_HOUSE_TYPE; ++i)
28 }
uint32 _checkInterval
Definition: AuctionHouseBotBuyer.h:83
AuctionHouseType
Definition: AuctionHouseBot.h:40
BuyerConfiguration _houseConfig[MAX_AUCTION_HOUSE_TYPE]
Definition: AuctionHouseBotBuyer.h:84
Definition: Common.h:97
#define MAX_AUCTION_HOUSE_TYPE
Definition: AuctionHouseBot.h:47
bool Initialize() override
Definition: AuctionHouseBotBuyer.cpp:34

+ Here is the call graph for this function:

AuctionBotBuyer::~AuctionBotBuyer ( )
31 {
32 }

Member Function Documentation

void AuctionBotBuyer::BuyAndBidItems ( BuyerConfiguration config)
253 {
254  time_t now = time(nullptr);
255  AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config.GetHouseType());
256  CheckEntryMap& items = config.EligibleItems;
257 
258  // Max amount of items to buy or bid
259  uint32 cycles = sAuctionBotConfig->GetItemPerCycleNormal();
260  if (items.size() > sAuctionBotConfig->GetItemPerCycleBoost())
261  {
262  // set more cycles if there is a huge influx of items
263  cycles = sAuctionBotConfig->GetItemPerCycleBoost();
264  TC_LOG_DEBUG("ahbot", "AHBot: Boost value used for Buyer! (if this happens often adjust both ItemsPerCycle in worldserver.conf)");
265  }
266 
267  // Process items eligible to be bidded or bought
268  CheckEntryMap::iterator itr = items.begin();
269  while (cycles && itr != items.end())
270  {
271  AuctionEntry* auction = auctionHouse->GetAuction(itr->second.AuctionId);
272  if (!auction)
273  {
274  TC_LOG_DEBUG("ahbot", "AHBot: Entry %u doesn't exists, perhaps bought already?", itr->second.AuctionId);
275  items.erase(itr++);
276  continue;
277  }
278 
279  // Check if the item has been checked once before
280  // If it has been checked and it was recently, skip it
281  if (itr->second.LastChecked && (now - itr->second.LastChecked) <= _checkInterval)
282  {
283  TC_LOG_DEBUG("ahbot", "AHBot: In time interval wait for entry %u!", auction->Id);
284  ++itr;
285  continue;
286  }
287 
288  Item* item = sAuctionMgr->GetAItem(auction->itemGUIDLow);
289  if (!item)
290  {
291  // auction item not accessible, possible auction in payment pending mode
292  items.erase(itr++);
293  continue;
294  }
295 
296  // price to bid if bidding
297  uint32 bidPrice;
298  if (auction->bid >= auction->startbid)
299  {
300  // get bid price to outbid previous bidder
301  bidPrice = auction->bid + auction->GetAuctionOutBid();
302  }
303  else
304  {
305  // no previous bidders - use starting bid
306  bidPrice = auction->startbid;
307  }
308 
309  const BuyerItemInfo* ahInfo = nullptr;
310  BuyerItemInfoMap::const_iterator sameItemItr = config.SameItemInfo.find(item->GetEntry());
311  if (sameItemItr != config.SameItemInfo.end())
312  ahInfo = &sameItemItr->second;
313 
314  TC_LOG_DEBUG("ahbot", "AHBot: Rolling for AHentry %u:", auction->Id);
315 
316  // Roll buy and bid chances
317  bool successBuy = RollBuyChance(ahInfo, item, auction, bidPrice);
318  bool successBid = RollBidChance(ahInfo, item, auction, bidPrice);
319 
320  // If roll bidding succesfully and bid price is above buyout -> buyout
321  // If roll for buying was successful but not for bid, buyout directly
322  // If roll bidding was also successful, buy the entry with 20% chance
323  // - Better bid than buy since the item is bought by bot if no player bids after
324  // Otherwise bid if roll for bid was successful
325  if ((auction->buyout && successBid && bidPrice >= auction->buyout) ||
326  (successBuy && (!successBid || urand(1, 5) == 1)))
327  BuyEntry(auction, auctionHouse); // buyout
328  else if (successBid)
329  PlaceBidToEntry(auction, bidPrice); // bid
330 
331  itr->second.LastChecked = now;
332  --cycles;
333  ++itr;
334  }
335 
336  // Clear not needed entries
337  config.SameItemInfo.clear();
338 }
uint32 _checkInterval
Definition: AuctionHouseBotBuyer.h:83
#define sAuctionBotConfig
Definition: AuctionHouseBot.h:252
AuctionEntry * GetAuction(uint32 id) const
Definition: AuctionHouseMgr.h:116
ObjectGuid::LowType itemGUIDLow
Definition: AuctionHouseMgr.h:71
Definition: AuctionHouseMgr.h:67
void BuyEntry(AuctionEntry *auction, AuctionHouseObject *auctionHouse)
Definition: AuctionHouseBotBuyer.cpp:387
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
bool RollBuyChance(const BuyerItemInfo *ahInfo, const Item *item, const AuctionEntry *auction, uint32 bidPrice)
Definition: AuctionHouseBotBuyer.cpp:159
AuctionHouseType GetHouseType() const
Definition: AuctionHouseBotBuyer.h:58
uint32 Id
Definition: AuctionHouseMgr.h:69
BuyerItemInfoMap SameItemInfo
Definition: AuctionHouseBotBuyer.h:60
bool RollBidChance(const BuyerItemInfo *ahInfo, const Item *item, const AuctionEntry *auction, uint32 bidPrice)
Definition: AuctionHouseBotBuyer.cpp:198
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
Definition: Item.h:259
uint32 startbid
Definition: AuctionHouseMgr.h:75
uint32_t uint32
Definition: Define.h:150
uint32 bid
Definition: AuctionHouseMgr.h:76
CheckEntryMap EligibleItems
Definition: AuctionHouseBotBuyer.h:61
uint32 buyout
Definition: AuctionHouseMgr.h:77
#define sAuctionMgr
Definition: AuctionHouseMgr.h:199
Definition: AuctionHouseMgr.h:100
uint32 GetEntry() const
Definition: Object.h:107
void PlaceBidToEntry(AuctionEntry *auction, uint32 bidPrice)
Definition: AuctionHouseBotBuyer.cpp:418
std::map< uint32, BuyerAuctionEval > CheckEntryMap
Definition: AuctionHouseBotBuyer.h:47
uint32 GetAuctionOutBid() const
the sum of outbid is (1% from current bid)*5, if bid is very small, it is 1c
Definition: AuctionHouseMgr.cpp:794
Definition: AuctionHouseBotBuyer.h:34

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AuctionBotBuyer::BuyEntry ( AuctionEntry auction,
AuctionHouseObject auctionHouse 
)
private
388 {
389  TC_LOG_DEBUG("ahbot", "AHBot: Entry %u bought at %.2fg", auction->Id, float(auction->buyout) / GOLD);
390 
392 
393  // Send mail to previous bidder if any
394  if (auction->bidder)
395  sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, NULL, trans);
396 
397  // Set bot as bidder and set new bid amount
398  auction->bidder = 0;
399  auction->bid = auction->buyout;
400 
401  // Mails must be under transaction control too to prevent data loss
402  sAuctionMgr->SendAuctionSalePendingMail(auction, trans);
403  sAuctionMgr->SendAuctionSuccessfulMail(auction, trans);
404  sAuctionMgr->SendAuctionWonMail(auction, trans);
405 
406  // Delete auction from DB
407  auction->DeleteFromDB(trans);
408 
409  // Remove auction item and auction from memory
410  sAuctionMgr->RemoveAItem(auction->itemGUIDLow);
411  auctionHouse->RemoveAuction(auction);
412 
413  // Run SQLs
415 }
bool RemoveAuction(AuctionEntry *auction)
Definition: AuctionHouseMgr.cpp:564
ObjectGuid::LowType itemGUIDLow
Definition: AuctionHouseMgr.h:71
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
void DeleteFromDB(SQLTransaction &trans) const
Definition: AuctionHouseMgr.cpp:800
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint32 Id
Definition: AuctionHouseMgr.h:69
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
uint32 bid
Definition: AuctionHouseMgr.h:76
Definition: SharedDefines.h:232
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
uint32 buyout
Definition: AuctionHouseMgr.h:77
#define sAuctionMgr
Definition: AuctionHouseMgr.h:199
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 AuctionBotBuyer::GetChanceMultiplier ( uint32  quality)
private
364 {
365  switch (quality)
366  {
367  case ITEM_QUALITY_POOR:
369  case ITEM_QUALITY_NORMAL:
373  case ITEM_QUALITY_RARE:
375  case ITEM_QUALITY_EPIC:
381  default:
382  return 100;
383  }
384 }
Definition: AuctionHouseBot.h:125
#define sAuctionBotConfig
Definition: AuctionHouseBot.h:252
Definition: AuctionHouseBot.h:121
Definition: AuctionHouseBot.h:123
Definition: SharedDefines.h:322
Definition: SharedDefines.h:326
Definition: SharedDefines.h:321
Definition: AuctionHouseBot.h:126
Definition: AuctionHouseBot.h:122
Definition: SharedDefines.h:323
Definition: SharedDefines.h:325
Definition: AuctionHouseBot.h:127
Definition: SharedDefines.h:324
Definition: SharedDefines.h:320
Definition: AuctionHouseBot.h:124

+ Here is the caller graph for this function:

uint32 AuctionBotBuyer::GetItemInformation ( BuyerConfiguration config)
private
96 {
97  config.SameItemInfo.clear();
98  time_t now = time(nullptr);
99  uint32 count = 0;
100 
101  AuctionHouseObject* house = sAuctionMgr->GetAuctionsMap(config.GetHouseType());
102  for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = house->GetAuctionsBegin(); itr != house->GetAuctionsEnd(); ++itr)
103  {
104  AuctionEntry* entry = itr->second;
105 
106  if (!entry->owner)
107  continue; // Skip auctions owned by AHBot
108 
109  Item* item = sAuctionMgr->GetAItem(entry->itemGUIDLow);
110  if (!item)
111  continue;
112 
113  BuyerItemInfo& itemInfo = config.SameItemInfo[item->GetEntry()];
114 
115  // Update item entry's count and total bid prices
116  // This can be used later to determine the prices and chances to bid
117  uint32 itemBidPrice = entry->startbid / item->GetCount();
118  itemInfo.TotalBidPrice = itemInfo.TotalBidPrice + itemBidPrice;
119  itemInfo.BidItemCount++;
120 
121  // Set minimum bid price
122  if (!itemInfo.MinBidPrice)
123  itemInfo.MinBidPrice = itemBidPrice;
124  else
125  itemBidPrice = std::min(itemInfo.MinBidPrice, itemBidPrice);
126 
127  // Set minimum buyout price if item has buyout
128  if (entry->buyout)
129  {
130  // Update item entry's count and total buyout prices
131  // This can be used later to determine the prices and chances to buyout
132  uint32 itemBuyPrice = entry->buyout / item->GetCount();
133  itemInfo.TotalBuyPrice = itemInfo.TotalBuyPrice + itemBuyPrice;
134  itemInfo.BuyItemCount++;
135 
136  if (!itemInfo.MinBuyPrice)
137  itemInfo.MinBuyPrice = itemBuyPrice;
138  else
139  itemInfo.MinBuyPrice = std::min(itemInfo.MinBuyPrice, itemBuyPrice);
140  }
141 
142  // Add/update EligibleItems if:
143  // * no bid
144  // * bid from player
145  if (!entry->bid || entry->bidder)
146  {
147  config.EligibleItems[entry->Id].LastExist = now;
148  config.EligibleItems[entry->Id].AuctionId = entry->Id;
149  ++count;
150  }
151  }
152 
153  TC_LOG_DEBUG("ahbot", "AHBot: %u items added to buyable/biddable vector for ah type: %u", count, config.GetHouseType());
154  TC_LOG_DEBUG("ahbot", "AHBot: SameItemInfo size = %u", (uint32)config.SameItemInfo.size());
155  return count;
156 }
uint32 GetCount() const
Definition: Item.h:322
AuctionEntryMap::iterator GetAuctionsEnd()
Definition: AuctionHouseMgr.h:114
double TotalBidPrice
Definition: AuctionHouseBotBuyer.h:43
uint32 MinBuyPrice
Definition: AuctionHouseBotBuyer.h:40
ObjectGuid::LowType itemGUIDLow
Definition: AuctionHouseMgr.h:71
Definition: AuctionHouseMgr.h:67
AuctionEntryMap::iterator GetAuctionsBegin()
Definition: AuctionHouseMgr.h:113
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint32 BuyItemCount
Definition: AuctionHouseBotBuyer.h:39
AuctionHouseType GetHouseType() const
Definition: AuctionHouseBotBuyer.h:58
uint32 Id
Definition: AuctionHouseMgr.h:69
BuyerItemInfoMap SameItemInfo
Definition: AuctionHouseBotBuyer.h:60
T min(const T &x, const T &y)
Definition: g3dmath.h:305
ObjectGuid::LowType owner
Definition: AuctionHouseMgr.h:74
Definition: Item.h:259
uint32 startbid
Definition: AuctionHouseMgr.h:75
uint32 MinBidPrice
Definition: AuctionHouseBotBuyer.h:41
uint32_t uint32
Definition: Define.h:150
uint32 bid
Definition: AuctionHouseMgr.h:76
CheckEntryMap EligibleItems
Definition: AuctionHouseBotBuyer.h:61
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
uint32 buyout
Definition: AuctionHouseMgr.h:77
uint32 BidItemCount
Definition: AuctionHouseBotBuyer.h:38
#define sAuctionMgr
Definition: AuctionHouseMgr.h:199
Definition: AuctionHouseMgr.h:100
uint32 GetEntry() const
Definition: Object.h:107
Definition: AuctionHouseBotBuyer.h:34
double TotalBuyPrice
Definition: AuctionHouseBotBuyer.h:42

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 AuctionBotBuyer::GetVendorPrice ( uint32  quality)
private
341 {
342  switch (quality)
343  {
344  case ITEM_QUALITY_POOR:
346  case ITEM_QUALITY_NORMAL:
350  case ITEM_QUALITY_RARE:
352  case ITEM_QUALITY_EPIC:
358  default:
359  return 1 * SILVER;
360  }
361 }
Definition: SharedDefines.h:231
#define sAuctionBotConfig
Definition: AuctionHouseBot.h:252
Definition: AuctionHouseBot.h:117
Definition: AuctionHouseBot.h:118
Definition: AuctionHouseBot.h:120
Definition: SharedDefines.h:322
Definition: SharedDefines.h:326
Definition: AuctionHouseBot.h:114
Definition: SharedDefines.h:321
Definition: AuctionHouseBot.h:115
Definition: SharedDefines.h:323
Definition: SharedDefines.h:325
Definition: AuctionHouseBot.h:119
Definition: SharedDefines.h:324
Definition: SharedDefines.h:320
Definition: AuctionHouseBot.h:116

+ Here is the caller graph for this function:

bool AuctionBotBuyer::Initialize ( )
overridevirtual

Implements AuctionBotAgent.

35 {
36  LoadConfig();
37 
38  bool activeHouse = false;
39  for (int i = 0; i < MAX_AUCTION_HOUSE_TYPE; ++i)
40  {
41  if (_houseConfig[i].BuyerEnabled)
42  {
43  activeHouse = true;
44  break;
45  }
46  }
47 
48  if (!activeHouse)
49  return false;
50 
51  // load Check interval
53  TC_LOG_DEBUG("ahbot", "AHBot buyer interval is %u minutes", _checkInterval / MINUTE);
54  return true;
55 }
uint32 _checkInterval
Definition: AuctionHouseBotBuyer.h:83
#define sAuctionBotConfig
Definition: AuctionHouseBot.h:252
Definition: AuctionHouseBot.h:113
BuyerConfiguration _houseConfig[MAX_AUCTION_HOUSE_TYPE]
Definition: AuctionHouseBotBuyer.h:84
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: Common.h:97
#define MAX_AUCTION_HOUSE_TYPE
Definition: AuctionHouseBot.h:47
void LoadConfig()
Definition: AuctionHouseBotBuyer.cpp:57

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AuctionBotBuyer::LoadBuyerValues ( BuyerConfiguration config)
private
68 {
69 
70 }

+ Here is the caller graph for this function:

void AuctionBotBuyer::LoadConfig ( )
58 {
59  for (int i = 0; i < MAX_AUCTION_HOUSE_TYPE; ++i)
60  {
61  _houseConfig[i].BuyerEnabled = sAuctionBotConfig->GetConfigBuyerEnabled(AuctionHouseType(i));
62  if (_houseConfig[i].BuyerEnabled)
64  }
65 }
#define sAuctionBotConfig
Definition: AuctionHouseBot.h:252
AuctionHouseType
Definition: AuctionHouseBot.h:40
void LoadBuyerValues(BuyerConfiguration &config)
Definition: AuctionHouseBotBuyer.cpp:67
BuyerConfiguration _houseConfig[MAX_AUCTION_HOUSE_TYPE]
Definition: AuctionHouseBotBuyer.h:84
#define MAX_AUCTION_HOUSE_TYPE
Definition: AuctionHouseBot.h:47
bool BuyerEnabled
Definition: AuctionHouseBotBuyer.h:62

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AuctionBotBuyer::PlaceBidToEntry ( AuctionEntry auction,
uint32  bidPrice 
)
private
419 {
420  TC_LOG_DEBUG("ahbot", "AHBot: Bid placed to entry %u, %.2fg", auction->Id, float(bidPrice) / GOLD);
421 
423 
424  // Send mail to previous bidder if any
425  if (auction->bidder)
426  sAuctionMgr->SendAuctionOutbiddedMail(auction, bidPrice, NULL, trans);
427 
428  // Set bot as bidder and set new bid amount
429  auction->bidder = 0;
430  auction->bid = bidPrice;
431 
432  // Update auction to DB
434  stmt->setUInt64(0, auction->bidder);
435  stmt->setUInt32(1, auction->bid);
436  stmt->setUInt32(2, auction->Id);
437  trans->Append(stmt);
438 
439  // Run SQLs
441 }
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: PreparedStatement.h:74
uint32 Id
Definition: AuctionHouseMgr.h:69
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
uint32 bid
Definition: AuctionHouseMgr.h:76
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: SharedDefines.h:232
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
Definition: CharacterDatabase.h:124
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
#define sAuctionMgr
Definition: AuctionHouseMgr.h:199
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AuctionBotBuyer::PrepareListOfEntry ( BuyerConfiguration config)
private
236 {
237  // now - 5 seconds to leave out all old entries but keep the ones just updated a moment ago
238  time_t now = time(nullptr) - 5;
239 
240  for (CheckEntryMap::iterator itr = config.EligibleItems.begin(); itr != config.EligibleItems.end();)
241  {
242  if (itr->second.LastExist < now)
243  config.EligibleItems.erase(itr++);
244  else
245  ++itr;
246  }
247 
248  TC_LOG_DEBUG("ahbot", "AHBot: EligibleItems size = %u", (uint32)config.EligibleItems.size());
249 }
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint32_t uint32
Definition: Define.h:150
CheckEntryMap EligibleItems
Definition: AuctionHouseBotBuyer.h:61

+ Here is the caller graph for this function:

bool AuctionBotBuyer::RollBidChance ( const BuyerItemInfo ahInfo,
const Item item,
const AuctionEntry auction,
uint32  bidPrice 
)
private
199 {
200  float itemBidPrice = float(bidPrice / item->GetCount());
201  float itemPrice = float(item->GetTemplate()->GetSellPrice() ? item->GetTemplate()->GetSellPrice() : GetVendorPrice(item->GetTemplate()->GetQuality()));
202  // The AH cut needs to be added to the price, but we dont want a 100% chance to buy if the price is exactly AH default
203  itemPrice *= 1.4f;
204 
205  // This value is between 0 and 100 and is used directly as the chance to buy or bid
206  // Value equal or above 100 means 100% chance and value below 0 means 0% chance
207  float chance = std::min(100.f, std::pow(100.f, 1.f + (1.f - itemBidPrice / itemPrice) / sAuctionBotConfig->GetConfig(CONFIG_AHBOT_BUYER_CHANCE_FACTOR)));
208 
209  if (ahInfo)
210  {
211  float avgBidPrice = ahInfo->TotalBidPrice / float(ahInfo->BidItemCount);
212 
213  TC_LOG_DEBUG("ahbot", "AHBot: Bid average: %.1f biddable item count: %u", avgBidPrice, ahInfo->BidItemCount);
214 
215  // If there are more than 5 items on AH of this entry, try weigh in the average bid price
216  if (ahInfo->BidItemCount >= 5)
217  chance *= 1.f / std::sqrt(itemBidPrice / avgBidPrice);
218  }
219 
220  // If a player has bidded on item, have fifth of normal chance
221  if (auction->bidder)
222  chance = chance / 5.f;
223 
224  // Add config weigh in for quality
225  chance *= GetChanceMultiplier(item->GetTemplate()->GetQuality()) / 100.0f;
226 
227  float rand = frand(0.f, 100.f);
228  bool win = rand <= chance;
229  TC_LOG_DEBUG("ahbot", "AHBot: %s BID! chance = %.2f, price = %u, bidprice = %u.", win ? "WIN" : "LOSE", chance, uint32(itemPrice), uint32(itemBidPrice));
230  return win;
231 }
uint32 GetCount() const
Definition: Item.h:322
double TotalBidPrice
Definition: AuctionHouseBotBuyer.h:43
#define sAuctionBotConfig
Definition: AuctionHouseBot.h:252
double frand()
Definition: Vector3.cpp:170
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
T min(const T &x, const T &y)
Definition: g3dmath.h:305
uint32 GetSellPrice() const
Definition: ItemTemplate.h:663
uint32 GetChanceMultiplier(uint32 quality)
Definition: AuctionHouseBotBuyer.cpp:363
Definition: AuctionHouseBot.h:194
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
uint32 BidItemCount
Definition: AuctionHouseBotBuyer.h:38
G3D::Quat pow(const G3D::Quat &q, double x)
Definition: Quat.h:761
uint32_t uint32
Definition: g3dmath.h:168
uint32 GetVendorPrice(uint32 quality)
Definition: AuctionHouseBotBuyer.cpp:340
ItemTemplate const * GetTemplate() const
Definition: Item.cpp:547
uint32 GetQuality() const
Definition: ItemTemplate.h:655

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AuctionBotBuyer::RollBuyChance ( const BuyerItemInfo ahInfo,
const Item item,
const AuctionEntry auction,
uint32  bidPrice 
)
private
160 {
161  if (!auction->buyout)
162  return false;
163 
164  float itemBuyPrice = float(auction->buyout / item->GetCount());
165  float itemPrice = float(item->GetTemplate()->GetSellPrice() ? item->GetTemplate()->GetSellPrice() : GetVendorPrice(item->GetTemplate()->GetQuality()));
166  // The AH cut needs to be added to the price, but we dont want a 100% chance to buy if the price is exactly AH default
167  itemPrice *= 1.4f;
168 
169  // This value is between 0 and 100 and is used directly as the chance to buy or bid
170  // Value equal or above 100 means 100% chance and value below 0 means 0% chance
171  float chance = std::min(100.f, std::pow(100.f, 1.f + (1.f - itemBuyPrice / itemPrice) / sAuctionBotConfig->GetConfig(CONFIG_AHBOT_BUYER_CHANCE_FACTOR)));
172 
173  // If a player has bidded on item, have fifth of normal chance
174  if (auction->bidder)
175  chance = chance / 5.f;
176 
177  if (ahInfo)
178  {
179  float avgBuyPrice = ahInfo->TotalBuyPrice / float(ahInfo->BuyItemCount);
180 
181  TC_LOG_DEBUG("ahbot", "AHBot: buyout average: %.1f items with buyout: %u", avgBuyPrice, ahInfo->BuyItemCount);
182 
183  // If there are more than 5 items on AH of this entry, try weigh in the average buyout price
184  if (ahInfo->BuyItemCount > 5)
185  chance *= 1.f / std::sqrt(itemBuyPrice / avgBuyPrice);
186  }
187 
188  // Add config weigh in for quality
189  chance *= GetChanceMultiplier(item->GetTemplate()->GetQuality()) / 100.0f;
190 
191  float rand = frand(0.f, 100.f);
192  bool win = rand <= chance;
193  TC_LOG_DEBUG("ahbot", "AHBot: %s BUY! chance = %.2f, price = %u, buyprice = %u.", win ? "WIN" : "LOSE", chance, uint32(itemPrice), uint32(itemBuyPrice));
194  return win;
195 }
uint32 GetCount() const
Definition: Item.h:322
#define sAuctionBotConfig
Definition: AuctionHouseBot.h:252
double frand()
Definition: Vector3.cpp:170
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint32 BuyItemCount
Definition: AuctionHouseBotBuyer.h:39
T min(const T &x, const T &y)
Definition: g3dmath.h:305
uint32 GetSellPrice() const
Definition: ItemTemplate.h:663
uint32 GetChanceMultiplier(uint32 quality)
Definition: AuctionHouseBotBuyer.cpp:363
Definition: AuctionHouseBot.h:194
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
uint32 buyout
Definition: AuctionHouseMgr.h:77
G3D::Quat pow(const G3D::Quat &q, double x)
Definition: Quat.h:761
uint32_t uint32
Definition: g3dmath.h:168
uint32 GetVendorPrice(uint32 quality)
Definition: AuctionHouseBotBuyer.cpp:340
double TotalBuyPrice
Definition: AuctionHouseBotBuyer.h:42
ItemTemplate const * GetTemplate() const
Definition: Item.cpp:547
uint32 GetQuality() const
Definition: ItemTemplate.h:655

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AuctionBotBuyer::Update ( AuctionHouseType  houseType)
overridevirtual

Implements AuctionBotAgent.

74 {
75  if (!sAuctionBotConfig->GetConfigBuyerEnabled(houseType))
76  return false;
77 
78  TC_LOG_DEBUG("ahbot", "AHBot: %s buying ...", AuctionBotConfig::GetHouseTypeName(houseType));
79 
80  BuyerConfiguration& config = _houseConfig[houseType];
81  uint32 eligibleItems = GetItemInformation(config);
82  if (eligibleItems)
83  {
84  // Prepare list of items to bid or buy - remove old items
85  PrepareListOfEntry(config);
86  // Process buying and bidding items
87  BuyAndBidItems(config);
88  }
89 
90  return true;
91 }
#define sAuctionBotConfig
Definition: AuctionHouseBot.h:252
BuyerConfiguration _houseConfig[MAX_AUCTION_HOUSE_TYPE]
Definition: AuctionHouseBotBuyer.h:84
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint32 GetItemInformation(BuyerConfiguration &config)
Definition: AuctionHouseBotBuyer.cpp:95
void PrepareListOfEntry(BuyerConfiguration &config)
Definition: AuctionHouseBotBuyer.cpp:235
uint32_t uint32
Definition: Define.h:150
static char const * GetHouseTypeName(AuctionHouseType houseType)
Definition: AuctionHouseBot.cpp:269
void BuyAndBidItems(BuyerConfiguration &config)
Definition: AuctionHouseBotBuyer.cpp:252
Definition: AuctionHouseBotBuyer.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

uint32 AuctionBotBuyer::_checkInterval
private
BuyerConfiguration AuctionBotBuyer::_houseConfig[MAX_AUCTION_HOUSE_TYPE]
private

The documentation for this class was generated from the following files: