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 ()
 
CreatureTextMap const & GetTextMap () 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 ()
 
CreatureTextRepeatIds GetRepeatGroup (Creature *source, uint8 textGroup)
 
void SetRepeatId (Creature *source, uint8 textGroup, uint8 id)
 
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
 
CreatureTextRepeatMap mTextRepeatMap
 
LocaleCreatureTextMap mLocaleTextMap
 

Detailed Description

Constructor & Destructor Documentation

◆ CreatureTextMgr()

CreatureTextMgr::CreatureTextMgr ( )
inlineprivate
87{ }

◆ ~CreatureTextMgr()

CreatureTextMgr::~CreatureTextMgr ( )
inline
92{ }

Member Function Documentation

◆ GetLocalizedChatString()

std::string CreatureTextMgr::GetLocalizedChatString ( uint32  entry,
uint8  gender,
uint8  textGroup,
uint32  id,
LocaleConstant  locale 
) const
466{
467 CreatureTextMap::const_iterator mapitr = mTextMap.find(entry);
468 if (mapitr == mTextMap.end())
469 return "";
470
471 CreatureTextHolder::const_iterator holderItr = mapitr->second.find(textGroup);
472 if (holderItr == mapitr->second.end())
473 return "";
474
475 CreatureTextGroup::const_iterator groupItr = holderItr->second.begin();
476 for (; groupItr != holderItr->second.end(); ++groupItr)
477 if (groupItr->id == id)
478 break;
479
480 if (groupItr == holderItr->second.end())
481 return "";
482
483 if (locale > MAX_LOCALES)
484 locale = DEFAULT_LOCALE;
485
486 std::string baseText = "";
487
488 BroadcastText const* bct = sObjectMgr->GetBroadcastText(groupItr->BroadcastTextId);
489 if (bct)
490 baseText = bct->GetText(locale, gender);
491 else
492 baseText = groupItr->text;
493
494 if (locale != DEFAULT_LOCALE && !bct)
495 {
496 LocaleCreatureTextMap::const_iterator locItr = mLocaleTextMap.find(CreatureTextId(entry, uint32(textGroup), id));
497 if (locItr != mLocaleTextMap.end())
498 ObjectMgr::GetLocaleString(locItr->second.Text, locale, baseText);
499 }
500
501 return baseText;
502}
#define DEFAULT_LOCALE
Definition: Common.h:88
#define MAX_LOCALES
Definition: Common.h:90
std::uint32_t uint32
Definition: Define.h:108
#define sObjectMgr
Definition: ObjectMgr.h:1640
Definition: ObjectMgr.h:435
std::string const & GetText(LocaleConstant locale=DEFAULT_LOCALE, uint8 gender=GENDER_MALE, bool forceGender=false) const
Definition: ObjectMgr.h:457
static std::string_view GetLocaleString(std::vector< std::string > const &data, size_t locale)
Definition: ObjectMgr.h:1416
Definition: CreatureTextMgr.h:59
LocaleCreatureTextMap mLocaleTextMap
Definition: CreatureTextMgr.h:116
CreatureTextMap mTextMap
Definition: CreatureTextMgr.h:114

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

◆ GetRangeForChatType()

float CreatureTextMgr::GetRangeForChatType ( ChatMsg  msgType) const
private
312{
313 float dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY);
314 switch (msgType)
315 {
317 dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL);
318 break;
321 dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE);
322 break;
323 default:
324 break;
325 }
326
327 return dist;
328}
@ CONFIG_LISTEN_RANGE_YELL
Definition: IWorld.h:195
@ CONFIG_LISTEN_RANGE_SAY
Definition: IWorld.h:193
@ CONFIG_LISTEN_RANGE_TEXTEMOTE
Definition: IWorld.h:194
@ CHAT_MSG_RAID_BOSS_EMOTE
Definition: SharedDefines.h:3165
@ CHAT_MSG_MONSTER_EMOTE
Definition: SharedDefines.h:3140
@ CHAT_MSG_MONSTER_YELL
Definition: SharedDefines.h:3138
#define sWorld
Definition: World.h:451

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().

◆ GetRepeatGroup()

