AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
CreatureTextMgr Class Reference

#include "CreatureTextMgr.h"

Public Member Functions

 ~CreatureTextMgr ()
 
void LoadCreatureTexts ()
 
void LoadCreatureTextLocales ()
 
void LoadCreatureTextOptions ()
 
CreatureTextMap const & GetTextMap () const
 
CreatureTextOptions const * GetTextOptions (uint32 entry, uint8 group) const
 
void SendSound (Creature *source, uint32 sound, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly)
 
void SendEmote (Unit *source, uint32 emote)
 
uint32 SendChat (Creature *source, uint8 textGroup, WorldObject const *target=nullptr, ChatMsg msgType=CHAT_MSG_ADDON, Language language=LANG_ADDON, CreatureTextRange range=TEXT_RANGE_NORMAL, uint32 sound=0, TeamId teamId=TEAM_NEUTRAL, bool gmOnly=false, Player *srcPlr=nullptr)
 
bool TextExist (uint32 sourceEntry, uint8 textGroup)
 
std::string GetLocalizedChatString (uint32 entry, uint8 gender, uint8 textGroup, uint32 id, LocaleConstant locale) const
 
template<class Builder >
void SendChatPacket (WorldObject *source, Builder const &builder, ChatMsg msgType, WorldObject const *target=nullptr, CreatureTextRange range=TEXT_RANGE_NORMAL, TeamId teamId=TEAM_NEUTRAL, bool gmOnly=false) const
 

Static Public Member Functions

static CreatureTextMgrinstance ()
 

Private Member Functions

 CreatureTextMgr ()
 
void SendNonChatPacket (WorldObject *source, WorldPacket const *data, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly) const
 
float GetRangeForChatType (ChatMsg msgType) const
 

Private Attributes

CreatureTextMap mTextMap
 
LocaleCreatureTextMap mLocaleTextMap
 
CreatureTextOptionsContainer mTextOptionsMap
 

Detailed Description

Constructor & Destructor Documentation

◆ CreatureTextMgr()

CreatureTextMgr::CreatureTextMgr ( )
inlineprivate
92{ }

◆ ~CreatureTextMgr()

CreatureTextMgr::~CreatureTextMgr ( )
inline
97{ }

Member Function Documentation

◆ GetLocalizedChatString()

std::string CreatureTextMgr::GetLocalizedChatString ( uint32  entry,
uint8  gender,
uint8  textGroup,
uint32  id,
LocaleConstant  locale 
) const
476{
477 CreatureTextMap::const_iterator mapitr = mTextMap.find(entry);
478 if (mapitr == mTextMap.end())
479 return "";
480
481 CreatureTextHolder::const_iterator holderItr = mapitr->second.find(textGroup);
482 if (holderItr == mapitr->second.end())
483 return "";
484
485 CreatureTextGroup::const_iterator groupItr = holderItr->second.begin();
486 for (; groupItr != holderItr->second.end(); ++groupItr)
487 if (groupItr->id == id)
488 break;
489
490 if (groupItr == holderItr->second.end())
491 return "";
492
493 if (locale > MAX_LOCALES)
494 locale = DEFAULT_LOCALE;
495
496 std::string baseText = "";
497
498 BroadcastText const* bct = sObjectMgr->GetBroadcastText(groupItr->BroadcastTextId);
499 if (bct)
500 baseText = bct->GetText(locale, gender);
501 else
502 baseText = groupItr->text;
503
504 if (locale != DEFAULT_LOCALE && !bct)
505 {
506 LocaleCreatureTextMap::const_iterator locItr = mLocaleTextMap.find(CreatureTextId(entry, uint32(textGroup), id));
507 if (locItr != mLocaleTextMap.end())
508 ObjectMgr::GetLocaleString(locItr->second.Text, locale, baseText);
509 }
510
511 return baseText;
512}
#define DEFAULT_LOCALE
Definition Common.h:139
#define MAX_LOCALES
Definition Common.h:141
std::uint32_t uint32
Definition Define.h:107
#define sObjectMgr
Definition ObjectMgr.h:1730
LocaleCreatureTextMap mLocaleTextMap
Definition CreatureTextMgr.h:119
CreatureTextMap mTextMap
Definition CreatureTextMgr.h:118
static std::string_view GetLocaleString(std::vector< std::string > const &data, std::size_t locale)
Definition ObjectMgr.h:1490
Definition ObjectMgr.h:437
std::string const & GetText(LocaleConstant locale=DEFAULT_LOCALE, uint8 gender=GENDER_MALE, bool forceGender=false) const
Definition ObjectMgr.h:459
Definition CreatureTextMgr.h:59

