Merge pull request #404 from atidot3/master

General tweak and bug fixes on BotChat
This commit is contained in:
Yunfan Li
2024-07-29 15:19:55 +08:00
committed by GitHub
9 changed files with 55 additions and 49 deletions

View File

@@ -143,6 +143,7 @@ bool PlayerbotAIConfig::Initialize()
randomBotTalk = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotTalk", false); randomBotTalk = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotTalk", false);
randomBotEmote = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotEmote", false); randomBotEmote = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotEmote", false);
randomBotSuggestDungeons = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotSuggestDungeons", true); randomBotSuggestDungeons = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotSuggestDungeons", true);
randomBotGuildTalk = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotGuildTalk", false);
suggestDungeonsInLowerCaseRandomly = sConfigMgr->GetOption<bool>("AiPlayerbot.SuggestDungeonsInLowerCaseRandomly", false); suggestDungeonsInLowerCaseRandomly = sConfigMgr->GetOption<bool>("AiPlayerbot.SuggestDungeonsInLowerCaseRandomly", false);
randomBotJoinBG = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotJoinBG", true); randomBotJoinBG = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotJoinBG", true);
randomBotAutoJoinBG = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotAutoJoinBG", false); randomBotAutoJoinBG = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotAutoJoinBG", false);

View File

@@ -98,6 +98,7 @@ class PlayerbotAIConfig
bool randomBotTalk; bool randomBotTalk;
bool randomBotEmote; bool randomBotEmote;
bool randomBotSuggestDungeons; bool randomBotSuggestDungeons;
bool randomBotGuildTalk;
bool suggestDungeonsInLowerCaseRandomly; bool suggestDungeonsInLowerCaseRandomly;
bool randomBotJoinBG; bool randomBotJoinBG;
bool randomBotAutoJoinBG; bool randomBotAutoJoinBG;

View File

@@ -526,7 +526,7 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
// join standard channels // join standard channels
AreaTableEntry const* current_zone = sAreaTableStore.LookupEntry(bot->GetAreaId()); AreaTableEntry const* current_zone = sAreaTableStore.LookupEntry(bot->GetAreaId());
ChannelMgr* cMgr = ChannelMgr::forTeam(bot->GetTeamId()); ChannelMgr* cMgr = ChannelMgr::forTeam(bot->GetTeamId());
std::string current_zone_name = current_zone ? current_zone->area_name[0] : ""; std::string current_zone_name = current_zone ? current_zone->area_name[sWorld->GetDefaultDbcLocale()] : "";
if (current_zone && cMgr) if (current_zone && cMgr)
{ {

View File

@@ -36,18 +36,19 @@ void AutoLearnSpellAction::LearnSpells(std::ostringstream* out)
if (sPlayerbotAIConfig->autoLearnQuestSpells && sRandomPlayerbotMgr->IsRandomBot(bot))// || (!botAI->GetMaster() && sRandomPlayerbotMgr->IsRandomBot(bot))) if (sPlayerbotAIConfig->autoLearnQuestSpells && sRandomPlayerbotMgr->IsRandomBot(bot))// || (!botAI->GetMaster() && sRandomPlayerbotMgr->IsRandomBot(bot)))
LearnQuestSpells(out); LearnQuestSpells(out);
if (sPlayerbotAIConfig->randomBotTalk) if (sPlayerbotAIConfig->randomBotGuildTalk)
{ {
Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId()); Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId());
if (guild) if (guild)
{ {
std::map<std::string, std::string> placeholders; std::string toSay = "";
placeholders["%level"] = std::to_string(bot->GetLevel());
if (urand(0, 3)) if (urand(0, 3))
guild->BroadcastToGuild(bot->GetSession(), false, BOT_TEXT2("Ding!", placeholders), LANG_UNIVERSAL); toSay = "Ding !";
else else
guild->BroadcastToGuild(bot->GetSession(), false, BOT_TEXT2("Yay level %level!", placeholders), LANG_UNIVERSAL); toSay = "Yay level " + std::to_string(bot->GetLevel()) + " !";
guild->BroadcastToGuild(bot->GetSession(), false, toSay, LANG_UNIVERSAL);
} }
} }
} }

View File

