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
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:81
#define MAX_LOCALES
Definition: Common.h:83
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
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}
@ CONFIG_LISTEN_RANGE_YELL
Definition: IWorld.h:197
@ CONFIG_LISTEN_RANGE_SAY
Definition: IWorld.h:195
@ CONFIG_LISTEN_RANGE_TEXTEMOTE
Definition: IWorld.h:196
@ 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
#define sWorld
Definition: World.h:447

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: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
76{
78 return &instance;
79}
Definition: CreatureTextMgr.h:86
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:33
LocaleConstant
Definition: Common.h:67
@ LOCALE_enUS
Definition: Common.h:68
std::uint8_t uint8
Definition: Define.h:110
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
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:436
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 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
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:307
CreatureTextRange
Definition: CreatureTextMgr.h:29
@ TEXT_RANGE_WORLD
Definition: CreatureTextMgr.h:34
@ TEXT_RANGE_NORMAL
Definition: CreatureTextMgr.h:30
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
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 
)
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}
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:3151
@ LANG_ADDON
Definition: SharedDefines.h:753
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:1302
uint8 getGender() const
Definition: Unit.h:1440
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:180
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
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:3167
@ CHAT_MSG_RAID_BOSS_WHISPER
Definition: SharedDefines.h:3194
@ TEAM_NEUTRAL
Definition: SharedDefines.h:762
Definition: LinkedList.h:139
Map * GetMap() const
Definition: Object.h:517
uint32 GetAreaId() const
Definition: Object.cpp:3108
uint32 GetZoneId() const
Definition: Object.cpp:3100
Definition: Player.h:1056
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:448
PlayerList const & GetPlayers() const
Definition: Map.h:485
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: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 
)
406{
407 if (!source)
408 return;
409
410 source->HandleEmoteCommand(emote);
411}
void HandleEmoteCommand(uint32 emoteId)
Definition: Unit.cpp:1980

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 gmOnly
347 {
348 if (!target || target->GetTypeId() != TYPEID_PLAYER)
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, bool includeMargin=false, Player const *skipped_rcvr=nullptr) const
Definition: Object.cpp:2080

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