CreatureTextRepeatIds CreatureTextMgr::GetRepeatGroup ( Creature source,
uint8  textGroup 
)
private
428{
429 ASSERT(source);//should never happen
431
432 CreatureTextRepeatMap::const_iterator mapItr = mTextRepeatMap.find(source->GetGUID());
433 if (mapItr != mTextRepeatMap.end())
434 {
435 CreatureTextRepeatGroup::const_iterator groupItr = (*mapItr).second.find(textGroup);
436 if (groupItr != mapItr->second.end())
437 ids = groupItr->second;
438 }
439 return ids;
440}
#define ASSERT
Definition: Errors.h:68
std::vector< uint8 > CreatureTextRepeatIds
Definition: CreatureTextMgr.h:81
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
CreatureTextRepeatMap mTextRepeatMap
Definition: CreatureTextMgr.h:115

References ASSERT, Object::GetGUID(), and mTextRepeatMap.

Referenced by SendChat().

◆ GetTextMap()

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

References mTextMap.

◆ instance()

CreatureTextMgr * CreatureTextMgr::instance ( )
static
77{
79 return &instance;
80}
Definition: CreatureTextMgr.h:86
static CreatureTextMgr * instance()
Definition: CreatureTextMgr.cpp:76

References instance().

Referenced by instance().

◆ LoadCreatureTextLocales()

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

◆ LoadCreatureTexts()

