From 44ab5fc3f13edc36c107138214289107135d31f1 Mon Sep 17 00:00:00 2001 From: Winfidonarleyan Date: Sat, 19 Mar 2022 13:41:57 +0700 Subject: [PATCH 1/4] feat(Misc): base rework module --- conf/mod_ahbot.conf.dist | 12 - src/AuctionHouseBot.cpp | 1504 +++++++++++++------------------- src/AuctionHouseBot.h | 1320 +++------------------------- src/AuctionHouseBotConfig.cpp | 318 +++++++ src/AuctionHouseBotConfig.h | 169 ++++ src/AuctionHouseBotScript.cpp | 35 +- src/AuctionHouseBot_loader.cpp | 27 + src/ah_bot_loader.cpp | 15 - src/cs_ah_bot.cpp | 115 ++- 9 files changed, 1291 insertions(+), 2224 deletions(-) create mode 100644 src/AuctionHouseBotConfig.cpp create mode 100644 src/AuctionHouseBotConfig.h create mode 100644 src/AuctionHouseBot_loader.cpp delete mode 100644 src/ah_bot_loader.cpp diff --git a/conf/mod_ahbot.conf.dist b/conf/mod_ahbot.conf.dist index 26d8fdf..de71a17 100644 --- a/conf/mod_ahbot.conf.dist +++ b/conf/mod_ahbot.conf.dist @@ -1,16 +1,6 @@ -[worldserver] - ############################################################################### # AUCTION HOUSE BOT SETTINGS # -# AuctionHouseBot.DEBUG -# Enable/Disable Debugging output -# Default 0 (disabled) -# -# AuctionHouseBot.DEBUG_FILTERS -# Enable/Disable Debugging output from Filters -# Default 0 (disabled) -# # AuctionHouseBot.EnableSeller # Enable/Disable the part of AHBot that puts items up for auction # Default 0 (disabled) @@ -41,8 +31,6 @@ # ############################################################################### -AuctionHouseBot.DEBUG = 0 -AuctionHouseBot.DEBUG_FILTERS = 0 AuctionHouseBot.EnableSeller = 0 AuctionHouseBot.EnableBuyer = 0 AuctionHouseBot.UseBuyPriceForSeller = 0 diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index 9ceb204..e844740 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -1,20 +1,18 @@ /* - * Copyright (C) 2008-2010 Trinity - * Copyright (C) 2005-2009 MaNGOS + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . */ #include "ObjectMgr.h" @@ -24,70 +22,12 @@ #include "Player.h" #include "WorldSession.h" #include "GameTime.h" +#include "StringConvert.h" +#include "StringFormat.h" #include -using namespace std; -vector npcItems; -vector lootItems; -vector greyTradeGoodsBin; -vector whiteTradeGoodsBin; -vector greenTradeGoodsBin; -vector blueTradeGoodsBin; -vector purpleTradeGoodsBin; -vector orangeTradeGoodsBin; -vector yellowTradeGoodsBin; -vector greyItemsBin; -vector whiteItemsBin; -vector greenItemsBin; -vector blueItemsBin; -vector purpleItemsBin; -vector orangeItemsBin; -vector yellowItemsBin; - AuctionHouseBot::AuctionHouseBot() { - debug_Out = false; - debug_Out_Filters = false; - AHBSeller = false; - AHBBuyer = 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; @@ -107,25 +47,26 @@ AuctionHouseBot::AuctionHouseBot() //End Filters - _lastrun_a = time(NULL); - _lastrun_h = time(NULL); - _lastrun_n = time(NULL); + _lastUpdateAlliance = GameTime::GetGameTime(); + _lastUpdateHorde = GameTime::GetGameTime(); + _lastUpdateNeutral = GameTime::GetGameTime(); - AllianceConfig = AHBConfig(2); - HordeConfig = AHBConfig(6); - NeutralConfig = AHBConfig(7); + AllianceConfig = AHBConfig(AUCTIONHOUSE_ALLIANCE); + HordeConfig = AHBConfig(AUCTIONHOUSE_HORDE); + NeutralConfig = AHBConfig(AUCTIONHOUSE_NEUTRAL); } -AuctionHouseBot::~AuctionHouseBot() +/*static*/ AuctionHouseBot* AuctionHouseBot::instance() { + static AuctionHouseBot instance; + return &instance; } -void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) +void AuctionHouseBot::AddNewAuctions(Player* AHBplayer, AHBConfig* config) { if (!AHBSeller) { - if (debug_Out) - LOG_INFO("module", "AHSeller: Disabled"); + LOG_DEBUG("module.ahbot", "AHSeller: Disabled"); return; } @@ -134,36 +75,34 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) if (maxItems == 0) { - //if (debug_Out) sLog->outString( "AHSeller: Auctions disabled"); + LOG_DEBUG("module.ahbot", "Auctions disabled"); return; } - AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntry(config->GetAHFID()); + AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntry(config->GetAuctionHouseFactionID()); if (!ahEntry) { return; } - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); + + AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAuctionHouseFactionID()); if (!auctionHouse) { return; } uint32 auctions = auctionHouse->Getcount(); - uint32 items = 0; if (auctions >= minItems) { - if (debug_Out) - LOG_ERROR("module", "AHSeller: Auctions above minimum"); + LOG_ERROR("module.ahbot", "AHSeller: Auctions above minimum"); return; } if (auctions >= maxItems) { - if (debug_Out) - LOG_ERROR("module", "AHSeller: Auctions at or above maximum"); + LOG_ERROR("module.ahbot", "AHSeller: Auctions at or above maximum"); return; } @@ -172,194 +111,56 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) else items = (maxItems - auctions); - if (debug_Out) - LOG_INFO("module", "AHSeller: Adding {} Auctions", items); - - if (debug_Out) - LOG_ERROR("module", "AHSeller: Current house id is {}", config->GetAHID()); - - uint32 greyTGcount = config->GetPercents(AHB_GREY_TG); - uint32 whiteTGcount = config->GetPercents(AHB_WHITE_TG); - uint32 greenTGcount = config->GetPercents(AHB_GREEN_TG); - uint32 blueTGcount = config->GetPercents(AHB_BLUE_TG); - uint32 purpleTGcount = config->GetPercents(AHB_PURPLE_TG); - uint32 orangeTGcount = config->GetPercents(AHB_ORANGE_TG); - uint32 yellowTGcount = config->GetPercents(AHB_YELLOW_TG); - uint32 greyIcount = config->GetPercents(AHB_GREY_I); - uint32 whiteIcount = config->GetPercents(AHB_WHITE_I); - uint32 greenIcount = config->GetPercents(AHB_GREEN_I); - uint32 blueIcount = config->GetPercents(AHB_BLUE_I); - uint32 purpleIcount = config->GetPercents(AHB_PURPLE_I); - uint32 orangeIcount = config->GetPercents(AHB_ORANGE_I); - uint32 yellowIcount = config->GetPercents(AHB_YELLOW_I); -/* uint32 total = greyTGcount + whiteTGcount + greenTGcount + blueTGcount - + purpleTGcount + orangeTGcount + yellowTGcount - + whiteIcount + greenIcount + blueIcount + purpleIcount - + orangeIcount + yellowIcount; -*/ - uint32 greyTGoods = config->GetItemCounts(AHB_GREY_TG); - uint32 whiteTGoods = config->GetItemCounts(AHB_WHITE_TG); - uint32 greenTGoods = config->GetItemCounts(AHB_GREEN_TG); - uint32 blueTGoods = config->GetItemCounts(AHB_BLUE_TG); - uint32 purpleTGoods = config->GetItemCounts(AHB_PURPLE_TG); - uint32 orangeTGoods = config->GetItemCounts(AHB_ORANGE_TG); - uint32 yellowTGoods = config->GetItemCounts(AHB_YELLOW_TG); - - uint32 greyItems = config->GetItemCounts(AHB_GREY_I); - uint32 whiteItems = config->GetItemCounts(AHB_WHITE_I); - uint32 greenItems = config->GetItemCounts(AHB_GREEN_I); - uint32 blueItems = config->GetItemCounts(AHB_BLUE_I); - uint32 purpleItems = config->GetItemCounts(AHB_PURPLE_I); - uint32 orangeItems = config->GetItemCounts(AHB_ORANGE_I); - uint32 yellowItems = config->GetItemCounts(AHB_YELLOW_I); - - if (debug_Out) - LOG_ERROR("module", "AHSeller: {} items", items); + LOG_DEBUG("module.ahbot", "AHSeller: Adding {} Auctions", items); + LOG_DEBUG("module.ahbot", "AHSeller: Current house id is {}", config->GetAuctionHouseID()); + + std::array percents = *config->GetPercents(); + std::array itemsCount = *config->GetItemCounts(); + + LOG_DEBUG("module.ahbot", "AHSeller: {} items", items); // only insert a few at a time, so as not to peg the processor for (uint32 cnt = 1; cnt <= items; cnt++) { - if (debug_Out) - LOG_ERROR("module", "AHSeller: {} count", cnt); + LOG_DEBUG("module.ahbot", "AHSeller: {} count", cnt); uint32 itemID = 0; uint32 itemColor = 99; uint32 loopbreaker = 0; + while (itemID == 0 && loopbreaker <= 50) { ++loopbreaker; uint32 choice = urand(0, 13); itemColor = choice; - switch (choice) - { - case 0: - { - if ((greyItemsBin.size() > 0) && (greyItems < greyIcount)) - itemID = greyItemsBin[urand(0, greyItemsBin.size() - 1)]; - else continue; - break; - } - case 1: - { - if ((whiteItemsBin.size() > 0) && (whiteItems < whiteIcount)) - itemID = whiteItemsBin[urand(0, whiteItemsBin.size() - 1)]; - else continue; - break; - } - case 2: - { - if ((greenItemsBin.size() > 0) && (greenItems < greenIcount)) - itemID = greenItemsBin[urand(0, greenItemsBin.size() - 1)]; - else continue; - break; - } - case 3: - { - if ((blueItemsBin.size() > 0) && (blueItems < blueIcount)) - itemID = blueItemsBin[urand(0, blueItemsBin.size() - 1)]; - else continue; - break; - } - case 4: - { - if ((purpleItemsBin.size() > 0) && (purpleItems < purpleIcount)) - itemID = purpleItemsBin[urand(0, purpleItemsBin.size() - 1)]; - else continue; - break; - } - case 5: - { - if ((orangeItemsBin.size() > 0) && (orangeItems < orangeIcount)) - itemID = orangeItemsBin[urand(0, orangeItemsBin.size() - 1)]; - else continue; - break; - } - case 6: - { - if ((yellowItemsBin.size() > 0) && (yellowItems < yellowIcount)) - itemID = yellowItemsBin[urand(0, yellowItemsBin.size() - 1)]; - else continue; - break; - } - case 7: - { - if ((greyTradeGoodsBin.size() > 0) && (greyTGoods < greyTGcount)) - itemID = greyTradeGoodsBin[urand(0, greyTradeGoodsBin.size() - 1)]; - else continue; - break; - } - case 8: - { - if ((whiteTradeGoodsBin.size() > 0) && (whiteTGoods < whiteTGcount)) - itemID = whiteTradeGoodsBin[urand(0, whiteTradeGoodsBin.size() - 1)]; - else continue; - break; - } - case 9: - { - if ((greenTradeGoodsBin.size() > 0) && (greenTGoods < greenTGcount)) - itemID = greenTradeGoodsBin[urand(0, greenTradeGoodsBin.size() - 1)]; - else continue; - break; - } - case 10: - { - if ((blueTradeGoodsBin.size() > 0) && (blueTGoods < blueTGcount)) - itemID = blueTradeGoodsBin[urand(0, blueTradeGoodsBin.size() - 1)]; - else continue; - break; - } - case 11: - { - if ((purpleTradeGoodsBin.size() > 0) && (purpleTGoods < purpleTGcount)) - itemID = purpleTradeGoodsBin[urand(0, purpleTradeGoodsBin.size() - 1)]; - else continue; - break; - } - case 12: - { - if ((orangeTradeGoodsBin.size() > 0) && (orangeTGoods < orangeTGcount)) - itemID = orangeTradeGoodsBin[urand(0, orangeTradeGoodsBin.size() - 1)]; - else continue; - break; - } - case 13: - { - if ((yellowTradeGoodsBin.size() > 0) && (yellowTGoods < yellowTGcount)) - itemID = yellowTradeGoodsBin[urand(0, yellowTradeGoodsBin.size() - 1)]; - else continue; - break; - } - default: - { - if (debug_Out) - LOG_ERROR("module", "AHSeller: itemID Switch - Default Reached"); - break; - } - } - if (itemID == 0) + auto const& itemsBin = _itemsBin[choice]; + + if (!itemsBin.empty() && itemsCount[choice] < percents[choice]) + itemID = Acore::Containers::SelectRandomContainerElement(itemsBin); + else + continue; + + if (!itemID) { - if (debug_Out) - LOG_ERROR("module", "AHSeller: Item::CreateItem() - ItemID is 0"); + LOG_ERROR("module.ahbot", "AHSeller: Item::CreateItem() - ItemID is 0"); continue; } ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(itemID); - if (prototype == NULL) + if (!prototype) { - if (debug_Out) - LOG_ERROR("module", "AHSeller: Huh?!?! prototype == NULL"); + LOG_ERROR("module.ahbot", "AHSeller: ItemTemplate is nullptr!"); continue; } Item* item = Item::CreateItem(itemID, 1, AHBplayer); - if (item == NULL) + if (!item) { - if (debug_Out) - LOG_ERROR("module", "AHSeller: Item::CreateItem() returned NULL"); + LOG_ERROR("module.ahbot", "AHSeller: Item not created!"); break; } + item->AddToUpdateQueueOf(AHBplayer); uint32 randomPropertyId = Item::GenerateItemRandomPropertyId(itemID); @@ -375,7 +176,7 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) else buyoutPrice = prototype->SellPrice; - if (prototype->Quality <= AHB_MAX_QUALITY) + if (prototype->Quality <= AHB_MAX_DEFAULT_QUALITY) { if (config->GetMaxStack(prototype->Quality) > 1 && item->GetMaxStackCount() > 1) stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(prototype->Quality))); @@ -383,6 +184,7 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) stackCount = urand(1, item->GetMaxStackCount()); else stackCount = 1; + buyoutPrice *= urand(config->GetMinPrice(prototype->Quality), config->GetMaxPrice(prototype->Quality)); buyoutPrice /= 100; bidPrice = buyoutPrice * urand(config->GetMinBidPrice(prototype->Quality), config->GetMaxBidPrice(prototype->Quality)); @@ -391,36 +193,39 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) else { // quality is something it shouldn't be, let's get out of here - if (debug_Out) - LOG_ERROR("module", "AHBuyer: Quality {} not Supported", prototype->Quality); + LOG_ERROR("module.ahbot", "AHBuyer: Quality {} not Supported", prototype->Quality); item->RemoveFromUpdateQueueOf(AHBplayer); continue; } uint32 etime = urand(1,3); + Seconds elapsedTime = 24h; + switch(etime) { case 1: - etime = 43200; + elapsedTime = 12h; break; case 2: - etime = 86400; + elapsedTime = 24h; break; case 3: - etime = 172800; + elapsedTime = 48h; break; default: - etime = 86400; + elapsedTime = 24h; break; } + item->SetCount(stackCount); - uint32 dep = sAuctionMgr->GetAuctionDeposit(ahEntry, etime, item, stackCount); + uint32 dep = sAuctionMgr->GetAuctionDeposit(ahEntry, elapsedTime.count(), item, stackCount); auto trans = CharacterDatabase.BeginTransaction(); + AuctionEntry* auctionEntry = new AuctionEntry(); auctionEntry->Id = sObjectMgr->GenerateAuctionID(); - auctionEntry->houseId = config->GetAHID(); + auctionEntry->houseId = config->GetAuctionHouseID(); auctionEntry->item_guid = item->GetGUID(); auctionEntry->item_template = item->GetEntry(); auctionEntry->itemCount = item->GetCount(); @@ -429,91 +234,52 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) auctionEntry->buyout = buyoutPrice * stackCount; auctionEntry->bid = 0; auctionEntry->deposit = dep; - auctionEntry->expire_time = (time_t) etime + time(NULL); + auctionEntry->expire_time = elapsedTime.count() + GameTime::GetGameTime().count(); auctionEntry->auctionHouseEntry = ahEntry; + item->SaveToDB(trans); item->RemoveFromUpdateQueueOf(AHBplayer); + sAuctionMgr->AddAItem(item); + auctionHouse->AddAuction(auctionEntry); auctionEntry->SaveToDB(trans); + CharacterDatabase.CommitTransaction(trans); - switch(itemColor) - { - case 0: - ++greyItems; - break; - case 1: - ++whiteItems; - break; - case 2: - ++greenItems; - break; - case 3: - ++blueItems; - break; - case 4: - ++purpleItems; - break; - case 5: - ++orangeItems; - break; - case 6: - ++yellowItems; - break; - case 7: - ++greyTGoods; - break; - case 8: - ++whiteTGoods; - break; - case 9: - ++greenTGoods; - break; - case 10: - ++blueTGoods; - break; - case 11: - ++purpleTGoods; - break; - case 12: - ++orangeTGoods; - break; - case 13: - ++yellowTGoods; - break; - default: - break; - } + itemsCount[itemColor]++; } } } -void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, WorldSession *session) + +void AuctionHouseBot::AddNewAuctionBuyerBotBid(std::shared_ptr player, std::shared_ptr session, AHBConfig* config) { if (!AHBBuyer) { - if (debug_Out) - LOG_ERROR("module", "AHBuyer: Disabled"); + LOG_ERROR("module.ahbot", "AHBuyer: Disabled"); return; } - QueryResult result = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE itemowner<>{} AND buyguid<>{}", AHBplayerGUID, AHBplayerGUID); + auto sharedConfig = std::make_shared(*config); - if (!result) - return; + _queryProcessor.AddCallback(CharacterDatabase.AsyncQuery(Acore::StringFormatFmt("SELECT id FROM auctionhouse WHERE itemowner<>{} AND buyguid<>{}", AHBplayerGUID, AHBplayerGUID)). + WithCallback(std::bind(&AuctionHouseBot::AddNewAuctionBuyerBotBidCallback, this, player, session, sharedConfig, std::placeholders::_1))); +} - if (result->GetRowCount() == 0) +void AuctionHouseBot::AddNewAuctionBuyerBotBidCallback(std::shared_ptr player, std::shared_ptr session, std::shared_ptr config, QueryResult result) +{ + if (!result || !result->GetRowCount()) return; // Fetches content of selected AH - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); - vector possibleBids; + AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAuctionHouseFactionID()); + std::vector possibleBids; do { uint32 tmpdata = result->Fetch()->Get(); possibleBids.push_back(tmpdata); - }while (result->NextRow()); + } while (result->NextRow()); for (uint32 count = 1; count <= config->GetBidsPerInterval(); ++count) { @@ -526,25 +292,22 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con } // Choose random auction from possible auctions - uint32 vectorPos = urand(0, possibleBids.size() - 1); - vector::iterator iter = possibleBids.begin(); - advance(iter, vectorPos); + uint32 randomID = Acore::Containers::SelectRandomContainerElement(possibleBids); // from auctionhousehandler.cpp, creates auction pointer & player pointer - AuctionEntry* auction = auctionHouse->GetAuction(*iter); + AuctionEntry* auction = auctionHouse->GetAuction(randomID); // Erase the auction from the vector to prevent bidding on item in next iteration. - possibleBids.erase(iter); + std::erase(possibleBids, randomID); if (!auction) continue; // get exact item information - Item *pItem = sAuctionMgr->GetAItem(auction->item_guid); + Item* pItem = sAuctionMgr->GetAItem(auction->item_guid); if (!pItem) { - if (debug_Out) - LOG_ERROR("module", "AHBuyer: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString()); + LOG_DEBUG("module.ahbot", "AHBuyer: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString()); continue; } @@ -559,13 +322,13 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con currentprice = auction->startbid; // Prepare portion from maximum bid - double bidrate = static_cast(urand(1, 100)) / 100; - long double bidMax = 0; + float bidrate = frand(0.01f, 1.0f); + float bidMax = 0; // check that bid has acceptable value and take bid based on vendorprice, stacksize and quality if (BuyMethod) { - if (prototype->Quality <= AHB_MAX_QUALITY) + if (prototype->Quality <= AHB_MAX_DEFAULT_QUALITY) { if (currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(prototype->Quality)) bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(prototype->Quality); @@ -573,14 +336,13 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con else { // quality is something it shouldn't be, let's get out of here - if (debug_Out) - LOG_ERROR("module", "AHBuyer: Quality {} not Supported", prototype->Quality); - continue; + LOG_DEBUG("module.ahbot", "AHBuyer: Quality {} not Supported", prototype->Quality); + continue; } } else { - if (prototype->Quality <= AHB_MAX_QUALITY) + if (prototype->Quality <= AHB_MAX_DEFAULT_QUALITY) { if (currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(prototype->Quality)) bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(prototype->Quality); @@ -588,11 +350,10 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con else { // quality is something it shouldn't be, let's get out of here - if (debug_Out) - LOG_ERROR("module", "AHBuyer: Quality {} not Supported", prototype->Quality); - continue; + LOG_DEBUG("module.ahbot", "AHBuyer: Quality {} not Supported", prototype->Quality); + continue; } - } + } // check some special items, and do recalculating to their prices switch (prototype->Class) @@ -612,7 +373,8 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con } // Calculate our bid - long double bidvalue = currentprice + ((bidMax - currentprice) * bidrate); + float bidvalue = currentprice + ((bidMax - currentprice) * bidrate); + // Convert to uint32 uint32 bidprice = static_cast(bidvalue); @@ -621,69 +383,57 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con bidprice = currentprice + auction->GetAuctionOutBid(); - if (debug_Out) - { - 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", "-------------------------------------------------"); - } + LOG_DEBUG("module.ahbot", "-------------------------------------------------"); + LOG_DEBUG("module.ahbot", "AHBuyer: Info for Auction #{}:", auction->Id); + LOG_DEBUG("module.ahbot", "AHBuyer: AuctionHouse: {}", auction->GetHouseId()); + LOG_DEBUG("module.ahbot", "AHBuyer: Owner: {}", auction->owner.ToString()); + LOG_DEBUG("module.ahbot", "AHBuyer: Bidder: {}", auction->bidder.ToString()); + LOG_DEBUG("module.ahbot", "AHBuyer: Starting Bid: {}", auction->startbid); + LOG_DEBUG("module.ahbot", "AHBuyer: Current Bid: {}", currentprice); + LOG_DEBUG("module.ahbot", "AHBuyer: Buyout: {}", auction->buyout); + LOG_DEBUG("module.ahbot", "AHBuyer: Deposit: {}", auction->deposit); + LOG_DEBUG("module.ahbot", "AHBuyer: Expire Time: {}", uint32(auction->expire_time)); + LOG_DEBUG("module.ahbot", "AHBuyer: Bid Rate: {}", bidrate); + LOG_DEBUG("module.ahbot", "AHBuyer: Bid Max: {}", bidMax); + LOG_DEBUG("module.ahbot", "AHBuyer: Bid Value: {}", bidvalue); + LOG_DEBUG("module.ahbot", "AHBuyer: Bid Price: {}", bidprice); + LOG_DEBUG("module.ahbot", "AHBuyer: Item GUID: {}", auction->item_guid.ToString()); + LOG_DEBUG("module.ahbot", "AHBuyer: Item Template: {}", auction->item_template); + LOG_DEBUG("module.ahbot", "AHBuyer: Item Info:"); + LOG_DEBUG("module.ahbot", "AHBuyer: Item ID: {}", prototype->ItemId); + LOG_DEBUG("module.ahbot", "AHBuyer: Buy Price: {}", prototype->BuyPrice); + LOG_DEBUG("module.ahbot", "AHBuyer: Sell Price: {}", prototype->SellPrice); + LOG_DEBUG("module.ahbot", "AHBuyer: Bonding: {}", prototype->Bonding); + LOG_DEBUG("module.ahbot", "AHBuyer: Quality: {}", prototype->Quality); + LOG_DEBUG("module.ahbot", "AHBuyer: Item Level: {}", prototype->ItemLevel); + LOG_DEBUG("module.ahbot", "AHBuyer: Ammo Type: {}", prototype->AmmoType); + LOG_DEBUG("module.ahbot", "-------------------------------------------------"); // Check whether we do normal bid, or buyout - if ((bidprice < auction->buyout) || (auction->buyout == 0)) + if (bidprice < auction->buyout || !auction->buyout) { - if (auction->bidder) + if (auction->bidder && auction->bidder != player->GetGUID()) { - if (auction->bidder == AHBplayer->GetGUID()) - { - //pl->ModifyMoney(-int32(price - auction->bid)); - } - else - { - // mail to last bidder and return money - auto trans = CharacterDatabase.BeginTransaction(); - sAuctionMgr->SendAuctionOutbiddedMail(auction, bidprice, session->GetPlayer(), trans); - CharacterDatabase.CommitTransaction(trans); - //pl->ModifyMoney(-int32(price)); - } - } + auto trans = CharacterDatabase.BeginTransaction(); + sAuctionMgr->SendAuctionOutbiddedMail(auction, bidprice, player.get(), trans); + CharacterDatabase.CommitTransaction(trans); + } - auction->bidder = AHBplayer->GetGUID(); + auction->bidder = player->GetGUID(); auction->bid = bidprice; // Saving 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 { auto trans = CharacterDatabase.BeginTransaction(); - //buyout - if ((auction->bidder) && (AHBplayer->GetGUID() != auction->bidder)) - { - sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, session->GetPlayer(), trans); - } - auction->bidder = AHBplayer->GetGUID(); + + // Buyout + if (auction->bidder && player->GetGUID() != auction->bidder) + sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, player.get(), trans); + + auction->bidder = player->GetGUID(); auction->bid = auction->buyout; // Send mails to buyer & seller @@ -692,7 +442,7 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con sAuctionMgr->SendAuctionWonMail(auction, trans); auction->DeleteFromDB(trans); - sAuctionMgr->RemoveAItem(auction->item_guid); + sAuctionMgr->RemoveAItem(auction->item_guid); auctionHouse->RemoveAuction(auction); CharacterDatabase.CommitTransaction(trans); } @@ -701,48 +451,63 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con void AuctionHouseBot::Update() { - time_t _newrun = time(NULL); - if ((!AHBSeller) && (!AHBBuyer)) + if (!AHBSeller && !AHBBuyer) + return; + + if (!AHBplayerAccount || !AHBplayerGUID) + { + LOG_ERROR("module.ahbot", "{}: Invalid player data. Account {}. Guid {}", __FUNCTION__, AHBplayerAccount, AHBplayerGUID); return; + } + + std::string accountName = "AuctionHouseBot_" + std::to_string(AHBplayerAccount); + + auto session = std::make_shared(AHBplayerAccount, std::move(accountName), nullptr, SEC_PLAYER, sWorld->getIntConfig(CONFIG_EXPANSION), 0, LOCALE_enUS, 0, false, true, 0); + + std::shared_ptr playerBot(new Player(session.get()), [](Player* ptr) + { + ObjectAccessor::RemoveObject(ptr); + delete ptr; + }); - std::string accountName = "AuctionHouseBot" + std::to_string(AHBplayerAccount); + playerBot->Initialize(AHBplayerGUID); - WorldSession _session(AHBplayerAccount, std::move(accountName), nullptr, SEC_PLAYER, sWorld->getIntConfig(CONFIG_EXPANSION), 0, LOCALE_enUS, 0, false, false, 0); - Player _AHBplayer(&_session); - _AHBplayer.Initialize(AHBplayerGUID); - ObjectAccessor::AddObject(&_AHBplayer); + ObjectAccessor::AddObject(playerBot.get()); + + Seconds newUpdate = GameTime::GetGameTime(); // Add New Bids if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) { - addNewAuctions(&_AHBplayer, &AllianceConfig); - if (((_newrun - _lastrun_a) >= (AllianceConfig.GetBiddingInterval() * MINUTE)) && (AllianceConfig.GetBidsPerInterval() > 0)) + AddNewAuctions(playerBot.get(), &AllianceConfig); + if ((newUpdate - _lastUpdateAlliance >= AllianceConfig.GetBiddingInterval()) && AllianceConfig.GetBidsPerInterval() > 0) { - //if (debug_Out) sLog->outError( "AHBuyer: %u seconds have passed since last bid", (_newrun - _lastrun_a)); - //if (debug_Out) sLog->outError( "AHBuyer: Bidding on Alliance Auctions"); - addNewAuctionBuyerBotBid(&_AHBplayer, &AllianceConfig, &_session); - _lastrun_a = _newrun; + LOG_DEBUG("module.ahbot", "AHBuyer: {} seconds have passed since last bid", newUpdate.count() - _lastUpdateAlliance.count()); + LOG_DEBUG("module.ahbot", "AHBuyer: Bidding on Alliance Auctions"); + AddNewAuctionBuyerBotBid(playerBot, session, &AllianceConfig); + _lastUpdateAlliance = newUpdate; } - addNewAuctions(&_AHBplayer, &HordeConfig); - if (((_newrun - _lastrun_h) >= (HordeConfig.GetBiddingInterval() * MINUTE)) && (HordeConfig.GetBidsPerInterval() > 0)) + AddNewAuctions(playerBot.get(), &HordeConfig); + if ((newUpdate - _lastUpdateHorde >= HordeConfig.GetBiddingInterval()) && HordeConfig.GetBidsPerInterval() > 0) { - //if (debug_Out) sLog->outError( "AHBuyer: %u seconds have passed since last bid", (_newrun - _lastrun_h)); - //if (debug_Out) sLog->outError( "AHBuyer: Bidding on Horde Auctions"); - addNewAuctionBuyerBotBid(&_AHBplayer, &HordeConfig, &_session); - _lastrun_h = _newrun; + LOG_DEBUG("module.ahbot", "AHBuyer: {} seconds have passed since last bid", newUpdate.count() - _lastUpdateHorde.count()); + LOG_DEBUG("module.ahbot", "AHBuyer: Bidding on Horde Auctions"); + AddNewAuctionBuyerBotBid(playerBot, session, &HordeConfig); + _lastUpdateHorde = newUpdate; } } - addNewAuctions(&_AHBplayer, &NeutralConfig); - if (((_newrun - _lastrun_n) >= (NeutralConfig.GetBiddingInterval() * MINUTE)) && (NeutralConfig.GetBidsPerInterval() > 0)) + AddNewAuctions(playerBot.get(), &NeutralConfig); + if ((newUpdate - _lastUpdateNeutral >= NeutralConfig.GetBiddingInterval()) && NeutralConfig.GetBidsPerInterval() > 0) { - //if (debug_Out) sLog->outError( "AHBuyer: %u seconds have passed since last bid", (_newrun - _lastrun_n)); - //if (debug_Out) sLog->outError( "AHBuyer: Bidding on Neutral Auctions"); - addNewAuctionBuyerBotBid(&_AHBplayer, &NeutralConfig, &_session); - _lastrun_n = _newrun; + LOG_DEBUG("module.ahbot", "AHBuyer: {} seconds have passed since last bid", newUpdate.count() - _lastUpdateNeutral.count()); + LOG_DEBUG("module.ahbot", "AHBuyer: Bidding on Neutral Auctions"); + AddNewAuctionBuyerBotBid(playerBot, session, &NeutralConfig); + _lastUpdateNeutral = newUpdate; } - ObjectAccessor::RemoveObject(&_AHBplayer); + + ProcessQueryCallbacks(); } void AuctionHouseBot::Initialize() @@ -755,37 +520,37 @@ void AuctionHouseBot::Initialize() do { Field* fields = result->Fetch(); - DisableItemStore.insert(fields[0].Get()); + DisableItemStore.emplace(fields[0].Get()); } while (result->NextRow()); } - //End Filters + // End Filters if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) { LoadValues(&AllianceConfig); LoadValues(&HordeConfig); } + LoadValues(&NeutralConfig); // // check if the AHBot account/GUID in the config actually exists // - if ((AHBplayerAccount != 0) || (AHBplayerGUID != 0)) + if (AHBplayerAccount || AHBplayerGUID) { 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; + LOG_ERROR("module", "AuctionHouseBot: The account/GUID-information set for your AHBot is incorrect (account: {} guid: {})", AHBplayerAccount, AHBplayerGUID); + return; } } if (AHBSeller) { - QueryResult results = QueryResult(NULL); - char npcQuery[] = "SELECT distinct item FROM npc_vendor"; - results = WorldDatabase.Query(npcQuery); + std::string npcQuery = "SELECT distinct item FROM npc_vendor"; + QueryResult results = WorldDatabase.Query(npcQuery); if (results) { do @@ -796,12 +561,9 @@ void AuctionHouseBot::Initialize() } while (results->NextRow()); } else - { - if (debug_Out) - LOG_ERROR("module", "AuctionHouseBot: \"{}\" failed", npcQuery); - } + LOG_ERROR("module.ahbot", "AuctionHouseBot: \"{}\" failed", npcQuery); - char lootQuery[] = "SELECT item FROM creature_loot_template UNION " + std::string lootQuery = "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 " @@ -823,15 +585,11 @@ void AuctionHouseBot::Initialize() } while (results->NextRow()); } else - { - if (debug_Out) - LOG_ERROR("module", "AuctionHouseBot: \"{}\" failed", lootQuery); - } + LOG_ERROR("module.ahbot", "AuctionHouseBot: \"{}\" failed", lootQuery); - ItemTemplateContainer const* its = sObjectMgr->GetItemTemplateStore(); - for (ItemTemplateContainer::const_iterator itr = its->begin(); itr != its->end(); ++itr) + for (auto const& [itemID, itemTemplate] : *sObjectMgr->GetItemTemplateStore()) { - switch (itr->second.Bonding) + switch (itemTemplate.Bonding) { case NO_BIND: if (!No_Bind) @@ -860,25 +618,25 @@ void AuctionHouseBot::Initialize() if (SellMethod) { - if (itr->second.BuyPrice == 0) + if (!itemTemplate.BuyPrice) continue; } else { - if (itr->second.SellPrice == 0) + if (!itemTemplate.SellPrice) continue; } - if (itr->second.Quality > 6) + if (itemTemplate.Quality > ITEM_QUALITY_ARTIFACT) continue; - if ((Vendor_Items == 0) && !(itr->second.Class == ITEM_CLASS_TRADE_GOODS)) + if (!Vendor_Items && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) { bool isVendorItem = false; for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorItem); i++) { - if (itr->second.ItemId == npcItems[i]) + if (itemTemplate.ItemId == npcItems[i]) isVendorItem = true; } @@ -886,13 +644,13 @@ void AuctionHouseBot::Initialize() continue; } - if ((Vendor_TGs == 0) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS)) + if (!Vendor_TGs && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) { bool isVendorTG = false; for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorTG); i++) { - if (itr->second.ItemId == npcItems[i]) + if (itemTemplate.ItemId == npcItems[i]) isVendorTG = true; } @@ -900,13 +658,13 @@ void AuctionHouseBot::Initialize() continue; } - if ((Loot_Items == 0) && !(itr->second.Class == ITEM_CLASS_TRADE_GOODS)) + if (!Loot_Items && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) { bool isLootItem = false; for (unsigned int i = 0; (i < lootItems.size()) && (!isLootItem); i++) { - if (itr->second.ItemId == lootItems[i]) + if (itemTemplate.ItemId == lootItems[i]) isLootItem = true; } @@ -914,13 +672,13 @@ void AuctionHouseBot::Initialize() continue; } - if ((Loot_TGs == 0) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS)) + if (!Loot_TGs && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) { bool isLootTG = false; for (unsigned int i = 0; (i < lootItems.size()) && (!isLootTG); i++) { - if (itr->second.ItemId == lootItems[i]) + if (itemTemplate.ItemId == lootItems[i]) isLootTG = true; } @@ -928,428 +686,337 @@ void AuctionHouseBot::Initialize() continue; } - if ((Other_Items == 0) && !(itr->second.Class == ITEM_CLASS_TRADE_GOODS)) + if (Other_Items && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) { bool isVendorItem = false; bool isLootItem = false; for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorItem); i++) { - if (itr->second.ItemId == npcItems[i]) + if (itemTemplate.ItemId == npcItems[i]) isVendorItem = true; } + for (unsigned int i = 0; (i < lootItems.size()) && (!isLootItem); i++) { - if (itr->second.ItemId == lootItems[i]) + if (itemTemplate.ItemId == lootItems[i]) isLootItem = true; } - if ((!isLootItem) && (!isVendorItem)) + + if (!isLootItem && !isVendorItem) continue; } - if ((Other_TGs == 0) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS)) + if (Other_TGs && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) { bool isVendorTG = false; bool isLootTG = false; for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorTG); i++) { - if (itr->second.ItemId == npcItems[i]) + if (itemTemplate.ItemId == npcItems[i]) isVendorTG = true; } + for (unsigned int i = 0; (i < lootItems.size()) && (!isLootTG); i++) { - if (itr->second.ItemId == lootItems[i]) + if (itemTemplate.ItemId == lootItems[i]) isLootTG = true; } - if ((!isLootTG) && (!isVendorTG)) + + if (!isLootTG && !isVendorTG) continue; } // Disable items by Id - if (DisableItemStore.find(itr->second.ItemId) != DisableItemStore.end()) + if (DisableItemStore.find(itemTemplate.ItemId) != DisableItemStore.end()) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (PTR/Beta/Unused Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (PTR/Beta/Unused Item)", itemTemplate.ItemId); continue; } // Disable permanent enchants items - if ((DisablePermEnchant) && (itr->second.Class == ITEM_CLASS_PERMANENT)) + if (DisablePermEnchant && itemTemplate.Class == ITEM_CLASS_PERMANENT) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Permanent Enchant Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Permanent Enchant Item)", itemTemplate.ItemId); continue; } // Disable conjured items - if ((DisableConjured) && (itr->second.IsConjuredConsumable())) + if (DisableConjured && itemTemplate.IsConjuredConsumable()) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Conjured Consumable)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Conjured Consumable)", itemTemplate.ItemId); continue; } // Disable gems - if ((DisableGems) && (itr->second.Class == ITEM_CLASS_GEM)) + if (DisableGems && itemTemplate.Class == ITEM_CLASS_GEM) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Gem)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Gem)", itemTemplate.ItemId); continue; } // Disable money - if ((DisableMoney) && (itr->second.Class == ITEM_CLASS_MONEY)) + if (DisableMoney && itemTemplate.Class == ITEM_CLASS_MONEY) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Money)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Money)", itemTemplate.ItemId); continue; } // Disable moneyloot - if ((DisableMoneyLoot) && (itr->second.MinMoneyLoot > 0)) + if (DisableMoneyLoot && itemTemplate.MinMoneyLoot) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (MoneyLoot)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (MoneyLoot)", itemTemplate.ItemId); continue; } // Disable lootable items - if ((DisableLootable) && (itr->second.Flags & 4)) + if (DisableLootable && itemTemplate.Flags & 4) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Lootable Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Lootable Item)", itemTemplate.ItemId); continue; } // Disable Keys - if ((DisableKeys) && (itr->second.Class == ITEM_CLASS_KEY)) + if (DisableKeys && itemTemplate.Class == ITEM_CLASS_KEY) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Quest Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Quest Item)", itemTemplate.ItemId); continue; } // Disable items with duration - if ((DisableDuration) && (itr->second.Duration > 0)) + if (DisableDuration && itemTemplate.Duration) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Has a Duration)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Has a Duration)", itemTemplate.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 (DisableBOP_Or_Quest_NoReqLevel && ((itemTemplate.Bonding == BIND_WHEN_PICKED_UP || itemTemplate.Bonding == BIND_QUEST_ITEM) && (itemTemplate.RequiredLevel < itemTemplate.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); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (BOP or BQI and Required Level is less than Item Level)", itemTemplate.ItemId); continue; } // Disable items specifically for Warrior - if ((DisableWarriorItems) && (itr->second.AllowableClass == 1)) + if (DisableWarriorItems && itemTemplate.AllowableClass == 1) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Warrior Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Warrior Item)", itemTemplate.ItemId); continue; } // Disable items specifically for Paladin - if ((DisablePaladinItems) && (itr->second.AllowableClass == 2)) + if (DisablePaladinItems && itemTemplate.AllowableClass == 2) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Paladin Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Paladin Item)", itemTemplate.ItemId); continue; } // Disable items specifically for Hunter - if ((DisableHunterItems) && (itr->second.AllowableClass == 4)) + if (DisableHunterItems && itemTemplate.AllowableClass == 4) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Hunter Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Hunter Item)", itemTemplate.ItemId); continue; } // Disable items specifically for Rogue - if ((DisableRogueItems) && (itr->second.AllowableClass == 8)) + if (DisableRogueItems && itemTemplate.AllowableClass == 8) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Rogue Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Rogue Item)", itemTemplate.ItemId); continue; } // Disable items specifically for Priest - if ((DisablePriestItems) && (itr->second.AllowableClass == 16)) + if (DisablePriestItems && itemTemplate.AllowableClass == 16) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Priest Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Priest Item)", itemTemplate.ItemId); continue; } // Disable items specifically for DK - if ((DisableDKItems) && (itr->second.AllowableClass == 32)) + if (DisableDKItems && itemTemplate.AllowableClass == 32) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (DK Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (DK Item)", itemTemplate.ItemId); continue; } // Disable items specifically for Shaman - if ((DisableShamanItems) && (itr->second.AllowableClass == 64)) + if (DisableShamanItems && itemTemplate.AllowableClass == 64) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Shaman Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Shaman Item)", itemTemplate.ItemId); continue; } // Disable items specifically for Mage - if ((DisableMageItems) && (itr->second.AllowableClass == 128)) + if (DisableMageItems && itemTemplate.AllowableClass == 128) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Mage Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Mage Item)", itemTemplate.ItemId); continue; } // Disable items specifically for Warlock - if ((DisableWarlockItems) && (itr->second.AllowableClass == 256)) + if (DisableWarlockItems && itemTemplate.AllowableClass == 256) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Warlock Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Warlock Item)", itemTemplate.ItemId); continue; } // Disable items specifically for Unused Class - if ((DisableUnusedClassItems) && (itr->second.AllowableClass == 512)) + if (DisableUnusedClassItems && itemTemplate.AllowableClass == 512) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Unused Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Unused Item)", itemTemplate.ItemId); continue; } // Disable items specifically for Druid - if ((DisableDruidItems) && (itr->second.AllowableClass == 1024)) + if (DisableDruidItems && itemTemplate.AllowableClass == 1024) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Druid Item)", itr->second.ItemId); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Druid Item)", itemTemplate.ItemId); continue; } - // Disable Items below level X - if ((DisableItemsBelowLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel < DisableItemsBelowLevel)) + // Disable Items below level X + if (DisableItemsBelowLevel && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemLevel < DisableItemsBelowLevel) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); continue; } // Disable Items above level X - if ((DisableItemsAboveLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel > DisableItemsAboveLevel)) + if (DisableItemsAboveLevel && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemLevel > DisableItemsAboveLevel) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); continue; } - // Disable Trade Goods below level X - if ((DisableTGsBelowLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel < DisableTGsBelowLevel)) + // Disable Trade Goods below level X + if (DisableTGsBelowLevel && itemTemplate.Class == ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemLevel < DisableTGsBelowLevel) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); continue; } - // Disable Trade Goods above level X - if ((DisableTGsAboveLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel > DisableTGsAboveLevel)) + // Disable Trade Goods above level X + if (DisableTGsAboveLevel && itemTemplate.Class == ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemLevel > DisableTGsAboveLevel) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); continue; } // Disable Items below GUID X - if ((DisableItemsBelowGUID) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId < DisableItemsBelowGUID)) + if (DisableItemsBelowGUID && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemId < DisableItemsBelowGUID) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); continue; } // Disable Items above GUID X - if ((DisableItemsAboveGUID) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId > DisableItemsAboveGUID)) + if (DisableItemsAboveGUID && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemId > DisableItemsAboveGUID) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); continue; } // Disable Trade Goods below GUID X - if ((DisableTGsBelowGUID) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId < DisableTGsBelowGUID)) + if (DisableTGsBelowGUID && itemTemplate.Class == ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemId < DisableTGsBelowGUID) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); continue; } // Disable Trade Goods above GUID X - if ((DisableTGsAboveGUID) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId > DisableTGsAboveGUID)) + if (DisableTGsAboveGUID && itemTemplate.Class == ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemId > DisableTGsAboveGUID) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); continue; } // Disable Items for level lower than X - if ((DisableItemsBelowReqLevel) && (itr->second.RequiredLevel < DisableItemsBelowReqLevel)) + if (DisableItemsBelowReqLevel && itemTemplate.RequiredLevel < DisableItemsBelowReqLevel) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); continue; } // Disable Items for level higher than X - if ((DisableItemsAboveReqLevel) && (itr->second.RequiredLevel > DisableItemsAboveReqLevel)) + if (DisableItemsAboveReqLevel && itemTemplate.RequiredLevel > DisableItemsAboveReqLevel) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); continue; } // Disable Trade Goods for level lower than X - if ((DisableTGsBelowReqLevel) && (itr->second.RequiredLevel < DisableTGsBelowReqLevel)) + if (DisableTGsBelowReqLevel && itemTemplate.RequiredLevel < DisableTGsBelowReqLevel) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); continue; } // Disable Trade Goods for level higher than X - if ((DisableTGsAboveReqLevel) && (itr->second.RequiredLevel > DisableTGsAboveReqLevel)) + if (DisableTGsAboveReqLevel && itemTemplate.RequiredLevel > DisableTGsAboveReqLevel) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); continue; } // Disable Items that require skill lower than X - if ((DisableItemsBelowReqSkillRank) && (itr->second.RequiredSkillRank < DisableItemsBelowReqSkillRank)) + if (DisableItemsBelowReqSkillRank && itemTemplate.RequiredSkillRank < DisableItemsBelowReqSkillRank) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); continue; } // Disable Items that require skill higher than X - if ((DisableItemsAboveReqSkillRank) && (itr->second.RequiredSkillRank > DisableItemsAboveReqSkillRank)) + if (DisableItemsAboveReqSkillRank && itemTemplate.RequiredSkillRank > DisableItemsAboveReqSkillRank) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); continue; } // Disable Trade Goods that require skill lower than X - if ((DisableTGsBelowReqSkillRank) && (itr->second.RequiredSkillRank < DisableTGsBelowReqSkillRank)) + if (DisableTGsBelowReqSkillRank && itemTemplate.RequiredSkillRank < DisableTGsBelowReqSkillRank) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); continue; } // Disable Trade Goods that require skill higher than X - if ((DisableTGsAboveReqSkillRank) && (itr->second.RequiredSkillRank > DisableTGsAboveReqSkillRank)) + if (DisableTGsAboveReqSkillRank && itemTemplate.RequiredSkillRank > DisableTGsAboveReqSkillRank) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); continue; } - switch (itr->second.Quality) - { - case AHB_GREY: - if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) - greyTradeGoodsBin.push_back(itr->second.ItemId); - else - greyItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_WHITE: - if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) - whiteTradeGoodsBin.push_back(itr->second.ItemId); - else - whiteItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_GREEN: - if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) - greenTradeGoodsBin.push_back(itr->second.ItemId); - else - greenItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_BLUE: - if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) - blueTradeGoodsBin.push_back(itr->second.ItemId); - else - blueItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_PURPLE: - if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) - purpleTradeGoodsBin.push_back(itr->second.ItemId); - else - purpleItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_ORANGE: - if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) - orangeTradeGoodsBin.push_back(itr->second.ItemId); - else - orangeItemsBin.push_back(itr->second.ItemId); - break; - - case AHB_YELLOW: - if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) - yellowTradeGoodsBin.push_back(itr->second.ItemId); - else - yellowItemsBin.push_back(itr->second.ItemId); - break; - } + uint32 itemQualityIndexStart = itemTemplate.Class == ITEM_CLASS_TRADE_GOODS ? 0 : AHB_DEFAULT_QUALITY_SIZE; + _itemsBin[itemQualityIndexStart + itemTemplate.Quality].emplace_back(itemTemplate.ItemId); } - 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)) + std::size_t totalItems = 0; + for (auto const& itr : _itemsBin) + totalItems += itr.size(); + + if (!totalItems) { - LOG_ERROR("module", "AuctionHouseBot: No items"); + LOG_ERROR("module.ahbot", "AuctionHouseBot: No items"); AHBSeller = 0; } - LOG_INFO("module", "AuctionHouseBot:"); - LOG_INFO("module", "{} disabled items", uint32(DisableItemStore.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.ahbot", "AuctionHouseBot:"); + LOG_INFO("module.ahbot", "{} disabled items", DisableItemStore.size()); + LOG_INFO("module.ahbot", "Loaded {} grey trade goods", _itemsBin[ITEM_QUALITY_POOR].size()); + LOG_INFO("module.ahbot", "Loaded {} white trade goods", _itemsBin[ITEM_QUALITY_NORMAL].size()); + LOG_INFO("module.ahbot", "Loaded {} green trade goods", _itemsBin[ITEM_QUALITY_UNCOMMON].size()); + LOG_INFO("module.ahbot", "Loaded {} blue trade goods", _itemsBin[ITEM_QUALITY_RARE].size()); + LOG_INFO("module.ahbot", "Loaded {} purple trade goods", _itemsBin[ITEM_QUALITY_EPIC].size()); + LOG_INFO("module.ahbot", "Loaded {} orange trade goods", _itemsBin[ITEM_QUALITY_LEGENDARY].size()); + LOG_INFO("module.ahbot", "Loaded {} yellow trade goods", _itemsBin[ITEM_QUALITY_ARTIFACT].size()); + LOG_INFO("module.ahbot", "Loaded {} grey items", _itemsBin[AHB_ITEM_QUALITY_POOR].size()); + LOG_INFO("module.ahbot", "Loaded {} white items", _itemsBin[AHB_ITEM_QUALITY_NORMAL].size()); + LOG_INFO("module.ahbot", "Loaded {} green items", _itemsBin[AHB_ITEM_QUALITY_UNCOMMON].size()); + LOG_INFO("module.ahbot", "Loaded {} blue items", _itemsBin[AHB_ITEM_QUALITY_RARE].size()); + LOG_INFO("module.ahbot", "Loaded {} purple items", _itemsBin[AHB_ITEM_QUALITY_EPIC].size()); + LOG_INFO("module.ahbot", "Loaded {} orange items", _itemsBin[AHB_ITEM_QUALITY_LEGENDARY].size()); + LOG_INFO("module.ahbot", "Loaded {} yellow items", _itemsBin[AHB_ITEM_QUALITY_ARTIFACT].size()); } LOG_INFO("module", "AuctionHouseBot and AuctionHouseBuyer have been loaded."); @@ -1357,9 +1024,6 @@ void AuctionHouseBot::Initialize() void AuctionHouseBot::InitializeConfiguration() { - debug_Out = sConfigMgr->GetOption("AuctionHouseBot.DEBUG", false); - debug_Out_Filters = sConfigMgr->GetOption("AuctionHouseBot.DEBUG_FILTERS", false); - AHBSeller = sConfigMgr->GetOption("AuctionHouseBot.EnableSeller", false); AHBBuyer = sConfigMgr->GetOption("AuctionHouseBot.EnableBuyer", false); SellMethod = sConfigMgr->GetOption("AuctionHouseBot.UseBuyPriceForSeller", false); @@ -1369,7 +1033,7 @@ void AuctionHouseBot::InitializeConfiguration() AHBplayerGUID = sConfigMgr->GetOption("AuctionHouseBot.GUID", 0); ItemsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.ItemsPerCycle", 200); - //Begin Filters + // Begin Filters Vendor_Items = sConfigMgr->GetOption("AuctionHouseBot.VendorItems", false); Loot_Items = sConfigMgr->GetOption("AuctionHouseBot.LootItems", true); @@ -1426,49 +1090,42 @@ void AuctionHouseBot::InitializeConfiguration() void AuctionHouseBot::IncrementItemCounts(AuctionEntry* ah) { - // from auctionhousehandler.cpp, creates auction pointer & player pointer - // 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()); + LOG_ERROR("module.ahbot", "AHBot: Item {} doesn't exist, perhaps bought already?", ah->item_guid.ToString()); return; } // get item prototype ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(ah->item_template); - AHBConfig *config; + AHBConfig* config = nullptr; AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(ah->GetHouseId()); if (!ahEntry) { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); + LOG_DEBUG("module.ahbot", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); config = &NeutralConfig; } else if (ahEntry->houseId == AUCTIONHOUSE_ALLIANCE) { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Alliance", ah->GetHouseId()); + LOG_DEBUG("module.ahbot", "AHBot: {} returned as House Faction. Alliance", ah->GetHouseId()); config = &AllianceConfig; } else if (ahEntry->houseId == AUCTIONHOUSE_HORDE) { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Horde", ah->GetHouseId()); + LOG_DEBUG("module.ahbot", "AHBot: {} returned as House Faction. Horde", ah->GetHouseId()); config = &HordeConfig; } else { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); + LOG_DEBUG("module.ahbot", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); config = &NeutralConfig; } - config->IncItemCounts(prototype->Class, prototype->Quality); + config->IncreaseItemCounts(prototype->Class, prototype->Quality); } void AuctionHouseBot::DecrementItemCounts(AuctionEntry* ah, uint32 itemEntry) @@ -1476,98 +1133,92 @@ void AuctionHouseBot::DecrementItemCounts(AuctionEntry* ah, uint32 itemEntry) // get item prototype ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(itemEntry); - AHBConfig *config; + AHBConfig* config = nullptr; AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(ah->GetHouseId()); if (!ahEntry) { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); + LOG_DEBUG("module.ahbot", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); config = &NeutralConfig; } else if (ahEntry->houseId == AUCTIONHOUSE_ALLIANCE) { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Alliance", ah->GetHouseId()); + LOG_DEBUG("module.ahbot", "AHBot: {} returned as House Faction. Alliance", ah->GetHouseId()); config = &AllianceConfig; } else if (ahEntry->houseId == AUCTIONHOUSE_HORDE) { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Horde", ah->GetHouseId()); + LOG_DEBUG("module.ahbot", "AHBot: {} returned as House Faction. Horde", ah->GetHouseId()); config = &HordeConfig; } else { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); + LOG_DEBUG("module.ahbot", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); config = &NeutralConfig; } - config->DecItemCounts(prototype->Class, prototype->Quality); + config->DecreaseItemCounts(prototype->Class, prototype->Quality); } void AuctionHouseBot::Commands(uint32 command, uint32 ahMapID, uint32 col, char* args) { - AHBConfig *config = NULL; + AHBConfig* config = nullptr; switch (ahMapID) { - case 2: + case AUCTIONHOUSE_ALLIANCE: config = &AllianceConfig; break; - case 6: + case AUCTIONHOUSE_HORDE: config = &HordeConfig; break; - case 7: + case AUCTIONHOUSE_NEUTRAL: config = &NeutralConfig; break; } + std::string color; switch (col) { - case AHB_GREY: + case ITEM_QUALITY_POOR: color = "grey"; break; - case AHB_WHITE: + case ITEM_QUALITY_NORMAL: color = "white"; break; - case AHB_GREEN: + case ITEM_QUALITY_UNCOMMON: color = "green"; break; - case AHB_BLUE: + case ITEM_QUALITY_RARE: color = "blue"; break; - case AHB_PURPLE: + case ITEM_QUALITY_EPIC: color = "purple"; break; - case AHB_ORANGE: + case ITEM_QUALITY_LEGENDARY: color = "orange"; break; - case AHB_YELLOW: + case ITEM_QUALITY_ARTIFACT: color = "yellow"; break; default: break; } + switch (command) { case 0: //ahexpire { - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); - - AuctionHouseObject::AuctionEntryMap::iterator itr; - itr = auctionHouse->GetAuctionsBegin(); + AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAuctionHouseFactionID()); - while (itr != auctionHouse->GetAuctionsEnd()) + for (auto const& [__, auction] : auctionHouse->GetAuctions()) { - if (itr->second->owner.GetCounter() == AHBplayerGUID) + if (auction->owner.GetCounter() == AHBplayerGUID) { - itr->second->expire_time = GameTime::GetGameTime().count(); - uint32 id = itr->second->Id; - uint32 expire_time = itr->second->expire_time; + auction->expire_time = GameTime::GetGameTime().count(); + uint32 id = auction->Id; + uint32 expire_time = auction->expire_time; CharacterDatabase.Execute("UPDATE auctionhouse SET time = '{}' WHERE id = '{}'", expire_time, id); } - ++itr; } } break; @@ -1623,6 +1274,11 @@ void AuctionHouseBot::Commands(uint32 command, uint32 ahMapID, uint32 col, char* uint32 orangei = (uint32) strtoul(param13, NULL, 0); uint32 yellowi = (uint32) strtoul(param14, NULL, 0); + std::array percentages = + { + greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi + }; + auto trans = WorldDatabase.BeginTransaction(); trans->Append("UPDATE mod_auctionhousebot SET percentgreytradegoods = '{}' WHERE auctionhouse = '{}'", greytg, ahMapID); trans->Append("UPDATE mod_auctionhousebot SET percentwhitetradegoods = '{}' WHERE auctionhouse = '{}'", whitetg, ahMapID); @@ -1639,7 +1295,7 @@ void AuctionHouseBot::Commands(uint32 command, uint32 ahMapID, uint32 col, char* trans->Append("UPDATE mod_auctionhousebot SET percentorangeitems = '{}' WHERE auctionhouse = '{}'", orangei, ahMapID); trans->Append("UPDATE mod_auctionhousebot SET percentyellowitems = '{}' WHERE auctionhouse = '{}'", yellowi, ahMapID); WorldDatabase.CommitTransaction(trans); - config->SetPercentages(greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi); + config->SetPercentages(percentages); } break; case 6: //min prices @@ -1695,7 +1351,7 @@ void AuctionHouseBot::Commands(uint32 command, uint32 ahMapID, uint32 col, char* char * param1 = strtok(args, " "); uint32 bidInterval = (uint32) strtoul(param1, NULL, 0); WorldDatabase.Execute("UPDATE mod_auctionhousebot SET buyerbiddinginterval = '{}' WHERE auctionhouse = '{}'", bidInterval, ahMapID); - config->SetBiddingInterval(bidInterval); + config->SetBiddingInterval(Minutes(bidInterval)); } break; case 13: //buyer bids per interval @@ -1711,232 +1367,270 @@ void AuctionHouseBot::Commands(uint32 command, uint32 ahMapID, uint32 col, char* } } -void AuctionHouseBot::LoadValues(AHBConfig *config) +void AuctionHouseBot::LoadValues(AHBConfig* config) { - if (debug_Out) - LOG_ERROR("module", "Start Settings for {} Auctionhouses:", WorldDatabase.Query("SELECT name FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); + LOG_DEBUG("module.ahbot", "Start Settings for Auctionhouses"); 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) + std::string selectColumns = "minitems, maxitems,"; // min/max + selectColumns.append("percentgreytradegoods, percentwhitetradegoods, percentgreentradegoods, percentbluetradegoods, percentpurpletradegoods, percentorangetradegoods, percentyellowtradegoods,"); // tg items + selectColumns.append("percentgreyitems, percentwhiteitems, percentgreenitems, percentblueitems, percentpurpleitems, percentorangeitems, percentyellowitems,"); // default items + selectColumns.append("minpricegrey, minpricewhite, minpricegreen, minpriceblue, minpricepurple, minpriceorange, minpriceyellow,"); // min price + selectColumns.append("maxpricegrey, maxpricewhite, maxpricegreen, maxpriceblue, maxpricepurple, maxpriceorange, maxpriceyellow,"); // max price + selectColumns.append("minbidpricegrey, minbidpricewhite, minbidpricegreen, minbidpriceblue, minbidpricepurple, minbidpriceorange, minbidpriceyellow,"); // min bid prices + selectColumns.append("maxbidpricegrey, maxbidpricewhite, maxbidpricegreen, maxbidpriceblue, maxbidpricepurple, maxbidpriceorange, maxbidpriceyellow,"); // max bid prices + selectColumns.append("maxstackgrey, maxstackwhite, maxstackgreen, maxstackblue, maxstackpurple, maxstackorange, maxstackyellow,"); // max bid prices + selectColumns.append("name"); // auction name + + auto result = WorldDatabase.Query("SELECT {} FROM mod_auctionhousebot WHERE auctionhouse = {}", selectColumns, config->GetAuctionHouseID()); + if (!result) { - LOG_ERROR("module", "minItems = {}", config->GetMinItems()); - LOG_ERROR("module", "maxItems = {}", config->GetMaxItems()); - LOG_ERROR("module", "percentGreyTradeGoods = {}", config->GetPercentages(AHB_GREY_TG)); - LOG_ERROR("module", "percentWhiteTradeGoods = {}", config->GetPercentages(AHB_WHITE_TG)); - LOG_ERROR("module", "percentGreenTradeGoods = {}", config->GetPercentages(AHB_GREEN_TG)); - LOG_ERROR("module", "percentBlueTradeGoods = {}", config->GetPercentages(AHB_BLUE_TG)); - LOG_ERROR("module", "percentPurpleTradeGoods = {}", config->GetPercentages(AHB_PURPLE_TG)); - LOG_ERROR("module", "percentOrangeTradeGoods = {}", config->GetPercentages(AHB_ORANGE_TG)); - LOG_ERROR("module", "percentYellowTradeGoods = {}", config->GetPercentages(AHB_YELLOW_TG)); - LOG_ERROR("module", "percentGreyItems = {}", config->GetPercentages(AHB_GREY_I)); - LOG_ERROR("module", "percentWhiteItems = {}", config->GetPercentages(AHB_WHITE_I)); - LOG_ERROR("module", "percentGreenItems = {}", config->GetPercentages(AHB_GREEN_I)); - LOG_ERROR("module", "percentBlueItems = {}", config->GetPercentages(AHB_BLUE_I)); - LOG_ERROR("module", "percentPurpleItems = {}", config->GetPercentages(AHB_PURPLE_I)); - LOG_ERROR("module", "percentOrangeItems = {}", config->GetPercentages(AHB_ORANGE_I)); - LOG_ERROR("module", "percentYellowItems = {}", config->GetPercentages(AHB_YELLOW_I)); - LOG_ERROR("module", "minPriceGrey = {}", config->GetMinPrice(AHB_GREY)); - LOG_ERROR("module", "maxPriceGrey = {}", config->GetMaxPrice(AHB_GREY)); - LOG_ERROR("module", "minPriceWhite = {}", config->GetMinPrice(AHB_WHITE)); - LOG_ERROR("module", "maxPriceWhite = {}", config->GetMaxPrice(AHB_WHITE)); - LOG_ERROR("module", "minPriceGreen = {}", config->GetMinPrice(AHB_GREEN)); - LOG_ERROR("module", "maxPriceGreen = {}", config->GetMaxPrice(AHB_GREEN)); - LOG_ERROR("module", "minPriceBlue = {}", config->GetMinPrice(AHB_BLUE)); - LOG_ERROR("module", "maxPriceBlue = {}", config->GetMaxPrice(AHB_BLUE)); - LOG_ERROR("module", "minPricePurple = {}", config->GetMinPrice(AHB_PURPLE)); - LOG_ERROR("module", "maxPricePurple = {}", config->GetMaxPrice(AHB_PURPLE)); - LOG_ERROR("module", "minPriceOrange = {}", config->GetMinPrice(AHB_ORANGE)); - LOG_ERROR("module", "maxPriceOrange = {}", config->GetMaxPrice(AHB_ORANGE)); - LOG_ERROR("module", "minPriceYellow = {}", config->GetMinPrice(AHB_YELLOW)); - LOG_ERROR("module", "maxPriceYellow = {}", config->GetMaxPrice(AHB_YELLOW)); - LOG_ERROR("module", "minBidPriceGrey = {}", config->GetMinBidPrice(AHB_GREY)); - LOG_ERROR("module", "maxBidPriceGrey = {}", config->GetMaxBidPrice(AHB_GREY)); - LOG_ERROR("module", "minBidPriceWhite = {}", config->GetMinBidPrice(AHB_WHITE)); - LOG_ERROR("module", "maxBidPriceWhite = {}", config->GetMaxBidPrice(AHB_WHITE)); - LOG_ERROR("module", "minBidPriceGreen = {}", config->GetMinBidPrice(AHB_GREEN)); - LOG_ERROR("module", "maxBidPriceGreen = {}", config->GetMaxBidPrice(AHB_GREEN)); - LOG_ERROR("module", "minBidPriceBlue = {}", config->GetMinBidPrice(AHB_BLUE)); - LOG_ERROR("module", "maxBidPriceBlue = {}", config->GetMinBidPrice(AHB_BLUE)); - LOG_ERROR("module", "minBidPricePurple = {}", config->GetMinBidPrice(AHB_PURPLE)); - LOG_ERROR("module", "maxBidPricePurple = {}", config->GetMaxBidPrice(AHB_PURPLE)); - LOG_ERROR("module", "minBidPriceOrange = {}", config->GetMinBidPrice(AHB_ORANGE)); - LOG_ERROR("module", "maxBidPriceOrange = {}", config->GetMaxBidPrice(AHB_ORANGE)); - LOG_ERROR("module", "minBidPriceYellow = {}", config->GetMinBidPrice(AHB_YELLOW)); - LOG_ERROR("module", "maxBidPriceYellow = {}", config->GetMaxBidPrice(AHB_YELLOW)); - LOG_ERROR("module", "maxStackGrey = {}", config->GetMaxStack(AHB_GREY)); - LOG_ERROR("module", "maxStackWhite = {}", config->GetMaxStack(AHB_WHITE)); - LOG_ERROR("module", "maxStackGreen = {}", config->GetMaxStack(AHB_GREEN)); - LOG_ERROR("module", "maxStackBlue = {}", config->GetMaxStack(AHB_BLUE)); - LOG_ERROR("module", "maxStackPurple = {}", config->GetMaxStack(AHB_PURPLE)); - LOG_ERROR("module", "maxStackOrange = {}", config->GetMaxStack(AHB_ORANGE)); - LOG_ERROR("module", "maxStackYellow = {}", config->GetMaxStack(AHB_YELLOW)); + LOG_ERROR("module.ahbot", "> Empty or invalid sql query for Auctionhouse: {}", config->GetAuctionHouseID()); + return; } - //AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntry(config->GetAHFID()); - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); + auto const& [minitems, maxitems, + percentgreytradegoods, percentwhitetradegoods, percentgreentradegoods, percentbluetradegoods, percentpurpletradegoods, percentorangetradegoods, percentyellowtradegoods, + percentgreyitems, percentwhiteitems, percentgreenitems, percentblueitems, percentpurpleitems, percentorangeitems, percentyellowitems, + minpricegrey, minpricewhite, minpricegreen, minpriceblue, minpricepurple, minpriceorange, minpriceyellow, + maxpricegrey, maxpricewhite, maxpricegreen, maxpriceblue, maxpricepurple, maxpriceorange, maxpriceyellow, + minbidpricegrey, minbidpricewhite, minbidpricegreen, minbidpriceblue, minbidpricepurple, minbidpriceorange, minbidpriceyellow, + maxbidpricegrey, maxbidpricewhite, maxbidpricegreen, maxbidpriceblue, maxbidpricepurple, maxbidpriceorange, maxbidpriceyellow, + maxstackgrey, maxstackwhite, maxstackgreen, maxstackblue, maxstackpurple, maxstackorange, maxstackyellow, + auctionName] + = result->FetchTuple(); + + // Load min and max items + config->SetMinItems(minitems); + config->SetMaxItems(maxitems); + + std::array percetages = { percentgreytradegoods, percentwhitetradegoods, percentgreentradegoods, percentbluetradegoods, percentpurpletradegoods, percentorangetradegoods, percentyellowtradegoods, + percentgreyitems, percentwhiteitems, percentgreenitems, percentblueitems, percentpurpleitems, percentorangeitems, percentyellowitems }; + + config->SetPercentages(percetages); + + // Load min and max prices + config->SetMinPrice(ITEM_QUALITY_POOR, minpricegrey); + config->SetMaxPrice(ITEM_QUALITY_POOR, maxpricegrey); + config->SetMinPrice(ITEM_QUALITY_NORMAL, minpricewhite); + config->SetMaxPrice(ITEM_QUALITY_NORMAL, maxpricewhite); + config->SetMinPrice(ITEM_QUALITY_UNCOMMON, minpricegreen); + config->SetMaxPrice(ITEM_QUALITY_UNCOMMON, maxpricegreen); + config->SetMinPrice(ITEM_QUALITY_RARE, minpriceblue); + config->SetMaxPrice(ITEM_QUALITY_RARE, maxpriceblue); + config->SetMinPrice(ITEM_QUALITY_EPIC, minpricepurple); + config->SetMaxPrice(ITEM_QUALITY_EPIC, maxpricepurple); + config->SetMinPrice(ITEM_QUALITY_LEGENDARY, minpriceorange); + config->SetMaxPrice(ITEM_QUALITY_LEGENDARY, maxpriceorange); + config->SetMinPrice(ITEM_QUALITY_ARTIFACT, minpriceyellow); + config->SetMaxPrice(ITEM_QUALITY_ARTIFACT, maxpriceyellow); + + // Load min and max bid prices + config->SetMinBidPrice(ITEM_QUALITY_POOR, minbidpricegrey); + config->SetMaxBidPrice(ITEM_QUALITY_POOR, maxbidpricegrey); + config->SetMinBidPrice(ITEM_QUALITY_NORMAL, minbidpricewhite); + config->SetMaxBidPrice(ITEM_QUALITY_NORMAL, maxbidpricewhite); + config->SetMinBidPrice(ITEM_QUALITY_UNCOMMON, minbidpricegreen); + config->SetMaxBidPrice(ITEM_QUALITY_UNCOMMON, maxbidpricegreen); + config->SetMinBidPrice(ITEM_QUALITY_RARE, minbidpriceblue); + config->SetMaxBidPrice(ITEM_QUALITY_RARE, maxbidpriceblue); + config->SetMinBidPrice(ITEM_QUALITY_EPIC, minbidpricepurple); + config->SetMaxBidPrice(ITEM_QUALITY_EPIC, maxbidpricepurple); + config->SetMinBidPrice(ITEM_QUALITY_LEGENDARY, minbidpriceorange); + config->SetMaxBidPrice(ITEM_QUALITY_LEGENDARY, maxbidpriceorange); + config->SetMinBidPrice(ITEM_QUALITY_ARTIFACT, minbidpriceyellow); + config->SetMaxBidPrice(ITEM_QUALITY_ARTIFACT, maxbidpriceyellow); + + // Load max stacks + config->SetMaxStack(ITEM_QUALITY_POOR, maxstackgrey); + config->SetMaxStack(ITEM_QUALITY_NORMAL, maxstackwhite); + config->SetMaxStack(ITEM_QUALITY_UNCOMMON, maxstackgreen); + config->SetMaxStack(ITEM_QUALITY_RARE, maxstackblue); + config->SetMaxStack(ITEM_QUALITY_EPIC, maxstackpurple); + config->SetMaxStack(ITEM_QUALITY_LEGENDARY, maxstackorange); + config->SetMaxStack(ITEM_QUALITY_ARTIFACT, maxstackyellow); + + LOG_DEBUG("module.ahbot", "minItems = {}", config->GetMinItems()); + LOG_DEBUG("module.ahbot", "maxItems = {}", config->GetMaxItems()); + LOG_DEBUG("module.ahbot", "percentGreyTradeGoods = {}", config->GetPercentages(ITEM_QUALITY_POOR)); + LOG_DEBUG("module.ahbot", "percentWhiteTradeGoods = {}", config->GetPercentages(ITEM_QUALITY_NORMAL)); + LOG_DEBUG("module.ahbot", "percentGreenTradeGoods = {}", config->GetPercentages(ITEM_QUALITY_UNCOMMON)); + LOG_DEBUG("module.ahbot", "percentBlueTradeGoods = {}", config->GetPercentages(ITEM_QUALITY_RARE)); + LOG_DEBUG("module.ahbot", "percentPurpleTradeGoods = {}", config->GetPercentages(ITEM_QUALITY_EPIC)); + LOG_DEBUG("module.ahbot", "percentOrangeTradeGoods = {}", config->GetPercentages(ITEM_QUALITY_LEGENDARY)); + LOG_DEBUG("module.ahbot", "percentYellowTradeGoods = {}", config->GetPercentages(ITEM_QUALITY_ARTIFACT)); + LOG_DEBUG("module.ahbot", "percentGreyItems = {}", config->GetPercentages(AHB_ITEM_QUALITY_POOR)); + LOG_DEBUG("module.ahbot", "percentWhiteItems = {}", config->GetPercentages(AHB_ITEM_QUALITY_NORMAL)); + LOG_DEBUG("module.ahbot", "percentGreenItems = {}", config->GetPercentages(AHB_ITEM_QUALITY_UNCOMMON)); + LOG_DEBUG("module.ahbot", "percentBlueItems = {}", config->GetPercentages(AHB_ITEM_QUALITY_RARE)); + LOG_DEBUG("module.ahbot", "percentPurpleItems = {}", config->GetPercentages(AHB_ITEM_QUALITY_EPIC)); + LOG_DEBUG("module.ahbot", "percentOrangeItems = {}", config->GetPercentages(AHB_ITEM_QUALITY_LEGENDARY)); + LOG_DEBUG("module.ahbot", "percentYellowItems = {}", config->GetPercentages(AHB_ITEM_QUALITY_ARTIFACT)); + LOG_DEBUG("module.ahbot", "minPriceGrey = {}", config->GetMinPrice(ITEM_QUALITY_POOR)); + LOG_DEBUG("module.ahbot", "maxPriceGrey = {}", config->GetMaxPrice(ITEM_QUALITY_POOR)); + LOG_DEBUG("module.ahbot", "minPriceWhite = {}", config->GetMinPrice(ITEM_QUALITY_NORMAL)); + LOG_DEBUG("module.ahbot", "maxPriceWhite = {}", config->GetMaxPrice(ITEM_QUALITY_NORMAL)); + LOG_DEBUG("module.ahbot", "minPriceGreen = {}", config->GetMinPrice(ITEM_QUALITY_UNCOMMON)); + LOG_DEBUG("module.ahbot", "maxPriceGreen = {}", config->GetMaxPrice(ITEM_QUALITY_UNCOMMON)); + LOG_DEBUG("module.ahbot", "minPriceBlue = {}", config->GetMinPrice(ITEM_QUALITY_RARE)); + LOG_DEBUG("module.ahbot", "maxPriceBlue = {}", config->GetMaxPrice(ITEM_QUALITY_RARE)); + LOG_DEBUG("module.ahbot", "minPricePurple = {}", config->GetMinPrice(ITEM_QUALITY_EPIC)); + LOG_DEBUG("module.ahbot", "maxPricePurple = {}", config->GetMaxPrice(ITEM_QUALITY_EPIC)); + LOG_DEBUG("module.ahbot", "minPriceOrange = {}", config->GetMinPrice(ITEM_QUALITY_LEGENDARY)); + LOG_DEBUG("module.ahbot", "maxPriceOrange = {}", config->GetMaxPrice(ITEM_QUALITY_LEGENDARY)); + LOG_DEBUG("module.ahbot", "minPriceYellow = {}", config->GetMinPrice(ITEM_QUALITY_ARTIFACT)); + LOG_DEBUG("module.ahbot", "maxPriceYellow = {}", config->GetMaxPrice(ITEM_QUALITY_ARTIFACT)); + LOG_DEBUG("module.ahbot", "minBidPriceGrey = {}", config->GetMinBidPrice(ITEM_QUALITY_POOR)); + LOG_DEBUG("module.ahbot", "maxBidPriceGrey = {}", config->GetMaxBidPrice(ITEM_QUALITY_POOR)); + LOG_DEBUG("module.ahbot", "minBidPriceWhite = {}", config->GetMinBidPrice(ITEM_QUALITY_NORMAL)); + LOG_DEBUG("module.ahbot", "maxBidPriceWhite = {}", config->GetMaxBidPrice(ITEM_QUALITY_NORMAL)); + LOG_DEBUG("module.ahbot", "minBidPriceGreen = {}", config->GetMinBidPrice(ITEM_QUALITY_UNCOMMON)); + LOG_DEBUG("module.ahbot", "maxBidPriceGreen = {}", config->GetMaxBidPrice(ITEM_QUALITY_UNCOMMON)); + LOG_DEBUG("module.ahbot", "minBidPriceBlue = {}", config->GetMinBidPrice(ITEM_QUALITY_RARE)); + LOG_DEBUG("module.ahbot", "maxBidPriceBlue = {}", config->GetMinBidPrice(ITEM_QUALITY_RARE)); + LOG_DEBUG("module.ahbot", "minBidPricePurple = {}", config->GetMinBidPrice(ITEM_QUALITY_EPIC)); + LOG_DEBUG("module.ahbot", "maxBidPricePurple = {}", config->GetMaxBidPrice(ITEM_QUALITY_EPIC)); + LOG_DEBUG("module.ahbot", "minBidPriceOrange = {}", config->GetMinBidPrice(ITEM_QUALITY_LEGENDARY)); + LOG_DEBUG("module.ahbot", "maxBidPriceOrange = {}", config->GetMaxBidPrice(ITEM_QUALITY_LEGENDARY)); + LOG_DEBUG("module.ahbot", "minBidPriceYellow = {}", config->GetMinBidPrice(ITEM_QUALITY_ARTIFACT)); + LOG_DEBUG("module.ahbot", "maxBidPriceYellow = {}", config->GetMaxBidPrice(ITEM_QUALITY_ARTIFACT)); + LOG_DEBUG("module.ahbot", "maxStackGrey = {}", config->GetMaxStack(ITEM_QUALITY_POOR)); + LOG_DEBUG("module.ahbot", "maxStackWhite = {}", config->GetMaxStack(ITEM_QUALITY_NORMAL)); + LOG_DEBUG("module.ahbot", "maxStackGreen = {}", config->GetMaxStack(ITEM_QUALITY_UNCOMMON)); + LOG_DEBUG("module.ahbot", "maxStackBlue = {}", config->GetMaxStack(ITEM_QUALITY_RARE)); + LOG_DEBUG("module.ahbot", "maxStackPurple = {}", config->GetMaxStack(ITEM_QUALITY_EPIC)); + LOG_DEBUG("module.ahbot", "maxStackOrange = {}", config->GetMaxStack(ITEM_QUALITY_LEGENDARY)); + LOG_DEBUG("module.ahbot", "maxStackYellow = {}", config->GetMaxStack(ITEM_QUALITY_ARTIFACT)); + + AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAuctionHouseFactionID()); config->ResetItemCounts(); uint32 auctions = auctionHouse->Getcount(); if (auctions) { - for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr) + for (auto const& [__, auction] : auctionHouse->GetAuctions()) { - AuctionEntry *Aentry = itr->second; - Item *item = sAuctionMgr->GetAItem(Aentry->item_guid); - if (item) + Item* item = sAuctionMgr->GetAItem(auction->item_guid); + if (!item) + continue; + + ItemTemplate const* prototype = item->GetTemplate(); + if (!prototype) + continue; + + switch (prototype->Quality) { - ItemTemplate const *prototype = item->GetTemplate(); - if (prototype) - { - switch (prototype->Quality) - { - case 0: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - config->IncItemCounts(AHB_GREY_TG); - else - config->IncItemCounts(AHB_GREY_I); - break; - case 1: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - config->IncItemCounts(AHB_WHITE_TG); - else - config->IncItemCounts(AHB_WHITE_I); - break; - case 2: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - config->IncItemCounts(AHB_GREEN_TG); - else - config->IncItemCounts(AHB_GREEN_I); - break; - case 3: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - config->IncItemCounts(AHB_BLUE_TG); - else - config->IncItemCounts(AHB_BLUE_I); - break; - case 4: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - config->IncItemCounts(AHB_PURPLE_TG); - else - config->IncItemCounts(AHB_PURPLE_I); - break; - case 5: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - config->IncItemCounts(AHB_ORANGE_TG); - else - config->IncItemCounts(AHB_ORANGE_I); - break; - case 6: - if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - config->IncItemCounts(AHB_YELLOW_TG); - else - config->IncItemCounts(AHB_YELLOW_I); - break; - } - } + case 0: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + config->IncreaseItemCounts(ITEM_QUALITY_POOR); + else + config->IncreaseItemCounts(AHB_ITEM_QUALITY_POOR); + break; + case 1: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + config->IncreaseItemCounts(ITEM_QUALITY_NORMAL); + else + config->IncreaseItemCounts(AHB_ITEM_QUALITY_NORMAL); + break; + case 2: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + config->IncreaseItemCounts(ITEM_QUALITY_UNCOMMON); + else + config->IncreaseItemCounts(AHB_ITEM_QUALITY_UNCOMMON); + break; + case 3: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + config->IncreaseItemCounts(ITEM_QUALITY_RARE); + else + config->IncreaseItemCounts(AHB_ITEM_QUALITY_RARE); + break; + case 4: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + config->IncreaseItemCounts(ITEM_QUALITY_EPIC); + else + config->IncreaseItemCounts(AHB_ITEM_QUALITY_EPIC); + break; + case 5: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + config->IncreaseItemCounts(ITEM_QUALITY_LEGENDARY); + else + config->IncreaseItemCounts(AHB_ITEM_QUALITY_LEGENDARY); + break; + case 6: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + config->IncreaseItemCounts(ITEM_QUALITY_ARTIFACT); + else + config->IncreaseItemCounts(AHB_ITEM_QUALITY_ARTIFACT); + break; } } } - if (debug_Out) - { - LOG_ERROR("module", "Current Settings for {} Auctionhouses:", WorldDatabase.Query("SELECT name FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); - LOG_ERROR("module", "Grey Trade Goods\t{}\tGrey Items\t{}", config->GetItemCounts(AHB_GREY_TG), config->GetItemCounts(AHB_GREY_I)); - LOG_ERROR("module", "White Trade Goods\t{}\tWhite Items\t{}", config->GetItemCounts(AHB_WHITE_TG), config->GetItemCounts(AHB_WHITE_I)); - LOG_ERROR("module", "Green Trade Goods\t{}\tGreen Items\t{}", config->GetItemCounts(AHB_GREEN_TG), config->GetItemCounts(AHB_GREEN_I)); - LOG_ERROR("module", "Blue Trade Goods\t{}\tBlue Items\t{}", config->GetItemCounts(AHB_BLUE_TG), config->GetItemCounts(AHB_BLUE_I)); - LOG_ERROR("module", "Purple Trade Goods\t{}\tPurple Items\t{}", config->GetItemCounts(AHB_PURPLE_TG), config->GetItemCounts(AHB_PURPLE_I)); - LOG_ERROR("module", "Orange Trade Goods\t{}\tOrange Items\t{}", config->GetItemCounts(AHB_ORANGE_TG), config->GetItemCounts(AHB_ORANGE_I)); - LOG_ERROR("module", "Yellow Trade Goods\t{}\tYellow Items\t{}", config->GetItemCounts(AHB_YELLOW_TG), config->GetItemCounts(AHB_YELLOW_I)); - } + LOG_DEBUG("module.ahbot", "Current Settings for {} Auctionhouses:", auctionName); + LOG_DEBUG("module.ahbot", "Grey Trade Goods\t{}\tGrey Items\t{}", config->GetItemCounts(ITEM_QUALITY_POOR), config->GetItemCounts(AHB_ITEM_QUALITY_POOR)); + LOG_DEBUG("module.ahbot", "White Trade Goods\t{}\tWhite Items\t{}", config->GetItemCounts(ITEM_QUALITY_NORMAL), config->GetItemCounts(AHB_ITEM_QUALITY_NORMAL)); + LOG_DEBUG("module.ahbot", "Green Trade Goods\t{}\tGreen Items\t{}", config->GetItemCounts(ITEM_QUALITY_UNCOMMON), config->GetItemCounts(AHB_ITEM_QUALITY_UNCOMMON)); + LOG_DEBUG("module.ahbot", "Blue Trade Goods\t{}\tBlue Items\t{}", config->GetItemCounts(ITEM_QUALITY_RARE), config->GetItemCounts(AHB_ITEM_QUALITY_RARE)); + LOG_DEBUG("module.ahbot", "Purple Trade Goods\t{}\tPurple Items\t{}", config->GetItemCounts(ITEM_QUALITY_EPIC), config->GetItemCounts(AHB_ITEM_QUALITY_EPIC)); + LOG_DEBUG("module.ahbot", "Orange Trade Goods\t{}\tOrange Items\t{}", config->GetItemCounts(ITEM_QUALITY_LEGENDARY), config->GetItemCounts(AHB_ITEM_QUALITY_LEGENDARY)); + LOG_DEBUG("module.ahbot", "Yellow Trade Goods\t{}\tYellow Items\t{}", config->GetItemCounts(ITEM_QUALITY_ARTIFACT), config->GetItemCounts(AHB_ITEM_QUALITY_ARTIFACT)); } + 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) + auto result = WorldDatabase.Query("SELECT buyerpricegrey, buyerpricewhite, buyerpricegreen, buyerpriceblue, buyerpricepurple, buyerpriceorange, buyerpriceyellow, buyerbiddinginterval, buyerbidsperinterval " + "FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAuctionHouseID()); + + if (!result) { - LOG_ERROR("module", "buyerPriceGrey = {}", config->GetBuyerPrice(AHB_GREY)); - LOG_ERROR("module", "buyerPriceWhite = {}", config->GetBuyerPrice(AHB_WHITE)); - LOG_ERROR("module", "buyerPriceGreen = {}", config->GetBuyerPrice(AHB_GREEN)); - LOG_ERROR("module", "buyerPriceBlue = {}", config->GetBuyerPrice(AHB_BLUE)); - LOG_ERROR("module", "buyerPricePurple = {}", config->GetBuyerPrice(AHB_PURPLE)); - LOG_ERROR("module", "buyerPriceOrange = {}", config->GetBuyerPrice(AHB_ORANGE)); - LOG_ERROR("module", "buyerPriceYellow = {}", config->GetBuyerPrice(AHB_YELLOW)); - LOG_ERROR("module", "buyerBiddingInterval = {}", config->GetBiddingInterval()); - LOG_ERROR("module", "buyerBidsPerInterval = {}", config->GetBidsPerInterval()); + LOG_ERROR("module.ahbot", "> Empty or invalid sql query for Auctionhouse: {}", config->GetAuctionHouseID()); + return; } + + auto const& [buyerpricegrey, buyerpricewhite, buyerpricegreen, buyerpriceblue, buyerpricepurple, buyerpriceorange, buyerpriceyellow, + buyerbiddinginterval, buyerbidsperinterval] + = result->FetchTuple(); + + // Load buyer bid prices + config->SetBuyerPrice(ITEM_QUALITY_POOR, buyerpricegrey); + config->SetBuyerPrice(ITEM_QUALITY_NORMAL, buyerpricewhite); + config->SetBuyerPrice(ITEM_QUALITY_UNCOMMON, buyerpricegreen); + config->SetBuyerPrice(ITEM_QUALITY_RARE, buyerpriceblue); + config->SetBuyerPrice(ITEM_QUALITY_EPIC, buyerpricepurple); + config->SetBuyerPrice(ITEM_QUALITY_LEGENDARY, buyerpriceorange); + config->SetBuyerPrice(ITEM_QUALITY_ARTIFACT, buyerpriceyellow); + + // Load bidding interval + config->SetBiddingInterval(Minutes(buyerbiddinginterval)); + + // Load bids per interval + config->SetBidsPerInterval(buyerbidsperinterval); + + LOG_DEBUG("module.ahbot", "buyerPriceGrey = {}", config->GetBuyerPrice(ITEM_QUALITY_POOR)); + LOG_DEBUG("module.ahbot", "buyerPriceWhite = {}", config->GetBuyerPrice(ITEM_QUALITY_NORMAL)); + LOG_DEBUG("module.ahbot", "buyerPriceGreen = {}", config->GetBuyerPrice(ITEM_QUALITY_UNCOMMON)); + LOG_DEBUG("module.ahbot", "buyerPriceBlue = {}", config->GetBuyerPrice(ITEM_QUALITY_RARE)); + LOG_DEBUG("module.ahbot", "buyerPricePurple = {}", config->GetBuyerPrice(ITEM_QUALITY_EPIC)); + LOG_DEBUG("module.ahbot", "buyerPriceOrange = {}", config->GetBuyerPrice(ITEM_QUALITY_LEGENDARY)); + LOG_DEBUG("module.ahbot", "buyerPriceYellow = {}", config->GetBuyerPrice(ITEM_QUALITY_ARTIFACT)); + LOG_DEBUG("module.ahbot", "buyerBiddingInterval = {}", config->GetBiddingInterval().count()); + LOG_DEBUG("module.ahbot", "buyerBidsPerInterval = {}", config->GetBidsPerInterval()); } - if (debug_Out) - LOG_ERROR("module", "End Settings for {} Auctionhouses:", WorldDatabase.Query("SELECT name FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); + LOG_DEBUG("module.ahbot", "End Settings for Auctionhouses"); +} + +void AuctionHouseBot::ProcessQueryCallbacks() +{ + _queryProcessor.ProcessReadyCallbacks(); } diff --git a/src/AuctionHouseBot.h b/src/AuctionHouseBot.h index a091f7d..3566eea 100644 --- a/src/AuctionHouseBot.h +++ b/src/AuctionHouseBot.h @@ -1,1260 +1,140 @@ /* * Copyright (C) 2008-2010 Trinity - * Copyright (C) 2005-2009 MaNGOS +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . */ + #ifndef AUCTION_HOUSE_BOT_H #define AUCTION_HOUSE_BOT_H -#include "Common.h" #include "ObjectGuid.h" +#include "ItemTemplate.h" +#include "AuctionHouseBotConfig.h" +#include "DatabaseEnvFwd.h" +#include +#include struct AuctionEntry; class Player; class WorldSession; -#include "ItemTemplate.h" - -#define AHB_GREY 0 -#define AHB_WHITE 1 -#define AHB_GREEN 2 -#define AHB_BLUE 3 -#define AHB_PURPLE 4 -#define AHB_ORANGE 5 -#define AHB_YELLOW 6 -#define AHB_MAX_QUALITY 6 -#define AHB_GREY_TG 0 -#define AHB_WHITE_TG 1 -#define AHB_GREEN_TG 2 -#define AHB_BLUE_TG 3 -#define AHB_PURPLE_TG 4 -#define AHB_ORANGE_TG 5 -#define AHB_YELLOW_TG 6 -#define AHB_GREY_I 7 -#define AHB_WHITE_I 8 -#define AHB_GREEN_I 9 -#define AHB_BLUE_I 10 -#define AHB_PURPLE_I 11 -#define AHB_ORANGE_I 12 -#define AHB_YELLOW_I 13 - -class AHBConfig +class AuctionHouseBot { -private: - uint32 AHID; - uint32 AHFID; - uint32 minItems; - uint32 maxItems; - uint32 percentGreyTradeGoods; - uint32 percentWhiteTradeGoods; - uint32 percentGreenTradeGoods; - uint32 percentBlueTradeGoods; - uint32 percentPurpleTradeGoods; - uint32 percentOrangeTradeGoods; - uint32 percentYellowTradeGoods; - uint32 percentGreyItems; - uint32 percentWhiteItems; - uint32 percentGreenItems; - uint32 percentBlueItems; - uint32 percentPurpleItems; - uint32 percentOrangeItems; - uint32 percentYellowItems; - uint32 minPriceGrey; - uint32 maxPriceGrey; - uint32 minBidPriceGrey; - uint32 maxBidPriceGrey; - uint32 maxStackGrey; - uint32 minPriceWhite; - uint32 maxPriceWhite; - uint32 minBidPriceWhite; - uint32 maxBidPriceWhite; - uint32 maxStackWhite; - uint32 minPriceGreen; - uint32 maxPriceGreen; - uint32 minBidPriceGreen; - uint32 maxBidPriceGreen; - uint32 maxStackGreen; - uint32 minPriceBlue; - uint32 maxPriceBlue; - uint32 minBidPriceBlue; - uint32 maxBidPriceBlue; - uint32 maxStackBlue; - uint32 minPricePurple; - uint32 maxPricePurple; - uint32 minBidPricePurple; - uint32 maxBidPricePurple; - uint32 maxStackPurple; - uint32 minPriceOrange; - uint32 maxPriceOrange; - uint32 minBidPriceOrange; - uint32 maxBidPriceOrange; - uint32 maxStackOrange; - uint32 minPriceYellow; - uint32 maxPriceYellow; - uint32 minBidPriceYellow; - uint32 maxBidPriceYellow; - uint32 maxStackYellow; - - uint32 buyerPriceGrey; - uint32 buyerPriceWhite; - uint32 buyerPriceGreen; - uint32 buyerPriceBlue; - uint32 buyerPricePurple; - uint32 buyerPriceOrange; - uint32 buyerPriceYellow; - uint32 buyerBiddingInterval; - uint32 buyerBidsPerInterval; - - 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; - - uint32 greyTGoods; - uint32 whiteTGoods; - uint32 greenTGoods; - uint32 blueTGoods; - uint32 purpleTGoods; - uint32 orangeTGoods; - uint32 yellowTGoods; - - uint32 greyItems; - uint32 whiteItems; - uint32 greenItems; - uint32 blueItems; - uint32 purpleItems; - uint32 orangeItems; - uint32 yellowItems; - public: - AHBConfig(uint32 ahid) - { - AHID = ahid; - switch(ahid) - { - case 2: - AHFID = 55; - break; - case 6: - AHFID = 29; - break; - case 7: - AHFID = 120; - break; - default: - AHFID = 120; - break; - } - } - AHBConfig() - { - } - uint32 GetAHID() - { - return AHID; - } - uint32 GetAHFID() - { - return AHFID; - } - void SetMinItems(uint32 value) - { - minItems = value; - } - uint32 GetMinItems() - { - if ((minItems == 0) && (maxItems)) - return maxItems; - else if ((maxItems) && (minItems > maxItems)) - return maxItems; - else - return minItems; - } - void SetMaxItems(uint32 value) - { - maxItems = value; - // CalculatePercents() needs to be called, but only if - // SetPercentages() has been called at least once already. - } - uint32 GetMaxItems() - { - return maxItems; - } - 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 totalPercent = greytg + whitetg + greentg + bluetg + purpletg + orangetg + yellowtg + greyi + whitei + greeni + bluei + purplei + orangei + yellowi; - - if (totalPercent == 0) - { - maxItems = 0; - } - else if (totalPercent != 100) - { - greytg = 0; - whitetg = 27; - greentg = 12; - bluetg = 10; - purpletg = 1; - orangetg = 0; - yellowtg = 0; - greyi = 0; - whitei = 10; - greeni = 30; - bluei = 8; - purplei = 2; - orangei = 0; - yellowi = 0; - } - percentGreyTradeGoods = greytg; - percentWhiteTradeGoods = whitetg; - percentGreenTradeGoods = greentg; - percentBlueTradeGoods = bluetg; - percentPurpleTradeGoods = purpletg; - percentOrangeTradeGoods = orangetg; - percentYellowTradeGoods = yellowtg; - percentGreyItems = greyi; - percentWhiteItems = whitei; - percentGreenItems = greeni; - percentBlueItems = bluei; - percentPurpleItems = purplei; - percentOrangeItems = orangei; - percentYellowItems = yellowi; - CalculatePercents(); - } - uint32 GetPercentages(uint32 color) - { - switch(color) - { - case AHB_GREY_TG: - return percentGreyTradeGoods; - break; - case AHB_WHITE_TG: - return percentWhiteTradeGoods; - break; - case AHB_GREEN_TG: - return percentGreenTradeGoods; - break; - case AHB_BLUE_TG: - return percentBlueTradeGoods; - break; - case AHB_PURPLE_TG: - return percentPurpleTradeGoods; - break; - case AHB_ORANGE_TG: - return percentOrangeTradeGoods; - break; - case AHB_YELLOW_TG: - return percentYellowTradeGoods; - break; - case AHB_GREY_I: - return percentGreyItems; - break; - case AHB_WHITE_I: - return percentWhiteItems; - break; - case AHB_GREEN_I: - return percentGreenItems; - break; - case AHB_BLUE_I: - return percentBlueItems; - break; - case AHB_PURPLE_I: - return percentPurpleItems; - break; - case AHB_ORANGE_I: - return percentOrangeItems; - break; - case AHB_YELLOW_I: - return percentYellowItems; - break; - default: - return 0; - break; - } - } - void SetMinPrice(uint32 color, uint32 value) - { - switch(color) - { - case AHB_GREY: - minPriceGrey = value; - break; - case AHB_WHITE: - minPriceWhite = value; - break; - case AHB_GREEN: - minPriceGreen = value; - break; - case AHB_BLUE: - minPriceBlue = value; - break; - case AHB_PURPLE: - minPricePurple = value; - break; - case AHB_ORANGE: - minPriceOrange = value; - break; - case AHB_YELLOW: - minPriceYellow = value; - break; - default: - break; - } - } - uint32 GetMinPrice(uint32 color) - { - switch(color) - { - case AHB_GREY: - { - if (minPriceGrey == 0) - return 100; - else if (minPriceGrey > maxPriceGrey) - return maxPriceGrey; - else - return minPriceGrey; - break; - } - case AHB_WHITE: - { - if (minPriceWhite == 0) - return 150; - else if (minPriceWhite > maxPriceWhite) - return maxPriceWhite; - else - return minPriceWhite; - break; - } - case AHB_GREEN: - { - if (minPriceGreen == 0) - return 200; - else if (minPriceGreen > maxPriceGreen) - return maxPriceGreen; - else - return minPriceGreen; - break; - } - case AHB_BLUE: - { - if (minPriceBlue == 0) - return 250; - else if (minPriceBlue > maxPriceBlue) - return maxPriceBlue; - else - return minPriceBlue; - break; - } - case AHB_PURPLE: - { - if (minPricePurple == 0) - return 300; - else if (minPricePurple > maxPricePurple) - return maxPricePurple; - else - return minPricePurple; - break; - } - case AHB_ORANGE: - { - if (minPriceOrange == 0) - return 400; - else if (minPriceOrange > maxPriceOrange) - return maxPriceOrange; - else - return minPriceOrange; - break; - } - case AHB_YELLOW: - { - if (minPriceYellow == 0) - return 500; - else if (minPriceYellow > maxPriceYellow) - return maxPriceYellow; - else - return minPriceYellow; - break; - } - default: - { - return 0; - break; - } - } - } - void SetMaxPrice(uint32 color, uint32 value) - { - switch(color) - { - case AHB_GREY: - maxPriceGrey = value; - break; - case AHB_WHITE: - maxPriceWhite = value; - break; - case AHB_GREEN: - maxPriceGreen = value; - break; - case AHB_BLUE: - maxPriceBlue = value; - break; - case AHB_PURPLE: - maxPricePurple = value; - break; - case AHB_ORANGE: - maxPriceOrange = value; - break; - case AHB_YELLOW: - maxPriceYellow = value; - break; - default: - break; - } - } - uint32 GetMaxPrice(uint32 color) - { - switch(color) - { - case AHB_GREY: - { - if (maxPriceGrey == 0) - return 150; - else - return maxPriceGrey; - break; - } - case AHB_WHITE: - { - if (maxPriceWhite == 0) - return 250; - else - return maxPriceWhite; - break; - } - case AHB_GREEN: - { - if (maxPriceGreen == 0) - return 300; - else - return maxPriceGreen; - break; - } - case AHB_BLUE: - { - if (maxPriceBlue == 0) - return 350; - else - return maxPriceBlue; - break; - } - case AHB_PURPLE: - { - if (maxPricePurple == 0) - return 450; - else - return maxPricePurple; - break; - } - case AHB_ORANGE: - { - if (maxPriceOrange == 0) - return 550; - else - return maxPriceOrange; - break; - } - case AHB_YELLOW: - { - if (maxPriceYellow == 0) - return 650; - else - return maxPriceYellow; - break; - } - default: - { - return 0; - break; - } - } - } - void SetMinBidPrice(uint32 color, uint32 value) - { - switch(color) - { - case AHB_GREY: - minBidPriceGrey = value; - break; - case AHB_WHITE: - minBidPriceWhite = value; - break; - case AHB_GREEN: - minBidPriceGreen = value; - break; - case AHB_BLUE: - minBidPriceBlue = value; - break; - case AHB_PURPLE: - minBidPricePurple = value; - break; - case AHB_ORANGE: - minBidPriceOrange = value; - break; - case AHB_YELLOW: - minBidPriceYellow = value; - break; - default: - break; - } - } - uint32 GetMinBidPrice(uint32 color) - { - switch(color) - { - case AHB_GREY: - { - if (minBidPriceGrey > 100) - return 100; - else - return minBidPriceGrey; - break; - } - case AHB_WHITE: - { - if (minBidPriceWhite > 100) - return 100; - else - return minBidPriceWhite; - break; - } - case AHB_GREEN: - { - if (minBidPriceGreen > 100) - return 100; - else - return minBidPriceGreen; - break; - } - case AHB_BLUE: - { - if (minBidPriceBlue > 100) - return 100; - else - return minBidPriceBlue; - break; - } - case AHB_PURPLE: - { - if (minBidPricePurple > 100) - return 100; - else - return minBidPricePurple; - break; - } - case AHB_ORANGE: - { - if (minBidPriceOrange > 100) - return 100; - else - return minBidPriceOrange; - break; - } - case AHB_YELLOW: - { - if (minBidPriceYellow > 100) - return 100; - else - return minBidPriceYellow; - break; - } - default: - { - return 0; - break; - } - } - } - void SetMaxBidPrice(uint32 color, uint32 value) - { - switch(color) - { - case AHB_GREY: - maxBidPriceGrey = value; - break; - case AHB_WHITE: - maxBidPriceWhite = value; - break; - case AHB_GREEN: - maxBidPriceGreen = value; - break; - case AHB_BLUE: - maxBidPriceBlue = value; - break; - case AHB_PURPLE: - maxBidPricePurple = value; - break; - case AHB_ORANGE: - maxBidPriceOrange = value; - break; - case AHB_YELLOW: - maxBidPriceYellow = value; - break; - default: - break; - } - } - uint32 GetMaxBidPrice(uint32 color) - { - switch(color) - { - case AHB_GREY: - { - if (maxBidPriceGrey > 100) - return 100; - else - return maxBidPriceGrey; - break; - } - case AHB_WHITE: - { - if (maxBidPriceWhite > 100) - return 100; - else - return maxBidPriceWhite; - break; - } - case AHB_GREEN: - { - if (maxBidPriceGreen > 100) - return 100; - else - return maxBidPriceGreen; - break; - } - case AHB_BLUE: - { - if (maxBidPriceBlue > 100) - return 100; - else - return maxBidPriceBlue; - break; - } - case AHB_PURPLE: - { - if (maxBidPricePurple > 100) - return 100; - else - return maxBidPricePurple; - break; - } - case AHB_ORANGE: - { - if (maxBidPriceOrange > 100) - return 100; - else - return maxBidPriceOrange; - break; - } - case AHB_YELLOW: - { - if (maxBidPriceYellow > 100) - return 100; - else - return maxBidPriceYellow; - break; - } - default: - { - return 0; - break; - } - } - } - void SetMaxStack(uint32 color, uint32 value) - { - switch(color) - { - case AHB_GREY: - maxStackGrey = value; - break; - case AHB_WHITE: - maxStackWhite = value; - break; - case AHB_GREEN: - maxStackGreen = value; - break; - case AHB_BLUE: - maxStackBlue = value; - break; - case AHB_PURPLE: - maxStackPurple = value; - break; - case AHB_ORANGE: - maxStackOrange = value; - break; - case AHB_YELLOW: - maxStackYellow = value; - break; - default: - break; - } - } - uint32 GetMaxStack(uint32 color) - { - switch(color) - { - case AHB_GREY: - { - return maxStackGrey; - break; - } - case AHB_WHITE: - { - return maxStackWhite; - break; - } - case AHB_GREEN: - { - return maxStackGreen; - break; - } - case AHB_BLUE: - { - return maxStackBlue; - break; - } - case AHB_PURPLE: - { - return maxStackPurple; - break; - } - case AHB_ORANGE: - { - return maxStackOrange; - break; - } - case AHB_YELLOW: - { - return maxStackYellow; - break; - } - default: - { - return 0; - break; - } - } - } - void SetBuyerPrice(uint32 color, uint32 value) - { - switch(color) - { - case AHB_GREY: - buyerPriceGrey = value; - break; - case AHB_WHITE: - buyerPriceWhite = value; - break; - case AHB_GREEN: - buyerPriceGreen = value; - break; - case AHB_BLUE: - buyerPriceBlue = value; - break; - case AHB_PURPLE: - buyerPricePurple = value; - break; - case AHB_ORANGE: - buyerPriceOrange = value; - break; - case AHB_YELLOW: - buyerPriceYellow = value; - break; - default: - break; - } - } - uint32 GetBuyerPrice(uint32 color) - { - switch(color) - { - case AHB_GREY: - return buyerPriceGrey; - break; - case AHB_WHITE: - return buyerPriceWhite; - break; - case AHB_GREEN: - return buyerPriceGreen; - break; - case AHB_BLUE: - return buyerPriceBlue; - break; - case AHB_PURPLE: - return buyerPricePurple; - break; - case AHB_ORANGE: - return buyerPriceOrange; - break; - case AHB_YELLOW: - return buyerPriceYellow; - break; - default: - return 0; - break; - } - } - void SetBiddingInterval(uint32 value) - { - buyerBiddingInterval = value; - } - uint32 GetBiddingInterval() - { - return buyerBiddingInterval; - } - void CalculatePercents() - { - greytgp = (uint32) (((double)percentGreyTradeGoods / 100.0) * maxItems); - whitetgp = (uint32) (((double)percentWhiteTradeGoods / 100.0) * maxItems); - greentgp = (uint32) (((double)percentGreenTradeGoods / 100.0) * maxItems); - bluetgp = (uint32) (((double)percentBlueTradeGoods / 100.0) * maxItems); - purpletgp = (uint32) (((double)percentPurpleTradeGoods / 100.0) * maxItems); - orangetgp = (uint32) (((double)percentOrangeTradeGoods / 100.0) * maxItems); - yellowtgp = (uint32) (((double)percentYellowTradeGoods / 100.0) * maxItems); - greyip = (uint32) (((double)percentGreyItems / 100.0) * maxItems); - whiteip = (uint32) (((double)percentWhiteItems / 100.0) * maxItems); - greenip = (uint32) (((double)percentGreenItems / 100.0) * maxItems); - blueip = (uint32) (((double)percentBlueItems / 100.0) * maxItems); - purpleip = (uint32) (((double)percentPurpleItems / 100.0) * maxItems); - orangeip = (uint32) (((double)percentOrangeItems / 100.0) * maxItems); - yellowip = (uint32) (((double)percentYellowItems / 100.0) * maxItems); - uint32 total = greytgp + whitetgp + greentgp + bluetgp + purpletgp + orangetgp + yellowtgp + greyip + whiteip + greenip + blueip + purpleip + orangeip + yellowip; - int32 diff = (maxItems - total); - if (diff < 0) - { - if ((whiteip - diff) > 0) - whiteip -= diff; - else if ((greenip - diff) > 0) - greenip -= diff; - } - else if (diff < 0) - { - whiteip += diff; - } - } - uint32 GetPercents(uint32 color) - { - switch(color) - { - case AHB_GREY_TG: - return greytgp; - break; - case AHB_WHITE_TG: - return whitetgp; - break; - case AHB_GREEN_TG: - return greentgp; - break; - case AHB_BLUE_TG: - return bluetgp; - break; - case AHB_PURPLE_TG: - return purpletgp; - break; - case AHB_ORANGE_TG: - return orangetgp; - break; - case AHB_YELLOW_TG: - return yellowtgp; - break; - case AHB_GREY_I: - return greyip; - break; - case AHB_WHITE_I: - return whiteip; - break; - case AHB_GREEN_I: - return greenip; - break; - case AHB_BLUE_I: - return blueip; - break; - case AHB_PURPLE_I: - return purpleip; - break; - case AHB_ORANGE_I: - return orangeip; - break; - case AHB_YELLOW_I: - return yellowip; - break; - default: - return 0; - break; - } - } - - void DecItemCounts(uint32 Class, uint32 Quality) - { - switch(Class) - { - case ITEM_CLASS_TRADE_GOODS: - DecItemCounts(Quality); - break; - default: - DecItemCounts(Quality + 7); - break; - } - } - - void DecItemCounts(uint32 color) - { - switch(color) - { - case AHB_GREY_TG: - --greyTGoods; - break; - case AHB_WHITE_TG: - --whiteTGoods; - break; - case AHB_GREEN_TG: - --greenTGoods; - break; - case AHB_BLUE_TG: - --blueTGoods; - break; - case AHB_PURPLE_TG: - --purpleTGoods; - break; - case AHB_ORANGE_TG: - --orangeTGoods; - break; - case AHB_YELLOW_TG: - --yellowTGoods; - break; - case AHB_GREY_I: - --greyItems; - break; - case AHB_WHITE_I: - --whiteItems; - break; - case AHB_GREEN_I: - --greenItems; - break; - case AHB_BLUE_I: - --blueItems; - break; - case AHB_PURPLE_I: - --purpleItems; - break; - case AHB_ORANGE_I: - --orangeItems; - break; - case AHB_YELLOW_I: - --yellowItems; - break; - default: - break; - } - } - - void IncItemCounts(uint32 Class, uint32 Quality) - { - switch(Class) - { - case ITEM_CLASS_TRADE_GOODS: - IncItemCounts(Quality); - break; - default: - IncItemCounts(Quality + 7); - break; - } - } - - void IncItemCounts(uint32 color) - { - switch(color) - { - case AHB_GREY_TG: - ++greyTGoods; - break; - case AHB_WHITE_TG: - ++whiteTGoods; - break; - case AHB_GREEN_TG: - ++greenTGoods; - break; - case AHB_BLUE_TG: - ++blueTGoods; - break; - case AHB_PURPLE_TG: - ++purpleTGoods; - break; - case AHB_ORANGE_TG: - ++orangeTGoods; - break; - case AHB_YELLOW_TG: - ++yellowTGoods; - break; - case AHB_GREY_I: - ++greyItems; - break; - case AHB_WHITE_I: - ++whiteItems; - break; - case AHB_GREEN_I: - ++greenItems; - break; - case AHB_BLUE_I: - ++blueItems; - break; - case AHB_PURPLE_I: - ++purpleItems; - break; - case AHB_ORANGE_I: - ++orangeItems; - break; - case AHB_YELLOW_I: - ++yellowItems; - break; - default: - break; - } - } - - void ResetItemCounts() - { - 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; - } + AuctionHouseBot(); + ~AuctionHouseBot() = default; - uint32 TotalItemCounts() - { - return( - greyTGoods + - whiteTGoods + - greenTGoods + - blueTGoods + - purpleTGoods + - orangeTGoods + - yellowTGoods + + static AuctionHouseBot* instance(); - greyItems + - whiteItems + - greenItems + - blueItems + - purpleItems + - orangeItems + - yellowItems); - } + void Update(); + void Initialize(); + void InitializeConfiguration(); + void LoadValues(AHBConfig*); + void DecrementItemCounts(AuctionEntry* ah, uint32 itemEntry); + void IncrementItemCounts(AuctionEntry* ah); + void Commands(uint32, uint32, uint32, char*); + ObjectGuid::LowType GetAHBplayerGUID() { return AHBplayerGUID; }; - uint32 GetItemCounts(uint32 color) - { - switch(color) - { - case AHB_GREY_TG: - return greyTGoods; - break; - case AHB_WHITE_TG: - return whiteTGoods; - break; - case AHB_GREEN_TG: - return greenTGoods; - break; - case AHB_BLUE_TG: - return blueTGoods; - break; - case AHB_PURPLE_TG: - return purpleTGoods; - break; - case AHB_ORANGE_TG: - return orangeTGoods; - break; - case AHB_YELLOW_TG: - return yellowTGoods; - break; - case AHB_GREY_I: - return greyItems; - break; - case AHB_WHITE_I: - return whiteItems; - break; - case AHB_GREEN_I: - return greenItems; - break; - case AHB_BLUE_I: - return blueItems; - break; - case AHB_PURPLE_I: - return purpleItems; - break; - case AHB_ORANGE_I: - return orangeItems; - break; - case AHB_YELLOW_I: - return yellowItems; - break; - default: - return 0; - break; - } - } - void SetBidsPerInterval(uint32 value) - { - buyerBidsPerInterval = value; - } - uint32 GetBidsPerInterval() - { - return buyerBidsPerInterval; - } - ~AHBConfig() - { - } -}; -class AuctionHouseBot -{ private: - - bool debug_Out; - bool debug_Out_Filters; - - bool AHBSeller; - bool AHBBuyer; - bool BuyMethod; - bool SellMethod; + bool AHBSeller{ false }; + bool AHBBuyer{ false }; + bool BuyMethod{ false }; + bool SellMethod{ false }; uint32 AHBplayerAccount; ObjectGuid::LowType AHBplayerGUID; uint32 ItemsPerCycle; - //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; - - 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; - - //End Filters + bool Vendor_Items{ false }; + bool Loot_Items{ false }; + bool Other_Items{ false }; + bool Vendor_TGs{ false }; + bool Loot_TGs{ false }; + bool Other_TGs{ false }; + + bool No_Bind{ false }; + bool Bind_When_Picked_Up{ false }; + bool Bind_When_Equipped{ false }; + bool Bind_When_Use{ false }; + bool Bind_Quest_Item{ false }; + + bool DisablePermEnchant{ false }; + bool DisableConjured{ false }; + bool DisableGems{ false }; + bool DisableMoney{ false }; + bool DisableMoneyLoot{ false }; + bool DisableLootable{ false };; + bool DisableKeys{ false }; + bool DisableDuration{ false }; + bool DisableBOP_Or_Quest_NoReqLevel{ false }; + + bool DisableWarriorItems{ false }; + bool DisablePaladinItems{ false }; + bool DisableHunterItems{ false }; + bool DisableRogueItems{ false }; + bool DisablePriestItems{ false }; + bool DisableDKItems{ false }; + bool DisableShamanItems{ false }; + bool DisableMageItems{ false }; + bool DisableWarlockItems{ false }; + bool DisableUnusedClassItems{ false }; + bool DisableDruidItems{ false }; + + uint32 DisableItemsBelowLevel{ 0 }; + uint32 DisableItemsAboveLevel{ 0 }; + uint32 DisableTGsBelowLevel{ 0 }; + uint32 DisableTGsAboveLevel{ 0 }; + uint32 DisableItemsBelowGUID{ 0 }; + uint32 DisableItemsAboveGUID{ 0 }; + uint32 DisableTGsBelowGUID{ 0 }; + uint32 DisableTGsAboveGUID{ 0 }; + uint32 DisableItemsBelowReqLevel{ 0 }; + uint32 DisableItemsAboveReqLevel{ 0 }; + uint32 DisableTGsBelowReqLevel{ 0 }; + uint32 DisableTGsAboveReqLevel{ 0 }; + uint32 DisableItemsBelowReqSkillRank{ 0 }; + uint32 DisableItemsAboveReqSkillRank{ 0 }; + uint32 DisableTGsBelowReqSkillRank{ 0 }; + uint32 DisableTGsAboveReqSkillRank{ 0 }; + + std::unordered_set DisableItemStore{}; AHBConfig AllianceConfig; AHBConfig HordeConfig; AHBConfig NeutralConfig; - time_t _lastrun_a; - time_t _lastrun_h; - time_t _lastrun_n; + Seconds _lastUpdateAlliance{ 0s }; + Seconds _lastUpdateHorde{ 0s }; + Seconds _lastUpdateNeutral{ 0s }; + + std::array, AHB_MAX_QUALITY> _itemsBin{}; + std::vector npcItems{}; + std::vector lootItems{}; inline uint32 minValue(uint32 a, uint32 b) { return a <= b ? a : b; }; - void addNewAuctions(Player *AHBplayer, AHBConfig *config); - void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, WorldSession *session); + void AddNewAuctions(Player* AHBplayer, AHBConfig* config); + void AddNewAuctionBuyerBotBid(std::shared_ptr player, std::shared_ptr session, AHBConfig* config); + void AddNewAuctionBuyerBotBidCallback(std::shared_ptr player, std::shared_ptr session, std::shared_ptr config, QueryResult result); -// friend class ACE_Singleton; - AuctionHouseBot(); + void ProcessQueryCallbacks(); -public: - static AuctionHouseBot* instance() - { - static AuctionHouseBot instance; - return &instance; - } - - ~AuctionHouseBot(); - void Update(); - void Initialize(); - void InitializeConfiguration(); - void LoadValues(AHBConfig*); - void DecrementItemCounts(AuctionEntry* ah, uint32 itemEntry); - void IncrementItemCounts(AuctionEntry* ah); - void Commands(uint32, uint32, uint32, char*); - ObjectGuid::LowType GetAHBplayerGUID() { return AHBplayerGUID; }; + QueryCallbackProcessor _queryProcessor; }; -#define auctionbot AuctionHouseBot::instance() +#define sAHBot AuctionHouseBot::instance() #endif diff --git a/src/AuctionHouseBotConfig.cpp b/src/AuctionHouseBotConfig.cpp new file mode 100644 index 0000000..2c231c2 --- /dev/null +++ b/src/AuctionHouseBotConfig.cpp @@ -0,0 +1,318 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "AuctionHouseBotConfig.h" +#include "AuctionHouseMgr.h" +#include "ItemTemplate.h" +#include + +AHBConfig::AHBConfig(uint32 ahid) +{ + _auctionHouseID = ahid; + + switch (ahid) + { + case AUCTIONHOUSE_ALLIANCE: + _auctionHouseFactionID = 55; + break; + case AUCTIONHOUSE_HORDE: + _auctionHouseFactionID = 29; + break; + case AUCTIONHOUSE_NEUTRAL: + _auctionHouseFactionID = 120; + break; + default: + _auctionHouseFactionID = 120; + break; + } +} + +uint32 AHBConfig::GetMinItems() +{ + if (!_minItems && _maxItems) + return _maxItems; + else if (_maxItems && (_minItems > _maxItems)) + return _maxItems; + + return _minItems; +} + +void AHBConfig::SetPercentages(std::array& percentages) +{ + uint32 totalPercent = std::accumulate(percentages.begin(), percentages.end(), 0); + + if (totalPercent == 0) + { + _maxItems = 0; + } + else if (totalPercent != 100) + { + _itemsPercent[ITEM_QUALITY_POOR] = 0; + _itemsPercent[ITEM_QUALITY_NORMAL] = 27; + _itemsPercent[ITEM_QUALITY_UNCOMMON] = 12; + _itemsPercent[ITEM_QUALITY_RARE] = 10; + _itemsPercent[ITEM_QUALITY_EPIC] = 1; + _itemsPercent[ITEM_QUALITY_LEGENDARY] = 0; + _itemsPercent[ITEM_QUALITY_ARTIFACT] = 0; + + _itemsPercent[AHB_ITEM_QUALITY_POOR] = 0; + _itemsPercent[AHB_ITEM_QUALITY_NORMAL] = 10; + _itemsPercent[AHB_ITEM_QUALITY_UNCOMMON] = 30; + _itemsPercent[AHB_ITEM_QUALITY_RARE] = 8; + _itemsPercent[AHB_ITEM_QUALITY_EPIC] = 2; + _itemsPercent[AHB_ITEM_QUALITY_LEGENDARY] = 0; + _itemsPercent[AHB_ITEM_QUALITY_ARTIFACT] = 0; + } + + for (size_t i = 0; i < percentages.size(); i++) + _itemsPercent[i] = percentages[i]; + + CalculatePercents(); +} + +uint32 AHBConfig::GetPercentages(uint32 color) +{ + if (color > AHB_ITEM_QUALITY_ARTIFACT) + return 0; + + return _itemsPercent[color]; +} + +void AHBConfig::SetMinPrice(uint32 color, uint32 value) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return; + + _minPrice[color] = value; +} + +uint32 AHBConfig::GetMinPrice(uint32 color) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return 0; + + auto _GetMinPrice = [this, color](uint32 returnValue) + { + uint32 minPrice = _minPrice[color]; + uint32 maxPrice = _maxPrice[color]; + + if (!minPrice) + return returnValue; + else if (minPrice > maxPrice) + return maxPrice; + + return minPrice; + }; + + switch (color) + { + case ITEM_QUALITY_POOR: return _GetMinPrice(100); + case ITEM_QUALITY_NORMAL: return _GetMinPrice(150); + case ITEM_QUALITY_UNCOMMON: return _GetMinPrice(200); + case ITEM_QUALITY_RARE: return _GetMinPrice(250); + case ITEM_QUALITY_EPIC: return _GetMinPrice(300); + case ITEM_QUALITY_LEGENDARY: return _GetMinPrice(400); + case ITEM_QUALITY_ARTIFACT: return _GetMinPrice(500); + default: + return 0; + } +} + +void AHBConfig::SetMaxPrice(uint32 color, uint32 value) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return; + + _maxPrice[color] = value; +} + +uint32 AHBConfig::GetMaxPrice(uint32 color) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return 0; + + uint32 maxPrice = _maxPrice[color]; + + switch (color) + { + case ITEM_QUALITY_POOR: return !maxPrice ? 150 : maxPrice; + case ITEM_QUALITY_NORMAL: return !maxPrice ? 250 : maxPrice; + case ITEM_QUALITY_UNCOMMON: return !maxPrice ? 300 : maxPrice; + case ITEM_QUALITY_RARE: return !maxPrice ? 350 : maxPrice; + case ITEM_QUALITY_EPIC: return !maxPrice ? 450 : maxPrice; + case ITEM_QUALITY_LEGENDARY: return !maxPrice ? 550 : maxPrice; + case ITEM_QUALITY_ARTIFACT: return !maxPrice ? 650 : maxPrice; + default: + return 0; + } +} + +void AHBConfig::SetMinBidPrice(uint32 color, uint32 value) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return; + + _minBidPrice[color] = value; +} + +uint32 AHBConfig::GetMinBidPrice(uint32 color) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return 0; + + uint32 minBidPrice = _minBidPrice[color]; + return minBidPrice > 100 ? 100 : minBidPrice; +} + +void AHBConfig::SetMaxBidPrice(uint32 color, uint32 value) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return; + + _maxBidPrice[color] = value; +} + +uint32 AHBConfig::GetMaxBidPrice(uint32 color) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return 0; + + uint32 maxBidPrice = _maxBidPrice[color]; + return maxBidPrice > 100 ? 100 : maxBidPrice; +} + +void AHBConfig::SetMaxStack(uint32 color, uint32 value) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return; + + _maxStack[color] = value; +} + +uint32 AHBConfig::GetMaxStack(uint32 color) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return 0; + + return _maxStack[color]; +} + +void AHBConfig::SetBuyerPrice(uint32 color, uint32 value) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return; + + _buyerPrice[color] = value; +} + +uint32 AHBConfig::GetBuyerPrice(uint32 color) +{ + if (color >= AHB_DEFAULT_QUALITY_SIZE) + return 0; + + return _buyerPrice[color]; +} + +void AHBConfig::CalculatePercents() +{ + for (size_t i = 0; i < AHB_MAX_QUALITY; i++) + { + double itemPercent = _itemsPercent[i]; + _itemsPercentages[i] = uint32(itemPercent / 100 * _maxItems); + } + + uint32 totalPercent = std::accumulate(_itemsPercentages.begin(), _itemsPercentages.end(), 0); + int32 diff = (_maxItems - totalPercent); + + if (diff < 0) + { + if (_itemsPercentages[AHB_ITEM_QUALITY_NORMAL] - diff > 0) + _itemsPercentages[AHB_ITEM_QUALITY_NORMAL] -= diff; + else if (_itemsPercentages[AHB_ITEM_QUALITY_UNCOMMON] - diff > 0) + _itemsPercentages[AHB_ITEM_QUALITY_UNCOMMON] -= diff; + } + else if (diff < 0) + _itemsPercentages[AHB_ITEM_QUALITY_NORMAL] += diff; +} + +uint32 AHBConfig::GetPercents(uint32 color) +{ + if (color >= AHB_MAX_QUALITY) + return 0; + + return _itemsPercentages[color]; +} + +void AHBConfig::DecreaseItemCounts(uint32 Class, uint32 Quality) +{ + switch (Class) + { + case ITEM_CLASS_TRADE_GOODS: + DecreaseItemCounts(Quality); + break; + default: + DecreaseItemCounts(Quality + 7); + break; + } +} + +void AHBConfig::DecreaseItemCounts(uint32 color) +{ + if (color >= AHB_MAX_QUALITY) + return; + + _itemsCount[color]--; +} + +void AHBConfig::IncreaseItemCounts(uint32 Class, uint32 Quality) +{ + switch (Class) + { + case ITEM_CLASS_TRADE_GOODS: + IncreaseItemCounts(Quality); + break; + default: + IncreaseItemCounts(Quality + AHB_MAX_DEFAULT_QUALITY + 1); + break; + } +} + +void AHBConfig::IncreaseItemCounts(uint32 color) +{ + if (color >= AHB_MAX_QUALITY) + return; + + _itemsCount[color]++; +} + +void AHBConfig::ResetItemCounts() +{ + _itemsCount.fill(0); +} + +uint32 AHBConfig::TotalItemCounts() +{ + return std::accumulate(_itemsCount.begin(), _itemsCount.end(), 0); +} + +uint32 AHBConfig::GetItemCounts(uint32 color) +{ + if (color >= AHB_MAX_QUALITY) + return 0; + + return _itemsCount[color]; +} diff --git a/src/AuctionHouseBotConfig.h b/src/AuctionHouseBotConfig.h new file mode 100644 index 0000000..b47cb4f --- /dev/null +++ b/src/AuctionHouseBotConfig.h @@ -0,0 +1,169 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "Define.h" +#include "Duration.h" +#include + +enum AHItemQualities +{ + AHB_ITEM_QUALITY_POOR = 7, // GREY + AHB_ITEM_QUALITY_NORMAL, // WHITE + AHB_ITEM_QUALITY_UNCOMMON, // GREEN + AHB_ITEM_QUALITY_RARE, // BLUE + AHB_ITEM_QUALITY_EPIC, // PURPLE + AHB_ITEM_QUALITY_LEGENDARY, // ORANGE + AHB_ITEM_QUALITY_ARTIFACT, // LIGHT YELLOW +}; + +constexpr uint32 AHB_MAX_DEFAULT_QUALITY = 6; +constexpr uint32 AHB_DEFAULT_QUALITY_SIZE = AHB_MAX_DEFAULT_QUALITY + 1; +constexpr uint32 AHB_MAX_QUALITY = AHB_ITEM_QUALITY_ARTIFACT + 1; + +class AHBConfig +{ +public: + AHBConfig() = default; + ~AHBConfig() = default; + + AHBConfig(uint32 ahid); + + inline uint32 GetAuctionHouseID() + { + return _auctionHouseID; + } + + inline uint32 GetAuctionHouseFactionID() + { + return _auctionHouseFactionID; + } + + inline void SetMinItems(uint32 value) + { + _minItems = value; + } + + uint32 GetMinItems(); + + inline void SetMaxItems(uint32 value) + { + _maxItems = value; + // CalculatePercents() needs to be called, but only if + // SetPercentages() has been called at least once already. + } + + inline uint32 GetMaxItems() + { + return _maxItems; + } + + void SetPercentages(std::array& percentages); + + uint32 GetPercentages(uint32 color); + + void SetMinPrice(uint32 color, uint32 value); + + uint32 GetMinPrice(uint32 color); + + void SetMaxPrice(uint32 color, uint32 value); + + uint32 GetMaxPrice(uint32 color); + + void SetMinBidPrice(uint32 color, uint32 value); + + uint32 GetMinBidPrice(uint32 color); + + void SetMaxBidPrice(uint32 color, uint32 value); + + uint32 GetMaxBidPrice(uint32 color); + + void SetMaxStack(uint32 color, uint32 value); + + uint32 GetMaxStack(uint32 color); + + void SetBuyerPrice(uint32 color, uint32 value); + + uint32 GetBuyerPrice(uint32 color); + + inline void SetBiddingInterval(Minutes value) + { + _buyerBiddingInterval = value; + } + + inline Minutes GetBiddingInterval() + { + return _buyerBiddingInterval; + } + + void CalculatePercents(); + + uint32 GetPercents(uint32 color); + + inline std::array const* GetPercents() + { + return &_itemsPercentages; + } + + void DecreaseItemCounts(uint32 Class, uint32 Quality); + + void DecreaseItemCounts(uint32 color); + + void IncreaseItemCounts(uint32 Class, uint32 Quality); + + void IncreaseItemCounts(uint32 color); + + void ResetItemCounts(); + + uint32 TotalItemCounts(); + + uint32 GetItemCounts(uint32 color); + + inline std::array const* GetItemCounts() + { + return &_itemsCount; + } + + inline void SetBidsPerInterval(uint32 value) + { + _buyerBidsPerInterval = value; + } + + inline uint32 GetBidsPerInterval() + { + return _buyerBidsPerInterval; + } + +private: + uint32 _auctionHouseID{ 0 }; + uint32 _auctionHouseFactionID{ 0 }; + + uint32 _minItems{ 0 }; + uint32 _maxItems{ 0 }; + + Minutes _buyerBiddingInterval{ 0min }; + uint32 _buyerBidsPerInterval{ 0 }; + + std::array _itemsPercent{}; + std::array _itemsPercentages{}; + std::array _buyerPrice{}; + std::array _maxStack{}; + std::array _minBidPrice{}; + std::array _maxBidPrice{}; + std::array _minPrice{}; + std::array _maxPrice{}; + std::array _itemsCount{}; +}; diff --git a/src/AuctionHouseBotScript.cpp b/src/AuctionHouseBotScript.cpp index 19ef7c8..0d9ca73 100644 --- a/src/AuctionHouseBotScript.cpp +++ b/src/AuctionHouseBotScript.cpp @@ -1,6 +1,19 @@ /* - * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 -*/ + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ #include "ScriptMgr.h" #include "AuctionHouseBot.h" @@ -16,13 +29,13 @@ class AHBot_WorldScript : public WorldScript void OnBeforeConfigLoad(bool /*reload*/) override { - auctionbot->InitializeConfiguration(); + sAHBot->InitializeConfiguration(); } void OnStartup() override { LOG_INFO("server.loading", "Initialize AuctionHouseBot..."); - auctionbot->Initialize(); + sAHBot->Initialize(); } }; @@ -33,7 +46,7 @@ class AHBot_AuctionHouseScript : public AuctionHouseScript void OnBeforeAuctionHouseMgrSendAuctionSuccessfulMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* /*auction*/, Player* owner, uint32& /*owner_accId*/, uint32& /*profit*/, bool& sendNotification, bool& updateAchievementCriteria, bool& /*sendMail*/) override { - if (owner && owner->GetGUID().GetCounter() == auctionbot->GetAHBplayerGUID()) + if (owner && owner->GetGUID().GetCounter() == sAHBot->GetAHBplayerGUID()) { sendNotification = false; updateAchievementCriteria = false; @@ -42,29 +55,29 @@ class AHBot_AuctionHouseScript : public AuctionHouseScript void OnBeforeAuctionHouseMgrSendAuctionExpiredMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* /*auction*/, Player* owner, uint32& /*owner_accId*/, bool& sendNotification, bool& /*sendMail*/) override { - if (owner && owner->GetGUID().GetCounter() == auctionbot->GetAHBplayerGUID()) + if (owner && owner->GetGUID().GetCounter() == sAHBot->GetAHBplayerGUID()) sendNotification = false; } void OnBeforeAuctionHouseMgrSendAuctionOutbiddedMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* auction, Player* oldBidder, uint32& /*oldBidder_accId*/, Player* newBidder, uint32& newPrice, bool& /*sendNotification*/, bool& /*sendMail*/) override { if (oldBidder && !newBidder) - oldBidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, ObjectGuid::Create(auctionbot->GetAHBplayerGUID()), newPrice, auction->GetAuctionOutBid(), auction->item_template); + oldBidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, ObjectGuid::Create(sAHBot->GetAHBplayerGUID()), newPrice, auction->GetAuctionOutBid(), auction->item_template); } void OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionEntry* auction) override { - auctionbot->IncrementItemCounts(auction); + sAHBot->IncrementItemCounts(auction); } void OnAuctionRemove(AuctionHouseObject* /*ah*/, AuctionEntry* auction) override { - auctionbot->DecrementItemCounts(auction, auction->item_template); + sAHBot->DecrementItemCounts(auction, auction->item_template); } void OnBeforeAuctionHouseMgrUpdate() override { - auctionbot->Update(); + sAHBot->Update(); } }; @@ -75,7 +88,7 @@ class AHBot_MailScript : public MailScript void OnBeforeMailDraftSendMailTo(MailDraft* /*mailDraft*/, MailReceiver const& receiver, MailSender const& sender, MailCheckMask& /*checked*/, uint32& /*deliver_delay*/, uint32& /*custom_expiration*/, bool& deleteMailItemsFromDB, bool& sendMail) override { - if (receiver.GetPlayerGUIDLow() == auctionbot->GetAHBplayerGUID()) + if (receiver.GetPlayerGUIDLow() == sAHBot->GetAHBplayerGUID()) { if (sender.GetMailMessageType() == MAIL_AUCTION) // auction mail with items deleteMailItemsFromDB = true; diff --git a/src/AuctionHouseBot_loader.cpp b/src/AuctionHouseBot_loader.cpp new file mode 100644 index 0000000..65b98a8 --- /dev/null +++ b/src/AuctionHouseBot_loader.cpp @@ -0,0 +1,27 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +// From SC +void AddAHBotCommandScripts(); +void AddAHBotScripts(); + +// Add all +void Addmod_ah_botScripts() +{ + AddAHBotCommandScripts(); + AddAHBotScripts(); +} diff --git a/src/ah_bot_loader.cpp b/src/ah_bot_loader.cpp deleted file mode 100644 index 1344243..0000000 --- a/src/ah_bot_loader.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 - * Copyright (C) 2021+ WarheadCore - */ - -// From SC -void AddAHBotCommandScripts(); -void AddAHBotScripts(); - -// Add all -void Addmod_ah_botScripts() -{ - AddAHBotCommandScripts(); - AddAHBotScripts(); -} diff --git a/src/cs_ah_bot.cpp b/src/cs_ah_bot.cpp index 469f7b5..07d64a3 100644 --- a/src/cs_ah_bot.cpp +++ b/src/cs_ah_bot.cpp @@ -1,27 +1,20 @@ /* - * Copyright (C) 2008-2012 TrinityCore + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information * * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -/* ScriptData -Name: ah_bot_commandscript -%Complete: 100 -Comment: All ah_bot related commands -Category: commandscripts -EndScriptData */ - #include "ScriptMgr.h" #include "Chat.h" #include "AuctionHouseBot.h" @@ -104,7 +97,7 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(0, ahMapID, 0, NULL); + sAHBot->Commands(0, ahMapID, 0, NULL); } else if (strncmp(opt, "minitems", l) == 0) { @@ -115,7 +108,7 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(1, ahMapID, 0, param1); + sAHBot->Commands(1, ahMapID, 0, param1); } else if (strncmp(opt, "maxitems", l) == 0) { @@ -126,7 +119,7 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(2, ahMapID, 0, param1); + sAHBot->Commands(2, ahMapID, 0, param1); } else if (strncmp(opt, "mintime", l) == 0) { @@ -140,7 +133,7 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot.Commands(3, ahMapID, 0, param1); + sAHBot.Commands(3, ahMapID, 0, param1); */ } else if (strncmp(opt, "maxtime", l) == 0) @@ -155,7 +148,7 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot.Commands(4, ahMapID, 0, param1); + sAHBot.Commands(4, ahMapID, 0, param1); */ } else if (strncmp(opt, "percentages", l) == 0) @@ -240,7 +233,7 @@ class ah_bot_commandscript : public CommandScript strcat(param, param13); strcat(param, " "); strcat(param, param14); - auctionbot->Commands(5, ahMapID, 0, param); + sAHBot->Commands(5, ahMapID, 0, param); } else if (strncmp(opt, "minprice", l) == 0) { @@ -254,19 +247,19 @@ class ah_bot_commandscript : public CommandScript } if (strncmp(param1, "grey", l) == 0) - auctionbot->Commands(6, ahMapID, AHB_GREY, param2); + sAHBot->Commands(6, ahMapID, ITEM_QUALITY_POOR, param2); else if (strncmp(param1, "white", l) == 0) - auctionbot->Commands(6, ahMapID, AHB_WHITE, param2); + sAHBot->Commands(6, ahMapID, ITEM_QUALITY_NORMAL, param2); else if (strncmp(param1, "green", l) == 0) - auctionbot->Commands(6, ahMapID, AHB_GREEN, param2); + sAHBot->Commands(6, ahMapID, ITEM_QUALITY_UNCOMMON, param2); else if (strncmp(param1, "blue", l) == 0) - auctionbot->Commands(6, ahMapID, AHB_BLUE, param2); + sAHBot->Commands(6, ahMapID, ITEM_QUALITY_RARE, param2); else if (strncmp(param1, "purple", l) == 0) - auctionbot->Commands(6, ahMapID, AHB_PURPLE, param2); + sAHBot->Commands(6, ahMapID, ITEM_QUALITY_EPIC, param2); else if (strncmp(param1, "orange", l) == 0) - auctionbot->Commands(6, ahMapID, AHB_ORANGE, param2); + sAHBot->Commands(6, ahMapID, ITEM_QUALITY_LEGENDARY, param2); else if (strncmp(param1, "yellow", l) == 0) - auctionbot->Commands(6, ahMapID, AHB_YELLOW, param2); + sAHBot->Commands(6, ahMapID, ITEM_QUALITY_ARTIFACT, param2); else { handler->PSendSysMessage("Syntax is: ahbotoptions minprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); @@ -283,19 +276,19 @@ class ah_bot_commandscript : public CommandScript return false; } if (strncmp(param1, "grey", l) == 0) - auctionbot->Commands(7, ahMapID, AHB_GREY, param2); + sAHBot->Commands(7, ahMapID, ITEM_QUALITY_POOR, param2); else if (strncmp(param1, "white", l) == 0) - auctionbot->Commands(7, ahMapID, AHB_WHITE, param2); + sAHBot->Commands(7, ahMapID, ITEM_QUALITY_NORMAL, param2); else if (strncmp(param1, "green", l) == 0) - auctionbot->Commands(7, ahMapID, AHB_GREEN, param2); + sAHBot->Commands(7, ahMapID, ITEM_QUALITY_UNCOMMON, param2); else if (strncmp(param1, "blue", l) == 0) - auctionbot->Commands(7, ahMapID, AHB_BLUE, param2); + sAHBot->Commands(7, ahMapID, ITEM_QUALITY_RARE, param2); else if (strncmp(param1, "purple", l) == 0) - auctionbot->Commands(7, ahMapID, AHB_PURPLE, param2); + sAHBot->Commands(7, ahMapID, ITEM_QUALITY_EPIC, param2); else if (strncmp(param1, "orange",l) == 0) - auctionbot->Commands(7, ahMapID, AHB_ORANGE, param2); + sAHBot->Commands(7, ahMapID, ITEM_QUALITY_LEGENDARY, param2); else if (strncmp(param1, "yellow", l) == 0) - auctionbot->Commands(7, ahMapID, AHB_YELLOW, param2); + sAHBot->Commands(7, ahMapID, ITEM_QUALITY_ARTIFACT, param2); else { handler->PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); @@ -321,19 +314,19 @@ class ah_bot_commandscript : public CommandScript } if (strncmp(param1, "grey", l) == 0) - auctionbot->Commands(8, ahMapID, AHB_GREY, param2); + sAHBot->Commands(8, ahMapID, ITEM_QUALITY_POOR, param2); else if (strncmp(param1, "white", l) == 0) - auctionbot->Commands(8, ahMapID, AHB_WHITE, param2); + sAHBot->Commands(8, ahMapID, ITEM_QUALITY_NORMAL, param2); else if (strncmp(param1, "green", l) == 0) - auctionbot->Commands(8, ahMapID, AHB_GREEN, param2); + sAHBot->Commands(8, ahMapID, ITEM_QUALITY_UNCOMMON, param2); else if (strncmp(param1, "blue", l) == 0) - auctionbot->Commands(8, ahMapID, AHB_BLUE, param2); + sAHBot->Commands(8, ahMapID, ITEM_QUALITY_RARE, param2); else if (strncmp(param1, "purple", l) == 0) - auctionbot->Commands(8, ahMapID, AHB_PURPLE, param2); + sAHBot->Commands(8, ahMapID, ITEM_QUALITY_EPIC, param2); else if (strncmp(param1, "orange", l) == 0) - auctionbot->Commands(8, ahMapID, AHB_ORANGE, param2); + sAHBot->Commands(8, ahMapID, ITEM_QUALITY_LEGENDARY, param2); else if (strncmp(param1, "yellow", l) == 0) - auctionbot->Commands(8, ahMapID, AHB_YELLOW, param2); + sAHBot->Commands(8, ahMapID, ITEM_QUALITY_ARTIFACT, param2); else { handler->PSendSysMessage("Syntax is: ahbotoptions minbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); @@ -359,19 +352,19 @@ class ah_bot_commandscript : public CommandScript } if (strncmp(param1, "grey", l) == 0) - auctionbot->Commands(9, ahMapID, AHB_GREY, param2); + sAHBot->Commands(9, ahMapID, ITEM_QUALITY_POOR, param2); else if (strncmp(param1, "white", l) == 0) - auctionbot->Commands(9, ahMapID, AHB_WHITE, param2); + sAHBot->Commands(9, ahMapID, ITEM_QUALITY_NORMAL, param2); else if (strncmp(param1, "green", l) == 0) - auctionbot->Commands(9, ahMapID, AHB_GREEN, param2); + sAHBot->Commands(9, ahMapID, ITEM_QUALITY_UNCOMMON, param2); else if (strncmp(param1, "blue", l) == 0) - auctionbot->Commands(9, ahMapID, AHB_BLUE, param2); + sAHBot->Commands(9, ahMapID, ITEM_QUALITY_RARE, param2); else if (strncmp(param1, "purple", l) == 0) - auctionbot->Commands(9, ahMapID, AHB_PURPLE, param2); + sAHBot->Commands(9, ahMapID, ITEM_QUALITY_EPIC, param2); else if (strncmp(param1, " orange", l) == 0) - auctionbot->Commands(9, ahMapID, AHB_ORANGE, param2); + sAHBot->Commands(9, ahMapID, ITEM_QUALITY_LEGENDARY, param2); else if (strncmp(param1, "yellow", l) == 0) - auctionbot->Commands(9, ahMapID, AHB_YELLOW, param2); + sAHBot->Commands(9, ahMapID, ITEM_QUALITY_ARTIFACT, param2); else { handler->PSendSysMessage("Syntax is: ahbotoptions max bidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); @@ -397,19 +390,19 @@ class ah_bot_commandscript : public CommandScript // } if (strncmp(param1, "grey",l) == 0) - auctionbot->Commands(10, ahMapID, AHB_GREY, param2); + sAHBot->Commands(10, ahMapID, ITEM_QUALITY_POOR, param2); else if (strncmp(param1, "white", l) == 0) - auctionbot->Commands(10, ahMapID, AHB_WHITE, param2); + sAHBot->Commands(10, ahMapID, ITEM_QUALITY_NORMAL, param2); else if (strncmp(param1, "green", l) == 0) - auctionbot->Commands(10, ahMapID, AHB_GREEN, param2); + sAHBot->Commands(10, ahMapID, ITEM_QUALITY_UNCOMMON, param2); else if (strncmp(param1, "blue", l) == 0) - auctionbot->Commands(10, ahMapID, AHB_BLUE, param2); + sAHBot->Commands(10, ahMapID, ITEM_QUALITY_RARE, param2); else if (strncmp(param1, "purple", l) == 0) - auctionbot->Commands(10, ahMapID, AHB_PURPLE, param2); + sAHBot->Commands(10, ahMapID, ITEM_QUALITY_EPIC, param2); else if (strncmp(param1, "orange", l) == 0) - auctionbot->Commands(10, ahMapID, AHB_ORANGE, param2); + sAHBot->Commands(10, ahMapID, ITEM_QUALITY_LEGENDARY, param2); else if (strncmp(param1, "yellow", l) == 0) - auctionbot->Commands(10, ahMapID, AHB_YELLOW, param2); + sAHBot->Commands(10, ahMapID, ITEM_QUALITY_ARTIFACT, param2); else { handler->PSendSysMessage("Syntax is: ahbotoptions maxstack $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $value"); @@ -428,19 +421,19 @@ class ah_bot_commandscript : public CommandScript } if (strncmp(param1, "grey", l) == 0) - auctionbot->Commands(11, ahMapID, AHB_GREY, param2); + sAHBot->Commands(11, ahMapID, ITEM_QUALITY_POOR, param2); else if (strncmp(param1, "white", l) == 0) - auctionbot->Commands(11, ahMapID, AHB_WHITE, param2); + sAHBot->Commands(11, ahMapID, ITEM_QUALITY_NORMAL, param2); else if (strncmp(param1, "green", l) == 0) - auctionbot->Commands(11, ahMapID, AHB_GREEN, param2); + sAHBot->Commands(11, ahMapID, ITEM_QUALITY_UNCOMMON, param2); else if (strncmp(param1, "blue", l) == 0) - auctionbot->Commands(11, ahMapID, AHB_BLUE, param2); + sAHBot->Commands(11, ahMapID, ITEM_QUALITY_RARE, param2); else if (strncmp(param1, "purple", l) == 0) - auctionbot->Commands(11, ahMapID, AHB_PURPLE, param2); + sAHBot->Commands(11, ahMapID, ITEM_QUALITY_EPIC, param2); else if (strncmp(param1, "orange", l) == 0) - auctionbot->Commands(11, ahMapID, AHB_ORANGE, param2); + sAHBot->Commands(11, ahMapID, ITEM_QUALITY_LEGENDARY, param2); else if (strncmp(param1, "yellow", l) == 0) - auctionbot->Commands(11, ahMapID, AHB_YELLOW, param2); + sAHBot->Commands(11, ahMapID, ITEM_QUALITY_ARTIFACT, param2); else { handler->PSendSysMessage("Syntax is: ahbotoptions buyerprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue or purple) $price"); @@ -457,7 +450,7 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(12, ahMapID, 0, param1); + sAHBot->Commands(12, ahMapID, 0, param1); } else if (strncmp(opt, "bidsperinterval", l) == 0) { @@ -469,7 +462,7 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(13, ahMapID, 0, param1); + sAHBot->Commands(13, ahMapID, 0, param1); } else { From dad83c3e91ddbdfc3969a18dea4c97a9f7efdf1f Mon Sep 17 00:00:00 2001 From: Winfidonarleyan Date: Sat, 19 Mar 2022 13:46:53 +0700 Subject: [PATCH 2/4] chore(Core/Misc): code cleanup --- src/AuctionHouseBot.cpp | 1 - src/AuctionHouseBot.h | 1 - src/AuctionHouseBotConfig.h | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index e844740..21a2bb8 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -382,7 +382,6 @@ void AuctionHouseBot::AddNewAuctionBuyerBotBidCallback(std::shared_ptr p if ((currentprice + auction->GetAuctionOutBid()) > bidprice) bidprice = currentprice + auction->GetAuctionOutBid(); - LOG_DEBUG("module.ahbot", "-------------------------------------------------"); LOG_DEBUG("module.ahbot", "AHBuyer: Info for Auction #{}:", auction->Id); LOG_DEBUG("module.ahbot", "AHBuyer: AuctionHouse: {}", auction->GetHouseId()); diff --git a/src/AuctionHouseBot.h b/src/AuctionHouseBot.h index 3566eea..aec8c37 100644 --- a/src/AuctionHouseBot.h +++ b/src/AuctionHouseBot.h @@ -17,7 +17,6 @@ * with this program. If not, see . */ - #ifndef AUCTION_HOUSE_BOT_H #define AUCTION_HOUSE_BOT_H diff --git a/src/AuctionHouseBotConfig.h b/src/AuctionHouseBotConfig.h index b47cb4f..49acbba 100644 --- a/src/AuctionHouseBotConfig.h +++ b/src/AuctionHouseBotConfig.h @@ -41,7 +41,7 @@ class AHBConfig ~AHBConfig() = default; AHBConfig(uint32 ahid); - + inline uint32 GetAuctionHouseID() { return _auctionHouseID; From a25c3f0230cd1eb2c26f8d4d86f4c6314a9898d1 Mon Sep 17 00:00:00 2001 From: Winfidonarleyan Date: Fri, 3 Nov 2023 08:37:15 +0700 Subject: [PATCH 3/4] Update src/AuctionHouseBot.cpp Co-authored-by: Dedmen Miller --- src/AuctionHouseBot.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index 21a2bb8..53cebe5 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -22,6 +22,7 @@ #include "Player.h" #include "WorldSession.h" #include "GameTime.h" +#include "DatabaseEnv.h" #include "StringConvert.h" #include "StringFormat.h" #include From 739ae722cf60f9fbda791d6bf90f8aa8ed17a56a Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Thu, 9 May 2024 18:58:42 +0200 Subject: [PATCH 4/4] Split item filtering into separate source file (#75) * chore: switch to reusable module workflow (#58) * chore(Module/Structure): update structure (#72) * chore(Bot): add db env include * Split item indexing into separate files * Fixed copyright headers * Remove unused variable --------- Co-authored-by: Patrick Lewis Co-authored-by: Walter Pagani Co-authored-by: Winfidonarleyan --- .github/ISSUE_TEMPLATE/bug_report.yml | 72 +++ .github/ISSUE_TEMPLATE/feature_request.yml | 33 + .github/workflows/core-build.yml | 43 +- README.md | 1 - conf/conf.sh.dist | 9 - data/.gitkeep | 0 data/sql/db-auth/base/.gitkeep | 0 data/sql/db-auth/updates/.gitkeep | 0 data/sql/db-characters/base/.gitkeep | 0 data/sql/db-characters/updates/.gitkeep | 0 data/sql/db-world/base/.gitkeep | 0 .../db-world}/base/mod_auctionhousebot.sql | 0 data/sql/db-world/updates/.gitkeep | 0 include.sh | 9 - pull_request_template.md | 25 + src/AuctionHouseBot.cpp | 575 +---------------- src/AuctionHouseBot.h | 58 -- src/AuctionHouseBotConfig.cpp | 27 +- src/AuctionHouseBotConfig.h | 6 + src/ItemIndex.cpp | 576 ++++++++++++++++++ src/ItemIndex.h | 53 ++ 21 files changed, 794 insertions(+), 693 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml delete mode 100644 conf/conf.sh.dist create mode 100644 data/.gitkeep create mode 100644 data/sql/db-auth/base/.gitkeep create mode 100644 data/sql/db-auth/updates/.gitkeep create mode 100644 data/sql/db-characters/base/.gitkeep create mode 100644 data/sql/db-characters/updates/.gitkeep create mode 100644 data/sql/db-world/base/.gitkeep rename {sql/world => data/sql/db-world}/base/mod_auctionhousebot.sql (100%) create mode 100644 data/sql/db-world/updates/.gitkeep create mode 100644 pull_request_template.md create mode 100644 src/ItemIndex.cpp create mode 100644 src/ItemIndex.h diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..5610d2b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,72 @@ +name: Bug report +description: Create a bug report to help us improve. +title: "Bug: " +body: + - type: textarea + id: current + attributes: + label: Current Behaviour + description: | + Description of the problem or issue here. + Include entries of affected creatures / items / quests / spells etc. + If this is a crash, post the crashlog (upload to https://gist.github.com/) and include the link here. + Never upload files! Use GIST for text and YouTube for videos! + validations: + required: true + - type: textarea + id: expected + attributes: + label: Expected Behaviour + description: | + Tell us what should happen instead. + validations: + required: true + - type: textarea + id: reproduce + attributes: + label: Steps to reproduce the problem + description: | + What does someone else need to do to encounter the same bug? + placeholder: | + 1. Step 1 + 2. Step 2 + 3. Step 3 + validations: + required: true + - type: textarea + id: extra + attributes: + label: Extra Notes + description: | + Do you have any extra notes that can help solve the issue that does not fit any other field? + placeholder: | + None + validations: + required: false + - type: textarea + id: commit + attributes: + label: AC rev. hash/commit + description: | + Copy the result of the `.server debug` command (if you need to run it from the client get a prat addon) + validations: + required: true + - type: input + id: os + attributes: + label: Operating system + description: | + The Operating System the Server is running on. + i.e. Windows 11 x64, Debian 10 x64, macOS 12, Ubuntu 20.04 + validations: + required: true + - type: textarea + id: custom + attributes: + label: Custom changes or Modules + description: | + List which custom changes or modules you have applied, i.e. Eluna module, etc. + placeholder: | + None + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..58f79dd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,33 @@ +name: Feature request +description: Suggest an idea for this project +title: "Feature: " +body: + - type: markdown + attributes: + value: | + Thank you for taking your time to fill out a feature request. Remember to fill out all fields including the title above. + An issue that is not properly filled out will be closed. + - type: textarea + id: description + attributes: + label: Describe your feature request or suggestion in detail + description: | + A clear and concise description of what you want to happen. + validations: + required: true + - type: textarea + id: solution + attributes: + label: Describe a possible solution to your feature or suggestion in detail + description: | + A clear and concise description of any alternative solutions or features you've considered. + validations: + required: false + - type: textarea + id: additional + attributes: + label: Additional context + description: | + Add any other context or screenshots about the feature request here. + validations: + required: false diff --git a/.github/workflows/core-build.yml b/.github/workflows/core-build.yml index f0f3cb0..921c9eb 100644 --- a/.github/workflows/core-build.yml +++ b/.github/workflows/core-build.yml @@ -1,45 +1,12 @@ name: core-build on: push: + branches: + - 'master' pull_request: jobs: build: - strategy: - fail-fast: false - matrix: - compiler: [clang] - runs-on: ubuntu-20.04 - name: ${{ matrix.compiler }} - env: - COMPILER: ${{ matrix.compiler }} - steps: - - uses: actions/checkout@v2 - with: - repository: 'azerothcore/azerothcore-wotlk' - ref: 'master' - submodules: 'recursive' - - uses: actions/checkout@v2 - with: - submodules: 'recursive' - path: 'modules/mod-ah-bot' - - name: Cache - uses: actions/cache@v1.1.2 - with: - path: /home/runner/.ccache - key: ccache:${{ matrix.compiler }}:${{ github.ref }}:${{ github.sha }} - restore-keys: | - ccache:${{ matrix.compiler }}:${{ github.ref }} - ccache:${{ matrix.compiler }} - - name: Configure OS - run: source ./apps/ci/ci-install.sh - env: - CONTINUOUS_INTEGRATION: true - - name: Import db - run: source ./apps/ci/ci-import-db.sh - - name: Build - run: source ./apps/ci/ci-compile.sh - - name: Dry run - run: source ./apps/ci/ci-worldserver-dry-run.sh - - name: Check startup errors - run: source ./apps/ci/ci-error-check.sh \ No newline at end of file + uses: azerothcore/reusable-workflows/.github/workflows/core_build_modules.yml@main + with: + module_repo: ${{ github.event.repository.name }} diff --git a/README.md b/README.md index db90434..810b8e7 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,3 @@ Notes: - Ayase: ported the bot to AzerothCore - Other contributors (check the contributors list) - diff --git a/conf/conf.sh.dist b/conf/conf.sh.dist deleted file mode 100644 index 937a7bc..0000000 --- a/conf/conf.sh.dist +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -# -# CUSTOM -# - -DB_WORLD_CUSTOM_PATHS+=( - $MOD_AH_BOT_ROOT"/sql/world/base/" -) diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/sql/db-auth/base/.gitkeep b/data/sql/db-auth/base/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/sql/db-auth/updates/.gitkeep b/data/sql/db-auth/updates/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/sql/db-characters/base/.gitkeep b/data/sql/db-characters/base/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/sql/db-characters/updates/.gitkeep b/data/sql/db-characters/updates/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/sql/db-world/base/.gitkeep b/data/sql/db-world/base/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/sql/world/base/mod_auctionhousebot.sql b/data/sql/db-world/base/mod_auctionhousebot.sql similarity index 100% rename from sql/world/base/mod_auctionhousebot.sql rename to data/sql/db-world/base/mod_auctionhousebot.sql diff --git a/data/sql/db-world/updates/.gitkeep b/data/sql/db-world/updates/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/include.sh b/include.sh index 038ece6..e69de29 100644 --- a/include.sh +++ b/include.sh @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -MOD_AH_BOT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )" - -source $MOD_AH_BOT_ROOT"/conf/conf.sh.dist" - -if [ -f $MOD_AH_BOT_ROOT"/conf/conf.sh" ]; then - source $MOD_AH_BOT_ROOT"/conf/conf.sh" -fi diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 0000000..21c9245 --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,25 @@ + + +## Changes Proposed: +- +- + +## Issues Addressed: + +- Closes + +## SOURCE: + + +## Tests Performed: + +- +- + + +## How to Test the Changes: + + +1. +2. +3. diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index 53cebe5..dd80109 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -18,6 +18,11 @@ #include "ObjectMgr.h" #include "AuctionHouseMgr.h" #include "AuctionHouseBot.h" +#include "ItemIndex.h" + +#include +#include + #include "Config.h" #include "Player.h" #include "WorldSession.h" @@ -29,25 +34,6 @@ AuctionHouseBot::AuctionHouseBot() { - 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 - _lastUpdateAlliance = GameTime::GetGameTime(); _lastUpdateHorde = GameTime::GetGameTime(); _lastUpdateNeutral = GameTime::GetGameTime(); @@ -120,6 +106,8 @@ void AuctionHouseBot::AddNewAuctions(Player* AHBplayer, AHBConfig* config) LOG_DEBUG("module.ahbot", "AHSeller: {} items", items); + auto const itemIndex = sAHIndex; + // only insert a few at a time, so as not to peg the processor for (uint32 cnt = 1; cnt <= items; cnt++) { @@ -135,7 +123,7 @@ void AuctionHouseBot::AddNewAuctions(Player* AHBplayer, AHBConfig* config) uint32 choice = urand(0, 13); itemColor = choice; - auto const& itemsBin = _itemsBin[choice]; + auto const& itemsBin = itemIndex->GetItemBin(choice); if (!itemsBin.empty() && itemsCount[choice] < percents[choice]) itemID = Acore::Containers::SelectRandomContainerElement(itemsBin); @@ -227,7 +215,7 @@ void AuctionHouseBot::AddNewAuctions(Player* AHBplayer, AHBConfig* config) AuctionEntry* auctionEntry = new AuctionEntry(); auctionEntry->Id = sObjectMgr->GenerateAuctionID(); auctionEntry->houseId = config->GetAuctionHouseID(); - auctionEntry->item_guid = item->GetGUID(); + auctionEntry->item_guid = item->GetGUID(); auctionEntry->item_template = item->GetEntry(); auctionEntry->itemCount = item->GetCount(); auctionEntry->owner = AHBplayer->GetGUID(); @@ -267,7 +255,7 @@ void AuctionHouseBot::AddNewAuctionBuyerBotBid(std::shared_ptr player, s WithCallback(std::bind(&AuctionHouseBot::AddNewAuctionBuyerBotBidCallback, this, player, session, sharedConfig, std::placeholders::_1))); } -void AuctionHouseBot::AddNewAuctionBuyerBotBidCallback(std::shared_ptr player, std::shared_ptr session, std::shared_ptr config, QueryResult result) +void AuctionHouseBot::AddNewAuctionBuyerBotBidCallback(std::shared_ptr player, std::shared_ptr /*session*/, std::shared_ptr config, QueryResult result) { if (!result || !result->GetRowCount()) return; @@ -512,19 +500,10 @@ void AuctionHouseBot::Update() void AuctionHouseBot::Initialize() { - DisableItemStore.clear(); - QueryResult result = WorldDatabase.Query("SELECT item FROM mod_auctionhousebot_disabled_items"); - - if (result) - { - do - { - Field* fields = result->Fetch(); - DisableItemStore.emplace(fields[0].Get()); - } while (result->NextRow()); - } + if (AHBSeller) + if (!sAHIndex->InitializeItemsToSell()) + AHBSeller = false; - // End Filters if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) { LoadValues(&AllianceConfig); @@ -547,479 +526,7 @@ void AuctionHouseBot::Initialize() } } - if (AHBSeller) - { - std::string npcQuery = "SELECT distinct item FROM npc_vendor"; - QueryResult results = WorldDatabase.Query(npcQuery); - if (results) - { - do - { - Field* fields = results->Fetch(); - npcItems.push_back(fields[0].Get()); - - } while (results->NextRow()); - } - else - LOG_ERROR("module.ahbot", "AuctionHouseBot: \"{}\" failed", npcQuery); - - std::string lootQuery = "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"; - - results = WorldDatabase.Query(lootQuery); - if (results) - { - do - { - Field* fields = results->Fetch(); - lootItems.push_back(fields[0].Get()); - - } while (results->NextRow()); - } - else - LOG_ERROR("module.ahbot", "AuctionHouseBot: \"{}\" failed", lootQuery); - - for (auto const& [itemID, itemTemplate] : *sObjectMgr->GetItemTemplateStore()) - { - switch (itemTemplate.Bonding) - { - case NO_BIND: - if (!No_Bind) - continue; - break; - case BIND_WHEN_PICKED_UP: - if (!Bind_When_Picked_Up) - continue; - break; - case BIND_WHEN_EQUIPED: - if (!Bind_When_Equipped) - continue; - break; - case BIND_WHEN_USE: - if (!Bind_When_Use) - continue; - break; - case BIND_QUEST_ITEM: - if (!Bind_Quest_Item) - continue; - break; - default: - continue; - break; - } - - if (SellMethod) - { - if (!itemTemplate.BuyPrice) - continue; - } - else - { - if (!itemTemplate.SellPrice) - continue; - } - - if (itemTemplate.Quality > ITEM_QUALITY_ARTIFACT) - continue; - - if (!Vendor_Items && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) - { - bool isVendorItem = false; - - for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorItem); i++) - { - if (itemTemplate.ItemId == npcItems[i]) - isVendorItem = true; - } - - if (isVendorItem) - continue; - } - - if (!Vendor_TGs && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) - { - bool isVendorTG = false; - - for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorTG); i++) - { - if (itemTemplate.ItemId == npcItems[i]) - isVendorTG = true; - } - - if (isVendorTG) - continue; - } - - if (!Loot_Items && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) - { - bool isLootItem = false; - - for (unsigned int i = 0; (i < lootItems.size()) && (!isLootItem); i++) - { - if (itemTemplate.ItemId == lootItems[i]) - isLootItem = true; - } - - if (isLootItem) - continue; - } - - if (!Loot_TGs && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) - { - bool isLootTG = false; - - for (unsigned int i = 0; (i < lootItems.size()) && (!isLootTG); i++) - { - if (itemTemplate.ItemId == lootItems[i]) - isLootTG = true; - } - - if (isLootTG) - continue; - } - - if (Other_Items && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) - { - bool isVendorItem = false; - bool isLootItem = false; - - for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorItem); i++) - { - if (itemTemplate.ItemId == npcItems[i]) - isVendorItem = true; - } - - for (unsigned int i = 0; (i < lootItems.size()) && (!isLootItem); i++) - { - if (itemTemplate.ItemId == lootItems[i]) - isLootItem = true; - } - - if (!isLootItem && !isVendorItem) - continue; - } - - if (Other_TGs && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) - { - bool isVendorTG = false; - bool isLootTG = false; - - for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorTG); i++) - { - if (itemTemplate.ItemId == npcItems[i]) - isVendorTG = true; - } - - for (unsigned int i = 0; (i < lootItems.size()) && (!isLootTG); i++) - { - if (itemTemplate.ItemId == lootItems[i]) - isLootTG = true; - } - - if (!isLootTG && !isVendorTG) - continue; - } - - // Disable items by Id - if (DisableItemStore.find(itemTemplate.ItemId) != DisableItemStore.end()) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (PTR/Beta/Unused Item)", itemTemplate.ItemId); - continue; - } - - // Disable permanent enchants items - if (DisablePermEnchant && itemTemplate.Class == ITEM_CLASS_PERMANENT) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Permanent Enchant Item)", itemTemplate.ItemId); - continue; - } - - // Disable conjured items - if (DisableConjured && itemTemplate.IsConjuredConsumable()) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Conjured Consumable)", itemTemplate.ItemId); - continue; - } - - // Disable gems - if (DisableGems && itemTemplate.Class == ITEM_CLASS_GEM) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Gem)", itemTemplate.ItemId); - continue; - } - - // Disable money - if (DisableMoney && itemTemplate.Class == ITEM_CLASS_MONEY) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Money)", itemTemplate.ItemId); - continue; - } - - // Disable moneyloot - if (DisableMoneyLoot && itemTemplate.MinMoneyLoot) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (MoneyLoot)", itemTemplate.ItemId); - continue; - } - - // Disable lootable items - if (DisableLootable && itemTemplate.Flags & 4) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Lootable Item)", itemTemplate.ItemId); - continue; - } - - // Disable Keys - if (DisableKeys && itemTemplate.Class == ITEM_CLASS_KEY) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Quest Item)", itemTemplate.ItemId); - continue; - } - - // Disable items with duration - if (DisableDuration && itemTemplate.Duration) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Has a Duration)", itemTemplate.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 && ((itemTemplate.Bonding == BIND_WHEN_PICKED_UP || itemTemplate.Bonding == BIND_QUEST_ITEM) && (itemTemplate.RequiredLevel < itemTemplate.ItemLevel))) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (BOP or BQI and Required Level is less than Item Level)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for Warrior - if (DisableWarriorItems && itemTemplate.AllowableClass == 1) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Warrior Item)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for Paladin - if (DisablePaladinItems && itemTemplate.AllowableClass == 2) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Paladin Item)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for Hunter - if (DisableHunterItems && itemTemplate.AllowableClass == 4) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Hunter Item)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for Rogue - if (DisableRogueItems && itemTemplate.AllowableClass == 8) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Rogue Item)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for Priest - if (DisablePriestItems && itemTemplate.AllowableClass == 16) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Priest Item)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for DK - if (DisableDKItems && itemTemplate.AllowableClass == 32) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (DK Item)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for Shaman - if (DisableShamanItems && itemTemplate.AllowableClass == 64) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Shaman Item)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for Mage - if (DisableMageItems && itemTemplate.AllowableClass == 128) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Mage Item)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for Warlock - if (DisableWarlockItems && itemTemplate.AllowableClass == 256) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Warlock Item)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for Unused Class - if (DisableUnusedClassItems && itemTemplate.AllowableClass == 512) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Unused Item)", itemTemplate.ItemId); - continue; - } - - // Disable items specifically for Druid - if (DisableDruidItems && itemTemplate.AllowableClass == 1024) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Druid Item)", itemTemplate.ItemId); - continue; - } - - // Disable Items below level X - if (DisableItemsBelowLevel && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemLevel < DisableItemsBelowLevel) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); - continue; - } - - // Disable Items above level X - if (DisableItemsAboveLevel && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemLevel > DisableItemsAboveLevel) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); - continue; - } - - // Disable Trade Goods below level X - if (DisableTGsBelowLevel && itemTemplate.Class == ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemLevel < DisableTGsBelowLevel) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); - continue; - } - - // Disable Trade Goods above level X - if (DisableTGsAboveLevel && itemTemplate.Class == ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemLevel > DisableTGsAboveLevel) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); - continue; - } - - // Disable Items below GUID X - if (DisableItemsBelowGUID && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemId < DisableItemsBelowGUID) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); - continue; - } - - // Disable Items above GUID X - if (DisableItemsAboveGUID && itemTemplate.Class != ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemId > DisableItemsAboveGUID) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); - continue; - } - - // Disable Trade Goods below GUID X - if (DisableTGsBelowGUID && itemTemplate.Class == ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemId < DisableTGsBelowGUID) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); - continue; - } - - // Disable Trade Goods above GUID X - if (DisableTGsAboveGUID && itemTemplate.Class == ITEM_CLASS_TRADE_GOODS && itemTemplate.ItemId > DisableTGsAboveGUID) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); - continue; - } - - // Disable Items for level lower than X - if (DisableItemsBelowReqLevel && itemTemplate.RequiredLevel < DisableItemsBelowReqLevel) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); - continue; - } - - // Disable Items for level higher than X - if (DisableItemsAboveReqLevel && itemTemplate.RequiredLevel > DisableItemsAboveReqLevel) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); - continue; - } - - // Disable Trade Goods for level lower than X - if (DisableTGsBelowReqLevel && itemTemplate.RequiredLevel < DisableTGsBelowReqLevel) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); - continue; - } - - // Disable Trade Goods for level higher than X - if (DisableTGsAboveReqLevel && itemTemplate.RequiredLevel > DisableTGsAboveReqLevel) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); - continue; - } - - // Disable Items that require skill lower than X - if (DisableItemsBelowReqSkillRank && itemTemplate.RequiredSkillRank < DisableItemsBelowReqSkillRank) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); - continue; - } - - // Disable Items that require skill higher than X - if (DisableItemsAboveReqSkillRank && itemTemplate.RequiredSkillRank > DisableItemsAboveReqSkillRank) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); - continue; - } - - // Disable Trade Goods that require skill lower than X - if (DisableTGsBelowReqSkillRank && itemTemplate.RequiredSkillRank < DisableTGsBelowReqSkillRank) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); - continue; - } - - // Disable Trade Goods that require skill higher than X - if (DisableTGsAboveReqSkillRank && itemTemplate.RequiredSkillRank > DisableTGsAboveReqSkillRank) - { - LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); - continue; - } - - uint32 itemQualityIndexStart = itemTemplate.Class == ITEM_CLASS_TRADE_GOODS ? 0 : AHB_DEFAULT_QUALITY_SIZE; - _itemsBin[itemQualityIndexStart + itemTemplate.Quality].emplace_back(itemTemplate.ItemId); - } - - std::size_t totalItems = 0; - for (auto const& itr : _itemsBin) - totalItems += itr.size(); - - if (!totalItems) - { - LOG_ERROR("module.ahbot", "AuctionHouseBot: No items"); - AHBSeller = 0; - } - - LOG_INFO("module.ahbot", "AuctionHouseBot:"); - LOG_INFO("module.ahbot", "{} disabled items", DisableItemStore.size()); - LOG_INFO("module.ahbot", "Loaded {} grey trade goods", _itemsBin[ITEM_QUALITY_POOR].size()); - LOG_INFO("module.ahbot", "Loaded {} white trade goods", _itemsBin[ITEM_QUALITY_NORMAL].size()); - LOG_INFO("module.ahbot", "Loaded {} green trade goods", _itemsBin[ITEM_QUALITY_UNCOMMON].size()); - LOG_INFO("module.ahbot", "Loaded {} blue trade goods", _itemsBin[ITEM_QUALITY_RARE].size()); - LOG_INFO("module.ahbot", "Loaded {} purple trade goods", _itemsBin[ITEM_QUALITY_EPIC].size()); - LOG_INFO("module.ahbot", "Loaded {} orange trade goods", _itemsBin[ITEM_QUALITY_LEGENDARY].size()); - LOG_INFO("module.ahbot", "Loaded {} yellow trade goods", _itemsBin[ITEM_QUALITY_ARTIFACT].size()); - LOG_INFO("module.ahbot", "Loaded {} grey items", _itemsBin[AHB_ITEM_QUALITY_POOR].size()); - LOG_INFO("module.ahbot", "Loaded {} white items", _itemsBin[AHB_ITEM_QUALITY_NORMAL].size()); - LOG_INFO("module.ahbot", "Loaded {} green items", _itemsBin[AHB_ITEM_QUALITY_UNCOMMON].size()); - LOG_INFO("module.ahbot", "Loaded {} blue items", _itemsBin[AHB_ITEM_QUALITY_RARE].size()); - LOG_INFO("module.ahbot", "Loaded {} purple items", _itemsBin[AHB_ITEM_QUALITY_EPIC].size()); - LOG_INFO("module.ahbot", "Loaded {} orange items", _itemsBin[AHB_ITEM_QUALITY_LEGENDARY].size()); - LOG_INFO("module.ahbot", "Loaded {} yellow items", _itemsBin[AHB_ITEM_QUALITY_ARTIFACT].size()); - } - - LOG_INFO("module", "AuctionHouseBot and AuctionHouseBuyer have been loaded."); + LOG_INFO("module", "AuctionHouseBot has been loaded."); } void AuctionHouseBot::InitializeConfiguration() @@ -1032,60 +539,6 @@ void AuctionHouseBot::InitializeConfiguration() AHBplayerAccount = sConfigMgr->GetOption("AuctionHouseBot.Account", 0); AHBplayerGUID = sConfigMgr->GetOption("AuctionHouseBot.GUID", 0); ItemsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.ItemsPerCycle", 200); - - // Begin Filters - - 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); - - 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); - - DisablePermEnchant = sConfigMgr->GetOption("AuctionHouseBot.DisablePermEnchant", false); - 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); - - 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); - - DisableItemsBelowLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowLevel", 0); - DisableItemsAboveLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveLevel", 0); - DisableTGsBelowLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowLevel", 0); - DisableTGsAboveLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveLevel", 0); - DisableItemsBelowGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowGUID", 0); - DisableItemsAboveGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveGUID", 0); - DisableTGsBelowGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowGUID", 0); - DisableTGsAboveGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveGUID", 0); - DisableItemsBelowReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowReqLevel", 0); - DisableItemsAboveReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveReqLevel", 0); - DisableTGsBelowReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowReqLevel", 0); - DisableTGsAboveReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveReqLevel", 0); - DisableItemsBelowReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowReqSkillRank", 0); - DisableItemsAboveReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveReqSkillRank", 0); - DisableTGsBelowReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowReqSkillRank", 0); - DisableTGsAboveReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveReqSkillRank", 0); } void AuctionHouseBot::IncrementItemCounts(AuctionEntry* ah) diff --git a/src/AuctionHouseBot.h b/src/AuctionHouseBot.h index aec8c37..19c10dd 100644 --- a/src/AuctionHouseBot.h +++ b/src/AuctionHouseBot.h @@ -1,5 +1,3 @@ -/* - * Copyright (C) 2008-2010 Trinity /* * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information * @@ -58,58 +56,6 @@ class AuctionHouseBot ObjectGuid::LowType AHBplayerGUID; uint32 ItemsPerCycle; - bool Vendor_Items{ false }; - bool Loot_Items{ false }; - bool Other_Items{ false }; - bool Vendor_TGs{ false }; - bool Loot_TGs{ false }; - bool Other_TGs{ false }; - - bool No_Bind{ false }; - bool Bind_When_Picked_Up{ false }; - bool Bind_When_Equipped{ false }; - bool Bind_When_Use{ false }; - bool Bind_Quest_Item{ false }; - - bool DisablePermEnchant{ false }; - bool DisableConjured{ false }; - bool DisableGems{ false }; - bool DisableMoney{ false }; - bool DisableMoneyLoot{ false }; - bool DisableLootable{ false };; - bool DisableKeys{ false }; - bool DisableDuration{ false }; - bool DisableBOP_Or_Quest_NoReqLevel{ false }; - - bool DisableWarriorItems{ false }; - bool DisablePaladinItems{ false }; - bool DisableHunterItems{ false }; - bool DisableRogueItems{ false }; - bool DisablePriestItems{ false }; - bool DisableDKItems{ false }; - bool DisableShamanItems{ false }; - bool DisableMageItems{ false }; - bool DisableWarlockItems{ false }; - bool DisableUnusedClassItems{ false }; - bool DisableDruidItems{ false }; - - uint32 DisableItemsBelowLevel{ 0 }; - uint32 DisableItemsAboveLevel{ 0 }; - uint32 DisableTGsBelowLevel{ 0 }; - uint32 DisableTGsAboveLevel{ 0 }; - uint32 DisableItemsBelowGUID{ 0 }; - uint32 DisableItemsAboveGUID{ 0 }; - uint32 DisableTGsBelowGUID{ 0 }; - uint32 DisableTGsAboveGUID{ 0 }; - uint32 DisableItemsBelowReqLevel{ 0 }; - uint32 DisableItemsAboveReqLevel{ 0 }; - uint32 DisableTGsBelowReqLevel{ 0 }; - uint32 DisableTGsAboveReqLevel{ 0 }; - uint32 DisableItemsBelowReqSkillRank{ 0 }; - uint32 DisableItemsAboveReqSkillRank{ 0 }; - uint32 DisableTGsBelowReqSkillRank{ 0 }; - uint32 DisableTGsAboveReqSkillRank{ 0 }; - std::unordered_set DisableItemStore{}; AHBConfig AllianceConfig; @@ -120,10 +66,6 @@ class AuctionHouseBot Seconds _lastUpdateHorde{ 0s }; Seconds _lastUpdateNeutral{ 0s }; - std::array, AHB_MAX_QUALITY> _itemsBin{}; - std::vector npcItems{}; - std::vector lootItems{}; - inline uint32 minValue(uint32 a, uint32 b) { return a <= b ? a : b; }; void AddNewAuctions(Player* AHBplayer, AHBConfig* config); void AddNewAuctionBuyerBotBid(std::shared_ptr player, std::shared_ptr session, AHBConfig* config); diff --git a/src/AuctionHouseBotConfig.cpp b/src/AuctionHouseBotConfig.cpp index 2c231c2..8cfcda8 100644 --- a/src/AuctionHouseBotConfig.cpp +++ b/src/AuctionHouseBotConfig.cpp @@ -20,6 +20,8 @@ #include "ItemTemplate.h" #include +#include "Log.h" + AHBConfig::AHBConfig(uint32 ahid) { _auctionHouseID = ahid; @@ -61,25 +63,16 @@ void AHBConfig::SetPercentages(std::array& percentages) } else if (totalPercent != 100) { - _itemsPercent[ITEM_QUALITY_POOR] = 0; - _itemsPercent[ITEM_QUALITY_NORMAL] = 27; - _itemsPercent[ITEM_QUALITY_UNCOMMON] = 12; - _itemsPercent[ITEM_QUALITY_RARE] = 10; - _itemsPercent[ITEM_QUALITY_EPIC] = 1; - _itemsPercent[ITEM_QUALITY_LEGENDARY] = 0; - _itemsPercent[ITEM_QUALITY_ARTIFACT] = 0; - - _itemsPercent[AHB_ITEM_QUALITY_POOR] = 0; - _itemsPercent[AHB_ITEM_QUALITY_NORMAL] = 10; - _itemsPercent[AHB_ITEM_QUALITY_UNCOMMON] = 30; - _itemsPercent[AHB_ITEM_QUALITY_RARE] = 8; - _itemsPercent[AHB_ITEM_QUALITY_EPIC] = 2; - _itemsPercent[AHB_ITEM_QUALITY_LEGENDARY] = 0; - _itemsPercent[AHB_ITEM_QUALITY_ARTIFACT] = 0; + // re-normalize all percentages + const float fixMultiplier = 100.f / static_cast(totalPercent); + + for (auto& it : percentages) + it *= fixMultiplier; + + LOG_WARN("module.ahbot", "AHConfig: Percentages don't add up to 100 (was {}), they have been auto-normalized.", totalPercent); } - for (size_t i = 0; i < percentages.size(); i++) - _itemsPercent[i] = percentages[i]; + std::copy_n(percentages.begin(), AHB_MAX_QUALITY, _itemsPercent.begin()); CalculatePercents(); } diff --git a/src/AuctionHouseBotConfig.h b/src/AuctionHouseBotConfig.h index 49acbba..ea66ece 100644 --- a/src/AuctionHouseBotConfig.h +++ b/src/AuctionHouseBotConfig.h @@ -15,8 +15,12 @@ * with this program. If not, see . */ +#ifndef AUCTION_HOUSE_BOT_CONFIG_H +#define AUCTION_HOUSE_BOT_CONFIG_H + #include "Define.h" #include "Duration.h" +#include "SharedDefines.h" #include enum AHItemQualities @@ -167,3 +171,5 @@ class AHBConfig std::array _maxPrice{}; std::array _itemsCount{}; }; + +#endif // AUCTION_HOUSE_BOT_CONFIG_H diff --git a/src/ItemIndex.cpp b/src/ItemIndex.cpp new file mode 100644 index 0000000..fb0a307 --- /dev/null +++ b/src/ItemIndex.cpp @@ -0,0 +1,576 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "ItemIndex.h" + +#include + +#include "Config.h" +#include "WorldSession.h" +#include "DatabaseEnv.h" +#include "Log.h" +#include "ObjectMgr.h" +#include "SmartEnum.h" + +AuctionHouseIndex* AuctionHouseIndex::instance() +{ + static AuctionHouseIndex instance; + return &instance; +} + +struct ItemFilter +{ + bool SellMethod{ false }; + + bool Vendor_Items{ false }; + bool Loot_Items{ false }; + bool Other_Items{ false }; + bool Vendor_TGs{ false }; + bool Loot_TGs{ false }; + bool Other_TGs{ false }; + + bool No_Bind{ false }; + bool Bind_When_Picked_Up{ false }; + bool Bind_When_Equipped{ false }; + bool Bind_When_Use{ false }; + bool Bind_Quest_Item{ false }; + + bool DisablePermEnchant{ false }; + bool DisableConjured{ false }; + bool DisableGems{ false }; + bool DisableMoney{ false }; + bool DisableMoneyLoot{ false }; + bool DisableLootable{ false };; + bool DisableKeys{ false }; + bool DisableDuration{ false }; + bool DisableBOP_Or_Quest_NoReqLevel{ false }; + + std::bitset<32> DisableClassItemsMask; + + uint32 DisableItemsBelowLevel{ 0 }; + uint32 DisableItemsAboveLevel{ 0 }; + uint32 DisableTGsBelowLevel{ 0 }; + uint32 DisableTGsAboveLevel{ 0 }; + uint32 DisableItemsBelowGUID{ 0 }; + uint32 DisableItemsAboveGUID{ 0 }; + uint32 DisableTGsBelowGUID{ 0 }; + uint32 DisableTGsAboveGUID{ 0 }; + uint32 DisableItemsBelowReqLevel{ 0 }; + uint32 DisableItemsAboveReqLevel{ 0 }; + uint32 DisableTGsBelowReqLevel{ 0 }; + uint32 DisableTGsAboveReqLevel{ 0 }; + uint32 DisableItemsBelowReqSkillRank{ 0 }; + uint32 DisableItemsAboveReqSkillRank{ 0 }; + uint32 DisableTGsBelowReqSkillRank{ 0 }; + uint32 DisableTGsAboveReqSkillRank{ 0 }; + + std::unordered_set disabledItems{}; + std::unordered_set npcItems{}; + std::unordered_set lootItems{}; + + ItemFilter() + { + QueryResult results = WorldDatabase.Query("SELECT item FROM mod_auctionhousebot_disabled_items"); + + if (results) + { + do + { + const Field* fields = results->Fetch(); + disabledItems.emplace(fields[0].Get()); + } while (results->NextRow()); + } + + std::string npcQuery = "SELECT distinct item FROM npc_vendor"; + results = WorldDatabase.Query(npcQuery); + if (results) + { + do + { + const Field* fields = results->Fetch(); + npcItems.emplace(fields[0].Get()); + } while (results->NextRow()); + } + else + LOG_ERROR("module.ahbot", "AuctionHouseBot: \"{}\" failed", npcQuery); + + std::string lootQuery = "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"; + + results = WorldDatabase.Query(lootQuery); + if (results) + { + do + { + const Field* fields = results->Fetch(); + lootItems.emplace(fields[0].Get()); + } while (results->NextRow()); + } + else + LOG_ERROR("module.ahbot", "AuctionHouseBot: \"{}\" failed", lootQuery); + + + + SellMethod = sConfigMgr->GetOption("AuctionHouseBot.UseBuyPriceForSeller", false); + + // Begin Filters + + 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); + + 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); + + DisablePermEnchant = sConfigMgr->GetOption("AuctionHouseBot.DisablePermEnchant", false); + 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); + + // Classes are 1 based index, to get their flag bit we need zero based, so -1 + DisableClassItemsMask.set(Classes::CLASS_WARRIOR - 1, sConfigMgr->GetOption("AuctionHouseBot.DisableWarriorItems", false)); + DisableClassItemsMask.set(Classes::CLASS_PALADIN - 1, sConfigMgr->GetOption("AuctionHouseBot.DisablePaladinItems", false)); + DisableClassItemsMask.set(Classes::CLASS_HUNTER - 1, sConfigMgr->GetOption("AuctionHouseBot.DisableHunterItems", false)); + DisableClassItemsMask.set(Classes::CLASS_ROGUE - 1, sConfigMgr->GetOption("AuctionHouseBot.DisableRogueItems", false)); + DisableClassItemsMask.set(Classes::CLASS_PRIEST - 1, sConfigMgr->GetOption("AuctionHouseBot.DisablePriestItems", false)); + DisableClassItemsMask.set(Classes::CLASS_DEATH_KNIGHT - 1, sConfigMgr->GetOption("AuctionHouseBot.DisableDKItems", false)); + DisableClassItemsMask.set(Classes::CLASS_SHAMAN - 1, sConfigMgr->GetOption("AuctionHouseBot.DisableShamanItems", false)); + DisableClassItemsMask.set(Classes::CLASS_MAGE - 1, sConfigMgr->GetOption("AuctionHouseBot.DisableMageItems", false)); + DisableClassItemsMask.set(Classes::CLASS_WARLOCK - 1, sConfigMgr->GetOption("AuctionHouseBot.DisableWarlockItems", false)); + DisableClassItemsMask.set(10 - 1, sConfigMgr->GetOption("AuctionHouseBot.DisableUnusedClassItems", false)); + DisableClassItemsMask.set(Classes::CLASS_DRUID - 1, sConfigMgr->GetOption("AuctionHouseBot.DisableDruidItems", false)); + DisableClassItemsMask.set(Classes::CLASS_WARRIOR - 1, sConfigMgr->GetOption("AuctionHouseBot.DisableWarriorItems", false)); + + DisableItemsBelowLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowLevel", 0); + DisableItemsAboveLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveLevel", 0); + DisableTGsBelowLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowLevel", 0); + DisableTGsAboveLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveLevel", 0); + DisableItemsBelowGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowGUID", 0); + DisableItemsAboveGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveGUID", 0); + DisableTGsBelowGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowGUID", 0); + DisableTGsAboveGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveGUID", 0); + DisableItemsBelowReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowReqLevel", 0); + DisableItemsAboveReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveReqLevel", 0); + DisableTGsBelowReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowReqLevel", 0); + DisableTGsAboveReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveReqLevel", 0); + DisableItemsBelowReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowReqSkillRank", 0); + DisableItemsAboveReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveReqSkillRank", 0); + DisableTGsBelowReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowReqSkillRank", 0); + DisableTGsAboveReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveReqSkillRank", 0); + } + + bool IsAccepted(const ItemTemplate& itemTemplate) const + { + switch (itemTemplate.Bonding) + { + case NO_BIND: + if (!No_Bind) + return false; + break; + case BIND_WHEN_PICKED_UP: + if (!Bind_When_Picked_Up) + return false; + break; + case BIND_WHEN_EQUIPED: + if (!Bind_When_Equipped) + return false; + break; + case BIND_WHEN_USE: + if (!Bind_When_Use) + return false; + break; + case BIND_QUEST_ITEM: + if (!Bind_Quest_Item) + return false; + break; + default: + return false; + } + + if (SellMethod) + { + if (!itemTemplate.BuyPrice) + return false; + } + else + { + if (!itemTemplate.SellPrice) + return false; + } + + if (itemTemplate.Quality > ITEM_QUALITY_ARTIFACT) + return false; + + auto isVendorItem = [this](const ItemTemplate& itemTemplate) + { + return npcItems.contains(itemTemplate.ItemId); + }; + + auto isLootItem = [this](const ItemTemplate& itemTemplate) + { + return lootItems.contains(itemTemplate.ItemId); + }; + + if (itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) + { + // Item checks + + if (!Vendor_Items) + { + if (isVendorItem(itemTemplate)) + return false; + } + + if (!Loot_Items) + { + if (isLootItem(itemTemplate)) + return false; + } + + if (!Other_Items) + { + if (!isLootItem(itemTemplate) && !isVendorItem(itemTemplate)) + return false; + } + } + else if (itemTemplate.Class == ITEM_CLASS_TRADE_GOODS) + { + // Tradegood checks + + if (!Vendor_TGs) + { + if (isVendorItem(itemTemplate)) + return false; + } + + if (!Loot_TGs) + { + if (isLootItem(itemTemplate)) + return false; + } + + if (!Other_TGs) + { + if (!isLootItem(itemTemplate) && !isVendorItem(itemTemplate)) + return false; + } + } + + + // Disable items by Id + if (disabledItems.contains(itemTemplate.ItemId)) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (PTR/Beta/Unused Item)", itemTemplate.ItemId); + return false; + } + + // Disable permanent enchants items + if (DisablePermEnchant && itemTemplate.Class == ITEM_CLASS_PERMANENT) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Permanent Enchant Item)", itemTemplate.ItemId); + return false; + } + + // Disable conjured items + if (DisableConjured && itemTemplate.IsConjuredConsumable()) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Conjured Consumable)", itemTemplate.ItemId); + return false; + } + + // Disable gems + if (DisableGems && itemTemplate.Class == ITEM_CLASS_GEM) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Gem)", itemTemplate.ItemId); + return false; + } + + // Disable money + if (DisableMoney && itemTemplate.Class == ITEM_CLASS_MONEY) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Money)", itemTemplate.ItemId); + return false; + } + + // Disable moneyloot + if (DisableMoneyLoot && itemTemplate.MinMoneyLoot) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (MoneyLoot)", itemTemplate.ItemId); + return false; + } + + // Disable lootable items + if (DisableLootable && itemTemplate.Flags & 4) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Lootable Item)", itemTemplate.ItemId); + return false; + } + + // Disable Keys + if (DisableKeys && itemTemplate.Class == ITEM_CLASS_KEY) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Quest Item)", itemTemplate.ItemId); + return false; + } + + // Disable items with duration + if (DisableDuration && itemTemplate.Duration) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Has a Duration)", itemTemplate.ItemId); + return false; + } + + // Disable items which are BOP or Quest Items and have a required level lower than the item level + if (DisableBOP_Or_Quest_NoReqLevel && ((itemTemplate.Bonding == BIND_WHEN_PICKED_UP || itemTemplate.Bonding == BIND_QUEST_ITEM) && (itemTemplate.RequiredLevel < itemTemplate.ItemLevel))) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (BOP or BQI and Required Level is less than Item Level)", itemTemplate.ItemId); + return false; + } + + + // We have disabled some class-specific items, lets see if this is one of them + if (DisableClassItemsMask.any()) + { + const std::bitset<32> allowableClass(itemTemplate.AllowableClass); + + // If this item is specific for just one class (as opposed to multiple classes), then check if its a class that we have disabled + if (allowableClass.count() == 1) + { + if ((DisableClassItemsMask & allowableClass).any()) + { + // slightly ugly, find index of first bit that is set, to find out which class this is + + Classes itemAllowClass = Classes::CLASS_NONE; + for (uint8 classBit = 0; classBit < MAX_CLASSES; ++classBit) + if (allowableClass.test(classBit)) + itemAllowClass = static_cast(classBit + 1); // Zero based index back to 1 based + + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled ({} Item)", itemTemplate.ItemId, Acore::Impl::EnumUtilsImpl::EnumUtils::ToString(itemAllowClass).Title); + return false; + } + } + } + + if (itemTemplate.Class != ITEM_CLASS_TRADE_GOODS) + { + // Item filters + + // Disable Items below level X + if (DisableItemsBelowLevel && itemTemplate.ItemLevel < DisableItemsBelowLevel) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); + return false; + } + + // Disable Items above level X + if (DisableItemsAboveLevel && itemTemplate.ItemLevel > DisableItemsAboveLevel) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); + return false; + } + + // Disable Items below GUID X + if (DisableItemsBelowGUID && itemTemplate.ItemId < DisableItemsBelowGUID) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); + return false; + } + + // Disable Items above GUID X + if (DisableItemsAboveGUID && itemTemplate.ItemId > DisableItemsAboveGUID) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Item Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); + return false; + } + } + else + { + // TradeGood filters + + // Disable Trade Goods below level X + if (DisableTGsBelowLevel && itemTemplate.ItemLevel < DisableTGsBelowLevel) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); + return false; + } + + // Disable Trade Goods above level X + if (DisableTGsAboveLevel && itemTemplate.ItemLevel > DisableTGsAboveLevel) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); + return false; + } + + // Disable Trade Goods below GUID X + if (DisableTGsBelowGUID && itemTemplate.ItemId < DisableTGsBelowGUID) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); + return false; + } + + // Disable Trade Goods above GUID X + if (DisableTGsAboveGUID && itemTemplate.ItemId > DisableTGsAboveGUID) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itemTemplate.ItemId, itemTemplate.ItemLevel); + return false; + } + } + + // Disable Items for level lower than X + if (DisableItemsBelowReqLevel && itemTemplate.RequiredLevel < DisableItemsBelowReqLevel) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); + return false; + } + + // Disable Items for level higher than X + if (DisableItemsAboveReqLevel && itemTemplate.RequiredLevel > DisableItemsAboveReqLevel) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); + return false; + } + + // Disable Trade Goods for level lower than X + if (DisableTGsBelowReqLevel && itemTemplate.RequiredLevel < DisableTGsBelowReqLevel) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); + return false; + } + + // Disable Trade Goods for level higher than X + if (DisableTGsAboveReqLevel && itemTemplate.RequiredLevel > DisableTGsAboveReqLevel) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itemTemplate.ItemId, itemTemplate.RequiredLevel); + return false; + } + + // Disable Items that require skill lower than X + if (DisableItemsBelowReqSkillRank && itemTemplate.RequiredSkillRank < DisableItemsBelowReqSkillRank) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); + return false; + } + + // Disable Items that require skill higher than X + if (DisableItemsAboveReqSkillRank && itemTemplate.RequiredSkillRank > DisableItemsAboveReqSkillRank) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); + return false; + } + + // Disable Trade Goods that require skill lower than X + if (DisableTGsBelowReqSkillRank && itemTemplate.RequiredSkillRank < DisableTGsBelowReqSkillRank) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); + return false; + } + + // Disable Trade Goods that require skill higher than X + if (DisableTGsAboveReqSkillRank && itemTemplate.RequiredSkillRank > DisableTGsAboveReqSkillRank) + { + LOG_DEBUG("module.ahbot.filters", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itemTemplate.ItemId, itemTemplate.RequiredSkillRank); + return false; + } + + return true; + } +}; + + + +bool AuctionHouseIndex::InitializeItemsToSell() +{ + const ItemFilter filter; + + + for (auto const& [itemID, itemTemplate] : *sObjectMgr->GetItemTemplateStore()) + { + WPAssert(itemTemplate.ItemId, "ItemID cannot be zero"); + + if (!filter.IsAccepted(itemTemplate)) + continue; + + const uint32 itemQualityIndexStart = itemTemplate.Class == ITEM_CLASS_TRADE_GOODS ? 0 : AHB_DEFAULT_QUALITY_SIZE; + _itemsBin[itemQualityIndexStart + itemTemplate.Quality].emplace_back(itemTemplate.ItemId); + } + + std::size_t totalItems = std::accumulate(_itemsBin.begin(), _itemsBin.end(), 0u, [](const std::size_t c, const std::vector& v) {return c + v.size(); }); + + if (!totalItems) + { + LOG_ERROR("module.ahbot", "AuctionHouseBot: No items"); + return false; + } + + LOG_INFO("module.ahbot", "AuctionHouseBot:"); + LOG_INFO("module.ahbot", "{} disabled items", filter.disabledItems.size()); + LOG_INFO("module.ahbot", "Loaded {} grey trade goods", _itemsBin[ITEM_QUALITY_POOR].size()); + LOG_INFO("module.ahbot", "Loaded {} white trade goods", _itemsBin[ITEM_QUALITY_NORMAL].size()); + LOG_INFO("module.ahbot", "Loaded {} green trade goods", _itemsBin[ITEM_QUALITY_UNCOMMON].size()); + LOG_INFO("module.ahbot", "Loaded {} blue trade goods", _itemsBin[ITEM_QUALITY_RARE].size()); + LOG_INFO("module.ahbot", "Loaded {} purple trade goods", _itemsBin[ITEM_QUALITY_EPIC].size()); + LOG_INFO("module.ahbot", "Loaded {} orange trade goods", _itemsBin[ITEM_QUALITY_LEGENDARY].size()); + LOG_INFO("module.ahbot", "Loaded {} yellow trade goods", _itemsBin[ITEM_QUALITY_ARTIFACT].size()); + LOG_INFO("module.ahbot", "Loaded {} grey items", _itemsBin[AHB_ITEM_QUALITY_POOR].size()); + LOG_INFO("module.ahbot", "Loaded {} white items", _itemsBin[AHB_ITEM_QUALITY_NORMAL].size()); + LOG_INFO("module.ahbot", "Loaded {} green items", _itemsBin[AHB_ITEM_QUALITY_UNCOMMON].size()); + LOG_INFO("module.ahbot", "Loaded {} blue items", _itemsBin[AHB_ITEM_QUALITY_RARE].size()); + LOG_INFO("module.ahbot", "Loaded {} purple items", _itemsBin[AHB_ITEM_QUALITY_EPIC].size()); + LOG_INFO("module.ahbot", "Loaded {} orange items", _itemsBin[AHB_ITEM_QUALITY_LEGENDARY].size()); + LOG_INFO("module.ahbot", "Loaded {} yellow items", _itemsBin[AHB_ITEM_QUALITY_ARTIFACT].size()); + + return true; + /* + AuctionHouseBot: + 5957 disabled items + loaded 5 grey trade goods + loaded 471 white trade goods + loaded 58 green trade goods + loaded 26 blue trade goods + loaded 3 purple trade goods + loaded 1 orange trade goods + loaded 0 yellow trade goods + loaded 1633 grey items + loaded 2771 white items + loaded 5520 green items + loaded 1645 blue items + loaded 809 purple items + loaded 0 orange items + loaded 1 yellow items + */ + +} + diff --git a/src/ItemIndex.h b/src/ItemIndex.h new file mode 100644 index 0000000..e61f57b --- /dev/null +++ b/src/ItemIndex.h @@ -0,0 +1,53 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef ITEM_INDEX_H +#define ITEM_INDEX_H + +#include "ObjectGuid.h" +#include "ItemTemplate.h" +#include "AuctionHouseBotConfig.h" +#include "DatabaseEnvFwd.h" +#include +#include + +class AuctionHouseIndex +{ +public: + AuctionHouseIndex() = default; + ~AuctionHouseIndex() = default; + + static AuctionHouseIndex* instance(); + + bool InitializeItemsToSell(); + + const std::vector& GetItemBin(uint32 quality) const + { + return _itemsBin[quality]; + } + +private: + + + std::array, AHB_MAX_QUALITY> _itemsBin{}; + +}; + + +#define sAHIndex AuctionHouseIndex::instance() + +#endif