From 5189b72de903ea73d38b9f2a73611676d0a31510 Mon Sep 17 00:00:00 2001 From: Kewin Rausch Date: Thu, 22 Aug 2024 16:39:15 +0200 Subject: [PATCH] Overall cleanup and extension of the mod (#96) * Overall cleanup of the mod, separation of class sources, introduction of whitelist mechanism compatible with disabled item table (take precedence), new configuration options to regulate amount of elements sold in the market, their size and the elapsed time * Fixed a bug which caused the seller to propose stack going over the given limit * No changes, just the script classes being organized in their own source and header files * Configuration moved from the bot to its own class; extended the bot to support multiple instances active at once --- conf/mod_ahbot.conf.dist | 65 + src/AuctionHouseBot.cpp | 2572 +++++++--------- src/AuctionHouseBot.h | 1267 +------- src/AuctionHouseBotAuctionHouseScript.cpp | 213 ++ src/AuctionHouseBotAuctionHouseScript.h | 30 + src/AuctionHouseBotCommon.cpp | 18 + src/AuctionHouseBotCommon.h | 104 + src/AuctionHouseBotConfig.cpp | 3334 +++++++++++++++++++++ src/AuctionHouseBotConfig.h | 356 +++ src/AuctionHouseBotMailScript.cpp | 33 + src/AuctionHouseBotMailScript.h | 23 + src/AuctionHouseBotScript.cpp | 94 +- src/AuctionHouseBotWorldScript.cpp | 122 + src/AuctionHouseBotWorldScript.h | 23 + src/cs_ah_bot.cpp | 275 +- 15 files changed, 5658 insertions(+), 2871 deletions(-) create mode 100644 src/AuctionHouseBotAuctionHouseScript.cpp create mode 100644 src/AuctionHouseBotAuctionHouseScript.h create mode 100644 src/AuctionHouseBotCommon.cpp create mode 100644 src/AuctionHouseBotCommon.h create mode 100644 src/AuctionHouseBotConfig.cpp create mode 100644 src/AuctionHouseBotConfig.h create mode 100644 src/AuctionHouseBotMailScript.cpp create mode 100644 src/AuctionHouseBotMailScript.h create mode 100644 src/AuctionHouseBotWorldScript.cpp create mode 100644 src/AuctionHouseBotWorldScript.h diff --git a/conf/mod_ahbot.conf.dist b/conf/mod_ahbot.conf.dist index 26d8fdf..f4e3762 100644 --- a/conf/mod_ahbot.conf.dist +++ b/conf/mod_ahbot.conf.dist @@ -7,10 +7,30 @@ # Enable/Disable Debugging output # Default 0 (disabled) # +# AuctionHouseBot.DEBUG_CONFIG +# Enable/Disable Debugging output from the configuration +# Default 0 (disabled) +# # AuctionHouseBot.DEBUG_FILTERS # Enable/Disable Debugging output from Filters # Default 0 (disabled) # +# AuctionHouseBot.DEBUG_BUYER +# Enable/Disable Debugging output from buyer +# Default 0 (disabled) +# +# AuctionHouseBot.DEBUG_SELLER +# Enable/Disable Debugging output from seller +# Default 0 (disabled) +# +# AuctionHouseBot.TRACE_SELLER +# Enable/Disable tracing for the sold items +# Default 0 (disabled) +# +# AuctionHouseBot.TRACE_BUYER +# Enable/Disable tracing for the bought items +# Default 0 (disabled) +# # AuctionHouseBot.EnableSeller # Enable/Disable the part of AHBot that puts items up for auction # Default 0 (disabled) @@ -39,10 +59,39 @@ # Number of Items to Add/Remove from the AH during mass operations # Default 200 # +# AuctionHouseBot.ConsiderOnlyBotAuctions +# Ignore player auctions and consider only bot ones when keeping track of the numer of auctions in place. +# This allow to keep a background noise in the market even when lot of players are in. +# Default 0 (False) +# +# AuctionHouseBot.DuplicatesCount +# The maximum amount of duplicates stacks present in the market sold by the bot. +# If set to zero then no limits are set in place. +# Default 0 +# +# AuctionHouseBot.DivisibleStacks +# Sell items in stack sizes which depends on the maximum amount per stack. +# For example, an item with max stack size 20 will be sold in 5, 10 15 and 20 stacks, and not at random. +# Default 0 (False) +# +# AuctionHouseBot.ElapsingTimeClass +# The elapsing time for the sold items. There are three classes: +# 0 = long, auctions lasts from one to three days +# 1 = medium, auctions lasts within a day +# 2 = shorts, auctions lasts within an hour +# Default 1 +# +# ############################################################################### AuctionHouseBot.DEBUG = 0 +AuctionHouseBot.DEBUG_CONFIG = 0 AuctionHouseBot.DEBUG_FILTERS = 0 +AuctionHouseBot.DEBUG_BUYER = 0 +AuctionHouseBot.DEBUG_SELLER = 0 +AuctionHouseBot.TRACE_SELLER = 0 +AuctionHouseBot.TRACE_BUYER = 0 + AuctionHouseBot.EnableSeller = 0 AuctionHouseBot.EnableBuyer = 0 AuctionHouseBot.UseBuyPriceForSeller = 0 @@ -50,6 +99,10 @@ AuctionHouseBot.UseBuyPriceForBuyer = 0 AuctionHouseBot.Account = 0 AuctionHouseBot.GUID = 0 AuctionHouseBot.ItemsPerCycle = 200 +AuctionHouseBot.ConsiderOnlyBotAuctions = 0 +AuctionHouseBot.DuplicatesCount = 0 +AuctionHouseBot.DivisibleStacks = 0 +AuctionHouseBot.ElapsingTimeClass = 1 ############################################################################### # AUCTION HOUSE BOT FILTERS PART 1 @@ -264,3 +317,15 @@ AuctionHouseBot.DisableItemsBelowReqSkillRank = 0 AuctionHouseBot.DisableItemsAboveReqSkillRank = 0 AuctionHouseBot.DisableTGsBelowReqSkillRank = 0 AuctionHouseBot.DisableTGsAboveReqSkillRank = 0 + +############################################################################### +# AUCTION HOUSE BOT FILTERS PART 4 +# +# AuctionHouseBot.SellerWhiteList +# Bypass the values of the disabled items table and only allows selling of the selected items +# Values here must be the item template id separated with a comma (eg "1, 2, 3") +# Default "" (Empty) +# +############################################################################### + +AuctionHouseBot.SellerWhiteList = "" diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index b2730b7..65a6646 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -19,564 +19,295 @@ #include "ObjectMgr.h" #include "AuctionHouseMgr.h" -#include "AuctionHouseBot.h" #include "Config.h" #include "Player.h" #include "WorldSession.h" #include "GameTime.h" #include "DatabaseEnv.h" -#include + +#include "AuctionHouseBot.h" +#include "AuctionHouseBotCommon.h" 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() + +AuctionHouseBot::AuctionHouseBot(uint32 account, uint32 id) { - 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; - DisableTGsAboveLevel = 0; - DisableItemsBelowGUID = 0; - DisableItemsAboveGUID = 0; - DisableTGsBelowGUID = 0; - DisableTGsAboveGUID = 0; - DisableItemsBelowReqLevel = 0; - DisableItemsAboveReqLevel = 0; - DisableTGsBelowReqLevel = 0; - DisableTGsAboveReqLevel = 0; - DisableItemsBelowReqSkillRank = 0; - DisableItemsAboveReqSkillRank = 0; - DisableTGsBelowReqSkillRank = 0; - DisableTGsAboveReqSkillRank = 0; - - //End Filters - - _lastrun_a = time(NULL); - _lastrun_h = time(NULL); - _lastrun_n = time(NULL); - - AllianceConfig = AHBConfig(2); - HordeConfig = AHBConfig(6); - NeutralConfig = AHBConfig(7); + _account = account; + _id = id; + + _lastrun_a_sec = time(NULL); + _lastrun_h_sec = time(NULL); + _lastrun_n_sec = time(NULL); + + _allianceConfig = NULL; + _hordeConfig = NULL; + _neutralConfig = NULL; } AuctionHouseBot::~AuctionHouseBot() { + // Nothing } -void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) +uint32 AuctionHouseBot::getElement(std::set set, int index) { - if (!AHBSeller) - { - if (debug_Out) - LOG_INFO("module", "AHSeller: Disabled"); - return; - } - - uint32 minItems = config->GetMinItems(); - uint32 maxItems = config->GetMaxItems(); + std::set::iterator it = set.begin(); + std::advance(it, index); - if (maxItems == 0) - { - //if (debug_Out) sLog->outString( "AHSeller: Auctions disabled"); - return; - } + return *it; +} - AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntry(config->GetAHFID()); - if (!ahEntry) - { - return; - } - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); - if (!auctionHouse) +uint32 AuctionHouseBot::getStackCount(AHBConfig* config, uint32 max) +{ + if (max == 1) { - return; + return 1; } - uint32 auctions = auctionHouse->Getcount(); - - uint32 items = 0; + // + // Organize the stacks in a pseudo random way + // - if (auctions >= minItems) + if (config->DivisibleStacks) { - if (debug_Out) - LOG_ERROR("module", "AHSeller: Auctions above minimum"); - return; - } + uint32 ret = 0; - if (auctions >= maxItems) - { - if (debug_Out) - LOG_ERROR("module", "AHSeller: Auctions at or above maximum"); - return; - } + if (max % 5 == 0) // 5, 10, 15, 20 + { + ret = urand(1, 4) * 5; + } - if ((maxItems - auctions) >= ItemsPerCycle) - items = ItemsPerCycle; - else - items = (maxItems - auctions); + if (max % 4 == 0) // 4, 8, 12, 16 + { + ret = urand(1, 4) * 4; + } - 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); - - // 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); + if (max % 3 == 0) // 3, 6, 9 + { + ret = urand(1, 3) * 3; + } - uint32 itemID = 0; - uint32 itemColor = 99; - uint32 loopbreaker = 0; - while (itemID == 0 && loopbreaker <= 50) + if (ret > max) { - ++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; - } - } + ret = max; + } - if (itemID == 0) - { - if (debug_Out) - LOG_ERROR("module", "AHSeller: Item::CreateItem() - ItemID is 0"); - continue; - } + return ret; + } - ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(itemID); - if (prototype == NULL) - { - if (debug_Out) - LOG_ERROR("module", "AHSeller: Huh?!?! prototype == NULL"); - continue; - } + // + // Totally random + // - Item* item = Item::CreateItem(itemID, 1, AHBplayer); - if (item == NULL) - { - if (debug_Out) - LOG_ERROR("module", "AHSeller: Item::CreateItem() returned NULL"); - break; - } - item->AddToUpdateQueueOf(AHBplayer); + return urand(1, max); +} - uint32 randomPropertyId = Item::GenerateItemRandomPropertyId(itemID); - if (randomPropertyId != 0) - item->SetItemRandomProperties(randomPropertyId); +uint32 AuctionHouseBot::getElapsedTime(uint32 timeClass) +{ + switch (timeClass) + { + case 2: + return urand(1, 5) * 600; // SHORT = In the range of one hour - uint64 buyoutPrice = 0; - uint64 bidPrice = 0; - uint32 stackCount = 1; + case 1: + return urand(1, 23) * 3600; // MEDIUM = In the range of one day - if (SellMethod) - buyoutPrice = prototype->BuyPrice; - else - buyoutPrice = prototype->SellPrice; + default: + return urand(1, 3) * 86400; // LONG = More than one day but less than three + } +} - if (prototype->Quality <= AHB_MAX_QUALITY) - { - if (config->GetMaxStack(prototype->Quality) > 1 && item->GetMaxStackCount() > 1) - stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(prototype->Quality))); - else if (config->GetMaxStack(prototype->Quality) == 0 && item->GetMaxStackCount() > 1) - 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)); - bidPrice /= 100; - } - 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); - item->RemoveFromUpdateQueueOf(AHBplayer); - continue; - } +uint32 AuctionHouseBot::getNofAuctions(AHBConfig* config, AuctionHouseObject* auctionHouse, ObjectGuid guid) +{ + // + // All the auctions + // - uint32 etime = urand(1,3); - switch(etime) - { - case 1: - etime = 43200; - break; - case 2: - etime = 86400; - break; - case 3: - etime = 172800; - break; - default: - etime = 86400; - break; - } - item->SetCount(stackCount); + if (!config->ConsiderOnlyBotAuctions) + { + return auctionHouse->Getcount(); + } - uint32 dep = sAuctionMgr->GetAuctionDeposit(ahEntry, etime, item, stackCount); + // + // Just the one handled by the bot + // - auto trans = CharacterDatabase.BeginTransaction(); - AuctionEntry* auctionEntry = new AuctionEntry(); - auctionEntry->Id = sObjectMgr->GenerateAuctionID(); - auctionEntry->houseId = config->GetAHID(); - auctionEntry->item_guid = item->GetGUID(); - auctionEntry->item_template = item->GetEntry(); - auctionEntry->itemCount = item->GetCount(); - auctionEntry->owner = AHBplayer->GetGUID(); - auctionEntry->startbid = bidPrice * stackCount; - auctionEntry->buyout = buyoutPrice * stackCount; - auctionEntry->bid = 0; - auctionEntry->deposit = dep; - auctionEntry->expire_time = (time_t) etime + time(NULL); - auctionEntry->auctionHouseEntry = ahEntry; - item->SaveToDB(trans); - item->RemoveFromUpdateQueueOf(AHBplayer); - sAuctionMgr->AddAItem(item); - auctionHouse->AddAuction(auctionEntry); - auctionEntry->SaveToDB(trans); - CharacterDatabase.CommitTransaction(trans); + uint32 count = 0; - 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; - } + for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr) + { + AuctionEntry* Aentry = itr->second; + + if (guid == Aentry->owner) + { + count++; + break; } } + + return count; } -void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, WorldSession *session) + +// ============================================================================= +// This routine performs the bidding operations for the bot +// ============================================================================= + +void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* session) { - if (!AHBBuyer) + // + // Check if disabled + // + + if (!config->AHBBuyer) { - if (debug_Out) - LOG_ERROR("module", "AHBuyer: Disabled"); return; } - QueryResult result = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE itemowner<>{} AND buyguid<>{}", AHBplayerGUID, AHBplayerGUID); + // + // Retrieve items not owner by the bot and not bought by the bot + // + + QueryResult result = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE itemowner<>{} AND buyguid<>{}", _id, _id); if (!result) + { return; + } if (result->GetRowCount() == 0) + { return; + } - // Fetches content of selected AH - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); - vector possibleBids; + // + // Fetches content of selected AH to look for possible bids + // + + AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); + std::set possibleBids; do { uint32 tmpdata = result->Fetch()->Get(); - possibleBids.push_back(tmpdata); - }while (result->NextRow()); + possibleBids.insert(tmpdata); + } while (result->NextRow()); - for (uint32 count = 1; count <= config->GetBidsPerInterval(); ++count) + // + // If it's not possible to bid stop here + // + + if (possibleBids.empty()) { - // Do we have anything to bid? If not, stop here. - if (possibleBids.empty()) + if (config->DebugOutBuyer) { - //if (debug_Out) sLog->outError( "AHBuyer: I have no items to bid on."); - count = config->GetBidsPerInterval(); - continue; + LOG_INFO("module", "AHBot [{}]: no auctions to bid on has been recovered", _id); } - // Choose random auction from possible auctions - uint32 vectorPos = urand(0, possibleBids.size() - 1); - vector::iterator iter = possibleBids.begin(); - advance(iter, vectorPos); + return; + } - // from auctionhousehandler.cpp, creates auction pointer & player pointer - AuctionEntry* auction = auctionHouse->GetAuction(*iter); + // + // Perform the operation for a maximum amount of bids attempts configured + // - // Erase the auction from the vector to prevent bidding on item in next iteration. - possibleBids.erase(iter); + for (uint32 count = 1; count <= config->GetBidsPerInterval(); ++count) + { + // + // Choose a random auction from possible auctions + // + + uint32 randBid = urand(0, possibleBids.size() - 1); + + std::set::iterator it = possibleBids.begin(); + std::advance(it, randBid); + + AuctionEntry* auction = auctionHouse->GetAuction(*it); + + // + // Prevent to bid again on the same auction + // + + possibleBids.erase(randBid); if (!auction) + { continue; + } + + // + // Prevent from buying items from the other bots + // + + if (gBotsId.find(auction->owner.GetCounter()) != gBotsId.end()) + { + continue; + } + + // + // Get the item information + // + + Item* pItem = sAuctionMgr->GetAItem(auction->item_guid); - // get exact item information - 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()); + if (config->DebugOutBuyer) + { + LOG_ERROR("module", "AHBot [{}]: item {} doesn't exist, perhaps bought already?", _id, auction->item_guid.ToString()); + } + continue; } - // get item prototype + // + // Get the item prototype + // + ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template); - // check which price we have to use, startbid or if it is bidded already + // + // Check which price we have to use, startbid or if it is bidded already + // + uint32 currentprice; + if (auction->bid) + { currentprice = auction->bid; + } else + { currentprice = auction->startbid; + } + // // Prepare portion from maximum bid - double bidrate = static_cast(urand(1, 100)) / 100; - long double bidMax = 0; + // + + double bidrate = static_cast(urand(1, 100)) / 100; + long double bidMax = 0; - // check that bid has acceptable value and take bid based on vendorprice, stacksize and quality - if (BuyMethod) + // + // Check that bid has an acceptable value and take bid based on vendorprice, stacksize and quality + // + + if (config->BuyMethod) { if (prototype->Quality <= AHB_MAX_QUALITY) { if (currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(prototype->Quality)) + { bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(prototype->Quality); + } } 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; + if (config->DebugOutBuyer) + { + LOG_ERROR("module", "AHBot [{}]: Quality {} not Supported", _id, prototype->Quality); + } + + continue; } } else @@ -584,18 +315,25 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con if (prototype->Quality <= AHB_MAX_QUALITY) { if (currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(prototype->Quality)) + { bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(prototype->Quality); + } } 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; + if (config->DebugOutBuyer) + { + LOG_ERROR("module", "AHBot [{}]: Quality {} not Supported", _id, prototype->Quality); + } + + continue; } } - // check some special items, and do recalculating to their prices + // + // Recalculate the bid depending on the type of the item + // + switch (prototype->Class) { // ammo @@ -606,924 +344,895 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con break; } + // + // Test the computed bid + // + if (bidMax == 0) { - // quality check failed to get bidmax, let's get out of here continue; } + // // Calculate our bid + // + long double bidvalue = currentprice + ((bidMax - currentprice) * bidrate); - // Convert to uint32 - uint32 bidprice = static_cast(bidvalue); + uint32 bidprice = static_cast(bidvalue); + // // Check our bid is high enough to be valid. If not, correct it to minimum. + // + if ((currentprice + auction->GetAuctionOutBid()) > bidprice) + { bidprice = currentprice + auction->GetAuctionOutBid(); + } + // + // Print out debug info + // - if (debug_Out) + if (config->DebugOutBuyer) { LOG_INFO("module", "-------------------------------------------------"); - LOG_INFO("module", "AHBuyer: Info for Auction #{}:", auction->Id); - LOG_INFO("module", "AHBuyer: AuctionHouse: {}", auction->GetHouseId()); - LOG_INFO("module", "AHBuyer: Owner: {}", auction->owner.ToString()); - LOG_INFO("module", "AHBuyer: Bidder: {}", auction->bidder.ToString()); - LOG_INFO("module", "AHBuyer: Starting Bid: {}", auction->startbid); - LOG_INFO("module", "AHBuyer: Current Bid: {}", currentprice); - LOG_INFO("module", "AHBuyer: Buyout: {}", auction->buyout); - LOG_INFO("module", "AHBuyer: Deposit: {}", auction->deposit); - LOG_INFO("module", "AHBuyer: Expire Time: {}", uint32(auction->expire_time)); - LOG_INFO("module", "AHBuyer: Bid Rate: {}", bidrate); - LOG_INFO("module", "AHBuyer: Bid Max: {}", bidMax); - LOG_INFO("module", "AHBuyer: Bid Value: {}", bidvalue); - LOG_INFO("module", "AHBuyer: Bid Price: {}", bidprice); - LOG_INFO("module", "AHBuyer: Item GUID: {}", auction->item_guid.ToString()); - LOG_INFO("module", "AHBuyer: Item Template: {}", auction->item_template); - LOG_INFO("module", "AHBuyer: Item Info:"); - LOG_INFO("module", "AHBuyer: Item ID: {}", prototype->ItemId); - LOG_INFO("module", "AHBuyer: Buy Price: {}", prototype->BuyPrice); - LOG_INFO("module", "AHBuyer: Sell Price: {}", prototype->SellPrice); - LOG_INFO("module", "AHBuyer: Bonding: {}", prototype->Bonding); - LOG_INFO("module", "AHBuyer: Quality: {}", prototype->Quality); - LOG_INFO("module", "AHBuyer: Item Level: {}", prototype->ItemLevel); - LOG_INFO("module", "AHBuyer: Ammo Type: {}", prototype->AmmoType); + LOG_INFO("module", "AHBot [{}]: Info for Auction #{}:", _id, auction->Id); + LOG_INFO("module", "AHBot [{}]: AuctionHouse: {}" , _id, auction->GetHouseId()); + LOG_INFO("module", "AHBot [{}]: Owner: {}" , _id, auction->owner.ToString()); + LOG_INFO("module", "AHBot [{}]: Bidder: {}" , _id, auction->bidder.ToString()); + LOG_INFO("module", "AHBot [{}]: Starting Bid: {}" , _id, auction->startbid); + LOG_INFO("module", "AHBot [{}]: Current Bid: {}" , _id, currentprice); + LOG_INFO("module", "AHBot [{}]: Buyout: {}" , _id, auction->buyout); + LOG_INFO("module", "AHBot [{}]: Deposit: {}" , _id, auction->deposit); + LOG_INFO("module", "AHBot [{}]: Expire Time: {}" , _id, uint32(auction->expire_time)); + LOG_INFO("module", "AHBot [{}]: Bid Rate: {}" , _id, bidrate); + LOG_INFO("module", "AHBot [{}]: Bid Max: {}" , _id, bidMax); + LOG_INFO("module", "AHBot [{}]: Bid Value: {}" , _id, bidvalue); + LOG_INFO("module", "AHBot [{}]: Bid Price: {}" , _id, bidprice); + LOG_INFO("module", "AHBot [{}]: Item GUID: {}" , _id, auction->item_guid.ToString()); + LOG_INFO("module", "AHBot [{}]: Item Template: {}" , _id, auction->item_template); + LOG_INFO("module", "AHBot [{}]: Item Info:"); + LOG_INFO("module", "AHBot [{}]: Item ID: {}" , _id, prototype->ItemId); + LOG_INFO("module", "AHBot [{}]: Buy Price: {}" , _id, prototype->BuyPrice); + LOG_INFO("module", "AHBot [{}]: Sell Price: {}" , _id, prototype->SellPrice); + LOG_INFO("module", "AHBot [{}]: Bonding: {}" , _id, prototype->Bonding); + LOG_INFO("module", "AHBot [{}]: Quality: {}" , _id, prototype->Quality); + LOG_INFO("module", "AHBot [{}]: Item Level: {}" , _id, prototype->ItemLevel); + LOG_INFO("module", "AHBot [{}]: Ammo Type: {}" , _id, prototype->AmmoType); LOG_INFO("module", "-------------------------------------------------"); } + // // Check whether we do normal bid, or buyout + // + + bool bought = false; + if ((bidprice < auction->buyout) || (auction->buyout == 0)) { + // + // Perform a new bid on the auction + // + if (auction->bidder) { - if (auction->bidder == AHBplayer->GetGUID()) + if (auction->bidder != AHBplayer->GetGUID()) { - //pl->ModifyMoney(-int32(price - auction->bid)); - } - else - { - // mail to last bidder and return money + // + // Mail to last bidder and return their money + // + auto trans = CharacterDatabase.BeginTransaction(); + sAuctionMgr->SendAuctionOutbiddedMail(auction, bidprice, session->GetPlayer(), trans); - CharacterDatabase.CommitTransaction(trans); - //pl->ModifyMoney(-int32(price)); + CharacterDatabase.CommitTransaction (trans); } - } + } auction->bidder = AHBplayer->GetGUID(); - auction->bid = bidprice; + auction->bid = bidprice; + + // + // Save the auction into database + // - // 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 { + bought = true; + + // + // Perform the buyout + // + auto trans = CharacterDatabase.BeginTransaction(); - //buyout + if ((auction->bidder) && (AHBplayer->GetGUID() != auction->bidder)) { + // + // Send the mail to the last bidder + // + sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, session->GetPlayer(), trans); } + auction->bidder = AHBplayer->GetGUID(); - auction->bid = auction->buyout; + auction->bid = auction->buyout; + // // Send mails to buyer & seller - //sAuctionMgr->SendAuctionSalePendingMail(auction, trans); + // + sAuctionMgr->SendAuctionSuccessfulMail(auction, trans); - sAuctionMgr->SendAuctionWonMail(auction, trans); + sAuctionMgr->SendAuctionWonMail (auction, trans); + + // + // Removes any trace of the item + // + auction->DeleteFromDB(trans); - sAuctionMgr->RemoveAItem(auction->item_guid); + sAuctionMgr->RemoveAItem (auction->item_guid); auctionHouse->RemoveAuction(auction); + CharacterDatabase.CommitTransaction(trans); } + + // + // Tracing + // + + if (config->TraceBuyer) + { + if (bought) + { + LOG_INFO("module", "AHBot [{}]: Bought , id={}, ah={}, item={}, start={}, current={}, buyout={}", _id, auction->Id, auction->GetHouseId(), auction->item_template, auction->startbid, currentprice, auction->buyout); + } + else + { + LOG_INFO("module", "AHBot [{}]: New bid, id={}, ah={}, item={}, start={}, current={}, buyout={}", _id, auction->Id, auction->GetHouseId(), auction->item_template, auction->startbid, currentprice, auction->buyout); + } + } } } -void AuctionHouseBot::Update() +// ============================================================================= +// This routine performs the selling operations for the bot +// ============================================================================= + +void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) { - time_t _newrun = time(NULL); - if ((!AHBSeller) && (!AHBBuyer)) + // + // Check if disabled + // + + if (!config->AHBSeller) + { return; + } - std::string accountName = "AuctionHouseBot" + std::to_string(AHBplayerAccount); + // + // Check the given limits + // - 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); + uint32 minItems = config->GetMinItems(); + uint32 maxItems = config->GetMaxItems(); - // Add New Bids - if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) + if (maxItems == 0) { - addNewAuctions(&_AHBplayer, &AllianceConfig); - if (((_newrun - _lastrun_a) >= (AllianceConfig.GetBiddingInterval() * MINUTE)) && (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; - } - - addNewAuctions(&_AHBplayer, &HordeConfig); - if (((_newrun - _lastrun_h) >= (HordeConfig.GetBiddingInterval() * MINUTE)) && (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; - } + return; } - addNewAuctions(&_AHBplayer, &NeutralConfig); - if (((_newrun - _lastrun_n) >= (NeutralConfig.GetBiddingInterval() * MINUTE)) && (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; - } - ObjectAccessor::RemoveObject(&_AHBplayer); -} + // + // Retrieve the auction house situation + // -void AuctionHouseBot::Initialize() -{ - DisableItemStore.clear(); - QueryResult result = WorldDatabase.Query("SELECT item FROM mod_auctionhousebot_disabled_items"); + AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntry(config->GetAHFID()); - if (result) + if (!ahEntry) { - do - { - Field* fields = result->Fetch(); - DisableItemStore.insert(fields[0].Get()); - } while (result->NextRow()); + return; } - //End Filters - if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) + AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); + + if (!auctionHouse) { - LoadValues(&AllianceConfig); - LoadValues(&HordeConfig); + return; } - LoadValues(&NeutralConfig); - // - // check if the AHBot account/GUID in the config actually exists - // + auctionHouse->Update(); + + // + // Check if we are clear to proceed + // - if ((AHBplayerAccount != 0) || (AHBplayerGUID != 0)) + bool aboveMin = false; + bool aboveMax = false; + uint32 auctions = getNofAuctions(config, auctionHouse, AHBplayer->GetGUID()); + uint32 items = 0; + + if (auctions >= minItems) { - QueryResult result = CharacterDatabase.Query("SELECT 1 FROM characters WHERE account = {} AND guid = {}", AHBplayerAccount, AHBplayerGUID); - if (!result) + aboveMin = true; + + if (config->DebugOutSeller) { - LOG_ERROR("module", "AuctionHouseBot: The account/GUID-information set for your AHBot is incorrect (account: {} guid: {})", AHBplayerAccount, AHBplayerGUID); - return; + LOG_ERROR("module", "AHBot [{}]: Auctions above minimum", _id); } + + return; } - if (AHBSeller) + if (auctions >= maxItems) { - QueryResult results = QueryResult(NULL); - char npcQuery[] = "SELECT distinct item FROM npc_vendor"; - results = WorldDatabase.Query(npcQuery); - if (results) - { - do - { - Field* fields = results->Fetch(); - npcItems.push_back(fields[0].Get()); + aboveMax = true; - } while (results->NextRow()); - } - else + if (config->DebugOutSeller) { - if (debug_Out) - LOG_ERROR("module", "AuctionHouseBot: \"{}\" failed", npcQuery); + LOG_ERROR("module", "AHBot [{}]: Auctions at or above maximum", _id); } - char 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) + return; + } + + if ((maxItems - auctions) >= config->ItemsPerCycle) + { + items = config->ItemsPerCycle; + } + else + { + items = (maxItems - auctions); + } + + // + // Retrieve the configuration for this run + // + + uint32 greyTGcount = config->GetMaximum(AHB_GREY_TG); + uint32 whiteTGcount = config->GetMaximum(AHB_WHITE_TG); + uint32 greenTGcount = config->GetMaximum(AHB_GREEN_TG); + uint32 blueTGcount = config->GetMaximum(AHB_BLUE_TG); + uint32 purpleTGcount = config->GetMaximum(AHB_PURPLE_TG); + uint32 orangeTGcount = config->GetMaximum(AHB_ORANGE_TG); + uint32 yellowTGcount = config->GetMaximum(AHB_YELLOW_TG); + + uint32 greyIcount = config->GetMaximum(AHB_GREY_I); + uint32 whiteIcount = config->GetMaximum(AHB_WHITE_I); + uint32 greenIcount = config->GetMaximum(AHB_GREEN_I); + uint32 blueIcount = config->GetMaximum(AHB_BLUE_I); + uint32 purpleIcount = config->GetMaximum(AHB_PURPLE_I); + uint32 orangeIcount = config->GetMaximum(AHB_ORANGE_I); + uint32 yellowIcount = config->GetMaximum(AHB_YELLOW_I); + + 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); + + // + // Only insert a few at a time, so they dont appear all at once + // + + uint32 noSold = 0; // Tracing counter + uint32 binEmpty = 0; // Tracing counter + uint32 noNeed = 0; // Tracing counter + uint32 tooMany = 0; // Tracing counter + uint32 loopBrk = 0; // Tracing counter + uint32 err = 0; // Tracing counter + + for (uint32 cnt = 1; cnt <= items; cnt++) + { + uint32 itemID = 0; + uint32 loopbreaker = 0; + + // + // Attempts for some times to insert a single item stack as an auction. + // The attempt can be stopped by several internal checks. + // + + while (itemID == 0 && loopbreaker <= 32) { - do + ++loopbreaker; + + // + // Get a random item from the bins + // + + uint32 choice = urand(0, 13); + + switch (choice) { - Field* fields = results->Fetch(); - lootItems.push_back(fields[0].Get()); + case AHB_GREY_I: + if ((config->GreyItemsBin.size() > 0) && (greyItems < greyIcount)) + { + itemID = getElement(config->GreyItemsBin, urand(0, config->GreyItemsBin.size() - 1)); + } + else + { + noNeed++; + continue; + } - } while (results->NextRow()); - } - else - { - if (debug_Out) - LOG_ERROR("module", "AuctionHouseBot: \"{}\" failed", lootQuery); - } + break; + + case AHB_WHITE_I: + if ((config->WhiteItemsBin.size() > 0) && (whiteItems < whiteIcount)) + { + itemID = getElement(config->WhiteItemsBin, urand(0, config->WhiteItemsBin.size() - 1)); + } + else + { + noNeed++; + continue; + } + + break; - ItemTemplateContainer const* its = sObjectMgr->GetItemTemplateStore(); - for (ItemTemplateContainer::const_iterator itr = its->begin(); itr != its->end(); ++itr) - { - switch (itr->second.Bonding) - { - case NO_BIND: - if (!No_Bind) + case AHB_GREEN_I: + if ((config->GreenItemsBin.size() > 0) && (greenItems < greenIcount)) + { + itemID = getElement(config->GreenItemsBin, urand(0, config->GreenItemsBin.size() - 1)); + } + else + { + noNeed++; continue; + } + break; - case BIND_WHEN_PICKED_UP: - if (!Bind_When_Picked_Up) + + case AHB_BLUE_I: + if ((config->BlueItemsBin.size() > 0) && (blueItems < blueIcount)) + { + itemID = getElement(config->BlueItemsBin, urand(0, config->BlueItemsBin.size() - 1)); + } + else + { + noNeed++; continue; + } + break; - case BIND_WHEN_EQUIPED: - if (!Bind_When_Equipped) + + case AHB_PURPLE_I: + if ((config->PurpleItemsBin.size() > 0) && (purpleItems < purpleIcount)) + { + itemID = getElement(config->PurpleItemsBin, urand(0, config->PurpleItemsBin.size() - 1)); + } + else + { + noNeed++; continue; + } + break; - case BIND_WHEN_USE: - if (!Bind_When_Use) + + case AHB_ORANGE_I: + if ((config->OrangeItemsBin.size() > 0) && (orangeItems < orangeIcount)) + { + itemID = getElement(config->OrangeItemsBin, urand(0, config->OrangeItemsBin.size() - 1)); + } + else + { + noNeed++; continue; + } + break; - case BIND_QUEST_ITEM: - if (!Bind_Quest_Item) + + case AHB_YELLOW_I: + if ((config->YellowItemsBin.size() > 0) && (yellowItems < yellowIcount)) + { + itemID = getElement(config->YellowItemsBin, urand(0, config->YellowItemsBin.size() - 1)); + } + else + { + noNeed++; continue; + } + break; - default: - continue; - break; - } - if (SellMethod) - { - if (itr->second.BuyPrice == 0) + case AHB_GREY_TG: + if ((config->GreyTradeGoodsBin.size() > 0) && (greyTGoods < greyTGcount)) + { + itemID = getElement(config->GreyTradeGoodsBin, urand(0, config->GreyTradeGoodsBin.size() - 1)); + } + else + { + noNeed++; continue; - } - else - { - if (itr->second.SellPrice == 0) + } + + break; + + case AHB_WHITE_TG: + if ((config->WhiteTradeGoodsBin.size() > 0) && (whiteTGoods < whiteTGcount)) + { + itemID = getElement(config->WhiteTradeGoodsBin, urand(0, config->WhiteTradeGoodsBin.size() - 1)); + } + else + { + noNeed++; continue; - } + } - if (itr->second.Quality > 6) - continue; + break; - if ((Vendor_Items == 0) && !(itr->second.Class == ITEM_CLASS_TRADE_GOODS)) - { - bool isVendorItem = false; + case AHB_GREEN_TG: + if ((config->GreenTradeGoodsBin.size() > 0) && (greenTGoods < greenTGcount)) + { + itemID = getElement(config->GreenTradeGoodsBin, urand(0, config->GreenTradeGoodsBin.size() - 1)); + } + else + { + noNeed++; + continue; + } + + break; - for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorItem); i++) + case AHB_BLUE_TG: + if ((config->BlueTradeGoodsBin.size() > 0) && (blueTGoods < blueTGcount)) + { + itemID = getElement(config->BlueTradeGoodsBin, urand(0, config->BlueTradeGoodsBin.size() - 1)); + } + else { - if (itr->second.ItemId == npcItems[i]) - isVendorItem = true; + noNeed++; + continue; } - if (isVendorItem) + break; + + case AHB_PURPLE_TG: + if ((config->PurpleTradeGoodsBin.size() > 0) && (purpleTGoods < purpleTGcount)) + { + itemID = getElement(config->PurpleTradeGoodsBin, urand(0, config->PurpleTradeGoodsBin.size() - 1)); + } + else + { + noNeed++; continue; - } + } - if ((Vendor_TGs == 0) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS)) - { - bool isVendorTG = false; + break; - for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorTG); i++) + case AHB_ORANGE_TG: + if ((config->OrangeTradeGoodsBin.size() > 0) && (orangeTGoods < orangeTGcount)) + { + itemID = getElement(config->OrangeTradeGoodsBin, urand(0, config->OrangeTradeGoodsBin.size() - 1)); + } + else { - if (itr->second.ItemId == npcItems[i]) - isVendorTG = true; + noNeed++; + continue; } - if (isVendorTG) + break; + + case AHB_YELLOW_TG: + if ((config->YellowTradeGoodsBin.size() > 0) && (yellowTGoods < yellowTGcount)) + { + itemID = getElement(config->YellowTradeGoodsBin, urand(0, config->YellowTradeGoodsBin.size() - 1)); + } + else + { + noNeed++; continue; - } + } - if ((Loot_Items == 0) && !(itr->second.Class == ITEM_CLASS_TRADE_GOODS)) - { - bool isLootItem = false; + break; + + default: + err++; - for (unsigned int i = 0; (i < lootItems.size()) && (!isLootItem); i++) + if (config->DebugOutSeller) { - if (itr->second.ItemId == lootItems[i]) - isLootItem = true; + LOG_ERROR("module", "AHBot [{}]: itemID Switch - Default Reached", _id); } - if (isLootItem) - continue; + break; } - if ((Loot_TGs == 0) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS)) + // + // Check if it's a valid selection + // + + if (itemID == 0) { - bool isLootTG = false; + binEmpty++; - for (unsigned int i = 0; (i < lootItems.size()) && (!isLootTG); i++) + if (config->DebugOutSeller) { - if (itr->second.ItemId == lootItems[i]) - isLootTG = true; + LOG_ERROR("module", "AHBot [{}]: No item could be selected in the bin {}", _id, choice); } - if (isLootTG) - continue; + continue; } - if ((Other_Items == 0) && !(itr->second.Class == ITEM_CLASS_TRADE_GOODS)) + // + // Check how many stacks of this items are sold by the bot. + // This avoid unfortunate rolls to overwhelm the market with the same products on low population, especially with whitelists. + // + + if (config->DuplicatesCount > 0) { - bool isVendorItem = false; - bool isLootItem = false; + uint32 noStacks = 0; - for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorItem); i++) + for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr) { - if (itr->second.ItemId == npcItems[i]) - isVendorItem = true; + AuctionEntry* Aentry = itr->second; + + if (AHBplayer->GetGUID() == Aentry->owner) + { + if (itemID == Aentry->item_template) + { + noStacks++; + } + } } - for (unsigned int i = 0; (i < lootItems.size()) && (!isLootItem); i++) + + if (noStacks >= config->DuplicatesCount) { - if (itr->second.ItemId == lootItems[i]) - isLootItem = true; - } - if ((!isLootItem) && (!isVendorItem)) + tooMany++; continue; + } } - if ((Other_TGs == 0) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS)) + // + // Retrieve information about the selected item + // + + ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(itemID); + + if (prototype == NULL) { - bool isVendorTG = false; - bool isLootTG = false; + err++; - for (unsigned int i = 0; (i < npcItems.size()) && (!isVendorTG); i++) - { - if (itr->second.ItemId == npcItems[i]) - isVendorTG = true; - } - for (unsigned int i = 0; (i < lootItems.size()) && (!isLootTG); i++) + if (config->DebugOutSeller) { - if (itr->second.ItemId == lootItems[i]) - isLootTG = true; + LOG_ERROR("module", "AHBot [{}]: could not get prototype of item {}", _id, itemID); } - if ((!isLootTG) && (!isVendorTG)) - continue; - } - // Disable items by Id - if (DisableItemStore.find(itr->second.ItemId) != DisableItemStore.end()) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (PTR/Beta/Unused Item)", itr->second.ItemId); continue; } - // Disable permanent enchants items - if ((DisablePermEnchant) && (itr->second.Class == ITEM_CLASS_PERMANENT)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Permanent Enchant Item)", itr->second.ItemId); - continue; - } + Item* item = Item::CreateItem(itemID, 1, AHBplayer); - // Disable conjured items - if ((DisableConjured) && (itr->second.IsConjuredConsumable())) + if (item == NULL) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Conjured Consumable)", itr->second.ItemId); - continue; - } + err++; - // Disable gems - if ((DisableGems) && (itr->second.Class == ITEM_CLASS_GEM)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Gem)", itr->second.ItemId); - continue; - } + if (config->DebugOutSeller) + { + LOG_ERROR("module", "AHBot [{}]: could not create item from prototype {}", _id, itemID); + } - // Disable money - if ((DisableMoney) && (itr->second.Class == ITEM_CLASS_MONEY)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Money)", itr->second.ItemId); - continue; + break; } - // Disable moneyloot - if ((DisableMoneyLoot) && (itr->second.MinMoneyLoot > 0)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (MoneyLoot)", itr->second.ItemId); - continue; - } + // + // Start interacting with the item by adding a random property + // - // Disable lootable items - if ((DisableLootable) && (itr->second.Flags & 4)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Lootable Item)", itr->second.ItemId); - continue; - } + item->AddToUpdateQueueOf(AHBplayer); - // Disable Keys - if ((DisableKeys) && (itr->second.Class == ITEM_CLASS_KEY)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Quest Item)", itr->second.ItemId); - continue; - } + uint32 randomPropertyId = Item::GenerateItemRandomPropertyId(itemID); - // Disable items with duration - if ((DisableDuration) && (itr->second.Duration > 0)) + if (randomPropertyId != 0) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Has a Duration)", itr->second.ItemId); - continue; + item->SetItemRandomProperties(randomPropertyId); } - // Disable items which are BOP or Quest Items and have a required level lower than the item level - if ((DisableBOP_Or_Quest_NoReqLevel) && ((itr->second.Bonding == BIND_WHEN_PICKED_UP || itr->second.Bonding == BIND_QUEST_ITEM) && (itr->second.RequiredLevel < itr->second.ItemLevel))) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (BOP or BQI and Required Level is less than Item Level)", itr->second.ItemId); - continue; - } + // + // Determine the price and stack size + // - // Disable items specifically for Warrior - if ((DisableWarriorItems) && (itr->second.AllowableClass == 1)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Warrior Item)", itr->second.ItemId); - continue; - } + uint64 buyoutPrice = 0; + uint64 bidPrice = 0; + uint32 stackCount = 1; - // Disable items specifically for Paladin - if ((DisablePaladinItems) && (itr->second.AllowableClass == 2)) + if (config->SellMethod) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Paladin Item)", itr->second.ItemId); - continue; + buyoutPrice = prototype->BuyPrice; } - - // Disable items specifically for Hunter - if ((DisableHunterItems) && (itr->second.AllowableClass == 4)) + else { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Hunter Item)", itr->second.ItemId); - continue; + buyoutPrice = prototype->SellPrice; } - // Disable items specifically for Rogue - if ((DisableRogueItems) && (itr->second.AllowableClass == 8)) + if (prototype->Quality <= AHB_MAX_QUALITY) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Rogue Item)", itr->second.ItemId); - continue; - } + if (config->GetMaxStack(prototype->Quality) > 1 && item->GetMaxStackCount() > 1) + { + stackCount = minValue(getStackCount(config, item->GetMaxStackCount()), config->GetMaxStack(prototype->Quality)); + } + else if (config->GetMaxStack(prototype->Quality) == 0 && item->GetMaxStackCount() > 1) + { + stackCount = getStackCount(config, item->GetMaxStackCount()); + } + else + { + stackCount = 1; + } - // Disable items specifically for Priest - if ((DisablePriestItems) && (itr->second.AllowableClass == 16)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Priest Item)", itr->second.ItemId); - continue; + buyoutPrice *= urand(config->GetMinPrice(prototype->Quality), config->GetMaxPrice(prototype->Quality)); + buyoutPrice /= 100; + bidPrice = buyoutPrice * urand(config->GetMinBidPrice(prototype->Quality), config->GetMaxBidPrice(prototype->Quality)); + bidPrice /= 100; } - - // Disable items specifically for DK - if ((DisableDKItems) && (itr->second.AllowableClass == 32)) + else { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (DK Item)", itr->second.ItemId); - continue; - } + err++; - // Disable items specifically for Shaman - if ((DisableShamanItems) && (itr->second.AllowableClass == 64)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Shaman Item)", itr->second.ItemId); - continue; - } + if (config->DebugOutSeller) + { + LOG_ERROR("module", "AHBot [{}]: Quality {} TOO HIGH for item {}", _id, prototype->Quality, itemID); + } - // Disable items specifically for Mage - if ((DisableMageItems) && (itr->second.AllowableClass == 128)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Mage Item)", itr->second.ItemId); + item->RemoveFromUpdateQueueOf(AHBplayer); continue; } - // Disable items specifically for Warlock - if ((DisableWarlockItems) && (itr->second.AllowableClass == 256)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Warlock Item)", itr->second.ItemId); - continue; - } + item->SetCount(stackCount); - // Disable items specifically for Unused Class - if ((DisableUnusedClassItems) && (itr->second.AllowableClass == 512)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Unused Item)", itr->second.ItemId); - continue; - } + // + // Determine the auction time + // - // Disable items specifically for Druid - if ((DisableDruidItems) && (itr->second.AllowableClass == 1024)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Druid Item)", itr->second.ItemId); - continue; - } + uint32 etime = getElapsedTime(config->ElapsingTimeClass); - // Disable Items below level X - if ((DisableItemsBelowLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel < DisableItemsBelowLevel)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); - continue; - } + // + // Determine the deposit + // - // Disable Items above level X - if ((DisableItemsAboveLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel > DisableItemsAboveLevel)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); - continue; - } + uint32 dep = sAuctionMgr->GetAuctionDeposit(ahEntry, etime, item, stackCount); - // Disable Trade Goods below level X - if ((DisableTGsBelowLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel < DisableTGsBelowLevel)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); - continue; - } + // + // Perform the auction + // - // Disable Trade Goods above level X - if ((DisableTGsAboveLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel > DisableTGsAboveLevel)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); - continue; - } + auto trans = CharacterDatabase.BeginTransaction(); - // Disable Items below GUID X - if ((DisableItemsBelowGUID) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId < DisableItemsBelowGUID)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); - continue; - } + AuctionEntry* auctionEntry = new AuctionEntry(); + auctionEntry->Id = sObjectMgr->GenerateAuctionID(); + auctionEntry->houseId = config->GetAHID(); + auctionEntry->item_guid = item->GetGUID(); + auctionEntry->item_template = item->GetEntry(); + auctionEntry->itemCount = item->GetCount(); + auctionEntry->owner = AHBplayer->GetGUID(); + auctionEntry->startbid = bidPrice * stackCount; + auctionEntry->buyout = buyoutPrice * stackCount; + auctionEntry->bid = 0; + auctionEntry->deposit = dep; + auctionEntry->expire_time = (time_t)etime + time(NULL); + auctionEntry->auctionHouseEntry = ahEntry; - // Disable Items above GUID X - if ((DisableItemsAboveGUID) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId > DisableItemsAboveGUID)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); - continue; - } + item->SaveToDB(trans); + item->RemoveFromUpdateQueueOf(AHBplayer); + sAuctionMgr->AddAItem(item); + auctionHouse->AddAuction(auctionEntry); + auctionEntry->SaveToDB(trans); - // Disable Trade Goods below GUID X - if ((DisableTGsBelowGUID) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId < DisableTGsBelowGUID)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); - continue; - } + CharacterDatabase.CommitTransaction(trans); - // Disable Trade Goods above GUID X - if ((DisableTGsAboveGUID) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId > DisableTGsAboveGUID)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); - continue; - } + // + // Increments the number of items presents in the auction + // - // Disable Items for level lower than X - if ((DisableItemsBelowReqLevel) && (itr->second.RequiredLevel < DisableItemsBelowReqLevel)) + switch (choice) { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); - continue; - } + case 0: + ++greyItems; + break; - // Disable Items for level higher than X - if ((DisableItemsAboveReqLevel) && (itr->second.RequiredLevel > DisableItemsAboveReqLevel)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); - continue; - } + case 1: + ++whiteItems; + break; - // Disable Trade Goods for level lower than X - if ((DisableTGsBelowReqLevel) && (itr->second.RequiredLevel < DisableTGsBelowReqLevel)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); - continue; - } + case 2: + ++greenItems; + break; - // Disable Trade Goods for level higher than X - if ((DisableTGsAboveReqLevel) && (itr->second.RequiredLevel > DisableTGsAboveReqLevel)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); - continue; - } + case 3: + ++blueItems; + break; - // Disable Items that require skill lower than X - if ((DisableItemsBelowReqSkillRank) && (itr->second.RequiredSkillRank < DisableItemsBelowReqSkillRank)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); - continue; - } + case 4: + ++purpleItems; + break; - // Disable Items that require skill higher than X - if ((DisableItemsAboveReqSkillRank) && (itr->second.RequiredSkillRank > DisableItemsAboveReqSkillRank)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); - continue; - } + case 5: + ++orangeItems; + break; - // Disable Trade Goods that require skill lower than X - if ((DisableTGsBelowReqSkillRank) && (itr->second.RequiredSkillRank < DisableTGsBelowReqSkillRank)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); - continue; - } + case 6: + ++yellowItems; + break; - // Disable Trade Goods that require skill higher than X - if ((DisableTGsAboveReqSkillRank) && (itr->second.RequiredSkillRank > DisableTGsAboveReqSkillRank)) - { - if (debug_Out_Filters) - LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); - continue; - } + case 7: + ++greyTGoods; + break; - 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); + case 8: + ++whiteTGoods; 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); + case 9: + ++greenTGoods; 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); + case 10: + ++blueTGoods; 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); + case 11: + ++purpleTGoods; 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); + case 12: + ++orangeTGoods; 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); + case 13: + ++yellowTGoods; 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); + default: break; } + + noSold++; + + if (config->TraceSeller) + { + LOG_INFO("module", "AHBot [{}]: New stack ah={}, id={}, stack={}, bid={}, buyout={}", _id, config->GetAHID(), itemID, stackCount, auctionEntry->startbid, auctionEntry->buyout); + } } - 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)) + if (itemID == 0 || loopbreaker > 50) { - LOG_ERROR("module", "AuctionHouseBot: No items"); - AHBSeller = 0; + loopBrk++; } - - 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", "AuctionHouseBot and AuctionHouseBuyer have been loaded."); + if (config->TraceSeller) + { + LOG_INFO("module", "AHBot [{}]: auctionhouse {}, req={}, sold={}, aboveMin={}, aboveMax={}, loopBrk={}, noNeed={}, tooMany={}, binEmpty={}, err={}", _id, config->GetAHID(), items, noSold, aboveMin, aboveMax, loopBrk, noNeed, tooMany, binEmpty, err); + } } -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); - BuyMethod = sConfigMgr->GetOption("AuctionHouseBot.UseBuyPriceForBuyer", false); - - 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); -} +// ============================================================================= +// Perform an update cycle +// ============================================================================= -void AuctionHouseBot::IncrementItemCounts(AuctionEntry* ah) +void AuctionHouseBot::Update() { - // from auctionhousehandler.cpp, creates auction pointer & player pointer + time_t _newrun = time(NULL); + + // + // If no configuration is associated, then stop here + // - // get exact item information - Item *pItem = sAuctionMgr->GetAItem(ah->item_guid); - if (!pItem) + if (!_allianceConfig && !_hordeConfig && !_neutralConfig) { - if (debug_Out) - LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", ah->item_guid.ToString()); return; } - // get item prototype - ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(ah->item_template); + // + // Preprare for operation + // + + std::string accountName = "AuctionHouseBot" + std::to_string(_account); - AHBConfig *config; + WorldSession _session(_account, std::move(accountName), nullptr, SEC_PLAYER, sWorld->getIntConfig(CONFIG_EXPANSION), 0, LOCALE_enUS, 0, false, false, 0); - AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(ah->GetHouseId()); - if (!ahEntry) - { - if (debug_Out) - LOG_ERROR("module", "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()); - config = &AllianceConfig; - } - else if (ahEntry->houseId == AUCTIONHOUSE_HORDE) - { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Horde", ah->GetHouseId()); - config = &HordeConfig; - } - else + Player _AHBplayer(&_session); + _AHBplayer.Initialize(_id); + + ObjectAccessor::AddObject(&_AHBplayer); + + // + // Perform update for the factions markets + // + + if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); - config = &NeutralConfig; - } + // + // Alliance + // - config->IncItemCounts(prototype->Class, prototype->Quality); -} + if (_allianceConfig) + { + Sell(&_AHBplayer, _allianceConfig); -void AuctionHouseBot::DecrementItemCounts(AuctionEntry* ah, uint32 itemEntry) -{ - // get item prototype - ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(itemEntry); + if (((_newrun - _lastrun_a_sec) >= (_allianceConfig->GetBiddingInterval() * MINUTE)) && (_allianceConfig->GetBidsPerInterval() > 0)) + { + Buy(&_AHBplayer, _allianceConfig, &_session); + _lastrun_a_sec = _newrun; + } + } - AHBConfig *config; + // + // Horde + // + + if (_hordeConfig) + { + Sell(&_AHBplayer, _hordeConfig); + + if (((_newrun - _lastrun_h_sec) >= (_hordeConfig->GetBiddingInterval() * MINUTE)) && (_hordeConfig->GetBidsPerInterval() > 0)) + { + Buy(&_AHBplayer, _hordeConfig, &_session); + _lastrun_h_sec = _newrun; + } + } - AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(ah->GetHouseId()); - if (!ahEntry) - { - if (debug_Out) - LOG_ERROR("module", "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()); - config = &AllianceConfig; - } - else if (ahEntry->houseId == AUCTIONHOUSE_HORDE) - { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Horde", ah->GetHouseId()); - config = &HordeConfig; } - else + + // + // Neutral + // + + if (_neutralConfig) { - if (debug_Out) - LOG_ERROR("module", "AHBot: {} returned as House Faction. Neutral", ah->GetHouseId()); - config = &NeutralConfig; + Sell(&_AHBplayer, _neutralConfig); + + if (((_newrun - _lastrun_n_sec) >= (_neutralConfig->GetBiddingInterval() * MINUTE)) && (_neutralConfig->GetBidsPerInterval() > 0)) + { + Buy(&_AHBplayer, _neutralConfig, &_session); + _lastrun_n_sec = _newrun; + } } - config->DecItemCounts(prototype->Class, prototype->Quality); + ObjectAccessor::RemoveObject(&_AHBplayer); } +// ============================================================================= +// Execute commands coming from the console +// ============================================================================= + void AuctionHouseBot::Commands(AHBotCommand command, uint32 ahMapID, uint32 col, char* args) { + // + // Retrieve the auction house configuration + // + AHBConfig *config = NULL; + switch (ahMapID) { case 2: - config = &AllianceConfig; + config = _allianceConfig; break; case 6: - config = &HordeConfig; + config = _hordeConfig; break; case 7: - config = &NeutralConfig; + config = _neutralConfig; break; } + + // + // Retrive the item quality + // + std::string color; + switch (col) { case AHB_GREY: @@ -1550,390 +1259,261 @@ void AuctionHouseBot::Commands(AHBotCommand command, uint32 ahMapID, uint32 col, default: break; } + + // + // Perform the command + // + switch (command) { - case AHBotCommand::ahexpire: + case AHBotCommand::buyer: + { + char* param1 = strtok(args, " "); + uint32 state = (uint32)strtoul(param1, NULL, 0); + + if (state == 0) + { + config->AHBBuyer = false; + LOG_ERROR("module", "AHBot: Buyer disabled from console"); + } + else + { + config->AHBBuyer = true; + LOG_ERROR("module", "AHBot: Buyer enabled from console"); + } + + break; + } + case AHBotCommand::seller: + { + char* param1 = strtok(args, " "); + uint32 state = (uint32)strtoul(param1, NULL, 0); + + if (state == 0) { - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); + config->AHBSeller = false; + LOG_ERROR("module", "AHBot: Seller disabled from console"); + } + else + { + config->AHBSeller = true; + LOG_ERROR("module", "AHBot: Seller enabled from console"); + } + + break; + } + case AHBotCommand::ahexpire: + { + AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); - AuctionHouseObject::AuctionEntryMap::iterator itr; - itr = auctionHouse->GetAuctionsBegin(); + AuctionHouseObject::AuctionEntryMap::iterator itr; + itr = auctionHouse->GetAuctionsBegin(); - while (itr != auctionHouse->GetAuctionsEnd()) + while (itr != auctionHouse->GetAuctionsEnd()) + { + if (itr->second->owner.GetCounter() == _id) { - if (itr->second->owner.GetCounter() == AHBplayerGUID) - { - itr->second->expire_time = GameTime::GetGameTime().count(); - uint32 id = itr->second->Id; - uint32 expire_time = itr->second->expire_time; - CharacterDatabase.Execute("UPDATE auctionhouse SET time = '{}' WHERE id = '{}'", expire_time, id); - } - ++itr; + // Expired NOW. + itr->second->expire_time = GameTime::GetGameTime().count(); + + uint32 id = itr->second->Id; + uint32 expire_time = itr->second->expire_time; + + CharacterDatabase.Execute("UPDATE auctionhouse SET time = '{}' WHERE id = '{}'", expire_time, id); } + + ++itr; } + break; + } case AHBotCommand::minitems: - { - char * param1 = strtok(args, " "); - uint32 minItems = (uint32) strtoul(param1, NULL, 0); - WorldDatabase.Execute("UPDATE mod_auctionhousebot SET minitems = '{}' WHERE auctionhouse = '{}'", minItems, ahMapID); - config->SetMinItems(minItems); - } + { + char * param1 = strtok(args, " "); + uint32 minItems = (uint32) strtoul(param1, NULL, 0); + + WorldDatabase.Execute("UPDATE mod_auctionhousebot SET minitems = '{}' WHERE auctionhouse = '{}'", minItems, ahMapID); + + config->SetMinItems(minItems); + break; + } case AHBotCommand::maxitems: - { - char * param1 = strtok(args, " "); - uint32 maxItems = (uint32) strtoul(param1, NULL, 0); - WorldDatabase.Execute("UPDATE mod_auctionhousebot SET maxitems = '{}' WHERE auctionhouse = '{}'", maxItems, ahMapID); - config->SetMaxItems(maxItems); - config->CalculatePercents(); - } + { + char * param1 = strtok(args, " "); + uint32 maxItems = (uint32) strtoul(param1, NULL, 0); + + WorldDatabase.Execute("UPDATE mod_auctionhousebot SET maxitems = '{}' WHERE auctionhouse = '{}'", maxItems, ahMapID); + + config->SetMaxItems(maxItems); + config->CalculatePercents(); break; + } case AHBotCommand::percentages: - { - char * param1 = strtok(args, " "); - char * param2 = strtok(NULL, " "); - char * param3 = strtok(NULL, " "); - char * param4 = strtok(NULL, " "); - char * param5 = strtok(NULL, " "); - char * param6 = strtok(NULL, " "); - char * param7 = strtok(NULL, " "); - char * param8 = strtok(NULL, " "); - char * param9 = strtok(NULL, " "); - char * param10 = strtok(NULL, " "); - char * param11 = strtok(NULL, " "); - char * param12 = strtok(NULL, " "); - char * param13 = strtok(NULL, " "); - char * param14 = strtok(NULL, " "); - uint32 greytg = (uint32) strtoul(param1, NULL, 0); - uint32 whitetg = (uint32) strtoul(param2, NULL, 0); - uint32 greentg = (uint32) strtoul(param3, NULL, 0); - uint32 bluetg = (uint32) strtoul(param4, NULL, 0); - uint32 purpletg = (uint32) strtoul(param5, NULL, 0); - uint32 orangetg = (uint32) strtoul(param6, NULL, 0); - uint32 yellowtg = (uint32) strtoul(param7, NULL, 0); - uint32 greyi = (uint32) strtoul(param8, NULL, 0); - uint32 whitei = (uint32) strtoul(param9, NULL, 0); - uint32 greeni = (uint32) strtoul(param10, NULL, 0); - uint32 bluei = (uint32) strtoul(param11, NULL, 0); - uint32 purplei = (uint32) strtoul(param12, NULL, 0); - uint32 orangei = (uint32) strtoul(param13, NULL, 0); - uint32 yellowi = (uint32) strtoul(param14, NULL, 0); - - 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); - trans->Append("UPDATE mod_auctionhousebot SET percentgreentradegoods = '{}' WHERE auctionhouse = '{}'", greentg, ahMapID); - trans->Append("UPDATE mod_auctionhousebot SET percentbluetradegoods = '{}' WHERE auctionhouse = '{}'", bluetg, ahMapID); - trans->Append("UPDATE mod_auctionhousebot SET percentpurpletradegoods = '{}' WHERE auctionhouse = '{}'", purpletg, ahMapID); - trans->Append("UPDATE mod_auctionhousebot SET percentorangetradegoods = '{}' WHERE auctionhouse = '{}'", orangetg, ahMapID); - trans->Append("UPDATE mod_auctionhousebot SET percentyellowtradegoods = '{}' WHERE auctionhouse = '{}'", yellowtg, ahMapID); - trans->Append("UPDATE mod_auctionhousebot SET percentgreyitems = '{}' WHERE auctionhouse = '{}'", greyi, ahMapID); - trans->Append("UPDATE mod_auctionhousebot SET percentwhiteitems = '{}' WHERE auctionhouse = '{}'", whitei, ahMapID); - trans->Append("UPDATE mod_auctionhousebot SET percentgreenitems = '{}' WHERE auctionhouse = '{}'", greeni, ahMapID); - trans->Append("UPDATE mod_auctionhousebot SET percentblueitems = '{}' WHERE auctionhouse = '{}'", bluei, ahMapID); - trans->Append("UPDATE mod_auctionhousebot SET percentpurpleitems = '{}' WHERE auctionhouse = '{}'", purplei, ahMapID); - 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); - } + { + char * param1 = strtok(args, " "); + char * param2 = strtok(NULL, " "); + char * param3 = strtok(NULL, " "); + char * param4 = strtok(NULL, " "); + char * param5 = strtok(NULL, " "); + char * param6 = strtok(NULL, " "); + char * param7 = strtok(NULL, " "); + char * param8 = strtok(NULL, " "); + char * param9 = strtok(NULL, " "); + char * param10 = strtok(NULL, " "); + char * param11 = strtok(NULL, " "); + char * param12 = strtok(NULL, " "); + char * param13 = strtok(NULL, " "); + char * param14 = strtok(NULL, " "); + + uint32 greytg = (uint32) strtoul(param1, NULL, 0); + uint32 whitetg = (uint32) strtoul(param2, NULL, 0); + uint32 greentg = (uint32) strtoul(param3, NULL, 0); + uint32 bluetg = (uint32) strtoul(param4, NULL, 0); + uint32 purpletg = (uint32) strtoul(param5, NULL, 0); + uint32 orangetg = (uint32) strtoul(param6, NULL, 0); + uint32 yellowtg = (uint32) strtoul(param7, NULL, 0); + uint32 greyi = (uint32) strtoul(param8, NULL, 0); + uint32 whitei = (uint32) strtoul(param9, NULL, 0); + uint32 greeni = (uint32) strtoul(param10, NULL, 0); + uint32 bluei = (uint32) strtoul(param11, NULL, 0); + uint32 purplei = (uint32) strtoul(param12, NULL, 0); + uint32 orangei = (uint32) strtoul(param13, NULL, 0); + uint32 yellowi = (uint32) strtoul(param14, NULL, 0); + + 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); + trans->Append("UPDATE mod_auctionhousebot SET percentgreentradegoods = '{}' WHERE auctionhouse = '{}'", greentg, ahMapID); + trans->Append("UPDATE mod_auctionhousebot SET percentbluetradegoods = '{}' WHERE auctionhouse = '{}'", bluetg, ahMapID); + trans->Append("UPDATE mod_auctionhousebot SET percentpurpletradegoods = '{}' WHERE auctionhouse = '{}'", purpletg, ahMapID); + trans->Append("UPDATE mod_auctionhousebot SET percentorangetradegoods = '{}' WHERE auctionhouse = '{}'", orangetg, ahMapID); + trans->Append("UPDATE mod_auctionhousebot SET percentyellowtradegoods = '{}' WHERE auctionhouse = '{}'", yellowtg, ahMapID); + trans->Append("UPDATE mod_auctionhousebot SET percentgreyitems = '{}' WHERE auctionhouse = '{}'", greyi, ahMapID); + trans->Append("UPDATE mod_auctionhousebot SET percentwhiteitems = '{}' WHERE auctionhouse = '{}'", whitei, ahMapID); + trans->Append("UPDATE mod_auctionhousebot SET percentgreenitems = '{}' WHERE auctionhouse = '{}'", greeni, ahMapID); + trans->Append("UPDATE mod_auctionhousebot SET percentblueitems = '{}' WHERE auctionhouse = '{}'", bluei, ahMapID); + trans->Append("UPDATE mod_auctionhousebot SET percentpurpleitems = '{}' WHERE auctionhouse = '{}'", purplei, ahMapID); + 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); + break; + } case AHBotCommand::minprice: - { - char * param1 = strtok(args, " "); - uint32 minPrice = (uint32) strtoul(param1, NULL, 0); - WorldDatabase.Execute("UPDATE mod_auctionhousebot SET minprice{} = '{}' WHERE auctionhouse = '{}'", color, minPrice, ahMapID); - config->SetMinPrice(col, minPrice); - } + { + char * param1 = strtok(args, " "); + uint32 minPrice = (uint32) strtoul(param1, NULL, 0); + + WorldDatabase.Execute("UPDATE mod_auctionhousebot SET minprice{} = '{}' WHERE auctionhouse = '{}'", color, minPrice, ahMapID); + + config->SetMinPrice(col, minPrice); + break; + } case AHBotCommand::maxprice: - { - char * param1 = strtok(args, " "); - uint32 maxPrice = (uint32) strtoul(param1, NULL, 0); - WorldDatabase.Execute("UPDATE mod_auctionhousebot SET maxprice{} = '{}' WHERE auctionhouse = '{}'", color, maxPrice, ahMapID); - config->SetMaxPrice(col, maxPrice); - } + { + char * param1 = strtok(args, " "); + uint32 maxPrice = (uint32) strtoul(param1, NULL, 0); + + WorldDatabase.Execute("UPDATE mod_auctionhousebot SET maxprice{} = '{}' WHERE auctionhouse = '{}'", color, maxPrice, ahMapID); + + config->SetMaxPrice(col, maxPrice); + break; + } case AHBotCommand::minbidprice: - { - char * param1 = strtok(args, " "); - uint32 minBidPrice = (uint32) strtoul(param1, NULL, 0); - WorldDatabase.Execute("UPDATE mod_auctionhousebot SET minbidprice{} = '{}' WHERE auctionhouse = '{}'", color, minBidPrice, ahMapID); - config->SetMinBidPrice(col, minBidPrice); - } + { + char * param1 = strtok(args, " "); + uint32 minBidPrice = (uint32) strtoul(param1, NULL, 0); + + WorldDatabase.Execute("UPDATE mod_auctionhousebot SET minbidprice{} = '{}' WHERE auctionhouse = '{}'", color, minBidPrice, ahMapID); + + config->SetMinBidPrice(col, minBidPrice); + break; + } case AHBotCommand::maxbidprice: - { - char * param1 = strtok(args, " "); - uint32 maxBidPrice = (uint32) strtoul(param1, NULL, 0); - WorldDatabase.Execute("UPDATE mod_auctionhousebot SET maxbidprice{} = '{}' WHERE auctionhouse = '{}'", color, maxBidPrice, ahMapID); - config->SetMaxBidPrice(col, maxBidPrice); - } + { + char * param1 = strtok(args, " "); + uint32 maxBidPrice = (uint32) strtoul(param1, NULL, 0); + + WorldDatabase.Execute("UPDATE mod_auctionhousebot SET maxbidprice{} = '{}' WHERE auctionhouse = '{}'", color, maxBidPrice, ahMapID); + + config->SetMaxBidPrice(col, maxBidPrice); + break; + } case AHBotCommand::maxstack: - { - char * param1 = strtok(args, " "); - uint32 maxStack = (uint32) strtoul(param1, NULL, 0); - WorldDatabase.Execute("UPDATE mod_auctionhousebot SET maxstack{} = '{}' WHERE auctionhouse = '{}'", color, maxStack, ahMapID); - config->SetMaxStack(col, maxStack); - } + { + char * param1 = strtok(args, " "); + uint32 maxStack = (uint32) strtoul(param1, NULL, 0); + + WorldDatabase.Execute("UPDATE mod_auctionhousebot SET maxstack{} = '{}' WHERE auctionhouse = '{}'", color, maxStack, ahMapID); + + config->SetMaxStack(col, maxStack); + break; + } case AHBotCommand::buyerprice: - { - char * param1 = strtok(args, " "); - uint32 buyerPrice = (uint32) strtoul(param1, NULL, 0); - WorldDatabase.Execute("UPDATE mod_auctionhousebot SET buyerprice{} = '{}' WHERE auctionhouse = '{}'", color, buyerPrice, ahMapID); - config->SetBuyerPrice(col, buyerPrice); - } + { + char * param1 = strtok(args, " "); + uint32 buyerPrice = (uint32) strtoul(param1, NULL, 0); + + WorldDatabase.Execute("UPDATE mod_auctionhousebot SET buyerprice{} = '{}' WHERE auctionhouse = '{}'", color, buyerPrice, ahMapID); + + config->SetBuyerPrice(col, buyerPrice); + break; + } case AHBotCommand::bidinterval: - { - 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); - } + { + 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); + break; + } case AHBotCommand::bidsperinterval: - { - char * param1 = strtok(args, " "); - uint32 bidsPerInterval = (uint32) strtoul(param1, NULL, 0); - WorldDatabase.Execute("UPDATE mod_auctionhousebot SET buyerbidsperinterval = '{}' WHERE auctionhouse = '{}'", bidsPerInterval, ahMapID); - config->SetBidsPerInterval(bidsPerInterval); - } + { + char * param1 = strtok(args, " "); + uint32 bidsPerInterval = (uint32) strtoul(param1, NULL, 0); + + WorldDatabase.Execute("UPDATE mod_auctionhousebot SET buyerbidsperinterval = '{}' WHERE auctionhouse = '{}'", bidsPerInterval, ahMapID); + + config->SetBidsPerInterval(bidsPerInterval); + break; + } default: break; } } -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()); - - 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) - { - 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)); - } - - //AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntry(config->GetAHFID()); - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); +// ============================================================================= +// Initialization of the bot +// ============================================================================= - config->ResetItemCounts(); - uint32 auctions = auctionHouse->Getcount(); +void AuctionHouseBot::Initialize(AHBConfig* allianceConfig, AHBConfig* hordeConfig, AHBConfig* neutralConfig) +{ + // + // Save the pointer for the configurations + // - if (auctions) - { - for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr) - { - AuctionEntry *Aentry = itr->second; - Item *item = sAuctionMgr->GetAItem(Aentry->item_guid); - if (item) - { - 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; - } - } - } - } - } + _allianceConfig = allianceConfig; + _hordeConfig = hordeConfig; + _neutralConfig = neutralConfig; - 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)); - } - } - 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) - { - 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()); - } - } + // + // Done + // - if (debug_Out) - LOG_ERROR("module", "End Settings for {} Auctionhouses:", WorldDatabase.Query("SELECT name FROM mod_auctionhousebot WHERE auctionhouse = {}", config->GetAHID())->Fetch()->Get()); + LOG_INFO("module", "AHBot [{}]: initialization complete", uint32(_id)); } diff --git a/src/AuctionHouseBot.h b/src/AuctionHouseBot.h index 3b1c720..9f6b38d 100644 --- a/src/AuctionHouseBot.h +++ b/src/AuctionHouseBot.h @@ -22,1255 +22,60 @@ #include "Common.h" #include "ObjectGuid.h" +#include "AuctionHouseMgr.h" -struct AuctionEntry; -class Player; -class WorldSession; - -enum class AHBotCommand : uint32 -{ - ahexpire, - minitems, - maxitems, - percentages, - minprice, - maxprice, - minbidprice, - maxbidprice, - maxstack, - buyerprice, - bidinterval, - bidsperinterval -}; - -#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 -{ -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; - } - } +#include "AuctionHouseBotCommon.h" +#include "AuctionHouseBotConfig.h" - 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; - } - - uint32 TotalItemCounts() - { - return( - greyTGoods + - whiteTGoods + - greenTGoods + - blueTGoods + - purpleTGoods + - orangeTGoods + - yellowTGoods + - - greyItems + - whiteItems + - greenItems + - blueItems + - purpleItems + - orangeItems + - yellowItems); - } +struct AuctionEntry; +class Player; +class WorldSession; - 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: + uint32 _account; + uint32 _id; - bool debug_Out; - bool debug_Out_Filters; - - bool AHBSeller; - bool AHBBuyer; - bool BuyMethod; - bool SellMethod; - - 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; + AHBConfig* _allianceConfig; + AHBConfig* _hordeConfig; + AHBConfig* _neutralConfig; - bool DisablePermEnchant; - bool DisableConjured; - bool DisableGems; - bool DisableMoney; - bool DisableMoneyLoot; - bool DisableLootable; - bool DisableKeys; - bool DisableDuration; - bool DisableBOP_Or_Quest_NoReqLevel; + time_t _lastrun_a_sec; + time_t _lastrun_h_sec; + time_t _lastrun_n_sec; - bool DisableWarriorItems; - bool DisablePaladinItems; - bool DisableHunterItems; - bool DisableRogueItems; - bool DisablePriestItems; - bool DisableDKItems; - bool DisableShamanItems; - bool DisableMageItems; - bool DisableWarlockItems; - bool DisableUnusedClassItems; - bool DisableDruidItems; + // + // Main operations + // - 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; + void Sell(Player *AHBplayer, AHBConfig *config); + void Buy (Player *AHBplayer, AHBConfig *config, WorldSession *session); - std::set DisableItemStore; - - //End Filters - - AHBConfig AllianceConfig; - AHBConfig HordeConfig; - AHBConfig NeutralConfig; - - time_t _lastrun_a; - time_t _lastrun_h; - time_t _lastrun_n; + // + // Utilities + // 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); -// friend class ACE_Singleton; - AuctionHouseBot(); + uint32 getNofAuctions(AHBConfig* config, AuctionHouseObject* auctionHouse, ObjectGuid guid); + uint32 getStackCount(AHBConfig* config, uint32 max); + uint32 getElapsedTime(uint32 timeClass); + uint32 getElement(std::set set, int index); public: - static AuctionHouseBot* instance() - { - static AuctionHouseBot instance; - return &instance; - } - + AuctionHouseBot(uint32 account, uint32 id); ~AuctionHouseBot(); + + void Initialize(AHBConfig* allianceConfig, AHBConfig* hordeConfig, AHBConfig* neutralConfig); void Update(); - void Initialize(); - void InitializeConfiguration(); - void LoadValues(AHBConfig*); - void DecrementItemCounts(AuctionEntry* ah, uint32 itemEntry); + + void DecrementItemCounts(AuctionEntry* ah); void IncrementItemCounts(AuctionEntry* ah); - void Commands(AHBotCommand, uint32, uint32, char*); - ObjectGuid::LowType GetAHBplayerGUID() { return AHBplayerGUID; }; -}; -#define auctionbot AuctionHouseBot::instance() + void Commands(AHBotCommand command, uint32 ahMapID, uint32 col, char* args); + + ObjectGuid::LowType GetAHBplayerGUID() { return _id; }; +}; -#endif +#endif // AUCTION_HOUSE_BOT_H diff --git a/src/AuctionHouseBotAuctionHouseScript.cpp b/src/AuctionHouseBotAuctionHouseScript.cpp new file mode 100644 index 0000000..1811b70 --- /dev/null +++ b/src/AuctionHouseBotAuctionHouseScript.cpp @@ -0,0 +1,213 @@ +#include "AuctionHouseMgr.h" + +#include "AuctionHouseBot.h" +#include "AuctionHouseBotCommon.h" +#include "AuctionHouseBotAuctionHouseScript.h" + +AHBot_AuctionHouseScript::AHBot_AuctionHouseScript() : AuctionHouseScript("AHBot_AuctionHouseScript") +{ + +} + +void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrSendAuctionSuccessfulMail( + AuctionHouseMgr*, /*auctionHouseMgr*/ + AuctionEntry*, /*auction*/ + Player* owner, + uint32&, /*owner_accId*/ + uint32&, /*profit*/ + bool& sendNotification, + bool& updateAchievementCriteria, + bool& /*sendMail*/) +{ + if (owner && gBotsId.find(owner->GetGUID().GetCounter()) != gBotsId.end()) + { + sendNotification = false; + updateAchievementCriteria = false; + } +} + +void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrSendAuctionExpiredMail( + AuctionHouseMgr*, /* auctionHouseMgr */ + AuctionEntry*, /* auction */ + Player* owner, + uint32&, /* owner_accId */ + bool& sendNotification, + bool& /* sendMail */) +{ + if (owner && gBotsId.find(owner->GetGUID().GetCounter()) != gBotsId.end()) + { + sendNotification = false; + } +} + +void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrSendAuctionOutbiddedMail( + AuctionHouseMgr*, /* auctionHouseMgr */ + AuctionEntry* auction, + Player* oldBidder, + uint32&, /* oldBidder_accId */ + Player* newBidder, + uint32& newPrice, + bool&, /* sendNotification */ + bool& /* sendMail */) +{ + if (oldBidder && !newBidder) + { + if (gBotsId.size() > 0) + { + // + // Use a random bot id + // + + uint32 randBot = urand(0, gBotsId.size() - 1); + std::set::iterator it = gBotsId.begin(); + std::advance(it, randBot); + + oldBidder->GetSession()->SendAuctionBidderNotification( + auction->GetHouseId(), + auction->Id, + ObjectGuid::Create(*it), + newPrice, + auction->GetAuctionOutBid(), + auction->item_template); + } + } +} + +void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionEntry* auction) +{ + // + // The the configuration for the auction house + // + + AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(auction->GetHouseId()); + AHBConfig* config = gNeutralConfig; + + if (ahEntry) + { + if (ahEntry->houseId == AUCTIONHOUSE_ALLIANCE) + { + config = gAllianceConfig; + } + else if (ahEntry->houseId == AUCTIONHOUSE_HORDE) + { + config = gHordeConfig; + } + } + + // + // Consider only those auctions handled by the bots + // + + if (config->ConsiderOnlyBotAuctions) + { + if (gBotsId.find(auction->owner.GetCounter()) != gBotsId.end()) + { + return; + } + } + + // + // Verify if we can operate on the item + // + + Item* pItem = sAuctionMgr->GetAItem(auction->item_guid); + + if (!pItem) + { + if (config->DebugOut) + { + LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString()); + } + + return; + } + + // + // Keeps updated the amount of items in the auction + // + + ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template); + + if (config->DebugOut) + { + LOG_INFO("module", "AHBot: ah={}, item={}, count={}", auction->GetHouseId(), auction->item_template, config->GetItemCounts(prototype->Quality)); + } + + config->IncItemCounts(prototype->Class, prototype->Quality); +} + +void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, AuctionEntry* auction) +{ + + // + // The the configuration for the auction house + // + + AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(auction->GetHouseId()); + AHBConfig* config = gNeutralConfig; + + if (ahEntry) + { + if (ahEntry->houseId == AUCTIONHOUSE_ALLIANCE) + { + config = gAllianceConfig; + } + else if (ahEntry->houseId == AUCTIONHOUSE_HORDE) + { + config = gHordeConfig; + } + } + + // + // Consider only those auctions handled by the bots + // + + if (config->ConsiderOnlyBotAuctions) + { + if (gBotsId.find(auction->owner.GetCounter()) != gBotsId.end()) + { + return; + } + } + + // + // Verify if we can operate on the item + // + + Item* pItem = sAuctionMgr->GetAItem(auction->item_guid); + + if (!pItem) + { + if (config->DebugOut) + { + LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString()); + } + + return; + } + + // + // Decrements + // + + ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template); + + if (config->DebugOut) + { + LOG_INFO("module", "AHBot: ah={}, item={}, count={}", auction->GetHouseId(), auction->item_template, config->GetItemCounts(prototype->Quality)); + } + + config->DecItemCounts(prototype->Class, prototype->Quality); +} + +void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrUpdate() +{ + // + // For every registered bot, perform an update + // + + for (AuctionHouseBot* bot: gBots) + { + bot->Update(); + } +} diff --git a/src/AuctionHouseBotAuctionHouseScript.h b/src/AuctionHouseBotAuctionHouseScript.h new file mode 100644 index 0000000..16ba1b5 --- /dev/null +++ b/src/AuctionHouseBotAuctionHouseScript.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 + */ + +#ifndef AUCTION_HOUSE_BOT_AUCTION_HOUSE_SCRIPT_H +#define AUCTION_HOUSE_BOT_AUCTION_HOUSE_SCRIPT_H + +#include "Player.h" +#include "ScriptMgr.h" + +// ============================================================================= +// Interaction with the auction house core mechanisms +// ============================================================================= + +class AHBot_AuctionHouseScript : public AuctionHouseScript +{ +public: + AHBot_AuctionHouseScript(); + + void OnBeforeAuctionHouseMgrSendAuctionSuccessfulMail(AuctionHouseMgr* auctionHouseMgr, AuctionEntry* auction, Player* owner, uint32& owner_accId, uint32& profit, bool& sendNotification, bool& updateAchievementCriteria, bool& sendMail) override; + void OnBeforeAuctionHouseMgrSendAuctionExpiredMail (AuctionHouseMgr* auctionHouseMgr, AuctionEntry* auction, Player* owner, uint32& owner_accId, bool& sendNotification, bool& sendMail) override; + void OnBeforeAuctionHouseMgrSendAuctionOutbiddedMail (AuctionHouseMgr* auctionHouseMgr, AuctionEntry* auction, Player* oldBidder, uint32& oldBidder_accId, Player* newBidder, uint32& newPrice, bool& sendNotification, bool& sendMail) override; + + void OnAuctionAdd (AuctionHouseObject* ah, AuctionEntry* auction) override; + void OnAuctionRemove(AuctionHouseObject* ah, AuctionEntry* auction) override; + + void OnBeforeAuctionHouseMgrUpdate() override; +}; + +#endif /* AUCTION_HOUSE_BOT_AUCTION_HOUSE_SCRIPT_H */ \ No newline at end of file diff --git a/src/AuctionHouseBotCommon.cpp b/src/AuctionHouseBotCommon.cpp new file mode 100644 index 0000000..c0564c9 --- /dev/null +++ b/src/AuctionHouseBotCommon.cpp @@ -0,0 +1,18 @@ +#include "AuctionHouseBot.h" +#include "AuctionHouseBotCommon.h" +#include "AuctionHouseBotConfig.h" + +// +// Configuration used globally by all the bots instances +// + +AHBConfig* gAllianceConfig = new AHBConfig(2); +AHBConfig* gHordeConfig = new AHBConfig(6); +AHBConfig* gNeutralConfig = new AHBConfig(7); + +// +// Active bots +// + +std::set gBotsId; +std::set gBots; \ No newline at end of file diff --git a/src/AuctionHouseBotCommon.h b/src/AuctionHouseBotCommon.h new file mode 100644 index 0000000..1e32cd6 --- /dev/null +++ b/src/AuctionHouseBotCommon.h @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2008-2010 Trinity + * Copyright (C) 2005-2009 MaNGOS + * + * 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 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. + * + * 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 + */ + +#ifndef AUCTION_HOUSE_BOT_COMMON_H +#define AUCTION_HOUSE_BOT_COMMON_H + +#include + +#include "Common.h" + +class AuctionHouseBot; + +// +// Item quality +// + +#define AHB_GREY ITEM_QUALITY_POOR +#define AHB_WHITE ITEM_QUALITY_NORMAL +#define AHB_GREEN ITEM_QUALITY_UNCOMMON +#define AHB_BLUE ITEM_QUALITY_RARE +#define AHB_PURPLE ITEM_QUALITY_EPIC +#define AHB_ORANGE ITEM_QUALITY_LEGENDARY +#define AHB_YELLOW ITEM_QUALITY_ARTIFACT +#define AHB_MAX_QUALITY ITEM_QUALITY_ARTIFACT + +#define AHB_CLASS_WARRIOR 1 +#define AHB_CLASS_PALADIN 2 +#define AHB_CLASS_HUNTER 4 +#define AHB_CLASS_ROGUE 8 +#define AHB_CLASS_PRIEST 16 +#define AHB_CLASS_DK 32 +#define AHB_CLASS_SHAMAN 64 +#define AHB_CLASS_MAGE 128 +#define AHB_CLASS_WARLOCK 256 +#define AHB_CLASS_UNUSED 512 +#define AHB_CLASS_DRUID 1024 + +// +// Items classification +// + +#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 + +// +// Chat GM commands +// + +enum class AHBotCommand : uint32 +{ + buyer, + seller, + + ahexpire, + minitems, + maxitems, + percentages, + minprice, + maxprice, + minbidprice, + maxbidprice, + maxstack, + buyerprice, + bidinterval, + bidsperinterval +}; + +// +// Globals +// + +extern std::set gBotsId; // Active bots players ids +extern std::set gBots; // Active bots + +#endif // AUCTION_HOUSE_BOT_COMMON_H diff --git a/src/AuctionHouseBotConfig.cpp b/src/AuctionHouseBotConfig.cpp new file mode 100644 index 0000000..5353ab7 --- /dev/null +++ b/src/AuctionHouseBotConfig.cpp @@ -0,0 +1,3334 @@ +/* + * Copyright (C) 2008-2010 Trinity + * Copyright (C) 2005-2009 MaNGOS + * + * 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 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. + * + * 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 + */ + +#include "AuctionHouseMgr.h" +#include "Common.h" +#include "Config.h" +#include "DatabaseEnv.h" +#include "Item.h" +#include "ItemTemplate.h" +#include "Log.h" +#include "ObjectMgr.h" +#include "WorldSession.h" + +#include "AuctionHouseBotCommon.h" +#include "AuctionHouseBotConfig.h" + +using namespace std; + +AHBConfig::AHBConfig() +{ + Reset(); +} + +AHBConfig::AHBConfig(uint32 ahid) +{ + Reset(); + + AHID = ahid; + + switch (ahid) + { + case 2: + AHFID = 55; // Alliance + break; + + case 6: + AHFID = 29; // Horde + break; + + case 7: + AHFID = 120; // Neutral + break; + + default: + AHFID = 120; // Neutral + break; + } +} + +AHBConfig::AHBConfig(uint32 ahid, AHBConfig* conf) +{ + Reset(); + + // + // Ids + // + + AHID = ahid; + + switch (ahid) + { + case 2: + AHFID = 55; // Alliance + break; + + case 6: + AHFID = 29; // Horde + break; + + case 7: + AHFID = 120; // Neutral + break; + + default: + AHFID = 120; // Neutral + break; + } + + // + // Copy the private values + // + + minItems = conf->minItems; + maxItems = conf->maxItems; + percentGreyTradeGoods = conf->percentGreyTradeGoods; + percentWhiteTradeGoods = conf->percentWhiteTradeGoods; + percentGreenTradeGoods = conf->percentGreenTradeGoods; + percentBlueTradeGoods = conf->percentBlueTradeGoods; + percentPurpleTradeGoods = conf->percentPurpleTradeGoods; + percentOrangeTradeGoods = conf->percentOrangeTradeGoods; + percentYellowTradeGoods = conf->percentYellowTradeGoods; + percentGreyItems = conf->percentGreyItems; + percentWhiteItems = conf->percentWhiteItems; + percentGreenItems = conf->percentGreenItems; + percentBlueItems = conf->percentBlueItems; + percentPurpleItems = conf->percentPurpleItems; + percentOrangeItems = conf->percentOrangeItems; + percentYellowItems = conf->percentYellowItems; + minPriceGrey = conf->minPriceGrey; + maxPriceGrey = conf->maxPriceGrey; + minBidPriceGrey = conf->minBidPriceGrey; + maxBidPriceGrey = conf->maxBidPriceGrey; + maxStackGrey = conf->maxStackGrey; + maxPriceWhite = conf->maxPriceWhite; + minBidPriceWhite = conf->minBidPriceWhite; + maxBidPriceWhite = conf->maxBidPriceWhite; + maxStackWhite = conf->maxStackWhite; + minPriceGreen = conf->minPriceGreen; + maxPriceGreen = conf->maxPriceGreen; + minBidPriceGreen = conf->minBidPriceGreen; + maxBidPriceGreen = conf->maxBidPriceGreen; + maxStackGreen = conf->maxStackGreen; + minPriceBlue = conf->minPriceBlue; + maxPriceBlue = conf->maxPriceBlue; + minBidPriceBlue = conf->minBidPriceBlue; + maxBidPriceBlue = conf->maxBidPriceBlue; + maxStackBlue = conf->maxStackBlue; + minPricePurple = conf->minPricePurple; + maxPricePurple = conf->maxPricePurple; + minBidPricePurple = conf->minBidPricePurple; + maxBidPricePurple = conf->maxBidPricePurple; + maxStackPurple = conf->maxStackPurple; + minPriceOrange = conf->minPriceOrange; + maxPriceOrange = conf->maxPriceOrange; + minBidPriceOrange = conf->minBidPriceOrange; + maxBidPriceOrange = conf->maxBidPriceOrange; + maxStackOrange = conf->maxStackOrange; + minPriceYellow = conf->minPriceYellow; + maxPriceYellow = conf->maxPriceYellow; + minBidPriceYellow = conf->minBidPriceYellow; + maxBidPriceYellow = conf->maxBidPriceYellow; + maxStackYellow = conf->maxStackYellow; + buyerPriceGrey = conf->buyerPriceGrey; + buyerPriceWhite = conf->buyerPriceWhite; + buyerPriceGreen = conf->buyerPriceGreen; + buyerPriceBlue = conf->buyerPriceBlue; + buyerPricePurple = conf->buyerPricePurple; + buyerPriceOrange = conf->buyerPriceOrange; + buyerPriceYellow = conf->buyerPriceYellow; + buyerBiddingInterval = conf->buyerBiddingInterval; + buyerBidsPerInterval = conf->buyerBidsPerInterval; + + // This part is acquired thorugh initialization + // + // greytgp = conf->greytgp; + // whitetgp = conf->whitetgp; + // greentgp = conf->greentgp; + // bluetgp = conf->bluetgp; + // purpletgp = conf->purpletgp; + // orangetgp = conf->orangetgp; + // yellowtgp = conf->yellowtgp; + // greyip = conf->greyip; + // whiteip = conf->whiteip; + // greenip = conf->greenip; + // blueip = conf->blueip; + // purpleip = conf->purpleip; + // orangeip = conf->orangeip; + // yellowip = conf->yellowip; + // greyTGoods = conf->greyTGoods; + // whiteTGoods = conf->whiteTGoods; + // greenTGoods = conf->greenTGoods; + // blueTGoods = conf->blueTGoods; + // purpleTGoods = conf->purpleTGoods; + // orangeTGoods = conf->orangeTGoods; + // yellowTGoods = conf->yellowTGoods; + // greyItems = conf->greyItems; + // whiteItems = conf->whiteItems; + // greenItems = conf->greenItems; + // blueItems = conf->blueItems; + // purpleItems = conf->purpleItems; + // orangeItems = conf->orangeItems; + // yellowItems = conf->yellowItems; + + // + // Copy the public properties + // + + DebugOut = conf->DebugOut; + DebugOutConfig = conf->DebugOutConfig; + DebugOutFilters = conf->DebugOutFilters; + DebugOutBuyer = conf->DebugOutBuyer; + DebugOutSeller = conf->DebugOutSeller; + TraceSeller = conf->TraceSeller; + TraceBuyer = conf->TraceBuyer; + AHBSeller = conf->AHBSeller; + AHBBuyer = conf->AHBBuyer; + BuyMethod = conf->BuyMethod; + SellMethod = conf->SellMethod; + ConsiderOnlyBotAuctions = conf->ConsiderOnlyBotAuctions; + ItemsPerCycle = conf->ItemsPerCycle; + Vendor_Items = conf->Vendor_Items; + Loot_Items = conf->Loot_Items; + Other_Items = conf->Other_Items; + Vendor_TGs = conf->Vendor_TGs; + Loot_TGs = conf->Loot_TGs; + Other_TGs = conf->Other_TGs; + No_Bind = conf->No_Bind; + Bind_When_Picked_Up = conf->Bind_When_Picked_Up; + Bind_When_Equipped = conf->Bind_When_Equipped; + Bind_When_Use = conf->Bind_When_Use; + Bind_Quest_Item = conf->Bind_Quest_Item; + DuplicatesCount = conf->DuplicatesCount; + ElapsingTimeClass = conf->ElapsingTimeClass; + DivisibleStacks = conf->DivisibleStacks; + DisablePermEnchant = conf->DisablePermEnchant; + DisableConjured = conf->DisableConjured; + DisableGems = conf->DisableGems; + DisableMoney = conf->DisableMoney; + DisableMoneyLoot = conf->DisableMoneyLoot; + DisableLootable = conf->DisableLootable; + DisableKeys = conf->DisableKeys; + DisableDuration = conf->DisableDuration; + DisableBOP_Or_Quest_NoReqLevel = conf->DisableBOP_Or_Quest_NoReqLevel; + DisableWarriorItems = conf->DisableWarriorItems; + DisablePaladinItems = conf->DisablePaladinItems; + DisableHunterItems = conf->DisableHunterItems; + DisableRogueItems = conf->DisableRogueItems; + DisablePriestItems = conf->DisablePriestItems; + DisableDKItems = conf->DisableDKItems; + DisableShamanItems = conf->DisableShamanItems; + DisableMageItems = conf->DisableMageItems; + DisableWarlockItems = conf->DisableWarlockItems; + DisableUnusedClassItems = conf->DisableUnusedClassItems; + DisableDruidItems = conf->DisableDruidItems; + DisableItemsBelowLevel = conf->DisableItemsBelowLevel; + DisableItemsAboveLevel = conf->DisableItemsAboveLevel; + DisableTGsBelowLevel = conf->DisableTGsBelowLevel; + DisableTGsAboveLevel = conf->DisableTGsAboveLevel; + DisableItemsBelowGUID = conf->DisableItemsBelowGUID; + DisableItemsAboveGUID = conf->DisableItemsAboveGUID; + DisableTGsBelowGUID = conf->DisableTGsBelowGUID; + DisableTGsAboveGUID = conf->DisableTGsAboveGUID; + DisableItemsBelowReqLevel = conf->DisableItemsBelowReqLevel; + DisableItemsAboveReqLevel = conf->DisableItemsAboveReqLevel; + DisableTGsBelowReqLevel = conf->DisableTGsBelowReqLevel; + DisableTGsAboveReqLevel = conf->DisableTGsAboveReqLevel; + DisableItemsBelowReqSkillRank = conf->DisableItemsBelowReqSkillRank; + DisableItemsAboveReqSkillRank = conf->DisableItemsAboveReqSkillRank; + DisableTGsBelowReqSkillRank = conf->DisableTGsBelowReqSkillRank; + DisableTGsAboveReqSkillRank = conf->DisableTGsAboveReqSkillRank; + + // + // Copy the sets + // + + NpcItems.clear(); + for (uint32 id: conf->NpcItems) + { + NpcItems.insert(id); + } + + LootItems.clear(); + for (uint32 id: conf->LootItems) + { + LootItems.insert(id); + } + + DisableItemStore.clear(); + for (uint32 id: conf->DisableItemStore) + { + DisableItemStore.insert(id); + } + + SellerWhiteList.clear(); + for (uint32 id: conf->SellerWhiteList) + { + SellerWhiteList.insert(id); + } + + GreyTradeGoodsBin.clear(); + for (uint32 id: conf->GreyTradeGoodsBin) + { + GreyTradeGoodsBin.insert(id); + } + + WhiteTradeGoodsBin.clear(); + for (uint32 id: conf->WhiteTradeGoodsBin) + { + WhiteTradeGoodsBin.insert(id); + } + + GreenTradeGoodsBin.clear(); + for (uint32 id: conf->GreenTradeGoodsBin) + { + GreenTradeGoodsBin.insert(id); + } + + BlueTradeGoodsBin.clear(); + for (uint32 id: conf->BlueTradeGoodsBin) + { + BlueTradeGoodsBin.insert(id); + } + + PurpleTradeGoodsBin.clear(); + for (uint32 id: conf->PurpleTradeGoodsBin) + { + PurpleTradeGoodsBin.insert(id); + } + + OrangeTradeGoodsBin.clear(); + for (uint32 id: conf->OrangeTradeGoodsBin) + { + OrangeTradeGoodsBin.insert(id); + } + + YellowTradeGoodsBin.clear(); + for (uint32 id: conf->YellowTradeGoodsBin) + { + YellowTradeGoodsBin.insert(id); + } + + + // + // Bins for items + // + + GreyItemsBin.clear(); + for (uint32 id: conf->GreyItemsBin) + { + GreyItemsBin.insert(id); + } + + WhiteItemsBin.clear(); + for (uint32 id: conf->WhiteItemsBin) + { + WhiteItemsBin.insert(id); + } + + GreenItemsBin.clear(); + for (uint32 id: conf->GreenItemsBin) + { + GreenItemsBin.insert(id); + } + + BlueItemsBin.clear(); + for (uint32 id: conf->BlueItemsBin) + { + BlueItemsBin.insert(id); + } + + PurpleItemsBin.clear(); + for (uint32 id: conf->PurpleItemsBin) + { + PurpleItemsBin.insert(id); + } + + OrangeItemsBin.clear(); + for (uint32 id: conf->OrangeItemsBin) + { + OrangeItemsBin.insert(id); + } + + YellowItemsBin.clear(); + for (uint32 id: conf->YellowItemsBin) + { + YellowItemsBin.insert(id); + } +} + +AHBConfig::~AHBConfig() +{ +} + +void AHBConfig::Reset() +{ + // + // Private variables + // + + AHID = 0; + AHFID = 0; + + minItems = 0; + maxItems = 0; + + percentGreyTradeGoods = 0; + percentWhiteTradeGoods = 0; + percentGreenTradeGoods = 0; + percentBlueTradeGoods = 0; + percentPurpleTradeGoods = 0; + percentOrangeTradeGoods = 0; + percentYellowTradeGoods = 0; + + percentGreyItems = 0; + percentWhiteItems = 0; + percentGreenItems = 0; + percentBlueItems = 0; + percentPurpleItems = 0; + percentOrangeItems = 0; + percentYellowItems = 0; + + minPriceGrey = 0; + maxPriceGrey = 0; + minBidPriceGrey = 0; + maxBidPriceGrey = 0; + maxStackGrey = 0; + + minPriceWhite = 0; + maxPriceWhite = 0; + minBidPriceWhite = 0; + maxBidPriceWhite = 0; + maxStackWhite = 0; + + minPriceGreen = 0; + maxPriceGreen = 0; + minBidPriceGreen = 0; + maxBidPriceGreen = 0; + maxStackGreen = 0; + + minPriceBlue = 0; + maxPriceBlue = 0; + minBidPriceBlue = 0; + maxBidPriceBlue = 0; + maxStackBlue = 0; + + minPricePurple = 0; + maxPricePurple = 0; + minBidPricePurple = 0; + maxBidPricePurple = 0; + maxStackPurple = 0; + + minPriceOrange = 0; + maxPriceOrange = 0; + minBidPriceOrange = 0; + maxBidPriceOrange = 0; + maxStackOrange = 0; + + minPriceYellow = 0; + maxPriceYellow = 0; + minBidPriceYellow = 0; + maxBidPriceYellow = 0; + maxStackYellow = 0; + + buyerPriceGrey = 0; + buyerPriceWhite = 0; + buyerPriceGreen = 0; + buyerPriceBlue = 0; + buyerPricePurple = 0; + buyerPriceOrange = 0; + buyerPriceYellow = 0; + + buyerBiddingInterval = 0; + buyerBidsPerInterval = 0; + + greytgp = 0; + whitetgp = 0; + greentgp = 0; + bluetgp = 0; + purpletgp = 0; + orangetgp = 0; + yellowtgp = 0; + + greyip = 0; + whiteip = 0; + greenip = 0; + blueip = 0; + purpleip = 0; + orangeip = 0; + yellowip = 0; + + greyTGoods = 0; + whiteTGoods = 0; + greenTGoods = 0; + blueTGoods = 0; + purpleTGoods = 0; + orangeTGoods = 0; + yellowTGoods = 0; + + greyItems = 0; + whiteItems = 0; + greenItems = 0; + blueItems = 0; + purpleItems = 0; + orangeItems = 0; + yellowItems = 0; + + // + // Public properties + // + + DebugOut = false; + DebugOutConfig = false; + DebugOutFilters = false; + DebugOutBuyer = false; + DebugOutSeller = false; + + TraceSeller = false; + TraceBuyer = false; + + AHBSeller = false; + AHBBuyer = false; + + BuyMethod = false; + SellMethod = false; + ConsiderOnlyBotAuctions = false; + ItemsPerCycle = 200; + + Vendor_Items = false; + Loot_Items = true; + Other_Items = false; + Vendor_TGs = false; + Loot_TGs = true; + Other_TGs = false; + + No_Bind = true; + Bind_When_Picked_Up = true; + Bind_When_Equipped = false; + Bind_When_Use = false; + Bind_Quest_Item = false; + DuplicatesCount = 0; + ElapsingTimeClass = 1; + DivisibleStacks = false; + + DisablePermEnchant = false; + DisableConjured = false; + DisableGems = false; + DisableMoney = false; + DisableMoneyLoot = false; + DisableLootable = false; + DisableKeys = false; + DisableDuration = false; + DisableBOP_Or_Quest_NoReqLevel = false; + + DisableWarriorItems = false; + DisablePaladinItems = false; + DisableHunterItems = false; + DisableRogueItems = false; + DisablePriestItems = false; + DisableDKItems = false; + DisableShamanItems = false; + DisableMageItems = false; + DisableWarlockItems = false; + DisableUnusedClassItems = false; + DisableDruidItems = false; + + DisableItemsBelowLevel = false; + DisableItemsAboveLevel = false; + DisableTGsBelowLevel = false; + DisableTGsAboveLevel = false; + DisableItemsBelowGUID = false; + DisableItemsAboveGUID = false; + DisableTGsBelowGUID = false; + DisableTGsAboveGUID = false; + DisableItemsBelowReqLevel = false; + DisableItemsAboveReqLevel = false; + DisableTGsBelowReqLevel = false; + DisableTGsAboveReqLevel = false; + DisableItemsBelowReqSkillRank = false; + DisableItemsAboveReqSkillRank = false; + DisableTGsBelowReqSkillRank = false; + DisableTGsAboveReqSkillRank = false; + + // + // Sets + // + + NpcItems.clear(); + LootItems.clear(); + + DisableItemStore.clear(); + SellerWhiteList.clear(); + + GreyTradeGoodsBin.clear(); + WhiteTradeGoodsBin.clear(); + GreenTradeGoodsBin.clear(); + BlueTradeGoodsBin.clear(); + PurpleTradeGoodsBin.clear(); + OrangeTradeGoodsBin.clear(); + YellowTradeGoodsBin.clear(); + + GreyItemsBin.clear(); + WhiteItemsBin.clear(); + GreenItemsBin.clear(); + BlueItemsBin.clear(); + PurpleItemsBin.clear(); + OrangeItemsBin.clear(); + YellowItemsBin.clear(); +} + +uint32 AHBConfig::GetAHID() +{ + return AHID; +} + +uint32 AHBConfig::GetAHFID() +{ + return AHFID; +} + +void AHBConfig::SetMinItems(uint32 value) +{ + minItems = value; +} + +uint32 AHBConfig::GetMinItems() +{ + if ((minItems == 0) && (maxItems)) + { + return maxItems; + } + else if ((maxItems) && (minItems > maxItems)) + { + return maxItems; + } + else + { + return minItems; + } +} + +void AHBConfig::SetMaxItems(uint32 value) +{ + maxItems = value; + // CalculatePercents() needs to be called, but only if + // SetPercentages() has been called at least once already. +} + +uint32 AHBConfig::GetMaxItems() +{ + return maxItems; +} + +void AHBConfig::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 AHBConfig::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 AHBConfig::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 AHBConfig::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; + } +} + +void AHBConfig::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 AHBConfig::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; + + } +} + +void AHBConfig::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 AHBConfig::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; + } +} + +void AHBConfig::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 AHBConfig::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; + } +} + +void AHBConfig::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 AHBConfig::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; + } +} + +void AHBConfig::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 AHBConfig::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 AHBConfig::SetBiddingInterval(uint32 value) +{ + buyerBiddingInterval = value; +} + +uint32 AHBConfig::GetBiddingInterval() +{ + return buyerBiddingInterval; +} + +void AHBConfig::CalculatePercents() +{ + // + // Use the percent values to setup the maximum amount of items per category + // to be sold in the market + // + + 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; + } + } +} + +uint32 AHBConfig::GetMaximum(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 AHBConfig::DecItemCounts(uint32 Class, uint32 Quality) +{ + switch (Class) + { + case ITEM_CLASS_TRADE_GOODS: + DecItemCounts(Quality); + break; + + default: + DecItemCounts(Quality + 7); + break; + } +} + +void AHBConfig::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 AHBConfig::IncItemCounts(uint32 Class, uint32 Quality) +{ + switch (Class) + { + case ITEM_CLASS_TRADE_GOODS: + IncItemCounts(Quality); + break; + + default: + IncItemCounts(Quality + 7); + break; + } +} + +void AHBConfig::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 AHBConfig::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; +} + +uint32 AHBConfig::TotalItemCounts() +{ + return( + greyTGoods + + whiteTGoods + + greenTGoods + + blueTGoods + + purpleTGoods + + orangeTGoods + + yellowTGoods + + + greyItems + + whiteItems + + greenItems + + blueItems + + purpleItems + + orangeItems + + yellowItems); +} + +uint32 AHBConfig::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 AHBConfig::SetBidsPerInterval(uint32 value) +{ + buyerBidsPerInterval = value; +} + +uint32 AHBConfig::GetBidsPerInterval() +{ + return buyerBidsPerInterval; +} + +void AHBConfig::Initialize(std::set botsIds) +{ + InitializeFromFile(); + InitializeFromSql(botsIds); +} + +void AHBConfig::InitializeFromFile() +{ + // + // Load from, the configuration file + // + + DebugOut = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG" , false); + DebugOutConfig = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_CONFIG" , false); + DebugOutFilters = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_FILTERS", false); + DebugOutBuyer = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_BUYER" , false); + DebugOutSeller = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG_SELLER" , false); + + TraceSeller = sConfigMgr->GetOption ("AuctionHouseBot.TRACE_SELLER" , false); + TraceBuyer = sConfigMgr->GetOption ("AuctionHouseBot.TRACE_BUYER" , false); + + AHBSeller = sConfigMgr->GetOption ("AuctionHouseBot.EnableSeller" , false); + AHBBuyer = sConfigMgr->GetOption ("AuctionHouseBot.EnableBuyer" , false); + SellMethod = sConfigMgr->GetOption ("AuctionHouseBot.UseBuyPriceForSeller" , false); + BuyMethod = sConfigMgr->GetOption ("AuctionHouseBot.UseBuyPriceForBuyer" , false); + DuplicatesCount = sConfigMgr->GetOption("AuctionHouseBot.DuplicatesCount" , 0); + DivisibleStacks = sConfigMgr->GetOption ("AuctionHouseBot.DivisibleStacks" , false); + ElapsingTimeClass = sConfigMgr->GetOption("AuctionHouseBot.DuplicatesCount" , 1); + ConsiderOnlyBotAuctions = sConfigMgr->GetOption ("AuctionHouseBot.ConsiderOnlyBotAuctions", false); + ItemsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.ItemsPerCycle" , 200); + + // + // Flags: item types + // + + Vendor_Items = sConfigMgr->GetOption ("AuctionHouseBot.VendorItems" , false); + Loot_Items = sConfigMgr->GetOption ("AuctionHouseBot.LootItems" , true); + Other_Items = sConfigMgr->GetOption ("AuctionHouseBot.OtherItems" , false); + Vendor_TGs = sConfigMgr->GetOption ("AuctionHouseBot.VendorTradeGoods" , false); + Loot_TGs = sConfigMgr->GetOption ("AuctionHouseBot.LootTradeGoods" , true); + Other_TGs = sConfigMgr->GetOption ("AuctionHouseBot.OtherTradeGoods" , false); + + // + // Flags: items binding + // + + No_Bind = sConfigMgr->GetOption ("AuctionHouseBot.No_Bind" , true); + Bind_When_Picked_Up = sConfigMgr->GetOption ("AuctionHouseBot.Bind_When_Picked_Up" , false); + Bind_When_Equipped = sConfigMgr->GetOption ("AuctionHouseBot.Bind_When_Equipped" , true); + Bind_When_Use = sConfigMgr->GetOption ("AuctionHouseBot.Bind_When_Use" , true); + Bind_Quest_Item = sConfigMgr->GetOption ("AuctionHouseBot.Bind_Quest_Item" , false); + + // + // Flags: misc + // + + DisableConjured = sConfigMgr->GetOption ("AuctionHouseBot.DisableConjured" , false); + DisableGems = sConfigMgr->GetOption ("AuctionHouseBot.DisableGems" , false); + DisableMoney = sConfigMgr->GetOption ("AuctionHouseBot.DisableMoney" , false); + DisableMoneyLoot = sConfigMgr->GetOption ("AuctionHouseBot.DisableMoneyLoot" , false); + DisableLootable = sConfigMgr->GetOption ("AuctionHouseBot.DisableLootable" , false); + DisableKeys = sConfigMgr->GetOption ("AuctionHouseBot.DisableKeys" , false); + DisableDuration = sConfigMgr->GetOption ("AuctionHouseBot.DisableDuration" , false); + DisableBOP_Or_Quest_NoReqLevel = sConfigMgr->GetOption ("AuctionHouseBot.DisableBOP_Or_Quest_NoReqLevel", false); + + // + // Flags: items per class + // + + DisableWarriorItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableWarriorItems" , false); + DisablePaladinItems = sConfigMgr->GetOption ("AuctionHouseBot.DisablePaladinItems" , false); + DisableHunterItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableHunterItems" , false); + DisableRogueItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableRogueItems" , false); + DisablePriestItems = sConfigMgr->GetOption ("AuctionHouseBot.DisablePriestItems" , false); + DisableDKItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableDKItems" , false); + DisableShamanItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableShamanItems" , false); + DisableMageItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableMageItems" , false); + DisableWarlockItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableWarlockItems" , false); + DisableUnusedClassItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableUnusedClassItems", false); + DisableDruidItems = sConfigMgr->GetOption ("AuctionHouseBot.DisableDruidItems" , false); + + // + // Items level and skills + // + + DisableItemsBelowLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowLevel" , 0); + DisableItemsAboveLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveLevel" , 0); + DisableItemsBelowGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowGUID" , 0); + DisableItemsAboveGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveGUID" , 0); + DisableItemsBelowReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowReqLevel" , 0); + DisableItemsAboveReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveReqLevel" , 0); + DisableItemsBelowReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsBelowReqSkillRank", 0); + DisableItemsAboveReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableItemsAboveReqSkillRank", 0); + + // + // Trade goods level and skills + // + + DisableTGsBelowLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowLevel" , 0); + DisableTGsAboveLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveLevel" , 0); + DisableTGsBelowGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowGUID" , 0); + DisableTGsAboveGUID = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveGUID" , 0); + DisableTGsBelowReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowReqLevel" , 0); + DisableTGsAboveReqLevel = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveReqLevel" , 0); + DisableTGsBelowReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsBelowReqSkillRank", 0); + DisableTGsAboveReqSkillRank = sConfigMgr->GetOption("AuctionHouseBot.DisableTGsAboveReqSkillRank", 0); + + // + // Whitelists + // + + SellerWhiteList = getCommaSeparatedIntegers(sConfigMgr->GetOption("AuctionHouseBot.SellerWhiteList", "")); +} + +void AHBConfig::InitializeFromSql(std::set botsIds) +{ + // + // Load min and max items + // + + SetMinItems(WorldDatabase.Query("SELECT minitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxItems(WorldDatabase.Query("SELECT maxitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + // + // Load percentages + // + + uint32 greytg = WorldDatabase.Query("SELECT percentgreytradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 whitetg = WorldDatabase.Query("SELECT percentwhitetradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 greentg = WorldDatabase.Query("SELECT percentgreentradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 bluetg = WorldDatabase.Query("SELECT percentbluetradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 purpletg = WorldDatabase.Query("SELECT percentpurpletradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 orangetg = WorldDatabase.Query("SELECT percentorangetradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 yellowtg = WorldDatabase.Query("SELECT percentyellowtradegoods FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + + uint32 greyi = WorldDatabase.Query("SELECT percentgreyitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 whitei = WorldDatabase.Query("SELECT percentwhiteitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 greeni = WorldDatabase.Query("SELECT percentgreenitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 bluei = WorldDatabase.Query("SELECT percentblueitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 purplei = WorldDatabase.Query("SELECT percentpurpleitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 orangei = WorldDatabase.Query("SELECT percentorangeitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + uint32 yellowi = WorldDatabase.Query("SELECT percentyellowitems FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get(); + + SetPercentages(greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi); + + // + // Load min and max prices + // + + SetMinPrice(AHB_GREY , WorldDatabase.Query("SELECT minpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_GREY , WorldDatabase.Query("SELECT maxpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_WHITE , WorldDatabase.Query("SELECT minpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_WHITE , WorldDatabase.Query("SELECT maxpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_GREEN , WorldDatabase.Query("SELECT minpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_GREEN , WorldDatabase.Query("SELECT maxpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_BLUE , WorldDatabase.Query("SELECT minpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_BLUE , WorldDatabase.Query("SELECT maxpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_PURPLE, WorldDatabase.Query("SELECT minpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_PURPLE, WorldDatabase.Query("SELECT maxpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_ORANGE, WorldDatabase.Query("SELECT minpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_ORANGE, WorldDatabase.Query("SELECT maxpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinPrice(AHB_YELLOW, WorldDatabase.Query("SELECT minpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxPrice(AHB_YELLOW, WorldDatabase.Query("SELECT maxpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + // + // Load min and max bid prices + // + + SetMinBidPrice(AHB_GREY , WorldDatabase.Query("SELECT minbidpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_GREY , WorldDatabase.Query("SELECT maxbidpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_WHITE , WorldDatabase.Query("SELECT minbidpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_WHITE , WorldDatabase.Query("SELECT maxbidpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_GREEN , WorldDatabase.Query("SELECT minbidpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_GREEN , WorldDatabase.Query("SELECT maxbidpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_BLUE , WorldDatabase.Query("SELECT minbidpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_BLUE , WorldDatabase.Query("SELECT maxbidpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_PURPLE, WorldDatabase.Query("SELECT minbidpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_PURPLE, WorldDatabase.Query("SELECT maxbidpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_ORANGE, WorldDatabase.Query("SELECT minbidpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_ORANGE, WorldDatabase.Query("SELECT maxbidpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMinBidPrice(AHB_YELLOW, WorldDatabase.Query("SELECT minbidpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxBidPrice(AHB_YELLOW, WorldDatabase.Query("SELECT maxbidpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + // + // Load max stacks + // + + SetMaxStack(AHB_GREY , WorldDatabase.Query("SELECT maxstackgrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_WHITE , WorldDatabase.Query("SELECT maxstackwhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_GREEN , WorldDatabase.Query("SELECT maxstackgreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_BLUE , WorldDatabase.Query("SELECT maxstackblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_PURPLE, WorldDatabase.Query("SELECT maxstackpurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_ORANGE, WorldDatabase.Query("SELECT maxstackorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetMaxStack(AHB_YELLOW, WorldDatabase.Query("SELECT maxstackyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + if (DebugOutConfig) + { + LOG_INFO("module", "Settings for Auctionhouse {}", GetAHID()); + + LOG_INFO("module", "minItems = {}", GetMinItems()); + LOG_INFO("module", "maxItems = {}", GetMaxItems()); + + LOG_INFO("module", "percentGreyTradeGoods = {}", GetPercentages(AHB_GREY_TG)); + LOG_INFO("module", "percentWhiteTradeGoods = {}", GetPercentages(AHB_WHITE_TG)); + LOG_INFO("module", "percentGreenTradeGoods = {}", GetPercentages(AHB_GREEN_TG)); + LOG_INFO("module", "percentBlueTradeGoods = {}", GetPercentages(AHB_BLUE_TG)); + LOG_INFO("module", "percentPurpleTradeGoods = {}", GetPercentages(AHB_PURPLE_TG)); + LOG_INFO("module", "percentOrangeTradeGoods = {}", GetPercentages(AHB_ORANGE_TG)); + LOG_INFO("module", "percentYellowTradeGoods = {}", GetPercentages(AHB_YELLOW_TG)); + LOG_INFO("module", "percentGreyItems = {}", GetPercentages(AHB_GREY_I)); + LOG_INFO("module", "percentWhiteItems = {}", GetPercentages(AHB_WHITE_I)); + LOG_INFO("module", "percentGreenItems = {}", GetPercentages(AHB_GREEN_I)); + LOG_INFO("module", "percentBlueItems = {}", GetPercentages(AHB_BLUE_I)); + LOG_INFO("module", "percentPurpleItems = {}", GetPercentages(AHB_PURPLE_I)); + LOG_INFO("module", "percentOrangeItems = {}", GetPercentages(AHB_ORANGE_I)); + LOG_INFO("module", "percentYellowItems = {}", GetPercentages(AHB_YELLOW_I)); + + LOG_INFO("module", "minPriceGrey = {}", GetMinPrice(AHB_GREY)); + LOG_INFO("module", "maxPriceGrey = {}", GetMaxPrice(AHB_GREY)); + LOG_INFO("module", "minPriceWhite = {}", GetMinPrice(AHB_WHITE)); + LOG_INFO("module", "maxPriceWhite = {}", GetMaxPrice(AHB_WHITE)); + LOG_INFO("module", "minPriceGreen = {}", GetMinPrice(AHB_GREEN)); + LOG_INFO("module", "maxPriceGreen = {}", GetMaxPrice(AHB_GREEN)); + LOG_INFO("module", "minPriceBlue = {}", GetMinPrice(AHB_BLUE)); + LOG_INFO("module", "maxPriceBlue = {}", GetMaxPrice(AHB_BLUE)); + LOG_INFO("module", "minPricePurple = {}", GetMinPrice(AHB_PURPLE)); + LOG_INFO("module", "maxPricePurple = {}", GetMaxPrice(AHB_PURPLE)); + LOG_INFO("module", "minPriceOrange = {}", GetMinPrice(AHB_ORANGE)); + LOG_INFO("module", "maxPriceOrange = {}", GetMaxPrice(AHB_ORANGE)); + LOG_INFO("module", "minPriceYellow = {}", GetMinPrice(AHB_YELLOW)); + LOG_INFO("module", "maxPriceYellow = {}", GetMaxPrice(AHB_YELLOW)); + + LOG_INFO("module", "minBidPriceGrey = {}", GetMinBidPrice(AHB_GREY)); + LOG_INFO("module", "maxBidPriceGrey = {}", GetMaxBidPrice(AHB_GREY)); + LOG_INFO("module", "minBidPriceWhite = {}", GetMinBidPrice(AHB_WHITE)); + LOG_INFO("module", "maxBidPriceWhite = {}", GetMaxBidPrice(AHB_WHITE)); + LOG_INFO("module", "minBidPriceGreen = {}", GetMinBidPrice(AHB_GREEN)); + LOG_INFO("module", "maxBidPriceGreen = {}", GetMaxBidPrice(AHB_GREEN)); + LOG_INFO("module", "minBidPriceBlue = {}", GetMinBidPrice(AHB_BLUE)); + LOG_INFO("module", "maxBidPriceBlue = {}", GetMinBidPrice(AHB_BLUE)); + LOG_INFO("module", "minBidPricePurple = {}", GetMinBidPrice(AHB_PURPLE)); + LOG_INFO("module", "maxBidPricePurple = {}", GetMaxBidPrice(AHB_PURPLE)); + LOG_INFO("module", "minBidPriceOrange = {}", GetMinBidPrice(AHB_ORANGE)); + LOG_INFO("module", "maxBidPriceOrange = {}", GetMaxBidPrice(AHB_ORANGE)); + LOG_INFO("module", "minBidPriceYellow = {}", GetMinBidPrice(AHB_YELLOW)); + LOG_INFO("module", "maxBidPriceYellow = {}", GetMaxBidPrice(AHB_YELLOW)); + + LOG_INFO("module", "maxStackGrey = {}", GetMaxStack(AHB_GREY)); + LOG_INFO("module", "maxStackWhite = {}", GetMaxStack(AHB_WHITE)); + LOG_INFO("module", "maxStackGreen = {}", GetMaxStack(AHB_GREEN)); + LOG_INFO("module", "maxStackBlue = {}", GetMaxStack(AHB_BLUE)); + LOG_INFO("module", "maxStackPurple = {}", GetMaxStack(AHB_PURPLE)); + LOG_INFO("module", "maxStackOrange = {}", GetMaxStack(AHB_ORANGE)); + LOG_INFO("module", "maxStackYellow = {}", GetMaxStack(AHB_YELLOW)); + } + + // + // Reset the situation of the auction house + // + + ResetItemCounts(); + + // + // Update the situation of the auction house + // + + AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(GetAHFID()); + uint32 auctions = auctionHouse->Getcount(); + + if (auctions) + { + for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr) + { + AuctionEntry* Aentry = itr->second; + Item* item = sAuctionMgr->GetAItem(Aentry->item_guid); + + // + // If it has to only consider the bots auctions, skip the ones belonging to the players + // + + if (ConsiderOnlyBotAuctions) + { + if (botsIds.find(Aentry->owner.GetCounter()) == botsIds.end()) + { + continue; + } + } + + if (item) + { + ItemTemplate const* prototype = item->GetTemplate(); + + if (prototype) + { + switch (prototype->Quality) + { + case AHB_GREY: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_GREY_TG); + } + else + { + IncItemCounts(AHB_GREY_I); + } + break; + + case AHB_WHITE: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_WHITE_TG); + } + else + { + IncItemCounts(AHB_WHITE_I); + } + + break; + + case AHB_GREEN: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_GREEN_TG); + } + else + { + IncItemCounts(AHB_GREEN_I); + } + + break; + + case AHB_BLUE: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_BLUE_TG); + } + else + { + IncItemCounts(AHB_BLUE_I); + } + + break; + + case AHB_PURPLE: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_PURPLE_TG); + } + else + { + IncItemCounts(AHB_PURPLE_I); + } + + break; + + case AHB_ORANGE: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_ORANGE_TG); + } + else + { + IncItemCounts(AHB_ORANGE_I); + } + + break; + + case AHB_YELLOW: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + { + IncItemCounts(AHB_YELLOW_TG); + } + else + { + IncItemCounts(AHB_YELLOW_I); + } + + break; + } + } + } + } + } + + if (DebugOutConfig) + { + LOG_INFO("module", "Current situation for the auctionhouse {}", GetAHID()); + LOG_INFO("module", " Grey Trade Goods {}", GetItemCounts(AHB_GREY_TG)); + LOG_INFO("module", " White Trade Goods {}", GetItemCounts(AHB_WHITE_TG)); + LOG_INFO("module", " Green Trade Goods {}", GetItemCounts(AHB_GREEN_TG)); + LOG_INFO("module", " Blue Trade Goods {}", GetItemCounts(AHB_BLUE_TG)); + LOG_INFO("module", " Purple Trade Goods {}", GetItemCounts(AHB_PURPLE_TG)); + LOG_INFO("module", " Orange Trade Goods {}", GetItemCounts(AHB_ORANGE_TG)); + LOG_INFO("module", " Yellow Trade Goods {}", GetItemCounts(AHB_YELLOW_TG)); + LOG_INFO("module", " Grey Items {}", GetItemCounts(AHB_GREY_I)); + LOG_INFO("module", " White Items {}", GetItemCounts(AHB_WHITE_I)); + LOG_INFO("module", " Green Items {}", GetItemCounts(AHB_GREEN_I)); + LOG_INFO("module", " Blue Items {}", GetItemCounts(AHB_BLUE_I)); + LOG_INFO("module", " Purple Items {}", GetItemCounts(AHB_PURPLE_I)); + LOG_INFO("module", " Orange Items {}", GetItemCounts(AHB_ORANGE_I)); + LOG_INFO("module", " Yellow Items {}", GetItemCounts(AHB_YELLOW_I)); + } + + // + // Auctions buyer + // + + SetBuyerPrice(AHB_GREY , WorldDatabase.Query("SELECT buyerpricegrey FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_WHITE , WorldDatabase.Query("SELECT buyerpricewhite FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_GREEN , WorldDatabase.Query("SELECT buyerpricegreen FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_BLUE , WorldDatabase.Query("SELECT buyerpriceblue FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_PURPLE, WorldDatabase.Query("SELECT buyerpricepurple FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_ORANGE, WorldDatabase.Query("SELECT buyerpriceorange FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + SetBuyerPrice(AHB_YELLOW, WorldDatabase.Query("SELECT buyerpriceyellow FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + // + // Load bidding interval + // + + SetBiddingInterval(WorldDatabase.Query("SELECT buyerbiddinginterval FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + // + // Load bids per interval + // + + SetBidsPerInterval(WorldDatabase.Query("SELECT buyerbidsperinterval FROM mod_auctionhousebot WHERE auctionhouse = {}", GetAHID())->Fetch()->Get()); + + if (DebugOutConfig) + { + LOG_INFO("module", "Current Settings for Auctionhouse {} buyer", GetAHID()); + LOG_INFO("module", "buyerPriceGrey = {}", GetBuyerPrice(AHB_GREY)); + LOG_INFO("module", "buyerPriceWhite = {}", GetBuyerPrice(AHB_WHITE)); + LOG_INFO("module", "buyerPriceGreen = {}", GetBuyerPrice(AHB_GREEN)); + LOG_INFO("module", "buyerPriceBlue = {}", GetBuyerPrice(AHB_BLUE)); + LOG_INFO("module", "buyerPricePurple = {}", GetBuyerPrice(AHB_PURPLE)); + LOG_INFO("module", "buyerPriceOrange = {}", GetBuyerPrice(AHB_ORANGE)); + LOG_INFO("module", "buyerPriceYellow = {}", GetBuyerPrice(AHB_YELLOW)); + LOG_INFO("module", "buyerBiddingInterval = {}", GetBiddingInterval()); + LOG_INFO("module", "buyerBidsPerInterval = {}", GetBidsPerInterval()); + } + + // + // Reload the list of disabled items + // + + DisableItemStore.clear(); + + QueryResult result = WorldDatabase.Query("SELECT item FROM mod_auctionhousebot_disabled_items"); + + if (result) + { + do + { + Field* fields = result->Fetch(); + DisableItemStore.insert(fields[0].Get()); + } while (result->NextRow()); + } + + if (DebugOutConfig) + { + LOG_INFO("module", "Loaded {} items from the disabled item store", uint32(DisableItemStore.size())); + } + + // + // Reload the list of npc items + // + + NpcItems.clear(); + + QueryResult npcResults = WorldDatabase.Query("SELECT distinct item FROM npc_vendor"); + + if (npcResults) + { + do + { + Field* fields = npcResults->Fetch(); + NpcItems.insert(fields[0].Get()); + + } while (npcResults->NextRow()); + } + else + { + if (DebugOutConfig) + { + LOG_ERROR("module", "AuctionHouseBot: failed to retrieve npc items"); + } + } + + if (DebugOutConfig) + { + LOG_INFO("module", "Loaded {} items from NPCs", uint32(NpcItems.size())); + } + + // + // Reload the list from the lootable items + // + + LootItems.clear(); + + QueryResult itemsResults = WorldDatabase.Query( + "SELECT item FROM creature_loot_template UNION " + "SELECT item FROM reference_loot_template UNION " + "SELECT item FROM disenchant_loot_template UNION " + "SELECT item FROM fishing_loot_template UNION " + "SELECT item FROM gameobject_loot_template UNION " + "SELECT item FROM item_loot_template UNION " + "SELECT item FROM milling_loot_template UNION " + "SELECT item FROM pickpocketing_loot_template UNION " + "SELECT item FROM prospecting_loot_template UNION " + "SELECT item FROM skinning_loot_template"); + + if (itemsResults) + { + do + { + Field* fields = itemsResults->Fetch(); + LootItems.insert(fields[0].Get()); + + } while (itemsResults->NextRow()); + } + else + { + if (DebugOutConfig) + { + LOG_ERROR("module", "AuctionHouseBot: failed to retrieve loot items"); + } + } + + if (DebugOutConfig) + { + LOG_INFO("module", "Loaded {} items from lootable items", uint32(LootItems.size())); + } +} + +void AHBConfig::InitializeBins() +{ + // + // Exclude items depending on the configuration; whatever passes all the tests is put in the lists. + // + + ItemTemplateContainer const* its = sObjectMgr->GetItemTemplateStore(); + + for (ItemTemplateContainer::const_iterator itr = its->begin(); itr != its->end(); ++itr) + { + + // + // Exclude items with the blocked binding type + // + + if (itr->second.Bonding == NO_BIND && !No_Bind) + { + continue; + } + + if (itr->second.Bonding == BIND_WHEN_PICKED_UP && !Bind_When_Picked_Up) + { + continue; + } + + if (itr->second.Bonding == BIND_WHEN_EQUIPED && !Bind_When_Equipped) + { + continue; + } + + if (itr->second.Bonding == BIND_WHEN_USE && !Bind_When_Use) + { + continue; + } + + if (itr->second.Bonding == BIND_QUEST_ITEM && !Bind_Quest_Item) + { + continue; + } + + // + // Exclude items with no possible price + // + + if (SellMethod) + { + if (itr->second.BuyPrice == 0) + { + continue; + } + } + else + { + if (itr->second.SellPrice == 0) + { + continue; + } + } + + // + // Exclude items with no costs associated, in any case + // + + if ((itr->second.BuyPrice == 0) && (itr->second.SellPrice == 0)) + { + continue; + } + + // + // Exlude items superior to the limit quality + // + + if (itr->second.Quality > 6) + { + continue; + } + + // + // Exclude trade goods items + // + + if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) + { + bool isNpc = false; + bool isLoot = false; + bool exclude = false; + + if (NpcItems.find(itr->second.ItemId) != NpcItems.end()) + { + isNpc = true; + + if (!Vendor_TGs) + { + exclude = true; + } + } + + if (!exclude) + { + if (LootItems.find(itr->second.ItemId) != LootItems.end()) + { + isLoot = true; + + if (!Loot_TGs) + { + exclude = true; + } + } + } + + if (exclude) + { + continue; + } + + if (!Other_TGs) + { + if (!isNpc && !isLoot) + { + continue; + } + } + } + + // + // Exclude loot items + // + + if (itr->second.Class != ITEM_CLASS_TRADE_GOODS) + { + bool isNpc = false; + bool isLoot = false; + bool exclude = false; + + if (NpcItems.find(itr->second.ItemId) != NpcItems.end()) + { + isNpc = true; + + if (!Vendor_Items) + { + exclude = true; + } + } + + if (!exclude) + { + if (LootItems.find(itr->second.ItemId) != LootItems.end()) + { + isLoot = true; + + if (!Loot_Items) + { + exclude = true; + } + } + } + + if (exclude) + { + continue; + } + + if (!Other_Items) + { + if (!isNpc && !isLoot) + { + continue; + } + } + } + + // + // Verify if the item is disabled or not in the whitelist + // + + if (SellerWhiteList.size() == 0) + { + if (DisableItemStore.find(itr->second.ItemId) != DisableItemStore.end()) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (PTR/Beta/Unused Item)", itr->second.ItemId); + } + + continue; + } + } + else + { + if (SellerWhiteList.find(itr->second.ItemId) == SellerWhiteList.end()) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (not in the whitelist)", itr->second.ItemId); + } + + continue; + } + } + + // + // Disable permanent enchants items + // + + if ((DisablePermEnchant) && (itr->second.Class == ITEM_CLASS_PERMANENT)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Permanent Enchant Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable conjured items + // + + if ((DisableConjured) && (itr->second.IsConjuredConsumable())) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Conjured Consumable)", itr->second.ItemId); + } + + continue; + } + + // + // Disable gems + // + + if ((DisableGems) && (itr->second.Class == ITEM_CLASS_GEM)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Gem)", itr->second.ItemId); + } + + continue; + } + + // + // Disable money + // + + if ((DisableMoney) && (itr->second.Class == ITEM_CLASS_MONEY)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Money)", itr->second.ItemId); + } + + continue; + } + + // + // Disable moneyloot + // + + if ((DisableMoneyLoot) && (itr->second.MinMoneyLoot > 0)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (MoneyLoot)", itr->second.ItemId); + } + + continue; + } + + // + // Disable lootable items + // + + if ((DisableLootable) && (itr->second.Flags & 4)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Lootable Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable Keys + // + + if ((DisableKeys) && (itr->second.Class == ITEM_CLASS_KEY)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Quest Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items with duration + // + + if ((DisableDuration) && (itr->second.Duration > 0)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Has a Duration)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items which are BOP or Quest Items and have a required level lower than the item level + // + + if ((DisableBOP_Or_Quest_NoReqLevel) && ((itr->second.Bonding == BIND_WHEN_PICKED_UP || itr->second.Bonding == BIND_QUEST_ITEM) && (itr->second.RequiredLevel < itr->second.ItemLevel))) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (BOP or BQI and Required Level is less than Item Level)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Warrior + // + + if ((DisableWarriorItems) && (itr->second.AllowableClass == AHB_CLASS_WARRIOR)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Warrior Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Paladin + // + + if ((DisablePaladinItems) && (itr->second.AllowableClass == AHB_CLASS_PALADIN)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Paladin Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Hunter + // + + if ((DisableHunterItems) && (itr->second.AllowableClass == AHB_CLASS_HUNTER)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Hunter Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Rogue + // + + if ((DisableRogueItems) && (itr->second.AllowableClass == AHB_CLASS_ROGUE)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Rogue Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Priest + // + + if ((DisablePriestItems) && (itr->second.AllowableClass == AHB_CLASS_PRIEST)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Priest Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for DK + // + + if ((DisableDKItems) && (itr->second.AllowableClass == AHB_CLASS_DK)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (DK Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Shaman + // + + if ((DisableShamanItems) && (itr->second.AllowableClass == AHB_CLASS_SHAMAN)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Shaman Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Mage + // + + if ((DisableMageItems) && (itr->second.AllowableClass == AHB_CLASS_MAGE)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Mage Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Warlock + // + + if ((DisableWarlockItems) && (itr->second.AllowableClass == AHB_CLASS_WARLOCK)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Warlock Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Unused Class + // + + if ((DisableUnusedClassItems) && (itr->second.AllowableClass == AHB_CLASS_UNUSED)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Unused Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable items specifically for Druid + // + + if ((DisableDruidItems) && (itr->second.AllowableClass == AHB_CLASS_DRUID)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Druid Item)", itr->second.ItemId); + } + + continue; + } + + // + // Disable Items below level X + // + + if ((DisableItemsBelowLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel < DisableItemsBelowLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Items above level X + // + + if ((DisableItemsAboveLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel > DisableItemsAboveLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Trade Goods below level X + // + + if ((DisableTGsBelowLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel < DisableTGsBelowLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Trade Goods above level X + // + + if ((DisableTGsAboveLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemLevel > DisableTGsAboveLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Items below GUID X + // + + if ((DisableItemsBelowGUID) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId < DisableItemsBelowGUID)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Items above GUID X + // + + if ((DisableItemsAboveGUID) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId > DisableItemsAboveGUID)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Item Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Trade Goods below GUID X + // + + if ((DisableTGsBelowGUID) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId < DisableTGsBelowGUID)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Trade Goods above GUID X + // + + if ((DisableTGsAboveGUID) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.ItemId > DisableTGsAboveGUID)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (Trade Good Level = {})", itr->second.ItemId, itr->second.ItemLevel); + } + + continue; + } + + // + // Disable Items for level lower than X + // + + if ((DisableItemsBelowReqLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel < DisableItemsBelowReqLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + } + + continue; + } + + // + // Disable Items for level higher than X + // + + if ((DisableItemsAboveReqLevel) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel > DisableItemsAboveReqLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + } + + continue; + } + + // + // Disable Trade Goods for level lower than X + // + + if ((DisableTGsBelowReqLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel < DisableTGsBelowReqLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + } + + continue; + } + + // + // Disable Trade Goods for level higher than X + // + + if ((DisableTGsAboveReqLevel) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredLevel > DisableTGsAboveReqLevel)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Trade Good {} disabled (RequiredLevel = {})", itr->second.ItemId, itr->second.RequiredLevel); + } + + continue; + } + + // + // Disable Items that require skill lower than X + // + + if ((DisableItemsBelowReqSkillRank) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank < DisableItemsBelowReqSkillRank)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + } + + continue; + } + + // + // Disable Items that require skill higher than X + // + + if ((DisableItemsAboveReqSkillRank) && (itr->second.Class != ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank > DisableItemsAboveReqSkillRank)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + } + + continue; + } + + // + // Disable Trade Goods that require skill lower than X + // + + if ((DisableTGsBelowReqSkillRank) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank < DisableTGsBelowReqSkillRank)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + } + + continue; + } + + // + // Disable Trade Goods that require skill higher than X + // + + if ((DisableTGsAboveReqSkillRank) && (itr->second.Class == ITEM_CLASS_TRADE_GOODS) && (itr->second.RequiredSkillRank > DisableTGsAboveReqSkillRank)) + { + if (DebugOutFilters) + { + LOG_ERROR("module", "AuctionHouseBot: Item {} disabled (RequiredSkillRank = {})", itr->second.ItemId, itr->second.RequiredSkillRank); + } + + continue; + } + + // + // Now that the items passed all the tests, organize it by quality + // + + if (itr->second.Class == ITEM_CLASS_TRADE_GOODS) + { + switch (itr->second.Quality) + { + case AHB_GREY: + GreyTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_WHITE: + WhiteTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_GREEN: + GreenTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_BLUE: + BlueTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_PURPLE: + PurpleTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_ORANGE: + OrangeTradeGoodsBin.insert(itr->second.ItemId); + break; + + case AHB_YELLOW: + YellowTradeGoodsBin.insert(itr->second.ItemId); + break; + } + } + else + { + switch (itr->second.Quality) + { + case AHB_GREY: + GreyItemsBin.insert(itr->second.ItemId); + break; + + case AHB_WHITE: + WhiteItemsBin.insert(itr->second.ItemId); + break; + + case AHB_GREEN: + GreenItemsBin.insert(itr->second.ItemId); + break; + + case AHB_BLUE: + BlueItemsBin.insert(itr->second.ItemId); + break; + + case AHB_PURPLE: + PurpleItemsBin.insert(itr->second.ItemId); + break; + + case AHB_ORANGE: + OrangeItemsBin.insert(itr->second.ItemId); + break; + + case AHB_YELLOW: + YellowItemsBin.insert(itr->second.ItemId); + break; + } + } + } + + // + // Perform reporting and the last check: if no items are disabled or in the whitelist clear the bin making the selling useless + // + + LOG_INFO("module", "Configuration for ah {}", AHID); + + if (SellerWhiteList.size() == 0) + { + if (DisableItemStore.size() == 0) + { + LOG_ERROR("module", "No items are disabled or in the whitelist! Selling will be disabled!"); + + GreyTradeGoodsBin.clear(); + WhiteTradeGoodsBin.clear(); + GreenTradeGoodsBin.clear(); + BlueTradeGoodsBin.clear(); + PurpleTradeGoodsBin.clear(); + OrangeTradeGoodsBin.clear(); + YellowTradeGoodsBin.clear(); + GreyItemsBin.clear(); + WhiteItemsBin.clear(); + GreenItemsBin.clear(); + BlueItemsBin.clear(); + PurpleItemsBin.clear(); + OrangeItemsBin.clear(); + YellowItemsBin.clear(); + + AHBSeller = false; + + return; + } + + LOG_INFO("module", "{} disabled items", uint32(DisableItemStore.size())); + } + else + { + LOG_INFO("module", "Using a whitelist of {} items", uint32(SellerWhiteList.size())); + } + + // if (DebugOutConfig) + // { + LOG_INFO("module", "loaded {} grey trade goods", uint32(GreyTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} white trade goods", uint32(WhiteTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} green trade goods", uint32(GreenTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} blue trade goods", uint32(BlueTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} purple trade goods", uint32(PurpleTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} orange trade goods", uint32(OrangeTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} yellow trade goods", uint32(YellowTradeGoodsBin.size())); + LOG_INFO("module", "loaded {} grey items" , uint32(GreyItemsBin.size())); + LOG_INFO("module", "loaded {} white items" , uint32(WhiteItemsBin.size())); + LOG_INFO("module", "loaded {} green items" , uint32(GreenItemsBin.size())); + LOG_INFO("module", "loaded {} blue items" , uint32(BlueItemsBin.size())); + LOG_INFO("module", "loaded {} purple items" , uint32(PurpleItemsBin.size())); + LOG_INFO("module", "loaded {} orange items" , uint32(OrangeItemsBin.size())); + LOG_INFO("module", "loaded {} yellow items" , uint32(YellowItemsBin.size())); + // } +} + +std::set AHBConfig::getCommaSeparatedIntegers(std::string text) +{ + std::string value; + std::stringstream stream; + std::set ret; + + stream.str(text); + + // + // Continue to precess comma separated values + // + + while (std::getline(stream, value, ',')) + { + ret.insert(atoi(value.c_str())); + } + + return ret; +} diff --git a/src/AuctionHouseBotConfig.h b/src/AuctionHouseBotConfig.h new file mode 100644 index 0000000..13601c7 --- /dev/null +++ b/src/AuctionHouseBotConfig.h @@ -0,0 +1,356 @@ +/* + * Copyright (C) 2008-2010 Trinity + * Copyright (C) 2005-2009 MaNGOS + * + * 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 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. + * + * 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 + */ + +#ifndef AUCTION_HOUSE_BOT_CONFIG_H +#define AUCTION_HOUSE_BOT_CONFIG_H + +#include +#include + +#include "ObjectMgr.h" + +class AHBConfig +{ +private: + uint32 AHID; // Id + uint32 AHFID; // Faction id + + 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; + + // + // Amount of items to be sold in absolute values + // + + uint32 greytgp; + uint32 whitetgp; + uint32 greentgp; + uint32 bluetgp; + uint32 purpletgp; + uint32 orangetgp; + uint32 yellowtgp; + + uint32 greyip; + uint32 whiteip; + uint32 greenip; + uint32 blueip; + uint32 purpleip; + uint32 orangeip; + uint32 yellowip; + + // + // Situation of the auction house + // + + uint32 greyTGoods; + uint32 whiteTGoods; + uint32 greenTGoods; + uint32 blueTGoods; + uint32 purpleTGoods; + uint32 orangeTGoods; + uint32 yellowTGoods; + + uint32 greyItems; + uint32 whiteItems; + uint32 greenItems; + uint32 blueItems; + uint32 purpleItems; + uint32 orangeItems; + uint32 yellowItems; + + void InitializeFromFile(); + void InitializeFromSql(std::set botsIds); + + std::set getCommaSeparatedIntegers(std::string text); + +public: + // + // Debugging + // + + bool DebugOut; + bool DebugOutConfig; + bool DebugOutFilters; + bool DebugOutBuyer; + bool DebugOutSeller; + + // + // Tracing + // + + bool TraceSeller; + bool TraceBuyer; + + // + // Setup + // + + bool AHBSeller; + bool AHBBuyer; + bool BuyMethod; + bool SellMethod; + bool ConsiderOnlyBotAuctions; + uint32 ItemsPerCycle; + + // + // Filters + // + + bool Vendor_Items; + bool Loot_Items; + bool Other_Items; + bool Vendor_TGs; + bool Loot_TGs; + bool Other_TGs; + + bool No_Bind; + bool Bind_When_Picked_Up; + bool Bind_When_Equipped; + bool Bind_When_Use; + bool Bind_Quest_Item; + + uint32 DuplicatesCount; + uint32 ElapsingTimeClass; + + bool DivisibleStacks; + bool DisablePermEnchant; + bool DisableConjured; + bool DisableGems; + bool DisableMoney; + bool DisableMoneyLoot; + bool DisableLootable; + bool DisableKeys; + bool DisableDuration; + bool DisableBOP_Or_Quest_NoReqLevel; + + bool DisableWarriorItems; + bool DisablePaladinItems; + bool DisableHunterItems; + bool DisableRogueItems; + bool DisablePriestItems; + bool DisableDKItems; + bool DisableShamanItems; + bool DisableMageItems; + bool DisableWarlockItems; + bool DisableUnusedClassItems; + bool DisableDruidItems; + + uint32 DisableItemsBelowLevel; + uint32 DisableItemsAboveLevel; + + uint32 DisableTGsBelowLevel; + uint32 DisableTGsAboveLevel; + + uint32 DisableItemsBelowGUID; + uint32 DisableItemsAboveGUID; + + uint32 DisableTGsBelowGUID; + uint32 DisableTGsAboveGUID; + + uint32 DisableItemsBelowReqLevel; + uint32 DisableItemsAboveReqLevel; + + uint32 DisableTGsBelowReqLevel; + uint32 DisableTGsAboveReqLevel; + + uint32 DisableItemsBelowReqSkillRank; + uint32 DisableItemsAboveReqSkillRank; + + uint32 DisableTGsBelowReqSkillRank; + uint32 DisableTGsAboveReqSkillRank; + + // + // Items validity for selling purposes + // + + std::set NpcItems; + std::set LootItems; + std::set DisableItemStore; + std::set SellerWhiteList; + + // + // Bins for trade goods. + // + + std::set GreyTradeGoodsBin; + std::set WhiteTradeGoodsBin; + std::set GreenTradeGoodsBin; + std::set BlueTradeGoodsBin; + std::set PurpleTradeGoodsBin; + std::set OrangeTradeGoodsBin; + std::set YellowTradeGoodsBin; + + // + // Bins for items + // + + std::set GreyItemsBin; + std::set WhiteItemsBin; + std::set GreenItemsBin; + std::set BlueItemsBin; + std::set PurpleItemsBin; + std::set OrangeItemsBin; + std::set YellowItemsBin; + + // + // Constructors/destructors + // + + AHBConfig(uint32 ahid, AHBConfig* conf); + AHBConfig(uint32 ahid); + AHBConfig(); + ~AHBConfig(); + + // + // Ruotines + // + + void Initialize(std::set botsIds); + void InitializeBins(); + void Reset(); + + uint32 GetAHID(); + uint32 GetAHFID(); + + void SetMinItems (uint32 value); + uint32 GetMinItems (); + + void SetMaxItems (uint32 value); + uint32 GetMaxItems (); + + void SetPercentages (uint32 greytg, uint32 whitetg, uint32 greentg, uint32 bluetg, uint32 purpletg, uint32 orangetg, uint32 yellowtg, + uint32 greyi , uint32 whitei , uint32 greeni , uint32 bluei , uint32 purplei , uint32 orangei , uint32 yellowi); + 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); + + void SetBiddingInterval(uint32 value); + uint32 GetBiddingInterval(); + + void SetBidsPerInterval(uint32 value); + uint32 GetBidsPerInterval(); + + void CalculatePercents (); + uint32 GetMaximum (uint32 color); + + void DecItemCounts (uint32 Class, uint32 Quality); + void DecItemCounts (uint32 color); + + void IncItemCounts (uint32 Class, uint32 Quality); + void IncItemCounts (uint32 color); + + void ResetItemCounts (); + uint32 TotalItemCounts (); + + uint32 GetItemCounts (uint32 color); +}; + +// +// Globally defined configurations +// + +extern AHBConfig* gAllianceConfig; +extern AHBConfig* gHordeConfig; +extern AHBConfig* gNeutralConfig; + +#endif // AUCTION_HOUSE_BOT_CONFIG_H diff --git a/src/AuctionHouseBotMailScript.cpp b/src/AuctionHouseBotMailScript.cpp new file mode 100644 index 0000000..5c3dee2 --- /dev/null +++ b/src/AuctionHouseBotMailScript.cpp @@ -0,0 +1,33 @@ +#include "AuctionHouseBot.h" +#include "AuctionHouseBotCommon.h" +#include "AuctionHouseBotMailScript.h" + +AHBot_MailScript::AHBot_MailScript() : MailScript("AHBot_MailScript") +{ + +} + +void AHBot_MailScript::OnBeforeMailDraftSendMailTo( + MailDraft*, /* mailDraft */ + MailReceiver const& receiver, + MailSender const& sender, + MailCheckMask&, /* checked */ + uint32&, /* deliver_delay */ + uint32&, /* custom_expiration */ + bool& deleteMailItemsFromDB, + bool& sendMail) +{ + // + // If the mail is for the bot, then remove it and delete the items bought + // + + if (gBotsId.find(receiver.GetPlayerGUIDLow()) != gBotsId.end()) + { + if (sender.GetMailMessageType() == MAIL_AUCTION) + { + deleteMailItemsFromDB = true; + } + + sendMail = false; + } +} diff --git a/src/AuctionHouseBotMailScript.h b/src/AuctionHouseBotMailScript.h new file mode 100644 index 0000000..dbd0b8d --- /dev/null +++ b/src/AuctionHouseBotMailScript.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 + */ + +#ifndef AUCTION_HOUSE_BOT_MAIL_SCRIPT_H +#define AUCTION_HOUSE_BOT_MAIL_SCRIPT_H + +#include "ScriptMgr.h" +#include "Mail.h" + +// ============================================================================= +// Interaction with the mailing systems +// ============================================================================= + +class AHBot_MailScript : public MailScript +{ +public: + AHBot_MailScript(); + + void OnBeforeMailDraftSendMailTo(MailDraft* mailDraft, MailReceiver const& receiver, MailSender const& sender, MailCheckMask& checked, uint32& deliver_delay, uint32& custom_expiration, bool& deleteMailItemsFromDB, bool& sendMail) override; +}; + +#endif /* AUCTION_HOUSE_BOT_MAIL_SCRIPT_H */ \ No newline at end of file diff --git a/src/AuctionHouseBotScript.cpp b/src/AuctionHouseBotScript.cpp index 19ef7c8..5cf7149 100644 --- a/src/AuctionHouseBotScript.cpp +++ b/src/AuctionHouseBotScript.cpp @@ -1,88 +1,20 @@ /* * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 -*/ + */ -#include "ScriptMgr.h" +// #include "ScriptMgr.h" #include "AuctionHouseBot.h" -#include "Log.h" -#include "Mail.h" -#include "Player.h" -#include "WorldSession.h" - -class AHBot_WorldScript : public WorldScript -{ -public: - AHBot_WorldScript() : WorldScript("AHBot_WorldScript") { } - - void OnBeforeConfigLoad(bool /*reload*/) override - { - auctionbot->InitializeConfiguration(); - } - - void OnStartup() override - { - LOG_INFO("server.loading", "Initialize AuctionHouseBot..."); - auctionbot->Initialize(); - } -}; - -class AHBot_AuctionHouseScript : public AuctionHouseScript -{ -public: - AHBot_AuctionHouseScript() : AuctionHouseScript("AHBot_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()) - { - sendNotification = false; - updateAchievementCriteria = false; - } - } - - void OnBeforeAuctionHouseMgrSendAuctionExpiredMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* /*auction*/, Player* owner, uint32& /*owner_accId*/, bool& sendNotification, bool& /*sendMail*/) override - { - if (owner && owner->GetGUID().GetCounter() == auctionbot->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); - } - - void OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionEntry* auction) override - { - auctionbot->IncrementItemCounts(auction); - } - - void OnAuctionRemove(AuctionHouseObject* /*ah*/, AuctionEntry* auction) override - { - auctionbot->DecrementItemCounts(auction, auction->item_template); - } - - void OnBeforeAuctionHouseMgrUpdate() override - { - auctionbot->Update(); - } -}; - -class AHBot_MailScript : public MailScript -{ -public: - AHBot_MailScript() : MailScript("AHBot_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 (sender.GetMailMessageType() == MAIL_AUCTION) // auction mail with items - deleteMailItemsFromDB = true; - sendMail = false; - } - } -}; +#include "AuctionHouseBotAuctionHouseScript.h" +#include "AuctionHouseBotMailScript.h" +#include "AuctionHouseBotWorldScript.h" +// #include "Log.h" +// #include "Mail.h" +// #include "Player.h" +// #include "WorldSession.h" + +// ============================================================================= +// This provides the effective startup of the module by istanciating the scripts +// ============================================================================= void AddAHBotScripts() { diff --git a/src/AuctionHouseBotWorldScript.cpp b/src/AuctionHouseBotWorldScript.cpp new file mode 100644 index 0000000..5238fa2 --- /dev/null +++ b/src/AuctionHouseBotWorldScript.cpp @@ -0,0 +1,122 @@ +#include "Config.h" +#include "Log.h" + +#include "AuctionHouseBot.h" +#include "AuctionHouseBotCommon.h" +#include "AuctionHouseBotWorldScript.h" + +// ============================================================================= +// Initialization of the bot during the world startup +// ============================================================================= + +AHBot_WorldScript::AHBot_WorldScript() : WorldScript("AHBot_WorldScript") +{ + +} + +void AHBot_WorldScript::OnBeforeConfigLoad(bool /*reload*/) +{ + // + // Retrieve how many bots shall be operating on the auction market + // + + bool debug = sConfigMgr->GetOption ("AuctionHouseBot.DEBUG" , false); + uint32 account = sConfigMgr->GetOption("AuctionHouseBot.Account", 0); + uint32 player = sConfigMgr->GetOption("AuctionHouseBot.GUID" , 0); + + // + // All the bots bound to the provided account will be used for auctioning, if GUID is zero. + // Otherwise only the specified character is used. + // + + if (account == 0 && player == 0) + { + LOG_ERROR("server.loading", "AHBot: Account id and player id missing from configuration; is that the right file?"); + return; + } + else + { + QueryResult result = CharacterDatabase.Query("SELECT guid FROM characters WHERE account = {}", account); + + if (result) + { + gBotsId.clear(); + + do + { + Field* fields = result->Fetch(); + uint32 botId = fields[0].Get(); + + if (player == 0) + { + if (debug) + { + LOG_INFO("server.loading", "AHBot: New bot to start, account={} character={}", account, botId); + } + + gBotsId.insert(botId); + } + else + { + if (player == botId) + { + if (debug) + { + LOG_INFO("server.loading", "AHBot: Starting only one bot, account={} character={}", account, botId); + } + + gBotsId.insert(botId); + break; + } + } + + } while (result->NextRow()); + } + else + { + LOG_ERROR("server.loading", "AHBot: Could not query the database for characters of account {}", account); + return; + } + } + + if (gBotsId.size() == 0) + { + LOG_ERROR("server.loading", "AHBot: no characters registered for account {}", account); + return; + } + + // + // Preparare the global configuration for all factions using the configuration just read + // + + gAllianceConfig->Initialize(gBotsId); + gHordeConfig->Initialize (gBotsId); + gNeutralConfig->Initialize (gBotsId); +} + +void AHBot_WorldScript::OnStartup() +{ + LOG_INFO("server.loading", "Initialize AuctionHouseBot..."); + + // + // Initialize the configuration items bins here, when items has been handled by the object manager + // + + gAllianceConfig->InitializeBins(); + gHordeConfig->InitializeBins (); + gNeutralConfig->InitializeBins (); + + // + // Starts the amount of bots read furing the configuration phase + // + + uint32 account = sConfigMgr->GetOption("AuctionHouseBot.Account", 0); + + for (uint32 id: gBotsId) + { + AuctionHouseBot* bot = new AuctionHouseBot(account, id); + bot->Initialize(gAllianceConfig, gHordeConfig, gNeutralConfig); + + gBots.insert(bot); + } +} diff --git a/src/AuctionHouseBotWorldScript.h b/src/AuctionHouseBotWorldScript.h new file mode 100644 index 0000000..e455595 --- /dev/null +++ b/src/AuctionHouseBotWorldScript.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 + */ + +#ifndef AUCTION_HOUSE_BOT_WORLD_SCRIPT_H +#define AUCTION_HOUSE_BOT_WORLD_SCRIPT_H + +#include "ScriptMgr.h" + +// ============================================================================= +// Interaction with the world core mechanisms +// ============================================================================= + +class AHBot_WorldScript : public WorldScript +{ +public: + AHBot_WorldScript(); + + void OnBeforeConfigLoad(bool reload) override; + void OnStartup() override; +}; + +#endif /* AUCTION_HOUSE_BOT_WORLD_SCRIPT_H */ \ No newline at end of file diff --git a/src/cs_ah_bot.cpp b/src/cs_ah_bot.cpp index b02bb40..d2941e4 100644 --- a/src/cs_ah_bot.cpp +++ b/src/cs_ah_bot.cpp @@ -36,7 +36,10 @@ using namespace Acore::ChatCommands; class ah_bot_commandscript : public CommandScript { public: - ah_bot_commandscript() : CommandScript("ah_bot_commandscript") { } + ah_bot_commandscript() : CommandScript("ah_bot_commandscript") + { + + } std::vector GetCommands() const override { @@ -44,38 +47,118 @@ class ah_bot_commandscript : public CommandScript { { "ahbotoptions", HandleAHBotOptionsCommand, SEC_GAMEMASTER, Console::Yes } }; + return commandTable; } static bool HandleAHBotOptionsCommand(ChatHandler* handler, const char*args) { uint32 ahMapID = 0; - char* opt = strtok((char*)args, " "); - char* ahMapIdStr = strtok(NULL, " "); + char* opt = strtok((char*)args, " "); + + if (!opt) + { + handler->PSendSysMessage("Invalid syntax"); + handler->PSendSysMessage("Try ahbotoptions help to see a list of options."); + + return false; + } + + // + // Support function the item quality + // auto qualityStringToEnum = [](const char* qualityName, int maxCount) { if (strncmp(qualityName, "grey", maxCount) == 0) + { return ITEM_QUALITY_POOR; + } + if (strncmp(qualityName, "white", maxCount) == 0) + { return ITEM_QUALITY_NORMAL; + } + if (strncmp(qualityName, "green", maxCount) == 0) + { return ITEM_QUALITY_UNCOMMON; + } + if (strncmp(qualityName, "blue", maxCount) == 0) + { return ITEM_QUALITY_RARE; + } + if (strncmp(qualityName, "purple", maxCount) == 0) + { return ITEM_QUALITY_EPIC; + } + if (strncmp(qualityName, "orange", maxCount) == 0) + { return ITEM_QUALITY_LEGENDARY; + } + if (strncmp(qualityName, "yellow", maxCount) == 0) + { return ITEM_QUALITY_ARTIFACT; + } return static_cast(-1); // Invalid }; + // + // Commands which does not requires an AH + // + + int l = strlen(opt); + + if (strncmp(opt, "buyer", l) == 0) + { + char* param1 = strtok(NULL, " "); + + if (!param1) + { + handler->PSendSysMessage("Syntax is: ahbotoptions buyer $state (0 off 1 on)"); + return false; + } + + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::buyer, 0, 0, param1); + } + + return true; + } + else if (strncmp(opt, "seller", l) == 0) + { + char* param1 = strtok(NULL, " "); + + if (!param1) + { + handler->PSendSysMessage("Syntax is: ahbotoptions seller $state (0 off 1 on)"); + return false; + } + + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::seller, 0, 0, param1); + } + + return true; + } + + // + // Retrieve the auction house type + // + + char* ahMapIdStr = strtok(NULL, " "); + if (ahMapIdStr) { ahMapID = uint32(strtoul(ahMapIdStr, NULL, 0)); + switch (ahMapID) { case 2: @@ -88,33 +171,40 @@ class ah_bot_commandscript : public CommandScript } } + // + // Syntax check + // + if (!opt) { - handler->PSendSysMessage("Syntax is: ahbotoptions $option $ahMapID (2, 6 or 7) $parameter"); + handler->PSendSysMessage("Invalid syntax"); handler->PSendSysMessage("Try ahbotoptions help to see a list of options."); + return false; } - int l = strlen(opt); + // + // Commands that do requires an AH id to be performed + // if (strncmp(opt, "help", l) == 0) { handler->PSendSysMessage("AHBot commands:"); - handler->PSendSysMessage("ahexpire"); - handler->PSendSysMessage("minitems"); - handler->PSendSysMessage("maxitems"); - //handler->PSendSysMessage(""); - //handler->PSendSysMessage(""); - handler->PSendSysMessage("percentages"); - handler->PSendSysMessage("minprice"); - handler->PSendSysMessage("maxprice"); - handler->PSendSysMessage("minbidprice"); - handler->PSendSysMessage("maxbidprice"); - handler->PSendSysMessage("maxstack"); - handler->PSendSysMessage("buyerprice"); - handler->PSendSysMessage("bidinterval"); - handler->PSendSysMessage("bidsperinterval"); - handler->PSendSysMessage("reload"); + handler->PSendSysMessage("buyer - enable/disable buyer"); + handler->PSendSysMessage("seller - enable/disabler seller"); + handler->PSendSysMessage("ahexpire - remove all bot auctions"); + handler->PSendSysMessage("minitems - set min auctions"); + handler->PSendSysMessage("maxitems - set max auctions"); + handler->PSendSysMessage("percentages - set selling percentages"); + handler->PSendSysMessage("minprice - set min price"); + handler->PSendSysMessage("maxprice - set max price"); + handler->PSendSysMessage("minbidprice - set min bid price for buyer"); + handler->PSendSysMessage("maxbidprice - set max bid price for buyer"); + handler->PSendSysMessage("maxstack - set max stack"); + handler->PSendSysMessage("buyerprice - set the buyer price policy"); + handler->PSendSysMessage("bidinterval - set the bid interval for buyer"); + handler->PSendSysMessage("bidsperinterval - set the bid amount for buyer"); + return true; } else if (strncmp(opt, "ahexpire", l) == 0) @@ -125,41 +215,52 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(AHBotCommand::ahexpire, ahMapID, 0, NULL); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::ahexpire, ahMapID, 0, NULL); + } } else if (strncmp(opt, "minitems", l) == 0) { char* param1 = strtok(NULL, " "); + if (!ahMapIdStr || !param1) { handler->PSendSysMessage("Syntax is: ahbotoptions minitems $ahMapID (2, 6 or 7) $minItems"); return false; } - auctionbot->Commands(AHBotCommand::minitems, ahMapID, 0, param1); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::minitems, ahMapID, 0, param1); + } } else if (strncmp(opt, "maxitems", l) == 0) { char* param1 = strtok(NULL, " "); + if (!ahMapIdStr || !param1) { handler->PSendSysMessage("Syntax is: ahbotoptions maxitems $ahMapID (2, 6 or 7) $maxItems"); return false; } - auctionbot->Commands(AHBotCommand::maxitems, ahMapID, 0, param1); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::maxitems, ahMapID, 0, param1); + } } else if (strncmp(opt, "percentages", l) == 0) { - char* param1 = strtok(NULL, " "); - char* param2 = strtok(NULL, " "); - char* param3 = strtok(NULL, " "); - char* param4 = strtok(NULL, " "); - char* param5 = strtok(NULL, " "); - char* param6 = strtok(NULL, " "); - char* param7 = strtok(NULL, " "); - char* param8 = strtok(NULL, " "); - char* param9 = strtok(NULL, " "); + char* param1 = strtok(NULL, " "); + char* param2 = strtok(NULL, " "); + char* param3 = strtok(NULL, " "); + char* param4 = strtok(NULL, " "); + char* param5 = strtok(NULL, " "); + char* param6 = strtok(NULL, " "); + char* param7 = strtok(NULL, " "); + char* param8 = strtok(NULL, " "); + char* param9 = strtok(NULL, " "); char* param10 = strtok(NULL, " "); char* param11 = strtok(NULL, " "); char* param12 = strtok(NULL, " "); @@ -172,38 +273,36 @@ class ah_bot_commandscript : public CommandScript handler->PSendSysMessage("1 GreyTradeGoods 2 WhiteTradeGoods 3 GreenTradeGoods 4 BlueTradeGoods 5 PurpleTradeGoods"); handler->PSendSysMessage("6 OrangeTradeGoods 7 YellowTradeGoods 8 GreyItems 9 WhiteItems 10 GreenItems 11 BlueItems"); handler->PSendSysMessage("12 PurpleItems 13 OrangeItems 14 YellowItems"); - handler->PSendSysMessage("The total must add up to 100%%"); + return false; } - uint32 greytg = uint32(strtoul(param1, NULL, 0)); - uint32 whitetg = uint32(strtoul(param2, NULL, 0)); - uint32 greentg = uint32(strtoul(param3, NULL, 0)); - uint32 bluetg = uint32(strtoul(param4, NULL, 0)); - uint32 purpletg = uint32(strtoul(param5, NULL, 0)); - uint32 orangetg = uint32(strtoul(param6, NULL, 0)); - uint32 yellowtg = uint32(strtoul(param7, NULL, 0)); - uint32 greyi = uint32(strtoul(param8, NULL, 0)); - uint32 whitei = uint32(strtoul(param9, NULL, 0)); - uint32 greeni = uint32(strtoul(param10, NULL, 0)); - uint32 bluei = uint32(strtoul(param11, NULL, 0)); - uint32 purplei = uint32(strtoul(param12, NULL, 0)); - uint32 orangei = uint32(strtoul(param13, NULL, 0)); - uint32 yellowi = uint32(strtoul(param14, NULL, 0)); + uint32 greytg = uint32(strtoul(param1, NULL, 0)); + uint32 whitetg = uint32(strtoul(param2, NULL, 0)); + uint32 greentg = uint32(strtoul(param3, NULL, 0)); + uint32 bluetg = uint32(strtoul(param4, NULL, 0)); + uint32 purpletg = uint32(strtoul(param5, NULL, 0)); + uint32 orangetg = uint32(strtoul(param6, NULL, 0)); + uint32 yellowtg = uint32(strtoul(param7, NULL, 0)); + uint32 greyi = uint32(strtoul(param8, NULL, 0)); + uint32 whitei = uint32(strtoul(param9, NULL, 0)); + uint32 greeni = uint32(strtoul(param10, NULL, 0)); + uint32 bluei = uint32(strtoul(param11, NULL, 0)); + uint32 purplei = uint32(strtoul(param12, NULL, 0)); + uint32 orangei = uint32(strtoul(param13, NULL, 0)); + uint32 yellowi = uint32(strtoul(param14, NULL, 0)); + uint32 totalPercent = greytg + whitetg + greentg + bluetg + purpletg + orangetg + yellowtg + greyi + whitei + greeni + bluei + purplei + orangei + yellowi; if (totalPercent == 0 || totalPercent != 100) { - handler->PSendSysMessage("Syntax is: ahbotoptions percentages $ahMapID (2, 6 or 7) $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14"); - handler->PSendSysMessage("1 GreyTradeGoods 2 WhiteTradeGoods 3 GreenTradeGoods 4 BlueTradeGoods 5 PurpleTradeGoods"); - handler->PSendSysMessage("6 OrangeTradeGoods 7 YellowTradeGoods 8 GreyItems 9 WhiteItems 10 GreenItems 11 BlueItems"); - handler->PSendSysMessage("12 PurpleItems 13 OrangeItems 14 YellowItems"); handler->PSendSysMessage("The total must add up to 100%%"); + return false; } - char param[100]; - param[0] = '\0'; + char param[100] = { 0 }; + strcat(param, param1); strcat(param, " "); strcat(param, param2); @@ -231,7 +330,11 @@ class ah_bot_commandscript : public CommandScript strcat(param, param13); strcat(param, " "); strcat(param, param14); - auctionbot->Commands(AHBotCommand::percentages, ahMapID, 0, param); + + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::percentages, ahMapID, 0, param); + } } else if (strncmp(opt, "minprice", l) == 0) { @@ -245,8 +348,14 @@ class ah_bot_commandscript : public CommandScript } auto quality = qualityStringToEnum(param1, l); + if (quality != static_cast(-1)) - auctionbot->Commands(AHBotCommand::minprice, ahMapID, quality, param2); + { + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::minprice, ahMapID, quality, param2); + } + } else { handler->PSendSysMessage("Syntax is: ahbotoptions minprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); @@ -257,6 +366,7 @@ class ah_bot_commandscript : public CommandScript { char* param1 = strtok(NULL, " "); char* param2 = strtok(NULL, " "); + if (!ahMapIdStr || !param1 || !param2) { handler->PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); @@ -264,8 +374,14 @@ class ah_bot_commandscript : public CommandScript } auto quality = qualityStringToEnum(param1, l); + if (quality != static_cast(-1)) - auctionbot->Commands(AHBotCommand::maxprice, ahMapID, quality, param2); + { + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::maxprice, ahMapID, quality, param2); + } + } else { handler->PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); @@ -284,6 +400,7 @@ class ah_bot_commandscript : public CommandScript } uint32 minBidPrice = uint32(strtoul(param2, NULL, 0)); + if (minBidPrice < 1 || minBidPrice > 100) { handler->PSendSysMessage("The min bid price multiplier must be between 1 and 100"); @@ -291,8 +408,14 @@ class ah_bot_commandscript : public CommandScript } auto quality = qualityStringToEnum(param1, l); + if (quality != static_cast(-1)) - auctionbot->Commands(AHBotCommand::minbidprice, ahMapID, quality, param2); + { + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::minbidprice, ahMapID, quality, param2); + } + } else { handler->PSendSysMessage("Syntax is: ahbotoptions minbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); @@ -311,6 +434,7 @@ class ah_bot_commandscript : public CommandScript } uint32 maxBidPrice = uint32(strtoul(param2, NULL, 0)); + if (maxBidPrice < 1 || maxBidPrice > 100) { handler->PSendSysMessage("The max bid price multiplier must be between 1 and 100"); @@ -318,8 +442,14 @@ class ah_bot_commandscript : public CommandScript } auto quality = qualityStringToEnum(param1, l); + if (quality != static_cast(-1)) - auctionbot->Commands(AHBotCommand::maxbidprice, ahMapID, quality, param2); + { + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::maxbidprice, ahMapID, quality, param2); + } + } else { handler->PSendSysMessage("Syntax is: ahbotoptions max bidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); @@ -345,8 +475,14 @@ class ah_bot_commandscript : public CommandScript // } auto quality = qualityStringToEnum(param1, l); + if (quality != static_cast(-1)) - auctionbot->Commands(AHBotCommand::maxstack, ahMapID, quality, param2); + { + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::maxstack, ahMapID, quality, param2); + } + } else { handler->PSendSysMessage("Syntax is: ahbotoptions maxstack $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $value"); @@ -365,8 +501,14 @@ class ah_bot_commandscript : public CommandScript } auto quality = qualityStringToEnum(param1, l); + if (quality != static_cast(-1)) - auctionbot->Commands(AHBotCommand::buyerprice, ahMapID, quality, param2); + { + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::buyerprice, ahMapID, quality, param2); + } + } else { handler->PSendSysMessage("Syntax is: ahbotoptions buyerprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue or purple) $price"); @@ -383,7 +525,10 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(AHBotCommand::bidinterval, ahMapID, 0, param1); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::bidinterval, ahMapID, 0, param1); + } } else if (strncmp(opt, "bidsperinterval", l) == 0) { @@ -395,15 +540,19 @@ class ah_bot_commandscript : public CommandScript return false; } - auctionbot->Commands(AHBotCommand::bidsperinterval, ahMapID, 0, param1); + for (AuctionHouseBot* bot: gBots) + { + bot->Commands(AHBotCommand::bidsperinterval, ahMapID, 0, param1); + } } else { - handler->PSendSysMessage("Syntax is: ahbotoptions $option $ahMapID (2, 6 or 7) $parameter"); + handler->PSendSysMessage("Invalid syntax"); handler->PSendSysMessage("Try ahbotoptions help to see a list of options."); return false; } + handler->PSendSysMessage("Done"); return true; } };