From 7737f9ab724bc3711841929459a63409f1e567b2 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 16 Apr 2025 20:52:14 -0700 Subject: [PATCH] Add additional trading options (#1186) * Add addclass bots to trading list, differentiate between buying and selling. * typos * Try calling playerguid * point IsAddclassBot to IsRandomBot * typo * Fix through IsAddClassbot * Working Version * Minor typos. --- conf/playerbots.conf.dist | 3 ++- src/PlayerbotAIConfig.cpp | 2 +- src/PlayerbotAIConfig.h | 2 +- src/RandomPlayerbotMgr.cpp | 13 +++++++++++++ src/RandomPlayerbotMgr.h | 1 + src/strategy/actions/TradeStatusAction.cpp | 16 ++++++++++++---- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index f8d1b8ec..1b83542c 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -544,7 +544,8 @@ AiPlayerbot.DisableDeathKnightLogin = 0 # Default: 0 AiPlayerbot.LimitTalentsExpansion = 0 -# Allow random bots to trade +# Configure random bots and addClass bot trading (0: Disabled, 1: Enabled, 2: Only buy, 3: Only Sell) +# Default: 1 (Enabled) AiPlayerbot.EnableRandomBotTrading = 1 # # diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index 98a5560d..ab62ba09 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -506,7 +506,7 @@ bool PlayerbotAIConfig::Initialize() limitGearExpansion = sConfigMgr->GetOption("AiPlayerbot.LimitGearExpansion", 1); randombotStartingLevel = sConfigMgr->GetOption("AiPlayerbot.RandombotStartingLevel", 5); enablePeriodicOnlineOffline = sConfigMgr->GetOption("AiPlayerbot.EnablePeriodicOnlineOffline", false); - enableRandomBotTrading = sConfigMgr->GetOption("AiPlayerbot.EnableRandomBotTrading", true); + enableRandomBotTrading = sConfigMgr->GetOption("AiPlayerbot.EnableRandomBotTrading", 1); periodicOnlineOfflineRatio = sConfigMgr->GetOption("AiPlayerbot.PeriodicOnlineOfflineRatio", 2.0); gearscorecheck = sConfigMgr->GetOption("AiPlayerbot.GearScoreCheck", false); randomBotPreQuests = sConfigMgr->GetOption("AiPlayerbot.PreQuests", true); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index 1eca0295..325c174a 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -313,7 +313,7 @@ public: bool autoLearnQuestSpells; bool autoTeleportForLevel; bool randomBotGroupNearby; - bool enableRandomBotTrading; + int32 enableRandomBotTrading; uint32 tweakValue; // Debugging config uint32 randomBotArenaTeamCount; diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index b6947dda..fb2167a4 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -2204,6 +2204,19 @@ bool RandomPlayerbotMgr::IsRandomBot(ObjectGuid::LowType bot) return true; return false; } +bool RandomPlayerbotMgr::IsAddclassBot(Player* bot) +{ + if (bot && GET_PLAYERBOT_AI(bot)) + { + if (GET_PLAYERBOT_AI(bot)->IsRealPlayer()) + return false; + } + if (bot) + { + return IsAddclassBot(bot->GetGUID().GetCounter()); + } + return false; +} bool RandomPlayerbotMgr::IsAddclassBot(ObjectGuid::LowType bot) { diff --git a/src/RandomPlayerbotMgr.h b/src/RandomPlayerbotMgr.h index 56f63b63..bd5b7cd4 100644 --- a/src/RandomPlayerbotMgr.h +++ b/src/RandomPlayerbotMgr.h @@ -112,6 +112,7 @@ public: static bool HandlePlayerbotConsoleCommand(ChatHandler* handler, char const* args); bool IsRandomBot(Player* bot); bool IsRandomBot(ObjectGuid::LowType bot); + bool IsAddclassBot(Player* bot); bool IsAddclassBot(ObjectGuid::LowType bot); void Randomize(Player* bot); void Clear(Player* bot); diff --git a/src/strategy/actions/TradeStatusAction.cpp b/src/strategy/actions/TradeStatusAction.cpp index 4c20b7ce..f401e7eb 100644 --- a/src/strategy/actions/TradeStatusAction.cpp +++ b/src/strategy/actions/TradeStatusAction.cpp @@ -32,7 +32,7 @@ bool TradeStatusAction::Execute(Event event) return false; } - if (!sPlayerbotAIConfig->enableRandomBotTrading && sRandomPlayerbotMgr->IsRandomBot(bot)) + if (sPlayerbotAIConfig->enableRandomBotTrading == 0 && (sRandomPlayerbotMgr->IsRandomBot(bot)|| sRandomPlayerbotMgr->IsAddclassBot(bot))) { bot->Whisper("Trading is disabled", LANG_UNIVERSAL, trader); return false; @@ -171,7 +171,6 @@ bool TradeStatusAction::CheckTrade() break; } } - bool isGettingItem = false; for (uint32 slot = 0; slot < TRADE_SLOT_TRADED_COUNT; ++slot) { @@ -182,7 +181,7 @@ bool TradeStatusAction::CheckTrade() break; } } - + if (isGettingItem) { if (bot->GetGroup() && bot->GetGroup()->IsMember(bot->GetTrader()->GetGUID()) && @@ -215,7 +214,16 @@ bool TradeStatusAction::CheckTrade() int32 botMoney = bot->GetTradeData()->GetMoney() + botItemsMoney; int32 playerItemsMoney = CalculateCost(trader, false); int32 playerMoney = trader->GetTradeData()->GetMoney() + playerItemsMoney; - + if (botItemsMoney > 0 && sPlayerbotAIConfig->enableRandomBotTrading == 2 && (sRandomPlayerbotMgr->IsRandomBot(bot)|| sRandomPlayerbotMgr->IsAddclassBot(bot))) + { + bot->Whisper("Selling is disabled.", LANG_UNIVERSAL, trader); + return false; + } + if (playerItemsMoney && sPlayerbotAIConfig->enableRandomBotTrading == 3 && (sRandomPlayerbotMgr->IsRandomBot(bot)|| sRandomPlayerbotMgr->IsAddclassBot(bot))) + { + bot->Whisper("Buying is disabled.", LANG_UNIVERSAL, trader); + return false; + } for (uint32 slot = 0; slot < TRADE_SLOT_TRADED_COUNT; ++slot) { Item* item = bot->GetTradeData()->GetItem((TradeSlots)slot);