mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Merge branch 'master' into equip_init
This commit is contained in:
@@ -593,34 +593,41 @@ void ChatHelper::eraseAllSubStr(std::string& mainStr, std::string const toErase)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<uint32> ChatHelper::ExtractAllQuestIds(const std::string& text)
|
std::set<uint32> extractGeneric(std::string_view text, std::string_view prefix)
|
||||||
{
|
{
|
||||||
std::set<uint32> ids;
|
std::set<uint32_t> ids;
|
||||||
|
std::string_view text_view = text;
|
||||||
|
|
||||||
std::regex rgx("Hquest:[0-9]+");
|
size_t pos = 0;
|
||||||
auto begin = std::sregex_iterator(text.begin(), text.end(), rgx);
|
while ((pos = text_view.find(prefix, pos)) != std::string::npos)
|
||||||
auto end = std::sregex_iterator();
|
|
||||||
for (std::sregex_iterator i = begin; i != end; ++i)
|
|
||||||
{
|
{
|
||||||
std::smatch match = *i;
|
// skip "Hquest:/Hitem:"
|
||||||
ids.insert(std::stoi(match.str().erase(0, 7)));
|
pos += prefix.size();
|
||||||
|
|
||||||
|
// extract everything after "Hquest:/Hitem:"
|
||||||
|
size_t end_pos = text_view.find_first_not_of("0123456789", pos);
|
||||||
|
std::string_view number_str = text_view.substr(pos, end_pos - pos);
|
||||||
|
|
||||||
|
uint32 number = 0;
|
||||||
|
|
||||||
|
auto [ptr, ec] = std::from_chars(number_str.data(), number_str.data() + number_str.size(), number);
|
||||||
|
|
||||||
|
if (ec == std::errc())
|
||||||
|
{
|
||||||
|
ids.insert(number);
|
||||||
|
}
|
||||||
|
pos = end_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<uint32> ChatHelper::ExtractAllQuestIds(const std::string& text)
|
||||||
|
{
|
||||||
|
return extractGeneric(text, "Hquest:");
|
||||||
|
}
|
||||||
|
|
||||||
std::set<uint32> ChatHelper::ExtractAllItemIds(const std::string& text)
|
std::set<uint32> ChatHelper::ExtractAllItemIds(const std::string& text)
|
||||||
{
|
{
|
||||||
std::set<uint32> ids;
|
return extractGeneric(text, "Hitem:");
|
||||||
|
|
||||||
std::regex rgx("Hitem:[0-9]+");
|
|
||||||
auto begin = std::sregex_iterator(text.begin(), text.end(), rgx);
|
|
||||||
auto end = std::sregex_iterator();
|
|
||||||
for (std::sregex_iterator i = begin; i != end; ++i)
|
|
||||||
{
|
|
||||||
std::smatch match = *i;
|
|
||||||
ids.insert(std::stoi(match.str().erase(0, 6)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ids;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1003,26 +1003,25 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)
|
|||||||
if (lang == LANG_ADDON)
|
if (lang == LANG_ADDON)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Disable since ExtractAllItemIds bad performance
|
if (message.starts_with(sPlayerbotAIConfig->toxicLinksPrefix) &&
|
||||||
// if (message.starts_with(sPlayerbotAIConfig->toxicLinksPrefix) &&
|
(GetChatHelper()->ExtractAllItemIds(message).size() > 0 ||
|
||||||
// (GetChatHelper()->ExtractAllItemIds(message).size() > 0 ||
|
GetChatHelper()->ExtractAllQuestIds(message).size() > 0) &&
|
||||||
// GetChatHelper()->ExtractAllQuestIds(message).size() > 0) &&
|
sPlayerbotAIConfig->toxicLinksRepliesChance)
|
||||||
// sPlayerbotAIConfig->toxicLinksRepliesChance)
|
{
|
||||||
// {
|
if (urand(0, 50) > 0 || urand(1, 100) > sPlayerbotAIConfig->toxicLinksRepliesChance)
|
||||||
// if (urand(0, 50) > 0 || urand(1, 100) > sPlayerbotAIConfig->toxicLinksRepliesChance)
|
{
|
||||||
// {
|
return;
|
||||||
// return;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
else if ((GetChatHelper()->ExtractAllItemIds(message).count(19019) &&
|
||||||
// else if ((GetChatHelper()->ExtractAllItemIds(message).count(19019) &&
|
sPlayerbotAIConfig->thunderfuryRepliesChance))
|
||||||
// sPlayerbotAIConfig->thunderfuryRepliesChance))
|
{
|
||||||
// {
|
if (urand(0, 60) > 0 || urand(1, 100) > sPlayerbotAIConfig->thunderfuryRepliesChance)
|
||||||
// if (urand(0, 60) > 0 || urand(1, 100) > sPlayerbotAIConfig->thunderfuryRepliesChance)
|
{
|
||||||
// {
|
return;
|
||||||
// return;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
else
|
||||||
// else
|
|
||||||
{
|
{
|
||||||
if (isFromFreeBot && urand(0, 20))
|
if (isFromFreeBot && urand(0, 20))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -205,21 +205,20 @@ void ChatReplyAction::ChatReplyDo(Player* bot, uint32& type, uint32& guid1, uint
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable since ExtractAllItemIds bad performance
|
//toxic links
|
||||||
// //toxic links
|
if (msg.starts_with(sPlayerbotAIConfig->toxicLinksPrefix)
|
||||||
// if (msg.starts_with(sPlayerbotAIConfig->toxicLinksPrefix)
|
&& (GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg).size() > 0 || GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllQuestIds(msg).size() > 0))
|
||||||
// && (GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg).size() > 0 || GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllQuestIds(msg).size() > 0))
|
{
|
||||||
// {
|
HandleToxicLinksReply(bot, chatChannelSource, msg, name);
|
||||||
// HandleToxicLinksReply(bot, chatChannelSource, msg, name);
|
return;
|
||||||
// return;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// //thunderfury
|
//thunderfury
|
||||||
// if (GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg).count(19019))
|
if (GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg).count(19019))
|
||||||
// {
|
{
|
||||||
// HandleThunderfuryReply(bot, chatChannelSource, msg, name);
|
HandleThunderfuryReply(bot, chatChannelSource, msg, name);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
auto messageRepy = GenerateReplyMessage(bot, msg, guid1, name);
|
auto messageRepy = GenerateReplyMessage(bot, msg, guid1, name);
|
||||||
SendGeneralResponse(bot, chatChannelSource, messageRepy, name);
|
SendGeneralResponse(bot, chatChannelSource, messageRepy, name);
|
||||||
@@ -321,8 +320,6 @@ bool ChatReplyAction::HandleToxicLinksReply(Player* bot, ChatChannelSource chatC
|
|||||||
}
|
}
|
||||||
bool ChatReplyAction::HandleWTBItemsReply(Player* bot, ChatChannelSource chatChannelSource, std::string& msg, std::string& name)
|
bool ChatReplyAction::HandleWTBItemsReply(Player* bot, ChatChannelSource chatChannelSource, std::string& msg, std::string& name)
|
||||||
{
|
{
|
||||||
// Disable since ExtractAllItemIds bad performance
|
|
||||||
return false;
|
|
||||||
auto messageItemIds = GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg);
|
auto messageItemIds = GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg);
|
||||||
|
|
||||||
if (messageItemIds.empty())
|
if (messageItemIds.empty())
|
||||||
@@ -418,8 +415,6 @@ bool ChatReplyAction::HandleWTBItemsReply(Player* bot, ChatChannelSource chatCha
|
|||||||
}
|
}
|
||||||
bool ChatReplyAction::HandleLFGQuestsReply(Player* bot, ChatChannelSource chatChannelSource, std::string& msg, std::string& name)
|
bool ChatReplyAction::HandleLFGQuestsReply(Player* bot, ChatChannelSource chatChannelSource, std::string& msg, std::string& name)
|
||||||
{
|
{
|
||||||
// Disable since ExtractAllQuestIds bad performance
|
|
||||||
return false;
|
|
||||||
auto messageQuestIds = GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllQuestIds(msg);
|
auto messageQuestIds = GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllQuestIds(msg);
|
||||||
|
|
||||||
if (messageQuestIds.empty())
|
if (messageQuestIds.empty())
|
||||||
|
|||||||
Reference in New Issue
Block a user