References DEFAULT_LOCALE, ObjectMgr::GetLocaleString(), BroadcastText::GetText(), MAX_LOCALES, mLocaleTextMap, mTextMap, and sObjectMgr.

◆ GetRangeForChatType()

float CreatureTextMgr::GetRangeForChatType ( ChatMsg  msgType) const
private
350{
351 float dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY);
352 switch (msgType)
353 {
355 dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL);
356 break;
359 dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE);
360 break;
361 default:
362 break;
363 }
364
365 return dist;
366}
@ CHAT_MSG_RAID_BOSS_EMOTE
Definition SharedDefines.h:3426
@ CHAT_MSG_MONSTER_EMOTE
Definition SharedDefines.h:3401
@ CHAT_MSG_MONSTER_YELL
Definition SharedDefines.h:3399
@ CONFIG_LISTEN_RANGE_YELL
Definition WorldConfig.h:158
@ CONFIG_LISTEN_RANGE_SAY
Definition WorldConfig.h:156
@ CONFIG_LISTEN_RANGE_TEXTEMOTE
Definition WorldConfig.h:157
#define sWorld
Definition World.h:318

References CHAT_MSG_MONSTER_EMOTE, CHAT_MSG_MONSTER_YELL, CHAT_MSG_RAID_BOSS_EMOTE, CONFIG_LISTEN_RANGE_SAY, CONFIG_LISTEN_RANGE_TEXTEMOTE, CONFIG_LISTEN_RANGE_YELL, and sWorld.

Referenced by SendChatPacket(), and SendNonChatPacket().

◆ GetTextMap()

CreatureTextMap const & CreatureTextMgr::GetTextMap ( ) const
inline
101{ return mTextMap; }

References mTextMap.

◆ GetTextOptions()

CreatureTextOptions const * CreatureTextMgr::GetTextOptions ( uint32  entry,
uint8  group 
) const
245{
246 auto entryItr = mTextOptionsMap.find(entry);
247 if (entryItr == mTextOptionsMap.end())
248 return nullptr;
249
250 auto groupItr = entryItr->second.find(group);
251 if (groupItr == entryItr->second.end())
252 return nullptr;
253
254 return &groupItr->second;
255}
CreatureTextOptionsContainer mTextOptionsMap
Definition CreatureTextMgr.h:120

References mTextOptionsMap.

Referenced by SendChat().

◆ instance()

CreatureTextMgr * CreatureTextMgr::instance ( )
static
78{
80 return &instance;
81}
Definition CreatureTextMgr.h:91
static CreatureTextMgr * instance()
Definition CreatureTextMgr.cpp:77

References instance().

Referenced by instance().

◆ LoadCreatureTextLocales()

void CreatureTextMgr::LoadCreatureTextLocales ( )
171{
172 uint32 oldMSTime = getMSTime();
173
174 mLocaleTextMap.clear(); // for reload case
175
176 QueryResult result = WorldDatabase.Query("SELECT CreatureId, GroupId, ID, Locale, Text FROM creature_text_locale");
177
178 if (!result)
179 return;
180
181 do
182 {
183 Field* fields = result->Fetch();
184
185 uint32 CreatureId = fields[0].Get<uint32>();
186 uint32 GroupId = fields[1].Get<uint8>();
187 uint32 ID = fields[2].Get<uint8>();
188
189 LocaleConstant locale = GetLocaleByName(fields[3].Get<std::string>());
190 if (locale == LOCALE_enUS)
191 continue;
192
193 CreatureTextLocale& data = mLocaleTextMap[CreatureTextId(CreatureId, GroupId, ID)];
194 ObjectMgr::AddLocaleString(fields[4].Get<std::string>(), locale, data.Text);
195 } while (result->NextRow());
196
197 LOG_INFO("server.loading", ">> Loaded {} Creature Text Locale in {} ms", uint32(mLocaleTextMap.size()), GetMSTimeDiffToNow(oldMSTime));
198 LOG_INFO("server.loading", " ");
199}
LocaleConstant GetLocaleByName(std::string const &name)
Definition Common.cpp:78
LocaleConstant
Definition Common.h:125
@ LOCALE_enUS
Definition Common.h:126
std::shared_ptr< ResultSet > QueryResult
Definition DatabaseEnvFwd.h:27
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition DatabaseEnv.cpp:20
std::uint8_t uint8
Definition Define.h:109
#define LOG_INFO(filterType__,...)
Definition Log.h:153
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:131
uint32 getMSTime()
Definition Timer.h:103
Class used to access individual fields of database query result.
Definition Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112
static void AddLocaleString(std::string &&s, LocaleConstant locale, std::vector< std::string > &data)
Definition ObjectMgr.cpp:383
Definition CreatureTextMgr.h:54
std::vector< std::string > Text
Definition CreatureTextMgr.h:55

