From c20fb3447076e98e6c56febbb8e84b458ccca5e7 Mon Sep 17 00:00:00 2001 From: kadeshar Date: Sun, 28 Sep 2025 13:39:59 +0200 Subject: [PATCH] - Added method to get translation bot text or default (#1678) --- src/PlayerbotTextMgr.cpp | 16 ++++++++++++++ src/PlayerbotTextMgr.h | 2 ++ src/strategy/actions/GenericBuffUtils.cpp | 27 +++++++---------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/PlayerbotTextMgr.cpp b/src/PlayerbotTextMgr.cpp index 9a923de9..e758d630 100644 --- a/src/PlayerbotTextMgr.cpp +++ b/src/PlayerbotTextMgr.cpp @@ -101,6 +101,22 @@ std::string PlayerbotTextMgr::GetBotText(std::string name, std::map placeholders) +{ + std::string botText = GetBotText(name, placeholders); + if (botText.empty()) + { + for (std::map::iterator i = placeholders.begin(); i != placeholders.end(); ++i) + { + replaceAll(defaultText, i->first, i->second); + } + return defaultText; + } + + return botText; +} + // chat replies std::string PlayerbotTextMgr::GetBotText(ChatReplyType replyType, std::map placeholders) diff --git a/src/PlayerbotTextMgr.h b/src/PlayerbotTextMgr.h index 5ec3aaa6..05c47ce2 100644 --- a/src/PlayerbotTextMgr.h +++ b/src/PlayerbotTextMgr.h @@ -83,6 +83,8 @@ public: std::string GetBotText(ChatReplyType replyType, std::string name); bool GetBotText(std::string name, std::string& text); bool GetBotText(std::string name, std::string& text, std::map placeholders); + std::string GetBotTextOrDefault(std::string name, std::string defaultText, + std::map placeholders); void LoadBotTexts(); void LoadBotTextChance(); static void replaceAll(std::string& str, const std::string& from, const std::string& to); diff --git a/src/strategy/actions/GenericBuffUtils.cpp b/src/strategy/actions/GenericBuffUtils.cpp index e1dce004..d222667c 100644 --- a/src/strategy/actions/GenericBuffUtils.cpp +++ b/src/strategy/actions/GenericBuffUtils.cpp @@ -125,26 +125,15 @@ namespace ai::buff key = "rp_missing_reagent_generic"; // Placeholders - std::map ph; - ph["%group_spell"] = groupName; - ph["%base_spell"] = baseName; + std::map placeholders; + placeholders["%group_spell"] = groupName; + placeholders["%base_spell"] = baseName; - // Respecte ai_playerbot_texts_chance if present - std::string rp; - bool got = sPlayerbotTextMgr->GetBotText(key, rp, ph); - if (got && !rp.empty()) - { - announce(rp); - last = now; - } - else - { - // Minimal Fallback - std::ostringstream oss; - oss << "Out of components for " << groupName << ". Using " << baseName << "!"; - announce(oss.str()); - last = now; - } + std::string announceText = sPlayerbotTextMgr->GetBotTextOrDefault(key, + "Out of components for %group_spell. Using %base_spell!", placeholders); + + announce(announceText); + last = now; } } }