From 21a6628161d5367c5d18f090d31cad54c8417fe1 Mon Sep 17 00:00:00 2001 From: antony Date: Thu, 25 Jul 2024 13:31:08 +0200 Subject: [PATCH] French + locale dbc use fix --- src/PlayerbotMgr.cpp | 6 +- src/PlayerbotTextMgr.cpp | 2 + src/strategy/actions/SayAction.cpp | 15 ++- .../actions/SuggestWhatToDoAction.cpp | 119 ++++++++++++++---- src/strategy/actions/SuggestWhatToDoAction.h | 2 + 5 files changed, 110 insertions(+), 34 deletions(-) diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index f236d769..c72e7a7b 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -544,13 +544,13 @@ void PlayerbotHolder::OnBotLogin(Player* const bot) Channel* new_channel = nullptr; if (isLfg) { - std::string lfgChannelName = channel->pattern[0]; - new_channel = cMgr->GetJoinChannel("LookingForGroup", channel->ChannelID); + std::string lfgChannelName = channel->pattern[sWorld->GetDefaultDbcLocale()]; + new_channel = cMgr->GetJoinChannel(lfgChannelName, channel->ChannelID); } else { char new_channel_name_buf[100]; - snprintf(new_channel_name_buf, 100, channel->pattern[0], current_zone_name.c_str()); + snprintf(new_channel_name_buf, 100, channel->pattern[sWorld->GetDefaultDbcLocale()], current_zone_name.c_str()); new_channel = cMgr->GetJoinChannel(new_channel_name_buf, channel->ChannelID); } if (new_channel && new_channel->GetName().length() > 0) diff --git a/src/PlayerbotTextMgr.cpp b/src/PlayerbotTextMgr.cpp index acfaada8..64261314 100644 --- a/src/PlayerbotTextMgr.cpp +++ b/src/PlayerbotTextMgr.cpp @@ -191,6 +191,8 @@ uint32 PlayerbotTextMgr::GetLocalePriority() if (botTextLocalePriority[i] > topLocale) topLocale = i; } + + LOG_INFO("playerbots", "GetLocalePriority: {}", topLocale); return topLocale; } diff --git a/src/strategy/actions/SayAction.cpp b/src/strategy/actions/SayAction.cpp index 02f03499..4b68a323 100644 --- a/src/strategy/actions/SayAction.cpp +++ b/src/strategy/actions/SayAction.cpp @@ -105,6 +105,9 @@ bool SayAction::isUseful() if (!botAI->AllowActivity()) return false; + if (botAI->HasStrategy("silent", BotState::BOT_STATE_NON_COMBAT)) + return false; + time_t lastSaid = AI_VALUE2(time_t, "last said", qualifier); return (time(nullptr) - lastSaid) > 30; } @@ -160,7 +163,8 @@ void ChatReplyAction::ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32 // } // } // - if (word[i] == "hi" || word[i] == "hey" || word[i] == "hello" || word[i] == "wazzup") + if (word[i] == "hi" || word[i] == "hey" || word[i] == "hello" || word[i] == "wazzup" + || word[i] == "salut" || word[i] == "plop" || word[i] == "yo") { replyType = REPLY_HELLO; found = true; @@ -169,22 +173,23 @@ void ChatReplyAction::ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32 if (verb_type < 4) { - if (word[i] == "am" || word[i] == "are" || word[i] == "is") + if (word[i] == "am" || word[i] == "are" || word[i] == "is" || word[i] == "suis" || word[i] == "a" || word[i] == "est" + || word[i] == "dois" || word[i] == "doit") { verb_pos = i; verb_type = 2; // present } - else if (word[i] == "will") + else if (word[i] == "will" || word[i] == "vais" || word[i] == "sera") { verb_pos = i; verb_type = 3; // future } - else if (word[i] == "was" || word[i] == "were") + else if (word[i] == "was" || word[i] == "were" || word[i] == "été" || word[i] == "ai" || word[i] == "eu" || word[i] == "étions" || word[i] == "etion" ) { verb_pos = i; verb_type = 1; // past } - else if (word[i] == "shut" || word[i] == "noob") + else if (word[i] == "shut" || word[i] == "noob" || word[i] == "tg") { if (msg.find(bot->GetName()) == std::string::npos) { diff --git a/src/strategy/actions/SuggestWhatToDoAction.cpp b/src/strategy/actions/SuggestWhatToDoAction.cpp index 3c797193..fa8eada1 100644 --- a/src/strategy/actions/SuggestWhatToDoAction.cpp +++ b/src/strategy/actions/SuggestWhatToDoAction.cpp @@ -11,15 +11,39 @@ #include "Playerbots.h" #include "PlayerbotTextMgr.h" #include "GuildMgr.h" +#include "Config.h" + +enum eTalkType +{ + General = ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG, + Trade = ChannelFlags::CHANNEL_FLAG_CITY | ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG | ChannelFlags::CHANNEL_FLAG_TRADE, + LocalDefence = ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG, + GuildRecruitment = ChannelFlags::CHANNEL_FLAG_CITY | ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG, + LookingForGroup = ChannelFlags::CHANNEL_FLAG_LFG | ChannelFlags::CHANNEL_FLAG_GENERAL +}; std::map SuggestWhatToDoAction::instances; std::map SuggestWhatToDoAction::factions; -SuggestWhatToDoAction::SuggestWhatToDoAction(PlayerbotAI* botAI, std::string const name) : InventoryAction(botAI, name) +SuggestWhatToDoAction::SuggestWhatToDoAction(PlayerbotAI* botAI, std::string const name) + : InventoryAction{ botAI, name } + , _dbc_locale{ sWorld->GetDefaultDbcLocale() } { suggestions.push_back(&SuggestWhatToDoAction::specificQuest); suggestions.push_back(&SuggestWhatToDoAction::grindReputation); suggestions.push_back(&SuggestWhatToDoAction::something); + suggestions.push_back(&SuggestWhatToDoAction::instance); + suggestions.push_back(&SuggestWhatToDoAction::grindMaterials); +} + +bool SuggestWhatToDoAction::isUseful() +{ + if (!sRandomPlayerbotMgr->IsRandomBot(bot) || bot->GetGroup() || bot->GetInstanceId()) + return false; + + std::string qualifier = "suggest what to do"; + time_t lastSaid = AI_VALUE2(time_t, "last said", qualifier); + return (time(0) - lastSaid) > 30; } bool SuggestWhatToDoAction::Execute(Event event) @@ -85,12 +109,12 @@ void SuggestWhatToDoAction::instance() instances["Halls of Reflection"] = 80; } - std::vector allowedInstances; - for (auto & instance : instances) + std::vector allowedInstances; + for (const auto& instance : instances) { - if (bot->GetLevel() >= instance.second) allowedInstances.push_back(instance.first); + if (bot->GetLevel() >= instance.second) + allowedInstances.push_back(instance.first); } - if (allowedInstances.empty()) return; std::map placeholders; @@ -101,7 +125,7 @@ void SuggestWhatToDoAction::instance() itemout << allowedInstances[urand(0, allowedInstances.size() - 1)]; placeholders["%instance"] = itemout.str(); - spam(BOT_TEXT2("suggest_instance", placeholders), urand(0, 1) ? 0x50 : 0, urand(0, 2), urand(0, 2)); + spam(BOT_TEXT2("suggest_instance", placeholders), urand(0, 1) ? eTalkType::LookingForGroup : 0, urand(0, 2), urand(0, 2)); } std::vector SuggestWhatToDoAction::GetIncompletedQuests() @@ -136,7 +160,52 @@ void SuggestWhatToDoAction::specificQuest() placeholders["%role"] = chat->FormatClass(bot, AiFactory::GetPlayerSpecTab(bot)); placeholders["%quest"] = chat->FormatQuest(quest); - spam(BOT_TEXT2("suggest_quest", placeholders), urand(0, 1) ? 0x18 : 0, urand(0, 2), urand(0, 2)); + spam(BOT_TEXT2("suggest_quest", placeholders), urand(0, 1) ? eTalkType::General : 0, urand(0, 2), urand(0, 2)); +} + +void SuggestWhatToDoAction::grindMaterials() +{ + /*if (bot->GetLevel() <= 5) + return; + + auto result = CharacterDatabase.Query("SELECT distinct category, multiplier FROM ahbot_category where category not in ('other', 'quest', 'trade', 'reagent') and multiplier > 3 order by multiplier desc limit 10"); + if (!result) + return; + + std::map categories; + do + { + Field* fields = result->Fetch(); + categories[fields[0].Get()] = fields[1].Get(); + } while (result->NextRow()); + + for (std::map::iterator i = categories.begin(); i != categories.end(); ++i) + { + if (urand(0, 10) < 3) { + std::string name = i->first; + double multiplier = i->second; + + for (int j = 0; j < ahbot::CategoryList::instance.size(); j++) + { + ahbot::Category* category = ahbot::CategoryList::instance[j]; + if (name == category->GetName()) + { + std::string item = category->GetLabel(); + transform(item.begin(), item.end(), item.begin(), ::tolower); + std::ostringstream itemout; + itemout << "|c0000b000" << item << "|r"; + item = itemout.str(); + + std::map placeholders; + placeholders["%role"] = chat->formatClass(bot, AiFactory::GetPlayerSpecTab(bot)); + placeholders["%category"] = item; + + spam(BOT_TEXT2("suggest_trade", placeholders), urand(0, 1) ? 0x3C : 0x18, !urand(0, 2), !urand(0, 3)); + return; + } + } + } + }*/ } void SuggestWhatToDoAction::grindReputation() @@ -179,18 +248,17 @@ void SuggestWhatToDoAction::grindReputation() factions["The Wyrmrest Accord"] = 77; } - std::vector levels; + std::vector levels; levels.push_back("honored"); levels.push_back("revered"); levels.push_back("exalted"); - std::vector allowedFactions; - for (std::map::iterator i = factions.begin(); i != factions.end(); ++i) + std::vector allowedFactions; + for (const auto& i : factions) { - if (bot->GetLevel() >= i->second) - allowedFactions.push_back(i->first); + if (bot->GetLevel() >= i.second) + allowedFactions.push_back(i.first); } - if (allowedFactions.empty()) return; @@ -207,7 +275,7 @@ void SuggestWhatToDoAction::grindReputation() itemout << allowedFactions[urand(0, allowedFactions.size() - 1)]; placeholders["%faction"] = itemout.str(); - spam(BOT_TEXT2("suggest_faction", placeholders), 0x18, true); + spam(BOT_TEXT2("suggest_faction", placeholders), eTalkType::General, true); } void SuggestWhatToDoAction::something() @@ -221,10 +289,10 @@ void SuggestWhatToDoAction::something() std::ostringstream out; // out << "|cffb04040" << entry->area_name[0] << "|r"; - out << entry->area_name[0]; + out << entry->area_name[_dbc_locale]; placeholders["%zone"] = out.str(); - spam(BOT_TEXT2("suggest_something", placeholders), urand(0, 1) ? 0x18 : 0, urand(0, 2), urand(0, 2)); + spam(BOT_TEXT2("suggest_something", placeholders), urand(0, 1) ? eTalkType::General : 0, urand(0, 2), urand(0, 2)); } void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, bool guild) @@ -237,12 +305,13 @@ void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, b if (!cMgr) return; - for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i) { ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(i); if (!channel) continue; + LOG_INFO("playerbots", "Loop on channel: {}", channel->pattern[_dbc_locale]); + for (AreaTableEntry const* current_zone : sAreaTableStore) { if (!current_zone) @@ -254,13 +323,15 @@ void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, b Channel* chn = nullptr; if ((channel->flags & CHANNEL_DBC_FLAG_LFG) != 0) { - std::string chanName = channel->pattern[0]; + std::string chanName = channel->pattern[_dbc_locale]; + LOG_INFO("playerbots", "Trying to chat on channel: {}", chanName); chn = cMgr->GetChannel(chanName, bot); } else { - snprintf(channelName, 100, channel->pattern[0], current_zone->area_name[0]); + snprintf(channelName, 100, channel->pattern[_dbc_locale], current_zone->area_name[_dbc_locale]); chn = cMgr->GetChannel(channelName, bot); + LOG_INFO("playerbots", "Trying to chat on channel: {}", channelName); } if (!chn) continue; @@ -287,8 +358,11 @@ void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, b if (!channelNames.empty()) { std::string randomName = channelNames[urand(0, channelNames.size() - 1)]; + LOG_INFO("playerbots", "Chatting on channel: {}", randomName); if (Channel* chn = cMgr->GetChannel(randomName, bot)) + { chn->Say(bot->GetGUID(), msg.c_str(), LANG_UNIVERSAL); + } } if (worldChat) @@ -403,10 +477,3 @@ bool SuggestTradeAction::Execute(Event event) spam(BOT_TEXT2("suggest_sell", placeholders), urand(0, 1) ? 0x3C : 0, urand(0, 1), urand(0, 5)); return true; } - -bool SuggestWhatToDoAction::isUseful() -{ - std::string const qualifier = "suggest what to do"; - time_t lastSaid = AI_VALUE2(time_t, "last said", qualifier); - return (time(nullptr) - lastSaid) > 30; -} diff --git a/src/strategy/actions/SuggestWhatToDoAction.h b/src/strategy/actions/SuggestWhatToDoAction.h index 4bff50cf..58fafd59 100644 --- a/src/strategy/actions/SuggestWhatToDoAction.h +++ b/src/strategy/actions/SuggestWhatToDoAction.h @@ -23,6 +23,7 @@ class SuggestWhatToDoAction : public InventoryAction void instance(); void specificQuest(); void grindReputation(); + void grindMaterials(); void something(); void spam(std::string msg, uint8 flags = 0, bool worldChat = false, bool guild = false); @@ -31,6 +32,7 @@ class SuggestWhatToDoAction : public InventoryAction private: static std::map instances; static std::map factions; + const int32_t& _dbc_locale; }; class SuggestTradeAction : public SuggestWhatToDoAction