diff --git a/conf/mod_ahbot.conf.dist b/conf/mod_ahbot.conf.dist index 1aa5fea..d7cc287 100644 --- a/conf/mod_ahbot.conf.dist +++ b/conf/mod_ahbot.conf.dist @@ -42,7 +42,7 @@ AuctionHouseBot.DEBUG = 0 AuctionHouseBot.DEBUG_FILTERS = 0 AuctionHouseBot.EnableSeller = 1 AuctionHouseBot.EnableBuyer = 1 -AuctionHouseBot.GUIDs = 42,43,44,45,46 +AuctionHouseBot.GUIDs = 3 AuctionHouseBot.BotsPerCycle = 1 AuctionHouseBot.ItemsPerCycle = 75 diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index f6ba8d2..3a4a6a8 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -419,7 +419,7 @@ void AuctionHouseBot::populateItemCandidateList() } } -void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) +void AuctionHouseBot::addNewAuctions(std::vector& playerSessions, AHBConfig *config) { if (!AHBSeller) { @@ -483,6 +483,9 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) // only insert a few at a time, so as not to peg the processor for (uint32 cnt = 1; cnt <= items; cnt++) { + // Pick a random player session + Player* playerSession = playerSessions[urand(0, playerSessions.size() - 1)]; + if (debug_Out) LOG_ERROR("module", "AHSeller: {} count", cnt); @@ -508,14 +511,14 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) continue; } - Item* item = Item::CreateItem(itemID, 1, AHBplayer); + Item* item = Item::CreateItem(itemID, 1, playerSession); if (item == NULL) { if (debug_Out) LOG_ERROR("module", "AHSeller: Item::CreateItem() returned NULL"); break; } - item->AddToUpdateQueueOf(AHBplayer); + item->AddToUpdateQueueOf(playerSession); uint32 randomPropertyId = Item::GenerateItemRandomPropertyId(itemID); if (randomPropertyId != 0) @@ -542,7 +545,7 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) auctionEntry->item_guid = item->GetGUID(); auctionEntry->item_template = item->GetEntry(); auctionEntry->itemCount = item->GetCount(); - auctionEntry->owner = AHBplayer->GetGUID(); + auctionEntry->owner = playerSession->GetGUID(); auctionEntry->startbid = bidPrice * stackCount; auctionEntry->buyout = buyoutPrice * stackCount; auctionEntry->bid = 0; @@ -550,7 +553,7 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) auctionEntry->expire_time = (time_t) etime + time(NULL); auctionEntry->auctionHouseEntry = ahEntry; item->SaveToDB(trans); - item->RemoveFromUpdateQueueOf(AHBplayer); + item->RemoveFromUpdateQueueOf(playerSession); sAuctionMgr->AddAItem(item); auctionHouse->AddAuction(auctionEntry); auctionEntry->SaveToDB(trans); @@ -558,7 +561,7 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config) } } -void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, WorldSession *session) +void AuctionHouseBot::addNewAuctionBuyerBotBid(std::vector& playerSessions, AHBConfig *config) { if (!AHBBuyer) { @@ -567,7 +570,7 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con return; } - QueryResult result = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE itemowner<>{} AND buyguid<>{}", AHBplayerGUID, AHBplayerGUID); + QueryResult result = CharacterDatabase.Query("SELECT id FROM auctionhouse WHERE itemowner NOT IN ({}) AND buyguid NOT IN ({})", AHCharactersGUIDsForQuery, AHCharactersGUIDsForQuery); if (!result) return; @@ -587,6 +590,9 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con for (uint32 count = 1; count <= config->GetBidsPerInterval(); ++count) { + // Pick a random player session + Player* playerSession = playerSessions[urand(0, playerSessions.size() - 1)]; + // Do we have anything to bid? If not, stop here. if (possibleBids.empty()) { @@ -683,7 +689,7 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con // Return money of prior bidder if (auction->bidder) { - if (auction->bidder == AHBplayer->GetGUID()) + if (auction->bidder == playerSession->GetGUID()) { //pl->ModifyMoney(-int32(price - auction->bid)); } @@ -691,13 +697,13 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con { // mail to last bidder and return money auto trans = CharacterDatabase.BeginTransaction(); - sAuctionMgr->SendAuctionOutbiddedMail(auction, minBidPrice, session->GetPlayer(), trans); + sAuctionMgr->SendAuctionOutbiddedMail(auction, minBidPrice, playerSession, trans); CharacterDatabase.CommitTransaction(trans); //pl->ModifyMoney(-int32(price)); } } - auction->bidder = AHBplayer->GetGUID(); + auction->bidder = playerSession->GetGUID(); auction->bid = minBidPrice; // Saving auction into database @@ -707,11 +713,11 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con { auto trans = CharacterDatabase.BeginTransaction(); //buyout - if ((auction->bidder) && (AHBplayer->GetGUID() != auction->bidder)) + if ((auction->bidder) && (playerSession->GetGUID() != auction->bidder)) { - sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, session->GetPlayer(), trans); + sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, playerSession, trans); } - auction->bidder = AHBplayer->GetGUID(); + auction->bidder = playerSession->GetGUID(); auction->bid = auction->buyout; // Send mails to buyer & seller @@ -728,7 +734,7 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con } } -void AuctionHouseBot::LoadBotSessions(std::vector& outPlayerSessions) +void AuctionHouseBot::LoadBotSessions(std::vector& outPlayerSessions) { // Determine number to load uint32 numOfBotsToLoad = BotsPerCycle; @@ -736,17 +742,22 @@ void AuctionHouseBot::LoadBotSessions(std::vector& outPlayerSessions) numOfBotsToLoad = AHCharacters.size(); // Build a shufflebag for char indices to pick from - std::deque charGUIDBag; + std::deque charIndicesBag; for (AuctionHouseBotCharacter ahBot : AHCharacters) - charGUIDBag.push_back(ahBot.CharacterGUID); + charIndicesBag.push_back(ahBot.CharacterGUID); // Pluck out the guids and load them one at a time for (uint32 i = 0; i < numOfBotsToLoad; i++) { - - - - + uint32 index = urand(0, charIndicesBag.size()-1); + uint32 charIndex = charIndicesBag[index]; + charIndicesBag.erase(charIndicesBag.begin() + index); + std::string accountName = "AuctionHouseBotGUID" + std::to_string(AHCharacters[charIndex].CharacterGUID); + WorldSession _session(AHCharacters[charIndex].AccountID, std::move(accountName), nullptr, SEC_PLAYER, sWorld->getIntConfig(CONFIG_EXPANSION), 0, LOCALE_enUS, 0, false, false, 0); + Player playerSession(&_session); + playerSession.Initialize(AHCharacters[charIndex].CharacterGUID); + ObjectAccessor::AddObject(&playerSession); + outPlayerSessions.push_back(&playerSession); } } @@ -758,44 +769,45 @@ void AuctionHouseBot::Update() if (AHCharacters.size() == 0) return; - std::string accountName = "AuctionHouseBot" + std::to_string(AHBplayerAccount); - - 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); + // Load the bots + std::vector playerSessions; + LoadBotSessions(playerSessions); // Add New Bids if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) { - addNewAuctions(&_AHBplayer, &AllianceConfig); + addNewAuctions(playerSessions, &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); + addNewAuctionBuyerBotBid(playerSessions, &AllianceConfig); _lastrun_a = _newrun; } - addNewAuctions(&_AHBplayer, &HordeConfig); + addNewAuctions(playerSessions, &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); + addNewAuctionBuyerBotBid(playerSessions, &HordeConfig); _lastrun_h = _newrun; } } - addNewAuctions(&_AHBplayer, &NeutralConfig); + addNewAuctions(playerSessions, &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); + addNewAuctionBuyerBotBid(playerSessions, &NeutralConfig); _lastrun_n = _newrun; } - ObjectAccessor::RemoveObject(&_AHBplayer); + + // Remove the player sessions + for (int i = 0; i < playerSessions.size(); i++) + ObjectAccessor::RemoveObject(playerSessions[i]); + playerSessions.clear(); } void AuctionHouseBot::Initialize() @@ -813,9 +825,9 @@ void AuctionHouseBot::InitializeConfiguration() AHBSeller = sConfigMgr->GetOption("AuctionHouseBot.EnableSeller", false); AHBBuyer = sConfigMgr->GetOption("AuctionHouseBot.EnableBuyer", false); - AddCharacters(sConfigMgr->GetOption("AuctionHouseBot.GUIDs", 0)); + AddCharacters(sConfigMgr->GetOption("AuctionHouseBot.GUIDs", "0")); if (AHCharacters.size() == 0) - AddCharacters(sConfigMgr->GetOption("AuctionHouseBot.GUID", 0)); // Backwards compat + AddCharacters(sConfigMgr->GetOption("AuctionHouseBot.GUID", "0")); // Backwards compat ItemsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.ItemsPerCycle", 75); BotsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.BotsPerCycle", 1); diff --git a/src/AuctionHouseBot.h b/src/AuctionHouseBot.h index ca83908..f41a294 100644 --- a/src/AuctionHouseBot.h +++ b/src/AuctionHouseBot.h @@ -133,6 +133,9 @@ public: class AuctionHouseBot { +public: + std::vector AHCharacters; + private: bool debug_Out; bool debug_Out_Filters; @@ -140,7 +143,6 @@ private: bool AHBSeller; bool AHBBuyer; - std::vector AHCharacters; std::string AHCharactersGUIDsForQuery; uint32 ItemsPerCycle; uint32 BotsPerCycle; @@ -232,8 +234,8 @@ private: void populatetemClassSeedListForItemClass(uint32 itemClass, uint32 itemClassSeedWeight); void populateItemClassProportionList(); void populateItemCandidateList(); - void addNewAuctions(Player *AHBplayer, AHBConfig *config); - void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, WorldSession *session); + void addNewAuctions(std::vector& playerSessions, AHBConfig *config); + void addNewAuctionBuyerBotBid(std::vector& playerSessions, AHBConfig *config); AuctionHouseBot(); @@ -255,7 +257,7 @@ public: void AddDisabledItems(std::string disabledItemIdString); void AddPriceMinimumOverrides(std::string priceMinimimOverridesString); //ObjectGuid::LowType GetAHBplayerGUID() { return AHBplayerGUID; }; - void LoadBotSessions(std::vector& outPlayerSessions); + void LoadBotSessions(std::vector& outPlayerSessions); }; #define auctionbot AuctionHouseBot::instance() diff --git a/src/AuctionHouseBotScript.cpp b/src/AuctionHouseBotScript.cpp index 3d7e5ff..ee10beb 100644 --- a/src/AuctionHouseBotScript.cpp +++ b/src/AuctionHouseBotScript.cpp @@ -33,23 +33,49 @@ public: void OnBeforeAuctionHouseMgrSendAuctionSuccessfulMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* /*auction*/, Player* owner, uint32& /*owner_accId*/, uint32& /*profit*/, bool& sendNotification, bool& updateAchievementCriteria, bool& /*sendMail*/) override { - if (owner && owner->GetGUID().GetCounter() == auctionbot->GetAHBplayerGUID()) + if (owner) { - sendNotification = false; - updateAchievementCriteria = false; + bool isAHBot = false; + for (AuctionHouseBotCharacter character : auctionbot->AHCharacters) + { + if (character.CharacterGUID == owner->GetGUID().GetCounter()) + { + isAHBot = true; + break; + } + } + if (isAHBot == true) + { + 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; + if (owner) + { + bool isAHBot = false; + for (AuctionHouseBotCharacter character : auctionbot->AHCharacters) + { + if (character.CharacterGUID == owner->GetGUID().GetCounter()) + { + isAHBot = true; + break; + } + } + if (isAHBot == true) + { + 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((uint32)auction->GetHouseId(), auction->Id, ObjectGuid::Create(auctionbot->GetAHBplayerGUID()), newPrice, auction->GetAuctionOutBid(), auction->item_template); + //if (oldBidder && !newBidder) + // oldBidder->GetSession()->SendAuctionBidderNotification((uint32)auction->GetHouseId(), auction->Id, ObjectGuid::Create(auctionbot->GetAHBplayerGUID()), newPrice, auction->GetAuctionOutBid(), auction->item_template); } void OnBeforeAuctionHouseMgrUpdate() override @@ -65,7 +91,16 @@ public: 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()) + bool isAHBot = false; + for (AuctionHouseBotCharacter character : auctionbot->AHCharacters) + { + if (character.CharacterGUID == receiver.GetPlayerGUIDLow()) + { + isAHBot = true; + break; + } + } + if (isAHBot == true) { if (sender.GetMailMessageType() == MAIL_AUCTION) // auction mail with items deleteMailItemsFromDB = true;