From 7c57a6f11e67c673819a7f820905813a1149bb71 Mon Sep 17 00:00:00 2001 From: NathanHandley Date: Tue, 9 Sep 2025 17:37:10 -0500 Subject: [PATCH] Fix and re-enable bid support on buyer bot --- README.md | 2 +- conf/mod_ahbot.conf.dist | 10 +++-- src/AuctionHouseBot.cpp | 90 +++++++++++++++++++++++++++------------- src/AuctionHouseBot.h | 2 +- 4 files changed, 70 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 28eaced..53ccad4 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Notes: 1. **Determining Items to Buy:** Every minute the buyer bot will select (BuyCanditatesPerBuyoutCycle) items currently up for auction which are listed by players as potential purchase items. 2. **Price Willing to Pay:** The buyer bot will use the same item price calculation the seller bot uses, including the random +/- 25%, and that calculated price is then multiplied by (AcceptablePriceModifier) which then becomes the price the buyer will be willing to spend. -3. **Buying it:** If the price calculated is higher than the buy out price, then the bot will buy it out. +3. **Buying it:** If the price calculated is higher than the buy out price, then the bot will buy it out. If not, it will test to see if it has been bidded on by a bot and if not, if the bid price is below the price it is willing to pay. If so, it will bid (outbid, so just over current bid). The above behavior is replicated on each enabled auction house. If left to default settings, 1 item in each auction house will attempt to be bought from, if the price calculation seems favorable. Note that any item buy attempt, even items above buying price, consumes a buy candidate. That means that too many overpriced items can drown out potential sales. diff --git a/conf/mod_ahbot.conf.dist b/conf/mod_ahbot.conf.dist index b76eea4..71deb9a 100644 --- a/conf/mod_ahbot.conf.dist +++ b/conf/mod_ahbot.conf.dist @@ -48,14 +48,16 @@ AuctionHouseBot.AuctionHouseManagerCyclesBetweenBuyOrSell = 1 # BUYER PROPERTIES # Behavior: # 1) Determining Items to Buy: Every minute the buyer bot will select -# (BuyCanditatesPerBuyoutCycle) items currently up for auction which are +# (BuyCanditatesPerBuyCycle) items currently up for auction which are # listed by players as potential purchase items. # 2) Price Willing to Pay: The buyer bot will use the same item price # calculation the seller bot uses, including the random +/- 25%, and # that calculated price is then multiplied by (AcceptablePriceModifier) # which then becomes the price the buyer will be willing to spend. # 3) Buying it: If the price calculated is higher than the buy out price, -# then the bot will buy it out. +# then the bot will buy it out. If not, it will see if it's an item +# not yet bidded on by a bot and the price is affordable, then it will +# place a bid (outbid, so just over current bid) # - The above behavior is replicated on each enabled auction house. # - If left to default settings, 1 item in each auction house will attempt # to be bought from, if the price calculation seems favorable. @@ -67,7 +69,7 @@ AuctionHouseBot.AuctionHouseManagerCyclesBetweenBuyOrSell = 1 # Enable/Disable the buying bot. # Default 0 (disabled) # -# AuctionHouseBot.Buyer.BuyCanditatesPerBuyoutCycle +# AuctionHouseBot.Buyer.BuyCanditatesPerBuyCycle # How many to items to price and attempt to buy. Note, this number of # items will be selected from each of the auction house types (Alliance, # Horde, Neutral). Meaning if you set this as 10, then up to 10 items @@ -88,7 +90,7 @@ AuctionHouseBot.AuctionHouseManagerCyclesBetweenBuyOrSell = 1 ############################################################################### AuctionHouseBot.Buyer.Enabled = 0 -AuctionHouseBot.Buyer.BuyCanditatesPerBuyoutCycle = 1 +AuctionHouseBot.Buyer.BuyCanditatesPerBuyCycle = 1 AuctionHouseBot.Buyer.AcceptablePriceModifier = 1 ############################################################################### diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index 7b5ef22..5035627 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -21,6 +21,7 @@ #include "ObjectMgr.h" #include "AuctionHouseMgr.h" #include "AuctionHouseBot.h" +#include "AuctionHouseSearcher.h" #include "Config.h" #include "Player.h" #include "WorldSession.h" @@ -37,7 +38,7 @@ AuctionHouseBot::AuctionHouseBot() : SellingBotEnabled(false), BuyingBotEnabled(false), CyclesBetweenBuyOrSell(1), - BuyingBotBuyCanditatesPerBuyoutCycle(1), + BuyingBotBuyCanditatesPerBuyCycle(1), BuyingBotAcceptablePriceModifier(1), AHCharactersGUIDsForQuery(""), ItemsPerCycle(75), @@ -675,13 +676,13 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player* AHBplayer, AHBConfig *con possibleBids.push_back(tmpdata); }while (result->NextRow()); - for (uint32 count = 1; count <= BuyingBotBuyCanditatesPerBuyoutCycle; ++count) + for (uint32 count = 1; count <= BuyingBotBuyCanditatesPerBuyCycle; ++count) { // Do we have anything to bid? If not, stop here. if (possibleBids.empty()) { //if (debug_Out) sLog->outError( "AHBuyer: I have no items to bid on."); - count = BuyingBotBuyCanditatesPerBuyoutCycle; + count = BuyingBotBuyCanditatesPerBuyCycle; continue; } @@ -716,15 +717,20 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player* AHBplayer, AHBConfig *con uint64 discardBidPrice = 0; calculateItemValue(prototype, discardBidPrice, willingToSpendPerItemPrice); willingToSpendPerItemPrice = (uint64)((float)willingToSpendPerItemPrice * BuyingBotAcceptablePriceModifier); - uint64 willingToSpendForStackPrice = willingToSpendPerItemPrice * pItem->GetCount(); - // Buy it if the price is greater than buy out, otherwise skip + uint64 willingToPayForStackPrice = willingToSpendPerItemPrice * pItem->GetCount(); + uint64 bidAmount = 0; + + // Determine if it's a bid, buyout, or skip bool doBuyout = false; - uint32 minBuyoutPrice = 0; - if (auction->buyout != 0 && willingToSpendForStackPrice >= auction->buyout) - doBuyout = true; + bool doBid = false; - if (doBuyout == true) + if (auction->buyout != 0 && auction->buyout < willingToPayForStackPrice) + doBuyout = true; + else if (auction->startbid < willingToPayForStackPrice && auction->GetAuctionOutBid() < willingToPayForStackPrice) + doBid = true; + + if (doBuyout == true || doBid == true) { if (debug_Out) { @@ -738,8 +744,7 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player* AHBplayer, AHBConfig *con 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: Willing To Spend For Stack Price: {}", willingToSpendForStackPrice); - LOG_INFO("module", "AHBuyer: Minimum Buyout Price: {}", minBuyoutPrice); + LOG_INFO("module", "AHBuyer: Willing To Pay For Stack Price: {}", willingToPayForStackPrice); 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:"); @@ -753,23 +758,52 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player* AHBplayer, AHBConfig *con LOG_INFO("module", "-------------------------------------------------"); } - auto trans = CharacterDatabase.BeginTransaction(); - - if ((auction->bidder) && (AHBplayer->GetGUID() != auction->bidder)) + if (doBid) { - sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, AHBplayer, trans); + auto trans = CharacterDatabase.BeginTransaction(); + + // Perform outbid + uint32 bidAmount = 0; + if (auction->bid == 0) + bidAmount = auction->startbid; + else + bidAmount = auction->GetAuctionOutBid(); + + if (auction->bidder) + { + sAuctionMgr->SendAuctionOutbiddedMail(auction, bidAmount, AHBplayer, trans); + CharacterDatabase.CommitTransaction(trans); + } + + auction->bidder = AHBplayer->GetGUID(); + auction->bid = bidAmount; + + sAuctionMgr->GetAuctionHouseSearcher()->UpdateBid(auction); + + CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_AUCTION_BID); + stmt->SetData(0, auction->bidder.GetCounter()); + stmt->SetData(1, auction->bid); + stmt->SetData(2, auction->Id); + trans->Append(stmt); } - auction->bidder = AHBplayer->GetGUID(); - auction->bid = auction->buyout; + else if (doBuyout) + { + auto trans = CharacterDatabase.BeginTransaction(); - // Send mails to buyer & seller - sAuctionMgr->SendAuctionSuccessfulMail(auction, trans); - sAuctionMgr->SendAuctionWonMail(auction, trans); - auction->DeleteFromDB(trans); + if ((auction->bidder) && (AHBplayer->GetGUID() != auction->bidder)) + sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, AHBplayer, trans); + auction->bidder = AHBplayer->GetGUID(); + auction->bid = auction->buyout; - sAuctionMgr->RemoveAItem(auction->item_guid); - auctionHouse->RemoveAuction(auction); - CharacterDatabase.CommitTransaction(trans); + // Send mails to buyer & seller + sAuctionMgr->SendAuctionSuccessfulMail(auction, trans); + sAuctionMgr->SendAuctionWonMail(auction, trans); + auction->DeleteFromDB(trans); + + sAuctionMgr->RemoveAItem(auction->item_guid); + auctionHouse->RemoveAuction(auction); + CharacterDatabase.CommitTransaction(trans); + } } } } @@ -800,16 +834,16 @@ void AuctionHouseBot::Update() if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) { addNewAuctions(&_AHBplayer, &AllianceConfig); - if (BuyingBotBuyCanditatesPerBuyoutCycle > 0) + if (BuyingBotBuyCanditatesPerBuyCycle > 0) addNewAuctionBuyerBotBid(&_AHBplayer, &AllianceConfig); addNewAuctions(&_AHBplayer, &HordeConfig); - if (BuyingBotBuyCanditatesPerBuyoutCycle > 0) + if (BuyingBotBuyCanditatesPerBuyCycle > 0) addNewAuctionBuyerBotBid(&_AHBplayer, &HordeConfig); } addNewAuctions(&_AHBplayer, &NeutralConfig); - if (BuyingBotBuyCanditatesPerBuyoutCycle > 0) + if (BuyingBotBuyCanditatesPerBuyCycle > 0) addNewAuctionBuyerBotBid(&_AHBplayer, &NeutralConfig); ObjectAccessor::RemoveObject(&_AHBplayer); @@ -831,7 +865,7 @@ void AuctionHouseBot::InitializeConfiguration() // Buyer Bot BuyingBotEnabled = sConfigMgr->GetOption("AuctionHouseBot.Buyer.Enabled", false); CyclesBetweenBuyOrSell = sConfigMgr->GetOption("AuctionHouseBot.AuctionHouseManagerCyclesBetweenBuyOrSell", 1); - BuyingBotBuyCanditatesPerBuyoutCycle = sConfigMgr->GetOption("AuctionHouseBot.Buyer.BuyCanditatesPerBuyoutCycle", 1); + BuyingBotBuyCanditatesPerBuyCycle = sConfigMgr->GetOption("AuctionHouseBot.Buyer.BuyCanditatesPerBuyCycle", 1); BuyingBotAcceptablePriceModifier = sConfigMgr->GetOption("AuctionHouseBot.Buyer.AcceptablePriceModifier", 1); if (SellingBotEnabled == false && BuyingBotEnabled == false) diff --git a/src/AuctionHouseBot.h b/src/AuctionHouseBot.h index 0dcb387..44234e3 100644 --- a/src/AuctionHouseBot.h +++ b/src/AuctionHouseBot.h @@ -124,7 +124,7 @@ private: bool BuyingBotEnabled; int CyclesBetweenBuyOrSell; - int BuyingBotBuyCanditatesPerBuyoutCycle; + int BuyingBotBuyCanditatesPerBuyCycle; float BuyingBotAcceptablePriceModifier; std::string AHCharactersGUIDsForQuery;