mirror of
https://github.com/NathanHandley/mod-ah-bot-plus.git
synced 2026-01-13 01:08:37 +00:00
Merge pull request #36 from zeb139/cleanup-dangling-expired-auctions
Added config to remove dangling expired/emptied auctions
This commit is contained in:
@@ -39,6 +39,13 @@
|
||||
# Enable/Disable the part of AHBot that puts items up for auction
|
||||
# Default: false (disabled)
|
||||
#
|
||||
# AuctionHouseBot.ReturnExpiredAuctionItemsToBot
|
||||
# If enabled (true), returns expired auction items to the AH Bot(s) via
|
||||
# mail. Note: if enabled, this can cause your bot's mailbox to fill up
|
||||
# if you don't manage it manually. This can also cause the size of your
|
||||
# acore_characters.item_instance database table to grow over time.
|
||||
# Default: false (disabled)
|
||||
#
|
||||
# AuctionHouseBot.GUIDs
|
||||
# These are the character GUIDS (from characters->characters table) that
|
||||
# will be used to create auctions and otherwise interact with auctions.
|
||||
@@ -68,6 +75,7 @@ AuctionHouseBot.DEBUG_FILTERS = false
|
||||
AuctionHouseBot.MinutesBetweenBuyCycle = 1
|
||||
AuctionHouseBot.MinutesBetweenSellCycle = 1
|
||||
AuctionHouseBot.EnableSeller = false
|
||||
AuctionHouseBot.ReturnExpiredAuctionItemsToBot = false
|
||||
AuctionHouseBot.GUIDs = 0
|
||||
AuctionHouseBot.ItemsPerCycle = 150
|
||||
AuctionHouseBot.ListingExpireTimeInSecondsMin = 900
|
||||
|
||||
@@ -41,6 +41,7 @@ AuctionHouseBot::AuctionHouseBot() :
|
||||
debug_Out_Filters(false),
|
||||
SellingBotEnabled(false),
|
||||
BuyingBotEnabled(false),
|
||||
ReturnExpiredAuctionItemsToBot(false),
|
||||
CyclesBetweenBuyActionMin(1),
|
||||
CyclesBetweenBuyAction(1),
|
||||
CyclesBetweenBuyActionMax(1),
|
||||
@@ -1266,11 +1267,14 @@ void AuctionHouseBot::AddNewAuctionBuyerBotBid(std::vector<Player*> AHBPlayers,
|
||||
|
||||
void AuctionHouseBot::Update()
|
||||
{
|
||||
if ((SellingBotEnabled == false) && (BuyingBotEnabled == false))
|
||||
return;
|
||||
if (AHCharacters.empty() == true)
|
||||
return;
|
||||
|
||||
CleanupExpiredAuctionItems();
|
||||
|
||||
if ((SellingBotEnabled == false) && (BuyingBotEnabled == false))
|
||||
return;
|
||||
|
||||
LastBuyCycleCount++;
|
||||
LastSellCycleCount++;
|
||||
|
||||
@@ -1369,6 +1373,7 @@ void AuctionHouseBot::InitializeConfiguration()
|
||||
|
||||
// Buyer & Seller core properties
|
||||
SetCyclesBetweenBuyOrSell();
|
||||
ReturnExpiredAuctionItemsToBot = sConfigMgr->GetOption<bool>("AuctionHouseBot.ReturnExpiredAuctionItemsToBot", false);
|
||||
ItemsPerCycle = sConfigMgr->GetOption<uint32>("AuctionHouseBot.ItemsPerCycle", 75);
|
||||
MaxBuyoutPriceInCopper = sConfigMgr->GetOption<uint32>("AuctionHouseBot.MaxBuyoutPriceInCopper", 1000000000);
|
||||
BuyoutVariationReducePercent = sConfigMgr->GetOption<float>("AuctionHouseBot.BuyoutVariationReducePercent", 0.15f);
|
||||
@@ -1647,7 +1652,13 @@ void AuctionHouseBot::EmptyAuctionHouses()
|
||||
if (ai.characterGUID != 0)
|
||||
sAuctionMgr->SendAuctionCancelledToBidderMail(auction, trans);
|
||||
|
||||
// Remove item from AH
|
||||
// Return item to AHBot if configured, else delete it
|
||||
if (ReturnExpiredAuctionItemsToBot)
|
||||
sAuctionMgr->SendAuctionExpiredMail(auction, trans, true, true);
|
||||
else
|
||||
Item::DeleteFromDB(trans, auction->item_guid.GetCounter());
|
||||
|
||||
// Remove auction from AH
|
||||
auction->DeleteFromDB(trans);
|
||||
sAuctionMgr->RemoveAItem(auction->item_guid);
|
||||
auctionHouse->RemoveAuction(auction);
|
||||
@@ -1943,3 +1954,33 @@ void AuctionHouseBot::PopulateVendorItemsPrices()
|
||||
} while (result->NextRow());
|
||||
}
|
||||
}
|
||||
|
||||
void AuctionHouseBot::CleanupExpiredAuctionItems()
|
||||
{
|
||||
if (AHCharactersGUIDsForQuery.empty() ||
|
||||
ReturnExpiredAuctionItemsToBot)
|
||||
return;
|
||||
|
||||
// Delete item_instances that are not in the Auction Houses
|
||||
std::string queryItemInstancesString = R"SQL(
|
||||
SELECT guid
|
||||
FROM item_instance
|
||||
LEFT JOIN auctionhouse ON auctionhouse.itemguid = item_instance.guid
|
||||
WHERE item_instance.owner_guid IN ({})
|
||||
AND auctionhouse.id IS NULL
|
||||
)SQL";
|
||||
|
||||
QueryResult queryItemInstancesResult = CharacterDatabase.Query(queryItemInstancesString, AHCharactersGUIDsForQuery);
|
||||
if (!queryItemInstancesResult)
|
||||
return;
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
do
|
||||
{
|
||||
uint32 guid = queryItemInstancesResult->Fetch()[0].Get<uint32>();
|
||||
Item::DeleteFromDB(trans, guid);
|
||||
} while (queryItemInstancesResult->NextRow());
|
||||
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ private:
|
||||
|
||||
bool SellingBotEnabled;
|
||||
bool BuyingBotEnabled;
|
||||
bool ReturnExpiredAuctionItemsToBot;
|
||||
uint32 CyclesBetweenBuyActionMin;
|
||||
uint32 CyclesBetweenBuyAction;
|
||||
uint32 CyclesBetweenBuyActionMax;
|
||||
@@ -322,6 +323,7 @@ public:
|
||||
void AddNewAuctions(std::vector<Player*> AHBPlayers, FactionSpecificAuctionHouseConfig* config);
|
||||
void AddNewAuctionBuyerBotBid(std::vector<Player*> AHBPlayers, FactionSpecificAuctionHouseConfig* config);
|
||||
void PopulateVendorItemsPrices();
|
||||
void CleanupExpiredAuctionItems();
|
||||
|
||||
template <typename ValueType>
|
||||
void AddItemValuePairsToItemIDMap(std::unordered_map<uint32, ValueType>& workingValueToItemIDMap, std::string valueToItemIDMap);
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void OnBeforeAuctionHouseMgrSendAuctionExpiredMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* /*auction*/, Player* owner, uint32& /*owner_accId*/, bool& sendNotification, bool& /*sendMail*/) override
|
||||
void OnBeforeAuctionHouseMgrSendAuctionExpiredMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* /*auction*/, Player* owner, uint32& /*owner_accId*/, bool& sendNotification, bool& sendMail) override
|
||||
{
|
||||
if (owner)
|
||||
{
|
||||
@@ -78,6 +78,11 @@ public:
|
||||
if (isAHBot == true)
|
||||
{
|
||||
sendNotification = false;
|
||||
|
||||
if (sConfigMgr->GetOption<bool>("AuctionHouseBot.ReturnExpiredAuctionItemsToBot", false))
|
||||
sendMail = true;
|
||||
else
|
||||
sendMail = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,9 +117,17 @@ public:
|
||||
}
|
||||
if (isAHBot == true)
|
||||
{
|
||||
if (sender.GetMailMessageType() == MAIL_AUCTION) // auction mail with items
|
||||
deleteMailItemsFromDB = true;
|
||||
sendMail = false;
|
||||
if (sConfigMgr->GetOption<bool>("AuctionHouseBot.ReturnExpiredAuctionItemsToBot", false))
|
||||
{
|
||||
deleteMailItemsFromDB = false;
|
||||
sendMail = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sender.GetMailMessageType() == MAIL_AUCTION) // auction mail with items
|
||||
deleteMailItemsFromDB = true;
|
||||
sendMail = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user