Skip to content

Commit

Permalink
AuctionHouse Bot fixes (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
H0zen authored and billy1arm committed Sep 14, 2016
1 parent 2445ac7 commit 806a2a8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 49 deletions.
67 changes: 26 additions & 41 deletions src/game/AuctionHouseBot/AuctionHouseBot.cpp
Expand Up @@ -428,9 +428,21 @@ bool AuctionBotConfig::Initialize()

m_ItemsPerCycleBoost = getConfig(CONFIG_UINT32_AHBOT_ITEMS_PER_CYCLE_BOOST);
m_ItemsPerCycleNormal = getConfig(CONFIG_UINT32_AHBOT_ITEMS_PER_CYCLE_NORMAL);

return true;
}

void AuctionBotConfig::SetAHBotId(const std::string& BotCharName)
{
m_BotId = 0;
if (!BotCharName.empty())
{
m_BotId = sObjectMgr.GetPlayerGuidByName(BotCharName.c_str()).GetCounter();
if (!m_BotId)
{ sLog.outError("AHBot uses an invalid character name `%s`", BotCharName.c_str()); }
}
}

void AuctionBotConfig::setConfig(AuctionBotConfigUInt32Values index, char const* fieldname, uint32 defvalue)
{
setConfig(index, m_AhBotCfg.GetIntDefault(fieldname, defvalue));
Expand Down Expand Up @@ -484,7 +496,7 @@ void AuctionBotConfig::GetConfigFromFile()

SetAHBotIncludes(m_AhBotCfg.GetStringDefault("AuctionHouseBot.forceIncludeItems", ""));
SetAHBotExcludes(m_AhBotCfg.GetStringDefault("AuctionHouseBot.forceExcludeItems", ""));
SetAHBotCharacterName(m_AhBotCfg.GetStringDefault("AuctionHouseBot.CharacterName", ""));
SetAHBotId(m_AhBotCfg.GetStringDefault("AuctionHouseBot.CharacterName", ""));

setConfig(CONFIG_BOOL_AHBOT_BUYER_ALLIANCE_ENABLED , "AuctionHouseBot.Buyer.Alliance.Enabled" , false);
setConfig(CONFIG_BOOL_AHBOT_BUYER_HORDE_ENABLED , "AuctionHouseBot.Buyer.Horde.Enabled" , false);
Expand Down Expand Up @@ -719,11 +731,7 @@ uint32 AuctionBotBuyer::GetBuyableEntry(AHB_Buyer_Config& config)
else if (buyerItem.MinBidPrice == 0)
{ buyerItem.MinBidPrice = Aentry->startbid / item->GetCount(); }

uint32 AHBotGuid;
std::string AHBotCharacterName = sAuctionBotConfig.GetAHBotCharacterName();
if (!AHBotCharacterName.empty())
{ AHBotGuid = sObjectMgr.GetPlayerGuidByName(AHBotCharacterName.c_str()); }
if (!Aentry->owner || Aentry->owner == AHBotGuid)
if (Aentry->owner == sAuctionBotConfig.GetAHBotId())
{
if ((Aentry->bid != 0) && Aentry->bidder) // Add bided by player
{
Expand Down Expand Up @@ -754,7 +762,7 @@ uint32 AuctionBotBuyer::GetBuyableEntry(AHB_Buyer_Config& config)
}
}

DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: %u items added to buyable vector for ah type: %u", count, config.GetHouseType());
DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: %u items added to buyable vector for AH type: %u", count, config.GetHouseType());
DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: SameItemInfo size = " SIZEFMTD, config.SameItemInfo.size());
return count;
}
Expand Down Expand Up @@ -998,11 +1006,7 @@ void AuctionBotBuyer::addNewAuctionBuyerBotBid(AHB_Buyer_Config& config)
minBuyPrice / 10000, minBidPrice / 10000);
DEBUG_FILTER_LOG(LOG_FILTER_AHBOT_BUYER, "AHBot: Actual Entry price, Buy=%ug, Bid=%ug.", buyoutPrice / 10000, bidPrice / 10000);

