mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
- Added method to get translation bot text or default (#1678)
This commit is contained in:
@@ -101,6 +101,22 @@ std::string PlayerbotTextMgr::GetBotText(std::string name, std::map<std::string,
|
||||
return botText;
|
||||
}
|
||||
|
||||
std::string PlayerbotTextMgr::GetBotTextOrDefault(std::string name, std::string defaultText,
|
||||
std::map<std::string, std::string> placeholders)
|
||||
{
|
||||
std::string botText = GetBotText(name, placeholders);
|
||||
if (botText.empty())
|
||||
{
|
||||
for (std::map<std::string, std::string>::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<std::string, std::string> placeholders)
|
||||
|
||||
@@ -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<std::string, std::string> placeholders);
|
||||
std::string GetBotTextOrDefault(std::string name, std::string defaultText,
|
||||
std::map<std::string, std::string> placeholders);
|
||||
void LoadBotTexts();
|
||||
void LoadBotTextChance();
|
||||
static void replaceAll(std::string& str, const std::string& from, const std::string& to);
|
||||
|
||||
@@ -125,26 +125,15 @@ namespace ai::buff
|
||||
key = "rp_missing_reagent_generic";
|
||||
|
||||
// Placeholders
|
||||
std::map<std::string, std::string> ph;
|
||||
ph["%group_spell"] = groupName;
|
||||
ph["%base_spell"] = baseName;
|
||||
std::map<std::string, std::string> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user