void CreatureTextMgr::LoadCreatureTexts ( )
83{
84 uint32 oldMSTime = getMSTime();
85
86 mTextMap.clear(); // for reload case
87 mTextRepeatMap.clear(); //reset all currently used temp texts
88
90 PreparedQueryResult result = WorldDatabase.Query(stmt);
91
92 if (!result)
93 {
94 LOG_WARN("server.loading", ">> Loaded 0 ceature texts. DB table `creature_texts` is empty.");
95 LOG_INFO("server.loading", " ");
96 return;
97 }
98
99 uint32 textCount = 0;
100
101 do
102 {
103 Field* fields = result->Fetch();
105
106 temp.entry = fields[0].Get<uint32>();
107 temp.group = fields[1].Get<uint8>();
108 temp.id = fields[2].Get<uint8>();
109 temp.text = fields[3].Get<std::string>();
110 temp.type = ChatMsg(fields[4].Get<uint8>());
111 temp.lang = Language(fields[5].Get<uint8>());
112 temp.probability = fields[6].Get<float>();
113 temp.emote = Emote(fields[7].Get<uint32>());
114 temp.duration = fields[8].Get<uint32>();
115 temp.sound = fields[9].Get<uint32>();
116 temp.BroadcastTextId = fields[10].Get<uint32>();
117 temp.TextRange = CreatureTextRange(fields[11].Get<uint8>());
118
119 if (temp.sound)
120 {
121 if (!sSoundEntriesStore.LookupEntry(temp.sound))
122 {
123 LOG_ERROR("sql.sql", "CreatureTextMgr: Entry {}, Group {} in table `creature_texts` has Sound {} but sound does not exist.", temp.entry, temp.group, temp.sound);
124 temp.sound = 0;
125 }
126 }
127 if (!GetLanguageDescByID(temp.lang))
128 {
129 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));
130 temp.lang = LANG_UNIVERSAL;
131 }
132 if (temp.type >= MAX_CHAT_MSG_TYPE)
133 {
134 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));
135 temp.type = CHAT_MSG_SAY;
136 }
137 if (temp.emote)
138 {
139 if (!sEmotesStore.LookupEntry(temp.emote))
140 {
141 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));
143 }
144 }
145 if (temp.BroadcastTextId)
146 {
147 if (!sObjectMgr->GetBroadcastText(temp.BroadcastTextId))
148 {
149 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);
150 temp.BroadcastTextId = 0;
151 }
152 }
153 if (temp.TextRange > TEXT_RANGE_WORLD)
154 {
155 LOG_ERROR("sql.sql", "CreatureTextMgr: Entry {}, Group {}, Id {} in table `creature_text` has incorrect TextRange {}.", temp.entry, temp.group, temp.id, temp.TextRange);
157 }
158
159 //add the text into our entry's group
160 mTextMap[temp.entry][temp.group].push_back(temp);
161
162 ++textCount;
163 } while (result->NextRow());
164
165 LOG_INFO("server.loading", ">> Loaded {} Creature Texts For {} Creatures in {} ms", textCount, mTextMap.size(), GetMSTimeDiffToNow(oldMSTime));
166 LOG_INFO("server.loading", " ");
167}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
#define LOG_WARN(filterType__,...)
Definition: Log.h:163
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:46
@ WORLD_SEL_CREATURE_TEXT
Definition: WorldDatabase.h:34
DBCStorage< SoundEntriesEntry > sSoundEntriesStore(SoundEntriesfmt)
DBCStorage< EmotesEntry > sEmotesStore(EmotesEntryfmt)
LanguageDesc const * GetLanguageDescByID(uint32 lang)
Definition: ObjectMgr.cpp:309
CreatureTextRange
Definition: CreatureTextMgr.h:29
@ TEXT_RANGE_WORLD
Definition: CreatureTextMgr.h:34
@ TEXT_RANGE_NORMAL
Definition: CreatureTextMgr.h:30
Emote
Definition: SharedDefines.h:1865
@ EMOTE_ONESHOT_NONE
Definition: SharedDefines.h:1866
ChatMsg
Definition: SharedDefines.h:3122
@ CHAT_MSG_SAY
Definition: SharedDefines.h:3125
Language
Definition: SharedDefines.h:706
@ LANG_UNIVERSAL
Definition: SharedDefines.h:707
#define MAX_CHAT_MSG_TYPE
Definition: SharedDefines.h:3178
Definition: PreparedStatement.h:158
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, mTextRepeatMap, 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 
)
201{
202 if (!source)
203 return 0;
204
205 CreatureTextMap::const_iterator sList = mTextMap.find(source->GetEntry());
206 if (sList == mTextMap.end())
207 {
208 LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find Text for Creature({}) Entry {} in 'creature_text' table. Ignoring.", source->GetName(), source->GetEntry());
209 return 0;
210 }
211
212 CreatureTextHolder const& textHolder = sList->second;
213 CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
214 if (itr == textHolder.end())
215 {
216 LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find TextGroup {} for Creature {} ({}). Ignoring.",
217 uint32(textGroup), source->GetName(), source->GetGUID().ToString());
218 return 0;
219 }
220
221 CreatureTextGroup const& textGroupContainer = itr->second; //has all texts in the group
222 CreatureTextRepeatIds repeatGroup = GetRepeatGroup(source, textGroup);//has all textIDs from the group that were already said
223 CreatureTextGroup tempGroup;//will use this to talk after sorting repeatGroup
224
225 for (CreatureTextGroup::const_iterator giter = textGroupContainer.begin(); giter != textGroupContainer.end(); ++giter)
226 if (std::find(repeatGroup.begin(), repeatGroup.end(), giter->id) == repeatGroup.end())
227 tempGroup.push_back(*giter);
228
229 if (tempGroup.empty())
230 {
231 CreatureTextRepeatMap::iterator mapItr = mTextRepeatMap.find(source->GetGUID());
232 if (mapItr != mTextRepeatMap.end())
233 {
234 CreatureTextRepeatGroup::iterator groupItr = mapItr->second.find(textGroup);
235 groupItr->second.clear();
236 }
237
238 tempGroup = textGroupContainer;
239 }
240
241 uint8 count = 0;
242 float lastChance = -1;
243 bool isEqualChanced = true;
244
245 float totalChance = 0;
246
247 for (CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter)
248 {
249 if (lastChance >= 0 && lastChance != iter->probability)
250 isEqualChanced = false;
251
252 lastChance = iter->probability;
253 totalChance += iter->probability;
254 ++count;
255 }
256
257 int32 offset = -1;
258 if (!isEqualChanced)
259 {
260 for (CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter)
261 {
262 uint32 chance = uint32(iter->probability);
263 uint32 r = urand(0, 100);
264 ++offset;
265 if (r <= chance)
266 break;
267 }
268 }
269
270 uint32 pos = 0;
271 if (isEqualChanced || offset < 0)
272 pos = urand(0, count - 1);
273 else if (offset >= 0)
274 pos = offset;
275
276 CreatureTextGroup::const_iterator iter = tempGroup.begin() + pos;
277
278 ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? iter->type : msgType;
279 Language finalLang = (language == LANG_ADDON) ? iter->lang : language;
280 uint32 finalSound = sound ? sound : iter->sound;
281
282 if (range == TEXT_RANGE_NORMAL)
283 range = iter->TextRange;
284
285 if (finalSound)
286 SendSound(source, finalSound, finalType, target, range, teamId, gmOnly);
287
288 Unit* finalSource = source;
289 if (srcPlr)
290 finalSource = srcPlr;
291
292 if (iter->emote)
293 SendEmote(finalSource, iter->emote);
294
295 if (srcPlr)
296 {
297 PlayerTextBuilder builder(source, finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, target);
298 SendChatPacket(finalSource, builder, finalType, target, range, teamId, gmOnly);
299 }
300 else
301 {
302 CreatureTextBuilder builder(finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, target);
303 SendChatPacket(finalSource, builder, finalType, target, range, teamId, gmOnly);
304 }
305 if (isEqualChanced || (!isEqualChanced && totalChance == 100.0f))
306 SetRepeatId(source, textGroup, iter->id);
307
308 return iter->duration;
309}
std::int32_t int32
Definition: Define.h:104
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:44
std::vector< CreatureTextEntry > CreatureTextGroup
Definition: CreatureTextMgr.h:74
std::unordered_map< uint8, CreatureTextGroup > CreatureTextHolder
Definition: CreatureTextMgr.h:75
@ CHAT_MSG_ADDON
Definition: SharedDefines.h:3123
@ LANG_ADDON
Definition: SharedDefines.h:725
uint32 GetEntry() const
Definition: Object.h:109
std::string const & GetName() const
Definition: Object.h:446
std::string ToString() const
Definition: ObjectGuid.cpp:47
Definition: Unit.h:1290
uint8 getGender() const
Definition: Unit.h:1428
Definition: CreatureTextMgr.cpp:30
Definition: CreatureTextMgr.cpp:53
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:180
void SetRepeatId(Creature *source, uint8 textGroup, uint8 id)
Definition: CreatureTextMgr.cpp:414
void SendEmote(Unit *source, uint32 emote)
Definition: CreatureTextMgr.cpp:406
void SendSound(Creature *source, uint32 sound, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly)
Definition: CreatureTextMgr.cpp:330
CreatureTextRepeatIds GetRepeatGroup(Creature *source, uint8 textGroup)
Definition: CreatureTextMgr.cpp:427