uint32 AHBotGuid;
std::string AHBotCharacterName = sAuctionBotConfig.GetAHBotCharacterName();
if (!AHBotCharacterName.empty())
{ AHBotGuid = sObjectMgr.GetPlayerGuidByName(AHBotCharacterName.c_str()); }
if (!auction->owner || auction->owner == AHBotGuid) // Original auction owner
if (auction->owner == sAuctionBotConfig.GetAHBotId()) // Original auction owner
{
MaxChance = MaxChance / 5; // if Owner is AHBot this mean player placed bid on this auction. We divide by 5 chance for AhBuyer to place bid on it. (This make more challenge than ignore entry)
}
Expand Down Expand Up @@ -1585,11 +1589,7 @@ uint32 AuctionBotSeller::SetStat(AHB_Seller_Config& config)
ItemPrototype const* prototype = item->GetProto();
if (prototype)
{
uint32 AHBotGuid;
std::string AHBotCharacterName = sAuctionBotConfig.GetAHBotCharacterName();
if (!AHBotCharacterName.empty())
{ AHBotGuid = sObjectMgr.GetPlayerGuidByName(AHBotCharacterName.c_str()); }
if (!Aentry->owner || Aentry->owner == AHBotGuid) // Add only ahbot items
if (Aentry->owner == sAuctionBotConfig.GetAHBotId()) // Add only ahbot items
{
++ItemsInAH[prototype->Quality][prototype->Class];
}
Expand Down Expand Up @@ -1788,16 +1788,7 @@ void AuctionBotSeller::addNewAuctions(AHB_Seller_Config& config)
// Price of items are set here
SetPricesOfItem(config, buyoutPrice, bidPrice, stackCount, ItemQualities(prototype->Quality));

// Add the auction under the player name specified in the configuration.
std::string AHBotCharacterName = sAuctionBotConfig.GetAHBotCharacterName();
if (!AHBotCharacterName.empty())
{
ObjectGuid guid = sObjectMgr.GetPlayerGuidByName(AHBotCharacterName.c_str());
if (guid)
{ auctionHouse->AddAuctionByGuid(ahEntry, item, urand(config.GetMinTime(), config.GetMaxTime()) * HOUR, bidPrice, buyoutPrice, guid.GetCounter()); }
}
else
{ auctionHouse->AddAuction(ahEntry, item, urand(config.GetMinTime(), config.GetMaxTime()) * HOUR, bidPrice, buyoutPrice); }
auctionHouse->AddAuctionByGuid(ahEntry, item, urand(config.GetMinTime(), config.GetMaxTime()) * HOUR, bidPrice, buyoutPrice, sAuctionBotConfig.GetAHBotId());
}
}

Expand Down Expand Up @@ -1826,7 +1817,7 @@ AuctionHouseBot::~AuctionHouseBot()
delete m_Seller;
}

void AuctionHouseBot::InitilizeAgents()
void AuctionHouseBot::InitializeAgents()
{
if (sAuctionBotConfig.getConfig(CONFIG_BOOL_AHBOT_SELLER_ENABLED))
{
Expand All @@ -1853,7 +1844,9 @@ void AuctionHouseBot::InitilizeAgents()
void AuctionHouseBot::Initialize()
{
if (sAuctionBotConfig.Initialize())
{ InitilizeAgents(); }
{
InitializeAgents();
}
}

void AuctionHouseBot::SetItemsRatio(uint32 al, uint32 ho, uint32 ne)
Expand Down Expand Up @@ -1888,7 +1881,7 @@ bool AuctionHouseBot::ReloadAllConfig()
return false;
}

InitilizeAgents();
InitializeAgents();
return true;
}

