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
86{ }

◆ ~CreatureTextMgr()

CreatureTextMgr::~CreatureTextMgr ( )
inline
91{ }

Member Function Documentation

◆ GetLocalizedChatString()

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

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

◆ GetRangeForChatType()

float CreatureTextMgr::GetRangeForChatType ( ChatMsg  msgType) const
private
311{
312 float dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY);
313 switch (msgType)
314 {
316 dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL);
317 break;
320 dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE);
321 break;
322 default:
323 break;
324 }
325
326 return dist;
327}
@ CHAT_MSG_RAID_BOSS_EMOTE
Definition: SharedDefines.h:3193
@ CHAT_MSG_MONSTER_EMOTE
Definition: SharedDefines.h:3168
@ CHAT_MSG_MONSTER_YELL
Definition: SharedDefines.h:3166
@ CONFIG_LISTEN_RANGE_YELL
Definition: IWorld.h:197
@ CONFIG_LISTEN_RANGE_SAY
Definition: IWorld.h:195
@ CONFIG_LISTEN_RANGE_TEXTEMOTE
Definition: IWorld.h:196
#define sWorld
Definition: World.h:443

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
427{
428 ASSERT(source);//should never happen
430
431 CreatureTextRepeatMap::const_iterator mapItr = mTextRepeatMap.find(source->GetGUID());
432 if (mapItr != mTextRepeatMap.end())
433 {
434 CreatureTextRepeatGroup::const_iterator groupItr = (*mapItr).second.find(textGroup);
435 if (groupItr != mapItr->second.end())
436 ids = groupItr->second;
437 }
438 return ids;
439}
#define ASSERT
Definition: Errors.h:68
std::vector< uint8 > CreatureTextRepeatIds
Definition: CreatureTextMgr.h:80
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
CreatureTextRepeatMap mTextRepeatMap
Definition: CreatureTextMgr.h:114

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

Referenced by SendChat().

◆ GetTextMap()

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

References mTextMap.

◆ instance()

CreatureTextMgr * CreatureTextMgr::instance ( )
static
76{
78 return &instance;
79}
Definition: CreatureTextMgr.h:85
static CreatureTextMgr * instance()
Definition: CreatureTextMgr.cpp:75

References instance().

Referenced by instance().

◆ LoadCreatureTextLocales()

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

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