References ObjectMgr::AddLocaleString(), Field::Get(), GetLocaleByName(), getMSTime(), GetMSTimeDiffToNow(), LOCALE_enUS, LOG_INFO, mLocaleTextMap, CreatureTextLocale::Text, and WorldDatabase.

◆ LoadCreatureTextOptions()

void CreatureTextMgr::LoadCreatureTextOptions ( )
202{
203 uint32 oldMSTime = getMSTime();
204
205 mTextOptionsMap.clear();
206
208 PreparedQueryResult result = WorldDatabase.Query(stmt);
209
210 if (!result)
211 {
212 LOG_WARN("server.loading", ">> Loaded 0 creature text options. DB table `creature_text_options` is empty.");
213 LOG_INFO("server.loading", " ");
214 return;
215 }
216
217 uint32 count = 0;
218
219 do
220 {
221 Field* fields = result->Fetch();
222 uint32 creatureId = fields[0].Get<uint32>();
223 uint8 groupId = fields[1].Get<uint8>();
224
225 CreatureTextOptions options;
226 options.cooldown = fields[2].Get<uint32>();
227 options.triggerChance = fields[3].Get<uint8>();
228 options.playerOnly = fields[4].Get<bool>();
229
230 if (options.triggerChance > 100)
231 {
232 LOG_ERROR("sql.sql", "CreatureTextMgr: Entry {}, Group {} in table `creature_text_options` has TriggerChance {} > 100. Setting to 100.", creatureId, groupId, options.triggerChance);
233 options.triggerChance = 100;
234 }
235
236 mTextOptionsMap[creatureId][groupId] = options;
237 ++count;
238 } while (result->NextRow());
239
240 LOG_INFO("server.loading", ">> Loaded {} Creature Text Options in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
241 LOG_INFO("server.loading", " ");
242}
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
#define LOG_ERROR(filterType__,...)
Definition Log.h:145
#define LOG_WARN(filterType__,...)
Definition Log.h:149
@ WORLD_SEL_CREATURE_TEXT_OPTIONS
Definition WorldDatabase.h:35
Definition PreparedStatement.h:157
Definition CreatureTextMgr.h:75
uint32 cooldown
Definition CreatureTextMgr.h:76

References CreatureTextOptions::cooldown, Field::Get(), getMSTime(), GetMSTimeDiffToNow(), LOG_ERROR, LOG_INFO, LOG_WARN, mTextOptionsMap, WORLD_SEL_CREATURE_TEXT_OPTIONS, and WorldDatabase.

◆ LoadCreatureTexts()

void CreatureTextMgr::LoadCreatureTexts ( )
84{
85 uint32 oldMSTime = getMSTime();
86
87 mTextMap.clear(); // for reload case
88 //all currently used temp texts are NOT reset
89
91 PreparedQueryResult result = WorldDatabase.Query(stmt);
92
93 if (!result)
94 {
95 LOG_WARN("server.loading", ">> Loaded 0 ceature texts. DB table `creature_texts` is empty.");
96 LOG_INFO("server.loading", " ");
97 return;
98 }
99
100 uint32 textCount = 0;
101
102 do
103 {
104 Field* fields = result->Fetch();
106
107 temp.entry = fields[0].Get<uint32>();
108 temp.group = fields[1].Get<uint8>();
109 temp.id = fields[2].Get<uint8>();
110 temp.text = fields[3].Get<std::string>();
111 temp.type = ChatMsg(fields[4].Get<uint8>());
112 temp.lang = Language(fields[5].Get<uint8>());
113 temp.probability = fields[6].Get<float>();
114 temp.emote = Emote(fields[7].Get<uint32>());
115 temp.duration = fields[8].Get<uint32>();
116 temp.sound = fields[9].Get<uint32>();
117 temp.BroadcastTextId = fields[10].Get<uint32>();
118 temp.TextRange = CreatureTextRange(fields[11].Get<uint8>());
119
120 if (temp.sound)
121 {
122 if (!sSoundEntriesStore.LookupEntry(temp.sound))
123 {
124 LOG_ERROR("sql.sql", "CreatureTextMgr: Entry {}, Group {} in table `creature_texts` has Sound {} but sound does not exist.", temp.entry, temp.group, temp.sound);
125 temp.sound = 0;
126 }
127 }
128 if (!GetLanguageDescByID(temp.lang))
129 {
130 LOG_ERROR("sql.sql", "CreatureTextMgr: Entry {}, Group {} in table `creature_texts` using Language {} but Language does not exist.", temp.entry, temp.group, uint32(temp.lang));
131 temp.lang = LANG_UNIVERSAL;
132 }
133 if (temp.type >= MAX_CHAT_MSG_TYPE)
134 {
135 LOG_ERROR("sql.sql", "CreatureTextMgr: Entry {}, Group {} in table `creature_texts` has Type {} but this Chat Type does not exist.", temp.entry, temp.group, uint32(temp.type));
136 temp.type = CHAT_MSG_SAY;
137 }
138 if (temp.emote)
139 {
140 if (!sEmotesStore.LookupEntry(temp.emote))
141 {
142 LOG_ERROR("sql.sql", "CreatureTextMgr: Entry {}, Group {} in table `creature_texts` has Emote {} but emote does not exist.", temp.entry, temp.group, uint32(temp.emote));
144 }
145 }
146 if (temp.BroadcastTextId)
147 {
148 if (!sObjectMgr->GetBroadcastText(temp.BroadcastTextId))
149 {
150 LOG_ERROR("sql.sql", "CreatureTextMgr: Entry {}, Group {}, Id {} in table `creature_text` has non-existing or incompatible BroadcastTextId {}.", temp.entry, temp.group, temp.id, temp.BroadcastTextId);
151 temp.BroadcastTextId = 0;
152 }
153 }
154 if (temp.TextRange > TEXT_RANGE_WORLD)
155 {
156 LOG_ERROR("sql.sql", "CreatureTextMgr: Entry {}, Group {}, Id {} in table `creature_text` has incorrect TextRange {}.", temp.entry, temp.group, temp.id, temp.TextRange);
158 }
159
160 //add the text into our entry's group
161 mTextMap[temp.entry][temp.group].push_back(temp);
162
163 ++textCount;
164 } while (result->NextRow());
165
166 LOG_INFO("server.loading", ">> Loaded {} Creature Texts For {} Creatures in {} ms", textCount, mTextMap.size(), GetMSTimeDiffToNow(oldMSTime));
167 LOG_INFO("server.loading", " ");
168}
CreatureTextRange
Definition CreatureTextMgr.h:29
@ TEXT_RANGE_WORLD
Definition CreatureTextMgr.h:34
@ TEXT_RANGE_NORMAL
Definition CreatureTextMgr.h:30
DBCStorage< SoundEntriesEntry > sSoundEntriesStore(SoundEntriesfmt)
DBCStorage< EmotesEntry > sEmotesStore(EmotesEntryfmt)
LanguageDesc const * GetLanguageDescByID(uint32 lang)
Definition ObjectMgr.cpp:254
Emote
Definition SharedDefines.h:1897
@ EMOTE_ONESHOT_NONE
Definition SharedDefines.h:1898
ChatMsg
Definition SharedDefines.h:3383
@ CHAT_MSG_SAY
Definition SharedDefines.h:3386
Language
Definition SharedDefines.h:722
@ LANG_UNIVERSAL
Definition SharedDefines.h:723
#define MAX_CHAT_MSG_TYPE
Definition SharedDefines.h:3439
@ WORLD_SEL_CREATURE_TEXT
Definition WorldDatabase.h:34
Definition CreatureTextMgr.h:38
uint32 duration
Definition CreatureTextMgr.h:47
uint32 BroadcastTextId
Definition CreatureTextMgr.h:50
CreatureTextRange TextRange
Definition CreatureTextMgr.h:49
uint32 entry
Definition CreatureTextMgr.h:39
ChatMsg type
Definition CreatureTextMgr.h:43
std::string text
Definition CreatureTextMgr.h:42
Language lang
Definition CreatureTextMgr.h:44
float probability
Definition CreatureTextMgr.h:45
Emote emote
Definition CreatureTextMgr.h:46
uint8 id
Definition CreatureTextMgr.h:41
uint8 group
Definition CreatureTextMgr.h:40
uint32 sound
Definition CreatureTextMgr.h:48

References CreatureTextEntry::BroadcastTextId, CHAT_MSG_SAY, CreatureTextEntry::duration, CreatureTextEntry::emote, EMOTE_ONESHOT_NONE, CreatureTextEntry::entry, Field::Get(), GetLanguageDescByID(), getMSTime(), GetMSTimeDiffToNow(), CreatureTextEntry::group, CreatureTextEntry::id, CreatureTextEntry::lang, LANG_UNIVERSAL, LOG_ERROR, LOG_INFO, LOG_WARN, MAX_CHAT_MSG_TYPE, mTextMap, CreatureTextEntry::probability, sEmotesStore, sObjectMgr, CreatureTextEntry::sound, sSoundEntriesStore, CreatureTextEntry::text, TEXT_RANGE_NORMAL, TEXT_RANGE_WORLD, CreatureTextEntry::TextRange, CreatureTextEntry::type, WORLD_SEL_CREATURE_TEXT, and WorldDatabase.

◆ SendChat()

uint32 CreatureTextMgr::SendChat ( Creature source,
uint8  textGroup,
WorldObject const *  target = nullptr,
ChatMsg  msgType = CHAT_MSG_ADDON,
Language  language = LANG_ADDON,
CreatureTextRange  range = TEXT_RANGE_NORMAL,
uint32  sound = 0,
TeamId  teamId = TEAM_NEUTRAL,
bool  gmOnly = false,
Player srcPlr = nullptr 
)
258{
259 if (!source)
260 return 0;
261
262 CreatureTextMap::const_iterator sList = mTextMap.find(source->GetEntry());
263 if (sList == mTextMap.end())
264 {
265 LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find Text for Creature({}) Entry {} in 'creature_text' table. Ignoring.", source->GetName(), source->GetEntry());
266 return 0;
267 }
268
269 CreatureTextHolder const& textHolder = sList->second;
270 CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
271 if (itr == textHolder.end())
272 {
273 LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find TextGroup {} for Creature {} ({}). Ignoring.",
274 uint32(textGroup), source->GetName(), source->GetGUID().ToString());
275 return 0;
276 }
277
278 CreatureTextGroup const& textGroupContainer = itr->second; //has all texts in the group
279
280 // Check creature_text_options for this group
281 CreatureTextOptions const* options = GetTextOptions(source->GetEntry(), textGroup);
282 if (options)
283 {
284 if (options->playerOnly && (!target || !target->IsPlayer()))
285 return 0;
286
287 if (options->triggerChance < 100 && !roll_chance_i(options->triggerChance))
288 return 0;
289
290 if (options->cooldown > 0 && source->IsTextOnCooldown(textGroup))
291 return 0;
292 }
293
294 CreatureTextRepeatIds repeatGroup = source->GetTextRepeatGroup(textGroup);//has all textIDs from the group that were already said
295 CreatureTextGroup tempGroup;//will use this to talk after sorting repeatGroup
296
297 for (CreatureTextGroup::const_iterator giter = textGroupContainer.begin(); giter != textGroupContainer.end(); ++giter)
298 if (std::find(repeatGroup.begin(), repeatGroup.end(), giter->id) == repeatGroup.end())
299 tempGroup.push_back(*giter);
300
301 if (tempGroup.empty())
302 {
303 source->ClearTextRepeatGroup(textGroup);
304 tempGroup = textGroupContainer;
305 }
306
307 auto iter = Acore::Containers::SelectRandomWeightedContainerElement(tempGroup, [](CreatureTextEntry const& t) -> double
308 {
309 return t.probability;
310 });
311
312 ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? iter->type : msgType;
313 Language finalLang = (language == LANG_ADDON) ? iter->lang : language;
314 uint32 finalSound = sound ? sound : iter->sound;
315
316 if (range == TEXT_RANGE_NORMAL)
317 range = iter->TextRange;
318
319 if (finalSound)
320 SendSound(source, finalSound, finalType, target, range, teamId, gmOnly);
321
322 Unit* finalSource = source;
323 if (srcPlr)
324 finalSource = srcPlr;
325
326 if (iter->emote)
327 SendEmote(finalSource, iter->emote);
328
329 if (srcPlr)
330 {
331 PlayerTextBuilder builder(source, finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, target);
332 SendChatPacket(finalSource, builder, finalType, target, range, teamId, gmOnly);
333 }
334 else
335 {
336 CreatureTextBuilder builder(finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, target);
337 SendChatPacket(finalSource, builder, finalType, target, range, teamId, gmOnly);
338 }
339
340 source->SetTextRepeatId(textGroup, iter->id);
341
342 // Set cooldown if creature_text_options specifies one
343 if (options && options->cooldown > 0)
344 source->SetTextCooldown(textGroup, options->cooldown);
345
346 return iter->duration;
347}
std::vector< CreatureTextEntry > CreatureTextGroup
Definition CreatureTextMgr.h:81
std::unordered_map< uint8, CreatureTextGroup > CreatureTextHolder
Definition CreatureTextMgr.h:82
std::vector< uint8 > CreatureTextRepeatIds
Definition Creature.h:43
bool roll_chance_i(int chance)
Definition Random.h:63
@ CHAT_MSG_ADDON
Definition SharedDefines.h:3384
@ LANG_ADDON
Definition SharedDefines.h:741
Definition CreatureTextMgr.cpp:31
void SendChatPacket(WorldObject *source, Builder const &builder, ChatMsg msgType, WorldObject const *target=nullptr, CreatureTextRange range=TEXT_RANGE_NORMAL, TeamId teamId=TEAM_NEUTRAL, bool gmOnly=false) const
Definition CreatureTextMgr.h:184
void SendEmote(Unit *source, uint32 emote)
Definition CreatureTextMgr.cpp:444
void SendSound(Creature *source, uint32 sound, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly)
Definition CreatureTextMgr.cpp:368
CreatureTextOptions const * GetTextOptions(uint32 entry, uint8 group) const
Definition CreatureTextMgr.cpp:244
void SetTextRepeatId(uint8 textGroup, uint8 id)
Definition Creature.cpp:3799
void ClearTextRepeatGroup(uint8 textGroup)
Definition Creature.cpp:3819
void SetTextCooldown(uint8 textGroup, uint32 cooldownMs)
Definition Creature.cpp:3835
bool IsTextOnCooldown(uint8 textGroup) const
Definition Creature.cpp:3826
CreatureTextRepeatIds const & GetTextRepeatGroup(uint8 textGroup)
Definition Creature.cpp:3808
std::string ToString() const
Definition ObjectGuid.cpp:48
uint32 GetEntry() const
Definition Object.h:117
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
Definition CreatureTextMgr.cpp:54
Definition Unit.h:665
uint8 getGender() const
Definition Unit.h:849
std::string const & GetName() const
Definition Object.h:529
auto SelectRandomWeightedContainerElement(C const &container, std::vector< double > weights) -> decltype(std::begin(container))
Definition Containers.h:175
bool playerOnly
Definition CreatureTextMgr.h:78
uint8 triggerChance
Definition CreatureTextMgr.h:77