Expand All @@ -1908,11 +1901,7 @@ void AuctionHouseBot::PrepareStatusInfos(AuctionHouseBotStatusInfo& statusInfo)
if (Item* item = sAuctionMgr.GetAItem(Aentry->itemGuidLow))
{
ItemPrototype const* prototype = item->GetProto();
uint32 AHBotGuid;
std::string AHBotCharacterName = sAuctionBotConfig.GetAHBotCharacterName();
if (!AHBotCharacterName.empty())
{ AHBotGuid = sObjectMgr.GetPlayerGuidByName(AHBotCharacterName.c_str()); }
if (!Aentry->owner || Aentry->owner == AHBotGuid) // Add only ahbot items
if (Aentry->owner == sAuctionBotConfig.GetAHBotId()) // Add only ahbot items
{
if (prototype->Quality < MAX_AUCTION_QUALITY)
{ ++statusInfo[i].QualityInfo[prototype->Quality]; }
Expand All @@ -1933,12 +1922,8 @@ void AuctionHouseBot::Rebuild(bool all)
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
{
AuctionEntry* entry = itr->second;
uint32 AHBotGuid;
std::string AHBotCharacterName = sAuctionBotConfig.GetAHBotCharacterName();
if (!AHBotCharacterName.empty())
{ AHBotGuid = sObjectMgr.GetPlayerGuidByName(AHBotCharacterName.c_str()); };
if (!entry->owner || entry->owner == AHBotGuid) // ahbot auction
if (all || entry->bid == 0) // expire now auction if no bid or forced
if (entry->owner == sAuctionBotConfig.GetAHBotId()) // ahbot auction
if (all || entry->bid == 0) // expire auction now if no bid or forced
entry->expireTime = sWorld.GetGameTime();
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/game/AuctionHouseBot/AuctionHouseBot.h
Expand Up @@ -195,9 +195,9 @@ class AuctionBotConfig
/**
* @brief
*
* @return const char
* @return uint32 - AH Bot ID
*/
const char* GetAHBotCharacterName() const { return m_AHBotCharacterName.c_str(); }
uint32 GetAHBotId() const { return m_BotId; }

/**
* @brief
Expand Down Expand Up @@ -292,11 +292,10 @@ class AuctionBotConfig
std::string m_configFileName; /**< TODO */
std::string m_AHBotIncludes; /**< TODO */
std::string m_AHBotExcludes; /**< TODO */
std::string m_AHBotCharacterName;
Config m_AhBotCfg; /**< TODO */
uint32 m_ItemsPerCycleBoost; /**< TODO */
uint32 m_ItemsPerCycleNormal; /**< TODO */

uint32 m_BotId;
uint32 m_configUint32Values[CONFIG_UINT32_AHBOT_UINT32_COUNT]; /**< TODO */
bool m_configBoolValues[CONFIG_UINT32_AHBOT_BOOL_COUNT]; /**< TODO */

Expand All @@ -315,9 +314,9 @@ class AuctionBotConfig
/**
* @brief
*
* @param AHBotCharacterName
* @param AHBot Character Name
*/
void SetAHBotCharacterName(const std::string& AHBotCharacterName) { m_AHBotCharacterName = AHBotCharacterName; }
void SetAHBotId(const std::string& BotCharName);

/**
* @brief Sets a certain config value to the given default value
Expand Down Expand Up @@ -519,8 +518,7 @@ class AuctionHouseBot
* @brief Initializes the agents, ie: the \ref AuctionBotBuyer and \ref AuctionBotSeller
*
*/
void InitilizeAgents();

void InitializeAgents();
AuctionBotAgent* m_Buyer; /**< The buyer (\ref AuctionBotBuyer) for this \ref AuctionHouseBot */
AuctionBotAgent* m_Seller; /**< The seller (\ref AuctionBotSeller) for this \ref AuctionHouseBot */

Expand Down

0 comments on commit 806a2a8

Please sign in to comment.