Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restock AH without a server restart or config reload #134

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions src/AuctionHouseBotAuctionHouseScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrSendAuctionOutbiddedMail(

void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionEntry* auction)
{
//
//
// The the configuration for the auction house
//
//

AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntryFromHouse(auction->GetHouseId());
AHBConfig* config = gNeutralConfig;
Expand All @@ -99,9 +99,9 @@ void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionE
}
}

//
//
// Consider only those auctions handled by the bots
//
//

if (config->ConsiderOnlyBotAuctions)
{
Expand Down Expand Up @@ -143,12 +143,9 @@ void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionE

void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, AuctionEntry* auction)
{
//
// Get the configuration for the auction house
//

AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntryFromHouse(auction->GetHouseId());
AHBConfig* config = gNeutralConfig;
AHBConfig* config = gNeutralConfig;

if (ahEntry)
{
Expand All @@ -162,10 +159,7 @@ void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, Aucti
}
}

//
// Consider only those auctions handled by the bots
//

if (config->ConsiderOnlyBotAuctions)
{
if (gBotsId.find(auction->owner.GetCounter()) != gBotsId.end())
Expand All @@ -174,41 +168,41 @@ void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, Aucti
}
}

//
// Verify if we can operate on the item
//

Item* pItem = sAuctionMgr->GetAItem(auction->item_guid);

ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template);

if (!pItem)
{
if (config->DebugOut)
{
LOG_ERROR("module", "AHBot: Item {} doesn't exist, perhaps bought already?", auction->item_guid.ToString());
}

// Decrement item counts even if the item does not exist
if (prototype)
{
config->DecItemCounts(prototype->Class, prototype->Quality);
}

return;
}

//
// Decrements
//

ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template);

if (config->DebugOut)
{
LOG_INFO("module", "AHBot: ah={}, item={}, count={}", auction->GetHouseId(), auction->item_template, config->GetItemCounts(prototype->Quality));
}

// Decrement item counts
config->DecItemCounts(prototype->Class, prototype->Quality);
}

void AHBot_AuctionHouseScript::OnAuctionSuccessful(AuctionHouseObject* /*ah*/, AuctionEntry* auction)
{
//
//
// Get the configuration for the auction house
//
//

AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntryFromHouse(auction->GetHouseId());
AHBConfig* config = gNeutralConfig;
Expand All @@ -225,19 +219,19 @@ void AHBot_AuctionHouseScript::OnAuctionSuccessful(AuctionHouseObject* /*ah*/, A
}
}

//
//
// If the auction has been won, it means that it has been accepted by the market.
// Use the buyout as a reference since the price for the bid is downgraded during selling.
//
//

config->UpdateItemStats(auction->item_template, auction->itemCount, auction->buyout);
}

void AHBot_AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* /*ah*/, AuctionEntry* auction)
{
//
//
// Get the configuration for the auction house
//
//

AuctionHouseEntry const* ahEntry = sAuctionMgr->GetAuctionHouseEntryFromHouse(auction->GetHouseId());
AHBConfig* config = gNeutralConfig;
Expand All @@ -254,12 +248,22 @@ void AHBot_AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* /*ah*/, Aucti
}
}

//
//
// If the auction expired, then it means that the bid was unwanted by the market.
// Bid price is usually less or equal to the buyout, so this likely will bring the price down.
//
//

config->UpdateItemStats(auction->item_template, auction->itemCount, auction->bid);

// Decrement item counts
ItemTemplate const* prototype = sObjectMgr->GetItemTemplate(auction->item_template);

if (config->DebugOut)
{
LOG_INFO("module", "AHBot: ah={}, item={}, count={}", auction->GetHouseId(), auction->item_template, config->GetItemCounts(prototype->Quality));
}

config->DecItemCounts(prototype->Class, prototype->Quality);
}

void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrUpdate()
Expand Down