Progress on channels and say yell etc

This commit is contained in:
Atidot3
2024-07-25 23:18:04 +02:00
parent 916a0002e8
commit 50bd63575d
6 changed files with 24 additions and 38 deletions

View File

@@ -264,7 +264,7 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa
if (!player->InBattleground()) if (!player->InBattleground())
{ {
engine->addStrategies("racials", "chat", "default", "cast time", "duel", "boost", nullptr); engine->addStrategies("racials", "chat", "default", "cast time", "duel", "boost", "emote", nullptr);
} }
if (sPlayerbotAIConfig->autoSaveMana) if (sPlayerbotAIConfig->autoSaveMana)
{ {
@@ -548,7 +548,7 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
if (!player->InBattleground()) if (!player->InBattleground())
{ {
nonCombatEngine->addStrategies("nc", "food", "chat", "follow", nonCombatEngine->addStrategies("nc", "food", "chat", "follow",
"default", "quest", "loot", "gather", "duel", "buff", "mount", nullptr); "default", "quest", "loot", "gather", "duel", "buff", "mount", "emote", nullptr);
} }
if (sPlayerbotAIConfig->autoSaveMana) { if (sPlayerbotAIConfig->autoSaveMana) {
nonCombatEngine->addStrategy("auto save mana"); nonCombatEngine->addStrategy("auto save mana");

View File

@@ -28,12 +28,13 @@ void PlayerbotTextMgr::LoadBotTexts()
Field* fields = result->Fetch(); Field* fields = result->Fetch();
std::string name = fields[0].Get<std::string>(); std::string name = fields[0].Get<std::string>();
text[0] = fields[1].Get<std::string>(); text[0] = fields[1].Get<std::string>();
uint32 sayType = fields[2].Get<uint32>(); uint8 sayType = fields[2].Get<uint8>();
uint32 replyType = fields[3].Get<uint32>(); uint8 replyType = fields[3].Get<uint8>();
for (uint8 i = 1; i < MAX_LOCALES; ++i) for (uint8 i = 1; i < MAX_LOCALES; ++i)
{ {
text[i] = fields[i + 3].Get<std::string>(); text[i] = fields[i + 3].Get<std::string>();
} }
botTexts[name].push_back(BotTextEntry(name, text, sayType, replyType)); botTexts[name].push_back(BotTextEntry(name, text, sayType, replyType));
++count; ++count;
} }

View File

@@ -671,9 +671,9 @@ bool EmoteAction::Execute(Event event)
if (pSource && (pSource->GetGUID() != bot->GetGUID()) && ((urand(0, 1) && bot->HasInArc(static_cast<float>(M_PI), pSource, 10.0f)) || if (pSource && (pSource->GetGUID() != bot->GetGUID()) && ((urand(0, 1) && bot->HasInArc(static_cast<float>(M_PI), pSource, 10.0f)) ||
(namlen > 1 && strstri(bot->GetName().c_str(), nam.c_str())))) (namlen > 1 && strstri(bot->GetName().c_str(), nam.c_str()))))
{ {
LOG_INFO("playerbots", "Bot {} {}:{} <{}> received SMSG_TEXT_EMOTE {} from player {} <{}>", /*LOG_INFO("playerbots", "Bot {} {}:{} <{}> received SMSG_TEXT_EMOTE {} from player {} <{}>",
bot->GetGUID().ToString().c_str(), bot->GetTeamId() == TEAM_ALLIANCE ? "A" : "H", bot->GetLevel(), bot->GetGUID().ToString().c_str(), bot->GetTeamId() == TEAM_ALLIANCE ? "A" : "H", bot->GetLevel(),
bot->GetName(), text_emote, pSource->GetGUID().ToString().c_str(), pSource->GetName()); bot->GetName(), text_emote, pSource->GetGUID().ToString().c_str(), pSource->GetName());*/
emote = text_emote; emote = text_emote;
} }
@@ -693,9 +693,9 @@ bool EmoteAction::Execute(Event event)
if ((pSource->GetGUID() != bot->GetGUID()) && (pSource->GetTarget() == bot->GetGUID() || if ((pSource->GetGUID() != bot->GetGUID()) && (pSource->GetTarget() == bot->GetGUID() ||
(urand(0, 1) && bot->HasInArc(static_cast<float>(M_PI), pSource, 10.0f)))) (urand(0, 1) && bot->HasInArc(static_cast<float>(M_PI), pSource, 10.0f))))
{ {
LOG_INFO("playerbots", "Bot {} {}:{} <{}> received SMSG_EMOTE {} from player {} <{}>", /*LOG_INFO("playerbots", "Bot {} {}:{} <{}> received SMSG_EMOTE {} from player {} <{}>",
bot->GetGUID().ToString().c_str(), bot->GetTeamId() == TEAM_ALLIANCE ? "A" : "H", bot->GetLevel(), bot->GetName(), bot->GetGUID().ToString().c_str(), bot->GetTeamId() == TEAM_ALLIANCE ? "A" : "H", bot->GetLevel(), bot->GetName(),
emoteId, pSource->GetGUID().ToString().c_str(), pSource->GetName()); emoteId, pSource->GetGUID().ToString().c_str(), pSource->GetName());*/
std::vector<uint32> types; std::vector<uint32> types;
for (int32 i = sEmotesTextStore.GetNumRows(); i >= 0; --i) for (int32 i = sEmotesTextStore.GetNumRows(); i >= 0; --i)

View File

@@ -124,8 +124,6 @@ bool SayAction::isUseful()
void ChatReplyAction::ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32 guid2, std::string msg, std::string chanName, std::string name) void ChatReplyAction::ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32 guid2, std::string msg, std::string chanName, std::string name)
{ {
LOG_INFO("playerbots", "{} Handle chat reply", bot->GetName());
ChatReplyType replyType = REPLY_NOT_UNDERSTAND; // default not understand ChatReplyType replyType = REPLY_NOT_UNDERSTAND; // default not understand
std::string respondsText = ""; std::string respondsText = "";
@@ -143,7 +141,6 @@ void ChatReplyAction::ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32
std::ostringstream out; std::ostringstream out;
out << "DEBUG ChatReplyDo decided to ignore partial blocklist match" << msg; out << "DEBUG ChatReplyDo decided to ignore partial blocklist match" << msg;
bot->Say(out.str(), LANG_UNIVERSAL); bot->Say(out.str(), LANG_UNIVERSAL);
return; return;
} }
@@ -657,13 +654,10 @@ void ChatReplyAction::ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32
bot->Whisper(c, LANG_ORCISH, plr); bot->Whisper(c, LANG_ORCISH, plr);
} }
} }
else
LOG_ERROR("playerbots", "plr pointer is nullptr chat whisper");
} }
else if (type == CHAT_MSG_SAY) else if (type == CHAT_MSG_SAY)
{ {
LOG_INFO("playerbots", "say respond: {}", respondsText);
if (bot->GetTeamId() == TEAM_ALLIANCE) if (bot->GetTeamId() == TEAM_ALLIANCE)
bot->Say(respondsText, LANG_COMMON); bot->Say(respondsText, LANG_COMMON);
else else
@@ -689,11 +683,6 @@ void ChatReplyAction::ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32
guild->BroadcastToGuild(bot->GetSession(), false, respondsText, LANG_UNIVERSAL); guild->BroadcastToGuild(bot->GetSession(), false, respondsText, LANG_UNIVERSAL);
} }
else
{
LOG_ERROR("playerbots", "Unknown chat type {}", type);
}
} }
GET_PLAYERBOT_AI(bot)->GetAiObjectContext()->GetValue<time_t>("last said", "chat")->Set(time(nullptr) + urand(5, 25)); GET_PLAYERBOT_AI(bot)->GetAiObjectContext()->GetValue<time_t>("last said", "chat")->Set(time(nullptr) + urand(5, 25));
} }

