mirror of
https://github.com/NathanHandley/mod-ah-bot-plus.git
synced 2026-01-13 01:08:37 +00:00
simplified EmptyAuctionHouses() logic
This commit is contained in:
@@ -1586,101 +1586,93 @@ void AuctionHouseBot::InitializeConfiguration()
|
|||||||
|
|
||||||
void AuctionHouseBot::EmptyAuctionHouses()
|
void AuctionHouseBot::EmptyAuctionHouses()
|
||||||
{
|
{
|
||||||
vector<FactionSpecificAuctionHouseConfig> configs = { AllianceConfig, HordeConfig, NeutralConfig };
|
struct AuctionInfo {
|
||||||
vector<uint32> ahBotActiveAuctions;
|
uint32 itemID {0};
|
||||||
|
uint32 characterGUID {0};
|
||||||
// Get all auctions owned by AHBots which have no bidders
|
uint32 houseID {0};
|
||||||
std::string queryString = "SELECT id FROM auctionhouse WHERE itemowner IN ({}) AND buyguid = 0";
|
};
|
||||||
QueryResult result = CharacterDatabase.Query(queryString, AHCharactersGUIDsForQuery);
|
vector<AuctionInfo> ahBotActiveAuctions;
|
||||||
|
|
||||||
auto trans = CharacterDatabase.BeginTransaction();
|
auto trans = CharacterDatabase.BeginTransaction();
|
||||||
if (result && result->GetRowCount() > 0)
|
|
||||||
|
// Get all auctions owned by AHBots
|
||||||
|
std::string queryString = "SELECT id, buyguid, houseid FROM auctionhouse WHERE itemowner IN ({})";
|
||||||
|
QueryResult result = CharacterDatabase.Query(queryString, AHCharactersGUIDsForQuery);
|
||||||
|
if (!result)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (result->GetRowCount() > 0)
|
||||||
{
|
{
|
||||||
|
// Load results into vector<AuctionInfo> for lookups later
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
uint32 tmpdata = result->Fetch()->Get<uint32>();
|
Field* fields = result->Fetch();
|
||||||
ahBotActiveAuctions.push_back(tmpdata);
|
AuctionInfo ai = {
|
||||||
|
fields[0].Get<uint32>(),
|
||||||
|
fields[1].Get<uint32>(),
|
||||||
|
fields[2].Get<uint32>()
|
||||||
|
};
|
||||||
|
ahBotActiveAuctions.push_back(ai);
|
||||||
} while (result->NextRow());
|
} while (result->NextRow());
|
||||||
|
|
||||||
// Remove bidder-less AHBot items from the AHs
|
// For each auction, refund bidder where possible, delete entry from AH
|
||||||
for (FactionSpecificAuctionHouseConfig config : configs) {
|
AuctionHouseObject* auctionHouse;
|
||||||
AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config.GetAHFID());
|
for (auto iter = ahBotActiveAuctions.begin(); iter != ahBotActiveAuctions.end(); ++iter)
|
||||||
for (uint32 auctionID : ahBotActiveAuctions)
|
|
||||||
{
|
|
||||||
vector<uint32>::iterator iter = ahBotActiveAuctions.begin();
|
|
||||||
AuctionEntry* auction = auctionHouse->GetAuction(*iter);
|
|
||||||
ahBotActiveAuctions.erase(iter);
|
|
||||||
|
|
||||||
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();
|
AuctionInfo& ai = *iter;
|
||||||
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
|
// Get Auction House and Auction references
|
||||||
for (FactionSpecificAuctionHouseConfig config : configs) {
|
auctionHouse = nullptr;
|
||||||
AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(config.GetAHFID());
|
switch (ai.houseID) {
|
||||||
for (std::pair<uint32, uint32> p : auctionsToRefund)
|
case 2: auctionHouse = sAuctionMgr->GetAuctionsMap(AllianceConfig.GetAHFID()); break;
|
||||||
|
case 6: auctionHouse = sAuctionMgr->GetAuctionsMap(HordeConfig.GetAHFID()); break;
|
||||||
|
case 7: auctionHouse = sAuctionMgr->GetAuctionsMap(NeutralConfig.GetAHFID()); break;
|
||||||
|
}
|
||||||
|
if (auctionHouse == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
AuctionEntry* auction = auctionHouse->GetAuction(ai.itemID);
|
||||||
|
if (!auction)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// If auction has a bidder, refund that character
|
||||||
|
if (ai.characterGUID != 0)
|
||||||
{
|
{
|
||||||
uint32 auctionID = p.first;
|
|
||||||
uint32 buyGUID = p.second;
|
|
||||||
|
|
||||||
// Lookup accountID and accountName associated with bidder character
|
// Lookup accountID and accountName associated with bidder character
|
||||||
std::string accountIDQueryString = "SELECT account FROM characters WHERE guid = {}";
|
std::string accountIDQueryString = "SELECT account FROM characters WHERE guid = {}";
|
||||||
std::string accountNameQueryString = "SELECT username FROM acore_auth.account WHERE id = {}";
|
std::string accountNameQueryString = "SELECT username FROM account WHERE id = {}";
|
||||||
QueryResult accountIDQueryResult = CharacterDatabase.Query(accountIDQueryString, buyGUID);
|
|
||||||
|
|
||||||
|
QueryResult accountIDQueryResult = CharacterDatabase.Query(accountIDQueryString, ai.characterGUID);
|
||||||
if (!accountIDQueryResult)
|
if (!accountIDQueryResult)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uint32 bidderAccountID = accountIDQueryResult->Fetch()->Get<uint32>();
|
uint32 bidderAccountID = (*accountIDQueryResult)[0].Get<uint32>();
|
||||||
QueryResult accountNameQueryResult = LoginDatabase.Query(accountNameQueryString, bidderAccountID);
|
|
||||||
|
|
||||||
|
QueryResult accountNameQueryResult = LoginDatabase.Query(accountNameQueryString, bidderAccountID);
|
||||||
if (!accountNameQueryResult)
|
if (!accountNameQueryResult)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string bidderAccountName = accountNameQueryResult->Fetch()->Get<std::string>();
|
std::string bidderAccountName = (*accountNameQueryResult)[0].Get<std::string>();
|
||||||
|
|
||||||
// Load Player information, and issue refund
|
// Load Player information, and issue refund
|
||||||
auto session = std::make_unique<WorldSession>(
|
auto session = std::make_unique<WorldSession>(
|
||||||
bidderAccountID, std::move(bidderAccountName), 0, nullptr,
|
bidderAccountID, std::move(bidderAccountName), 0, nullptr,
|
||||||
SEC_PLAYER, sWorld->getIntConfig(CONFIG_EXPANSION), 0, LOCALE_enUS, 0, false, false, 0
|
SEC_PLAYER, sWorld->getIntConfig(CONFIG_EXPANSION), 0, LOCALE_enUS, 0, false, false, 0
|
||||||
);
|
);
|
||||||
|
|
||||||
auto player = std::make_unique<Player>(session.get());
|
auto player = std::make_unique<Player>(session.get());
|
||||||
if (!player)
|
if (!player)
|
||||||
continue;
|
continue;
|
||||||
player->Initialize(buyGUID);
|
|
||||||
|
|
||||||
auto iter = auctionsToRefund.begin();
|
player->Initialize(ai.characterGUID);
|
||||||
AuctionEntry* auction = auctionHouse->GetAuction(iter->first);
|
|
||||||
if (!auction)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
uint32 auctionCut = auction->GetAuctionCut();
|
|
||||||
sAuctionMgr->SendAuctionCancelledToBidderMail(auction, trans);
|
sAuctionMgr->SendAuctionCancelledToBidderMail(auction, trans);
|
||||||
player->ModifyMoney(-int32(auctionCut)); // ModifyMoney() already handles negative check
|
player->ModifyMoney(-int32(auction->GetAuctionCut())); // ModifyMoney() already handles negative check
|
||||||
|
|
||||||
// Remove item from the AH
|
|
||||||
auctionsToRefund.erase(iter);
|
|
||||||
auction->DeleteFromDB(trans);
|
|
||||||
sAuctionMgr->RemoveAItem(auction->item_guid);
|
|
||||||
auctionHouse->RemoveAuction(auction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove item from AH
|
||||||
|
auction->DeleteFromDB(trans);
|
||||||
|
sAuctionMgr->RemoveAItem(auction->item_guid);
|
||||||
|
auctionHouse->RemoveAuction(auction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user