From 756e4df72571e3428069763d983ee16a9d3fa1b7 Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Wed, 15 Jan 2025 19:33:36 -0500 Subject: [PATCH 01/11] Fix Bug: Only finds a single auction #129 from azerothcore\mod-ah-bot https://github.com/azerothcore/mod-ah-bot/issues/129 remove break in AuctionHouseBot::getNofAuctions to avoid always returning 1 auction when using ConsiderOnlyBotAuctions true --- src/AuctionHouseBot.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index 8006012..a037aa2 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -164,7 +164,6 @@ uint32 AuctionHouseBot::getNofAuctions(AHBConfig* config, AuctionHouseObject* au if (guid == Aentry->owner) { count++; - break; } } From 610bb282babc1580fb0ec4fd1c78ebb48df864d0 Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Fri, 17 Jan 2025 08:55:37 -0500 Subject: [PATCH 02/11] Update AuctionHouseBotConfig.cpp Fix Bug: wrong variable read from the config #123 from azerothcore / mod-ah-bot https://github.com/azerothcore/mod-ah-bot/issues/123 Fix copy paste typo when reading config for ElapsingTimeClass --- src/AuctionHouseBotConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AuctionHouseBotConfig.cpp b/src/AuctionHouseBotConfig.cpp index 11b09c2..bde3737 100644 --- a/src/AuctionHouseBotConfig.cpp +++ b/src/AuctionHouseBotConfig.cpp @@ -2045,7 +2045,7 @@ void AHBConfig::InitializeFromFile() MarketResetThreshold = sConfigMgr->GetOption("AuctionHouseBot.MarketResetThreshold" , 25); DuplicatesCount = sConfigMgr->GetOption("AuctionHouseBot.DuplicatesCount" , 0); DivisibleStacks = sConfigMgr->GetOption ("AuctionHouseBot.DivisibleStacks" , false); - ElapsingTimeClass = sConfigMgr->GetOption("AuctionHouseBot.DuplicatesCount" , 1); + ElapsingTimeClass = sConfigMgr->GetOption("AuctionHouseBot.ElapsingTimeClass" , 1); ConsiderOnlyBotAuctions = sConfigMgr->GetOption ("AuctionHouseBot.ConsiderOnlyBotAuctions", false); ItemsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.ItemsPerCycle" , 200); From 565ebd082762e1c99452833192b7116d6e0161eb Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:02:13 -0500 Subject: [PATCH 03/11] Try fix auction house inventory decrease over time Merge some fix from multiple contriburors. Thanks to code from PixelWeaver, Icemansparks Added some sanity checks in AHBConfig::DecItemCounts made sure to remove auctions when item is not found Co-Authored-By: Dennis Co-Authored-By: Antoine Cajot <8446329+pixelweaver@users.noreply.github.com> --- src/AuctionHouseBot.cpp | 233 +++++++++++++++------- src/AuctionHouseBotAuctionHouseScript.cpp | 24 ++- src/AuctionHouseBotConfig.cpp | 74 ++++++- src/AuctionHouseBotConfig.h | 4 +- 4 files changed, 244 insertions(+), 91 deletions(-) diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index a037aa2..8ac91e0 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -171,7 +171,7 @@ uint32 AuctionHouseBot::getNofAuctions(AHBConfig* config, AuctionHouseObject* au } // ============================================================================= -// This routine performs the bidding operations for the bot +// This routine performs the bidding/buyout operations for the bot // ============================================================================= void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* session) @@ -186,39 +186,45 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se } // - // Retrieve items not owner by the bot and not bought by the bot + // Retrieve items not owned by the bot and not bought/bidded on by the bot // - QueryResult result = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE itemowner<>{} AND buyguid<>{}", _id, _id); - if (!result) + QueryResult ahContentQueryResult = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE itemowner<>{} AND buyguid<>{}", _id, _id); + + if (!ahContentQueryResult) { return; } - if (result->GetRowCount() == 0) + if (ahContentQueryResult->GetRowCount() == 0) { return; } + if (config->DebugOutBuyer) + { + LOG_INFO("module", "AHBot [{}]: Performing Buy operations for AH={} nbOfAuctions={}", _id, config->GetAHID(), ahContentQueryResult->GetRowCount()); + } + // // Fetches content of selected AH to look for possible bids // AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); - std::set possibleBids; + std::vector auctionsGuidsToConsider; do { - uint32 tmpdata = result->Fetch()->Get(); - possibleBids.insert(tmpdata); - } while (result->NextRow()); + uint32 autionGuid = ahContentQueryResult->Fetch()->Get(); + auctionsGuidsToConsider.push_back(autionGuid); + } while (ahContentQueryResult->NextRow()); // // If it's not possible to bid stop here // - if (possibleBids.empty()) + if (auctionsGuidsToConsider.empty()) { if (config->DebugOutBuyer) { @@ -232,27 +238,36 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Perform the operation for a maximum amount of bids attempts configured // + if (config->TraceBuyer) + { + LOG_INFO("module", "AHBot [{}]: Considering {} auctions per interval to bid on.", _id, config->GetBidsPerInterval()); + } + for (uint32 count = 1; count <= config->GetBidsPerInterval(); ++count) { // // Choose a random auction from possible auctions // - uint32 randBid = urand(0, possibleBids.size() - 1); + uint32 randomIndex = urand(0, auctionsGuidsToConsider.size() - 1); - std::set::iterator it = possibleBids.begin(); - std::advance(it, randBid); + std::vector::iterator itBegin = auctionsGuidsToConsider.begin(); + //std::advance(it, randomIndex); - AuctionEntry* auction = auctionHouse->GetAuction(*it); + AuctionEntry* auction = auctionHouse->GetAuction(auctionsGuidsToConsider.at(randomIndex)); // // Prevent to bid again on the same auction // - possibleBids.erase(randBid); + auctionsGuidsToConsider.erase(itBegin + randomIndex); if (!auction) { + if (config->DebugOutBuyer) + { + LOG_ERROR("module", "AHBot [{}]: item {} Possible entry to buy/bid from AH pool is invalid, this should not happen, moving on next auciton"); + } continue; } @@ -287,33 +302,54 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template); + // - // Check which price we have to use, startbid or if it is bidded already + // Determine current price. // + uint32 currentPrice = auction->bid ? auction->bid : auction->startbid; - uint32 currentprice; + // + // Determine maximum bid and skip auctions with too high a currentPrice. + // - if (auction->bid) + double basePrice = config->UseBuyPriceForBuyer ? prototype->BuyPrice : prototype->SellPrice; + double maximumBid = basePrice * pItem->GetCount() * config->GetBuyerPrice(prototype->Quality); + + if (config->TraceBuyer) { - currentprice = auction->bid; + LOG_INFO("module", "-------------------------------------------------"); + 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 Max: {}", _id, maximumBid); + 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 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", "-------------------------------------------------"); } - else + + if (currentPrice > maximumBid) { - currentprice = auction->startbid; + if (config->TraceBuyer) + { + LOG_INFO("module", "AHBot [{}]: Current price too high, skipped.", _id); + } + continue; } - // - // Prepare portion from maximum bid - // - - double bidrate = static_cast(urand(1, 100)) / 100; - long double bidMax = 0; - - // - // Check that bid has an acceptable value and take bid based on vendorprice, stacksize and quality - // - - if (config->BuyMethod) + /*if (config->UseBuyPriceForBuyer) { if (prototype->Quality <= AHB_MAX_QUALITY) { @@ -350,7 +386,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se continue; } - } + }*/ // // Recalculate the bid depending on the type of the item @@ -358,20 +394,32 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se switch (prototype->Class) { - // ammo - case 6: - bidMax = 0; + case ITEM_CLASS_PROJECTILE: + maximumBid = 0; + break; + case ITEM_CLASS_GENERIC: + maximumBid = 0; + break; + case ITEM_CLASS_MONEY: + maximumBid = 0; + break; + case ITEM_CLASS_PERMANENT: + maximumBid = 0; break; default: break; } // - // Test the computed bid + // Make sure to skip the auction if maximum bid is 0. // - if (bidMax == 0) + if (maximumBid == 0) { + if (config->TraceBuyer) + { + LOG_INFO("module", "AHBot [{}]: Maximum bid value for item class {} is 0, skipped.", _id, prototype->Class); + } continue; } @@ -379,23 +427,43 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Calculate our bid // - long double bidvalue = currentprice + ((bidMax - currentprice) * bidrate); - uint32 bidprice = static_cast(bidvalue); + double bidRate = static_cast(urand(1, 100)) / 100; + double bidValue = currentPrice + ((maximumBid - currentPrice) * bidRate); + uint32 bidPrice = static_cast(bidValue); // // Check our bid is high enough to be valid. If not, correct it to minimum. // + uint32 minimumOutbid = auction->GetAuctionOutBid(); + if ((currentPrice + minimumOutbid) > bidPrice) + { + bidPrice = currentPrice + minimumOutbid; + } - if ((currentprice + auction->GetAuctionOutBid()) > bidprice) + if (bidPrice > maximumBid) { - bidprice = currentprice + auction->GetAuctionOutBid(); + if (config->TraceBuyer) + { + LOG_INFO("module", "AHBot [{}]: Bid was above bidMax for item={} AH={}", _id, auction->item_guid.ToString(), config->GetAHID()); + } + bidPrice = maximumBid; + } + + if (config->DebugOutBuyer) + { + LOG_INFO("module", "-------------------------------------------------"); + LOG_INFO("module", "AHBot [{}]: Bid Rate: {}", _id, bidRate); + LOG_INFO("module", "AHBot [{}]: Bid Value: {}", _id, bidValue); + LOG_INFO("module", "AHBot [{}]: Bid Price: {}", _id, bidPrice); + LOG_INFO("module", "AHBot [{}]: Minimum Outbid: {}", _id, minimumOutbid); + LOG_INFO("module", "-------------------------------------------------"); } // // Print out debug info // - if (config->DebugOutBuyer) + /*if (config->DebugOutBuyer) { LOG_INFO("module", "-------------------------------------------------"); LOG_INFO("module", "AHBot [{}]: Info for Auction #{}:", _id, auction->Id); @@ -422,18 +490,16 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se 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)) + if ((bidPrice < auction->buyout) || (auction->buyout == 0)) { // - // Perform a new bid on the auction + // Return money to last bidder. // if (auction->bidder) @@ -444,26 +510,28 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Mail to last bidder and return their money // - auto trans = CharacterDatabase.BeginTransaction(); - - sAuctionMgr->SendAuctionOutbiddedMail(auction, bidprice, session->GetPlayer(), trans); + auto trans = CharacterDatabase.BeginTransaction(); + sAuctionMgr->SendAuctionOutbiddedMail(auction, bidPrice, session->GetPlayer(), trans); CharacterDatabase.CommitTransaction (trans); } } auction->bidder = AHBplayer->GetGUID(); - auction->bid = bidprice; + auction->bid = bidPrice; // - // Save the auction into database + // update/save the auction into database // CharacterDatabase.Execute("UPDATE auctionhouse SET buyguid = '{}', lastbid = '{}' WHERE id = '{}'", auction->bidder.GetCounter(), auction->bid, auction->Id); + + if (config->TraceBuyer) + { + LOG_INFO("module", "AHBot [{}]: New bid, id={}, ah={}, item={}, start={}, current={}, buyout={}", _id, prototype->ItemId, auction->GetHouseId(), auction->item_template, auction->startbid, currentPrice, auction->buyout); + } } else { - bought = true; - // // Perform the buyout // @@ -473,21 +541,21 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se if ((auction->bidder) && (AHBplayer->GetGUID() != auction->bidder)) { // - // Send the mail to the last bidder + // Mail to last bidder and return their money // 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->SendAuctionSuccessfulMail(auction, trans); - sAuctionMgr->SendAuctionWonMail (auction, trans); + sAuctionMgr->SendAuctionWonMail(auction, trans); // // Removes any trace of the item @@ -495,25 +563,14 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se auction->DeleteFromDB(trans); - sAuctionMgr->RemoveAItem (auction->item_guid); + sAuctionMgr->RemoveAItem(auction->item_guid); auctionHouse->RemoveAuction(auction); CharacterDatabase.CommitTransaction(trans); - } - // - // Tracing - // - - if (config->TraceBuyer) - { - if (bought) + if (config->TraceBuyer) { - LOG_INFO("module", "AHBot [{}]: Bought , id={}, ah={}, item={}, start={}, current={}, buyout={}", _id, prototype->ItemId, auction->GetHouseId(), auction->item_template, auction->startbid, currentprice, auction->buyout); - } - else - { - LOG_INFO("module", "AHBot [{}]: New bid, id={}, ah={}, item={}, start={}, current={}, buyout={}", _id, prototype->ItemId, auction->GetHouseId(), auction->item_template, auction->startbid, currentprice, auction->buyout); + LOG_INFO("module", "AHBot [{}]: Bought , id={}, ah={}, item={}, start={}, current={}, buyout={}", _id, prototype->ItemId, auction->GetHouseId(), auction->item_template, auction->startbid, currentPrice, auction->buyout); } } } @@ -859,7 +916,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) if (buyoutPrice == 0) { - if (config->SellMethod) + if (config->UseBuyPriceForSeller) { buyoutPrice = prototype->BuyPrice; } @@ -1044,6 +1101,8 @@ void AuctionHouseBot::Update() ObjectAccessor::AddObject(&_AHBplayer); + LOG_INFO("module", "AHBot [{}]: Begin Performing Update Cycle", _id); + // // Perform update for the factions markets // @@ -1056,10 +1115,20 @@ void AuctionHouseBot::Update() if (_allianceConfig) { + if (_allianceConfig->TraceSeller) + { + LOG_INFO("module", "AHBot [{}]: Begin Sell for Alliance", _id); + } + Sell(&_AHBplayer, _allianceConfig); if (((_newrun - _lastrun_a_sec) >= (_allianceConfig->GetBiddingInterval() * MINUTE)) && (_allianceConfig->GetBidsPerInterval() > 0)) { + if (_allianceConfig->TraceBuyer) + { + LOG_INFO("module", "AHBot [{}]: Begin Buy for Alliance", _id); + } + Buy(&_AHBplayer, _allianceConfig, &_session); _lastrun_a_sec = _newrun; } @@ -1071,10 +1140,18 @@ void AuctionHouseBot::Update() if (_hordeConfig) { + if (_hordeConfig->TraceSeller) + { + LOG_INFO("module", "AHBot [{}]: Begin Sell for Horde", _id); + } Sell(&_AHBplayer, _hordeConfig); if (((_newrun - _lastrun_h_sec) >= (_hordeConfig->GetBiddingInterval() * MINUTE)) && (_hordeConfig->GetBidsPerInterval() > 0)) { + if (_hordeConfig->TraceBuyer) + { + LOG_INFO("module", "AHBot [{}]: Begin Buy for Horde", _id); + } Buy(&_AHBplayer, _hordeConfig, &_session); _lastrun_h_sec = _newrun; } @@ -1088,10 +1165,18 @@ void AuctionHouseBot::Update() if (_neutralConfig) { + if (_neutralConfig->TraceSeller) + { + LOG_INFO("module", "AHBot [{}]: Begin Sell for Neutral", _id); + } Sell(&_AHBplayer, _neutralConfig); if (((_newrun - _lastrun_n_sec) >= (_neutralConfig->GetBiddingInterval() * MINUTE)) && (_neutralConfig->GetBidsPerInterval() > 0)) { + if (_neutralConfig->TraceBuyer) + { + LOG_INFO("module", "AHBot [{}]: Begin Buy for Neutral", _id); + } Buy(&_AHBplayer, _neutralConfig, &_session); _lastrun_n_sec = _newrun; } diff --git a/src/AuctionHouseBotAuctionHouseScript.cpp b/src/AuctionHouseBotAuctionHouseScript.cpp index 6d8715a..37f1a45 100644 --- a/src/AuctionHouseBotAuctionHouseScript.cpp +++ b/src/AuctionHouseBotAuctionHouseScript.cpp @@ -180,6 +180,8 @@ void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, Aucti Item* pItem = sAuctionMgr->GetAItem(auction->item_guid); + ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template); + if (!pItem) { if (config->DebugOut) @@ -187,15 +189,15 @@ void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, Aucti LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString()); } + // Decrement item counts even if the item does not exist + if (prototype) + { + config->DecItemCounts(prototype->Class, prototype->Quality); + } + 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)); @@ -260,6 +262,16 @@ void AHBot_AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* /*ah*/, Aucti // config->UpdateItemStats(auction->item_template, auction->itemCount, auction->bid); + + // Decrement item counts + 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() diff --git a/src/AuctionHouseBotConfig.cpp b/src/AuctionHouseBotConfig.cpp index bde3737..cde5a1d 100644 --- a/src/AuctionHouseBotConfig.cpp +++ b/src/AuctionHouseBotConfig.cpp @@ -201,8 +201,8 @@ AHBConfig::AHBConfig(uint32 ahid, AHBConfig* conf) TraceBuyer = conf->TraceBuyer; AHBSeller = conf->AHBSeller; AHBBuyer = conf->AHBBuyer; - BuyMethod = conf->BuyMethod; - SellMethod = conf->SellMethod; + UseBuyPriceForBuyer = conf->UseBuyPriceForBuyer; + UseBuyPriceForSeller = conf->UseBuyPriceForSeller; ConsiderOnlyBotAuctions = conf->ConsiderOnlyBotAuctions; ItemsPerCycle = conf->ItemsPerCycle; Vendor_Items = conf->Vendor_Items; @@ -508,8 +508,8 @@ void AHBConfig::Reset() AHBSeller = false; AHBBuyer = false; - BuyMethod = false; - SellMethod = false; + UseBuyPriceForBuyer = false; + UseBuyPriceForSeller = false; SellAtMarketPrice = false; ConsiderOnlyBotAuctions = false; ItemsPerCycle = 200; @@ -1700,58 +1700,114 @@ void AHBConfig::DecItemCounts(uint32 color) { case AHB_GREY_TG: --greyTGoods; + if (greyTGoods < 0) + { + greyTGoods = 0; + } break; case AHB_WHITE_TG: --whiteTGoods; + if (whiteTGoods < 0) + { + whiteTGoods = 0; + } break; case AHB_GREEN_TG: --greenTGoods; + if (greenTGoods < 0) + { + greenTGoods = 0; + } break; case AHB_BLUE_TG: --blueTGoods; + if (blueTGoods < 0) + { + blueTGoods = 0; + } break; case AHB_PURPLE_TG: --purpleTGoods; + if (purpleTGoods < 0) + { + purpleTGoods = 0; + } break; case AHB_ORANGE_TG: --orangeTGoods; + if (orangeTGoods < 0) + { + orangeTGoods = 0; + } break; case AHB_YELLOW_TG: --yellowTGoods; + if (yellowTGoods < 0) + { + yellowTGoods = 0; + } break; case AHB_GREY_I: --greyItems; + if (greyItems < 0) + { + greyItems = 0; + } break; case AHB_WHITE_I: --whiteItems; + if (whiteItems < 0) + { + whiteItems = 0; + } break; case AHB_GREEN_I: --greenItems; + if (greenItems < 0) + { + greenItems = 0; + } break; case AHB_BLUE_I: --blueItems; + if (blueItems < 0) + { + blueItems = 0; + } break; case AHB_PURPLE_I: --purpleItems; + if (purpleItems < 0) + { + purpleItems = 0; + } break; case AHB_ORANGE_I: --orangeItems; + if (orangeItems < 0) + { + orangeItems = 0; + } break; case AHB_YELLOW_I: --yellowItems; + if (yellowItems < 0) + { + yellowItems = 0; + } break; default: @@ -2039,8 +2095,8 @@ void AHBConfig::InitializeFromFile() AHBSeller = sConfigMgr->GetOption ("AuctionHouseBot.EnableSeller" , false); AHBBuyer = sConfigMgr->GetOption ("AuctionHouseBot.EnableBuyer" , false); - SellMethod = sConfigMgr->GetOption ("AuctionHouseBot.UseBuyPriceForSeller" , false); - BuyMethod = sConfigMgr->GetOption ("AuctionHouseBot.UseBuyPriceForBuyer" , false); + UseBuyPriceForSeller = sConfigMgr->GetOption ("AuctionHouseBot.UseBuyPriceForSeller" , false); + UseBuyPriceForBuyer = sConfigMgr->GetOption ("AuctionHouseBot.UseBuyPriceForBuyer" , false); SellAtMarketPrice = sConfigMgr->GetOption ("AuctionHouseBot.UseMarketPriceForSeller", false); MarketResetThreshold = sConfigMgr->GetOption("AuctionHouseBot.MarketResetThreshold" , 25); DuplicatesCount = sConfigMgr->GetOption("AuctionHouseBot.DuplicatesCount" , 0); @@ -2286,9 +2342,9 @@ void AHBConfig::InitializeFromSql(std::set botsIds) // AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(GetAHFID()); - uint32 auctions = auctionHouse->Getcount(); + uint32 numberOfAuctions = auctionHouse->Getcount(); - if (auctions) + if (numberOfAuctions > 0) { for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr) { @@ -2621,7 +2677,7 @@ void AHBConfig::InitializeBins() // Exclude items with no possible price // - if (SellMethod) + if (UseBuyPriceForSeller) { if (itr->second.BuyPrice == 0) { diff --git a/src/AuctionHouseBotConfig.h b/src/AuctionHouseBotConfig.h index c5f4747..f8cc863 100644 --- a/src/AuctionHouseBotConfig.h +++ b/src/AuctionHouseBotConfig.h @@ -180,8 +180,8 @@ class AHBConfig bool AHBSeller; bool AHBBuyer; - bool BuyMethod; - bool SellMethod; + bool UseBuyPriceForBuyer; + bool UseBuyPriceForSeller; bool SellAtMarketPrice; uint32 MarketResetThreshold; bool ConsiderOnlyBotAuctions; From 8c2c7918c814c8f71687719a874f2426e882629a Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Sat, 25 Jan 2025 23:57:18 -0500 Subject: [PATCH 04/11] Fix decrement mistake with unsigned int fix mistake withj unsigned int while hunting for the missing item auctions --- data/sql/db-world/mod_auctionhousebot.sql | 6 +- src/AuctionHouseBotConfig.cpp | 72 +++++++++-------------- 2 files changed, 32 insertions(+), 46 deletions(-) diff --git a/data/sql/db-world/mod_auctionhousebot.sql b/data/sql/db-world/mod_auctionhousebot.sql index ead151d..904f29e 100644 --- a/data/sql/db-world/mod_auctionhousebot.sql +++ b/data/sql/db-world/mod_auctionhousebot.sql @@ -75,9 +75,9 @@ CREATE TABLE `mod_auctionhousebot` ( INSERT INTO `mod_auctionhousebot` (`auctionhouse`, `name`, `minitems`, `maxitems`, `percentgreytradegoods`, `percentwhitetradegoods`, `percentgreentradegoods`, `percentbluetradegoods`, `percentpurpletradegoods`, `percentorangetradegoods`, `percentyellowtradegoods`, `percentgreyitems`, `percentwhiteitems`, `percentgreenitems`, `percentblueitems`, `percentpurpleitems`, `percentorangeitems`, `percentyellowitems`, `minpricegrey`, `maxpricegrey`, `minpricewhite`, `maxpricewhite`, `minpricegreen`, `maxpricegreen`, `minpriceblue`, `maxpriceblue`, `minpricepurple`, `maxpricepurple`, `minpriceorange`, `maxpriceorange`, `minpriceyellow`, `maxpriceyellow`, `minbidpricegrey`, `maxbidpricegrey`, `minbidpricewhite`, `maxbidpricewhite`, `minbidpricegreen`, `maxbidpricegreen`, `minbidpriceblue`, `maxbidpriceblue`, `minbidpricepurple`, `maxbidpricepurple`, `minbidpriceorange`, `maxbidpriceorange`, `minbidpriceyellow`, `maxbidpriceyellow`, `maxstackgrey`, `maxstackwhite`, `maxstackgreen`, `maxstackblue`, `maxstackpurple`, `maxstackorange`, `maxstackyellow`, `buyerpricegrey`, `buyerpricewhite`, `buyerpricegreen`, `buyerpriceblue`, `buyerpricepurple`, `buyerpriceorange`, `buyerpriceyellow`, `buyerbiddinginterval`, `buyerbidsperinterval`) VALUES -(2,'Alliance',250,250,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1), -(6,'Horde',250,250,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1), -(7,'Neutral',250,250,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1); +(2,'Alliance',2500,2500,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1), +(6,'Horde',0,0,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1), +(7,'Neutral',0,0,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1); -- -- Items blacklist diff --git a/src/AuctionHouseBotConfig.cpp b/src/AuctionHouseBotConfig.cpp index cde5a1d..5346f59 100644 --- a/src/AuctionHouseBotConfig.cpp +++ b/src/AuctionHouseBotConfig.cpp @@ -1699,114 +1699,100 @@ void AHBConfig::DecItemCounts(uint32 color) switch (color) { case AHB_GREY_TG: - --greyTGoods; - if (greyTGoods < 0) + if (greyTGoods > 0) { - greyTGoods = 0; + --greyTGoods; } break; case AHB_WHITE_TG: - --whiteTGoods; - if (whiteTGoods < 0) + if (whiteTGoods > 0) { - whiteTGoods = 0; + --whiteTGoods; } break; - case AHB_GREEN_TG: - --greenTGoods; - if (greenTGoods < 0) + case AHB_GREEN_TG: + if (greenTGoods > 0) { - greenTGoods = 0; + --greenTGoods; } break; case AHB_BLUE_TG: - --blueTGoods; - if (blueTGoods < 0) + if (blueTGoods > 0) { - blueTGoods = 0; + --blueTGoods; } break; case AHB_PURPLE_TG: - --purpleTGoods; - if (purpleTGoods < 0) + if (purpleTGoods > 0) { - purpleTGoods = 0; + --purpleTGoods; } break; case AHB_ORANGE_TG: - --orangeTGoods; - if (orangeTGoods < 0) + if (orangeTGoods > 0) { - orangeTGoods = 0; + --orangeTGoods; } break; case AHB_YELLOW_TG: - --yellowTGoods; - if (yellowTGoods < 0) + if (yellowTGoods > 0) { - yellowTGoods = 0; + --yellowTGoods; } break; case AHB_GREY_I: - --greyItems; - if (greyItems < 0) + if (greyItems > 0) { - greyItems = 0; + --greyItems; } break; case AHB_WHITE_I: - --whiteItems; - if (whiteItems < 0) + if (whiteItems > 0) { - whiteItems = 0; + --whiteItems; } break; case AHB_GREEN_I: - --greenItems; - if (greenItems < 0) + if (greenItems > 0) { - greenItems = 0; + --greenItems; } break; case AHB_BLUE_I: - --blueItems; - if (blueItems < 0) + if (blueItems > 0) { - blueItems = 0; + --blueItems; } break; case AHB_PURPLE_I: - --purpleItems; - if (purpleItems < 0) + if (purpleItems > 0) { - purpleItems = 0; + --purpleItems; } break; case AHB_ORANGE_I: - --orangeItems; - if (orangeItems < 0) + if (orangeItems > 0) { - orangeItems = 0; + --orangeItems; } break; case AHB_YELLOW_I: - --yellowItems; - if (yellowItems < 0) + if (yellowItems > 0) { - yellowItems = 0; + --yellowItems; } break; From c1b5928daf5112d8e9d33c25f09259355db8f884 Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Sun, 26 Jan 2025 00:00:09 -0500 Subject: [PATCH 05/11] Put back original values. Git manipulation mistake revert back sql file to default values, git usage mistake --- data/sql/db-world/mod_auctionhousebot.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/sql/db-world/mod_auctionhousebot.sql b/data/sql/db-world/mod_auctionhousebot.sql index 904f29e..ead151d 100644 --- a/data/sql/db-world/mod_auctionhousebot.sql +++ b/data/sql/db-world/mod_auctionhousebot.sql @@ -75,9 +75,9 @@ CREATE TABLE `mod_auctionhousebot` ( INSERT INTO `mod_auctionhousebot` (`auctionhouse`, `name`, `minitems`, `maxitems`, `percentgreytradegoods`, `percentwhitetradegoods`, `percentgreentradegoods`, `percentbluetradegoods`, `percentpurpletradegoods`, `percentorangetradegoods`, `percentyellowtradegoods`, `percentgreyitems`, `percentwhiteitems`, `percentgreenitems`, `percentblueitems`, `percentpurpleitems`, `percentorangeitems`, `percentyellowitems`, `minpricegrey`, `maxpricegrey`, `minpricewhite`, `maxpricewhite`, `minpricegreen`, `maxpricegreen`, `minpriceblue`, `maxpriceblue`, `minpricepurple`, `maxpricepurple`, `minpriceorange`, `maxpriceorange`, `minpriceyellow`, `maxpriceyellow`, `minbidpricegrey`, `maxbidpricegrey`, `minbidpricewhite`, `maxbidpricewhite`, `minbidpricegreen`, `maxbidpricegreen`, `minbidpriceblue`, `maxbidpriceblue`, `minbidpricepurple`, `maxbidpricepurple`, `minbidpriceorange`, `maxbidpriceorange`, `minbidpriceyellow`, `maxbidpriceyellow`, `maxstackgrey`, `maxstackwhite`, `maxstackgreen`, `maxstackblue`, `maxstackpurple`, `maxstackorange`, `maxstackyellow`, `buyerpricegrey`, `buyerpricewhite`, `buyerpricegreen`, `buyerpriceblue`, `buyerpricepurple`, `buyerpriceorange`, `buyerpriceyellow`, `buyerbiddinginterval`, `buyerbidsperinterval`) VALUES -(2,'Alliance',2500,2500,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1), -(6,'Horde',0,0,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1), -(7,'Neutral',0,0,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1); +(2,'Alliance',250,250,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1), +(6,'Horde',250,250,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1), +(7,'Neutral',250,250,0,27,12,10,1,0,0,0,10,30,8,2,0,0,100,150,150,250,800,1400,1250,1750,2250,4550,3250,5550,5250,6550,70,100,70,100,80,100,75,100,80,100,80,100,80,100,0,0,3,2,1,1,1,1,3,5,12,15,20,22,1,1); -- -- Items blacklist From d5b9f7d4c9b3a7aec96cc8c119f42f326fca1b06 Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Sun, 26 Jan 2025 10:45:00 -0500 Subject: [PATCH 06/11] Fix log error in AuctionHouseBot::Buy fix log error in AuctionHouseBot::Buy --- src/AuctionHouseBot.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index 8ac91e0..8ad0385 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -254,7 +254,9 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se std::vector::iterator itBegin = auctionsGuidsToConsider.begin(); //std::advance(it, randomIndex); - AuctionEntry* auction = auctionHouse->GetAuction(auctionsGuidsToConsider.at(randomIndex)); + uint32 auctionID = auctionsGuidsToConsider.at(randomIndex); + + AuctionEntry* auction = auctionHouse->GetAuction(auctionID); // // Prevent to bid again on the same auction @@ -266,7 +268,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se { if (config->DebugOutBuyer) { - LOG_ERROR("module", "AHBot [{}]: item {} Possible entry to buy/bid from AH pool is invalid, this should not happen, moving on next auciton"); + LOG_ERROR("module", "AHBot [{}]: Auction id: {} Possible entry to buy/bid from AH pool is invalid, this should not happen, moving on next auciton", _id, auctionID); } continue; } From 679210be8742923d613db1e6be5062c90958ff3b Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Mon, 27 Jan 2025 22:34:26 -0500 Subject: [PATCH 07/11] Fix some magic number/AHB_ define value mismatch Fixed a bunch of magic number and define values mismatch. AuctionHouseBotyConfig was getting out of sync with the actual Server database until a server restart ( where on initialization it would query the server AH for real) --- src/AuctionHouseBot.cpp | 310 +++++++++------------- src/AuctionHouseBotAuctionHouseScript.cpp | 35 +-- src/AuctionHouseBotCommon.h | 2 + src/AuctionHouseBotConfig.cpp | 33 +-- src/AuctionHouseBotConfig.h | 11 +- 5 files changed, 154 insertions(+), 237 deletions(-) diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index 8ad0385..ad8c19f 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -351,45 +351,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se continue; } - /*if (config->UseBuyPriceForBuyer) - { - 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 - { - if (config->DebugOutBuyer) - { - LOG_ERROR("module", "AHBot [{}]: Quality {} not Supported", _id, prototype->Quality); - } - - continue; - } - } - else - { - 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 - { - if (config->DebugOutBuyer) - { - LOG_ERROR("module", "AHBot [{}]: Quality {} not Supported", _id, prototype->Quality); - } - - continue; - } - }*/ - + // // Recalculate the bid depending on the type of the item // @@ -433,6 +395,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se double bidValue = currentPrice + ((maximumBid - currentPrice) * bidRate); uint32 bidPrice = static_cast(bidValue); + // // Check our bid is high enough to be valid. If not, correct it to minimum. // @@ -460,39 +423,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se LOG_INFO("module", "AHBot [{}]: Minimum Outbid: {}", _id, minimumOutbid); LOG_INFO("module", "-------------------------------------------------"); } - - // - // Print out debug info - // - - /*if (config->DebugOutBuyer) - { - LOG_INFO("module", "-------------------------------------------------"); - 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 @@ -514,7 +445,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se auto trans = CharacterDatabase.BeginTransaction(); sAuctionMgr->SendAuctionOutbiddedMail(auction, bidPrice, session->GetPlayer(), trans); - CharacterDatabase.CommitTransaction (trans); + CharacterDatabase.CommitTransaction(trans); } } @@ -524,8 +455,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // // update/save the auction into database // - - CharacterDatabase.Execute("UPDATE auctionhouse SET buyguid = '{}', lastbid = '{}' WHERE id = '{}'", auction->bidder.GetCounter(), auction->bid, auction->Id); + CharacterDatabase.DirectExecute("UPDATE auctionhouse SET buyguid = '{}', lastbid = '{}' WHERE id = '{}'", auction->bidder.GetCounter(), auction->bid, auction->Id); if (config->TraceBuyer) { @@ -597,10 +527,10 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) // Check the given limits // - uint32 minItems = config->GetMinItems(); - uint32 maxItems = config->GetMaxItems(); + uint32 minTotalItems = config->GetMinItems(); + uint32 maxTotalItems = config->GetMaxItems(); - if (maxItems == 0) + if (maxTotalItems == 0) { return; } @@ -623,18 +553,19 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) return; } - auctionHouse->Update(); + // don't mess with the AH update let server do it. + //auctionHouse->Update(); // // Check if we are clear to proceed // - bool aboveMin = false; - bool aboveMax = false; - uint32 auctions = getNofAuctions(config, auctionHouse, AHBplayer->GetGUID()); - uint32 items = 0; + bool aboveMin = false; + bool aboveMax = false; + uint32 nbOfAuctions = getNofAuctions(config, auctionHouse, AHBplayer->GetGUID()); + uint32 nbItemsToSellThisCycle = 0; - if (auctions >= minItems) + if (nbOfAuctions >= minTotalItems) { aboveMin = true; @@ -646,7 +577,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) return; } - if (auctions >= maxItems) + if (nbOfAuctions >= maxTotalItems) { aboveMax = true; @@ -658,66 +589,66 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) return; } - if ((maxItems - auctions) >= config->ItemsPerCycle) + if ((maxTotalItems - nbOfAuctions) >= config->ItemsPerCycle) { - items = config->ItemsPerCycle; + nbItemsToSellThisCycle = config->ItemsPerCycle; } else { - items = (maxItems - auctions); + nbItemsToSellThisCycle = (maxTotalItems - nbOfAuctions); } // // 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); + uint32 maxGreyTG = config->GetMaximum(AHB_GREY_TG); + uint32 maxWhiteTG = config->GetMaximum(AHB_WHITE_TG); + uint32 maxGreenTG = config->GetMaximum(AHB_GREEN_TG); + uint32 maxBlueTG = config->GetMaximum(AHB_BLUE_TG); + uint32 maxPurpleTG = config->GetMaximum(AHB_PURPLE_TG); + uint32 maxOrangeTG = config->GetMaximum(AHB_ORANGE_TG); + uint32 maxYellowTG = config->GetMaximum(AHB_YELLOW_TG); + + uint32 maxGreyI = config->GetMaximum(AHB_GREY_I); + uint32 maxWhiteI = config->GetMaximum(AHB_WHITE_I); + uint32 maxGreenI = config->GetMaximum(AHB_GREEN_I); + uint32 maxBlueI = config->GetMaximum(AHB_BLUE_I); + uint32 maxPurpleI = config->GetMaximum(AHB_PURPLE_I); + uint32 maxOrangeI = config->GetMaximum(AHB_ORANGE_I); + uint32 maxYellowI = config->GetMaximum(AHB_YELLOW_I); + + uint32 currentGreyTG = config->GetItemCounts(AHB_GREY_TG); + uint32 currentWhiteTG = config->GetItemCounts(AHB_WHITE_TG); + uint32 currentGreenTG = config->GetItemCounts(AHB_GREEN_TG); + uint32 currentBlueTG = config->GetItemCounts(AHB_BLUE_TG); + uint32 currentPurpleTG = config->GetItemCounts(AHB_PURPLE_TG); + uint32 currentOrangeTG = config->GetItemCounts(AHB_ORANGE_TG); + uint32 currentYellowTG = config->GetItemCounts(AHB_YELLOW_TG); + + uint32 currentGreyItems = config->GetItemCounts(AHB_GREY_I); + uint32 currentWhiteItems = config->GetItemCounts(AHB_WHITE_I); + uint32 currentGreenItems = config->GetItemCounts(AHB_GREEN_I); + uint32 currentBlueItems = config->GetItemCounts(AHB_BLUE_I); + uint32 currentPurpleItems = config->GetItemCounts(AHB_PURPLE_I); + uint32 currentOrangeItems = config->GetItemCounts(AHB_ORANGE_I); + uint32 currentYellowItems = config->GetItemCounts(AHB_YELLOW_I); // // Loop variables // - uint32 noSold = 0; // Tracing counter + uint32 nbSold = 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++) + for (uint32 cnt = 1; cnt <= nbItemsToSellThisCycle; cnt++) { - uint32 choice = 0; - uint32 itemID = 0; + uint32 itemTypeSelectedToSell = 0; + uint32 itemID = 0; uint32 loopbreaker = 0; // @@ -730,99 +661,99 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) // Poor - if ((config->GreyItemsBin.size() > 0) && (greyItems < greyIcount)) + if ((config->GreyItemsBin.size() > 0) && (currentGreyItems < maxGreyI)) { - choice = 0; + itemTypeSelectedToSell = AHB_GREY_I; itemID = getElement(config->GreyItemsBin, urand(0, config->GreyItemsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } - if (itemID == 0 && (config->GreyTradeGoodsBin.size() > 0) && (greyTGoods < greyTGcount)) + if (itemID == 0 && (config->GreyTradeGoodsBin.size() > 0) && (currentGreyTG < maxGreyTG)) { - choice = 7; + itemTypeSelectedToSell = AHB_GREY_TG; itemID = getElement(config->GreyTradeGoodsBin, urand(0, config->GreyTradeGoodsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } // Normal - if (itemID == 0 && (config->WhiteItemsBin.size() > 0) && (whiteItems < whiteIcount)) + if (itemID == 0 && (config->WhiteItemsBin.size() > 0) && (currentWhiteItems < maxWhiteI)) { - choice = 1; + itemTypeSelectedToSell = AHB_WHITE_I; itemID = getElement(config->WhiteItemsBin, urand(0, config->WhiteItemsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } - if (itemID == 0 && (config->WhiteTradeGoodsBin.size() > 0) && (whiteTGoods < whiteTGcount)) + if (itemID == 0 && (config->WhiteTradeGoodsBin.size() > 0) && (currentWhiteTG < maxWhiteTG)) { - choice = 8; + itemTypeSelectedToSell = AHB_WHITE_TG; itemID = getElement(config->WhiteTradeGoodsBin, urand(0, config->WhiteTradeGoodsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } // Uncommon - if (itemID == 0 && (config->GreenItemsBin.size() > 0) && (greenItems < greenIcount)) + if (itemID == 0 && (config->GreenItemsBin.size() > 0) && (currentGreenItems < maxGreenI)) { - choice = 2; + itemTypeSelectedToSell = AHB_GREEN_I; itemID = getElement(config->GreenItemsBin, urand(0, config->GreenItemsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } - if (itemID == 0 && (config->GreenTradeGoodsBin.size() > 0) && (greenTGoods < greenTGcount)) + if (itemID == 0 && (config->GreenTradeGoodsBin.size() > 0) && (currentGreenTG < maxGreenTG)) { - choice = 9; + itemTypeSelectedToSell = AHB_GREEN_TG; itemID = getElement(config->GreenTradeGoodsBin, urand(0, config->GreenTradeGoodsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } // Rare - if (itemID == 0 && (config->BlueItemsBin.size() > 0) && (blueItems < blueIcount)) + if (itemID == 0 && (config->BlueItemsBin.size() > 0) && (currentBlueItems < maxBlueI)) { - choice = 3; + itemTypeSelectedToSell = AHB_BLUE_I; itemID = getElement(config->BlueItemsBin, urand(0, config->BlueItemsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } - if (itemID == 0 && (config->BlueTradeGoodsBin.size() > 0) && (blueTGoods < blueTGcount)) + if (itemID == 0 && (config->BlueTradeGoodsBin.size() > 0) && (currentBlueTG < maxBlueTG)) { - choice = 10; + itemTypeSelectedToSell = AHB_BLUE_TG; itemID = getElement(config->BlueTradeGoodsBin, urand(0, config->BlueTradeGoodsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } // Epic - if (itemID == 0 && (config->PurpleItemsBin.size() > 0) && (purpleItems < purpleIcount)) + if (itemID == 0 && (config->PurpleItemsBin.size() > 0) && (currentPurpleItems < maxPurpleI)) { - choice = 4; + itemTypeSelectedToSell = AHB_PURPLE_I; itemID = getElement(config->PurpleItemsBin, urand(0, config->PurpleItemsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } - if (itemID == 0 && (config->PurpleTradeGoodsBin.size() > 0) && (purpleTGoods < purpleTGcount)) + if (itemID == 0 && (config->PurpleTradeGoodsBin.size() > 0) && (currentPurpleTG < maxPurpleTG)) { - choice = 11; + itemTypeSelectedToSell = AHB_PURPLE_TG; itemID = getElement(config->PurpleTradeGoodsBin, urand(0, config->PurpleTradeGoodsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } // Legendary - if (itemID == 0 && (config->OrangeItemsBin.size() > 0) && (orangeItems < orangeIcount)) + if (itemID == 0 && (config->OrangeItemsBin.size() > 0) && (currentOrangeItems < maxOrangeI)) { - choice = 5; + itemTypeSelectedToSell = AHB_ORANGE_I; itemID = getElement(config->OrangeItemsBin, urand(0, config->OrangeItemsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } - if (itemID == 0 && (config->OrangeTradeGoodsBin.size() > 0) && (orangeTGoods < orangeTGcount)) + if (itemID == 0 && (config->OrangeTradeGoodsBin.size() > 0) && (currentOrangeTG < maxOrangeTG)) { - choice = 12; + itemTypeSelectedToSell = AHB_ORANGE_TG; itemID = getElement(config->OrangeTradeGoodsBin, urand(0, config->OrangeTradeGoodsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } // Artifact - if (itemID == 0 && (config->YellowItemsBin.size() > 0) && (yellowItems < yellowIcount)) + if (itemID == 0 && (config->YellowItemsBin.size() > 0) && (currentYellowItems < maxYellowI)) { - choice = 6; + itemTypeSelectedToSell = AHB_YELLOW_I; itemID = getElement(config->YellowItemsBin, urand(0, config->YellowItemsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } - if (itemID == 0 && (config->YellowTradeGoodsBin.size() > 0) && (yellowTGoods < yellowTGcount)) + if (itemID == 0 && (config->YellowTradeGoodsBin.size() > 0) && (currentYellowTG < maxYellowTG)) { - choice = 13; + itemTypeSelectedToSell = AHB_YELLOW_TG; itemID = getElement(config->YellowTradeGoodsBin, urand(0, config->YellowTradeGoodsBin.size() - 1), _id, config->DuplicatesCount, auctionHouse); } @@ -908,8 +839,8 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) // uint64 buyoutPrice = 0; - uint64 bidPrice = 0; - uint32 stackCount = 1; + uint64 bidPrice = 0; + uint32 stackCount = 1; if (config->SellAtMarketPrice) { @@ -957,13 +888,13 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) // Determine the auction time // - uint32 etime = getElapsedTime(config->ElapsingTimeClass); + uint32 elapsingTime = getElapsedTime(config->ElapsingTimeClass); // // Determine the deposit // - uint32 dep = sAuctionMgr->GetAuctionDeposit(ahEntry, etime, item, stackCount); + uint32 deposit = sAuctionMgr->GetAuctionDeposit(ahEntry, elapsingTime, item, stackCount); // // Perform the auction @@ -981,8 +912,8 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) auctionEntry->startbid = bidPrice * stackCount; auctionEntry->buyout = buyoutPrice * stackCount; auctionEntry->bid = 0; - auctionEntry->deposit = dep; - auctionEntry->expire_time = (time_t)etime + time(NULL); + auctionEntry->deposit = deposit; + auctionEntry->expire_time = (time_t)elapsingTime + time(NULL); auctionEntry->auctionHouseEntry = ahEntry; item->SaveToDB(trans); @@ -997,69 +928,72 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) // Increments the number of items presents in the auction // - switch (choice) + // todo: reread config for actual values, maybe an array to not rely on local count that could potentially be mismatched from config. + // config is updated from callback received after auctionHouse->AddAuction(auctionEntry); + // or maybe reparse the server actual value each update cycle, would need profiling. + switch (itemTypeSelectedToSell) { - case 0: - ++greyItems; + case AHB_GREY_I: + ++currentGreyItems; break; - case 1: - ++whiteItems; + case AHB_WHITE_I: + ++currentWhiteItems; break; - case 2: - ++greenItems; + case AHB_GREEN_I: + ++currentGreenItems; break; - case 3: - ++blueItems; + case AHB_BLUE_I: + ++currentBlueItems; break; - case 4: - ++purpleItems; + case AHB_PURPLE_I: + ++currentPurpleItems; break; - case 5: - ++orangeItems; + case AHB_ORANGE_I: + ++currentOrangeItems; break; - case 6: - ++yellowItems; + case AHB_YELLOW_I: + ++currentYellowItems; break; - case 7: - ++greyTGoods; + case AHB_GREY_TG: + ++currentGreyTG; break; - case 8: - ++whiteTGoods; + case AHB_WHITE_TG: + ++currentWhiteTG; break; - case 9: - ++greenTGoods; + case AHB_GREEN_TG: + ++currentGreenTG; break; - case 10: - ++blueTGoods; + case AHB_BLUE_TG: + ++currentBlueTG; break; - case 11: - ++purpleTGoods; + case AHB_PURPLE_TG: + ++currentPurpleTG; break; - case 12: - ++orangeTGoods; + case AHB_ORANGE_TG: + ++currentOrangeTG; break; - case 13: - ++yellowTGoods; + case AHB_YELLOW_TG: + ++currentYellowTG; break; default: break; } - noSold++; + nbSold++; if (config->TraceSeller) { @@ -1069,7 +1003,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) 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); + LOG_INFO("module", "AHBot [{}]: auctionhouse {}, req={}, sold={}, aboveMin={}, aboveMax={}, loopBrk={}, noNeed={}, tooMany={}, binEmpty={}, err={}", _id, config->GetAHID(), nbItemsToSellThisCycle, nbSold, aboveMin, aboveMax, loopBrk, noNeed, tooMany, binEmpty, err); } } diff --git a/src/AuctionHouseBotAuctionHouseScript.cpp b/src/AuctionHouseBotAuctionHouseScript.cpp index 37f1a45..c3df5db 100644 --- a/src/AuctionHouseBotAuctionHouseScript.cpp +++ b/src/AuctionHouseBotAuctionHouseScript.cpp @@ -141,6 +141,7 @@ void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionE config->IncItemCounts(prototype->Class, prototype->Quality); } +// this is called after the auction has been removed from the DB void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, AuctionEntry* auction) { // @@ -174,36 +175,26 @@ void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, Aucti } } - // - // Verify if we can operate on the item - // - - Item* pItem = sAuctionMgr->GetAItem(auction->item_guid); - + // only get the prototype as actual ite mhas already been removed from server AH in this callback ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template); - if (!pItem) + if (prototype) { + config->DecItemCounts(prototype->Class, prototype->Quality); if (config->DebugOut) { - LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString()); - } - - // Decrement item counts even if the item does not exist - if (prototype) - { - config->DecItemCounts(prototype->Class, prototype->Quality); + LOG_INFO("module", "AHBot: Item was removed ah={}, item={}, count={}", auction->GetHouseId(), auction->item_template, config->GetItemCounts(prototype->Quality)); } - - return; } - - if (config->DebugOut) + else { - LOG_INFO("module", "AHBot: ah={}, item={}, count={}", auction->GetHouseId(), auction->item_template, config->GetItemCounts(prototype->Quality)); + // should never happen + if (config->DebugOut) + { + LOG_ERROR("module", "AHBot: Item was removed but no prototype was found"); + } } - - config->DecItemCounts(prototype->Class, prototype->Quality); + } void AHBot_AuctionHouseScript::OnAuctionSuccessful(AuctionHouseObject* /*ah*/, AuctionEntry* auction) @@ -270,8 +261,6 @@ void AHBot_AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* /*ah*/, Aucti { 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() diff --git a/src/AuctionHouseBotCommon.h b/src/AuctionHouseBotCommon.h index 3031485..26b477c 100644 --- a/src/AuctionHouseBotCommon.h +++ b/src/AuctionHouseBotCommon.h @@ -71,6 +71,8 @@ class AuctionHouseBot; #define AHB_ORANGE_I 12 #define AHB_YELLOW_I 13 +#define AHB_ITEM_TYPE_OFFSET 7 + // // Chat GM commands // diff --git a/src/AuctionHouseBotConfig.cpp b/src/AuctionHouseBotConfig.cpp index 5346f59..b47b07a 100644 --- a/src/AuctionHouseBotConfig.cpp +++ b/src/AuctionHouseBotConfig.cpp @@ -1615,68 +1615,57 @@ void AHBConfig::CalculatePercents() } } -uint32 AHBConfig::GetMaximum(uint32 color) +uint32 AHBConfig::GetMaximum(uint32 ahbotItemType) { - switch (color) + switch (ahbotItemType) { 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: + { + LOG_ERROR("module", "AHBot AHBConfig::GetMaximum() invalid param"); return 0; - break; + } } } @@ -1689,14 +1678,14 @@ void AHBConfig::DecItemCounts(uint32 Class, uint32 Quality) break; default: - DecItemCounts(Quality + 7); + DecItemCounts(Quality + AHB_ITEM_TYPE_OFFSET); break; } } -void AHBConfig::DecItemCounts(uint32 color) +void AHBConfig::DecItemCounts(uint32 ahbotItemType) { - switch (color) + switch (ahbotItemType) { case AHB_GREY_TG: if (greyTGoods > 0) @@ -1815,9 +1804,9 @@ void AHBConfig::IncItemCounts(uint32 Class, uint32 Quality) } } -void AHBConfig::IncItemCounts(uint32 color) +void AHBConfig::IncItemCounts(uint32 ahbotItemType) { - switch (color) + switch (ahbotItemType) { case AHB_GREY_TG: ++greyTGoods; diff --git a/src/AuctionHouseBotConfig.h b/src/AuctionHouseBotConfig.h index f8cc863..17cbab4 100644 --- a/src/AuctionHouseBotConfig.h +++ b/src/AuctionHouseBotConfig.h @@ -156,6 +156,9 @@ class AHBConfig std::set getCommaSeparatedIntegers(std::string text); + void DecItemCounts(uint32 ahbotItemType); + void IncItemCounts(uint32 ahbotItemType); + public: // // Debugging @@ -343,13 +346,13 @@ class AHBConfig uint32 GetBidsPerInterval(); void CalculatePercents (); - uint32 GetMaximum (uint32 color); - + // max number of items of type in AH based on maxItems + uint32 GetMaximum (uint32 ahbotItemType); + void DecItemCounts (uint32 Class, uint32 Quality); - void DecItemCounts (uint32 color); void IncItemCounts (uint32 Class, uint32 Quality); - void IncItemCounts (uint32 color); + void ResetItemCounts (); uint32 TotalItemCounts (); From 1d19f076bb9769c1168298745ab2fda00bfc0a19 Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Sat, 1 Feb 2025 19:52:58 -0500 Subject: [PATCH 08/11] More bug fixes and improved logging Changed SQL query of buyer to only get auctions from relevant house. better logging on auction events in script manager --- src/AuctionHouseBot.cpp | 38 +++++++++++++---------- src/AuctionHouseBotAuctionHouseScript.cpp | 36 ++++++++++++++------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index ad8c19f..a511b19 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -24,9 +24,11 @@ #include "WorldSession.h" #include "GameTime.h" #include "DatabaseEnv.h" +#include "ScriptMgr.h" #include "AuctionHouseBot.h" #include "AuctionHouseBotCommon.h" +#include "AuctionHouseSearcher.h" using namespace std; @@ -189,8 +191,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Retrieve items not owned by the bot and not bought/bidded on by the bot // - - QueryResult ahContentQueryResult = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE itemowner<>{} AND buyguid<>{}", _id, _id); + QueryResult ahContentQueryResult = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE houseid={} AND itemowner<>{} AND buyguid<>{}", config->GetAHID(), _id, _id); if (!ahContentQueryResult) { @@ -211,7 +212,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Fetches content of selected AH to look for possible bids // - AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); + AuctionHouseObject* auctionHouseObject = sAuctionMgr->GetAuctionsMap(config->GetAHFID()); std::vector auctionsGuidsToConsider; do @@ -256,7 +257,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se uint32 auctionID = auctionsGuidsToConsider.at(randomIndex); - AuctionEntry* auction = auctionHouse->GetAuction(auctionID); + AuctionEntry* auction = auctionHouseObject->GetAuction(auctionID); // // Prevent to bid again on the same auction @@ -451,15 +452,17 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se auction->bidder = AHBplayer->GetGUID(); auction->bid = bidPrice; + + sAuctionMgr->GetAuctionHouseSearcher()->UpdateBid(auction); // // update/save the auction into database // - CharacterDatabase.DirectExecute("UPDATE auctionhouse SET buyguid = '{}', lastbid = '{}' WHERE id = '{}'", auction->bidder.GetCounter(), auction->bid, auction->Id); + //CharacterDatabase.DirectExecute("UPDATE auctionhouse SET buyguid = '{}', lastbid = '{}' WHERE id = '{}'", auction->bidder.GetCounter(), auction->bid, auction->Id); if (config->TraceBuyer) { - LOG_INFO("module", "AHBot [{}]: New bid, id={}, ah={}, item={}, start={}, current={}, buyout={}", _id, prototype->ItemId, auction->GetHouseId(), auction->item_template, auction->startbid, currentPrice, auction->buyout); + LOG_INFO("module", "AHBot [{}]: New bid, itemid={}, ah={}, auctionId={} item={}, start={}, current={}, buyout={}", _id, prototype->ItemId, auction->GetHouseId(), auction->Id, auction->item_template, auction->startbid, currentPrice, auction->buyout); } } else @@ -493,16 +496,17 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // Removes any trace of the item // + ScriptMgr::instance()->OnAuctionSuccessful(auctionHouseObject, auction); auction->DeleteFromDB(trans); - sAuctionMgr->RemoveAItem(auction->item_guid); - auctionHouse->RemoveAuction(auction); + auctionHouseObject->RemoveAuction(auction); + CharacterDatabase.CommitTransaction(trans); if (config->TraceBuyer) { - LOG_INFO("module", "AHBot [{}]: Bought , id={}, ah={}, item={}, start={}, current={}, buyout={}", _id, prototype->ItemId, auction->GetHouseId(), auction->item_template, auction->startbid, currentPrice, auction->buyout); + LOG_INFO("module", "AHBot [{}]: Bought , itemid={}, ah={}, item={}, start={}, current={}, buyout={}", _id, prototype->ItemId, AuctionHouseId(auction->GetHouseId()), auction->item_template, auction->startbid, currentPrice, auction->buyout); } } } @@ -554,7 +558,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) } // don't mess with the AH update let server do it. - //auctionHouse->Update(); + //auctionHouseObject->Update(); // // Check if we are clear to proceed @@ -929,7 +933,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) // // todo: reread config for actual values, maybe an array to not rely on local count that could potentially be mismatched from config. - // config is updated from callback received after auctionHouse->AddAuction(auctionEntry); + // config is updated from callback received after auctionHouseObject->AddAuction(auctionEntry); // or maybe reparse the server actual value each update cycle, would need profiling. switch (itemTypeSelectedToSell) { @@ -1053,7 +1057,7 @@ void AuctionHouseBot::Update() { if (_allianceConfig->TraceSeller) { - LOG_INFO("module", "AHBot [{}]: Begin Sell for Alliance", _id); + LOG_INFO("module", "AHBot [{}]: Begin Sell for Alliance...", _id); } Sell(&_AHBplayer, _allianceConfig); @@ -1062,7 +1066,7 @@ void AuctionHouseBot::Update() { if (_allianceConfig->TraceBuyer) { - LOG_INFO("module", "AHBot [{}]: Begin Buy for Alliance", _id); + LOG_INFO("module", "AHBot [{}]: Begin Buy for Alliance...", _id); } Buy(&_AHBplayer, _allianceConfig, &_session); @@ -1078,7 +1082,7 @@ void AuctionHouseBot::Update() { if (_hordeConfig->TraceSeller) { - LOG_INFO("module", "AHBot [{}]: Begin Sell for Horde", _id); + LOG_INFO("module", "AHBot [{}]: Begin Sell for Horde...", _id); } Sell(&_AHBplayer, _hordeConfig); @@ -1086,7 +1090,7 @@ void AuctionHouseBot::Update() { if (_hordeConfig->TraceBuyer) { - LOG_INFO("module", "AHBot [{}]: Begin Buy for Horde", _id); + LOG_INFO("module", "AHBot [{}]: Begin Buy for Horde...", _id); } Buy(&_AHBplayer, _hordeConfig, &_session); _lastrun_h_sec = _newrun; @@ -1103,7 +1107,7 @@ void AuctionHouseBot::Update() { if (_neutralConfig->TraceSeller) { - LOG_INFO("module", "AHBot [{}]: Begin Sell for Neutral", _id); + LOG_INFO("module", "AHBot [{}]: Begin Sell for Neutral...", _id); } Sell(&_AHBplayer, _neutralConfig); @@ -1111,7 +1115,7 @@ void AuctionHouseBot::Update() { if (_neutralConfig->TraceBuyer) { - LOG_INFO("module", "AHBot [{}]: Begin Buy for Neutral", _id); + LOG_INFO("module", "AHBot [{}]: Begin Buy for Neutral...", _id); } Buy(&_AHBplayer, _neutralConfig, &_session); _lastrun_n_sec = _newrun; diff --git a/src/AuctionHouseBotAuctionHouseScript.cpp b/src/AuctionHouseBotAuctionHouseScript.cpp index c3df5db..d979121 100644 --- a/src/AuctionHouseBotAuctionHouseScript.cpp +++ b/src/AuctionHouseBotAuctionHouseScript.cpp @@ -85,7 +85,7 @@ void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionE // AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntryFromHouse(auction->GetHouseId()); - AHBConfig* config = gNeutralConfig; + AHBConfig* config = gNeutralConfig; if (ahEntry) { @@ -121,7 +121,7 @@ void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionE { if (config->DebugOut) { - LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString()); + LOG_ERROR("module", "AHBot: Item {} for entryiD={} doesn't exist, perhaps bought already?", auction->item_guid.ToString(), auction->Id); } return; @@ -133,12 +133,12 @@ void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionE ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template); + config->IncItemCounts(prototype->Class, prototype->Quality); + 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); + LOG_INFO("module", "AHBot: Auction Added ah={}, auctionId={}, totalAHItems = {}", AuctionHouseId(ahEntry->houseId), auction->Id, config->TotalItemCounts()); + } } // this is called after the auction has been removed from the DB @@ -149,7 +149,7 @@ void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, Aucti // AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntryFromHouse(auction->GetHouseId()); - AHBConfig* config = gNeutralConfig; + AHBConfig* config = gNeutralConfig; if (ahEntry) { @@ -183,7 +183,7 @@ void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, Aucti config->DecItemCounts(prototype->Class, prototype->Quality); if (config->DebugOut) { - LOG_INFO("module", "AHBot: Item was removed ah={}, item={}, count={}", auction->GetHouseId(), auction->item_template, config->GetItemCounts(prototype->Quality)); + LOG_INFO("module", "AHBot: Auction removed ah={}, auctionId={}, Bot totalAHItems={}", AuctionHouseId(ahEntry->houseId), auction->Id, config->TotalItemCounts()); } } else @@ -204,7 +204,7 @@ void AHBot_AuctionHouseScript::OnAuctionSuccessful(AuctionHouseObject* /*ah*/, A // AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntryFromHouse(auction->GetHouseId()); - AHBConfig* config = gNeutralConfig; + AHBConfig* config = gNeutralConfig; if (ahEntry) { @@ -218,22 +218,34 @@ void AHBot_AuctionHouseScript::OnAuctionSuccessful(AuctionHouseObject* /*ah*/, A } } + // // If the auction has been won, it means that it has been accepted by the market. // Use the buyout as a reference since the price for the bid is downgraded during selling. // + if (config->DebugOut) + { + LOG_INFO("module", "AHBot: Auction successful ah={}, auctionId={}, Bot totalAHItems={}", AuctionHouseId(ahEntry->houseId), auction->Id, config->TotalItemCounts()); + } + config->UpdateItemStats(auction->item_template, auction->itemCount, auction->buyout); + } -void AHBot_AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* /*ah*/, AuctionEntry* auction) +void AHBot_AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* ah, AuctionEntry* auction) { // // Get the configuration for the auction house // + if (!auction) + { + LOG_ERROR("module", "AHBot: AHBot_AuctionHouseScript::OnAuctionExpire invalid AuctionEntry"); + } + AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntryFromHouse(auction->GetHouseId()); - AHBConfig* config = gNeutralConfig; + AHBConfig* config = gNeutralConfig; if (ahEntry) { @@ -259,7 +271,7 @@ void AHBot_AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* /*ah*/, Aucti if (config->DebugOut) { - LOG_INFO("module", "AHBot: ah={}, item={}, count={}", auction->GetHouseId(), auction->item_template, config->GetItemCounts(prototype->Quality)); + LOG_INFO("module", "AHBot: Auction Expired ah={}, auctionId={} Bot totalAHItems={}", AuctionHouseId(ahEntry->houseId), auction->Id, config->TotalItemCounts()); } } From 82104fbfbc31dbfea6e8a004637bf74bc003e1e2 Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Sat, 15 Feb 2025 21:04:45 -0500 Subject: [PATCH 09/11] Remove early exit of sell if auctions are above min No need to stop selling item if above minimum and under maximum. --- src/AuctionHouseBot.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index a511b19..1d3f38b 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -575,10 +575,8 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) if (config->DebugOutSeller) { - LOG_ERROR("module", "AHBot [{}]: Auctions above minimum", _id); + LOG_TRACE("module", "AHBot [{}]: Auctions above minimum", _id); } - - return; } if (nbOfAuctions >= maxTotalItems) @@ -587,7 +585,7 @@ void AuctionHouseBot::Sell(Player* AHBplayer, AHBConfig* config) if (config->DebugOutSeller) { - LOG_ERROR("module", "AHBot [{}]: Auctions at or above maximum", _id); + LOG_TRACE("module", "AHBot [{}]: Auctions at or above maximum", _id); } return; From 2c132af1fca95ba7a845a6c79a0e04eb40a7ed4d Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Sun, 16 Feb 2025 15:11:07 -0500 Subject: [PATCH 10/11] Update AuctionHouseBotAuctionHouseScript.cpp commented out unused param because of warning as errors --- src/AuctionHouseBotAuctionHouseScript.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AuctionHouseBotAuctionHouseScript.cpp b/src/AuctionHouseBotAuctionHouseScript.cpp index 4e10dd6..2f0c6f3 100644 --- a/src/AuctionHouseBotAuctionHouseScript.cpp +++ b/src/AuctionHouseBotAuctionHouseScript.cpp @@ -227,7 +227,7 @@ void AHBot_AuctionHouseScript::OnAuctionSuccessful(AuctionHouseObject* /*ah*/, A } -void AHBot_AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* ah, AuctionEntry* auction) +void AHBot_AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* /*ah*/, AuctionEntry* auction) { // // Get the configuration for the auction house From 4a509ff658b1c572a17440baabf6a200cf2ce3fd Mon Sep 17 00:00:00 2001 From: Jaytapp <47534419+Jaytapp@users.noreply.github.com> Date: Tue, 25 Feb 2025 19:15:15 -0500 Subject: [PATCH 11/11] Fix issue ahbot bids no longer saved to the database Fix issue https://github.com/azerothcore/mod-ah-bot/issues/141 ahbot bids no longer saved to the database properly write in the database after updating the bid --- src/AuctionHouseBot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index 1d3f38b..fe6010c 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -458,7 +458,7 @@ void AuctionHouseBot::Buy(Player* AHBplayer, AHBConfig* config, WorldSession* se // // update/save the auction into database // - //CharacterDatabase.DirectExecute("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); if (config->TraceBuyer) {