mirror of
https://github.com/NathanHandley/mod-ah-bot-plus.git
synced 2026-01-13 01:08:37 +00:00
.ahbot empty respects player auctions and returns bids on cancelled items
This commit is contained in:
@@ -1587,20 +1587,100 @@ void AuctionHouseBot::InitializeConfiguration()
|
|||||||
void AuctionHouseBot::EmptyAuctionHouses()
|
void AuctionHouseBot::EmptyAuctionHouses()
|
||||||
{
|
{
|
||||||
vector<FactionSpecificAuctionHouseConfig> configs = { AllianceConfig, HordeConfig, NeutralConfig };
|
vector<FactionSpecificAuctionHouseConfig> configs = { AllianceConfig, HordeConfig, NeutralConfig };
|
||||||
|
vector<uint32> ahBotActiveAuctions;
|
||||||
|
|
||||||
|
// Get all auctions owned by AHBots which have no bidders
|
||||||
|
std::string queryString = "SELECT id FROM auctionhouse WHERE itemowner IN ({}) AND buyguid = 0";
|
||||||
|
QueryResult result = CharacterDatabase.Query(queryString, AHCharactersGUIDsForQuery);
|
||||||
|
|
||||||
auto trans = CharacterDatabase.BeginTransaction();
|
auto trans = CharacterDatabase.BeginTransaction();
|
||||||
|
if (result && result->GetRowCount() > 0)
|
||||||
for (FactionSpecificAuctionHouseConfig config : configs) {
|
{
|
||||||
AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config.GetAHFID());
|
do
|
||||||
auto auctionEntryMap = auctionHouse->GetAuctions();
|
|
||||||
for (auto itr = auctionEntryMap.begin(); itr != auctionEntryMap.end();)
|
|
||||||
{
|
{
|
||||||
AuctionEntry* auction = itr->second;
|
uint32 tmpdata = result->Fetch()->Get<uint32>();
|
||||||
|
ahBotActiveAuctions.push_back(tmpdata);
|
||||||
|
} while (result->NextRow());
|
||||||
|
|
||||||
auction->DeleteFromDB(trans);
|
// Remove bidder-less AHBot items from the AHs
|
||||||
sAuctionMgr->RemoveAItem(auction->item_guid);
|
for (FactionSpecificAuctionHouseConfig config : configs) {
|
||||||
auctionHouse->RemoveAuction(auction);
|
AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config.GetAHFID());
|
||||||
|
for (uint32 auctionID : ahBotActiveAuctions)
|
||||||
|
{
|
||||||
|
vector<uint32>::iterator iter = ahBotActiveAuctions.begin();
|
||||||
|
AuctionEntry* auction = auctionHouse->GetAuction(*iter);
|
||||||
|
ahBotActiveAuctions.erase(iter);
|
||||||
|
|
||||||
itr = auctionEntryMap.erase(itr);
|
auction->DeleteFromDB(trans);
|
||||||
|
sAuctionMgr->RemoveAItem(auction->item_guid);
|
||||||
|
auctionHouse->RemoveAuction(auction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get auctions owned by AHBots which DO have a bidder, return their deposits
|
||||||
|
std::vector<std::pair<uint32, uint32>> auctionsToRefund;
|
||||||
|
std::string refundQueryString = "SELECT id, buyguid FROM auctionhouse WHERE itemowner IN ({}) AND buyguid != 0";
|
||||||
|
QueryResult refundResult = CharacterDatabase.Query(refundQueryString, AHCharactersGUIDsForQuery);
|
||||||
|
if (refundResult && refundResult->GetRowCount() > 0)
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Field* fields = refundResult->Fetch();
|
||||||
|
uint32 auctionID = fields[0].Get<uint32>();
|
||||||
|
uint32 buyGUID = fields[1].Get<uint32>();
|
||||||
|
auctionsToRefund.push_back({auctionID, buyGUID});
|
||||||
|
} while (refundResult->NextRow());
|
||||||
|
|
||||||
|
// Remove AHBot items with bidders from the AHs
|
||||||
|
for (FactionSpecificAuctionHouseConfig config : configs) {
|
||||||
|
AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config.GetAHFID());
|
||||||
|
for (std::pair<uint32, uint32> p : auctionsToRefund)
|
||||||
|
{
|
||||||
|
uint32 auctionID = p.first;
|
||||||
|
uint32 buyGUID = p.second;
|
||||||
|
|
||||||
|
// Lookup accountID and accountName associated with bidder character
|
||||||
|
std::string accountIDQueryString = "SELECT account FROM characters WHERE guid = {}";
|
||||||
|
std::string accountNameQueryString = "SELECT username FROM acore_auth.account WHERE id = {}";
|
||||||
|
QueryResult accountIDQueryResult = CharacterDatabase.Query(accountIDQueryString, buyGUID);
|
||||||
|
|
||||||
|
if (!accountIDQueryResult)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uint32 bidderAccountID = accountIDQueryResult->Fetch()->Get<uint32>();
|
||||||
|
QueryResult accountNameQueryResult = LoginDatabase.Query(accountNameQueryString, bidderAccountID);
|
||||||
|
|
||||||
|
if (!accountNameQueryResult)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::string bidderAccountName = accountNameQueryResult->Fetch()->Get<std::string>();
|
||||||
|
|
||||||
|
// Load Player information, and issue refund
|
||||||
|
auto session = std::make_unique<WorldSession>(
|
||||||
|
bidderAccountID, std::move(bidderAccountName), 0, nullptr,
|
||||||
|
SEC_PLAYER, sWorld->getIntConfig(CONFIG_EXPANSION), 0, LOCALE_enUS, 0, false, false, 0
|
||||||
|
);
|
||||||
|
auto player = std::make_unique<Player>(session.get());
|
||||||
|
if (!player)
|
||||||
|
continue;
|
||||||
|
player->Initialize(buyGUID);
|
||||||
|
|
||||||
|
auto iter = auctionsToRefund.begin();
|
||||||
|
AuctionEntry* auction = auctionHouse->GetAuction(iter->first);
|
||||||
|
if (!auction)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uint32 auctionCut = auction->GetAuctionCut();
|
||||||
|
sAuctionMgr->SendAuctionCancelledToBidderMail(auction, trans);
|
||||||
|
player->ModifyMoney(-int32(auctionCut)); // ModifyMoney() already handles negative check
|
||||||
|
|
||||||
|
// Remove item from the AH
|
||||||
|
auctionsToRefund.erase(iter);
|
||||||
|
auction->DeleteFromDB(trans);
|
||||||
|
sAuctionMgr->RemoveAItem(auction->item_guid);
|
||||||
|
auctionHouse->RemoveAuction(auction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user