diff --git a/conf/mod_ahbot.conf.dist b/conf/mod_ahbot.conf.dist index 568ae05..f4e3762 100644 --- a/conf/mod_ahbot.conf.dist +++ b/conf/mod_ahbot.conf.dist @@ -27,6 +27,10 @@ # Enable/Disable tracing for the sold items # Default 0 (disabled) # +# AuctionHouseBot.TRACE_BUYER +# Enable/Disable tracing for the bought items +# Default 0 (disabled) +# # AuctionHouseBot.EnableSeller # Enable/Disable the part of AHBot that puts items up for auction # Default 0 (disabled) @@ -86,6 +90,8 @@ AuctionHouseBot.DEBUG_FILTERS = 0 AuctionHouseBot.DEBUG_BUYER = 0 AuctionHouseBot.DEBUG_SELLER = 0 AuctionHouseBot.TRACE_SELLER = 0 +AuctionHouseBot.TRACE_BUYER = 0 + AuctionHouseBot.EnableSeller = 0 AuctionHouseBot.EnableBuyer = 0 AuctionHouseBot.UseBuyPriceForSeller = 0 diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index d4f500d..65a6646 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -18,133 +18,30 @@ */ #include "ObjectMgr.h" -#include "AuctionHouseBotCommon.h" #include "AuctionHouseMgr.h" -#include "AuctionHouseBot.h" #include "Config.h" #include "Player.h" #include "WorldSession.h" #include "GameTime.h" #include "DatabaseEnv.h" -#include - -using namespace std; - -// -// Bins for selected items to be tested -// - -vector npcItems; -vector lootItems; - -// -// Bins for usable trade goods items -// - -vector greyTradeGoodsBin; -vector whiteTradeGoodsBin; -vector greenTradeGoodsBin; -vector blueTradeGoodsBin; -vector purpleTradeGoodsBin; -vector orangeTradeGoodsBin; -vector yellowTradeGoodsBin; -// -// Bins for usable items -// +#include "AuctionHouseBot.h" +#include "AuctionHouseBotCommon.h" -vector greyItemsBin; -vector whiteItemsBin; -vector greenItemsBin; -vector blueItemsBin; -vector purpleItemsBin; -vector orangeItemsBin; -vector yellowItemsBin; +using namespace std; -// -// Bins for whitelists -// +AuctionHouseBot::AuctionHouseBot(uint32 account, uint32 id) +{ + _account = account; + _id = id; -vector sellerItems; + _lastrun_a_sec = time(NULL); + _lastrun_h_sec = time(NULL); + _lastrun_n_sec = time(NULL); -AuctionHouseBot::AuctionHouseBot() -{ - debug_Out = false; - debug_Out_Config = false; - debug_Out_Filters = false; - debug_Out_Buyer = false; - debug_Out_Seller = false; - trace_Seller = false; - AHBSeller = false; - AHBBuyer = false; - DuplicatesCount = 0; - DivisibleStacks = false; - ElapsingTimeClass = 1; - ConsiderOnlyBotAuctions = false; - - // Begin Filters - - Vendor_Items = false; - Loot_Items = false; - Other_Items = false; - Vendor_TGs = false; - Loot_TGs = false; - Other_TGs = false; - - No_Bind = false; - Bind_When_Picked_Up = false; - Bind_When_Equipped = false; - Bind_When_Use = false; - Bind_Quest_Item = false; - - DisablePermEnchant = false; - DisableConjured = false; - DisableGems = false; - DisableMoney = false; - DisableMoneyLoot = false; - DisableLootable = false; - DisableKeys = false; - DisableDuration = false; - DisableBOP_Or_Quest_NoReqLevel = false; - - DisableWarriorItems = false; - DisablePaladinItems = false; - DisableHunterItems = false; - DisableRogueItems = false; - DisablePriestItems = false; - DisableDKItems = false; - DisableShamanItems = false; - DisableMageItems = false; - DisableWarlockItems = false; - DisableUnusedClassItems = false; - DisableDruidItems = false; - - DisableItemsBelowLevel = 0; - DisableItemsAboveLevel = 0; - DisableTGsBelowLevel = 0; - DisableTGsAboveLevel = 0; - DisableItemsBelowGUID = 0; - DisableItemsAboveGUID = 0; - DisableTGsBelowGUID = 0; - DisableTGsAboveGUID = 0; - DisableItemsBelowReqLevel = 0; - DisableItemsAboveReqLevel = 0; - DisableTGsBelowReqLevel = 0; - DisableTGsAboveReqLevel = 0; - DisableItemsBelowReqSkillRank = 0; - DisableItemsAboveReqSkillRank = 0; - DisableTGsBelowReqSkillRank = 0; - DisableTGsAboveReqSkillRank = 0; - - // End Filters - - _lastrun_a_sec = time(NULL); - _lastrun_h_sec = time(NULL); - _lastrun_n_sec = time(NULL); - - AllianceConfig = AHBConfig(2); - HordeConfig = AHBConfig(6); - NeutralConfig = AHBConfig(7); + _allianceConfig = NULL; + _hordeConfig = NULL; + _neutralConfig = NULL; } AuctionHouseBot::~AuctionHouseBot() @@ -152,35 +49,15 @@ AuctionHouseBot::~AuctionHouseBot() // Nothing } -// ============================================================================= -// Extracts integers from a string and return a set of them -// ============================================================================= - -std::set AuctionHouseBot::getCommaSeparatedIntegers(std::string text) +uint32 AuctionHouseBot::getElement(std::set set, int index) { - std::string value; - std::stringstream stream; - std::set ret; + std::set::iterator it = set.begin(); + std::advance(it, index); - stream.str(text); - - // - // Continue to precess comma separated values - // - - while (std::getline(stream, value, ',')) - { - ret.insert(atoi(value.c_str())); - } - - return ret; + return *it; } -// ============================================================================= -// Returns a stack size depending on the configuration -// ============================================================================= - -uint32 AuctionHouseBot::getStackCount(uint32 max) +uint32 AuctionHouseBot::getStackCount(AHBConfig* config, uint32 max) { if (max == 1) { @@ -191,7 +68,7 @@ uint32 AuctionHouseBot::getStackCount(uint32 max) // Organize the stacks in a pseudo random way // - if (DivisibleStacks) + if (config->DivisibleStacks) { uint32 ret = 0; @@ -225,10 +102,6 @@ uint32 AuctionHouseBot::getStackCount(uint32 max) return urand(1, max); } -// ============================================================================= -// Gets a random elapsing time depending on the provided class -// ============================================================================= - uint32 AuctionHouseBot::getElapsedTime(uint32 timeClass) { switch (timeClass) @@ -244,17 +117,13 @@ uint32 AuctionHouseBot::getElapsedTime(uint32 timeClass) } } -// ============================================================================= -// Gets the number of items actually present in the auction house -// ============================================================================= - -uint32 AuctionHouseBot::getNofAuctions(AuctionHouseObject* auctionHouse, ObjectGuid guid) +uint32 AuctionHouseBot::getNofAuctions(AHBConfig* config, AuctionHouseObject* auctionHouse, ObjectGuid guid) { // // All the auctions // - if (!ConsiderOnlyBotAuctions) + if (!config->ConsiderOnlyBotAuctions) { return auctionHouse->Getcount(); } @@ -289,13 +158,8 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Check if disabled // - if (!AHBBuyer) + if (!config->AHBBuyer) { - if (debug_Out_Buyer) - { - LOG_ERROR("module", "AHBuyer: Disabled"); - } - return; } @@ -303,7 +167,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Retrieve items not owner by the bot and not bought by the bot // - QueryResult result = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE itemowner<>{} AND buyguid<>{}", AHBplayerGUID, AHBplayerGUID); + QueryResult result = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE itemowner<>{} AND buyguid<>{}", _id, _id); if (!result) { @@ -320,13 +184,12 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); - - vector possibleBids; + std::set possibleBids; do { uint32 tmpdata = result->Fetch()->Get(); - possibleBids.push_back(tmpdata); + possibleBids.insert(tmpdata); } while (result->NextRow()); // @@ -335,16 +198,16 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se if (possibleBids.empty()) { - if (debug_Out_Buyer) + if (config->DebugOutBuyer) { - LOG_INFO("module", "No auctions to bid on has been recovered"); + LOG_INFO("module", "AHBot [{}]: no auctions to bid on has been recovered", _id); } return; } // - // Perform the operation for a maximum amount of bids configured + // Perform the operation for a maximum amount of bids attempts configured // for (uint32 count = 1; count <= config->GetBidsPerInterval(); ++count) @@ -353,24 +216,33 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Choose a random auction from possible auctions // - uint32 vectorPos = urand(0, possibleBids.size() - 1); + uint32 randBid = urand(0, possibleBids.size() - 1); - vector::iterator iter = possibleBids.begin(); - advance(iter, vectorPos); + std::set::iterator it = possibleBids.begin(); + std::advance(it, randBid); - AuctionEntry* auction = auctionHouse->GetAuction(*iter); + AuctionEntry* auction = auctionHouse->GetAuction(*it); // // Prevent to bid again on the same auction // - possibleBids.erase(iter); + possibleBids.erase(randBid); if (!auction) { continue; } + // + // Prevent from buying items from the other bots + // + + if (gBotsId.find(auction->owner.GetCounter()) != gBotsId.end()) + { + continue; + } + // // Get the item information // @@ -379,9 +251,9 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se if (!pItem) { - if (debug_Out_Buyer) + if (config->DebugOutBuyer) { - LOG_ERROR("module", "AHBuyer: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString()); + LOG_ERROR("module", "AHBot [{}]: item {} doesn't exist, perhaps bought already?", _id, auction->item_guid.ToString()); } continue; @@ -419,7 +291,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Check that bid has an acceptable value and take bid based on vendorprice, stacksize and quality // - if (BuyMethod) + if (config->BuyMethod) { if (prototype->Quality <= AHB_MAX_QUALITY) { @@ -430,9 +302,9 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se } else { - if (debug_Out_Buyer) + if (config->DebugOutBuyer) { - LOG_ERROR("module", "AHBuyer: Quality {} not Supported", prototype->Quality); + LOG_ERROR("module", "AHBot [{}]: Quality {} not Supported", _id, prototype->Quality); } continue; @@ -449,9 +321,9 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se } else { - if (debug_Out) + if (config->DebugOutBuyer) { - LOG_ERROR("module", "AHBuyer: Quality {} not Supported", prototype->Quality); + LOG_ERROR("module", "AHBot [{}]: Quality {} not Supported", _id, prototype->Quality); } continue; @@ -497,32 +369,36 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se bidprice = currentprice + auction->GetAuctionOutBid(); } - if (debug_Out_Buyer) + // + // Print out debug info + // + + if (config->DebugOutBuyer) { LOG_INFO("module", "-------------------------------------------------"); - LOG_INFO("module", "AHBuyer: Info for Auction #{}:", auction->Id); - LOG_INFO("module", "AHBuyer: AuctionHouse: {}", auction->GetHouseId()); - LOG_INFO("module", "AHBuyer: Owner: {}", auction->owner.ToString()); - LOG_INFO("module", "AHBuyer: Bidder: {}", auction->bidder.ToString()); - LOG_INFO("module", "AHBuyer: Starting Bid: {}", auction->startbid); - LOG_INFO("module", "AHBuyer: Current Bid: {}", currentprice); - LOG_INFO("module", "AHBuyer: Buyout: {}", auction->buyout); - LOG_INFO("module", "AHBuyer: Deposit: {}", auction->deposit); - LOG_INFO("module", "AHBuyer: Expire Time: {}", uint32(auction->expire_time)); - LOG_INFO("module", "AHBuyer: Bid Rate: {}", bidrate); - LOG_INFO("module", "AHBuyer: Bid Max: {}", bidMax); - LOG_INFO("module", "AHBuyer: Bid Value: {}", bidvalue); - LOG_INFO("module", "AHBuyer: Bid Price: {}", bidprice); - LOG_INFO("module", "AHBuyer: Item GUID: {}", auction->item_guid.ToString()); - LOG_INFO("module", "AHBuyer: Item Template: {}", auction->item_template); - LOG_INFO("module", "AHBuyer: Item Info:"); - LOG_INFO("module", "AHBuyer: Item ID: {}", prototype->ItemId); - LOG_INFO("module", "AHBuyer: Buy Price: {}", prototype->BuyPrice); - LOG_INFO("module", "AHBuyer: Sell Price: {}", prototype->SellPrice); - LOG_INFO("module", "AHBuyer: Bonding: {}", prototype->Bonding); - LOG_INFO("module", "AHBuyer: Quality: {}", prototype->Quality); - LOG_INFO("module", "AHBuyer: Item Level: {}", prototype->ItemLevel); - LOG_INFO("module", "AHBuyer: Ammo Type: {}", prototype->AmmoType); + LOG_INFO("module", "AHBot [{}]: Info for Auction #{}:", _id, auction->Id); + LOG_INFO("module", "AHBot [{}]: AuctionHouse: {}" , _id, auction->GetHouseId()); + LOG_INFO("module", "AHBot [{}]: Owner: {}" , _id, auction->owner.ToString()); + LOG_INFO("module", "AHBot [{}]: Bidder: {}" , _id, auction->bidder.ToString()); + LOG_INFO("module", "AHBot [{}]: Starting Bid: {}" , _id, auction->startbid); + LOG_INFO("module", "AHBot [{}]: Current Bid: {}" , _id, currentprice); + LOG_INFO("module", "AHBot [{}]: Buyout: {}" , _id, auction->buyout); + LOG_INFO("module", "AHBot [{}]: Deposit: {}" , _id, auction->deposit); + LOG_INFO("module", "AHBot [{}]: Expire Time: {}" , _id, uint32(auction->expire_time)); + LOG_INFO("module", "AHBot [{}]: Bid Rate: {}" , _id, bidrate); + LOG_INFO("module", "AHBot [{}]: Bid Max: {}" , _id, bidMax); + LOG_INFO("module", "AHBot [{}]: Bid Value: {}" , _id, bidvalue); + LOG_INFO("module", "AHBot [{}]: Bid Price: {}" , _id, bidprice); + LOG_INFO("module", "AHBot [{}]: Item GUID: {}" , _id, auction->item_guid.ToString()); + LOG_INFO("module", "AHBot [{}]: Item Template: {}" , _id, auction->item_template); + LOG_INFO("module", "AHBot [{}]: Item Info:"); + LOG_INFO("module", "AHBot [{}]: Item ID: {}" , _id, prototype->ItemId); + LOG_INFO("module", "AHBot [{}]: Buy Price: {}" , _id, prototype->BuyPrice); + LOG_INFO("module", "AHBot [{}]: Sell Price: {}" , _id, prototype->SellPrice); + LOG_INFO("module", "AHBot [{}]: Bonding: {}" , _id, prototype->Bonding); + LOG_INFO("module", "AHBot [{}]: Quality: {}" , _id, prototype->Quality); + LOG_INFO("module", "AHBot [{}]: Item Level: {}" , _id, prototype->ItemLevel); + LOG_INFO("module", "AHBot [{}]: Ammo Type: {}" , _id, prototype->AmmoType); LOG_INFO("module", "-------------------------------------------------"); } @@ -530,6 +406,8 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Check whether we do normal bid, or buyout // + bool bought = false; + if ((bidprice < auction->buyout) || (auction->buyout == 0)) { // @@ -547,7 +425,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se auto trans = CharacterDatabase.BeginTransaction(); sAuctionMgr->SendAuctionOutbiddedMail(auction, bidprice, session->GetPlayer(), trans); - CharacterDatabase.CommitTransaction(trans); + CharacterDatabase.CommitTransaction (trans); } } @@ -558,10 +436,12 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Save the auction into database // - CharacterDatabase.Execute("UPDATE auctionhouse SET buyguid = '{}',lastbid = '{}' WHERE id = '{}'", auction->bidder.GetCounter(), auction->bid, auction->Id); + CharacterDatabase.Execute("UPDATE auctionhouse SET buyguid = '{}', lastbid = '{}' WHERE id = '{}'", auction->bidder.GetCounter(), auction->bid, auction->Id); } else { + bought = true; + // // Perform the buyout // @@ -585,7 +465,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // sAuctionMgr->SendAuctionSuccessfulMail(auction, trans); - sAuctionMgr->SendAuctionWonMail(auction, trans); + sAuctionMgr->SendAuctionWonMail (auction, trans); // // Removes any trace of the item @@ -593,11 +473,27 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se auction->DeleteFromDB(trans); - sAuctionMgr->RemoveAItem(auction->item_guid); + sAuctionMgr->RemoveAItem (auction->item_guid); auctionHouse->RemoveAuction(auction); CharacterDatabase.CommitTransaction(trans); } + + // + // Tracing + // + + if (config->TraceBuyer) + { + if (bought) + { + LOG_INFO("module", "AHBot [{}]: Bought , id={}, ah={}, item={}, start={}, current={}, buyout={}", _id, auction->Id, auction->GetHouseId(), auction->item_template, auction->startbid, currentprice, auction->buyout); + } + else + { + LOG_INFO("module", "AHBot [{}]: New bid, id={}, ah={}, item={}, start={}, current={}, buyout={}", _id, auction->Id, auction->GetHouseId(), auction->item_template, auction->startbid, currentprice, auction->buyout); + } + } } } @@ -611,7 +507,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) // Check if disabled // - if (!AHBSeller) + if (!config->AHBSeller) { return; } @@ -654,16 +550,16 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) bool aboveMin = false; bool aboveMax = false; - uint32 auctions = getNofAuctions(auctionHouse, AHBplayer->GetGUID()); + uint32 auctions = getNofAuctions(config, auctionHouse, AHBplayer->GetGUID()); uint32 items = 0; if (auctions >= minItems) { aboveMin = true; - if (debug_Out_Seller) + if (config->DebugOutSeller) { - LOG_ERROR("module", "AHSeller: Auctions above minimum"); + LOG_ERROR("module", "AHBot [{}]: Auctions above minimum", _id); } return; @@ -673,17 +569,17 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) { aboveMax = true; - if (debug_Out_Seller) + if (config->DebugOutSeller) { - LOG_ERROR("module", "AHSeller: Auctions at or above maximum"); + LOG_ERROR("module", "AHBot [{}]: Auctions at or above maximum", _id); } return; } - if ((maxItems - auctions) >= ItemsPerCycle) + if ((maxItems - auctions) >= config->ItemsPerCycle) { - items = ItemsPerCycle; + items = config->ItemsPerCycle; } else { @@ -760,9 +656,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) switch (choice) { case AHB_GREY_I: - if ((greyItemsBin.size() > 0) && (greyItems < greyIcount)) + if ((config->GreyItemsBin.size() > 0) && (greyItems < greyIcount)) { - itemID = greyItemsBin[urand(0, greyItemsBin.size() - 1)]; + itemID = getElement(config->GreyItemsBin, urand(0, config->GreyItemsBin.size() - 1)); } else { @@ -773,9 +669,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_WHITE_I: - if ((whiteItemsBin.size() > 0) && (whiteItems < whiteIcount)) + if ((config->WhiteItemsBin.size() > 0) && (whiteItems < whiteIcount)) { - itemID = whiteItemsBin[urand(0, whiteItemsBin.size() - 1)]; + itemID = getElement(config->WhiteItemsBin, urand(0, config->WhiteItemsBin.size() - 1)); } else { @@ -786,9 +682,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_GREEN_I: - if ((greenItemsBin.size() > 0) && (greenItems < greenIcount)) + if ((config->GreenItemsBin.size() > 0) && (greenItems < greenIcount)) { - itemID = greenItemsBin[urand(0, greenItemsBin.size() - 1)]; + itemID = getElement(config->GreenItemsBin, urand(0, config->GreenItemsBin.size() - 1)); } else { @@ -799,9 +695,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_BLUE_I: - if ((blueItemsBin.size() > 0) && (blueItems < blueIcount)) + if ((config->BlueItemsBin.size() > 0) && (blueItems < blueIcount)) { - itemID = blueItemsBin[urand(0, blueItemsBin.size() - 1)]; + itemID = getElement(config->BlueItemsBin, urand(0, config->BlueItemsBin.size() - 1)); } else { @@ -812,9 +708,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_PURPLE_I: - if ((purpleItemsBin.size() > 0) && (purpleItems < purpleIcount)) + if ((config->PurpleItemsBin.size() > 0) && (purpleItems < purpleIcount)) { - itemID = purpleItemsBin[urand(0, purpleItemsBin.size() - 1)]; + itemID = getElement(config->PurpleItemsBin, urand(0, config->PurpleItemsBin.size() - 1)); } else { @@ -825,9 +721,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_ORANGE_I: - if ((orangeItemsBin.size() > 0) && (orangeItems < orangeIcount)) + if ((config->OrangeItemsBin.size() > 0) && (orangeItems < orangeIcount)) { - itemID = orangeItemsBin[urand(0, orangeItemsBin.size() - 1)]; + itemID = getElement(config->OrangeItemsBin, urand(0, config->OrangeItemsBin.size() - 1)); } else { @@ -838,9 +734,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_YELLOW_I: - if ((yellowItemsBin.size() > 0) && (yellowItems < yellowIcount)) + if ((config->YellowItemsBin.size() > 0) && (yellowItems < yellowIcount)) { - itemID = yellowItemsBin[urand(0, yellowItemsBin.size() - 1)]; + itemID = getElement(config->YellowItemsBin, urand(0, config->YellowItemsBin.size() - 1)); } else { @@ -851,9 +747,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_GREY_TG: - if ((greyTradeGoodsBin.size() > 0) && (greyTGoods < greyTGcount)) + if ((config->GreyTradeGoodsBin.size() > 0) && (greyTGoods < greyTGcount)) { - itemID = greyTradeGoodsBin[urand(0, greyTradeGoodsBin.size() - 1)]; + itemID = getElement(config->GreyTradeGoodsBin, urand(0, config->GreyTradeGoodsBin.size() - 1)); } else { @@ -864,9 +760,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_WHITE_TG: - if ((whiteTradeGoodsBin.size() > 0) && (whiteTGoods < whiteTGcount)) + if ((config->WhiteTradeGoodsBin.size() > 0) && (whiteTGoods < whiteTGcount)) { - itemID = whiteTradeGoodsBin[urand(0, whiteTradeGoodsBin.size() - 1)]; + itemID = getElement(config->WhiteTradeGoodsBin, urand(0, config->WhiteTradeGoodsBin.size() - 1)); } else { @@ -877,9 +773,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_GREEN_TG: - if ((greenTradeGoodsBin.size() > 0) && (greenTGoods < greenTGcount)) + if ((config->GreenTradeGoodsBin.size() > 0) && (greenTGoods < greenTGcount)) { - itemID = greenTradeGoodsBin[urand(0, greenTradeGoodsBin.size() - 1)]; + itemID = getElement(config->GreenTradeGoodsBin, urand(0, config->GreenTradeGoodsBin.size() - 1)); } else { @@ -890,9 +786,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_BLUE_TG: - if ((blueTradeGoodsBin.size() > 0) && (blueTGoods < blueTGcount)) + if ((config->BlueTradeGoodsBin.size() > 0) && (blueTGoods < blueTGcount)) { - itemID = blueTradeGoodsBin[urand(0, blueTradeGoodsBin.size() - 1)]; + itemID = getElement(config->BlueTradeGoodsBin, urand(0, config->BlueTradeGoodsBin.size() - 1)); } else { @@ -903,9 +799,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_PURPLE_TG: - if ((purpleTradeGoodsBin.size() > 0) && (purpleTGoods < purpleTGcount)) + if ((config->PurpleTradeGoodsBin.size() > 0) && (purpleTGoods < purpleTGcount)) { - itemID = purpleTradeGoodsBin[urand(0, purpleTradeGoodsBin.size() - 1)]; + itemID = getElement(config->PurpleTradeGoodsBin, urand(0, config->PurpleTradeGoodsBin.size() - 1)); } else { @@ -916,9 +812,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_ORANGE_TG: - if ((orangeTradeGoodsBin.size() > 0) && (orangeTGoods < orangeTGcount)) + if ((config->OrangeTradeGoodsBin.size() > 0) && (orangeTGoods < orangeTGcount)) { - itemID = orangeTradeGoodsBin[urand(0, orangeTradeGoodsBin.size() - 1)]; + itemID = getElement(config->OrangeTradeGoodsBin, urand(0, config->OrangeTradeGoodsBin.size() - 1)); } else { @@ -929,9 +825,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) break; case AHB_YELLOW_TG: - if ((yellowTradeGoodsBin.size() > 0) && (yellowTGoods < yellowTGcount)) + if ((config->YellowTradeGoodsBin.size() > 0) && (yellowTGoods < yellowTGcount)) { - itemID = yellowTradeGoodsBin[urand(0, yellowTradeGoodsBin.size() - 1)]; + itemID = getElement(config->YellowTradeGoodsBin, urand(0, config->YellowTradeGoodsBin.size() - 1)); } else { @@ -944,9 +840,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) default: err++; - if (debug_Out_Seller) + if (config->DebugOutSeller) { - LOG_ERROR("module", "AHSeller: itemID Switch - Default Reached"); + LOG_ERROR("module", "AHBot [{}]: itemID Switch - Default Reached", _id); } break; @@ -960,9 +856,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) { binEmpty++; - if (debug_Out_Seller) + if (config->DebugOutSeller) { - LOG_ERROR("module", "AHSeller: No item could be selected in the bin {}", choice); + LOG_ERROR("module", "AHBot [{}]: No item could be selected in the bin {}", _id, choice); } continue; @@ -973,7 +869,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) // This avoid unfortunate rolls to overwhelm the market with the same products on low population, especially with whitelists. // - if (DuplicatesCount > 0) + if (config->DuplicatesCount > 0) { uint32 noStacks = 0; @@ -990,7 +886,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) } } - if (noStacks >= DuplicatesCount) + if (noStacks >= config->DuplicatesCount) { tooMany++; continue; @@ -1007,9 +903,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) { err++; - if (debug_Out_Seller) + if (config->DebugOutSeller) { - LOG_ERROR("module", "AHSeller: could not get prototype of item {}", itemID); + LOG_ERROR("module", "AHBot [{}]: could not get prototype of item {}", _id, itemID); } continue; @@ -1021,9 +917,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) { err++; - if (debug_Out_Seller) + if (config->DebugOutSeller) { - LOG_ERROR("module", "AHSeller: could not create item from prototype {}", itemID); + LOG_ERROR("module", "AHBot [{}]: could not create item from prototype {}", _id, itemID); } break; @@ -1050,7 +946,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) uint64 bidPrice = 0; uint32 stackCount = 1; - if (SellMethod) + if (config->SellMethod) { buyoutPrice = prototype->BuyPrice; } @@ -1063,11 +959,11 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) { if (config->GetMaxStack(prototype->Quality) > 1 && item->GetMaxStackCount() > 1) { - stackCount = minValue(getStackCount(item->GetMaxStackCount()), config->GetMaxStack(prototype->Quality)); + stackCount = minValue(getStackCount(config, item->GetMaxStackCount()), config->GetMaxStack(prototype->Quality)); } else if (config->GetMaxStack(prototype->Quality) == 0 && item->GetMaxStackCount() > 1) { - stackCount = getStackCount(item->GetMaxStackCount()); + stackCount = getStackCount(config, item->GetMaxStackCount()); } else { @@ -1083,9 +979,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) { err++; - if (debug_Out_Seller) + if (config->DebugOutSeller) { - LOG_ERROR("module", "AHSeller: Quality {} TOO HIGH for item {}", prototype->Quality, itemID); + LOG_ERROR("module", "AHBot [{}]: Quality {} TOO HIGH for item {}", _id, prototype->Quality, itemID); } item->RemoveFromUpdateQueueOf(AHBplayer); @@ -1098,7 +994,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) // Determine the auction time // - uint32 etime = getElapsedTime(ElapsingTimeClass); + uint32 etime = getElapsedTime(config->ElapsingTimeClass); // // Determine the deposit @@ -1202,9 +1098,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) noSold++; - if (trace_Seller) + if (config->TraceSeller) { - LOG_INFO("module", "AHSeller: New stack ah={}, id={}, stack={}, bid={}, buyout={}", config->GetAHID(), itemID, stackCount, auctionEntry->startbid, auctionEntry->buyout); + LOG_INFO("module", "AHBot [{}]: New stack ah={}, id={}, stack={}, bid={}, buyout={}", _id, config->GetAHID(), itemID, stackCount, auctionEntry->startbid, auctionEntry->buyout); } } @@ -1214,9 +1110,9 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) } } - if (trace_Seller) + if (config->TraceSeller) { - LOG_INFO("module", "AHSeller: auctionhouse {}, req={}, sold={}, aboveMin={}, aboveMax={}, loopBrk={}, noNeed={}, tooMany={}, binEmpty={}, err={}", config->GetAHID(), items, noSold, aboveMin, aboveMax, loopBrk, noNeed, tooMany, binEmpty, err); + LOG_INFO("module", "AHBot [{}]: auctionhouse {}, req={}, sold={}, aboveMin={}, aboveMax={}, loopBrk={}, noNeed={}, tooMany={}, binEmpty={}, err={}", _id, config->GetAHID(), items, noSold, aboveMin, aboveMax, loopBrk, noNeed, tooMany, binEmpty, err); } } @@ -1229,10 +1125,10 @@ void AuctionHouseBot::Update() time_t _newrun = time(NULL); // - // If there is no seller or buyer then terminate + // If no configuration is associated, then stop here // - if ((!AHBSeller) && (!AHBBuyer)) + if (!_allianceConfig && !_hordeConfig && !_neutralConfig) { return; } @@ -1241,12 +1137,12 @@ void AuctionHouseBot::Update() // Preprare for operation // - std::string accountName = "AuctionHouseBot" + std::to_string(AHBplayerAccount); + std::string accountName = "AuctionHouseBot" + std::to_string(_account); - WorldSession _session(AHBplayerAccount, std::move(accountName), nullptr, SEC_PLAYER, sWorld->getIntConfig(CONFIG_EXPANSION), 0, LOCALE_enUS, 0, false, false, 0); + WorldSession _session(_account, std::move(accountName), nullptr, SEC_PLAYER, sWorld->getIntConfig(CONFIG_EXPANSION), 0, LOCALE_enUS, 0, false, false, 0); Player _AHBplayer(&_session); - _AHBplayer.Initialize(AHBplayerGUID); + _AHBplayer.Initialize(_id); ObjectAccessor::AddObject(&_AHBplayer); @@ -1260,234 +1156,50 @@ void AuctionHouseBot::Update() // Alliance // - Sell(&_AHBplayer, &AllianceConfig); - - if (((_newrun - _lastrun_a_sec) >= (AllianceConfig.GetBiddingInterval() * MINUTE)) && (AllianceConfig.GetBidsPerInterval() > 0)) + if (_allianceConfig) { - Buy(&_AHBplayer, &AllianceConfig, &_session); - _lastrun_a_sec = _newrun; + Sell(&_AHBplayer, _allianceConfig); + + if (((_newrun - _lastrun_a_sec) >= (_allianceConfig->GetBiddingInterval() * MINUTE)) && (_allianceConfig->GetBidsPerInterval() > 0)) + { + Buy(&_AHBplayer, _allianceConfig, &_session); + _lastrun_a_sec = _newrun; + } } // // Horde // - Sell(&_AHBplayer, &HordeConfig); - - if (((_newrun - _lastrun_h_sec) >= (HordeConfig.GetBiddingInterval() * MINUTE)) && (HordeConfig.GetBidsPerInterval() > 0)) + if (_hordeConfig) { - Buy(&_AHBplayer, &HordeConfig, &_session); - _lastrun_h_sec = _newrun; - } - } - - // - // Neutral - // - - Sell(&_AHBplayer, &NeutralConfig); - - if (((_newrun - _lastrun_n_sec) >= (NeutralConfig.GetBiddingInterval() * MINUTE)) && (NeutralConfig.GetBidsPerInterval() > 0)) - { - Buy(&_AHBplayer, &NeutralConfig, &_session); - _lastrun_n_sec = _newrun; - } - - ObjectAccessor::RemoveObject(&_AHBplayer); -} - -// ============================================================================= -// Increments the item count -// ============================================================================= - -void AuctionHouseBot::IncrementItemCounts(AuctionEntry* ah) -{ - // - // Consider only those auctions handled by this bot - // - - if (ConsiderOnlyBotAuctions) - { - // ObjectGuid playerGuid(HighGuid::Player, 0, AHBplayerGUID); - - if (AHBplayerGUID != ah->owner.GetCounter()) - { - return; - } - } - - // - // Get exact item information - // - - Item *pItem = sAuctionMgr->GetAItem(ah->item_guid); - - if (!pItem) - { - if (debug_Out) - { - LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", ah->item_guid.ToString()); - } - - return; - } - - // - // Get item prototype - // - - ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(ah->item_template); - - // - // The the configuration for the auction house - // - - AHBConfig *config; - - AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(ah->GetHouseId()); - - if (!ahEntry) - { - if (ahEntry->houseId == AUCTIONHOUSE_ALLIANCE) - { - if (debug_Out) - { - LOG_INFO("module", "AHBot: {} returned as House Faction. Alliance", ah->GetHouseId()); - } - - config = &AllianceConfig; - } - else if (ahEntry->houseId == AUCTIONHOUSE_HORDE) - { - if (debug_Out) - { - LOG_INFO("module", "AHBot: {} returned as House Faction. Horde", ah->GetHouseId()); - } + Sell(&_AHBplayer, _hordeConfig); - config = &HordeConfig; - } - else - { - if (debug_Out) + if (((_newrun - _lastrun_h_sec) >= (_hordeConfig->GetBiddingInterval() * MINUTE)) && (_hordeConfig->GetBidsPerInterval() > 0)) { - LOG_INFO("module", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); + Buy(&_AHBplayer, _hordeConfig, &_session); + _lastrun_h_sec = _newrun; } - - config = &NeutralConfig; - } - } - else - { - if (debug_Out) - { - LOG_INFO("module", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); - } - - config = &NeutralConfig; - } - - // - // Increments - // - - config->IncItemCounts(prototype->Class, prototype->Quality); -} - -// ============================================================================= -// Decrements the item count -// ============================================================================= - -void AuctionHouseBot::DecrementItemCounts(AuctionEntry* ah) -{ - // - // Consider only those auctions handled by this bot - // - - if (ConsiderOnlyBotAuctions) - { - // ObjectGuid playerGuid(HighGuid::Player, 0, AHBplayerGUID); - - if (AHBplayerGUID != ah->owner.GetCounter()) - { - return; - } - } - - // - // Get exact item information - // - - Item* pItem = sAuctionMgr->GetAItem(ah->item_guid); - - if (!pItem) - { - if (debug_Out) - { - LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", ah->item_guid.ToString()); } - return; } // - // Get item prototype + // Neutral // - ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(ah->item_template); - - // - // The the configuration for the auction house - // - - AHBConfig* config; - - AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(ah->GetHouseId()); - - if (!ahEntry) + if (_neutralConfig) { - if (ahEntry->houseId == AUCTIONHOUSE_ALLIANCE) - { - if (debug_Out) - { - LOG_INFO("module", "AHBot: {} returned as House Faction. Alliance", ah->GetHouseId()); - } - - config = &AllianceConfig; - } - else if (ahEntry->houseId == AUCTIONHOUSE_HORDE) - { - if (debug_Out) - { - LOG_INFO("module", "AHBot: {} returned as House Faction. Horde", ah->GetHouseId()); - } - - config = &HordeConfig; - } - else - { - if (debug_Out) - { - LOG_INFO("module", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); - } + Sell(&_AHBplayer, _neutralConfig); - config = &NeutralConfig; - } - } - else - { - if (debug_Out) + if (((_newrun - _lastrun_n_sec) >= (_neutralConfig->GetBiddingInterval() * MINUTE)) && (_neutralConfig->GetBidsPerInterval() > 0)) { - LOG_INFO("module", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); + Buy(&_AHBplayer, _neutralConfig, &_session); + _lastrun_n_sec = _newrun; } - - config = &NeutralConfig; } - // - // Decrements - // - - config->DecItemCounts(prototype->Class, prototype->Quality); + ObjectAccessor::RemoveObject(&_AHBplayer); } // ============================================================================= @@ -1505,13 +1217,13 @@ void AuctionHouseBot::Commands(AHBotCommand command, uint32 ahMapID, uint32 col, switch (ahMapID) { case 2: - config = &AllianceConfig; + config = _allianceConfig; break; case 6: - config = &HordeConfig; + config = _hordeConfig; break; case 7: - config = &NeutralConfig; + config = _neutralConfig; break; } @@ -1561,12 +1273,12 @@ void AuctionHouseBot::Commands(AHBotCommand command, uint32 ahMapID, uint32 col, if (state == 0) { - AHBBuyer = false; + config->AHBBuyer = false; LOG_ERROR("module", "AHBot: Buyer disabled from console"); } else { - AHBBuyer = true; + config->AHBBuyer = true; LOG_ERROR("module", "AHBot: Buyer enabled from console"); } @@ -1579,12 +1291,12 @@ void AuctionHouseBot::Commands(AHBotCommand command, uint32 ahMapID, uint32 col, if (state == 0) { - AHBSeller = false; + config->AHBSeller = false; LOG_ERROR("module", "AHBot: Seller disabled from console"); } else { - AHBSeller = true; + config->AHBSeller = true; LOG_ERROR("module", "AHBot: Seller enabled from console"); } @@ -1592,15 +1304,14 @@ void AuctionHouseBot::Commands(AHBotCommand command, uint32 ahMapID, uint32 col, } case AHBotCommand::ahexpire: { - ObjectGuid playerGuid(HighGuid::Player, 0, AHBplayerGUID); - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); + AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); AuctionHouseObject::AuctionEntryMap::iterator itr; itr = auctionHouse->GetAuctionsBegin(); while (itr != auctionHouse->GetAuctionsEnd()) { - if (itr->second->owner == playerGuid) + if (itr->second->owner.GetCounter() == _id) { // Expired NOW. itr->second->expire_time = GameTime::GetGameTime().count(); @@ -1616,7 +1327,6 @@ void AuctionHouseBot::Commands(AHBotCommand command, uint32 ahMapID, uint32 col, break; } - case AHBotCommand::minitems: { char * param1 = strtok(args, " "); @@ -1788,1397 +1498,22 @@ void AuctionHouseBot::Commands(AHBotCommand command, uint32 ahMapID, uint32 col, } // ============================================================================= -// Loads options from the configuration file +// Initialization of the bot // ============================================================================= -void AuctionHouseBot::InitializeConfiguration() +void AuctionHouseBot::Initialize(AHBConfig* allianceConfig, AHBConfig* hordeConfig, AHBConfig* neutralConfig) { - debug_Out = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG", false); - debug_Out_Config = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_CONFIG", false); - debug_Out_Filters = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_FILTERS", false); - debug_Out_Buyer = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_BUYER", false); - debug_Out_Seller = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_SELLER", false); - trace_Seller = sConfigMgr->GetOption ("AuctionHouseBot.TRACE_SELLER", false); - - AHBSeller = sConfigMgr->GetOption ("AuctionHouseBot.EnableSeller", false); - AHBBuyer = sConfigMgr->GetOption ("AuctionHouseBot.EnableBuyer", false); - SellMethod = sConfigMgr->GetOption ("AuctionHouseBot.UseBuyPriceForSeller", false); - BuyMethod = sConfigMgr->GetOption ("AuctionHouseBot.UseBuyPriceForBuyer", false); - DuplicatesCount = sConfigMgr->GetOption("AuctionHouseBot.DuplicatesCount", 0); - DivisibleStacks = sConfigMgr->GetOption ("AuctionHouseBot.DivisibleStacks", false); - ElapsingTimeClass = sConfigMgr->GetOption("AuctionHouseBot.DuplicatesCount", 1); - ConsiderOnlyBotAuctions = sConfigMgr->GetOption ("AuctionHouseBot.ConsiderOnlyBotAuctions", false); - - AHBplayerAccount = sConfigMgr->GetOption("AuctionHouseBot.Account", 0); - AHBplayerGUID = sConfigMgr->GetOption("AuctionHouseBot.GUID", 0); - ItemsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.ItemsPerCycle", 200); - - // - // Flags: item types - // - - Vendor_Items = sConfigMgr->GetOption ("AuctionHouseBot.VendorItems", false); - Loot_Items = sConfigMgr->GetOption ("AuctionHouseBot.LootItems", true); - Other_Items = sConfigMgr->GetOption ("AuctionHouseBot.OtherItems", false); - Vendor_TGs = sConfigMgr->GetOption ("AuctionHouseBot.VendorTradeGoods", false); - Loot_TGs = sConfigMgr->GetOption ("AuctionHouseBot.LootTradeGoods", true); - Other_TGs = sConfigMgr->GetOption ("AuctionHouseBot.OtherTradeGoods", false); - - // - // Flags: items binding - // - - No_Bind = sConfigMgr->GetOption ("AuctionHouseBot.No_Bind", true); - Bind_When_Picked_Up = sConfigMgr->GetOption ("AuctionHouseBot.Bind_When_Picked_Up", false); - Bind_When_Equipped = sConfigMgr->GetOption ("AuctionHouseBot.Bind_When_Equipped", true); - Bind_When_Use = sConfigMgr->GetOption ("AuctionHouseBot.Bind_When_Use", true); - Bind_Quest_Item = sConfigMgr->GetOption ("AuctionHouseBot.Bind_Quest_Item", false); - - // - // Flags: misc - // - - DisableConjured = sConfigMgr->GetOption ("AuctionHouseBot.DisableConjured", false); - DisableGems = sConfigMgr->GetOption ("AuctionHouseBot.DisableGems", false); - DisableMoney = sConfigMgr->GetOption ("AuctionHouseBot.DisableMoney", false); - DisableMoneyLoot = sConfigMgr->GetOption ("AuctionHouseBot.DisableMoneyLoot", false); - DisableLootable = sConfigMgr->GetOption ("AuctionHouseBot.DisableLootable", false); - DisableKeys = sConfigMgr->GetOption ("AuctionHouseBot.DisableKeys", false); - DisableDuration = sConfigMgr->GetOption ("AuctionHouseBot.DisableDuration", false); - DisableBOP_Or_Quest_NoReqLevel = sConfigMgr->GetOption ("AuctionHouseBot.DisableBOP_Or_Quest_NoReqLevel", false); - - // - // Flags: items per class - // - - DisableWarriorItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableWarriorItems", false); - DisablePaladinItems = sConfigMgr->GetOption ("AuctionHouseBot.DisablePaladinItems", false); - DisableHunterItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableHunterItems", false); - DisableRogueItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableRogueItems", false); - DisablePriestItems = sConfigMgr->GetOption ("AuctionHouseBot.DisablePriestItems", false); - DisableDKItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableDKItems", false); - DisableShamanItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableShamanItems", false); - DisableMageItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableMageItems", false); - DisableWarlockItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableWarlockItems", false); - DisableUnusedClassItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableUnusedClassItems", false); - DisableDruidItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableDruidItems", false); - - // - // Items level and skills - // - - DisableItemsBelowLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowLevel", 0); - DisableItemsAboveLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveLevel", 0); - DisableItemsBelowGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowGUID", 0); - DisableItemsAboveGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveGUID", 0); - DisableItemsBelowReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowReqLevel", 0); - DisableItemsAboveReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveReqLevel", 0); - DisableItemsBelowReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowReqSkillRank", 0); - DisableItemsAboveReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveReqSkillRank", 0); - - // - // Trade goods level and skills - // - - DisableTGsBelowLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowLevel", 0); - DisableTGsAboveLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveLevel", 0); - DisableTGsBelowGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowGUID", 0); - DisableTGsAboveGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveGUID", 0); - DisableTGsBelowReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowReqLevel", 0); - DisableTGsAboveReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveReqLevel", 0); - DisableTGsBelowReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowReqSkillRank", 0); - DisableTGsAboveReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveReqSkillRank", 0); - - // - // Whitelists - // - - SellerWhiteList = getCommaSeparatedIntegers(sConfigMgr->GetOption("AuctionHouseBot.SellerWhiteList", "")); -} + // + // Save the pointer for the configurations + // -// ============================================================================= -// Loads options from the database -// ============================================================================= + _allianceConfig = allianceConfig; + _hordeConfig = hordeConfig; + _neutralConfig = neutralConfig; -void AuctionHouseBot::LoadValues(AHBConfig* config) -{ // - // Auctions seller + // Done // - if (AHBSeller) - { - // - // Load min and max items - // - - config->SetMinItems(WorldDatabase.Query("SELECT minitems FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxItems(WorldDatabase.Query("SELECT maxitems FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - - // - // Load percentages - // - - uint32 greytg = WorldDatabase.Query("SELECT percentgreytradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 whitetg = WorldDatabase.Query("SELECT percentwhitetradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 greentg = WorldDatabase.Query("SELECT percentgreentradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 bluetg = WorldDatabase.Query("SELECT percentbluetradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 purpletg = WorldDatabase.Query("SELECT percentpurpletradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 orangetg = WorldDatabase.Query("SELECT percentorangetradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 yellowtg = WorldDatabase.Query("SELECT percentyellowtradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - - uint32 greyi = WorldDatabase.Query("SELECT percentgreyitems FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 whitei = WorldDatabase.Query("SELECT percentwhiteitems FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 greeni = WorldDatabase.Query("SELECT percentgreenitems FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 bluei = WorldDatabase.Query("SELECT percentblueitems FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 purplei = WorldDatabase.Query("SELECT percentpurpleitems FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 orangei = WorldDatabase.Query("SELECT percentorangeitems FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - uint32 yellowi = WorldDatabase.Query("SELECT percentyellowitems FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get(); - - config->SetPercentages(greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi); - - // - // Load min and max prices - // - - config->SetMinPrice(AHB_GREY , WorldDatabase.Query("SELECT minpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxPrice(AHB_GREY , WorldDatabase.Query("SELECT maxpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinPrice(AHB_WHITE , WorldDatabase.Query("SELECT minpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxPrice(AHB_WHITE , WorldDatabase.Query("SELECT maxpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinPrice(AHB_GREEN , WorldDatabase.Query("SELECT minpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxPrice(AHB_GREEN , WorldDatabase.Query("SELECT maxpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinPrice(AHB_BLUE , WorldDatabase.Query("SELECT minpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxPrice(AHB_BLUE , WorldDatabase.Query("SELECT maxpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinPrice(AHB_PURPLE, WorldDatabase.Query("SELECT minpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxPrice(AHB_PURPLE, WorldDatabase.Query("SELECT maxpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinPrice(AHB_ORANGE, WorldDatabase.Query("SELECT minpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxPrice(AHB_ORANGE, WorldDatabase.Query("SELECT maxpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinPrice(AHB_YELLOW, WorldDatabase.Query("SELECT minpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxPrice(AHB_YELLOW, WorldDatabase.Query("SELECT maxpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - - // - // Load min and max bid prices - // - - config->SetMinBidPrice(AHB_GREY , WorldDatabase.Query("SELECT minbidpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxBidPrice(AHB_GREY , WorldDatabase.Query("SELECT maxbidpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinBidPrice(AHB_WHITE , WorldDatabase.Query("SELECT minbidpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxBidPrice(AHB_WHITE , WorldDatabase.Query("SELECT maxbidpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinBidPrice(AHB_GREEN , WorldDatabase.Query("SELECT minbidpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxBidPrice(AHB_GREEN , WorldDatabase.Query("SELECT maxbidpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinBidPrice(AHB_BLUE , WorldDatabase.Query("SELECT minbidpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxBidPrice(AHB_BLUE , WorldDatabase.Query("SELECT maxbidpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinBidPrice(AHB_PURPLE, WorldDatabase.Query("SELECT minbidpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxBidPrice(AHB_PURPLE, WorldDatabase.Query("SELECT maxbidpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinBidPrice(AHB_ORANGE, WorldDatabase.Query("SELECT minbidpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxBidPrice(AHB_ORANGE, WorldDatabase.Query("SELECT maxbidpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMinBidPrice(AHB_YELLOW, WorldDatabase.Query("SELECT minbidpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxBidPrice(AHB_YELLOW, WorldDatabase.Query("SELECT maxbidpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - - // - // Load max stacks - // - - config->SetMaxStack(AHB_GREY , WorldDatabase.Query("SELECT maxstackgrey FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxStack(AHB_WHITE , WorldDatabase.Query("SELECT maxstackwhite FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxStack(AHB_GREEN , WorldDatabase.Query("SELECT maxstackgreen FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxStack(AHB_BLUE , WorldDatabase.Query("SELECT maxstackblue FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxStack(AHB_PURPLE, WorldDatabase.Query("SELECT maxstackpurple FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxStack(AHB_ORANGE, WorldDatabase.Query("SELECT maxstackorange FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetMaxStack(AHB_YELLOW, WorldDatabase.Query("SELECT maxstackyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - - if (debug_Out_Config) - { - LOG_INFO("module", "Settings for Auctionhouse {}", config->GetAHID()); - LOG_INFO("module", "minItems = {}", config->GetMinItems()); - LOG_INFO("module", "maxItems = {}", config->GetMaxItems()); - LOG_INFO("module", "percentGreyTradeGoods = {}", config->GetPercentages(AHB_GREY_TG)); - LOG_INFO("module", "percentWhiteTradeGoods = {}", config->GetPercentages(AHB_WHITE_TG)); - LOG_INFO("module", "percentGreenTradeGoods = {}", config->GetPercentages(AHB_GREEN_TG)); - LOG_INFO("module", "percentBlueTradeGoods = {}", config->GetPercentages(AHB_BLUE_TG)); - LOG_INFO("module", "percentPurpleTradeGoods = {}", config->GetPercentages(AHB_PURPLE_TG)); - LOG_INFO("module", "percentOrangeTradeGoods = {}", config->GetPercentages(AHB_ORANGE_TG)); - LOG_INFO("module", "percentYellowTradeGoods = {}", config->GetPercentages(AHB_YELLOW_TG)); - LOG_INFO("module", "percentGreyItems = {}", config->GetPercentages(AHB_GREY_I)); - LOG_INFO("module", "percentWhiteItems = {}", config->GetPercentages(AHB_WHITE_I)); - LOG_INFO("module", "percentGreenItems = {}", config->GetPercentages(AHB_GREEN_I)); - LOG_INFO("module", "percentBlueItems = {}", config->GetPercentages(AHB_BLUE_I)); - LOG_INFO("module", "percentPurpleItems = {}", config->GetPercentages(AHB_PURPLE_I)); - LOG_INFO("module", "percentOrangeItems = {}", config->GetPercentages(AHB_ORANGE_I)); - LOG_INFO("module", "percentYellowItems = {}", config->GetPercentages(AHB_YELLOW_I)); - LOG_INFO("module", "minPriceGrey = {}", config->GetMinPrice(AHB_GREY)); - LOG_INFO("module", "maxPriceGrey = {}", config->GetMaxPrice(AHB_GREY)); - LOG_INFO("module", "minPriceWhite = {}", config->GetMinPrice(AHB_WHITE)); - LOG_INFO("module", "maxPriceWhite = {}", config->GetMaxPrice(AHB_WHITE)); - LOG_INFO("module", "minPriceGreen = {}", config->GetMinPrice(AHB_GREEN)); - LOG_INFO("module", "maxPriceGreen = {}", config->GetMaxPrice(AHB_GREEN)); - LOG_INFO("module", "minPriceBlue = {}", config->GetMinPrice(AHB_BLUE)); - LOG_INFO("module", "maxPriceBlue = {}", config->GetMaxPrice(AHB_BLUE)); - LOG_INFO("module", "minPricePurple = {}", config->GetMinPrice(AHB_PURPLE)); - LOG_INFO("module", "maxPricePurple = {}", config->GetMaxPrice(AHB_PURPLE)); - LOG_INFO("module", "minPriceOrange = {}", config->GetMinPrice(AHB_ORANGE)); - LOG_INFO("module", "maxPriceOrange = {}", config->GetMaxPrice(AHB_ORANGE)); - LOG_INFO("module", "minPriceYellow = {}", config->GetMinPrice(AHB_YELLOW)); - LOG_INFO("module", "maxPriceYellow = {}", config->GetMaxPrice(AHB_YELLOW)); - LOG_INFO("module", "minBidPriceGrey = {}", config->GetMinBidPrice(AHB_GREY)); - LOG_INFO("module", "maxBidPriceGrey = {}", config->GetMaxBidPrice(AHB_GREY)); - LOG_INFO("module", "minBidPriceWhite = {}", config->GetMinBidPrice(AHB_WHITE)); - LOG_INFO("module", "maxBidPriceWhite = {}", config->GetMaxBidPrice(AHB_WHITE)); - LOG_INFO("module", "minBidPriceGreen = {}", config->GetMinBidPrice(AHB_GREEN)); - LOG_INFO("module", "maxBidPriceGreen = {}", config->GetMaxBidPrice(AHB_GREEN)); - LOG_INFO("module", "minBidPriceBlue = {}", config->GetMinBidPrice(AHB_BLUE)); - LOG_INFO("module", "maxBidPriceBlue = {}", config->GetMinBidPrice(AHB_BLUE)); - LOG_INFO("module", "minBidPricePurple = {}", config->GetMinBidPrice(AHB_PURPLE)); - LOG_INFO("module", "maxBidPricePurple = {}", config->GetMaxBidPrice(AHB_PURPLE)); - LOG_INFO("module", "minBidPriceOrange = {}", config->GetMinBidPrice(AHB_ORANGE)); - LOG_INFO("module", "maxBidPriceOrange = {}", config->GetMaxBidPrice(AHB_ORANGE)); - LOG_INFO("module", "minBidPriceYellow = {}", config->GetMinBidPrice(AHB_YELLOW)); - LOG_INFO("module", "maxBidPriceYellow = {}", config->GetMaxBidPrice(AHB_YELLOW)); - LOG_INFO("module", "maxStackGrey = {}", config->GetMaxStack(AHB_GREY)); - LOG_INFO("module", "maxStackWhite = {}", config->GetMaxStack(AHB_WHITE)); - LOG_INFO("module", "maxStackGreen = {}", config->GetMaxStack(AHB_GREEN)); - LOG_INFO("module", "maxStackBlue = {}", config->GetMaxStack(AHB_BLUE)); - LOG_INFO("module", "maxStackPurple = {}", config->GetMaxStack(AHB_PURPLE)); - LOG_INFO("module", "maxStackOrange = {}", config->GetMaxStack(AHB_ORANGE)); - LOG_INFO("module", "maxStackYellow = {}", config->GetMaxStack(AHB_YELLOW)); - } - - // - // Collect how many items are currently present in the auction house - // - - config->ResetItemCounts(); - - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); - uint32 auctions = auctionHouse->Getcount(); - ObjectGuid playerGuid(HighGuid::Player, 0, AHBplayerGUID); - - if (auctions) - { - for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr) - { - AuctionEntry* Aentry = itr->second; - Item* item = sAuctionMgr->GetAItem(Aentry->item_guid); - - // - // If it has to only consider its auctions, skip the one belonging to the players - // - - if (ConsiderOnlyBotAuctions) - { - if (playerGuid != Aentry->owner) - { - continue; - } - } - - if (item) - { - ItemTemplate const* prototype = item->GetTemplate(); - - if (prototype) - { - switch (prototype->Quality) - { - case AHB_GREY: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - { - config->IncItemCounts(AHB_GREY_TG); - } - else - { - config->IncItemCounts(AHB_GREY_I); - } - break; - - case AHB_WHITE: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - { - config->IncItemCounts(AHB_WHITE_TG); - } - else - { - config->IncItemCounts(AHB_WHITE_I); - } - - break; - - case AHB_GREEN: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - { - config->IncItemCounts(AHB_GREEN_TG); - } - else - { - config->IncItemCounts(AHB_GREEN_I); - } - - break; - - case AHB_BLUE: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - { - config->IncItemCounts(AHB_BLUE_TG); - } - else - { - config->IncItemCounts(AHB_BLUE_I); - } - - break; - - case AHB_PURPLE: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - { - config->IncItemCounts(AHB_PURPLE_TG); - } - else - { - config->IncItemCounts(AHB_PURPLE_I); - } - - break; - - case AHB_ORANGE: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - { - config->IncItemCounts(AHB_ORANGE_TG); - } - else - { - config->IncItemCounts(AHB_ORANGE_I); - } - - break; - - case AHB_YELLOW: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - { - config->IncItemCounts(AHB_YELLOW_TG); - } - else - { - config->IncItemCounts(AHB_YELLOW_I); - } - - break; - } - } - } - } - } - - if (debug_Out_Config) - { - LOG_INFO("module", "Current compatible auctions presents on auctionhouse {}", config->GetAHID()); - LOG_INFO("module", " Grey Trade Goods {}", config->GetItemCounts(AHB_GREY_TG)); - LOG_INFO("module", " White Trade Goods {}", config->GetItemCounts(AHB_WHITE_TG)); - LOG_INFO("module", " Green Trade Goods {}", config->GetItemCounts(AHB_GREEN_TG)); - LOG_INFO("module", " Blue Trade Goods {}", config->GetItemCounts(AHB_BLUE_TG)); - LOG_INFO("module", " Purple Trade Goods {}", config->GetItemCounts(AHB_PURPLE_TG)); - LOG_INFO("module", " Orange Trade Goods {}", config->GetItemCounts(AHB_ORANGE_TG)); - LOG_INFO("module", " Yellow Trade Goods {}", config->GetItemCounts(AHB_YELLOW_TG)); - LOG_INFO("module", " Grey Items {}", config->GetItemCounts(AHB_GREY_I)); - LOG_INFO("module", " White Items {}", config->GetItemCounts(AHB_WHITE_I)); - LOG_INFO("module", " Green Items {}", config->GetItemCounts(AHB_GREEN_I)); - LOG_INFO("module", " Blue Items {}", config->GetItemCounts(AHB_BLUE_I)); - LOG_INFO("module", " Purple Items {}", config->GetItemCounts(AHB_PURPLE_I)); - LOG_INFO("module", " Orange Items {}", config->GetItemCounts(AHB_ORANGE_I)); - LOG_INFO("module", " Yellow Items {}", config->GetItemCounts(AHB_YELLOW_I)); - } - } - - // - // Auctions buyer - // - - if (AHBBuyer) - { - // - // Load buyer bid prices - // - - config->SetBuyerPrice(AHB_GREY , WorldDatabase.Query("SELECT buyerpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetBuyerPrice(AHB_WHITE , WorldDatabase.Query("SELECT buyerpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetBuyerPrice(AHB_GREEN , WorldDatabase.Query("SELECT buyerpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetBuyerPrice(AHB_BLUE , WorldDatabase.Query("SELECT buyerpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetBuyerPrice(AHB_PURPLE, WorldDatabase.Query("SELECT buyerpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetBuyerPrice(AHB_ORANGE, WorldDatabase.Query("SELECT buyerpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - config->SetBuyerPrice(AHB_YELLOW, WorldDatabase.Query("SELECT buyerpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - - // - // Load bidding interval - // - - config->SetBiddingInterval(WorldDatabase.Query("SELECT buyerbiddinginterval FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - - // - // Load bids per interval - // - - config->SetBidsPerInterval(WorldDatabase.Query("SELECT buyerbidsperinterval FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - - if (debug_Out_Config) - { - LOG_INFO("module", "Current Settings for Auctionhouse {} buyer", config->GetAHID()); - LOG_INFO("module", "buyerPriceGrey = {}", config->GetBuyerPrice(AHB_GREY)); - LOG_INFO("module", "buyerPriceWhite = {}", config->GetBuyerPrice(AHB_WHITE)); - LOG_INFO("module", "buyerPriceGreen = {}", config->GetBuyerPrice(AHB_GREEN)); - LOG_INFO("module", "buyerPriceBlue = {}", config->GetBuyerPrice(AHB_BLUE)); - LOG_INFO("module", "buyerPricePurple = {}", config->GetBuyerPrice(AHB_PURPLE)); - LOG_INFO("module", "buyerPriceOrange = {}", config->GetBuyerPrice(AHB_ORANGE)); - LOG_INFO("module", "buyerPriceYellow = {}", config->GetBuyerPrice(AHB_YELLOW)); - LOG_INFO("module", "buyerBiddingInterval = {}", config->GetBiddingInterval()); - LOG_INFO("module", "buyerBidsPerInterval = {}", config->GetBidsPerInterval()); - } - } -} - -// ============================================================================= -// Initialization of the bot -// ============================================================================= - -void AuctionHouseBot::Initialize() -{ - // - // Reload the list of disabled items - // - - DisableItemStore.clear(); - - QueryResult result = WorldDatabase.Query("SELECT item FROM mod_auctionhousebot_disabled_items"); - - if (result) - { - do - { - Field* fields = result->Fetch(); - DisableItemStore.insert(fields[0].Get()); - } while (result->NextRow()); - } - - // - // Check if the AHBot account/GUID in the config actually exists - // - - if ((AHBplayerAccount != 0) || (AHBplayerGUID != 0)) - { - QueryResult result = CharacterDatabase.Query("SELECT 1 FROM characters WHERE account = {} AND guid = {}", AHBplayerAccount, AHBplayerGUID); - - if (!result) - { - LOG_ERROR("module", "AuctionHouseBot: The account/GUID-information set for your AHBot is incorrect (account: {} guid: {})", AHBplayerAccount, AHBplayerGUID); - return; - } - } - - // - // Load the configuration for every auction house denpending on the configuration - // - - if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) - { - LoadValues(&AllianceConfig); - LoadValues(&HordeConfig); - } - - LoadValues(&NeutralConfig); - - // - // Organize the lists of items to be sold - // - - if (AHBSeller) - { - // - // Process vendors items - // - - QueryResult results = WorldDatabase.Query("SELECT distinct item FROM npc_vendor"); - - if (results) - { - do - { - Field* fields = results->Fetch(); - npcItems.push_back(fields[0].Get()); - - } while (results->NextRow()); - } - else - { - if (debug_Out) - { - LOG_ERROR("module", "AuctionHouseBot: failed to retrieve npc items"); - } - } - - // - // Process loot items - // - - results = WorldDatabase.Query( - "SELECT item FROM creature_loot_template UNION " - "SELECT item FROM reference_loot_template UNION " - "SELECT item FROM disenchant_loot_template UNION " - "SELECT item FROM fishing_loot_template UNION " - "SELECT item FROM gameobject_loot_template UNION " - "SELECT item FROM item_loot_template UNION " - "SELECT item FROM milling_loot_template UNION " - "SELECT item FROM pickpocketing_loot_template UNION " - "SELECT item FROM prospecting_loot_template UNION " - "SELECT item FROM skinning_loot_template"); - - if (results) - { - do - { - Field* fields = results->Fetch(); - lootItems.push_back(fields[0].Get()); - - } while (results->NextRow()); - } - else - { - if (debug_Out) - { - LOG_ERROR("module", "AuctionHouseBot: failed to retrieve loot items"); - } - } - - // - // Exclude items depending on the configuration; whatever passes all the tests is put in the lists. - // - - ItemTemplateContainer const* its = sObjectMgr->GetItemTemplateStore(); - - for (ItemTemplateContainer::const_iterator itr = its->begin(); itr != its->end(); ++itr) - { - // - // Exclude items with the blocked binding type - // - - if (itr->second.Bonding == NO_BIND && !No_Bind) - { - continue; - } - - if (itr->second.Bonding == BIND_WHEN_PICKED_UP && !Bind_When_Picked_Up) - { - continue; - } - - if (itr->second.Bonding == BIND_WHEN_EQUIPED && !Bind_When_Equipped) - { - continue; - } - - if (itr->second.Bonding == BIND_WHEN_USE && !Bind_When_Use) - { - continue; - } - - if (itr->second.Bonding == BIND_QUEST_ITEM && !Bind_Quest_Item) - { - continue; - } - - // - // Exclude items with no possible price - // - - if (SellMethod) - { - if (itr->second.BuyPrice == 0) - { - continue; - } - } - else - { - if (itr->second.SellPrice == 0) - { - continue; - } - } - - // - // Exclude items with no costs associated, in any case - // - - if ((itr->second.BuyPrice == 0) && (itr->second.SellPrice == 0)) - { - continue; - } - - // - // Exlude items superior to the limit quality - // - - if (itr->second.Quality > 6) - { - continue; - } - - // - // Exclude trade goods items - // - - if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) - { - bool isNpc = false; - bool isLoot = false; - bool exclude = false; - - for (unsigned int i = 0; i < npcItems.size(); i++) - { - if (itr->second.ItemId == npcItems[i]) - { - isNpc = true; - - if (!Vendor_TGs) - { - exclude = true; - } - - break; - } - } - - // Perform the loop only if exlude is not already true - for (unsigned int i = 0; i < lootItems.size() && !exclude; i++) - { - if (itr->second.ItemId == lootItems[i]) - { - isLoot = true; - - if (!Loot_TGs) - { - exclude = true; - } - - break; - } - } - - if (exclude) - { - continue; - } - - if (!Other_TGs) - { - if (!isNpc && !isLoot) - { - continue; - } - } - } - - // - // Exclude loot items - // - - if (itr->second.Class != ITEM_CLASS_TRADE_GOODS) - { - bool isNpc = false; - bool isLoot = false; - bool exclude = false; - - for (unsigned int i = 0; i < npcItems.size(); i++) - { - if (itr->second.ItemId == npcItems[i]) - { - isNpc = true; - - if (!Vendor_Items) - { - exclude = true; - } - - break; - } - } - - // Perform the loop only if exlude is not already true - for (unsigned int i = 0; i < lootItems.size() && !exclude; i++) - { - if (itr->second.ItemId == lootItems[i]) - { - isLoot = true; - - if (!Loot_Items) - { - exclude = true; - } - - break; - } - - } - - if (exclude) - { - continue; - } - - if (!Other_Items) - { - if (!isNpc && !isLoot) - { - continue; - } - } - } - - // - // Verify if the item is disabled or not in the whitelist - // - - if (SellerWhiteList.size() == 0) - { - if (DisableItemStore.find(itr->second.ItemId) != DisableItemStore.end()) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (PTR/Beta/Unused Item)", itr->second.ItemId); - } - - continue; - } - } - else - { - if (SellerWhiteList.find(itr->second.ItemId) == SellerWhiteList.end()) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (no in the whitelist)", itr->second.ItemId); - } - - continue; - } - } - - // - // Disable permanent enchants items - // - - if ((DisablePermEnchant) && (itr->second.Class == ITEM_CLASS_PERMANENT)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Permanent Enchant Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable conjured items - // - - if ((DisableConjured) && (itr->second.IsConjuredConsumable())) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Conjured Consumable)", itr->second.ItemId); - } - - continue; - } - - // - // Disable gems - // - - if ((DisableGems) && (itr->second.Class == ITEM_CLASS_GEM)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Gem)", itr->second.ItemId); - } - - continue; - } - - // - // Disable money - // - - if ((DisableMoney) && (itr->second.Class == ITEM_CLASS_MONEY)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Money)", itr->second.ItemId); - } - - continue; - } - - // - // Disable moneyloot - // - - if ((DisableMoneyLoot) && (itr->second.MinMoneyLoot > 0)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (MoneyLoot)", itr->second.ItemId); - } - - continue; - } - - // - // Disable lootable items - // - - if ((DisableLootable) && (itr->second.Flags & 4)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Lootable Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable Keys - // - - if ((DisableKeys) && (itr->second.Class == ITEM_CLASS_KEY)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Quest Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items with duration - // - - if ((DisableDuration) && (itr->second.Duration > 0)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Has a Duration)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items which are BOP or Quest Items and have a required level lower than the item level - // - - if ((DisableBOP_Or_Quest_NoReqLevel) && ((itr->second.Bonding == BIND_WHEN_PICKED_UP || itr->second.Bonding == BIND_QUEST_ITEM) && (itr->second.RequiredLevel < itr->second.ItemLevel))) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (BOP or BQI and Required Level is less than Item Level)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items specifically for Warrior - // - - if ((DisableWarriorItems) && (itr->second.AllowableClass == AHB_CLASS_WARRIOR)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Warrior Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items specifically for Paladin - // - - if ((DisablePaladinItems) && (itr->second.AllowableClass == AHB_CLASS_PALADIN)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Paladin Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items specifically for Hunter - // - - if ((DisableHunterItems) && (itr->second.AllowableClass == AHB_CLASS_HUNTER)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Hunter Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items specifically for Rogue - // - - if ((DisableRogueItems) && (itr->second.AllowableClass == AHB_CLASS_ROGUE)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Rogue Item)", itr->second.ItemId); - continue; - } - - // - // Disable items specifically for Priest - // - - if ((DisablePriestItems) && (itr->second.AllowableClass == AHB_CLASS_PRIEST)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Priest Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items specifically for DK - // - - if ((DisableDKItems) && (itr->second.AllowableClass == AHB_CLASS_DK)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (DK Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items specifically for Shaman - // - - if ((DisableShamanItems) && (itr->second.AllowableClass == AHB_CLASS_SHAMAN)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Shaman Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items specifically for Mage - // - - if ((DisableMageItems) && (itr->second.AllowableClass == AHB_CLASS_MAGE)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Mage Item)", itr->second.ItemId); - continue; - } - - // - // Disable items specifically for Warlock - // - - if ((DisableWarlockItems) && (itr->second.AllowableClass == AHB_CLASS_WARLOCK)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Warlock Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items specifically for Unused Class - // - - if ((DisableUnusedClassItems) && (itr->second.AllowableClass == AHB_CLASS_UNUSED)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Unused Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable items specifically for Druid - // - - if ((DisableDruidItems) && (itr->second.AllowableClass == AHB_CLASS_DRUID)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Druid Item)", itr->second.ItemId); - } - - continue; - } - - // - // Disable Items below level X - // - - if ((DisableItemsBelowLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel < DisableItemsBelowLevel)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); - } - - continue; - } - - // - // Disable Items above level X - // - - if ((DisableItemsAboveLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel > DisableItemsAboveLevel)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); - } - - continue; - } - - // - // Disable Trade Goods below level X - // - - if ((DisableTGsBelowLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel < DisableTGsBelowLevel)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); - } - - continue; - } - - // - // Disable Trade Goods above level X - // - - if ((DisableTGsAboveLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel > DisableTGsAboveLevel)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); - } - - continue; - } - - // - // Disable Items below GUID X - // - - if ((DisableItemsBelowGUID) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId < DisableItemsBelowGUID)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); - } - - continue; - } - - // - // Disable Items above GUID X - // - - if ((DisableItemsAboveGUID) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId > DisableItemsAboveGUID)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); - } - - continue; - } - - // - // Disable Trade Goods below GUID X - // - - if ((DisableTGsBelowGUID) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId < DisableTGsBelowGUID)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); - } - - continue; - } - - // - // Disable Trade Goods above GUID X - // - - if ((DisableTGsAboveGUID) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId > DisableTGsAboveGUID)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); - } - - continue; - } - - // - // Disable Items for level lower than X - // - - if ((DisableItemsBelowReqLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel < DisableItemsBelowReqLevel)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); - } - - continue; - } - - // - // Disable Items for level higher than X - // - - if ((DisableItemsAboveReqLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel > DisableItemsAboveReqLevel)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); - } - - continue; - } - - // - // Disable Trade Goods for level lower than X - // - - if ((DisableTGsBelowReqLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel < DisableTGsBelowReqLevel)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); - } - - continue; - } - - // - // Disable Trade Goods for level higher than X - // - - if ((DisableTGsAboveReqLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel > DisableTGsAboveReqLevel)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); - } - - continue; - } - - // - // Disable Items that require skill lower than X - // - - if ((DisableItemsBelowReqSkillRank) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank < DisableItemsBelowReqSkillRank)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); - } - - continue; - } - - // - // Disable Items that require skill higher than X - // - - if ((DisableItemsAboveReqSkillRank) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank > DisableItemsAboveReqSkillRank)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); - } - - continue; - } - - // - // Disable Trade Goods that require skill lower than X - // - - if ((DisableTGsBelowReqSkillRank) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank < DisableTGsBelowReqSkillRank)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); - } - - continue; - } - - // - // Disable Trade Goods that require skill higher than X - // - - if ((DisableTGsAboveReqSkillRank) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank > DisableTGsAboveReqSkillRank)) - { - if (debug_Out_Filters) - { - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); - } - - continue; - } - - // - // Now that the items passed all the tests, organize it by quality - // - - if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) - { - switch (itr->second.Quality) - { - case AHB_GREY: - greyTradeGoodsBin.push_back(itr->second.ItemId); - break; - - case AHB_WHITE: - whiteTradeGoodsBin.push_back(itr->second.ItemId); - break; - - case AHB_GREEN: - greenTradeGoodsBin.push_back(itr->second.ItemId); - break; - - case AHB_BLUE: - blueTradeGoodsBin.push_back(itr->second.ItemId); - break; - - case AHB_PURPLE: - purpleTradeGoodsBin.push_back(itr->second.ItemId); - break; - - case AHB_ORANGE: - orangeTradeGoodsBin.push_back(itr->second.ItemId); - break; - - case AHB_YELLOW: - yellowTradeGoodsBin.push_back(itr->second.ItemId); - break; - } - } - else - { - switch (itr->second.Quality) - { - case AHB_GREY: - greyItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_WHITE: - whiteItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_GREEN: - greenItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_BLUE: - blueItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_PURPLE: - purpleItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_ORANGE: - orangeItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_YELLOW: - yellowItemsBin.push_back(itr->second.ItemId); - break; - } - } - } - - // - // Disable the seller if no items passed the test - // - - if ((greyTradeGoodsBin.size() == 0) && - (whiteTradeGoodsBin.size() == 0) && - (greenTradeGoodsBin.size() == 0) && - (blueTradeGoodsBin.size() == 0) && - (purpleTradeGoodsBin.size() == 0) && - (orangeTradeGoodsBin.size() == 0) && - (yellowTradeGoodsBin.size() == 0) && - (greyItemsBin.size() == 0) && - (whiteItemsBin.size() == 0) && - (greenItemsBin.size() == 0) && - (blueItemsBin.size() == 0) && - (purpleItemsBin.size() == 0) && - (orangeItemsBin.size() == 0) && - (yellowItemsBin.size() == 0)) - { - LOG_ERROR("module", "AuctionHouseBot: No items, seller disabled"); - AHBSeller = 0; - } - - LOG_INFO("module", "AuctionHouseBot:"); - - if (SellerWhiteList.size() == 0) - { - LOG_INFO("module", "{} disabled items", uint32(DisableItemStore.size())); - } - else - { - LOG_INFO("module", "Using a whitelist of {} items", uint32(SellerWhiteList.size())); - } - - LOG_INFO("module", "loaded {} grey trade goods", uint32(greyTradeGoodsBin.size())); - LOG_INFO("module", "loaded {} white trade goods", uint32(whiteTradeGoodsBin.size())); - LOG_INFO("module", "loaded {} green trade goods", uint32(greenTradeGoodsBin.size())); - LOG_INFO("module", "loaded {} blue trade goods", uint32(blueTradeGoodsBin.size())); - LOG_INFO("module", "loaded {} purple trade goods", uint32(purpleTradeGoodsBin.size())); - LOG_INFO("module", "loaded {} orange trade goods", uint32(orangeTradeGoodsBin.size())); - LOG_INFO("module", "loaded {} yellow trade goods", uint32(yellowTradeGoodsBin.size())); - LOG_INFO("module", "loaded {} grey items" , uint32(greyItemsBin.size())); - LOG_INFO("module", "loaded {} white items" , uint32(whiteItemsBin.size())); - LOG_INFO("module", "loaded {} green items" , uint32(greenItemsBin.size())); - LOG_INFO("module", "loaded {} blue items" , uint32(blueItemsBin.size())); - LOG_INFO("module", "loaded {} purple items" , uint32(purpleItemsBin.size())); - LOG_INFO("module", "loaded {} orange items" , uint32(orangeItemsBin.size())); - LOG_INFO("module", "loaded {} yellow items" , uint32(yellowItemsBin.size())); - } - - LOG_INFO("module", "AuctionHouseBot and AuctionHouseBuyer have been loaded."); + LOG_INFO("module", "AHBot [{}]: initialization complete", uint32(_id)); } diff --git a/src/AuctionHouseBot.h b/src/AuctionHouseBot.h index e96866a..9f6b38d 100644 --- a/src/AuctionHouseBot.h +++ b/src/AuctionHouseBot.h @@ -23,6 +23,7 @@ #include "Common.h" #include "ObjectGuid.h" #include "AuctionHouseMgr.h" + #include "AuctionHouseBotCommon.h" #include "AuctionHouseBotConfig.h" @@ -33,106 +34,16 @@ class WorldSession; class AuctionHouseBot { private: + uint32 _account; + uint32 _id; - bool debug_Out; - bool debug_Out_Config; - bool debug_Out_Buyer; - bool debug_Out_Seller; - bool trace_Seller; - bool debug_Out_Filters; - - bool AHBSeller; - bool AHBBuyer; - bool BuyMethod; - bool SellMethod; - bool ConsiderOnlyBotAuctions; - - uint32 ItemsPerCycle; - uint32 AHBplayerAccount; + AHBConfig* _allianceConfig; + AHBConfig* _hordeConfig; + AHBConfig* _neutralConfig; - ObjectGuid::LowType AHBplayerGUID; - - // - // Begin Filters - // - - bool Vendor_Items; - bool Loot_Items; - bool Other_Items; - bool Vendor_TGs; - bool Loot_TGs; - bool Other_TGs; - - bool No_Bind; - bool Bind_When_Picked_Up; - bool Bind_When_Equipped; - bool Bind_When_Use; - bool Bind_Quest_Item; - - uint32 DuplicatesCount; - uint32 ElapsingTimeClass; - - bool DivisibleStacks; - bool DisablePermEnchant; - bool DisableConjured; - bool DisableGems; - bool DisableMoney; - bool DisableMoneyLoot; - bool DisableLootable; - bool DisableKeys; - bool DisableDuration; - bool DisableBOP_Or_Quest_NoReqLevel; - - bool DisableWarriorItems; - bool DisablePaladinItems; - bool DisableHunterItems; - bool DisableRogueItems; - bool DisablePriestItems; - bool DisableDKItems; - bool DisableShamanItems; - bool DisableMageItems; - bool DisableWarlockItems; - bool DisableUnusedClassItems; - bool DisableDruidItems; - - uint32 DisableItemsBelowLevel; - uint32 DisableItemsAboveLevel; - - uint32 DisableTGsBelowLevel; - uint32 DisableTGsAboveLevel; - - uint32 DisableItemsBelowGUID; - uint32 DisableItemsAboveGUID; - - uint32 DisableTGsBelowGUID; - uint32 DisableTGsAboveGUID; - - uint32 DisableItemsBelowReqLevel; - uint32 DisableItemsAboveReqLevel; - - uint32 DisableTGsBelowReqLevel; - uint32 DisableTGsAboveReqLevel; - - uint32 DisableItemsBelowReqSkillRank; - uint32 DisableItemsAboveReqSkillRank; - - uint32 DisableTGsBelowReqSkillRank; - uint32 DisableTGsAboveReqSkillRank; - - std::set DisableItemStore; - std::set SellerWhiteList; - - // - // End Filters - // - - AHBConfig AllianceConfig; - AHBConfig HordeConfig; - AHBConfig NeutralConfig; - - time_t _lastrun_a_sec; - time_t _lastrun_h_sec; - time_t _lastrun_n_sec; + time_t _lastrun_a_sec; + time_t _lastrun_h_sec; + time_t _lastrun_n_sec; // // Main operations @@ -147,38 +58,24 @@ class AuctionHouseBot inline uint32 minValue(uint32 a, uint32 b) { return a <= b ? a : b; }; - uint32 getNofAuctions(AuctionHouseObject* auctionHouse, ObjectGuid guid); - uint32 getStackCount(uint32 max); + uint32 getNofAuctions(AHBConfig* config, AuctionHouseObject* auctionHouse, ObjectGuid guid); + uint32 getStackCount(AHBConfig* config, uint32 max); uint32 getElapsedTime(uint32 timeClass); - - std::set getCommaSeparatedIntegers(std::string text); - -// friend class ACE_Singleton; - AuctionHouseBot(); + uint32 getElement(std::set set, int index); public: - static AuctionHouseBot* instance() - { - static AuctionHouseBot instance; - return &instance; - } - + AuctionHouseBot(uint32 account, uint32 id); ~AuctionHouseBot(); + void Initialize(AHBConfig* allianceConfig, AHBConfig* hordeConfig, AHBConfig* neutralConfig); void Update(); - void Initialize(); - void InitializeConfiguration(); - void LoadValues(AHBConfig*); - void DecrementItemCounts(AuctionEntry* ah); void IncrementItemCounts(AuctionEntry* ah); - void Commands(AHBotCommand, uint32, uint32, char*); + void Commands(AHBotCommand command, uint32 ahMapID, uint32 col, char* args); - ObjectGuid::LowType GetAHBplayerGUID() { return AHBplayerGUID; }; + ObjectGuid::LowType GetAHBplayerGUID() { return _id; }; }; -#define auctionbot AuctionHouseBot::instance() - -#endif +#endif // AUCTION_HOUSE_BOT_H diff --git a/src/AuctionHouseBotAuctionHouseScript.cpp b/src/AuctionHouseBotAuctionHouseScript.cpp index dd3b11b..1811b70 100644 --- a/src/AuctionHouseBotAuctionHouseScript.cpp +++ b/src/AuctionHouseBotAuctionHouseScript.cpp @@ -1,4 +1,7 @@ +#include "AuctionHouseMgr.h" + #include "AuctionHouseBot.h" +#include "AuctionHouseBotCommon.h" #include "AuctionHouseBotAuctionHouseScript.h" AHBot_AuctionHouseScript::AHBot_AuctionHouseScript() : AuctionHouseScript("AHBot_AuctionHouseScript") @@ -16,7 +19,7 @@ void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrSendAuctionSuccessfulMail( bool& updateAchievementCriteria, bool& /*sendMail*/) { - if (owner && owner->GetGUID().GetCounter() == auctionbot->GetAHBplayerGUID()) + if (owner && gBotsId.find(owner->GetGUID().GetCounter()) != gBotsId.end()) { sendNotification = false; updateAchievementCriteria = false; @@ -31,7 +34,7 @@ void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrSendAuctionExpiredMail( bool& sendNotification, bool& /* sendMail */) { - if (owner && owner->GetGUID().GetCounter() == auctionbot->GetAHBplayerGUID()) + if (owner && gBotsId.find(owner->GetGUID().GetCounter()) != gBotsId.end()) { sendNotification = false; } @@ -49,36 +52,162 @@ void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrSendAuctionOutbiddedMail( { if (oldBidder && !newBidder) { - oldBidder->GetSession()->SendAuctionBidderNotification( - auction->GetHouseId(), - auction->Id, - ObjectGuid::Create(auctionbot->GetAHBplayerGUID()), - newPrice, - auction->GetAuctionOutBid(), - auction->item_template); + if (gBotsId.size() > 0) + { + // + // Use a random bot id + // + + uint32 randBot = urand(0, gBotsId.size() - 1); + std::set::iterator it = gBotsId.begin(); + std::advance(it, randBot); + + oldBidder->GetSession()->SendAuctionBidderNotification( + auction->GetHouseId(), + auction->Id, + ObjectGuid::Create(*it), + newPrice, + auction->GetAuctionOutBid(), + auction->item_template); + } } } void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionEntry* auction) { + // + // The the configuration for the auction house + // + + AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(auction->GetHouseId()); + AHBConfig* config = gNeutralConfig; + + if (ahEntry) + { + if (ahEntry->houseId == AUCTIONHOUSE_ALLIANCE) + { + config = gAllianceConfig; + } + else if (ahEntry->houseId == AUCTIONHOUSE_HORDE) + { + config = gHordeConfig; + } + } + + // + // Consider only those auctions handled by the bots + // + + if (config->ConsiderOnlyBotAuctions) + { + if (gBotsId.find(auction->owner.GetCounter()) != gBotsId.end()) + { + return; + } + } + + // + // Verify if we can operate on the item + // + + Item* pItem = sAuctionMgr->GetAItem(auction->item_guid); + + if (!pItem) + { + if (config->DebugOut) + { + LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString()); + } + + return; + } + // // Keeps updated the amount of items in the auction // - auctionbot->IncrementItemCounts(auction); + ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template); + + if (config->DebugOut) + { + LOG_INFO("module", "AHBot: ah={}, item={}, count={}", auction->GetHouseId(), auction->item_template, config->GetItemCounts(prototype->Quality)); + } + + config->IncItemCounts(prototype->Class, prototype->Quality); } void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, AuctionEntry* auction) { + + // + // The the configuration for the auction house + // + + AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(auction->GetHouseId()); + AHBConfig* config = gNeutralConfig; + + if (ahEntry) + { + if (ahEntry->houseId == AUCTIONHOUSE_ALLIANCE) + { + config = gAllianceConfig; + } + else if (ahEntry->houseId == AUCTIONHOUSE_HORDE) + { + config = gHordeConfig; + } + } + + // + // Consider only those auctions handled by the bots + // + + if (config->ConsiderOnlyBotAuctions) + { + if (gBotsId.find(auction->owner.GetCounter()) != gBotsId.end()) + { + return; + } + } + // - // Keeps updated the amount of items in the auction + // Verify if we can operate on the item + // + + Item* pItem = sAuctionMgr->GetAItem(auction->item_guid); + + if (!pItem) + { + if (config->DebugOut) + { + LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString()); + } + + return; + } + // + // Decrements + // + + ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template); + + if (config->DebugOut) + { + LOG_INFO("module", "AHBot: ah={}, item={}, count={}", auction->GetHouseId(), auction->item_template, config->GetItemCounts(prototype->Quality)); + } - auctionbot->DecrementItemCounts(auction); + config->DecItemCounts(prototype->Class, prototype->Quality); } void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrUpdate() { - auctionbot->Update(); -} + // + // For every registered bot, perform an update + // + for (AuctionHouseBot* bot: gBots) + { + bot->Update(); + } +} diff --git a/src/AuctionHouseBotCommon.cpp b/src/AuctionHouseBotCommon.cpp new file mode 100644 index 0000000..c0564c9 --- /dev/null +++ b/src/AuctionHouseBotCommon.cpp @@ -0,0 +1,18 @@ +#include "AuctionHouseBot.h" +#include "AuctionHouseBotCommon.h" +#include "AuctionHouseBotConfig.h" + +// +// Configuration used globally by all the bots instances +// + +AHBConfig* gAllianceConfig = new AHBConfig(2); +AHBConfig* gHordeConfig = new AHBConfig(6); +AHBConfig* gNeutralConfig = new AHBConfig(7); + +// +// Active bots +// + +std::set gBotsId; +std::set gBots; \ No newline at end of file diff --git a/src/AuctionHouseBotCommon.h b/src/AuctionHouseBotCommon.h index bd77e90..1e32cd6 100644 --- a/src/AuctionHouseBotCommon.h +++ b/src/AuctionHouseBotCommon.h @@ -20,7 +20,11 @@ #ifndef AUCTION_HOUSE_BOT_COMMON_H #define AUCTION_HOUSE_BOT_COMMON_H -#include "Log.h" +#include + +#include "Common.h" + +class AuctionHouseBot; // // Item quality @@ -90,4 +94,11 @@ enum class AHBotCommand : uint32 bidsperinterval }; +// +// Globals +// + +extern std::set gBotsId; // Active bots players ids +extern std::set gBots; // Active bots + #endif // AUCTION_HOUSE_BOT_COMMON_H diff --git a/src/AuctionHouseBotConfig.cpp b/src/AuctionHouseBotConfig.cpp index 121d4c4..5353ab7 100644 --- a/src/AuctionHouseBotConfig.cpp +++ b/src/AuctionHouseBotConfig.cpp @@ -17,8 +17,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "AuctionHouseMgr.h" #include "Common.h" +#include "Config.h" +#include "DatabaseEnv.h" +#include "Item.h" #include "ItemTemplate.h" +#include "Log.h" +#include "ObjectMgr.h" +#include "WorldSession.h" #include "AuctionHouseBotCommon.h" #include "AuctionHouseBotConfig.h" @@ -56,118 +63,534 @@ AHBConfig::AHBConfig(uint32 ahid) } } +AHBConfig::AHBConfig(uint32 ahid, AHBConfig* conf) +{ + Reset(); + + // + // Ids + // + + AHID = ahid; + + switch (ahid) + { + case 2: + AHFID = 55; // Alliance + break; + + case 6: + AHFID = 29; // Horde + break; + + case 7: + AHFID = 120; // Neutral + break; + + default: + AHFID = 120; // Neutral + break; + } + + // + // Copy the private values + // + + minItems = conf->minItems; + maxItems = conf->maxItems; + percentGreyTradeGoods = conf->percentGreyTradeGoods; + percentWhiteTradeGoods = conf->percentWhiteTradeGoods; + percentGreenTradeGoods = conf->percentGreenTradeGoods; + percentBlueTradeGoods = conf->percentBlueTradeGoods; + percentPurpleTradeGoods = conf->percentPurpleTradeGoods; + percentOrangeTradeGoods = conf->percentOrangeTradeGoods; + percentYellowTradeGoods = conf->percentYellowTradeGoods; + percentGreyItems = conf->percentGreyItems; + percentWhiteItems = conf->percentWhiteItems; + percentGreenItems = conf->percentGreenItems; + percentBlueItems = conf->percentBlueItems; + percentPurpleItems = conf->percentPurpleItems; + percentOrangeItems = conf->percentOrangeItems; + percentYellowItems = conf->percentYellowItems; + minPriceGrey = conf->minPriceGrey; + maxPriceGrey = conf->maxPriceGrey; + minBidPriceGrey = conf->minBidPriceGrey; + maxBidPriceGrey = conf->maxBidPriceGrey; + maxStackGrey = conf->maxStackGrey; + maxPriceWhite = conf->maxPriceWhite; + minBidPriceWhite = conf->minBidPriceWhite; + maxBidPriceWhite = conf->maxBidPriceWhite; + maxStackWhite = conf->maxStackWhite; + minPriceGreen = conf->minPriceGreen; + maxPriceGreen = conf->maxPriceGreen; + minBidPriceGreen = conf->minBidPriceGreen; + maxBidPriceGreen = conf->maxBidPriceGreen; + maxStackGreen = conf->maxStackGreen; + minPriceBlue = conf->minPriceBlue; + maxPriceBlue = conf->maxPriceBlue; + minBidPriceBlue = conf->minBidPriceBlue; + maxBidPriceBlue = conf->maxBidPriceBlue; + maxStackBlue = conf->maxStackBlue; + minPricePurple = conf->minPricePurple; + maxPricePurple = conf->maxPricePurple; + minBidPricePurple = conf->minBidPricePurple; + maxBidPricePurple = conf->maxBidPricePurple; + maxStackPurple = conf->maxStackPurple; + minPriceOrange = conf->minPriceOrange; + maxPriceOrange = conf->maxPriceOrange; + minBidPriceOrange = conf->minBidPriceOrange; + maxBidPriceOrange = conf->maxBidPriceOrange; + maxStackOrange = conf->maxStackOrange; + minPriceYellow = conf->minPriceYellow; + maxPriceYellow = conf->maxPriceYellow; + minBidPriceYellow = conf->minBidPriceYellow; + maxBidPriceYellow = conf->maxBidPriceYellow; + maxStackYellow = conf->maxStackYellow; + buyerPriceGrey = conf->buyerPriceGrey; + buyerPriceWhite = conf->buyerPriceWhite; + buyerPriceGreen = conf->buyerPriceGreen; + buyerPriceBlue = conf->buyerPriceBlue; + buyerPricePurple = conf->buyerPricePurple; + buyerPriceOrange = conf->buyerPriceOrange; + buyerPriceYellow = conf->buyerPriceYellow; + buyerBiddingInterval = conf->buyerBiddingInterval; + buyerBidsPerInterval = conf->buyerBidsPerInterval; + + // This part is acquired thorugh initialization + // + // greytgp = conf->greytgp; + // whitetgp = conf->whitetgp; + // greentgp = conf->greentgp; + // bluetgp = conf->bluetgp; + // purpletgp = conf->purpletgp; + // orangetgp = conf->orangetgp; + // yellowtgp = conf->yellowtgp; + // greyip = conf->greyip; + // whiteip = conf->whiteip; + // greenip = conf->greenip; + // blueip = conf->blueip; + // purpleip = conf->purpleip; + // orangeip = conf->orangeip; + // yellowip = conf->yellowip; + // greyTGoods = conf->greyTGoods; + // whiteTGoods = conf->whiteTGoods; + // greenTGoods = conf->greenTGoods; + // blueTGoods = conf->blueTGoods; + // purpleTGoods = conf->purpleTGoods; + // orangeTGoods = conf->orangeTGoods; + // yellowTGoods = conf->yellowTGoods; + // greyItems = conf->greyItems; + // whiteItems = conf->whiteItems; + // greenItems = conf->greenItems; + // blueItems = conf->blueItems; + // purpleItems = conf->purpleItems; + // orangeItems = conf->orangeItems; + // yellowItems = conf->yellowItems; + + // + // Copy the public properties + // + + DebugOut = conf->DebugOut; + DebugOutConfig = conf->DebugOutConfig; + DebugOutFilters = conf->DebugOutFilters; + DebugOutBuyer = conf->DebugOutBuyer; + DebugOutSeller = conf->DebugOutSeller; + TraceSeller = conf->TraceSeller; + TraceBuyer = conf->TraceBuyer; + AHBSeller = conf->AHBSeller; + AHBBuyer = conf->AHBBuyer; + BuyMethod = conf->BuyMethod; + SellMethod = conf->SellMethod; + ConsiderOnlyBotAuctions = conf->ConsiderOnlyBotAuctions; + ItemsPerCycle = conf->ItemsPerCycle; + Vendor_Items = conf->Vendor_Items; + Loot_Items = conf->Loot_Items; + Other_Items = conf->Other_Items; + Vendor_TGs = conf->Vendor_TGs; + Loot_TGs = conf->Loot_TGs; + Other_TGs = conf->Other_TGs; + No_Bind = conf->No_Bind; + Bind_When_Picked_Up = conf->Bind_When_Picked_Up; + Bind_When_Equipped = conf->Bind_When_Equipped; + Bind_When_Use = conf->Bind_When_Use; + Bind_Quest_Item = conf->Bind_Quest_Item; + DuplicatesCount = conf->DuplicatesCount; + ElapsingTimeClass = conf->ElapsingTimeClass; + DivisibleStacks = conf->DivisibleStacks; + DisablePermEnchant = conf->DisablePermEnchant; + DisableConjured = conf->DisableConjured; + DisableGems = conf->DisableGems; + DisableMoney = conf->DisableMoney; + DisableMoneyLoot = conf->DisableMoneyLoot; + DisableLootable = conf->DisableLootable; + DisableKeys = conf->DisableKeys; + DisableDuration = conf->DisableDuration; + DisableBOP_Or_Quest_NoReqLevel = conf->DisableBOP_Or_Quest_NoReqLevel; + DisableWarriorItems = conf->DisableWarriorItems; + DisablePaladinItems = conf->DisablePaladinItems; + DisableHunterItems = conf->DisableHunterItems; + DisableRogueItems = conf->DisableRogueItems; + DisablePriestItems = conf->DisablePriestItems; + DisableDKItems = conf->DisableDKItems; + DisableShamanItems = conf->DisableShamanItems; + DisableMageItems = conf->DisableMageItems; + DisableWarlockItems = conf->DisableWarlockItems; + DisableUnusedClassItems = conf->DisableUnusedClassItems; + DisableDruidItems = conf->DisableDruidItems; + DisableItemsBelowLevel = conf->DisableItemsBelowLevel; + DisableItemsAboveLevel = conf->DisableItemsAboveLevel; + DisableTGsBelowLevel = conf->DisableTGsBelowLevel; + DisableTGsAboveLevel = conf->DisableTGsAboveLevel; + DisableItemsBelowGUID = conf->DisableItemsBelowGUID; + DisableItemsAboveGUID = conf->DisableItemsAboveGUID; + DisableTGsBelowGUID = conf->DisableTGsBelowGUID; + DisableTGsAboveGUID = conf->DisableTGsAboveGUID; + DisableItemsBelowReqLevel = conf->DisableItemsBelowReqLevel; + DisableItemsAboveReqLevel = conf->DisableItemsAboveReqLevel; + DisableTGsBelowReqLevel = conf->DisableTGsBelowReqLevel; + DisableTGsAboveReqLevel = conf->DisableTGsAboveReqLevel; + DisableItemsBelowReqSkillRank = conf->DisableItemsBelowReqSkillRank; + DisableItemsAboveReqSkillRank = conf->DisableItemsAboveReqSkillRank; + DisableTGsBelowReqSkillRank = conf->DisableTGsBelowReqSkillRank; + DisableTGsAboveReqSkillRank = conf->DisableTGsAboveReqSkillRank; + + // + // Copy the sets + // + + NpcItems.clear(); + for (uint32 id: conf->NpcItems) + { + NpcItems.insert(id); + } + + LootItems.clear(); + for (uint32 id: conf->LootItems) + { + LootItems.insert(id); + } + + DisableItemStore.clear(); + for (uint32 id: conf->DisableItemStore) + { + DisableItemStore.insert(id); + } + + SellerWhiteList.clear(); + for (uint32 id: conf->SellerWhiteList) + { + SellerWhiteList.insert(id); + } + + GreyTradeGoodsBin.clear(); + for (uint32 id: conf->GreyTradeGoodsBin) + { + GreyTradeGoodsBin.insert(id); + } + + WhiteTradeGoodsBin.clear(); + for (uint32 id: conf->WhiteTradeGoodsBin) + { + WhiteTradeGoodsBin.insert(id); + } + + GreenTradeGoodsBin.clear(); + for (uint32 id: conf->GreenTradeGoodsBin) + { + GreenTradeGoodsBin.insert(id); + } + + BlueTradeGoodsBin.clear(); + for (uint32 id: conf->BlueTradeGoodsBin) + { + BlueTradeGoodsBin.insert(id); + } + + PurpleTradeGoodsBin.clear(); + for (uint32 id: conf->PurpleTradeGoodsBin) + { + PurpleTradeGoodsBin.insert(id); + } + + OrangeTradeGoodsBin.clear(); + for (uint32 id: conf->OrangeTradeGoodsBin) + { + OrangeTradeGoodsBin.insert(id); + } + + YellowTradeGoodsBin.clear(); + for (uint32 id: conf->YellowTradeGoodsBin) + { + YellowTradeGoodsBin.insert(id); + } + + + // + // Bins for items + // + + GreyItemsBin.clear(); + for (uint32 id: conf->GreyItemsBin) + { + GreyItemsBin.insert(id); + } + + WhiteItemsBin.clear(); + for (uint32 id: conf->WhiteItemsBin) + { + WhiteItemsBin.insert(id); + } + + GreenItemsBin.clear(); + for (uint32 id: conf->GreenItemsBin) + { + GreenItemsBin.insert(id); + } + + BlueItemsBin.clear(); + for (uint32 id: conf->BlueItemsBin) + { + BlueItemsBin.insert(id); + } + + PurpleItemsBin.clear(); + for (uint32 id: conf->PurpleItemsBin) + { + PurpleItemsBin.insert(id); + } + + OrangeItemsBin.clear(); + for (uint32 id: conf->OrangeItemsBin) + { + OrangeItemsBin.insert(id); + } + + YellowItemsBin.clear(); + for (uint32 id: conf->YellowItemsBin) + { + YellowItemsBin.insert(id); + } +} + AHBConfig::~AHBConfig() { } void AHBConfig::Reset() { - AHID = 0; - AHFID = 0; - - minItems = 0; - maxItems = 0; - - percentGreyTradeGoods = 0; - percentWhiteTradeGoods = 0; - percentGreenTradeGoods = 0; - percentBlueTradeGoods = 0; - percentPurpleTradeGoods = 0; - percentOrangeTradeGoods = 0; - percentYellowTradeGoods = 0; - - percentGreyItems = 0; - percentWhiteItems = 0; - percentGreenItems = 0; - percentBlueItems = 0; - percentPurpleItems = 0; - percentOrangeItems = 0; - percentYellowItems = 0; - - minPriceGrey = 0; - maxPriceGrey = 0; - minBidPriceGrey = 0; - maxBidPriceGrey = 0; - maxStackGrey = 0; - - minPriceWhite = 0; - maxPriceWhite = 0; - minBidPriceWhite = 0; - maxBidPriceWhite = 0; - maxStackWhite = 0; - - minPriceGreen = 0; - maxPriceGreen = 0; - minBidPriceGreen = 0; - maxBidPriceGreen = 0; - maxStackGreen = 0; - - minPriceBlue = 0; - maxPriceBlue = 0; - minBidPriceBlue = 0; - maxBidPriceBlue = 0; - maxStackBlue = 0; - - minPricePurple = 0; - maxPricePurple = 0; - minBidPricePurple = 0; - maxBidPricePurple = 0; - maxStackPurple = 0; - - minPriceOrange = 0; - maxPriceOrange = 0; - minBidPriceOrange = 0; - maxBidPriceOrange = 0; - maxStackOrange = 0; - - minPriceYellow = 0; - maxPriceYellow = 0; - minBidPriceYellow = 0; - maxBidPriceYellow = 0; - maxStackYellow = 0; - - buyerPriceGrey = 0; - buyerPriceWhite = 0; - buyerPriceGreen = 0; - buyerPriceBlue = 0; - buyerPricePurple = 0; - buyerPriceOrange = 0; - buyerPriceYellow = 0; - - buyerBiddingInterval = 0; - buyerBidsPerInterval = 0; - - greytgp = 0; - whitetgp = 0; - greentgp = 0; - bluetgp = 0; - purpletgp = 0; - orangetgp = 0; - yellowtgp = 0; - - greyip = 0; - whiteip = 0; - greenip = 0; - blueip = 0; - purpleip = 0; - orangeip = 0; - yellowip = 0; - - greyTGoods = 0; - whiteTGoods = 0; - greenTGoods = 0; - blueTGoods = 0; - purpleTGoods = 0; - orangeTGoods = 0; - yellowTGoods = 0; - - greyItems = 0; - whiteItems = 0; - greenItems = 0; - blueItems = 0; - purpleItems = 0; - orangeItems = 0; - yellowItems = 0; + // + // Private variables + // + + AHID = 0; + AHFID = 0; + + minItems = 0; + maxItems = 0; + + percentGreyTradeGoods = 0; + percentWhiteTradeGoods = 0; + percentGreenTradeGoods = 0; + percentBlueTradeGoods = 0; + percentPurpleTradeGoods = 0; + percentOrangeTradeGoods = 0; + percentYellowTradeGoods = 0; + + percentGreyItems = 0; + percentWhiteItems = 0; + percentGreenItems = 0; + percentBlueItems = 0; + percentPurpleItems = 0; + percentOrangeItems = 0; + percentYellowItems = 0; + + minPriceGrey = 0; + maxPriceGrey = 0; + minBidPriceGrey = 0; + maxBidPriceGrey = 0; + maxStackGrey = 0; + + minPriceWhite = 0; + maxPriceWhite = 0; + minBidPriceWhite = 0; + maxBidPriceWhite = 0; + maxStackWhite = 0; + + minPriceGreen = 0; + maxPriceGreen = 0; + minBidPriceGreen = 0; + maxBidPriceGreen = 0; + maxStackGreen = 0; + + minPriceBlue = 0; + maxPriceBlue = 0; + minBidPriceBlue = 0; + maxBidPriceBlue = 0; + maxStackBlue = 0; + + minPricePurple = 0; + maxPricePurple = 0; + minBidPricePurple = 0; + maxBidPricePurple = 0; + maxStackPurple = 0; + + minPriceOrange = 0; + maxPriceOrange = 0; + minBidPriceOrange = 0; + maxBidPriceOrange = 0; + maxStackOrange = 0; + + minPriceYellow = 0; + maxPriceYellow = 0; + minBidPriceYellow = 0; + maxBidPriceYellow = 0; + maxStackYellow = 0; + + buyerPriceGrey = 0; + buyerPriceWhite = 0; + buyerPriceGreen = 0; + buyerPriceBlue = 0; + buyerPricePurple = 0; + buyerPriceOrange = 0; + buyerPriceYellow = 0; + + buyerBiddingInterval = 0; + buyerBidsPerInterval = 0; + + greytgp = 0; + whitetgp = 0; + greentgp = 0; + bluetgp = 0; + purpletgp = 0; + orangetgp = 0; + yellowtgp = 0; + + greyip = 0; + whiteip = 0; + greenip = 0; + blueip = 0; + purpleip = 0; + orangeip = 0; + yellowip = 0; + + greyTGoods = 0; + whiteTGoods = 0; + greenTGoods = 0; + blueTGoods = 0; + purpleTGoods = 0; + orangeTGoods = 0; + yellowTGoods = 0; + + greyItems = 0; + whiteItems = 0; + greenItems = 0; + blueItems = 0; + purpleItems = 0; + orangeItems = 0; + yellowItems = 0; + + // + // Public properties + // + + DebugOut = false; + DebugOutConfig = false; + DebugOutFilters = false; + DebugOutBuyer = false; + DebugOutSeller = false; + + TraceSeller = false; + TraceBuyer = false; + + AHBSeller = false; + AHBBuyer = false; + + BuyMethod = false; + SellMethod = false; + ConsiderOnlyBotAuctions = false; + ItemsPerCycle = 200; + + Vendor_Items = false; + Loot_Items = true; + Other_Items = false; + Vendor_TGs = false; + Loot_TGs = true; + Other_TGs = false; + + No_Bind = true; + Bind_When_Picked_Up = true; + Bind_When_Equipped = false; + Bind_When_Use = false; + Bind_Quest_Item = false; + DuplicatesCount = 0; + ElapsingTimeClass = 1; + DivisibleStacks = false; + + DisablePermEnchant = false; + DisableConjured = false; + DisableGems = false; + DisableMoney = false; + DisableMoneyLoot = false; + DisableLootable = false; + DisableKeys = false; + DisableDuration = false; + DisableBOP_Or_Quest_NoReqLevel = false; + + DisableWarriorItems = false; + DisablePaladinItems = false; + DisableHunterItems = false; + DisableRogueItems = false; + DisablePriestItems = false; + DisableDKItems = false; + DisableShamanItems = false; + DisableMageItems = false; + DisableWarlockItems = false; + DisableUnusedClassItems = false; + DisableDruidItems = false; + + DisableItemsBelowLevel = false; + DisableItemsAboveLevel = false; + DisableTGsBelowLevel = false; + DisableTGsAboveLevel = false; + DisableItemsBelowGUID = false; + DisableItemsAboveGUID = false; + DisableTGsBelowGUID = false; + DisableTGsAboveGUID = false; + DisableItemsBelowReqLevel = false; + DisableItemsAboveReqLevel = false; + DisableTGsBelowReqLevel = false; + DisableTGsAboveReqLevel = false; + DisableItemsBelowReqSkillRank = false; + DisableItemsAboveReqSkillRank = false; + DisableTGsBelowReqSkillRank = false; + DisableTGsAboveReqSkillRank = false; + + // + // Sets + // + + NpcItems.clear(); + LootItems.clear(); + + DisableItemStore.clear(); + SellerWhiteList.clear(); + + GreyTradeGoodsBin.clear(); + WhiteTradeGoodsBin.clear(); + GreenTradeGoodsBin.clear(); + BlueTradeGoodsBin.clear(); + PurpleTradeGoodsBin.clear(); + OrangeTradeGoodsBin.clear(); + YellowTradeGoodsBin.clear(); + + GreyItemsBin.clear(); + WhiteItemsBin.clear(); + GreenItemsBin.clear(); + BlueItemsBin.clear(); + PurpleItemsBin.clear(); + OrangeItemsBin.clear(); + YellowItemsBin.clear(); } uint32 AHBConfig::GetAHID() @@ -1521,3 +1944,1391 @@ uint32 AHBConfig::GetBidsPerInterval() { return buyerBidsPerInterval; } + +void AHBConfig::Initialize(std::set botsIds) +{ + InitializeFromFile(); + InitializeFromSql(botsIds); +} + +void AHBConfig::InitializeFromFile() +{ + // + // Load from, the configuration file + // + + DebugOut = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG" , false); + DebugOutConfig = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_CONFIG" , false); + DebugOutFilters = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_FILTERS", false); + DebugOutBuyer = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_BUYER" , false); + DebugOutSeller = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_SELLER" , false); + + TraceSeller = sConfigMgr->GetOption ("AuctionHouseBot.TRACE_SELLER" , false); + TraceBuyer = sConfigMgr->GetOption ("AuctionHouseBot.TRACE_BUYER" , false); + + AHBSeller = sConfigMgr->GetOption ("AuctionHouseBot.EnableSeller" , false); + AHBBuyer = sConfigMgr->GetOption ("AuctionHouseBot.EnableBuyer" , false); + SellMethod = sConfigMgr->GetOption ("AuctionHouseBot.UseBuyPriceForSeller" , false); + BuyMethod = sConfigMgr->GetOption ("AuctionHouseBot.UseBuyPriceForBuyer" , false); + DuplicatesCount = sConfigMgr->GetOption("AuctionHouseBot.DuplicatesCount" , 0); + DivisibleStacks = sConfigMgr->GetOption ("AuctionHouseBot.DivisibleStacks" , false); + ElapsingTimeClass = sConfigMgr->GetOption("AuctionHouseBot.DuplicatesCount" , 1); + ConsiderOnlyBotAuctions = sConfigMgr->GetOption ("AuctionHouseBot.ConsiderOnlyBotAuctions", false); + ItemsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.ItemsPerCycle" , 200); + + // + // Flags: item types + // + + Vendor_Items = sConfigMgr->GetOption ("AuctionHouseBot.VendorItems" , false); + Loot_Items = sConfigMgr->GetOption ("AuctionHouseBot.LootItems" , true); + Other_Items = sConfigMgr->GetOption ("AuctionHouseBot.OtherItems" , false); + Vendor_TGs = sConfigMgr->GetOption ("AuctionHouseBot.VendorTradeGoods" , false); + Loot_TGs = sConfigMgr->GetOption ("AuctionHouseBot.LootTradeGoods" , true); + Other_TGs = sConfigMgr->GetOption ("AuctionHouseBot.OtherTradeGoods" , false); + + // + // Flags: items binding + // + + No_Bind = sConfigMgr->GetOption ("AuctionHouseBot.No_Bind" , true); + Bind_When_Picked_Up = sConfigMgr->GetOption ("AuctionHouseBot.Bind_When_Picked_Up" , false); + Bind_When_Equipped = sConfigMgr->GetOption ("AuctionHouseBot.Bind_When_Equipped" , true); + Bind_When_Use = sConfigMgr->GetOption ("AuctionHouseBot.Bind_When_Use" , true); + Bind_Quest_Item = sConfigMgr->GetOption ("AuctionHouseBot.Bind_Quest_Item" , false); + + // + // Flags: misc + // + + DisableConjured = sConfigMgr->GetOption ("AuctionHouseBot.DisableConjured" , false); + DisableGems = sConfigMgr->GetOption ("AuctionHouseBot.DisableGems" , false); + DisableMoney = sConfigMgr->GetOption ("AuctionHouseBot.DisableMoney" , false); + DisableMoneyLoot = sConfigMgr->GetOption ("AuctionHouseBot.DisableMoneyLoot" , false); + DisableLootable = sConfigMgr->GetOption ("AuctionHouseBot.DisableLootable" , false); + DisableKeys = sConfigMgr->GetOption ("AuctionHouseBot.DisableKeys" , false); + DisableDuration = sConfigMgr->GetOption ("AuctionHouseBot.DisableDuration" , false); + DisableBOP_Or_Quest_NoReqLevel = sConfigMgr->GetOption ("AuctionHouseBot.DisableBOP_Or_Quest_NoReqLevel", false); + + // + // Flags: items per class + // + + DisableWarriorItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableWarriorItems" , false); + DisablePaladinItems = sConfigMgr->GetOption ("AuctionHouseBot.DisablePaladinItems" , false); + DisableHunterItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableHunterItems" , false); + DisableRogueItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableRogueItems" , false); + DisablePriestItems = sConfigMgr->GetOption ("AuctionHouseBot.DisablePriestItems" , false); + DisableDKItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableDKItems" , false); + DisableShamanItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableShamanItems" , false); + DisableMageItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableMageItems" , false); + DisableWarlockItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableWarlockItems" , false); + DisableUnusedClassItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableUnusedClassItems", false); + DisableDruidItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableDruidItems" , false); + + // + // Items level and skills + // + + DisableItemsBelowLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowLevel" , 0); + DisableItemsAboveLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveLevel" , 0); + DisableItemsBelowGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowGUID" , 0); + DisableItemsAboveGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveGUID" , 0); + DisableItemsBelowReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowReqLevel" , 0); + DisableItemsAboveReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveReqLevel" , 0); + DisableItemsBelowReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowReqSkillRank", 0); + DisableItemsAboveReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveReqSkillRank", 0); + + // + // Trade goods level and skills + // + + DisableTGsBelowLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowLevel" , 0); + DisableTGsAboveLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveLevel" , 0); + DisableTGsBelowGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowGUID" , 0); + DisableTGsAboveGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveGUID" , 0); + DisableTGsBelowReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowReqLevel" , 0); + DisableTGsAboveReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveReqLevel" , 0); + DisableTGsBelowReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowReqSkillRank", 0); + DisableTGsAboveReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveReqSkillRank", 0); + + // + // Whitelists + // + + SellerWhiteList = getCommaSeparatedIntegers(sConfigMgr->GetOption("AuctionHouseBot.SellerWhiteList", "")); +} + +void AHBConfig::InitializeFromSql(std::set botsIds) +{ + // + // Load min and max items + // + + SetMinItems(WorldDatabase.Query("SELECT minitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxItems(WorldDatabase.Query("SELECT maxitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + // + // Load percentages + // + + uint32 greytg = WorldDatabase.Query("SELECT percentgreytradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 whitetg = WorldDatabase.Query("SELECT percentwhitetradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 greentg = WorldDatabase.Query("SELECT percentgreentradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 bluetg = WorldDatabase.Query("SELECT percentbluetradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 purpletg = WorldDatabase.Query("SELECT percentpurpletradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 orangetg = WorldDatabase.Query("SELECT percentorangetradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 yellowtg = WorldDatabase.Query("SELECT percentyellowtradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + + uint32 greyi = WorldDatabase.Query("SELECT percentgreyitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 whitei = WorldDatabase.Query("SELECT percentwhiteitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 greeni = WorldDatabase.Query("SELECT percentgreenitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 bluei = WorldDatabase.Query("SELECT percentblueitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 purplei = WorldDatabase.Query("SELECT percentpurpleitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 orangei = WorldDatabase.Query("SELECT percentorangeitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 yellowi = WorldDatabase.Query("SELECT percentyellowitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + + SetPercentages(greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi); + + // + // Load min and max prices + // + + SetMinPrice(AHB_GREY , WorldDatabase.Query("SELECT minpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_GREY , WorldDatabase.Query("SELECT maxpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_WHITE , WorldDatabase.Query("SELECT minpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_WHITE , WorldDatabase.Query("SELECT maxpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_GREEN , WorldDatabase.Query("SELECT minpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_GREEN , WorldDatabase.Query("SELECT maxpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_BLUE , WorldDatabase.Query("SELECT minpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_BLUE , WorldDatabase.Query("SELECT maxpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_PURPLE, WorldDatabase.Query("SELECT minpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_PURPLE, WorldDatabase.Query("SELECT maxpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_ORANGE, WorldDatabase.Query("SELECT minpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_ORANGE, WorldDatabase.Query("SELECT maxpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_YELLOW, WorldDatabase.Query("SELECT minpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_YELLOW, WorldDatabase.Query("SELECT maxpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + // + // Load min and max bid prices + // + + SetMinBidPrice(AHB_GREY , WorldDatabase.Query("SELECT minbidpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_GREY , WorldDatabase.Query("SELECT maxbidpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_WHITE , WorldDatabase.Query("SELECT minbidpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_WHITE , WorldDatabase.Query("SELECT maxbidpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_GREEN , WorldDatabase.Query("SELECT minbidpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_GREEN , WorldDatabase.Query("SELECT maxbidpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_BLUE , WorldDatabase.Query("SELECT minbidpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_BLUE , WorldDatabase.Query("SELECT maxbidpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_PURPLE, WorldDatabase.Query("SELECT minbidpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_PURPLE, WorldDatabase.Query("SELECT maxbidpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_ORANGE, WorldDatabase.Query("SELECT minbidpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_ORANGE, WorldDatabase.Query("SELECT maxbidpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_YELLOW, WorldDatabase.Query("SELECT minbidpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_YELLOW, WorldDatabase.Query("SELECT maxbidpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + // + // Load max stacks + // + + SetMaxStack(AHB_GREY , WorldDatabase.Query("SELECT maxstackgrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_WHITE , WorldDatabase.Query("SELECT maxstackwhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_GREEN , WorldDatabase.Query("SELECT maxstackgreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_BLUE , WorldDatabase.Query("SELECT maxstackblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_PURPLE, WorldDatabase.Query("SELECT maxstackpurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_ORANGE, WorldDatabase.Query("SELECT maxstackorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_YELLOW, WorldDatabase.Query("SELECT maxstackyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + if (DebugOutConfig) + { + LOG_INFO("module", "Settings for Auctionhouse {}", GetAHID()); + + LOG_INFO("module", "minItems = {}", GetMinItems()); + LOG_INFO("module", "maxItems = {}", GetMaxItems()); + + LOG_INFO("module", "percentGreyTradeGoods = {}", GetPercentages(AHB_GREY_TG)); + LOG_INFO("module", "percentWhiteTradeGoods = {}", GetPercentages(AHB_WHITE_TG)); + LOG_INFO("module", "percentGreenTradeGoods = {}", GetPercentages(AHB_GREEN_TG)); + LOG_INFO("module", "percentBlueTradeGoods = {}", GetPercentages(AHB_BLUE_TG)); + LOG_INFO("module", "percentPurpleTradeGoods = {}", GetPercentages(AHB_PURPLE_TG)); + LOG_INFO("module", "percentOrangeTradeGoods = {}", GetPercentages(AHB_ORANGE_TG)); + LOG_INFO("module", "percentYellowTradeGoods = {}", GetPercentages(AHB_YELLOW_TG)); + LOG_INFO("module", "percentGreyItems = {}", GetPercentages(AHB_GREY_I)); + LOG_INFO("module", "percentWhiteItems = {}", GetPercentages(AHB_WHITE_I)); + LOG_INFO("module", "percentGreenItems = {}", GetPercentages(AHB_GREEN_I)); + LOG_INFO("module", "percentBlueItems = {}", GetPercentages(AHB_BLUE_I)); + LOG_INFO("module", "percentPurpleItems = {}", GetPercentages(AHB_PURPLE_I)); + LOG_INFO("module", "percentOrangeItems = {}", GetPercentages(AHB_ORANGE_I)); + LOG_INFO("module", "percentYellowItems = {}", GetPercentages(AHB_YELLOW_I)); + + LOG_INFO("module", "minPriceGrey = {}", GetMinPrice(AHB_GREY)); + LOG_INFO("module", "maxPriceGrey = {}", GetMaxPrice(AHB_GREY)); + LOG_INFO("module", "minPriceWhite = {}", GetMinPrice(AHB_WHITE)); + LOG_INFO("module", "maxPriceWhite = {}", GetMaxPrice(AHB_WHITE)); + LOG_INFO("module", "minPriceGreen = {}", GetMinPrice(AHB_GREEN)); + LOG_INFO("module", "maxPriceGreen = {}", GetMaxPrice(AHB_GREEN)); + LOG_INFO("module", "minPriceBlue = {}", GetMinPrice(AHB_BLUE)); + LOG_INFO("module", "maxPriceBlue = {}", GetMaxPrice(AHB_BLUE)); + LOG_INFO("module", "minPricePurple = {}", GetMinPrice(AHB_PURPLE)); + LOG_INFO("module", "maxPricePurple = {}", GetMaxPrice(AHB_PURPLE)); + LOG_INFO("module", "minPriceOrange = {}", GetMinPrice(AHB_ORANGE)); + LOG_INFO("module", "maxPriceOrange = {}", GetMaxPrice(AHB_ORANGE)); + LOG_INFO("module", "minPriceYellow = {}", GetMinPrice(AHB_YELLOW)); + LOG_INFO("module", "maxPriceYellow = {}", GetMaxPrice(AHB_YELLOW)); + + LOG_INFO("module", "minBidPriceGrey = {}", GetMinBidPrice(AHB_GREY)); + LOG_INFO("module", "maxBidPriceGrey = {}", GetMaxBidPrice(AHB_GREY)); + LOG_INFO("module", "minBidPriceWhite = {}", GetMinBidPrice(AHB_WHITE)); + LOG_INFO("module", "maxBidPriceWhite = {}", GetMaxBidPrice(AHB_WHITE)); + LOG_INFO("module", "minBidPriceGreen = {}", GetMinBidPrice(AHB_GREEN)); + LOG_INFO("module", "maxBidPriceGreen = {}", GetMaxBidPrice(AHB_GREEN)); + LOG_INFO("module", "minBidPriceBlue = {}", GetMinBidPrice(AHB_BLUE)); + LOG_INFO("module", "maxBidPriceBlue = {}", GetMinBidPrice(AHB_BLUE)); + LOG_INFO("module", "minBidPricePurple = {}", GetMinBidPrice(AHB_PURPLE)); + LOG_INFO("module", "maxBidPricePurple = {}", GetMaxBidPrice(AHB_PURPLE)); + LOG_INFO("module", "minBidPriceOrange = {}", GetMinBidPrice(AHB_ORANGE)); + LOG_INFO("module", "maxBidPriceOrange = {}", GetMaxBidPrice(AHB_ORANGE)); + LOG_INFO("module", "minBidPriceYellow = {}", GetMinBidPrice(AHB_YELLOW)); + LOG_INFO("module", "maxBidPriceYellow = {}", GetMaxBidPrice(AHB_YELLOW)); + + LOG_INFO("module", "maxStackGrey = {}", GetMaxStack(AHB_GREY)); + LOG_INFO("module", "maxStackWhite = {}", GetMaxStack(AHB_WHITE)); + LOG_INFO("module", "maxStackGreen = {}", GetMaxStack(AHB_GREEN)); + LOG_INFO("module", "maxStackBlue = {}", GetMaxStack(AHB_BLUE)); + LOG_INFO("module", "maxStackPurple = {}", GetMaxStack(AHB_PURPLE)); + LOG_INFO("module", "maxStackOrange = {}", GetMaxStack(AHB_ORANGE)); + LOG_INFO("module", "maxStackYellow = {}", GetMaxStack(AHB_YELLOW)); + } + + // + // Reset the situation of the auction house + // + + ResetItemCounts(); + + // + // Update the situation of the auction house + // + + AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(GetAHFID()); + uint32 auctions = auctionHouse->Getcount(); + + if (auctions) + { + for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr) + { + AuctionEntry* Aentry = itr->second; + Item* item = sAuctionMgr->GetAItem(Aentry->item_guid); + + // + // If it has to only consider the bots auctions, skip the ones belonging to the players + // + + if (ConsiderOnlyBotAuctions) + { + if (botsIds.find(Aentry->owner.GetCounter()) == botsIds.end()) + { + continue; + } + } + + if (item) + { + ItemTemplate const* prototype = item->GetTemplate(); + + if (prototype) + { + switch (prototype->Quality) + { + case AHB_GREY: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_GREY_TG); + } + else + { + IncItemCounts(AHB_GREY_I); + } + break; + + case AHB_WHITE: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_WHITE_TG); + } + else + { + IncItemCounts(AHB_WHITE_I); + } + + break; + + case AHB_GREEN: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_GREEN_TG); + } + else + { + IncItemCounts(AHB_GREEN_I); + } + + break; + + case AHB_BLUE: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_BLUE_TG); + } + else + { + IncItemCounts(AHB_BLUE_I); + } + + break; + + case AHB_PURPLE: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_PURPLE_TG); + } + else + { + IncItemCounts(AHB_PURPLE_I); + } + + break; + + case AHB_ORANGE: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_ORANGE_TG); + } + else + { + IncItemCounts(AHB_ORANGE_I); + } + + break; + + case AHB_YELLOW: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_YELLOW_TG); + } + else + { + IncItemCounts(AHB_YELLOW_I); + } + + break; + } + } + } + } + } + + if (DebugOutConfig) + { + LOG_INFO("module", "Current situation for the auctionhouse {}", GetAHID()); + LOG_INFO("module", " Grey Trade Goods {}", GetItemCounts(AHB_GREY_TG)); + LOG_INFO("module", " White Trade Goods {}", GetItemCounts(AHB_WHITE_TG)); + LOG_INFO("module", " Green Trade Goods {}", GetItemCounts(AHB_GREEN_TG)); + LOG_INFO("module", " Blue Trade Goods {}", GetItemCounts(AHB_BLUE_TG)); + LOG_INFO("module", " Purple Trade Goods {}", GetItemCounts(AHB_PURPLE_TG)); + LOG_INFO("module", " Orange Trade Goods {}", GetItemCounts(AHB_ORANGE_TG)); + LOG_INFO("module", " Yellow Trade Goods {}", GetItemCounts(AHB_YELLOW_TG)); + LOG_INFO("module", " Grey Items {}", GetItemCounts(AHB_GREY_I)); + LOG_INFO("module", " White Items {}", GetItemCounts(AHB_WHITE_I)); + LOG_INFO("module", " Green Items {}", GetItemCounts(AHB_GREEN_I)); + LOG_INFO("module", " Blue Items {}", GetItemCounts(AHB_BLUE_I)); + LOG_INFO("module", " Purple Items {}", GetItemCounts(AHB_PURPLE_I)); + LOG_INFO("module", " Orange Items {}", GetItemCounts(AHB_ORANGE_I)); + LOG_INFO("module", " Yellow Items {}", GetItemCounts(AHB_YELLOW_I)); + } + + // + // Auctions buyer + // + + SetBuyerPrice(AHB_GREY , WorldDatabase.Query("SELECT buyerpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_WHITE , WorldDatabase.Query("SELECT buyerpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_GREEN , WorldDatabase.Query("SELECT buyerpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_BLUE , WorldDatabase.Query("SELECT buyerpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_PURPLE, WorldDatabase.Query("SELECT buyerpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_ORANGE, WorldDatabase.Query("SELECT buyerpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_YELLOW, WorldDatabase.Query("SELECT buyerpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + // + // Load bidding interval + // + + SetBiddingInterval(WorldDatabase.Query("SELECT buyerbiddinginterval FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + // + // Load bids per interval + // + + SetBidsPerInterval(WorldDatabase.Query("SELECT buyerbidsperinterval FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + if (DebugOutConfig) + { + LOG_INFO("module", "Current Settings for Auctionhouse {} buyer", GetAHID()); + LOG_INFO("module", "buyerPriceGrey = {}", GetBuyerPrice(AHB_GREY)); + LOG_INFO("module", "buyerPriceWhite = {}", GetBuyerPrice(AHB_WHITE)); + LOG_INFO("module", "buyerPriceGreen = {}", GetBuyerPrice(AHB_GREEN)); + LOG_INFO("module", "buyerPriceBlue = {}", GetBuyerPrice(AHB_BLUE)); + LOG_INFO("module", "buyerPricePurple = {}", GetBuyerPrice(AHB_PURPLE)); + LOG_INFO("module", "buyerPriceOrange = {}", GetBuyerPrice(AHB_ORANGE)); + LOG_INFO("module", "buyerPriceYellow = {}", GetBuyerPrice(AHB_YELLOW)); + LOG_INFO("module", "buyerBiddingInterval = {}", GetBiddingInterval()); + LOG_INFO("module", "buyerBidsPerInterval = {}", GetBidsPerInterval()); + } + + // + // Reload the list of disabled items + // + + DisableItemStore.clear(); + + QueryResult result = WorldDatabase.Query("SELECT item FROM mod_auctionhousebot_disabled_items"); + + if (result) + { + do + { + Field* fields = result->Fetch(); + DisableItemStore.insert(fields[0].Get()); + } while (result->NextRow()); + } + + if (DebugOutConfig) + { + LOG_INFO("module", "Loaded {} items from the disabled item store", uint32(DisableItemStore.size())); + } + + // + // Reload the list of npc items + // + + NpcItems.clear(); + + QueryResult npcResults = WorldDatabase.Query("SELECT distinct item FROM npc_vendor"); + + if (npcResults) + { + do + { + Field* fields = npcResults->Fetch(); + NpcItems.insert(fields[0].Get()); + + } while (npcResults->NextRow()); + } + else + { + if (DebugOutConfig) + { + LOG_ERROR("module", "AuctionHouseBot: failed to retrieve npc items"); + } + } + + if (DebugOutConfig) + { + LOG_INFO("module", "Loaded {} items from NPCs", uint32(NpcItems.size())); + } + + // + // Reload the list from the lootable items + // + + LootItems.clear(); + + QueryResult itemsResults = WorldDatabase.Query( + "SELECT item FROM creature_loot_template UNION " + "SELECT item FROM reference_loot_template UNION " + "SELECT item FROM disenchant_loot_template UNION " + "SELECT item FROM fishing_loot_template UNION " + "SELECT item FROM gameobject_loot_template UNION " + "SELECT item FROM item_loot_template UNION " + "SELECT item FROM milling_loot_template UNION " + "SELECT item FROM pickpocketing_loot_template UNION " + "SELECT item FROM prospecting_loot_template UNION " + "SELECT item FROM skinning_loot_template"); + + if (itemsResults) + { + do + { + Field* fields = itemsResults->Fetch(); + LootItems.insert(fields[0].Get()); + + } while (itemsResults->NextRow()); + } + else + { + if (DebugOutConfig) + { + LOG_ERROR("module", "AuctionHouseBot: failed to retrieve loot items"); + } + } + + if (DebugOutConfig) + { + LOG_INFO("module", "Loaded {} items from lootable items", uint32(LootItems.size())); + } +} + +void AHBConfig::InitializeBins() +{ + // + // Exclude items depending on the configuration; whatever passes all the tests is put in the lists. + // + + ItemTemplateContainer const* its = sObjectMgr->GetItemTemplateStore(); + + for (ItemTemplateContainer::const_iterator itr = its->begin(); itr != its->end(); ++itr) + { + + // + // Exclude items with the blocked binding type + // + + if (itr->second.Bonding == NO_BIND && !No_Bind) + { + continue; + } + + if (itr->second.Bonding == BIND_WHEN_PICKED_UP && !Bind_When_Picked_Up) + { + continue; + } + + if (itr->second.Bonding == BIND_WHEN_EQUIPED && !Bind_When_Equipped) + { + continue; + } + + if (itr->second.Bonding == BIND_WHEN_USE && !Bind_When_Use) + { + continue; + } + + if (itr->second.Bonding == BIND_QUEST_ITEM && !Bind_Quest_Item) + { + continue; + } + + // + // Exclude items with no possible price + // + + if (SellMethod) + { + if (itr->second.BuyPrice == 0) + { + continue; + } + } + else + { + if (itr->second.SellPrice == 0) + { + continue; + } + } + + // + // Exclude items with no costs associated, in any case + // + + if ((itr->second.BuyPrice == 0) && (itr->second.SellPrice == 0)) + { + continue; + } + + // + // Exlude items superior to the limit quality + // + + if (itr->second.Quality > 6) + { + continue; + } + + // + // Exclude trade goods items + // + + if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) + { + bool isNpc = false; + bool isLoot = false; + bool exclude = false; + + if (NpcItems.find(itr->second.ItemId) != NpcItems.end()) + { + isNpc = true; + + if (!Vendor_TGs) + { + exclude = true; + } + } + + if (!exclude) + { + if (LootItems.find(itr->second.ItemId) != LootItems.end()) + { + isLoot = true; + + if (!Loot_TGs) + { + exclude = true; + } + } + } + + if (exclude) + { + continue; + } + + if (!Other_TGs) + { + if (!isNpc && !isLoot) + { + continue; + } + } + } + + // + // Exclude loot items + // + + if (itr->second.Class != ITEM_CLASS_TRADE_GOODS) + { + bool isNpc = false; + bool isLoot = false; + bool exclude = false; + + if (NpcItems.find(itr->second.ItemId) != NpcItems.end()) + { + isNpc = true; + + if (!Vendor_Items) + { + exclude = true; + } + } + + if (!exclude) + { + if (LootItems.find(itr->second.ItemId) != LootItems.end()) + { + isLoot = true; + + if (!Loot_Items) + { + exclude = true; + } + } + } + + if (exclude) + { + continue; + } + + if (!Other_Items) + { + if (!isNpc && !isLoot) + { + continue; + } + } + } + + // + // Verify if the item is disabled or not in the whitelist + // + + if (SellerWhiteList.size() == 0) + { + if (DisableItemStore.find(itr->second.ItemId) != DisableItemStore.end()) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (PTR/Beta/Unused Item)", itr->second.ItemId); + } + + continue; + } + } + else + { + if (SellerWhiteList.find(itr->second.ItemId) == SellerWhiteList.end()) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (not in the whitelist)", itr->second.ItemId); + } + + continue; + } + } + + // + // Disable permanent enchants items + // + + if ((DisablePermEnchant) && (itr->second.Class == ITEM_CLASS_PERMANENT)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Permanent Enchant Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable conjured items + // + + if ((DisableConjured) && (itr->second.IsConjuredConsumable())) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Conjured Consumable)", itr->second.ItemId); + } + + continue; + } + + // + // Disable gems + // + + if ((DisableGems) && (itr->second.Class == ITEM_CLASS_GEM)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Gem)", itr->second.ItemId); + } + + continue; + } + + // + // Disable money + // + + if ((DisableMoney) && (itr->second.Class == ITEM_CLASS_MONEY)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Money)", itr->second.ItemId); + } + + continue; + } + + // + // Disable moneyloot + // + + if ((DisableMoneyLoot) && (itr->second.MinMoneyLoot > 0)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (MoneyLoot)", itr->second.ItemId); + } + + continue; + } + + // + // Disable lootable items + // + + if ((DisableLootable) && (itr->second.Flags & 4)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Lootable Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable Keys + // + + if ((DisableKeys) && (itr->second.Class == ITEM_CLASS_KEY)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Quest Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items with duration + // + + if ((DisableDuration) && (itr->second.Duration > 0)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Has a Duration)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items which are BOP or Quest Items and have a required level lower than the item level + // + + if ((DisableBOP_Or_Quest_NoReqLevel) && ((itr->second.Bonding == BIND_WHEN_PICKED_UP || itr->second.Bonding == BIND_QUEST_ITEM) && (itr->second.RequiredLevel < itr->second.ItemLevel))) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (BOP or BQI and Required Level is less than Item Level)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Warrior + // + + if ((DisableWarriorItems) && (itr->second.AllowableClass == AHB_CLASS_WARRIOR)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Warrior Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Paladin + // + + if ((DisablePaladinItems) && (itr->second.AllowableClass == AHB_CLASS_PALADIN)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Paladin Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Hunter + // + + if ((DisableHunterItems) && (itr->second.AllowableClass == AHB_CLASS_HUNTER)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Hunter Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Rogue + // + + if ((DisableRogueItems) && (itr->second.AllowableClass == AHB_CLASS_ROGUE)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Rogue Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Priest + // + + if ((DisablePriestItems) && (itr->second.AllowableClass == AHB_CLASS_PRIEST)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Priest Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for DK + // + + if ((DisableDKItems) && (itr->second.AllowableClass == AHB_CLASS_DK)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (DK Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Shaman + // + + if ((DisableShamanItems) && (itr->second.AllowableClass == AHB_CLASS_SHAMAN)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Shaman Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Mage + // + + if ((DisableMageItems) && (itr->second.AllowableClass == AHB_CLASS_MAGE)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Mage Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Warlock + // + + if ((DisableWarlockItems) && (itr->second.AllowableClass == AHB_CLASS_WARLOCK)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Warlock Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Unused Class + // + + if ((DisableUnusedClassItems) && (itr->second.AllowableClass == AHB_CLASS_UNUSED)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Unused Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Druid + // + + if ((DisableDruidItems) && (itr->second.AllowableClass == AHB_CLASS_DRUID)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Druid Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable Items below level X + // + + if ((DisableItemsBelowLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel < DisableItemsBelowLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Items above level X + // + + if ((DisableItemsAboveLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel > DisableItemsAboveLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Trade Goods below level X + // + + if ((DisableTGsBelowLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel < DisableTGsBelowLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Trade Goods above level X + // + + if ((DisableTGsAboveLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel > DisableTGsAboveLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Items below GUID X + // + + if ((DisableItemsBelowGUID) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId < DisableItemsBelowGUID)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Items above GUID X + // + + if ((DisableItemsAboveGUID) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId > DisableItemsAboveGUID)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Trade Goods below GUID X + // + + if ((DisableTGsBelowGUID) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId < DisableTGsBelowGUID)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Trade Goods above GUID X + // + + if ((DisableTGsAboveGUID) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId > DisableTGsAboveGUID)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Items for level lower than X + // + + if ((DisableItemsBelowReqLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel < DisableItemsBelowReqLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + } + + continue; + } + + // + // Disable Items for level higher than X + // + + if ((DisableItemsAboveReqLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel > DisableItemsAboveReqLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + } + + continue; + } + + // + // Disable Trade Goods for level lower than X + // + + if ((DisableTGsBelowReqLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel < DisableTGsBelowReqLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + } + + continue; + } + + // + // Disable Trade Goods for level higher than X + // + + if ((DisableTGsAboveReqLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel > DisableTGsAboveReqLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + } + + continue; + } + + // + // Disable Items that require skill lower than X + // + + if ((DisableItemsBelowReqSkillRank) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank < DisableItemsBelowReqSkillRank)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + } + + continue; + } + + // + // Disable Items that require skill higher than X + // + + if ((DisableItemsAboveReqSkillRank) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank > DisableItemsAboveReqSkillRank)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + } + + continue; + } + + // + // Disable Trade Goods that require skill lower than X + // + + if ((DisableTGsBelowReqSkillRank) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank < DisableTGsBelowReqSkillRank)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + } + + continue; + } + + // + // Disable Trade Goods that require skill higher than X + // + + if ((DisableTGsAboveReqSkillRank) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank > DisableTGsAboveReqSkillRank)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + } + + continue; + } + + // + // Now that the items passed all the tests, organize it by quality + // + + if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) + { + switch (itr->second.Quality) + { + case AHB_GREY: + GreyTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_WHITE: + WhiteTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_GREEN: + GreenTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_BLUE: + BlueTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_PURPLE: + PurpleTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_ORANGE: + OrangeTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_YELLOW: + YellowTradeGoodsBin.insert(itr->second.ItemId); + break; + } + } + else + { + switch (itr->second.Quality) + { + case AHB_GREY: + GreyItemsBin.insert(itr->second.ItemId); + break; + + case AHB_WHITE: + WhiteItemsBin.insert(itr->second.ItemId); + break; + + case AHB_GREEN: + GreenItemsBin.insert(itr->second.ItemId); + break; + + case AHB_BLUE: + BlueItemsBin.insert(itr->second.ItemId); + break; + + case AHB_PURPLE: + PurpleItemsBin.insert(itr->second.ItemId); + break; + + case AHB_ORANGE: + OrangeItemsBin.insert(itr->second.ItemId); + break; + + case AHB_YELLOW: + YellowItemsBin.insert(itr->second.ItemId); + break; + } + } + } + + // + // Perform reporting and the last check: if no items are disabled or in the whitelist clear the bin making the selling useless + // + + LOG_INFO("module", "Configuration for ah {}", AHID); + + if (SellerWhiteList.size() == 0) + { + if (DisableItemStore.size() == 0) + { + LOG_ERROR("module", "No items are disabled or in the whitelist! Selling will be disabled!"); + + GreyTradeGoodsBin.clear(); + WhiteTradeGoodsBin.clear(); + GreenTradeGoodsBin.clear(); + BlueTradeGoodsBin.clear(); + PurpleTradeGoodsBin.clear(); + OrangeTradeGoodsBin.clear(); + YellowTradeGoodsBin.clear(); + GreyItemsBin.clear(); + WhiteItemsBin.clear(); + GreenItemsBin.clear(); + BlueItemsBin.clear(); + PurpleItemsBin.clear(); + OrangeItemsBin.clear(); + YellowItemsBin.clear(); + + AHBSeller = false; + + return; + } + + LOG_INFO("module", "{} disabled items", uint32(DisableItemStore.size())); + } + else + { + LOG_INFO("module", "Using a whitelist of {} items", uint32(SellerWhiteList.size())); + } + + // if (DebugOutConfig) + // { + LOG_INFO("module", "loaded {} grey trade goods", uint32(GreyTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} white trade goods", uint32(WhiteTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} green trade goods", uint32(GreenTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} blue trade goods", uint32(BlueTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} purple trade goods", uint32(PurpleTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} orange trade goods", uint32(OrangeTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} yellow trade goods", uint32(YellowTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} grey items" , uint32(GreyItemsBin.size())); + LOG_INFO("module", "loaded {} white items" , uint32(WhiteItemsBin.size())); + LOG_INFO("module", "loaded {} green items" , uint32(GreenItemsBin.size())); + LOG_INFO("module", "loaded {} blue items" , uint32(BlueItemsBin.size())); + LOG_INFO("module", "loaded {} purple items" , uint32(PurpleItemsBin.size())); + LOG_INFO("module", "loaded {} orange items" , uint32(OrangeItemsBin.size())); + LOG_INFO("module", "loaded {} yellow items" , uint32(YellowItemsBin.size())); + // } +} + +std::set AHBConfig::getCommaSeparatedIntegers(std::string text) +{ + std::string value; + std::stringstream stream; + std::set ret; + + stream.str(text); + + // + // Continue to precess comma separated values + // + + while (std::getline(stream, value, ',')) + { + ret.insert(atoi(value.c_str())); + } + + return ret; +} diff --git a/src/AuctionHouseBotConfig.h b/src/AuctionHouseBotConfig.h index 4dd1dd8..13601c7 100644 --- a/src/AuctionHouseBotConfig.h +++ b/src/AuctionHouseBotConfig.h @@ -20,11 +20,16 @@ #ifndef AUCTION_HOUSE_BOT_CONFIG_H #define AUCTION_HOUSE_BOT_CONFIG_H +#include +#include + +#include "ObjectMgr.h" + class AHBConfig { private: - uint32 AHID; - uint32 AHFID; + uint32 AHID; // Id + uint32 AHFID; // Faction id uint32 minItems; uint32 maxItems; @@ -97,21 +102,29 @@ class AHBConfig uint32 buyerBiddingInterval; uint32 buyerBidsPerInterval; - uint32 greytgp; // Contains the amount of items to be sold in absolute values - uint32 whitetgp; // Contains the amount of items to be sold in absolute values - uint32 greentgp; // Contains the amount of items to be sold in absolute values - uint32 bluetgp; // Contains the amount of items to be sold in absolute values - uint32 purpletgp; // Contains the amount of items to be sold in absolute values - uint32 orangetgp; // Contains the amount of items to be sold in absolute values - uint32 yellowtgp; // Contains the amount of items to be sold in absolute values - - uint32 greyip; // Contains the amount of items to be sold in absolute values - uint32 whiteip; // Contains the amount of items to be sold in absolute values - uint32 greenip; // Contains the amount of items to be sold in absolute values - uint32 blueip; // Contains the amount of items to be sold in absolute values - uint32 purpleip; // Contains the amount of items to be sold in absolute values - uint32 orangeip; // Contains the amount of items to be sold in absolute values - uint32 yellowip; // Contains the amount of items to be sold in absolute values + // + // Amount of items to be sold in absolute values + // + + uint32 greytgp; + uint32 whitetgp; + uint32 greentgp; + uint32 bluetgp; + uint32 purpletgp; + uint32 orangetgp; + uint32 yellowtgp; + + uint32 greyip; + uint32 whiteip; + uint32 greenip; + uint32 blueip; + uint32 purpleip; + uint32 orangeip; + uint32 yellowip; + + // + // Situation of the auction house + // uint32 greyTGoods; uint32 whiteTGoods; @@ -129,11 +142,155 @@ class AHBConfig uint32 orangeItems; uint32 yellowItems; + void InitializeFromFile(); + void InitializeFromSql(std::set botsIds); + + std::set getCommaSeparatedIntegers(std::string text); + public: + // + // Debugging + // + + bool DebugOut; + bool DebugOutConfig; + bool DebugOutFilters; + bool DebugOutBuyer; + bool DebugOutSeller; + + // + // Tracing + // + + bool TraceSeller; + bool TraceBuyer; + + // + // Setup + // + + bool AHBSeller; + bool AHBBuyer; + bool BuyMethod; + bool SellMethod; + bool ConsiderOnlyBotAuctions; + uint32 ItemsPerCycle; + + // + // Filters + // + + bool Vendor_Items; + bool Loot_Items; + bool Other_Items; + bool Vendor_TGs; + bool Loot_TGs; + bool Other_TGs; + + bool No_Bind; + bool Bind_When_Picked_Up; + bool Bind_When_Equipped; + bool Bind_When_Use; + bool Bind_Quest_Item; + + uint32 DuplicatesCount; + uint32 ElapsingTimeClass; + + bool DivisibleStacks; + bool DisablePermEnchant; + bool DisableConjured; + bool DisableGems; + bool DisableMoney; + bool DisableMoneyLoot; + bool DisableLootable; + bool DisableKeys; + bool DisableDuration; + bool DisableBOP_Or_Quest_NoReqLevel; + + bool DisableWarriorItems; + bool DisablePaladinItems; + bool DisableHunterItems; + bool DisableRogueItems; + bool DisablePriestItems; + bool DisableDKItems; + bool DisableShamanItems; + bool DisableMageItems; + bool DisableWarlockItems; + bool DisableUnusedClassItems; + bool DisableDruidItems; + + uint32 DisableItemsBelowLevel; + uint32 DisableItemsAboveLevel; + + uint32 DisableTGsBelowLevel; + uint32 DisableTGsAboveLevel; + + uint32 DisableItemsBelowGUID; + uint32 DisableItemsAboveGUID; + + uint32 DisableTGsBelowGUID; + uint32 DisableTGsAboveGUID; + + uint32 DisableItemsBelowReqLevel; + uint32 DisableItemsAboveReqLevel; + + uint32 DisableTGsBelowReqLevel; + uint32 DisableTGsAboveReqLevel; + + uint32 DisableItemsBelowReqSkillRank; + uint32 DisableItemsAboveReqSkillRank; + + uint32 DisableTGsBelowReqSkillRank; + uint32 DisableTGsAboveReqSkillRank; + + // + // Items validity for selling purposes + // + + std::set NpcItems; + std::set LootItems; + std::set DisableItemStore; + std::set SellerWhiteList; + + // + // Bins for trade goods. + // + + std::set GreyTradeGoodsBin; + std::set WhiteTradeGoodsBin; + std::set GreenTradeGoodsBin; + std::set BlueTradeGoodsBin; + std::set PurpleTradeGoodsBin; + std::set OrangeTradeGoodsBin; + std::set YellowTradeGoodsBin; + + // + // Bins for items + // + + std::set GreyItemsBin; + std::set WhiteItemsBin; + std::set GreenItemsBin; + std::set BlueItemsBin; + std::set PurpleItemsBin; + std::set OrangeItemsBin; + std::set YellowItemsBin; + + // + // Constructors/destructors + // + + AHBConfig(uint32 ahid, AHBConfig* conf); AHBConfig(uint32 ahid); AHBConfig(); ~AHBConfig(); + // + // Ruotines + // + + void Initialize(std::set botsIds); + void InitializeBins(); void Reset(); uint32 GetAHID(); @@ -145,21 +302,8 @@ class AHBConfig void SetMaxItems (uint32 value); uint32 GetMaxItems (); - void SetPercentages( - uint32 greytg, - uint32 whitetg, - uint32 greentg, - uint32 bluetg, - uint32 purpletg, - uint32 orangetg, - uint32 yellowtg, - uint32 greyi, - uint32 whitei, - uint32 greeni, - uint32 bluei, - uint32 purplei, - uint32 orangei, - uint32 yellowi); + void SetPercentages (uint32 greytg, uint32 whitetg, uint32 greentg, uint32 bluetg, uint32 purpletg, uint32 orangetg, uint32 yellowtg, + uint32 greyi , uint32 whitei , uint32 greeni , uint32 bluei , uint32 purplei , uint32 orangei , uint32 yellowi); uint32 GetPercentages (uint32 color); void SetMinPrice (uint32 color, uint32 value); @@ -201,5 +345,12 @@ class AHBConfig uint32 GetItemCounts (uint32 color); }; +// +// Globally defined configurations +// + +extern AHBConfig* gAllianceConfig; +extern AHBConfig* gHordeConfig; +extern AHBConfig* gNeutralConfig; #endif // AUCTION_HOUSE_BOT_CONFIG_H diff --git a/src/AuctionHouseBotMailScript.cpp b/src/AuctionHouseBotMailScript.cpp index 9c30f0a..5c3dee2 100644 --- a/src/AuctionHouseBotMailScript.cpp +++ b/src/AuctionHouseBotMailScript.cpp @@ -1,4 +1,5 @@ #include "AuctionHouseBot.h" +#include "AuctionHouseBotCommon.h" #include "AuctionHouseBotMailScript.h" AHBot_MailScript::AHBot_MailScript() : MailScript("AHBot_MailScript") @@ -20,7 +21,7 @@ void AHBot_MailScript::OnBeforeMailDraftSendMailTo( // If the mail is for the bot, then remove it and delete the items bought // - if (receiver.GetPlayerGUIDLow() == auctionbot->GetAHBplayerGUID()) + if (gBotsId.find(receiver.GetPlayerGUIDLow()) != gBotsId.end()) { if (sender.GetMailMessageType() == MAIL_AUCTION) { diff --git a/src/AuctionHouseBotWorldScript.cpp b/src/AuctionHouseBotWorldScript.cpp index 4167a4f..5238fa2 100644 --- a/src/AuctionHouseBotWorldScript.cpp +++ b/src/AuctionHouseBotWorldScript.cpp @@ -1,4 +1,8 @@ +#include "Config.h" +#include "Log.h" + #include "AuctionHouseBot.h" +#include "AuctionHouseBotCommon.h" #include "AuctionHouseBotWorldScript.h" // ============================================================================= @@ -12,11 +16,107 @@ AHBot_WorldScript::AHBot_WorldScript() : WorldScript("AHBot_WorldScript") void AHBot_WorldScript::OnBeforeConfigLoad(bool /*reload*/) { - auctionbot->InitializeConfiguration(); + // + // Retrieve how many bots shall be operating on the auction market + // + + bool debug = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG" , false); + uint32 account = sConfigMgr->GetOption("AuctionHouseBot.Account", 0); + uint32 player = sConfigMgr->GetOption("AuctionHouseBot.GUID" , 0); + + // + // All the bots bound to the provided account will be used for auctioning, if GUID is zero. + // Otherwise only the specified character is used. + // + + if (account == 0 && player == 0) + { + LOG_ERROR("server.loading", "AHBot: Account id and player id missing from configuration; is that the right file?"); + return; + } + else + { + QueryResult result = CharacterDatabase.Query("SELECT guid FROM characters WHERE account = {}", account); + + if (result) + { + gBotsId.clear(); + + do + { + Field* fields = result->Fetch(); + uint32 botId = fields[0].Get(); + + if (player == 0) + { + if (debug) + { + LOG_INFO("server.loading", "AHBot: New bot to start, account={} character={}", account, botId); + } + + gBotsId.insert(botId); + } + else + { + if (player == botId) + { + if (debug) + { + LOG_INFO("server.loading", "AHBot: Starting only one bot, account={} character={}", account, botId); + } + + gBotsId.insert(botId); + break; + } + } + + } while (result->NextRow()); + } + else + { + LOG_ERROR("server.loading", "AHBot: Could not query the database for characters of account {}", account); + return; + } + } + + if (gBotsId.size() == 0) + { + LOG_ERROR("server.loading", "AHBot: no characters registered for account {}", account); + return; + } + + // + // Preparare the global configuration for all factions using the configuration just read + // + + gAllianceConfig->Initialize(gBotsId); + gHordeConfig->Initialize (gBotsId); + gNeutralConfig->Initialize (gBotsId); } void AHBot_WorldScript::OnStartup() { LOG_INFO("server.loading", "Initialize AuctionHouseBot..."); - auctionbot->Initialize(); + + // + // Initialize the configuration items bins here, when items has been handled by the object manager + // + + gAllianceConfig->InitializeBins(); + gHordeConfig->InitializeBins (); + gNeutralConfig->InitializeBins (); + + // + // Starts the amount of bots read furing the configuration phase + // + + uint32 account = sConfigMgr->GetOption("AuctionHouseBot.Account", 0); + + for (uint32 id: gBotsId) + { + AuctionHouseBot* bot = new AuctionHouseBot(account, id); + bot->Initialize(gAllianceConfig, gHordeConfig, gNeutralConfig); + + gBots.insert(bot); + } } diff --git a/src/cs_ah_bot.cpp b/src/cs_ah_bot.cpp index dd606ea..d2941e4 100644 --- a/src/cs_ah_bot.cpp +++ b/src/cs_ah_bot.cpp @@ -124,7 +124,11 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(AHBotCommand::buyer, 0, 0, param1); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::buyer, 0, 0, param1); + } + return true; } else if (strncmp(opt, "seller", l) == 0) @@ -137,7 +141,11 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(AHBotCommand::seller, 0, 0, param1); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::seller, 0, 0, param1); + } + return true; } @@ -207,7 +215,10 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(AHBotCommand::ahexpire, ahMapID, 0, NULL); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::ahexpire, ahMapID, 0, NULL); + } } else if (strncmp(opt, "minitems", l) == 0) { @@ -219,7 +230,10 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(AHBotCommand::minitems, ahMapID, 0, param1); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::minitems, ahMapID, 0, param1); + } } else if (strncmp(opt, "maxitems", l) == 0) { @@ -231,7 +245,10 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(AHBotCommand::maxitems, ahMapID, 0, param1); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::maxitems, ahMapID, 0, param1); + } } else if (strncmp(opt, "percentages", l) == 0) { @@ -314,7 +331,10 @@ class ah_bot_commandscript : public CommandScript strcat(param, " "); strcat(param, param14); - auctionbot->Commands(AHBotCommand::percentages, ahMapID, 0, param); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::percentages, ahMapID, 0, param); + } } else if (strncmp(opt, "minprice", l) == 0) { @@ -331,7 +351,10 @@ class ah_bot_commandscript : public CommandScript if (quality != static_cast(-1)) { - auctionbot->Commands(AHBotCommand::minprice, ahMapID, quality, param2); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::minprice, ahMapID, quality, param2); + } } else { @@ -354,7 +377,10 @@ class ah_bot_commandscript : public CommandScript if (quality != static_cast(-1)) { - auctionbot->Commands(AHBotCommand::maxprice, ahMapID, quality, param2); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::maxprice, ahMapID, quality, param2); + } } else { @@ -385,7 +411,10 @@ class ah_bot_commandscript : public CommandScript if (quality != static_cast(-1)) { - auctionbot->Commands(AHBotCommand::minbidprice, ahMapID, quality, param2); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::minbidprice, ahMapID, quality, param2); + } } else { @@ -416,7 +445,10 @@ class ah_bot_commandscript : public CommandScript if (quality != static_cast(-1)) { - auctionbot->Commands(AHBotCommand::maxbidprice, ahMapID, quality, param2); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::maxbidprice, ahMapID, quality, param2); + } } else { @@ -446,7 +478,10 @@ class ah_bot_commandscript : public CommandScript if (quality != static_cast(-1)) { - auctionbot->Commands(AHBotCommand::maxstack, ahMapID, quality, param2); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::maxstack, ahMapID, quality, param2); + } } else { @@ -469,7 +504,10 @@ class ah_bot_commandscript : public CommandScript if (quality != static_cast(-1)) { - auctionbot->Commands(AHBotCommand::buyerprice, ahMapID, quality, param2); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::buyerprice, ahMapID, quality, param2); + } } else { @@ -487,7 +525,10 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(AHBotCommand::bidinterval, ahMapID, 0, param1); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::bidinterval, ahMapID, 0, param1); + } } else if (strncmp(opt, "bidsperinterval", l) == 0) { @@ -499,7 +540,10 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(AHBotCommand::bidsperinterval, ahMapID, 0, param1); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::bidsperinterval, ahMapID, 0, param1); + } } else {