Rewrite bot texts

This commit is contained in:
郑佩茹
2022-09-26 17:20:59 -06:00
parent 660fd2a0c1
commit b2821d7f3a
18 changed files with 1163 additions and 320 deletions

View File

@@ -10,10 +10,57 @@
#include <map>
#include <vector>
#define BOT_TEXT1(name) sPlayerbotTextMgr->GetBotText(name)
#define BOT_TEXT2(name, replace) sPlayerbotTextMgr->GetBotText(name, replace)
struct BotTextEntry
{
BotTextEntry(std::string name, std::map<uint32, std::string> text, uint32 say_type, uint32 reply_type) : m_name(name), m_text(text), m_sayType(say_type), m_replyType(reply_type) {}
std::string m_name;
std::map<uint32, std::string> m_text;
uint32 m_sayType;
uint32 m_replyType;
};
struct ChatReplyData
{
ChatReplyData(uint32 guid, uint32 type, std::string chat) : m_guid(guid), m_type(type), m_chat(chat) {}
uint32 m_type, m_guid = 0;
std::string m_chat = "";
};
struct ChatQueuedReply
{
ChatQueuedReply(uint32 type, uint32 guid1, uint32 guid2, std::string msg, std::string chanName, std::string name, time_t time) : m_type(type), m_guid1(guid1), m_guid2(guid2), m_msg(msg), m_chanName(chanName), m_name(name), m_time(time) {}
uint32 m_type;
uint32 m_guid1;
uint32 m_guid2;
std::string m_msg;
std::string m_chanName;
std::string m_name;
time_t m_time;
};
enum ChatReplyType
{
REPLY_NOT_UNDERSTAND,
REPLY_GRUDGE,
REPLY_VICTIM,
REPLY_ATTACKER,
REPLY_HELLO,
REPLY_NAME,
REPLY_ADMIN_ABUSE
};
class PlayerbotTextMgr
{
public:
PlayerbotTextMgr() { };
PlayerbotTextMgr() {
for (uint8 i = 0; i < MAX_LOCALES; ++i)
{
botTextLocalePriority[i] = 0;
}
};
virtual ~PlayerbotTextMgr() { };
static PlayerbotTextMgr* instance()
{
@@ -21,12 +68,25 @@ class PlayerbotTextMgr
return &instance;
}
std::string const Format(std::string const key, std::map<std::string, std::string> placeholders);
std::string GetBotText(std::string name, std::map<std::string, std::string> placeholders);
std::string GetBotText(std::string name);
std::string GetBotText(ChatReplyType replyType, std::map<std::string, std::string> placeholders);
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);
void LoadBotTexts();
void LoadBotTextChance();
static void replaceAll(std::string& str, const std::string& from, const std::string& to);
bool rollTextChance(std::string text);
uint32 GetLocalePriority();
void AddLocalePriority(uint32 locale);
void ResetLocalePriority();
private:
void LoadTemplates();
std::map<std::string, std::vector<std::string>> templates;
std::map<std::string, std::vector<BotTextEntry>> botTexts;
std::map<std::string, uint32 > botTextChance;
uint32 botTextLocalePriority[MAX_LOCALES];
};
#define sPlayerbotTextMgr PlayerbotTextMgr::instance()