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

Detailed Description

Constructor & Destructor Documentation

◆ CreatureTextMgr()

CreatureTextMgr::CreatureTextMgr ( )
inlineprivate
82{ }

◆ ~CreatureTextMgr()

CreatureTextMgr::~CreatureTextMgr ( )
inline
87{ }

Member Function Documentation

◆ GetLocalizedChatString()

std::string CreatureTextMgr::GetLocalizedChatString ( uint32  entry,
uint8  gender,
uint8  textGroup,
uint32  id,
LocaleConstant  locale 
) const
398{
399 CreatureTextMap::const_iterator mapitr = mTextMap.find(entry);
400 if (mapitr == mTextMap.end())
401 return "";
402
403 CreatureTextHolder::const_iterator holderItr = mapitr->second.find(textGroup);
404 if (holderItr == mapitr->second.end())
405 return "";
406
407 CreatureTextGroup::const_iterator groupItr = holderItr->second.begin();
408 for (; groupItr != holderItr->second.end(); ++groupItr)
409 if (groupItr->id == id)
410 break;
411
412 if (groupItr == holderItr->second.end())
413 return "";
414
415 if (locale > MAX_LOCALES)
416 locale = DEFAULT_LOCALE;
417
418 std::string baseText = "";
419
420 BroadcastText const* bct = sObjectMgr->GetBroadcastText(groupItr->BroadcastTextId);
421 if (bct)
422 baseText = bct->GetText(locale, gender);
423 else
424 baseText = groupItr->text;
425
426 if (locale != DEFAULT_LOCALE && !bct)
427 {
428 LocaleCreatureTextMap::const_iterator locItr = mLocaleTextMap.find(CreatureTextId(entry, uint32(textGroup), id));
429 if (locItr != mLocaleTextMap.end())
430 ObjectMgr::GetLocaleString(locItr->second.Text, locale, baseText);
431 }
432
433 return baseText;
434}
#define DEFAULT_LOCALE
Definition Common.h:131
#define MAX_LOCALES
Definition Common.h:133
std::uint32_t uint32
Definition Define.h:107
#define sObjectMgr
Definition ObjectMgr.h:1650
LocaleCreatureTextMap mLocaleTextMap
Definition CreatureTextMgr.h:107
CreatureTextMap mTextMap
Definition CreatureTextMgr.h:106
static std::string_view GetLocaleString(std::vector< std::string > const &data, std::size_t locale)
Definition ObjectMgr.h:1419
Definition ObjectMgr.h:434
std::string const & GetText(LocaleConstant locale=DEFAULT_LOCALE, uint8 gender=GENDER_MALE, bool forceGender=false) const
Definition ObjectMgr.h:456
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
272{
273 float dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY);
274 switch (msgType)
275 {
277 dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL);
278 break;
281 dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE);
282 break;
283 default:
284 break;
285 }
286
287 return dist;
288}
@ CHAT_MSG_RAID_BOSS_EMOTE
Definition SharedDefines.h:3443
@ CHAT_MSG_MONSTER_EMOTE
Definition SharedDefines.h:3418
@ CHAT_MSG_MONSTER_YELL
Definition SharedDefines.h:3416
@ CONFIG_LISTEN_RANGE_YELL
Definition WorldConfig.h:152
@ CONFIG_LISTEN_RANGE_SAY
Definition WorldConfig.h:150
@ CONFIG_LISTEN_RANGE_TEXTEMOTE
Definition WorldConfig.h:151
#define sWorld
Definition World.h:316

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
90{ return mTextMap; }

References mTextMap.

◆ instance()