◆ LoadCreatureTexts()

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

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 
)
200{
201 if (!source)
202 return 0;
203
204 CreatureTextMap::const_iterator sList = mTextMap.find(source->GetEntry());
205 if (sList == mTextMap.end())
206 {
207 LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find Text for Creature({}) Entry {} in 'creature_text' table. Ignoring.", source->GetName(), source->GetEntry());
208 return 0;
209 }
210
211 CreatureTextHolder const& textHolder = sList->second;
212 CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
213 if (itr == textHolder.end())
214 {
215 LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find TextGroup {} for Creature {} ({}). Ignoring.",
216 uint32(textGroup), source->GetName(), source->GetGUID().ToString());
217 return 0;
218 }
219
220 CreatureTextGroup const& textGroupContainer = itr->second; //has all texts in the group
221 CreatureTextRepeatIds repeatGroup = GetRepeatGroup(source, textGroup);//has all textIDs from the group that were already said
222 CreatureTextGroup tempGroup;//will use this to talk after sorting repeatGroup
223
224 for (CreatureTextGroup::const_iterator giter = textGroupContainer.begin(); giter != textGroupContainer.end(); ++giter)
225 if (std::find(repeatGroup.begin(), repeatGroup.end(), giter->id) == repeatGroup.end())
226 tempGroup.push_back(*giter);
227
228 if (tempGroup.empty())
229 {
230 CreatureTextRepeatMap::iterator mapItr = mTextRepeatMap.find(source->GetGUID());
231 if (mapItr != mTextRepeatMap.end())
232 {
233 CreatureTextRepeatGroup::iterator groupItr = mapItr->second.find(textGroup);
234 groupItr->second.clear();
235 }
236
237 tempGroup = textGroupContainer;
238 }
239
240 uint8 count = 0;
241 float lastChance = -1;
242 bool isEqualChanced = true;
243
244 float totalChance = 0;
245
246 for (CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter)
247 {
248 if (lastChance >= 0 && lastChance != iter->probability)
249 isEqualChanced = false;
250
251 lastChance = iter->probability;
252 totalChance += iter->probability;
253 ++count;
254 }
255
256 int32 offset = -1;
257 if (!isEqualChanced)
258 {
259 for (CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter)
260 {
261 uint32 chance = uint32(iter->probability);
262 uint32 r = urand(0, 100);
263 ++offset;
264 if (r <= chance)
265 break;
266 }
267 }
268
269 uint32 pos = 0;
270 if (isEqualChanced || offset < 0)
271 pos = urand(0, count - 1);
272 else if (offset >= 0)
273 pos = offset;
274
275 CreatureTextGroup::const_iterator iter = tempGroup.begin() + pos;
276
277 ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? iter->type : msgType;
278 Language finalLang = (language == LANG_ADDON) ? iter->lang : language;
279 uint32 finalSound = sound ? sound : iter->sound;
280
281 if (range == TEXT_RANGE_NORMAL)
282 range = iter->TextRange;
283
284 if (finalSound)
285 SendSound(source, finalSound, finalType, target, range, teamId, gmOnly);
286
287 Unit* finalSource = source;
288 if (srcPlr)
289 finalSource = srcPlr;
290
291 if (iter->emote)
292 SendEmote(finalSource, iter->emote);
293
294 if (srcPlr)
295 {
296 PlayerTextBuilder builder(source, finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, target);
297 SendChatPacket(finalSource, builder, finalType, target, range, teamId, gmOnly);
298 }
299 else
300 {
301 CreatureTextBuilder builder(finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, target);
302 SendChatPacket(finalSource, builder, finalType, target, range, teamId, gmOnly);
303 }
304 if (isEqualChanced || (!isEqualChanced && totalChance == 100.0f))
305 SetRepeatId(source, textGroup, iter->id);
306
307 return iter->duration;
308}
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:44
std::int32_t int32
Definition: Define.h:103
@ CHAT_MSG_ADDON
Definition: SharedDefines.h:3151
@ LANG_ADDON
Definition: SharedDefines.h:753
std::vector< CreatureTextEntry > CreatureTextGroup
Definition: CreatureTextMgr.h:73
std::unordered_map< uint8, CreatureTextGroup > CreatureTextHolder
Definition: CreatureTextMgr.h:74
uint32 GetEntry() const
Definition: Object.h:115
std::string const & GetName() const
Definition: Object.h:463
std::string ToString() const
Definition: ObjectGuid.cpp:47
Definition: Unit.h:630
uint8 getGender() const
Definition: Unit.h:805
Definition: CreatureTextMgr.cpp:29
Definition: CreatureTextMgr.cpp:52
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:179
void SetRepeatId(Creature *source, uint8 textGroup, uint8 id)
Definition: CreatureTextMgr.cpp:413
void SendEmote(Unit *source, uint32 emote)
Definition: CreatureTextMgr.cpp:405
void SendSound(Creature *source, uint32 sound, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly)
Definition: CreatureTextMgr.cpp:329
CreatureTextRepeatIds GetRepeatGroup(Creature *source, uint8 textGroup)
Definition: CreatureTextMgr.cpp:426

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

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

Referenced by SendChat().

◆ SendEmote()

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

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

References MapRefMgr::begin(), CHAT_MSG_MONSTER_WHISPER, CHAT_MSG_RAID_BOSS_WHISPER, MapRefMgr::end(), WorldObject::GetAreaId(), WorldObject::GetMap(), Map::GetPlayers(), GetRangeForChatType(), Player::GetSession(), WorldObject::GetZoneId(), Object::IsPlayer(), WorldObject::SendMessageToSetInRange(), WorldSession::SendPacket(), sWorld, 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 
)
330{
331 if (!sound || !source)
332 return;
333
334 SendNonChatPacket(source, WorldPackets::Misc::Playsound(sound).Write(), msgType, target, range, teamId, gmOnly);
335}
Definition: MiscPackets.h:85
void SendNonChatPacket(WorldObject *source, WorldPacket const *data, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly) const
Definition: CreatureTextMgr.cpp:337

References SendNonChatPacket().

Referenced by SendChat().

◆ SetRepeatId()

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

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

Referenced by SendChat().

◆ TextExist()

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

References LOG_DEBUG, and mTextMap.

Member Data Documentation

◆ mLocaleTextMap

LocaleCreatureTextMap CreatureTextMgr::mLocaleTextMap
private

◆ mTextMap

CreatureTextMap CreatureTextMgr::mTextMap
private

◆ mTextRepeatMap

CreatureTextRepeatMap CreatureTextMgr::mTextRepeatMap
private