View File

@@ -13,6 +13,8 @@
#include "GuildMgr.h" #include "GuildMgr.h"
#include "Config.h" #include "Config.h"
#include <functional>
enum eTalkType enum eTalkType
{ {
General = ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG, General = ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG,
@@ -29,11 +31,11 @@ SuggestWhatToDoAction::SuggestWhatToDoAction(PlayerbotAI* botAI, std::string con
: InventoryAction{ botAI, name } : InventoryAction{ botAI, name }
, _dbc_locale{ sWorld->GetDefaultDbcLocale() } , _dbc_locale{ sWorld->GetDefaultDbcLocale() }
{ {
suggestions.push_back(&SuggestWhatToDoAction::specificQuest); suggestions.push_back(std::bind(&SuggestWhatToDoAction::specificQuest, this));
suggestions.push_back(&SuggestWhatToDoAction::grindReputation); suggestions.push_back(std::bind(&SuggestWhatToDoAction::grindReputation, this));
suggestions.push_back(&SuggestWhatToDoAction::something); suggestions.push_back(std::bind(&SuggestWhatToDoAction::something, this));
suggestions.push_back(&SuggestWhatToDoAction::instance); suggestions.push_back(std::bind(&SuggestWhatToDoAction::instance, this));
suggestions.push_back(&SuggestWhatToDoAction::grindMaterials); suggestions.push_back(std::bind(&SuggestWhatToDoAction::grindMaterials, this));
} }
bool SuggestWhatToDoAction::isUseful() bool SuggestWhatToDoAction::isUseful()
@@ -48,11 +50,9 @@ bool SuggestWhatToDoAction::isUseful()
bool SuggestWhatToDoAction::Execute(Event event) bool SuggestWhatToDoAction::Execute(Event event)
{ {
if (!sRandomPlayerbotMgr->IsRandomBot(bot) || bot->GetGroup() || bot->GetInstanceId())
return false;
uint32 index = rand() % suggestions.size(); uint32 index = rand() % suggestions.size();
(this->*suggestions[index])(); auto fnct_ptr = suggestions[index];
fnct_ptr();
std::string const qualifier = "suggest what to do"; std::string const qualifier = "suggest what to do";
time_t lastSaid = AI_VALUE2(time_t, "last said", qualifier); time_t lastSaid = AI_VALUE2(time_t, "last said", qualifier);
@@ -310,11 +310,6 @@ void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, b
ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(i); ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(i);
if (!channel) continue; if (!channel) continue;
if (channel->pattern[_dbc_locale])
LOG_INFO("playerbots", "Loop on channel: {}", channel->pattern[_dbc_locale]);
else
LOG_ERROR("playerbots", "channel->pattern[_dbc_locale] is null");
for (AreaTableEntry const* current_zone : sAreaTableStore) for (AreaTableEntry const* current_zone : sAreaTableStore)
{ {
if (!current_zone) if (!current_zone)
@@ -327,14 +322,12 @@ void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, b
if ((channel->flags & CHANNEL_DBC_FLAG_LFG) != 0) if ((channel->flags & CHANNEL_DBC_FLAG_LFG) != 0)
{ {
std::string chanName = channel->pattern[_dbc_locale]; std::string chanName = channel->pattern[_dbc_locale];
LOG_INFO("playerbots", "Trying to chat on channel: {}", chanName);
chn = cMgr->GetChannel(chanName, bot); chn = cMgr->GetChannel(chanName, bot);
} }
else else
{ {
snprintf(channelName, 100, channel->pattern[_dbc_locale], current_zone->area_name[_dbc_locale]); snprintf(channelName, 100, channel->pattern[_dbc_locale], current_zone->area_name[_dbc_locale]);
chn = cMgr->GetChannel(channelName, bot); chn = cMgr->GetChannel(channelName, bot);
LOG_INFO("playerbots", "Trying to chat on channel: {}", channelName);
} }
if (!chn) if (!chn)
continue; continue;
@@ -355,16 +348,19 @@ void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, b
channelNames.push_back(chn->GetName()); channelNames.push_back(chn->GetName());
} }
else else
{
chn->Say(bot->GetGUID(), msg.c_str(), LANG_UNIVERSAL); chn->Say(bot->GetGUID(), msg.c_str(), LANG_UNIVERSAL);
LOG_DEBUG("playerbots", "send grind {} - {}", bot->GetName().c_str(), msg.c_str());
}
} }
if (!channelNames.empty()) if (!channelNames.empty())
{ {
std::string randomName = channelNames[urand(0, channelNames.size() - 1)]; std::string randomName = channelNames[urand(0, channelNames.size() - 1)];
LOG_INFO("playerbots", "Chatting on channel: {}", randomName);
if (Channel* chn = cMgr->GetChannel(randomName, bot)) if (Channel* chn = cMgr->GetChannel(randomName, bot))
{ {
chn->Say(bot->GetGUID(), msg.c_str(), LANG_UNIVERSAL); chn->Say(bot->GetGUID(), msg.c_str(), LANG_UNIVERSAL);
LOG_DEBUG("playerbots", "send grind {} - {}", bot->GetName().c_str(), msg.c_str());
} }
} }

View File

@@ -18,7 +18,7 @@ class SuggestWhatToDoAction : public InventoryAction
bool isUseful() override; bool isUseful() override;
protected: protected:
typedef void (SuggestWhatToDoAction::*Suggestion)(); using Suggestion = std::function<void()>;
std::vector<Suggestion> suggestions; std::vector<Suggestion> suggestions;
void instance(); void instance();
void specificQuest(); void specificQuest();
@@ -32,7 +32,7 @@ class SuggestWhatToDoAction : public InventoryAction
private: private:
static std::map<std::string, uint8> instances; static std::map<std::string, uint8> instances;
static std::map<std::string, uint8> factions; static std::map<std::string, uint8> factions;
const int32_t& _dbc_locale; const int32_t _dbc_locale;
}; };
class SuggestTradeAction : public SuggestWhatToDoAction class SuggestTradeAction : public SuggestWhatToDoAction