CreatureTextMgr * CreatureTextMgr::instance ( )
static
76{
78 return &instance;
79}
Definition CreatureTextMgr.h:81
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 GetLocaleByName(const std::string &name)
Definition Common.cpp:42
LocaleConstant
Definition Common.h:117
@ LOCALE_enUS
Definition Common.h:118
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:166
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:382
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 ( )
82{
83 uint32 oldMSTime = getMSTime();
84
85 mTextMap.clear(); // for reload case
86 //all currently used temp texts are NOT reset
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}
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)
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define LOG_WARN(filterType__,...)
Definition Log.h:162
LanguageDesc const * GetLanguageDescByID(uint32 lang)
Definition ObjectMgr.cpp:253
Emote
Definition SharedDefines.h:1904
@ EMOTE_ONESHOT_NONE
Definition SharedDefines.h:1905
ChatMsg
Definition SharedDefines.h:3400
@ CHAT_MSG_SAY
Definition SharedDefines.h:3403
Language
Definition SharedDefines.h:745
@ LANG_UNIVERSAL
Definition SharedDefines.h:746
#define MAX_CHAT_MSG_TYPE
Definition SharedDefines.h:3456
@ WORLD_SEL_CREATURE_TEXT
Definition WorldDatabase.h:34
Definition PreparedStatement.h:157
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 
)
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 = source->GetTextRepeatGroup(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 source->ClearTextRepeatGroup(textGroup);
231 tempGroup = textGroupContainer;
232 }
233
234 auto iter = Acore::Containers::SelectRandomWeightedContainerElement(tempGroup, [](CreatureTextEntry const& t) -> double
235 {
236 return t.probability;
237 });
238
239 ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? iter->type : msgType;
240 Language finalLang = (language == LANG_ADDON) ? iter->lang : language;
241 uint32 finalSound = sound ? sound : iter->sound;
242
243 if (range == TEXT_RANGE_NORMAL)
244 range = iter->TextRange;
245
246 if (finalSound)
247 SendSound(source, finalSound, finalType, target, range, teamId, gmOnly);
248
249 Unit* finalSource = source;
250 if (srcPlr)
251 finalSource = srcPlr;
252
253 if (iter->emote)
254 SendEmote(finalSource, iter->emote);
255
256 if (srcPlr)
257 {
258 PlayerTextBuilder builder(source, finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, target);
259 SendChatPacket(finalSource, builder, finalType, target, range, teamId, gmOnly);
260 }
261 else
262 {
263 CreatureTextBuilder builder(finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, target);
264 SendChatPacket(finalSource, builder, finalType, target, range, teamId, gmOnly);
265 }
266
267 source->SetTextRepeatId(textGroup, iter->id);
268 return iter->duration;
269}
std::vector< CreatureTextEntry > CreatureTextGroup
Definition CreatureTextMgr.h:74
std::unordered_map< uint8, CreatureTextGroup > CreatureTextHolder
Definition CreatureTextMgr.h:75
std::vector< uint8 > CreatureTextRepeatIds
Definition Creature.h:43
@ CHAT_MSG_ADDON
Definition SharedDefines.h:3401
@ LANG_ADDON
Definition SharedDefines.h:764
Definition CreatureTextMgr.cpp:29
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:171
void SendEmote(Unit *source, uint32 emote)
Definition CreatureTextMgr.cpp:366
void SendSound(Creature *source, uint32 sound, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly)
Definition CreatureTextMgr.cpp:290
void SetTextRepeatId(uint8 textGroup, uint8 id)
Definition Creature.cpp:3679
void ClearTextRepeatGroup(uint8 textGroup)
Definition Creature.cpp:3699
CreatureTextRepeatIds const & GetTextRepeatGroup(uint8 textGroup)
Definition Creature.cpp:3688
std::string ToString() const
Definition ObjectGuid.cpp:47
uint32 GetEntry() const
Definition Object.h:116
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
Definition CreatureTextMgr.cpp:52
Definition Unit.h:650
uint8 getGender() const
Definition Unit.h:831
std::string const & GetName() const
Definition Object.h:525
auto SelectRandomWeightedContainerElement(C const &container, std::vector< double > weights) -> decltype(std::begin(container))
Definition Containers.h:175

