Chat refactor quests and generic + suggest

This commit is contained in:
antony
2024-08-01 14:13:00 +02:00
parent 79d0f3fd28
commit 142f2ad212
19 changed files with 1855 additions and 304 deletions

View File

@@ -11,8 +11,8 @@
#include "ChatHelper.h"
#include "Playerbots.h"
#include "PlayerbotTextMgr.h"
#include "GuildMgr.h"
#include "Config.h"
#include "BroadcastHelper.h"
#include <functional>
@@ -36,6 +36,8 @@ SuggestWhatToDoAction::SuggestWhatToDoAction(PlayerbotAI* botAI, std::string con
suggestions.push_back(std::bind(&SuggestWhatToDoAction::grindReputation, this));
suggestions.push_back(std::bind(&SuggestWhatToDoAction::something, this));
suggestions.push_back(std::bind(&SuggestWhatToDoAction::grindMaterials, this));
suggestions.push_back(std::bind(&SuggestWhatToDoAction::somethingToxic, this));
suggestions.push_back(std::bind(&SuggestWhatToDoAction::toxicLinks, this));
}
bool SuggestWhatToDoAction::isUseful()
@@ -85,15 +87,7 @@ void SuggestWhatToDoAction::specificQuest()
if (quests.empty())
return;
uint32 index = rand() % quests.size();
Quest const* quest = sObjectMgr->GetQuestTemplate(quests[index]);
std::map<std::string, std::string> placeholders;
placeholders["%role"] = chat->FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
placeholders["%quest"] = chat->FormatQuest(quest);
spam(BOT_TEXT2("suggest_quest", placeholders), urand(0, 1) ? eTalkType::General : 0, !urand(0, 2), !urand(0, 3));
BroadcastHelper::BroadcastSuggestQuest(botAI, quests, bot);
}
void SuggestWhatToDoAction::grindMaterials()
@@ -187,123 +181,34 @@ void SuggestWhatToDoAction::grindReputation()
levels.push_back("exalted");
std::vector<std::string> allowedFactions;
for (const auto& i : factions)
for (auto it : factions)
{
if (bot->GetLevel() >= i.second)
allowedFactions.push_back(i.first);
if ((int)bot->GetLevel() >= it.second) allowedFactions.push_back(it.first);
}
if (allowedFactions.empty())
return;
std::map<std::string, std::string> placeholders;
placeholders["%role"] = chat->FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
placeholders["%level"] = levels[urand(0, 2)];
if (allowedFactions.empty()) return;
std::ostringstream rnd;
rnd << urand(1, 5) << "K";
placeholders["%rndK"] = rnd.str();
std::ostringstream itemout;
// itemout << "|c004040b0" << allowedFactions[urand(0, allowedFactions.size() - 1)] << "|r";
itemout << allowedFactions[urand(0, allowedFactions.size() - 1)];
placeholders["%faction"] = itemout.str();
spam(BOT_TEXT2("suggest_faction", placeholders), eTalkType::General, true);
BroadcastHelper::BroadcastSuggestGrindReputation(botAI, levels, allowedFactions, bot);
}
void SuggestWhatToDoAction::something()
{
std::map<std::string, std::string> placeholders;
placeholders["%role"] = chat->FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
AreaTableEntry const* zone = sAreaTableStore.LookupEntry(bot->GetMap()->GetZoneId(bot->GetPhaseMask(), bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ()));
if (!zone) return;
std::ostringstream out;
// out << "|cffb04040" << entry->area_name[0] << "|r";
out << zone->area_name[_dbc_locale];
placeholders["%zone"] = out.str();
spam(BOT_TEXT2("suggest_something", placeholders), urand(0, 1) ? eTalkType::General : 0, !urand(0, 2), !urand(0, 3));
BroadcastHelper::BroadcastSuggestSomething(botAI, bot);
}
void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, bool guild)
void SuggestWhatToDoAction::somethingToxic()
{
if (msg.empty())
return;
BroadcastHelper::BroadcastSuggestSomethingToxic(botAI, bot);
}
std::vector<std::string> channelNames;
ChannelMgr* cMgr = ChannelMgr::forTeam(bot->GetTeamId());
if (!cMgr)
return;
void SuggestWhatToDoAction::toxicLinks()
{
BroadcastHelper::BroadcastSuggestToxicLinks(botAI, bot);
}
AreaTableEntry const* zone = sAreaTableStore.LookupEntry(bot->GetMap()->GetZoneId(bot->GetPhaseMask(), bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ()));
if (!zone) return;
/*AreaTableEntry const* area = sAreaTableStore.LookupEntry(bot->GetMap()->GetAreaId(bot->GetPhaseMask(), bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ()));
if (!area) return;*/
for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
{
ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(i);
if (!channel) continue;
// combine full channel name
char channelName[100];
Channel* chn = nullptr;
if (channel->ChannelID == 24 || (channel->flags & CHANNEL_DBC_FLAG_LFG) != 0)
{
std::string chanName = channel->pattern[_dbc_locale];
chn = cMgr->GetChannel(chanName, bot);
}
else
{
snprintf(channelName, 100, channel->pattern[_dbc_locale], zone->area_name[_dbc_locale]);
chn = cMgr->GetChannel(channelName, bot);
}
if (!chn)
continue;
// skip world chat here
if (chn->GetName() == "World")
continue;
if (flags != 0 && chn->GetFlags() != flags)
continue;
// skip local defense and universal defense
if (chn->GetChannelId() == 22 || chn->GetChannelId() == 23)
continue;
// no filter, pick several options
if (flags == CHANNEL_FLAG_NONE)
{
channelNames.push_back(chn->GetName());
}
else
{
chn->Say(bot->GetGUID(), msg.c_str(), LANG_UNIVERSAL);
}
if (!channelNames.empty())
{
std::string randomName = channelNames[urand(0, channelNames.size() - 1)];
if (Channel* chn = cMgr->GetChannel(randomName, bot))
{
chn->Say(bot->GetGUID(), msg.c_str(), LANG_UNIVERSAL);
}
}
if (worldChat)
{
if (Channel* worldChannel = cMgr->GetChannel("World", bot))
worldChannel->Say(bot->GetGUID(), msg.c_str(), LANG_UNIVERSAL);
}
}
if (sPlayerbotAIConfig->randomBotGuildTalk)
{
botAI->SayToGuild(msg);
}
void SuggestWhatToDoAction::thunderfury()
{
BroadcastHelper::BroadcastSuggestThunderfury(botAI, bot);
}
class FindTradeItemsVisitor : public IterateItemsVisitor
@@ -394,22 +299,14 @@ bool SuggestDungeonAction::Execute(Event event)
}
std::vector<std::string> allowedInstances;
for (const auto& instance : instances)
for (auto it : instances)
{
if (bot->GetLevel() >= instance.second)
allowedInstances.push_back(instance.first);
if (bot->GetLevel() >= it.second) allowedInstances.push_back(it.first);
}
if (allowedInstances.empty()) return false;
std::map<std::string, std::string> placeholders;
placeholders["%role"] = ChatHelper::FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
std::ostringstream itemout;
//itemout << "|c00b000b0" << allowedInstances[urand(0, allowedInstances.size() - 1)] << "|r";
itemout << allowedInstances[urand(0, allowedInstances.size() - 1)];
placeholders["%instance"] = itemout.str();
spam(BOT_TEXT2("suggest_instance", placeholders), urand(0, 1) ? eTalkType::LookingForGroup : 0, !urand(0, 2), !urand(0, 3));
BroadcastHelper::BroadcastSuggestInstance(botAI, allowedInstances, bot);
return true;
}
@@ -469,11 +366,6 @@ bool SuggestTradeAction::Execute(Event event)
if (!price)
return false;
std::map<std::string, std::string> placeholders;
placeholders["%item"] = chat->FormatItem(proto, count);
placeholders["%gold"] = chat->formatMoney(price);
spam(BOT_TEXT2("suggest_sell", placeholders), urand(0, 1) ? eTalkType::Trade : 0, !urand(0, 2), urand(0, 5));
BroadcastHelper::BroadcastSuggestSell(botAI, proto, count, price, bot);
return true;
}