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

Market price adaptation mechanism #102

Merged
merged 7 commits into from
Sep 8, 2024
Prev Previous commit
Next Next commit
Handle of the configuration reloading in the correct way from the com…
…mand line (cleanup and initialization of new elements)
kewinrausch committed Aug 23, 2024
commit f8e0d89200b3b0eb69e253818a35a7302773542f
1 change: 0 additions & 1 deletion src/AuctionHouseBotConfig.cpp
Original file line number Diff line number Diff line change
@@ -3260,7 +3260,6 @@ void AHBConfig::InitializeBins()
// Perform reporting and the last check: if no items are disabled or in the whitelist clear the bin making the selling useless
//

LOG_INFO("module", "===== AHBot ====================");
LOG_INFO("module", "AHBot: Configuration for ah {}", AHID);

if (SellerWhiteList.size() == 0)
79 changes: 76 additions & 3 deletions src/AuctionHouseBotWorldScript.cpp
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ AHBot_WorldScript::AHBot_WorldScript() : WorldScript("AHBot_WorldScript")

}

void AHBot_WorldScript::OnBeforeConfigLoad(bool /*reload*/)
void AHBot_WorldScript::OnBeforeConfigLoad(bool reload)
{
//
// Retrieve how many bots shall be operating on the auction market
@@ -88,26 +88,99 @@ void AHBot_WorldScript::OnBeforeConfigLoad(bool /*reload*/)
LOG_ERROR("server.loading", "AHBot: no characters registered for account {}", account);
return;
}

//
// Start the bots only if the operation is a reload, otherwise let the OnStartup do the job
//

if (reload)
{
if (debug)
{
LOG_INFO("module", "AHBot: Reloading the bots");
}

//
// Clear the bots array; this way they wont be used anymore during the initialization stage.
//

DeleteBots();

//
// Reload the configuration for the auction houses
//

gAllianceConfig->Initialize(gBotsId);
gHordeConfig->Initialize (gBotsId);
gNeutralConfig->Initialize (gBotsId);

//
// Start again the bots
//

PopulateBots();
}
}

void AHBot_WorldScript::OnStartup()
{
LOG_INFO("server.loading", "Initialize AuctionHouseBot...");

//
// Initialize the configuration
// Initialize the configuration (done only once at startup)
//

gAllianceConfig->Initialize(gBotsId);
gHordeConfig->Initialize (gBotsId);
gNeutralConfig->Initialize (gBotsId);

//
// Starts the amount of bots read furing the configuration phase
// Starts the bots
//

PopulateBots();
}

void AHBot_WorldScript::DeleteBots()
{
//
// Save the old bots references.
//

std::set<AuctionHouseBot*> oldBots;

for (AuctionHouseBot* bot: gBots)
{
oldBots.insert(bot);
}

//
// Clear the bot list
//

gBots.clear();

//
// Free the resources used up by the old bots
//

for (AuctionHouseBot* bot: oldBots)
{
delete bot;
}
}


void AHBot_WorldScript::PopulateBots()
{
uint32 account = sConfigMgr->GetOption<uint32>("AuctionHouseBot.Account", 0);

//
// Insert the bot in the list used for auction house iterations
//

gBots.clear();

for (uint32 id: gBotsId)
{
AuctionHouseBot* bot = new AuctionHouseBot(account, id);
4 changes: 4 additions & 0 deletions src/AuctionHouseBotWorldScript.h
Original file line number Diff line number Diff line change
@@ -13,6 +13,10 @@

class AHBot_WorldScript : public WorldScript
{
private:
void DeleteBots();
void PopulateBots();

public:
AHBot_WorldScript();