References CHAT_MSG_ADDON, Creature::ClearTextRepeatGroup(), Object::GetEntry(), Unit::getGender(), Object::GetGUID(), WorldObject::GetName(), Creature::GetTextRepeatGroup(), LANG_ADDON, LOG_ERROR, mTextMap, CreatureTextEntry::probability, Acore::Containers::SelectRandomWeightedContainerElement(), SendChatPacket(), SendEmote(), SendSound(), Creature::SetTextRepeatId(), TEXT_RANGE_NORMAL, and ObjectGuid::ToString().

◆ 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
172{
173 if (!source)
174 return;
175
176 CreatureTextLocalizer<Builder> localizer(builder, msgType);
177
178 switch (msgType)
179 {
182 {
183 if (range == TEXT_RANGE_NORMAL) // ignores team and GM only
184 {
185 if (!target || !target->IsPlayer())
186 return;
187
188 localizer(const_cast<Player*>(target->ToPlayer()));
189 return;
190 }
191 break;
192 }
193 default:
194 break;
195 }
196
197 switch (range)
198 {
199 case TEXT_RANGE_AREA:
200 {
201 uint32 areaId = source->GetAreaId();
202 Map::PlayerList const& players = source->GetMap()->GetPlayers();
203 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
204 if (itr->GetSource()->GetAreaId() == areaId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
205 localizer(itr->GetSource());
206 return;
207 }
208 case TEXT_RANGE_ZONE:
209 {
210 uint32 zoneId = source->GetZoneId();
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()->GetZoneId() == zoneId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
214 localizer(itr->GetSource());
215 return;
216 }
217 case TEXT_RANGE_MAP:
218 {
219 Map::PlayerList const& players = source->GetMap()->GetPlayers();
220 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
221 if ((teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
222 localizer(itr->GetSource());
223 return;
224 }
225 case TEXT_RANGE_WORLD:
226 {
227 WorldSessionMgr::SessionMap const& smap = sWorldSessionMgr->GetAllSessions();
228 for (WorldSessionMgr::SessionMap::const_iterator itr = smap.begin(); itr != smap.end(); ++itr)
229 if (Player* player = itr->second->GetPlayer())
230 if ((teamId == TEAM_NEUTRAL || player->GetTeamId() == teamId) && (!gmOnly || player->IsGameMaster()))
231 localizer(player);
232 return;
233 }
235 default:
236 break;
237 }
238
239 float dist = GetRangeForChatType(msgType);
240 // xinef: hack for boss emote
241 if (msgType == CHAT_MSG_RAID_BOSS_EMOTE && source->GetMap()->IsDungeon())
242 dist = 250.0f;
243
244 Acore::PlayerDistWorker<CreatureTextLocalizer<Builder> > worker(source, dist, localizer);
245 Cell::VisitObjects(source, worker, dist);
246}
@ 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:3417
@ CHAT_MSG_RAID_BOSS_WHISPER
Definition SharedDefines.h:3444
@ TEAM_NEUTRAL
Definition SharedDefines.h:773
#define sWorldSessionMgr
Definition WorldSessionMgr.h:108
Definition CreatureTextMgr.h:114
float GetRangeForChatType(ChatMsg msgType) const
Definition CreatureTextMgr.cpp:271
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:295
PlayerList const & GetPlayers() const
Definition Map.h:326
Definition Player.h:1071
Map * GetMap() const
Definition Object.h:621
uint32 GetAreaId() const
Definition Object.cpp:3071
uint32 GetZoneId() const
Definition Object.cpp:3063
std::unordered_map< uint32, WorldSession * > SessionMap
Definition WorldSessionMgr.h:56
Definition GridNotifiers.h:583
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 
)
367{
368 if (!source)
369 return;
370
371 source->HandleEmoteCommand(emote);
372}
void HandleEmoteCommand(uint32 emoteId)
Definition Unit.cpp:2035

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
299{
300 float dist = GetRangeForChatType(msgType);
301
302 switch (msgType)
303 {
306 {
307 if (range == TEXT_RANGE_NORMAL) // ignores team and GM only
308 {
309 if (!target || !target->IsPlayer())
310 return;
311
312 target->ToPlayer()->SendDirectMessage(data);
313 return;
314 }
315 break;
316 }
317 default:
318 break;
319 }
320
321 switch (range)
322 {
323 case TEXT_RANGE_AREA:
324 {
325 uint32 areaId = source->GetAreaId();
326 Map::PlayerList const& players = source->GetMap()->GetPlayers();
327 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
328 if (itr->GetSource()->GetAreaId() == areaId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
329 itr->GetSource()->SendDirectMessage(data);
330 return;
331 }
332 case TEXT_RANGE_ZONE:
333 {
334 uint32 zoneId = source->GetZoneId();
335 Map::PlayerList const& players = source->GetMap()->GetPlayers();
336 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
337 if (itr->GetSource()->GetZoneId() == zoneId && (teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
338 itr->GetSource()->SendDirectMessage(data);
339 return;
340 }
341 case TEXT_RANGE_MAP:
342 {
343 Map::PlayerList const& players = source->GetMap()->GetPlayers();
344 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
345 if ((teamId == TEAM_NEUTRAL || itr->GetSource()->GetTeamId() == teamId) && (!gmOnly || itr->GetSource()->IsGameMaster()))
346 itr->GetSource()->SendDirectMessage(data);
347 return;
348 }
349 case TEXT_RANGE_WORLD:
350 {
351 WorldSessionMgr::SessionMap const& sessionMap = sWorldSessionMgr->GetAllSessions();
352 for (WorldSessionMgr::SessionMap::const_iterator itr = sessionMap.begin(); itr != sessionMap.end(); ++itr)
353 if (Player* player = itr->second->GetPlayer())
354 if ((teamId == TEAM_NEUTRAL || player->GetTeamId() == teamId) && (!gmOnly || player->IsGameMaster()))
355 player->SendDirectMessage(data);
356 return;
357 }
359 default:
360 break;
361 }
362
363 source->SendMessageToSetInRange(data, dist, true);
364}
virtual void SendMessageToSetInRange(WorldPacket const *data, float dist, bool self) const
Definition Object.cpp:2096

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 
)
291{
292 if (!sound || !source)
293 return;
294
295 SendNonChatPacket(source, WorldPackets::Misc::Playsound(sound).Write(), msgType, target, range, teamId, gmOnly);
296}
void SendNonChatPacket(WorldObject *source, WorldPacket const *data, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly) const
Definition CreatureTextMgr.cpp:298
Definition MiscPackets.h:85

References SendNonChatPacket().

Referenced by SendChat().

◆ TextExist()

bool CreatureTextMgr::TextExist ( uint32  sourceEntry,
uint8  textGroup 
)
375{
376 if (!sourceEntry)
377 return false;
378
379 CreatureTextMap::const_iterator sList = mTextMap.find(sourceEntry);
380 if (sList == mTextMap.end())
381 {
382 LOG_DEBUG("entities.unit", "CreatureTextMgr::TextExist: Could not find Text for Creature (entry {}) in 'creature_text' table.", sourceEntry);
383 return false;
384 }
385
386 CreatureTextHolder const& textHolder = sList->second;
387 CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
388 if (itr == textHolder.end())
389 {
390 LOG_DEBUG("entities.unit", "CreatureTextMgr::TextExist: Could not find TextGroup {} for Creature (entry {}).", uint32(textGroup), sourceEntry);
391 return false;
392 }
393
394 return true;
395}
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170

References LOG_DEBUG, and mTextMap.

Member Data Documentation

◆ mLocaleTextMap

LocaleCreatureTextMap CreatureTextMgr::mLocaleTextMap
private

◆ mTextMap

CreatureTextMap CreatureTextMgr::mTextMap
private

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