References CHAT_MSG_ADDON, Object::GetEntry(), Unit::getGender(), Object::GetGUID(), WorldObject::GetName(), GetRepeatGroup(), LANG_ADDON, LOG_ERROR, mTextMap, mTextRepeatMap, SendChatPacket(), SendEmote(), SendSound(), SetRepeatId(), TEXT_RANGE_NORMAL, ObjectGuid::ToString(), and urand().

◆ 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
181{
182 if (!source)
183 return;
184
185 CreatureTextLocalizer<Builder> localizer(builder, msgType);
186
187 switch (msgType)
188 {
191 {
192 if (range == TEXT_RANGE_NORMAL) //ignores team and gmOnly
193 {
194 if (!target || target->GetTypeId() != TYPEID_PLAYER)
195 return;
196
197 localizer(const_cast<Player*>(target->ToPlayer()));
198 return;
199 }
200 break;
201 }
202 default:
203 break;
204 }
205
206 switch (range)
207 {
208 case TEXT_RANGE_AREA:
209 {
210 uint32 areaId = source->GetAreaId();
211 Map::PlayerList const& players = source->GetMap()->GetPlayers();
212 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
213 if (itr->GetSource()->GetAreaId() == areaId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
214 localizer(itr->GetSource());
215 return;
216 }
217 case TEXT_RANGE_ZONE:
218 {
219 uint32 zoneId = source->GetZoneId();
220 Map::PlayerList const& players = source->GetMap()->GetPlayers();
221 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
222 if (itr->GetSource()->GetZoneId() == zoneId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
223 localizer(itr->GetSource());
224 return;
225 }
226 case TEXT_RANGE_MAP:
227 {
228 Map::PlayerList const& players = source->GetMap()->GetPlayers();
229 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
230 if ((teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
231 localizer(itr->GetSource());
232 return;
233 }
234 case TEXT_RANGE_WORLD:
235 {
236 SessionMap const& smap = sWorld->GetAllSessions();
237 for (SessionMap::const_iterator itr = smap.begin(); itr != smap.end(); ++itr)
238 if (Player* player = itr->second->GetPlayer())
239 if ((teamId == TEAM_NEUTRAL || player->GetTeamId() == teamId) && (!gmOnly || player->IsGameMaster()))
240 localizer(player);
241 return;
242 }
244 default:
245 break;
246 }
247
248 float dist = GetRangeForChatType(msgType);
249 // xinef: hack for boss emote
250 if (msgType == CHAT_MSG_RAID_BOSS_EMOTE && source->GetMap()->IsDungeon())
251 dist = 250.0f;
252
253 Acore::PlayerDistWorker<CreatureTextLocalizer<Builder> > worker(source, dist, localizer);
254 Cell::VisitWorldObjects(source, worker, dist);
255}
@ TYPEID_PLAYER
Definition: ObjectGuid.h:38
@ TEXT_RANGE_ZONE
Definition: CreatureTextMgr.h:32
@ TEXT_RANGE_AREA
Definition: CreatureTextMgr.h:31
@ TEXT_RANGE_MAP
Definition: CreatureTextMgr.h:33
std::unordered_map< uint32, WorldSession * > SessionMap
Definition: IWorld.h:56
@ CHAT_MSG_MONSTER_WHISPER
Definition: SharedDefines.h:3139
@ CHAT_MSG_RAID_BOSS_WHISPER
Definition: SharedDefines.h:3166
@ TEAM_NEUTRAL
Definition: SharedDefines.h:734
Definition: LinkedList.h:139
Map * GetMap() const
Definition: Object.h:517
uint32 GetAreaId() const
Definition: Object.cpp:3083
uint32 GetZoneId() const
Definition: Object.cpp:3075
Definition: Player.h:1046
static void VisitWorldObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition: CellImpl.h:193
Definition: GridNotifiers.h:589
bool IsDungeon() const
Definition: Map.h:447
PlayerList const & GetPlayers() const
Definition: Map.h:484
Definition: MapRefMgr.h:26
iterator begin()
Definition: MapRefMgr.h:36
iterator end()
Definition: MapRefMgr.h:37
float GetRangeForChatType(ChatMsg msgType) const
Definition: CreatureTextMgr.cpp:311
Definition: CreatureTextMgr.h:123

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(), Object::GetTypeId(), WorldObject::GetZoneId(), Map::IsDungeon(), sWorld, TEAM_NEUTRAL, TEXT_RANGE_AREA, TEXT_RANGE_MAP, TEXT_RANGE_NORMAL, TEXT_RANGE_WORLD, TEXT_RANGE_ZONE, Object::ToPlayer(), TYPEID_PLAYER, and Cell::VisitWorldObjects().

Referenced by SendChat().

◆ SendEmote()

void CreatureTextMgr::SendEmote ( Unit source,
uint32  emote 
)
407{
408 if (!source)
409 return;
410
411 source->HandleEmoteCommand(emote);
412}
void HandleEmoteCommand(uint32 emoteId)
Definition: Unit.cpp:1970

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
339{
340 float dist = GetRangeForChatType(msgType);
341
342 switch (msgType)
343 {
346 {
347 if (range == TEXT_RANGE_NORMAL)//ignores team and gmOnly
348 {
349 if (!target || target->GetTypeId() != TYPEID_PLAYER)
350 return;
351
352 target->ToPlayer()->GetSession()->SendPacket(data);
353 return;
354 }
355 break;
356 }
357 default:
358 break;
359 }
360
361 switch (range)
362 {
363 case TEXT_RANGE_AREA:
364 {
365 uint32 areaId = source->GetAreaId();
366 Map::PlayerList const& players = source->GetMap()->GetPlayers();
367 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
368 if (itr->GetSource()->GetAreaId() == areaId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
369 itr->GetSource()->GetSession()->SendPacket(data);
370 return;
371 }
372 case TEXT_RANGE_ZONE:
373 {
374 uint32 zoneId = source->GetZoneId();
375 Map::PlayerList const& players = source->GetMap()->GetPlayers();
376 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
377 if (itr->GetSource()->GetZoneId() == zoneId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
378 itr->GetSource()->GetSession()->SendPacket(data);
379 return;
380 }
381 case TEXT_RANGE_MAP:
382 {
383 Map::PlayerList const& players = source->GetMap()->GetPlayers();
384 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
385 if ((teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
386 itr->GetSource()->GetSession()->SendPacket(data);
387 return;
388 }
389 case TEXT_RANGE_WORLD:
390 {
391 SessionMap const& smap = sWorld->GetAllSessions();
392 for (SessionMap::const_iterator itr = smap.begin(); itr != smap.end(); ++itr)
393 if (Player* player = itr->second->GetPlayer())
394 if ((teamId == TEAM_NEUTRAL || player->GetTeamId() == teamId) && (!gmOnly || player->IsGameMaster()))
395 player->GetSession()->SendPacket(data);
396 return;
397 }
399 default:
400 break;
401 }
402
403 source->SendMessageToSetInRange(data, dist, true);
404}
virtual void SendMessageToSetInRange(WorldPacket const *data, float dist, bool, bool includeMargin=false, Player const *skipped_rcvr=nullptr) const
Definition: Object.cpp:2055

References MapRefMgr::begin(), CHAT_MSG_MONSTER_WHISPER, CHAT_MSG_RAID_BOSS_WHISPER, MapRefMgr::end(), WorldObject::GetAreaId(), WorldObject::GetMap(), Map::GetPlayers(), GetRangeForChatType(), Player::GetSession(), Object::GetTypeId(), WorldObject::GetZoneId(), WorldObject::SendMessageToSetInRange(), WorldSession::SendPacket(), sWorld, TEAM_NEUTRAL, TEXT_RANGE_AREA, TEXT_RANGE_MAP, TEXT_RANGE_NORMAL, TEXT_RANGE_WORLD, TEXT_RANGE_ZONE, Object::ToPlayer(), and TYPEID_PLAYER.

Referenced by SendSound().

◆ SendSound()

void CreatureTextMgr::SendSound ( Creature source,
uint32  sound,
ChatMsg  msgType,
WorldObject const *  target,
CreatureTextRange  range,
TeamId  teamId,
bool  gmOnly 
)
331{
332 if (!sound || !source)
333 return;
334
335 SendNonChatPacket(source, WorldPackets::Misc::Playsound(sound).Write(), msgType, target, range, teamId, gmOnly);
336}
Definition: MiscPackets.h:83
void SendNonChatPacket(WorldObject *source, WorldPacket const *data, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly) const
Definition: CreatureTextMgr.cpp:338

References SendNonChatPacket().

Referenced by SendChat().

◆ SetRepeatId()

void CreatureTextMgr::SetRepeatId ( Creature source,
uint8  textGroup,
uint8  id 
)
private
415{
416 if (!source)
417 return;
418
419 CreatureTextRepeatIds& repeats = mTextRepeatMap[source->GetGUID()][textGroup];
420 if (std::find(repeats.begin(), repeats.end(), id) == repeats.end())
421 repeats.push_back(id);
422 else
423 LOG_ERROR("sql.sql", "CreatureTextMgr: TextGroup {} for Creature {} ({}), id {} already added",
424 uint32(textGroup), source->GetName(), source->GetGUID().ToString(), uint32(id));
425}

References Object::GetGUID(), WorldObject::GetName(), LOG_ERROR, mTextRepeatMap, and ObjectGuid::ToString().

Referenced by SendChat().

◆ TextExist()

bool CreatureTextMgr::TextExist ( uint32  sourceEntry,
uint8  textGroup 
)
443{
444 if (!sourceEntry)
445 return false;
446
447 CreatureTextMap::const_iterator sList = mTextMap.find(sourceEntry);
448 if (sList == mTextMap.end())
449 {
450 LOG_DEBUG("entities.unit", "CreatureTextMgr::TextExist: Could not find Text for Creature (entry {}) in 'creature_text' table.", sourceEntry);
451 return false;
452 }
453
454 CreatureTextHolder const& textHolder = sList->second;
455 CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
456 if (itr == textHolder.end())
457 {
458 LOG_DEBUG("entities.unit", "CreatureTextMgr::TextExist: Could not find TextGroup {} for Creature (entry {}).", uint32(textGroup), sourceEntry);
459 return false;
460 }
461
462 return true;
463}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171

References LOG_DEBUG, and mTextMap.

Member Data Documentation

◆ mLocaleTextMap

LocaleCreatureTextMap CreatureTextMgr::mLocaleTextMap
private

◆ mTextMap

CreatureTextMap CreatureTextMgr::mTextMap
private

◆ mTextRepeatMap

CreatureTextRepeatMap CreatureTextMgr::mTextRepeatMap
private