diff options
author | jackpoz <giacomopoz@gmail.com> | 2015-08-01 18:48:55 +0200 |
---|---|---|
committer | Carbenium <carbenium@outlook.com> | 2015-09-24 19:48:31 +0200 |
commit | cf67b7d375845e1745a79a712701413fcf4e75ea (patch) | |
tree | 5a75704cec89a5981e1586c0114e0d5104ea32c0 /src | |
parent | 8a5d92726a0b52b70e881c595a2a8e1000d9de68 (diff) |
Core/AHBot: Adjust AHBot bid and buyout chances
Apply an exponential formula to define the chance to bid/buyout an auction depending on auction price and item price ratio. The formula can be adjusted changing the new AuctionHouseBot.Buyer.ChanceFactor config parameter
Chance = 100 ^ (1 + (1 - (auction_price / item_price) / k)
k is the config parameter AuctionHouseBot.Buyer.ChanceFactor, the higher the number the higher chance to buy overpriced auctions.
(cherry picked from commit 177b6319d1ad49a38fbd06f37671da1e3d1ae4e6)
Conflicts:
src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp
Diffstat (limited to 'src')
4 files changed, 38 insertions, 18 deletions
diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp index fd78e933960..5f791becf41 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp +++ b/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp @@ -97,6 +97,11 @@ void AuctionBotConfig::SetConfig(AuctionBotConfigBoolValues index, char const* f SetConfig(index, sConfigMgr->GetBoolDefault(fieldname, defvalue)); } +void AuctionBotConfig::SetConfig(AuctionBotConfigFloatValues index, char const* fieldname, float defvalue) +{ + SetConfig(index, sConfigMgr->GetFloatDefault(fieldname, defvalue)); +} + //Get AuctionHousebot configuration file void AuctionBotConfig::GetConfigFromFile() { @@ -111,6 +116,8 @@ void AuctionBotConfig::GetConfigFromFile() SetConfig(CONFIG_AHBOT_BUYER_HORDE_ENABLED, "AuctionHouseBot.Buyer.Horde.Enabled", false); SetConfig(CONFIG_AHBOT_BUYER_NEUTRAL_ENABLED, "AuctionHouseBot.Buyer.Neutral.Enabled", false); + SetConfig(CONFIG_AHBOT_BUYER_CHANCE_FACTOR, "AuctionHouseBot.Buyer.ChanceFactor", 2.0f); + SetConfig(CONFIG_AHBOT_ITEMS_VENDOR, "AuctionHouseBot.Items.Vendor", false); SetConfig(CONFIG_AHBOT_ITEMS_LOOT, "AuctionHouseBot.Items.Loot", true); SetConfig(CONFIG_AHBOT_ITEMS_MISC, "AuctionHouseBot.Items.Misc", false); diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBot.h b/src/server/game/AuctionHouseBot/AuctionHouseBot.h index d7570c37d44..225d3b7ee25 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBot.h +++ b/src/server/game/AuctionHouseBot/AuctionHouseBot.h @@ -174,6 +174,12 @@ enum AuctionBotConfigBoolValues CONFIG_UINT32_AHBOT_BOOL_COUNT }; +enum AuctionBotConfigFloatValues +{ + CONFIG_AHBOT_BUYER_CHANCE_FACTOR, + CONFIG_AHBOT_FLOAT_COUNT +}; + // All basic config data used by other AHBot classes for self-configure. class AuctionBotConfig { @@ -196,8 +202,10 @@ public: uint32 GetConfig(AuctionBotConfigUInt32Values index) const { return _configUint32Values[index]; } bool GetConfig(AuctionBotConfigBoolValues index) const { return _configBoolValues[index]; } + float GetConfig(AuctionBotConfigFloatValues index) const { return _configFloatValues[index]; } void SetConfig(AuctionBotConfigBoolValues index, bool value) { _configBoolValues[index] = value; } void SetConfig(AuctionBotConfigUInt32Values index, uint32 value) { _configUint32Values[index] = value; } + void SetConfig(AuctionBotConfigFloatValues index, float value) { _configFloatValues[index] = value; } uint32 GetConfigItemAmountRatio(AuctionHouseType houseType) const; bool GetConfigBuyerEnabled(AuctionHouseType houseType) const; @@ -217,6 +225,7 @@ private: uint32 _configUint32Values[CONFIG_UINT32_AHBOT_UINT32_COUNT]; bool _configBoolValues[CONFIG_UINT32_AHBOT_BOOL_COUNT]; + float _configFloatValues[CONFIG_AHBOT_FLOAT_COUNT]; void SetAHBotIncludes(const std::string& AHBotIncludes) { _AHBotIncludes = AHBotIncludes; } void SetAHBotExcludes(const std::string& AHBotExcludes) { _AHBotExcludes = AHBotExcludes; } @@ -225,6 +234,7 @@ private: void SetConfigMax(AuctionBotConfigUInt32Values index, char const* fieldname, uint32 defvalue, uint32 maxvalue); void SetConfigMinMax(AuctionBotConfigUInt32Values index, char const* fieldname, uint32 defvalue, uint32 minvalue, uint32 maxvalue); void SetConfig(AuctionBotConfigBoolValues index, char const* fieldname, bool defvalue); + void SetConfig(AuctionBotConfigFloatValues index, char const* fieldname, float defvalue); void GetConfigFromFile(); }; diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp index 993494c8b80..06ca0b02640 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp +++ b/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp @@ -157,18 +157,18 @@ bool AuctionBotBuyer::RollBuyChance(const BuyerItemInfo* ahInfo, const Item* ite if (!auction->buyout) return false; - uint32 itemBuyPrice = auction->buyout / item->GetCount(); - uint32 itemPrice = item->GetTemplate()->GetSellPrice() ? item->GetTemplate()->GetSellPrice() : GetVendorPrice(item->GetTemplate()->GetQuality()); + float itemBuyPrice = float(auction->buyout / item->GetCount()); + float itemPrice = float(item->GetTemplate()->GetSellPrice() ? item->GetTemplate()->GetSellPrice() : GetVendorPrice(item->GetTemplate()->GetQuality())); // The AH cut needs to be added to the price, but we dont want a 100% chance to buy if the price is exactly AH default itemPrice *= 1.4f; // This value is between 0 and 100 and is used directly as the chance to buy or bid // Value equal or above 100 means 100% chance and value below 0 means 0% chance - float chance = 100 / sqrt(itemBuyPrice / float(itemPrice)); + float chance = std::min(100.f, std::pow(100.f, 1.f + (1.f - itemBuyPrice / itemPrice) / sAuctionBotConfig->GetConfig(CONFIG_AHBOT_BUYER_CHANCE_FACTOR))); // If a player has bidded on item, have fifth of normal chance if (auction->bidder) - chance = chance / 5; + chance = chance / 5.f; if (ahInfo) { @@ -178,31 +178,29 @@ bool AuctionBotBuyer::RollBuyChance(const BuyerItemInfo* ahInfo, const Item* ite // If there are more than 5 items on AH of this entry, try weigh in the average buyout price if (ahInfo->BuyItemCount > 5) - { - chance *= 1 / sqrt(itemBuyPrice / avgBuyPrice); - } + chance *= 1.f / std::sqrt(itemBuyPrice / avgBuyPrice); } // Add config weigh in for quality chance *= GetChanceMultiplier(item->GetTemplate()->GetQuality()) / 100.0f; - float rand = frand(0, 100); + float rand = frand(0.f, 100.f); bool win = rand <= chance; - TC_LOG_DEBUG("ahbot", "AHBot: %s BUY! chance = %.2f, price = %u, buyprice = %u.", win ? "WIN" : "LOSE", chance, itemPrice, itemBuyPrice); + TC_LOG_DEBUG("ahbot", "AHBot: %s BUY! chance = %.2f, price = %u, buyprice = %u.", win ? "WIN" : "LOSE", chance, uint32(itemPrice), uint32(itemBuyPrice)); return win; } // ahInfo can be NULL bool AuctionBotBuyer::RollBidChance(const BuyerItemInfo* ahInfo, const Item* item, const AuctionEntry* auction, uint32 bidPrice) { - uint32 itemBidPrice = bidPrice / item->GetCount(); - uint32 itemPrice = item->GetTemplate()->GetSellPrice() ? item->GetTemplate()->GetSellPrice() : GetVendorPrice(item->GetTemplate()->GetQuality()); + float itemBidPrice = float(bidPrice / item->GetCount()); + float itemPrice = float(item->GetTemplate()->GetSellPrice() ? item->GetTemplate()->GetSellPrice() : GetVendorPrice(item->GetTemplate()->GetQuality())); // The AH cut needs to be added to the price, but we dont want a 100% chance to buy if the price is exactly AH default itemPrice *= 1.4f; // This value is between 0 and 100 and is used directly as the chance to buy or bid // Value equal or above 100 means 100% chance and value below 0 means 0% chance - float chance = 100 / sqrt(itemBidPrice / float(itemPrice)); + float chance = std::min(100.f, std::pow(100.f, 1.f + (1.f - itemBidPrice / itemPrice) / sAuctionBotConfig->GetConfig(CONFIG_AHBOT_BUYER_CHANCE_FACTOR))); if (ahInfo) { @@ -212,21 +210,19 @@ bool AuctionBotBuyer::RollBidChance(const BuyerItemInfo* ahInfo, const Item* ite // If there are more than 5 items on AH of this entry, try weigh in the average bid price if (ahInfo->BidItemCount >= 5) - { - chance *= 1 / sqrt(itemBidPrice / avgBidPrice); - } + chance *= 1.f / std::sqrt(itemBidPrice / avgBidPrice); } // If a player has bidded on item, have fifth of normal chance if (auction->bidder) - chance = chance / 5; + chance = chance / 5.f; // Add config weigh in for quality chance *= GetChanceMultiplier(item->GetTemplate()->GetQuality()) / 100.0f; - float rand = frand(0, 100); + float rand = frand(0.f, 100.f); bool win = rand <= chance; - TC_LOG_DEBUG("ahbot", "AHBot: %s BID! chance = %.2f, price = %u, bidprice = %u.", win ? "WIN" : "LOSE", chance, itemPrice, itemBidPrice); + TC_LOG_DEBUG("ahbot", "AHBot: %s BID! chance = %.2f, price = %u, bidprice = %u.", win ? "WIN" : "LOSE", chance, uint32(itemPrice), uint32(itemBidPrice)); return win; } diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist index 2465bdd3bdb..bb9c6ae9b0a 100644 --- a/src/server/worldserver/worldserver.conf.dist +++ b/src/server/worldserver/worldserver.conf.dist @@ -3153,6 +3153,13 @@ AuctionHouseBot.Buyer.Alliance.Enabled = 0 AuctionHouseBot.Buyer.Horde.Enabled = 0 AuctionHouseBot.Buyer.Neutral.Enabled = 0 +# AuctionHouseBot.Buyer.ChanceFactor +# Description: k value in the formula used for the chance to buy an item "100^(1 + (1 - (AuctionBid / ItemPrice)) / k)" +# It must be a decimal number in the range of (0, +infinity). The higher the number the higher chance to buy overpriced auctions +# Default: 2 + +AuctionHouseBot.Buyer.ChanceFactor = 2 + # # AuctionHouseBot.Buyer.Baseprice.QUALITY # Description: Base sellprices in copper for non priced items for each quality. |