Big update.

This commit is contained in:
UltraNix
2022-03-12 22:27:09 +01:00
parent b3d00ccb26
commit b952636f0d
843 changed files with 1534330 additions and 99 deletions

49
src/PlayerbotTextMgr.cpp Normal file
View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
*/
#include "PlayerbotTextMgr.h"
#include "Playerbots.h"
void replaceAll(std::string& str, std::string const from, std::string const to);
void PlayerbotTextMgr::LoadTemplates()
{
LOG_INFO("playerbots", "Loading playerbots texts...");
uint32 count = 0;
if (PreparedQueryResult result = PlayerbotsDatabase.Query(PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_SEL_TEXT)))
{
do
{
Field* fields = result->Fetch();
std::string const key = fields[0].Get<std::string>();
std::string const text = fields[1].Get<std::string>();
templates[key].push_back(text);
++count;
}
while (result->NextRow());
}
LOG_INFO("playerbots", "{} playerbots texts loaded", count);
}
std::string const PlayerbotTextMgr::Format(std::string const key, std::map<std::string, std::string> placeholders)
{
if (templates.empty())
LoadTemplates();
std::vector<std::string>& list = templates[key];
if (list.empty())
{
std::ostringstream out;
out << "Unknown text: " << key;
return out.str();
}
std::string str = list[urand(0, list.size() - 1)];
for (std::map<std::string, std::string>::iterator i = placeholders.begin(); i != placeholders.end(); ++i)
replaceAll(str, i->first, i->second);
return str;
}