@@ -417,19 +417,20 @@ bool StoreLootAction::Execute(Event event)
if (proto->Quality >= ITEM_QUALITY_RARE && !urand(0, 1) && botAI->HasStrategy("emote", BOT_STATE_NON_COMBAT)) if (proto->Quality >= ITEM_QUALITY_RARE && !urand(0, 1) && botAI->HasStrategy("emote", BOT_STATE_NON_COMBAT))
botAI->PlayEmote(TEXT_EMOTE_CHEER); botAI->PlayEmote(TEXT_EMOTE_CHEER);
if (sPlayerbotAIConfig->randomBotTalk && bot->GetGuildId() && urand(0, 10) && proto->Quality >= ITEM_QUALITY_RARE) if (sPlayerbotAIConfig->randomBotGuildTalk && bot->GetGuildId() && urand(0, 10) && proto->Quality >= ITEM_QUALITY_RARE)
{ {
Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId()); Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId());
if (guild) if (guild)
{ {
std::map<std::string, std::string> placeholders; std::string toSay = "";
placeholders["%name"] = chat->FormatItem(proto);
if (urand(0, 3)) if (urand(0, 3))
guild->BroadcastToGuild(bot->GetSession(), false, BOT_TEXT2("Yay I looted %name!", placeholders), LANG_UNIVERSAL); toSay = "Yay I looted " + chat->FormatItem(proto) + " !";
else else
guild->BroadcastToGuild(bot->GetSession(), false, BOT_TEXT2("Guess who got a %name? Me!", placeholders), LANG_UNIVERSAL); toSay = "Guess who got a " + chat->FormatItem(proto) + " ? Me !";
guild->BroadcastToGuild(bot->GetSession(), false, toSay, LANG_UNIVERSAL);
} }
} }

View File

@@ -674,7 +674,7 @@ void ChatReplyAction::ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32
else if (type == CHAT_MSG_GUILD) else if (type == CHAT_MSG_GUILD)
{ {
if (!bot->GetGuildId()) if (!bot->GetGuildId() || !sPlayerbotAIConfig->randomBotGuildTalk)
return; return;
Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId()); Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId());

View File

@@ -18,11 +18,11 @@
enum eTalkType enum eTalkType
{ {
General = ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG, /*0x18*/ General = ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG,
Trade = ChannelFlags::CHANNEL_FLAG_CITY | ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG | ChannelFlags::CHANNEL_FLAG_TRADE, /*0x3C*/ Trade = ChannelFlags::CHANNEL_FLAG_CITY | ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG | ChannelFlags::CHANNEL_FLAG_TRADE,
LocalDefence = ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG, /*0x18*/ LocalDefence = ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG,
GuildRecruitment = ChannelFlags::CHANNEL_FLAG_CITY | ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG, /*x038*/ GuildRecruitment = ChannelFlags::CHANNEL_FLAG_CITY | ChannelFlags::CHANNEL_FLAG_GENERAL | ChannelFlags::CHANNEL_FLAG_NOT_LFG,
LookingForGroup = ChannelFlags::CHANNEL_FLAG_LFG | ChannelFlags::CHANNEL_FLAG_GENERAL /*0x50*/ LookingForGroup = ChannelFlags::CHANNEL_FLAG_LFG | ChannelFlags::CHANNEL_FLAG_GENERAL
}; };
std::map<std::string, uint8> SuggestDungeonAction::instances; std::map<std::string, uint8> SuggestDungeonAction::instances;
@@ -93,7 +93,7 @@ void SuggestWhatToDoAction::specificQuest()
placeholders["%role"] = chat->FormatClass(bot, AiFactory::GetPlayerSpecTab(bot)); placeholders["%role"] = chat->FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
placeholders["%quest"] = chat->FormatQuest(quest); placeholders["%quest"] = chat->FormatQuest(quest);
spam(BOT_TEXT2("suggest_quest", placeholders), urand(0, 1) ? eTalkType::General : 0, urand(0, 2), urand(0, 2)); spam(BOT_TEXT2("suggest_quest", placeholders), urand(0, 1) ? eTalkType::General : 0, !urand(0, 2), !urand(0, 3));
} }
void SuggestWhatToDoAction::grindMaterials() void SuggestWhatToDoAction::grindMaterials()
@@ -225,7 +225,7 @@ void SuggestWhatToDoAction::something()
out << entry->area_name[_dbc_locale]; out << entry->area_name[_dbc_locale];
placeholders["%zone"] = out.str(); placeholders["%zone"] = out.str();
spam(BOT_TEXT2("suggest_something", placeholders), urand(0, 1) ? eTalkType::General : 0, urand(0, 2), urand(0, 2)); spam(BOT_TEXT2("suggest_something", placeholders), urand(0, 1) ? eTalkType::General : 0, !urand(0, 2), !urand(0, 3));
} }
void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, bool guild) void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, bool guild)
@@ -238,30 +238,32 @@ void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, b
if (!cMgr) if (!cMgr)
return; return;
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) for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
{ {
ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(i); ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(i);
if (!channel) continue; if (!channel) continue;
AreaTableEntry const* current_zone = GetAreaEntryByAreaID(bot->GetAreaId());
if (!current_zone)
continue;
// combine full channel name // combine full channel name
char channelName[100]; char channelName[100];
Channel* chn = nullptr; Channel* chn = nullptr;
if ((channel->flags & CHANNEL_DBC_FLAG_LFG) != 0) if (channel->ChannelID == 24 || (channel->flags & CHANNEL_DBC_FLAG_LFG) != 0)
{ {
std::string chanName = channel->pattern[_dbc_locale]; std::string chanName = channel->pattern[_dbc_locale];
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], zone->area_name[_dbc_locale]);
chn = cMgr->GetChannel(channelName, bot); chn = cMgr->GetChannel(channelName, bot);
} }
if (!chn) if (!chn)
continue; continue;
// skip world chat here // skip world chat here
if (chn->GetName() == "World") if (chn->GetName() == "World")
continue; continue;
@@ -269,8 +271,8 @@ void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, b
if (flags != 0 && chn->GetFlags() != flags) if (flags != 0 && chn->GetFlags() != flags)
continue; continue;
// skip local defense // skip local defense and universal defense
if (chn->GetChannelId() == 22) if (chn->GetChannelId() == 22 || chn->GetChannelId() == 23)
continue; continue;
// no filter, pick several options // no filter, pick several options
@@ -302,13 +304,13 @@ void SuggestWhatToDoAction::spam(std::string msg, uint8 flags, bool worldChat, b
if (Channel* worldChannel = cMgr->GetChannel("World", bot)) if (Channel* worldChannel = cMgr->GetChannel("World", bot))
worldChannel->Say(bot->GetGUID(), msg.c_str(), LANG_UNIVERSAL); worldChannel->Say(bot->GetGUID(), msg.c_str(), LANG_UNIVERSAL);
} }
}
if (guild && bot->GetGuildId()) if (sPlayerbotAIConfig->randomBotGuildTalk && guild && bot->GetGuildId())
{ {
Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId()); Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId());
if (guild) if (guild)
guild->BroadcastToGuild(bot->GetSession(), false, msg.c_str(), LANG_UNIVERSAL); guild->BroadcastToGuild(bot->GetSession(), false, msg.c_str(), LANG_UNIVERSAL);
}
} }
} }
@@ -351,6 +353,8 @@ bool SuggestDungeonAction::Execute(Event event)
{ {
// TODO: use sPlayerbotDungeonSuggestionMgr // TODO: use sPlayerbotDungeonSuggestionMgr
if (!sPlayerbotAIConfig->randomBotSuggestDungeons || bot->GetGroup()) return false;
if (instances.empty()) if (instances.empty())
{ {
instances["Ragefire Chasm"] = 15; instances["Ragefire Chasm"] = 15;
@@ -413,7 +417,7 @@ bool SuggestDungeonAction::Execute(Event event)
itemout << allowedInstances[urand(0, allowedInstances.size() - 1)]; itemout << allowedInstances[urand(0, allowedInstances.size() - 1)];
placeholders["%instance"] = itemout.str(); placeholders["%instance"] = itemout.str();
spam(BOT_TEXT2("suggest_instance", placeholders), urand(0, 1) ? eTalkType::LookingForGroup : 0, urand(0, 2), urand(0, 2)); spam(BOT_TEXT2("suggest_instance", placeholders), urand(0, 1) ? eTalkType::LookingForGroup : 0, !urand(0, 2), !urand(0, 3));
return true; return true;
} }
@@ -423,9 +427,6 @@ SuggestTradeAction::SuggestTradeAction(PlayerbotAI* botAI) : SuggestWhatToDoActi
bool SuggestTradeAction::Execute(Event event) bool SuggestTradeAction::Execute(Event event)
{ {
if (!sRandomPlayerbotMgr->IsRandomBot(bot) || bot->GetGroup() || bot->GetInstanceId())
return false;
uint32 quality = urand(0, 100); uint32 quality = urand(0, 100);
if (quality > 95) if (quality > 95)
quality = ITEM_QUALITY_LEGENDARY; quality = ITEM_QUALITY_LEGENDARY;
@@ -480,6 +481,7 @@ bool SuggestTradeAction::Execute(Event event)
placeholders["%item"] = chat->FormatItem(proto, count); placeholders["%item"] = chat->FormatItem(proto, count);
placeholders["%gold"] = chat->formatMoney(price); placeholders["%gold"] = chat->formatMoney(price);
spam(BOT_TEXT2("suggest_sell", placeholders), urand(0, 1) ? eTalkType::Trade : 0, urand(0, 1), urand(0, 5));
spam(BOT_TEXT2("suggest_sell", placeholders), urand(0, 1) ? eTalkType::Trade : 0, !urand(0, 2), urand(0, 5));
return true; return true;
} }

View File

@@ -33,7 +33,7 @@ bool XpGainAction::Execute(Event event)
p >> groupBonus; // 8 group bonus p >> groupBonus; // 8 group bonus
} }
if (sPlayerbotAIConfig->randomBotTalk && bot->GetGuildId() && urand(0, 10)) if (sPlayerbotAIConfig->randomBotGuildTalk && bot->GetGuildId() && urand(0, 10))
{ {
Creature* creature = botAI->GetCreature(guid); Creature* creature = botAI->GetCreature(guid);
if (creature && (creature->isElite() || creature->isWorldBoss() || creature->GetLevel() > 61 || creature->GetLevel() > bot->GetLevel() + 4)) if (creature && (creature->isElite() || creature->isWorldBoss() || creature->GetLevel() > 61 || creature->GetLevel() > bot->GetLevel() + 4))
@@ -41,13 +41,14 @@ bool XpGainAction::Execute(Event event)
Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId()); Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId());
if (guild) if (guild)
{ {
std::map<std::string, std::string> placeholders; std::string toSay = "";
placeholders["%name"] = creature->GetName();
if (urand(0, 3)) if (urand(0, 3))
guild->BroadcastToGuild(bot->GetSession(), false, BOT_TEXT2("Wow I just killed %name!", placeholders), LANG_UNIVERSAL); toSay = "Wow I just killed " + creature->GetName() + " !";
else else
guild->BroadcastToGuild(bot->GetSession(), false, BOT_TEXT2("Awesome that %name went down quickly!", placeholders), LANG_UNIVERSAL); toSay = "Awesome that " + creature->GetName() + " went down quickly !";
guild->BroadcastToGuild(bot->GetSession(), false, toSay, LANG_UNIVERSAL);
} }
} }
} }

View File

@@ -16,14 +16,13 @@ void EmoteStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)
if (sPlayerbotAIConfig->randomBotTalk) if (sPlayerbotAIConfig->randomBotTalk)
{ {
triggers.push_back(new TriggerNode("often", NextAction::array(0, new NextAction("suggest what to do", 1.0f), nullptr))); triggers.push_back(new TriggerNode("often", NextAction::array(0, new NextAction("suggest what to do", 10.0f),
triggers.push_back(new TriggerNode("often", NextAction::array(0, new NextAction("suggest trade", 1.0f), nullptr))); new NextAction("suggest dungeon", 3.0f),
triggers.push_back(new TriggerNode("seldom", NextAction::array(0, new NextAction("talk", 1.0f), nullptr))); new NextAction("suggest trade", 3.0f),
new NextAction("talk", 1.0f),
nullptr)));
} }
if (sPlayerbotAIConfig->randomBotSuggestDungeons)
triggers.push_back(new TriggerNode("often", NextAction::array(0, new NextAction("suggest dungeon", 1.0f), nullptr)));
if (sPlayerbotAIConfig->enableGreet) if (sPlayerbotAIConfig->enableGreet)
triggers.push_back(new TriggerNode("new player nearby", NextAction::array(0, new NextAction("greet", 1.0f), nullptr))); triggers.push_back(new TriggerNode("new player nearby", NextAction::array(0, new NextAction("greet", 1.0f), nullptr)));