[FIX] Folder restructure (#2018)

As requested

Poll
```
1. Yes
2. Yes
3. Maybe, but yes
```

---------

Co-authored-by: Celandriel <22352763+Celandriel@users.noreply.github.com>
This commit is contained in:
bashermens
2026-01-17 10:34:58 +01:00
committed by GitHub
parent 2eb98c3233
commit a1137dbddc
1160 changed files with 233 additions and 232 deletions

View File

@@ -0,0 +1,959 @@
#include "Playerbots.h"
#include "BroadcastHelper.h"
#include "ServerFacade.h"
#include "Channel.h"
#include "AiFactory.h"
BroadcastHelper::BroadcastHelper() {}
uint8 BroadcastHelper::GetLocale()
{
uint8 locale = sWorld->GetDefaultDbcLocale();
// -- In case we're using auto detect on config file^M
if (locale >= MAX_LOCALES)
locale = LocaleConstant::LOCALE_enUS;
return locale;
}
bool BroadcastHelper::BroadcastTest(PlayerbotAI* ai, Player* /* bot */)
{
//return something to ignore the logic
return false;
std::map<std::string, std::string> placeholders;
placeholders["%rand1"] = std::to_string(urand(0, 1));
placeholders["%rand2"] = std::to_string(urand(0, 1));
placeholders["%rand3"] = std::to_string(urand(0, 1));
int32 rand = urand(0, 1);
if (rand == 1 && ai->SayToChannel(BOT_TEXT2("Posted to trade, %rand1, %rand2, %rand3", placeholders), ChatChannelId::TRADE))
return true;
else if (ai->SayToChannel(BOT_TEXT2("Posted to GuildRecruitment, %rand1, %rand2, %rand3", placeholders), ChatChannelId::GUILD_RECRUITMENT))
return true;
return ai->SayToChannel(BOT_TEXT2("Posted to trade, %rand1, %rand2, %rand3", placeholders), ChatChannelId::TRADE);
//int32 rand = urand(1, 8);
if (rand == 1 && ai->SayToGuild(BOT_TEXT2("Posted to guild, %rand1, %rand2, %rand3", placeholders)))
return true;
else if (rand == 2 && ai->SayToWorld(BOT_TEXT2("Posted to world, %rand1, %rand2, %rand3", placeholders)))
return true;
else if (rand == 3 && ai->SayToChannel(BOT_TEXT2("Posted to general, %rand1, %rand2, %rand3", placeholders), ChatChannelId::GENERAL))
return true;
else if (rand == 4 && ai->SayToChannel(BOT_TEXT2("Posted to trade, %rand1, %rand2, %rand3", placeholders), ChatChannelId::TRADE))
return true;
else if (rand == 5 && ai->SayToChannel(BOT_TEXT2("Posted to LFG, %rand1, %rand2, %rand3", placeholders), ChatChannelId::LOOKING_FOR_GROUP))
return true;
else if (rand == 6 && ai->SayToChannel(BOT_TEXT2("Posted to LocalDefense, %rand1, %rand2, %rand3", placeholders), ChatChannelId::LOCAL_DEFENSE))
return true;
else if (rand == 7 && ai->SayToChannel(BOT_TEXT2("Posted to WorldDefense, %rand1, %rand2, %rand3", placeholders), ChatChannelId::WORLD_DEFENSE))
return true;
else if (rand == 8 && ai->SayToChannel(BOT_TEXT2("Posted to GuildRecruitment, %rand1, %rand2, %rand3", placeholders), ChatChannelId::GUILD_RECRUITMENT))
return true;
return false;
}
/**
@param toChannels - map of (ToChannel, chance), where chance is in range 0-100 as uint32 (unless global chance is not 100%)
@return true if said to the channel, false otherwise
*/
bool BroadcastHelper::BroadcastToChannelWithGlobalChance(PlayerbotAI* ai, std::string message, std::list<std::pair<ToChannel, uint32>> toChannels)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (message.empty())
{
return false;
}
for (auto const& pair : toChannels)
{
uint32 roll = urand(1, 100);
uint32 chance = pair.second;
uint32 broadcastRoll = urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue);
switch (pair.first)
{
case TO_GUILD:
{
if (roll <= chance
&& broadcastRoll <= sPlayerbotAIConfig->broadcastToGuildGlobalChance
&& ai->SayToGuild(message))
{
return true;
}
break;
}
case TO_WORLD:
{
if (roll <= chance
&& broadcastRoll <= sPlayerbotAIConfig->broadcastToWorldGlobalChance
&& ai->SayToWorld(message))
{
return true;
}
break;
}
case TO_GENERAL:
{
if (roll <= chance
&& broadcastRoll <= sPlayerbotAIConfig->broadcastToGeneralGlobalChance
&& ai->SayToChannel(message, ChatChannelId::GENERAL))
{
return true;
}
break;
}
case TO_TRADE:
{
if (roll <= chance
&& broadcastRoll <= sPlayerbotAIConfig->broadcastToTradeGlobalChance
&& ai->SayToChannel(message, ChatChannelId::TRADE))
{
return true;
}
break;
}
case TO_LOOKING_FOR_GROUP:
{
if (roll <= chance
&& broadcastRoll <= sPlayerbotAIConfig->broadcastToLFGGlobalChance
&& ai->SayToChannel(message, ChatChannelId::LOOKING_FOR_GROUP))
{
return true;
}
break;
}
case TO_LOCAL_DEFENSE:
{
if (roll <= chance
&& broadcastRoll <= sPlayerbotAIConfig->broadcastToLocalDefenseGlobalChance
&& ai->SayToChannel(message, ChatChannelId::LOCAL_DEFENSE))
{
return true;
}
break;
}
case TO_WORLD_DEFENSE:
{
if (roll <= chance
&& broadcastRoll <= sPlayerbotAIConfig->broadcastToWorldDefenseGlobalChance
&& ai->SayToChannel(message, ChatChannelId::WORLD_DEFENSE))
{
return true;
}
break;
}
case TO_GUILD_RECRUITMENT:
{
if (roll <= chance
&& broadcastRoll <= sPlayerbotAIConfig->broadcastToGuildRecruitmentGlobalChance
&& ai->SayToChannel(message, ChatChannelId::GUILD_RECRUITMENT))
{
return true;
}
break;
}
default:
break;
}
}
return false;
}
bool BroadcastHelper::BroadcastLootingItem(PlayerbotAI* ai, Player* bot, ItemTemplate const* proto)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
std::map<std::string, std::string> placeholders;
placeholders["%item_link"] = ai->GetChatHelper()->FormatItem(proto);
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
switch (proto->Quality)
{
case ITEM_QUALITY_POOR:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceLootingItemPoor)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_looting_item_poor", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case ITEM_QUALITY_NORMAL:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceLootingItemNormal)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_looting_item_normal", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case ITEM_QUALITY_UNCOMMON:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceLootingItemUncommon)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_looting_item_uncommon", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case ITEM_QUALITY_RARE:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceLootingItemRare)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_looting_item_rare", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case ITEM_QUALITY_EPIC:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceLootingItemEpic)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_looting_item_epic", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case ITEM_QUALITY_LEGENDARY:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceLootingItemLegendary)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_looting_item_legendary", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case ITEM_QUALITY_ARTIFACT:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceLootingItemArtifact)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_looting_item_artifact", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
default:
break;
}
return false;
}
bool BroadcastHelper::BroadcastQuestAccepted(PlayerbotAI* ai, Player* bot, const Quest* quest)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceQuestAccepted)
{
std::map<std::string, std::string> placeholders;
placeholders["%quest_link"] = ai->GetChatHelper()->FormatQuest(quest);
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_quest_accepted_generic", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastQuestUpdateAddKill(PlayerbotAI* ai, Player* bot, Quest const* quest, uint32 availableCount, uint32 requiredCount, std::string obectiveName)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
std::map<std::string, std::string> placeholders;
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%quest_link"] = ai->GetChatHelper()->FormatQuest(quest);
placeholders["%quest_obj_name"] = obectiveName;
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
placeholders["%quest_obj_available"] = std::to_string(availableCount);
placeholders["%quest_obj_required"] = std::to_string(requiredCount);
placeholders["%quest_obj_missing"] = std::to_string(requiredCount - std::min(availableCount, requiredCount));
placeholders["%quest_obj_full_formatted"] = ai->GetChatHelper()->FormatQuestObjective(obectiveName, availableCount, requiredCount);
if (availableCount < requiredCount
&& urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceQuestUpdateObjectiveProgress)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_quest_update_add_kill_objective_progress", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
else if (availableCount == requiredCount
&& urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceQuestUpdateObjectiveCompleted)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_quest_update_add_kill_objective_completed", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastQuestUpdateAddItem(PlayerbotAI* ai, Player* bot, Quest const* quest, uint32 availableCount, uint32 requiredCount, const ItemTemplate* proto)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
std::map<std::string, std::string> placeholders;
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%quest_link"] = ai->GetChatHelper()->FormatQuest(quest);
std::string itemLinkFormatted = ai->GetChatHelper()->FormatItem(proto);
placeholders["%item_link"] = itemLinkFormatted;
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
placeholders["%quest_obj_available"] = std::to_string(availableCount);
placeholders["%quest_obj_required"] = std::to_string(requiredCount);
placeholders["%quest_obj_missing"] = std::to_string(requiredCount - std::min(availableCount, requiredCount));
placeholders["%quest_obj_full_formatted"] = ai->GetChatHelper()->FormatQuestObjective(itemLinkFormatted, availableCount, requiredCount);
if (availableCount < requiredCount
&& urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceQuestUpdateObjectiveProgress)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_quest_update_add_item_objective_progress", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
else if (availableCount == requiredCount
&& urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceQuestUpdateObjectiveCompleted)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_quest_update_add_item_objective_completed", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastQuestUpdateFailedTimer(PlayerbotAI* ai, Player* bot, Quest const* quest)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceQuestUpdateFailedTimer)
{
std::map<std::string, std::string> placeholders;
placeholders["%quest_link"] = ai->GetChatHelper()->FormatQuest(quest);
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_quest_update_failed_timer", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastQuestUpdateComplete(PlayerbotAI* ai, Player* bot, Quest const* quest)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceQuestUpdateComplete)
{
std::map<std::string, std::string> placeholders;
placeholders["%quest_link"] = ai->GetChatHelper()->FormatQuest(quest);
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_quest_update_complete", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastQuestTurnedIn(PlayerbotAI* ai, Player* bot, Quest const* quest)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceQuestTurnedIn)
{
std::map<std::string, std::string> placeholders;
placeholders["%quest_link"] = ai->GetChatHelper()->FormatQuest(quest);
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_quest_turned_in", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastKill(PlayerbotAI* ai, Player* bot, Creature *creature)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
std::map<std::string, std::string> placeholders;
placeholders["%victim_name"] = creature->GetName();
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%victim_level"] = creature->GetLevel();
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
//if ((creature->IsElite() && !creature->GetMap()->IsDungeon())
//if creature->IsWorldBoss()
//if creature->GetLevel() > DEFAULT_MAX_LEVEL + 1
//if creature->GetLevel() > bot->GetLevel() + 4
if (creature->IsPet())
{
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceKillPet)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_killed_pet", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
}
else if (creature->IsPlayer())
{
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceKillPlayer)
{
placeholders["%victim_class"] = ai->GetChatHelper()->FormatClass(creature->getClass());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_killed_player", placeholders),
{ {TO_WORLD_DEFENSE, 50}, {TO_LOCAL_DEFENSE, 50}, {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
}
else
{
switch (creature->GetCreatureTemplate()->rank)
{
case CREATURE_ELITE_NORMAL:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceKillNormal)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_killed_normal", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case CREATURE_ELITE_ELITE:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceKillElite)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_killed_elite", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case CREATURE_ELITE_RAREELITE:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceKillRareelite)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_killed_rareelite", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case CREATURE_ELITE_WORLDBOSS:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceKillWorldboss)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_killed_worldboss", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case CREATURE_ELITE_RARE:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceKillRare)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_killed_rare", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
case CREATURE_UNKNOWN:
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceKillUnknown)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_killed_unknown", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
break;
default:
break;
}
}
return false;
}
bool BroadcastHelper::BroadcastLevelup(PlayerbotAI* ai, Player* bot)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
uint32 level = bot->GetLevel();
std::map<std::string, std::string> placeholders;
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(level);
if (level == sPlayerbotAIConfig->randomBotMaxLevel
&& urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceLevelupMaxLevel)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_levelup_max_level", placeholders),
{ {TO_GUILD, 30}, {TO_WORLD, 90}, {TO_GENERAL, 100} }
);
}
// It's divisible by 10
else if (level % 10 == 0
&& urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceLevelupTenX)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_levelup_10x", placeholders),
{ {TO_GUILD, 50}, {TO_WORLD, 90}, {TO_GENERAL, 100} }
);
}
else if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceLevelupGeneric)
{
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_levelup_generic", placeholders),
{ {TO_GUILD, 90}, {TO_WORLD, 90}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastGuildMemberPromotion(PlayerbotAI* ai, Player* /* bot */, Player* player)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceGuildManagement)
{
std::map<std::string, std::string> placeholders;
placeholders["%other_name"] = player->GetName();
placeholders["%other_class"] = ai->GetChatHelper()->FormatClass(player->getClass());
placeholders["%other_race"] = ai->GetChatHelper()->FormatRace(player->getRace());
placeholders["%other_level"] = std::to_string(player->GetLevel());
return ai->SayToGuild(BOT_TEXT2("broadcast_guild_promotion", placeholders));
}
return false;
}
bool BroadcastHelper::BroadcastGuildMemberDemotion(PlayerbotAI* ai, Player* /* bot */, Player* player)
{
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceGuildManagement)
{
std::map<std::string, std::string> placeholders;
placeholders["%other_name"] = player->GetName();
placeholders["%other_class"] = ai->GetChatHelper()->FormatClass(player->getClass());
placeholders["%other_race"] = ai->GetChatHelper()->FormatRace(player->getRace());
placeholders["%other_level"] = std::to_string(player->GetLevel());
return ai->SayToGuild(BOT_TEXT2("broadcast_guild_demotion", placeholders));
}
return false;
}
bool BroadcastHelper::BroadcastGuildGroupOrRaidInvite(PlayerbotAI* ai, Player* /* bot */, Player* player, Group* group)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
std::map<std::string, std::string> placeholders;
placeholders["%name"] = player->GetName();
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
//TODO move texts to sql!
if (group && group->isRaidGroup())
{
if (urand(0, 3))
{
return ai->SayToGuild(BOT_TEXT2("Hey anyone want to raid in %zone_name", placeholders));
}
else
{
return ai->SayToGuild(BOT_TEXT2("Hey %name I'm raiding in %zone_name do you wan to join me?", placeholders));
}
}
else
{
//(bot->GetTeam() == ALLIANCE ? LANG_COMMON : LANG_ORCISH)
if (urand(0, 3))
{
return ai->SayToGuild(BOT_TEXT2("Hey anyone wanna group up in %zone_name?", placeholders));
}
else
{
return ai->SayToGuild(BOT_TEXT2("Hey %name do you want join my group? I'm heading for %zone_name", placeholders));
}
}
return false;
}
bool BroadcastHelper::BroadcastSuggestInstance(PlayerbotAI* ai, std::vector<std::string>& allowedInstances, Player* bot)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceSuggestInstance)
{
std::map<std::string, std::string> placeholders;
placeholders["%my_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_name"] = itemout.str();
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("suggest_instance", placeholders),
{ {TO_LOOKING_FOR_GROUP, 50}, {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastSuggestQuest(PlayerbotAI* ai, std::vector<uint32>& quests, Player* bot)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceSuggestQuest)
{
int index = rand() % quests.size();
Quest const* quest = sObjectMgr->GetQuestTemplate(quests[index]);
std::map<std::string, std::string> placeholders;
placeholders["%my_role"] = ChatHelper::FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
placeholders["%quest_link"] = ai->GetChatHelper()->FormatQuest(quest);
placeholders["%quest_level"] = std::to_string(quest->GetQuestLevel());
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("suggest_quest", placeholders),
{ {TO_LOOKING_FOR_GROUP, 50}, {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastSuggestGrindMaterials(PlayerbotAI* ai, std::string item, Player* bot)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceSuggestGrindMaterials)
{
std::map<std::string, std::string> placeholders;
placeholders["%my_role"] = ChatHelper::FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
placeholders["%category"] = item;
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("suggest_trade", placeholders),
{ {TO_TRADE, 50}, {TO_LOOKING_FOR_GROUP, 50}, {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastSuggestGrindReputation(PlayerbotAI* ai, std::vector<std::string> levels, std::vector<std::string> allowedFactions, Player* bot)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceSuggestGrindReputation)
{
std::map<std::string, std::string> placeholders;
placeholders["%my_role"] = ChatHelper::FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
placeholders["%rep_level"] = levels[urand(0, 2)];
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();
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("suggest_faction", placeholders),
{ {TO_LOOKING_FOR_GROUP, 50}, {TO_GUILD, 50}, {TO_WORLD, 50}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastSuggestSell(PlayerbotAI* ai, const ItemTemplate* proto, uint32 count, uint32 price, Player* bot)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceSuggestSell)
{
std::map<std::string, std::string> placeholders;
placeholders["%item_link"] = ai->GetChatHelper()->FormatItem(proto, 0);
placeholders["%item_formatted_link"] = ai->GetChatHelper()->FormatItem(proto, count);
placeholders["%item_count"] = std::to_string(count);
placeholders["%cost_gold"] = ai->GetChatHelper()->formatMoney(price);
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("suggest_sell", placeholders),
{ {TO_TRADE, 90}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastSuggestSomething(PlayerbotAI* ai, Player* bot)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceSuggestSomething)
{
std::map<std::string, std::string> placeholders;
placeholders["%my_role"] = ChatHelper::FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("suggest_something", placeholders),
{ {TO_GUILD, 10}, {TO_WORLD, 70}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastSuggestSomethingToxic(PlayerbotAI* ai, Player* bot)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceSuggestSomethingToxic)
{
//items
std::vector<Item*> botItems = ai->GetInventoryAndEquippedItems();
std::map<std::string, std::string> placeholders;
placeholders["%random_inventory_item_link"] = botItems.size() > 0 ? ai->GetChatHelper()->FormatItem(botItems[rand() % botItems.size()]->GetTemplate()) : BOT_TEXT1("string_empty_link");
placeholders["%my_role"] = ChatHelper::FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("suggest_something_toxic", placeholders),
{ {TO_GUILD, 10}, {TO_WORLD, 70}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastSuggestToxicLinks(PlayerbotAI* ai, Player* bot)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceSuggestToxicLinks)
{
//quests
std::vector<uint32> incompleteQuests;
for (uint16 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
{
uint32 questId = bot->GetQuestSlotQuestId(slot);
if (!questId)
continue;
QuestStatus status = bot->GetQuestStatus(questId);
if (status == QUEST_STATUS_INCOMPLETE || status == QUEST_STATUS_NONE)
incompleteQuests.push_back(questId);
}
//items
std::vector<Item*> botItems = ai->GetInventoryAndEquippedItems();
//spells
//?
std::map<std::string, std::string> placeholders;
placeholders["%random_inventory_item_link"] = botItems.size() > 0 ? ai->GetChatHelper()->FormatItem(botItems[rand() % botItems.size()]->GetTemplate()) : BOT_TEXT1("string_empty_link");
placeholders["%prefix"] = sPlayerbotAIConfig->toxicLinksPrefix;
if (incompleteQuests.size() > 0)
{
Quest const* quest = sObjectMgr->GetQuestTemplate(incompleteQuests[rand() % incompleteQuests.size()]);
placeholders["%random_taken_quest_or_item_link"] = ai->GetChatHelper()->FormatQuest(quest);
}
else
{
placeholders["%random_taken_quest_or_item_link"] = placeholders["%random_inventory_item_link"];
}
placeholders["%my_role"] = ChatHelper::FormatClass(bot, AiFactory::GetPlayerSpecTab(bot));
AreaTableEntry const* current_area = ai->GetCurrentArea();
AreaTableEntry const* current_zone = ai->GetCurrentZone();
placeholders["%area_name"] = current_area ? ai->GetLocalizedAreaName(current_area) : BOT_TEXT1("string_unknown_area");
placeholders["%zone_name"] = current_zone ? ai->GetLocalizedAreaName(current_zone) : BOT_TEXT1("string_unknown_area");
placeholders["%my_class"] = ai->GetChatHelper()->FormatClass(bot->getClass());
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("suggest_toxic_links", placeholders),
{ {TO_GUILD, 10}, {TO_WORLD, 70}, {TO_GENERAL, 100} }
);
}
return false;
}
bool BroadcastHelper::BroadcastSuggestThunderfury(PlayerbotAI* ai, Player* bot)
{
if (urand(1, sPlayerbotAIConfig->broadcastChanceMaxValue) <= sPlayerbotAIConfig->broadcastChanceSuggestThunderfury)
{
std::map<std::string, std::string> placeholders;
ItemTemplate const* thunderfuryProto = sObjectMgr->GetItemTemplate(19019);
placeholders["%thunderfury_link"] = GET_PLAYERBOT_AI(bot)->GetChatHelper()->FormatItem(thunderfuryProto);
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("thunderfury_spam", placeholders),
{ {TO_WORLD, 70}, {TO_GENERAL, 100} }
);
}
return false;
}

148
src/Util/BroadcastHelper.h Normal file
View File

@@ -0,0 +1,148 @@
#pragma once
class PlayerbotAI;
class Player;
class ItemTemplate;
class Quest;
class Creature;
class Group;
class BroadcastHelper
{
public:
BroadcastHelper();
public:
enum ToChannel
{
TO_GUILD = 1,
TO_WORLD = 2,
TO_GENERAL = 3,
TO_TRADE = 4,
TO_LOOKING_FOR_GROUP = 5,
TO_LOCAL_DEFENSE = 6,
TO_WORLD_DEFENSE = 7,
TO_GUILD_RECRUITMENT = 8
};
static uint8_t GetLocale();
static bool BroadcastTest(
PlayerbotAI* ai,
Player* bot
);
static bool BroadcastToChannelWithGlobalChance(
PlayerbotAI* ai,
std::string message,
std::list<std::pair<ToChannel, uint32_t>> toChannels
);
static bool BroadcastLootingItem(
PlayerbotAI* ai,
Player* bot,
const ItemTemplate* proto
);
static bool BroadcastQuestAccepted(
PlayerbotAI* ai,
Player* bot,
const Quest* quest
);
static bool BroadcastQuestUpdateAddKill(
PlayerbotAI* ai,
Player* bot,
Quest const* quest,
uint32_t availableCount,
uint32_t requiredCount,
std::string obectiveName
);
static bool BroadcastQuestUpdateAddItem(
PlayerbotAI* ai,
Player* bot,
Quest const* quest,
uint32_t availableCount,
uint32_t requiredCount,
const ItemTemplate* proto
);
static bool BroadcastQuestUpdateFailedTimer(
PlayerbotAI* ai,
Player* bot,
Quest const* quest
);
static bool BroadcastQuestUpdateComplete(
PlayerbotAI* ai,
Player* bot,
Quest const* quest
);
static bool BroadcastQuestTurnedIn(
PlayerbotAI* ai,
Player* bot,
Quest const* quest
);
static bool BroadcastKill(
PlayerbotAI* ai,
Player* bot,
Creature* creature
);
static bool BroadcastLevelup(
PlayerbotAI* ai,
Player* bot
);
static bool BroadcastGuildMemberPromotion(
PlayerbotAI* ai,
Player* bot,
Player* player
);
static bool BroadcastGuildMemberDemotion(
PlayerbotAI* ai,
Player* bot,
Player* player
);
static bool BroadcastGuildGroupOrRaidInvite(
PlayerbotAI* ai,
Player* bot,
Player* player,
Group* group
);
static bool BroadcastSuggestInstance(
PlayerbotAI* ai,
std::vector<std::string>& allowedInstances,
Player* bot
);
static bool BroadcastSuggestQuest(
PlayerbotAI* ai,
std::vector<uint32>& quests,
Player* bot
);
static bool BroadcastSuggestGrindMaterials(
PlayerbotAI* ai,
std::string item,
Player* bot
);
static bool BroadcastSuggestGrindReputation(
PlayerbotAI* ai,
std::vector<std::string> levels,
std::vector<std::string> allowedFactions,
Player* bot
);
static bool BroadcastSuggestSell(
PlayerbotAI* ai,
const ItemTemplate* proto,
uint32_t count,
uint32_t price,
Player* bot
);
static bool BroadcastSuggestSomething(
PlayerbotAI* ai,
Player* bot
);
static bool BroadcastSuggestSomethingToxic(
PlayerbotAI* ai,
Player* bot
);
static bool BroadcastSuggestToxicLinks(
PlayerbotAI* ai,
Player* bot
);
static bool BroadcastSuggestThunderfury(
PlayerbotAI* ai,
Player* bot
);
};

50
src/Util/Helpers.cpp Normal file
View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#include "Helpers.h"
char* strstri(char const* haystack, char const* needle)
{
if (!*needle)
{
return (char*)haystack;
}
for (; *haystack; ++haystack)
{
if (tolower(*haystack) == tolower(*needle))
{
char const *h = haystack, *n = needle;
for (; *h && *n; ++h, ++n)
{
if (tolower(*h) != tolower(*n))
{
break;
}
}
if (!*n)
{
return (char*)haystack;
}
}
}
return 0;
}
std::string& ltrim(std::string& s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { return !std::isspace(c); }));
return s;
}
std::string& rtrim(std::string& s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), [](int c) { return !std::isspace(c); }).base(), s.end());
return s;
}
std::string& trim(std::string& s) { return ltrim(rtrim(s)); }

55
src/Util/Helpers.h Normal file
View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#ifndef _PLAYERBOT_HELPERS_H
#define _PLAYERBOT_HELPERS_H
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cctype>
#include <functional>
#include <locale>
#include <map>
#include <sstream>
#include <vector>
#include "Common.h"
void split(std::vector<std::string>& dest, std::string const str, char const* delim)
{
char* pTempStr = strdup(str.c_str());
char* pWord = strtok(pTempStr, delim);
while (pWord != nullptr)
{
dest.push_back(pWord);
pWord = strtok(nullptr, delim);
}
free(pTempStr);
}
std::vector<std::string>& split(std::string const s, char delim, std::vector<std::string>& elems)
{
std::stringstream ss(s);
std::string item;
while (getline(ss, item, delim))
{
elems.push_back(item);
}
return elems;
}
std::vector<std::string> split(std::string const s, char delim)
{
std::vector<std::string> elems;
return split(s, delim, elems);
}
#endif

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#ifndef _PLAYERBOT_LAZYCALCULATEDVALUE_H
#define _PLAYERBOT_LAZYCALCULATEDVALUE_H
template <class TValue, class TOwner>
class LazyCalculatedValue
{
public:
typedef TValue (TOwner::*Calculator)();
public:
LazyCalculatedValue(TOwner* owner, Calculator calculator) : calculator(calculator), owner(owner) { Reset(); }
public:
TValue GetValue()
{
if (!calculated)
{
value = (owner->*calculator)();
calculated = true;
}
return value;
}
void Reset() { calculated = false; }
protected:
Calculator calculator;
TOwner* owner;
bool calculated;
TValue value;
};
#endif

View File

@@ -0,0 +1,97 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#include "PlaceholderHelper.h"
#include "AiFactory.h"
#include "PlayerbotTextMgr.h"
#include "Playerbots.h"
#include "Util.h"
void PlaceholderHelper::MapDungeon(PlaceholderMap& placeholders, DungeonSuggestion const* dungeonSuggestion,
Player* bot)
{
std::ostringstream out;
Insertion insertion = {out, dungeonSuggestion};
InsertDungeonName(insertion);
InsertDungeonStrategy(insertion);
InsertDifficulty(insertion, bot);
placeholders["%dungeon"] = out.str();
}
void PlaceholderHelper::MapRole(PlaceholderMap& placeholders, Player* bot)
{
BotRoles const role = AiFactory::GetPlayerRoles(bot);
std::string roleText;
switch (role)
{
case BOT_ROLE_TANK:
roleText = "Tank";
break;
case BOT_ROLE_HEALER:
roleText = "Healer";
break;
case BOT_ROLE_DPS:
roleText = "DPS";
break;
case BOT_ROLE_NONE:
default:
return;
}
bool const hasRole = !roleText.empty();
if (hasRole)
{
placeholders["%role"] = roleText;
}
}
void PlaceholderHelper::InsertDungeonName(Insertion& insertion)
{
std::string name = insertion.dungeonSuggestion->name;
bool const hasAbbrevation = !insertion.dungeonSuggestion->abbrevation.empty();
if (hasAbbrevation)
{
name = insertion.dungeonSuggestion->abbrevation;
}
insertion.out << "|c00b000b0" << name << "|r";
}
void PlaceholderHelper::InsertDungeonStrategy(Insertion& insertion)
{
bool const hasStrategy = !insertion.dungeonSuggestion->strategy.empty();
bool const isRandomlyUsingStrategy = urand(0, 1);
if (hasStrategy && isRandomlyUsingStrategy)
{
std::string strategy = insertion.dungeonSuggestion->strategy;
insertion.out << " " + strategy;
}
}
void PlaceholderHelper::InsertDifficulty(Insertion& insertion, [[maybe_unused]] Player* bot)
{
bool const hasHeroic = insertion.dungeonSuggestion->difficulty == DUNGEON_DIFFICULTY_HEROIC;
std::string difficultyText;
if (hasHeroic)
{
bool const isRandomlyNormal = urand(0, 1);
bool const isRandomlyHeroic = urand(0, 1);
std::vector<std::string> normalAbbrevations = {"Normal", "N"};
std::vector<std::string> heroicAbbrevations = {"Heroic", "HC", "H"};
uint32 const randomAbbrevationIndex = urand(0, 1);
if (isRandomlyNormal)
{
difficultyText = normalAbbrevations[randomAbbrevationIndex];
}
else if (isRandomlyHeroic)
{
difficultyText = heroicAbbrevations[randomAbbrevationIndex];
}
insertion.out << " " << difficultyText;
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#ifndef _PLAYERBOT_PLACEHOLDERHELPER_H
#define _PLAYERBOT_PLACEHOLDERHELPER_H
#include <map>
#include "Common.h"
#include "Player.h"
#include "PlayerbotDungeonRepository.h"
typedef std::map<std::string, std::string> PlaceholderMap;
class PlaceholderHelper
{
public:
static void MapRole(PlaceholderMap& placeholders, Player* bot);
static void MapDungeon(PlaceholderMap& placeholders, DungeonSuggestion const* dungeonSuggestion, Player* bot);
private:
struct Insertion
{
std::ostringstream& out;
DungeonSuggestion const* dungeonSuggestion;
};
static void InsertDungeonName(Insertion& insertion);
static void InsertDungeonStrategy(Insertion& insertion);
static void InsertDifficulty(Insertion& insertion, Player* bot);
};
#endif

79
src/Util/ServerFacade.cpp Normal file
View File

@@ -0,0 +1,79 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#include "ServerFacade.h"
#include "Playerbots.h"
#include "TargetedMovementGenerator.h"
float ServerFacade::GetDistance2d(Unit* unit, WorldObject* wo)
{
ASSERT_NOTNULL(unit);
ASSERT_NOTNULL(wo);
float dist = unit->GetDistance2d(wo);
return std::round(dist * 10.0f) / 10.0f;
}
float ServerFacade::GetDistance2d(Unit* unit, float x, float y)
{
float dist = unit->GetDistance2d(x, y);
return std::round(dist * 10.0f) / 10.0f;
}
bool ServerFacade::IsDistanceLessThan(float dist1, float dist2)
{
// return dist1 - dist2 < sPlayerbotAIConfig->targetPosRecalcDistance;
return dist1 < dist2;
}
bool ServerFacade::IsDistanceGreaterThan(float dist1, float dist2)
{
// return dist1 - dist2 > sPlayerbotAIConfig->targetPosRecalcDistance;
return dist1 > dist2;
}
bool ServerFacade::IsDistanceGreaterOrEqualThan(float dist1, float dist2) { return !IsDistanceLessThan(dist1, dist2); }
bool ServerFacade::IsDistanceLessOrEqualThan(float dist1, float dist2) { return !IsDistanceGreaterThan(dist1, dist2); }
void ServerFacade::SetFacingTo(Player* bot, WorldObject* wo, bool force)
{
if (!bot)
return;
float angle = bot->GetAngle(wo);
// if (!force && bot->isMoving())
// bot->SetFacingTo(bot->GetAngle(wo));
// else
// {
bot->SetOrientation(angle);
if (!bot->IsRooted())
bot->SendMovementFlagUpdate();
// }
}
Unit* ServerFacade::GetChaseTarget(Unit* target)
{
MovementGenerator* movementGen = target->GetMotionMaster()->top();
if (movementGen && movementGen->GetMovementGeneratorType() == CHASE_MOTION_TYPE)
{
if (target->IsPlayer())
{
return static_cast<ChaseMovementGenerator<Player> const*>(movementGen)->GetTarget();
}
else
{
return static_cast<ChaseMovementGenerator<Creature> const*>(movementGen)->GetTarget();
}
}
return nullptr;
}
void ServerFacade::SendPacket(Player *player, WorldPacket *packet)
{
return player->GetSession()->SendPacket(packet);
}

43
src/Util/ServerFacade.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#ifndef _PLAYERBOT_SERVERFACADE_H
#define _PLAYERBOT_SERVERFACADE_H
#include "Common.h"
class Player;
class Unit;
class WorldObject;
class WorldPacket;
class ServerFacade
{
public:
ServerFacade(){};
virtual ~ServerFacade(){};
static ServerFacade* instance()
{
static ServerFacade instance;
return &instance;
}
public:
float GetDistance2d(Unit* unit, WorldObject* wo);
float GetDistance2d(Unit* unit, float x, float y);
bool IsDistanceLessThan(float dist1, float dist2);
bool IsDistanceGreaterThan(float dist1, float dist2);
bool IsDistanceGreaterOrEqualThan(float dist1, float dist2);
bool IsDistanceLessOrEqualThan(float dist1, float dist2);
void SetFacingTo(Player* bot, WorldObject* wo, bool force = false);
Unit* GetChaseTarget(Unit* target);
void SendPacket(Player *player, WorldPacket* packet);
};
#define sServerFacade ServerFacade::instance()
#endif