References CHAT_MSG_ADDON, Creature::ClearTextRepeatGroup(), CreatureTextOptions::cooldown, Object::GetEntry(), Unit::getGender(), Object::GetGUID(), WorldObject::GetName(), GetTextOptions(), Creature::GetTextRepeatGroup(), Object::IsPlayer(), Creature::IsTextOnCooldown(), LANG_ADDON, LOG_ERROR, mTextMap, CreatureTextOptions::playerOnly, CreatureTextEntry::probability, roll_chance_i(), Acore::Containers::SelectRandomWeightedContainerElement(), SendChatPacket(), SendEmote(), SendSound(), Creature::SetTextCooldown(), Creature::SetTextRepeatId(), TEXT_RANGE_NORMAL, ObjectGuid::ToString(), and CreatureTextOptions::triggerChance.

◆ SendChatPacket()

template<class Builder >
void CreatureTextMgr::SendChatPacket ( WorldObject source,
Builder const &  builder,
ChatMsg  msgType,
WorldObject const *  target = nullptr,
CreatureTextRange  range = TEXT_RANGE_NORMAL,
TeamId  teamId = TEAM_NEUTRAL,
bool  gmOnly = false 
) const
185{
186 if (!source)
187 return;
188
189 CreatureTextLocalizer<Builder> localizer(builder, msgType);
190
191 switch (msgType)
192 {
195 {
196 if (range == TEXT_RANGE_NORMAL) // ignores team and GM only
197 {
198 if (!target || !target->IsPlayer())
199 return;
200
201 localizer(const_cast<Player*>(target->ToPlayer()));
202 return;
203 }
204 break;
205 }
206 default:
207 break;
208 }
209
210 switch (range)
211 {
212 case TEXT_RANGE_AREA:
213 {
214 uint32 areaId = source->GetAreaId();
215 Map::PlayerList const& players = source->GetMap()->GetPlayers();
216 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
217 if (itr->GetSource()->GetAreaId() == areaId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
218 localizer(itr->GetSource());
219 return;
220 }
221 case TEXT_RANGE_ZONE:
222 {
223 uint32 zoneId = source->GetZoneId();
224 Map::PlayerList const& players = source->GetMap()->GetPlayers();
225 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
226 if (itr->GetSource()->GetZoneId() == zoneId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
227 localizer(itr->GetSource());
228 return;
229 }
230 case TEXT_RANGE_MAP:
231 {
232 Map::PlayerList const& players = source->GetMap()->GetPlayers();
233 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
234 if ((teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
235 localizer(itr->GetSource());
236 return;
237 }
238 case TEXT_RANGE_WORLD:
239 {
240 WorldSessionMgr::SessionMap const& smap = sWorldSessionMgr->GetAllSessions();
241 for (WorldSessionMgr::SessionMap::const_iterator itr = smap.begin(); itr != smap.end(); ++itr)
242 if (Player* player = itr->second->GetPlayer())
243 if ((teamId == TEAM_NEUTRAL || player->GetTeamId() == teamId) && (!gmOnly || player->IsGameMaster()))
244 localizer(player);
245 return;
246 }
248 default:
249 break;
250 }
251
252 float dist = GetRangeForChatType(msgType);
253 // xinef: hack for boss emote
254 if (msgType == CHAT_MSG_RAID_BOSS_EMOTE && source->GetMap()->IsDungeon())
255 dist = 250.0f;
256
257 Acore::PlayerDistWorker<CreatureTextLocalizer<Builder> > worker(source, dist, localizer);
258 Cell::VisitObjects(source, worker, dist);
259}
@ TEXT_RANGE_ZONE
Definition CreatureTextMgr.h:32
@ TEXT_RANGE_AREA
Definition CreatureTextMgr.h:31
@ TEXT_RANGE_MAP
Definition CreatureTextMgr.h:33
@ CHAT_MSG_MONSTER_WHISPER
Definition SharedDefines.h:3400
@ CHAT_MSG_RAID_BOSS_WHISPER
Definition SharedDefines.h:3427
@ TEAM_NEUTRAL
Definition SharedDefines.h:750
#define sWorldSessionMgr
Definition WorldSessionMgr.h:118
Definition CreatureTextMgr.h:127
float GetRangeForChatType(ChatMsg msgType) const
Definition CreatureTextMgr.cpp:349
Definition LinkedList.h:139
Definition MapRefMgr.h:26
iterator begin()
Definition MapRefMgr.h:36
iterator end()
Definition MapRefMgr.h:37
bool IsDungeon() const
Definition Map.h:299
PlayerList const & GetPlayers() const
Definition Map.h:335
Definition Player.h:1086
Map * GetMap() const
Definition Object.h:631
uint32 GetAreaId() const
Definition Object.cpp:3174
uint32 GetZoneId() const
Definition Object.cpp:3166
std::unordered_map< uint32, WorldSession * > SessionMap
Definition WorldSessionMgr.h:64
Definition GridNotifiers.h:615
static void VisitObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:165

References MapRefMgr::begin(), CHAT_MSG_MONSTER_WHISPER, CHAT_MSG_RAID_BOSS_EMOTE, CHAT_MSG_RAID_BOSS_WHISPER, MapRefMgr::end(), WorldObject::GetAreaId(), WorldObject::GetMap(), Map::GetPlayers(), GetRangeForChatType(), WorldObject::GetZoneId(), Map::IsDungeon(), Object::IsPlayer(), sWorldSessionMgr, TEAM_NEUTRAL, TEXT_RANGE_AREA, TEXT_RANGE_MAP, TEXT_RANGE_NORMAL, TEXT_RANGE_WORLD, TEXT_RANGE_ZONE, Object::ToPlayer(), and Cell::VisitObjects().

Referenced by SendChat().

◆ SendEmote()

void CreatureTextMgr::SendEmote ( Unit source,
uint32  emote 
)
445{
446 if (!source)
447 return;
448
449 source->HandleEmoteCommand(emote);
450}
void HandleEmoteCommand(uint32 emoteId)
Definition Unit.cpp:2187

References Unit::HandleEmoteCommand().

Referenced by SendChat().

◆ SendNonChatPacket()

void CreatureTextMgr::SendNonChatPacket ( WorldObject source,
WorldPacket const *  data,
ChatMsg  msgType,
WorldObject const *  target,
CreatureTextRange  range,
TeamId  teamId,
bool  gmOnly 
) const
private
377{
378 float dist = GetRangeForChatType(msgType);
379
380 switch (msgType)
381 {
384 {
385 if (range == TEXT_RANGE_NORMAL) // ignores team and GM only
386 {
387 if (!target || !target->IsPlayer())
388 return;
389
390 target->ToPlayer()->SendDirectMessage(data);
391 return;
392 }
393 break;
394 }
395 default:
396 break;
397 }
398
399 switch (range)
400 {
401 case TEXT_RANGE_AREA:
402 {
403 uint32 areaId = source->GetAreaId();
404 Map::PlayerList const& players = source->GetMap()->GetPlayers();
405 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
406 if (itr->GetSource()->GetAreaId() == areaId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
407 itr->GetSource()->SendDirectMessage(data);
408 return;
409 }
410 case TEXT_RANGE_ZONE:
411 {
412 uint32 zoneId = source->GetZoneId();
413 Map::PlayerList const& players = source->GetMap()->GetPlayers();
414 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
415 if (itr->GetSource()->GetZoneId() == zoneId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
416 itr->GetSource()->SendDirectMessage(data);
417 return;
418 }
419 case TEXT_RANGE_MAP:
420 {
421 Map::PlayerList const& players = source->GetMap()->GetPlayers();
422 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
423 if ((teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
424 itr->GetSource()->SendDirectMessage(data);
425 return;
426 }
427 case TEXT_RANGE_WORLD:
428 {
429 WorldSessionMgr::SessionMap const& sessionMap = sWorldSessionMgr->GetAllSessions();
430 for (WorldSessionMgr::SessionMap::const_iterator itr = sessionMap.begin(); itr != sessionMap.end(); ++itr)
431 if (Player* player = itr->second->GetPlayer())
432 if ((teamId == TEAM_NEUTRAL || player->GetTeamId() == teamId) && (!gmOnly || player->IsGameMaster()))
433 player->SendDirectMessage(data);
434 return;
435 }
437 default:
438 break;
439 }
440
441 source->SendMessageToSetInRange(data, dist, true);
442}
virtual void SendMessageToSetInRange(WorldPacket const *data, float dist, bool self) const
Definition Object.cpp:2172

References MapRefMgr::begin(), CHAT_MSG_MONSTER_WHISPER, CHAT_MSG_RAID_BOSS_WHISPER, MapRefMgr::end(), WorldObject::GetAreaId(), WorldObject::GetMap(), Map::GetPlayers(), GetRangeForChatType(), WorldObject::GetZoneId(), Object::IsPlayer(), Player::SendDirectMessage(), WorldObject::SendMessageToSetInRange(), sWorldSessionMgr, TEAM_NEUTRAL, TEXT_RANGE_AREA, TEXT_RANGE_MAP, TEXT_RANGE_NORMAL, TEXT_RANGE_WORLD, TEXT_RANGE_ZONE, and Object::ToPlayer().

Referenced by SendSound().

◆ SendSound()

void CreatureTextMgr::SendSound ( Creature source,
uint32  sound,
ChatMsg  msgType,
WorldObject const *  target,
CreatureTextRange  range,
TeamId  teamId,
bool  gmOnly 
)
369{
370 if (!sound || !source)
371 return;
372
373 SendNonChatPacket(source, WorldPackets::Misc::Playsound(sound).Write(), msgType, target, range, teamId, gmOnly);
374}
void SendNonChatPacket(WorldObject *source, WorldPacket const *data, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly) const
Definition CreatureTextMgr.cpp:376
Definition MiscPackets.h:85

References SendNonChatPacket().

Referenced by SendChat().

◆ TextExist()

bool CreatureTextMgr::TextExist ( uint32  sourceEntry,
uint8  textGroup 
)
453{
454 if (!sourceEntry)
455 return false;
456
457 CreatureTextMap::const_iterator sList = mTextMap.find(sourceEntry);
458 if (sList == mTextMap.end())
459 {
460 LOG_DEBUG("entities.unit", "CreatureTextMgr::TextExist: Could not find Text for Creature (entry {}) in 'creature_text' table.", sourceEntry);
461 return false;
462 }
463
464 CreatureTextHolder const& textHolder = sList->second;
465 CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
466 if (itr == textHolder.end())
467 {
468 LOG_DEBUG("entities.unit", "CreatureTextMgr::TextExist: Could not find TextGroup {} for Creature (entry {}).", uint32(textGroup), sourceEntry);
469 return false;
470 }
471
472 return true;
473}
#define LOG_DEBUG(filterType__,...)
Definition Log.h:157

References LOG_DEBUG, and mTextMap.

Member Data Documentation

◆ mLocaleTextMap

LocaleCreatureTextMap CreatureTextMgr::mLocaleTextMap
private

◆ mTextMap

CreatureTextMap CreatureTextMgr::mTextMap
private

◆ mTextOptionsMap

CreatureTextOptionsContainer CreatureTextMgr::mTextOptionsMap
private

The documentation for this class was generated from the following files: