TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CreatureTextMgr Class Reference

#include <CreatureTextMgr.h>

Public Member Functions

void LoadCreatureTexts ()
 
void LoadCreatureTextLocales ()
 
CreatureTextMap constGetTextMap () const
 
uint32 SendChat (Creature *source, uint8 textGroup, WorldObject const *whisperTarget=nullptr, ChatMsg msgType=CHAT_MSG_ADDON, Language language=LANG_ADDON, CreatureTextRange range=TEXT_RANGE_NORMAL, uint32 sound=0, Team team=TEAM_OTHER, bool gmOnly=false, Player *srcPlr=nullptr)
 
bool TextExist (uint32 sourceEntry, uint8 textGroup) const
 
std::string GetLocalizedChatString (uint32 entry, uint8 gender, uint8 textGroup, uint32 id, LocaleConstant locale) const
 

Static Public Member Functions

static CreatureTextMgrinstance ()
 
static void SendSound (Creature *source, uint32 sound, ChatMsg msgType, WorldObject const *whisperTarget=nullptr, CreatureTextRange range=TEXT_RANGE_NORMAL, Team team=TEAM_OTHER, bool gmOnly=false)
 
static void SendEmote (Unit *source, uint32 emote)
 
template<class Builder >
static void SendChatPacket (WorldObject *source, Builder const &builder, ChatMsg msgType, WorldObject const *whisperTarget=nullptr, CreatureTextRange range=TEXT_RANGE_NORMAL, Team team=TEAM_OTHER, bool gmOnly=false)
 

Private Member Functions

 CreatureTextMgr ()
 
 ~CreatureTextMgr ()
 
CreatureTextRepeatIds GetRepeatGroup (Creature *source, uint8 textGroup) const
 
void SetRepeatId (Creature *source, uint8 textGroup, uint8 id)
 

Static Private Member Functions

static void SendNonChatPacket (WorldObject *source, WorldPacket const *data, ChatMsg msgType, WorldObject const *whisperTarget, CreatureTextRange range, Team team, bool gmOnly)
 
static float GetRangeForChatType (ChatMsg msgType)
 

Private Attributes

CreatureTextMap mTextMap
 
LocaleCreatureTextMap mLocaleTextMap
 

Constructor & Destructor Documentation

CreatureTextMgr::CreatureTextMgr ( )
inlineprivate
82 { }
CreatureTextMgr::~CreatureTextMgr ( )
inlineprivate
83 { }

Member Function Documentation

std::string CreatureTextMgr::GetLocalizedChatString ( uint32  entry,
uint8  gender,
uint8  textGroup,
uint32  id,
LocaleConstant  locale 
) const
430 {
431  CreatureTextMap::const_iterator mapitr = mTextMap.find(entry);
432  if (mapitr == mTextMap.end())
433  return "";
434 
435  CreatureTextHolder::const_iterator holderItr = mapitr->second.find(textGroup);
436  if (holderItr == mapitr->second.end())
437  return "";
438 
439  CreatureTextGroup::const_iterator groupItr = holderItr->second.begin();
440  for (; groupItr != holderItr->second.end(); ++groupItr)
441  if (groupItr->id == id)
442  break;
443 
444  if (groupItr == holderItr->second.end())
445  return "";
446 
447  if (locale > MAX_LOCALES)
448  locale = DEFAULT_LOCALE;
449 
450  std::string baseText = "";
451  BroadcastTextEntry const* bct = sBroadcastTextStore.LookupEntry(groupItr->BroadcastTextId);
452 
453  if (bct)
454  baseText = DB2Manager::GetBroadcastTextValue(bct, locale, gender);
455  else
456  baseText = groupItr->text;
457 
458  if (locale != DEFAULT_LOCALE && !bct)
459  {
460  LocaleCreatureTextMap::const_iterator locItr = mLocaleTextMap.find(CreatureTextId(entry, uint32(textGroup), id));
461  if (locItr != mLocaleTextMap.end())
462  ObjectMgr::GetLocaleString(locItr->second.Text, locale, baseText);
463  }
464 
465  return baseText;
466 }
DB2Storage< BroadcastTextEntry > sBroadcastTextStore("BroadcastText.db2", BroadcastTextFormat, HOTFIX_SEL_BROADCAST_TEXT)
static char const * GetBroadcastTextValue(BroadcastTextEntry const *broadcastText, LocaleConstant locale=DEFAULT_LOCALE, uint8 gender=GENDER_MALE, bool forceGender=false)
Definition: DB2Stores.cpp:610
Definition: DB2Structure.h:112
#define MAX_LOCALES
Definition: Common.h:136
LocaleCreatureTextMap mLocaleTextMap
Definition: CreatureTextMgr.h:110
CreatureTextMap mTextMap
Definition: CreatureTextMgr.h:109
static void GetLocaleString(StringVector const &data, LocaleConstant localeConstant, std::string &value)
Definition: ObjectMgr.h:1345
uint32_t uint32
Definition: g3dmath.h:168
Definition: CreatureTextMgr.h:59
#define DEFAULT_LOCALE
Definition: Common.h:134

+ Here is the call graph for this function:

float CreatureTextMgr::GetRangeForChatType ( ChatMsg  msgType)
staticprivate
278 {
279  float dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY);
280  switch (msgType)
281  {
283  dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL);
284  break;
287  dist = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE);
288  break;
289  default:
290  break;
291  }
292 
293  return dist;
294 }
Definition: World.h:190
#define sWorld
Definition: World.h:887
Definition: SharedDefines.h:4247
Definition: SharedDefines.h:4245
Definition: World.h:191
Definition: World.h:192
Definition: SharedDefines.h:4272

+ Here is the caller graph for this function:

CreatureTextRepeatIds CreatureTextMgr::GetRepeatGroup ( Creature source,
uint8  textGroup 
) const
private
400 {
401  ASSERT(source);//should never happen
402 
403  return source->GetTextRepeatGroup(textGroup);
404 }
#define ASSERT
Definition: Errors.h:55
CreatureTextRepeatIds GetTextRepeatGroup(uint8 textGroup)
Definition: Creature.cpp:2804

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CreatureTextMap const& CreatureTextMgr::GetTextMap ( ) const
inline
90 { return mTextMap; }
CreatureTextMap mTextMap
Definition: CreatureTextMgr.h:109
CreatureTextMgr * CreatureTextMgr::instance ( )
static
80 {
82  return &instance;
83 }
static CreatureTextMgr * instance()
Definition: CreatureTextMgr.cpp:79
Definition: CreatureTextMgr.h:79
void CreatureTextMgr::LoadCreatureTextLocales ( )
178 {
179  uint32 oldMSTime = getMSTime();
180 
181  mLocaleTextMap.clear(); // for reload case
182 
183  QueryResult result = WorldDatabase.Query("SELECT entry, groupid, id, text_loc1, text_loc2, text_loc3, text_loc4, text_loc5, text_loc6, text_loc7, text_loc8 FROM locales_creature_text");
184 
185  if (!result)
186  return;
187 
188  uint32 textCount = 0;
189 
190  do
191  {
192  Field* fields = result->Fetch();
193  CreatureTextLocale& loc = mLocaleTextMap[CreatureTextId(fields[0].GetUInt32(), uint32(fields[1].GetUInt8()), uint32(fields[2].GetUInt8()))];
194  for (uint8 i = OLD_TOTAL_LOCALES - 1; i > 0; --i)
195  {
196  LocaleConstant locale = LocaleConstant(i);
197  ObjectMgr::AddLocaleString(fields[3 + i - 1].GetString(), locale, loc.Text);
198  }
199 
200  ++textCount;
201  } while (result->NextRow());
202 
203  TC_LOG_INFO("server.loading", ">> Loaded %u creature localized texts in %u ms", textCount, GetMSTimeDiffToNow(oldMSTime));
204 }
Class used to access individual fields of database query result.
Definition: Field.h:56
const uint8 OLD_TOTAL_LOCALES
Definition: Common.h:133
uint32 getMSTime()
Definition: Timer.h:24
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Definition: CreatureTextMgr.h:54
LocaleConstant
Definition: Common.h:115
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
static void AddLocaleString(std::string const &value, LocaleConstant localeConstant, StringVector &data)
Definition: ObjectMgr.cpp:295
LocaleCreatureTextMap mLocaleTextMap
Definition: CreatureTextMgr.h:110
uint8_t uint8
Definition: Define.h:152
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
uint32_t uint32
Definition: g3dmath.h:168
Definition: CreatureTextMgr.h:59
StringVector Text
Definition: CreatureTextMgr.h:56

+ Here is the call graph for this function:

void CreatureTextMgr::LoadCreatureTexts ( )
86 {
87  uint32 oldMSTime = getMSTime();
88 
89  mTextMap.clear(); // for reload case
90  //all currently used temp texts are NOT reset
91 
94 
95  if (!result)
96  {
97  TC_LOG_INFO("server.loading", ">> Loaded 0 ceature texts. DB table `creature_text` is empty.");
98 
99  return;
100  }
101 
102  uint32 textCount = 0;
103 
104  do
105  {
106  Field* fields = result->Fetch();
107  CreatureTextEntry temp;
108 
109  temp.entry = fields[0].GetUInt32();
110  temp.group = fields[1].GetUInt8();
111  temp.id = fields[2].GetUInt8();
112  temp.text = fields[3].GetString();
113  temp.type = ChatMsg(fields[4].GetUInt8());
114  temp.lang = Language(fields[5].GetUInt8());
115  temp.probability = fields[6].GetFloat();
116  temp.emote = Emote(fields[7].GetUInt32());
117  temp.duration = fields[8].GetUInt32();
118  temp.sound = fields[9].GetUInt32();
119  temp.BroadcastTextId = fields[10].GetUInt32();
120  temp.TextRange = CreatureTextRange(fields[11].GetUInt8());
121 
122  if (temp.sound)
123  {
124  if (!sSoundEntriesStore.LookupEntry(temp.sound))
125  {
126  TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Sound %u but sound does not exist.", temp.entry, temp.group, temp.sound);
127  temp.sound = 0;
128  }
129  }
130 
131  if (!GetLanguageDescByID(temp.lang))
132  {
133  TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` using Language %u but Language does not exist.", temp.entry, temp.group, uint32(temp.lang));
134  temp.lang = LANG_UNIVERSAL;
135  }
136 
137  if (temp.type >= MAX_CHAT_MSG_TYPE)
138  {
139  TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Type %u but this Chat Type does not exist.", temp.entry, temp.group, uint32(temp.type));
140  temp.type = CHAT_MSG_SAY;
141  }
142 
143  if (temp.emote)
144  {
145  if (!sEmotesStore.LookupEntry(temp.emote))
146  {
147  TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Emote %u but emote does not exist.", temp.entry, temp.group, uint32(temp.emote));
148  temp.emote = EMOTE_ONESHOT_NONE;
149  }
150  }
151 
152  if (temp.BroadcastTextId)
153  {
154  if (!sBroadcastTextStore.LookupEntry(temp.BroadcastTextId))
155  {
156  TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has non-existing or incompatible BroadcastTextId %u.", temp.entry, temp.group, temp.id, temp.BroadcastTextId);
157  temp.BroadcastTextId = 0;
158  }
159  }
160 
161  if (temp.TextRange > TEXT_RANGE_WORLD)
162  {
163  TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has incorrect TextRange %u.", temp.entry, temp.group, temp.id, temp.TextRange);
165  }
166 
167  // add the text into our entry's group
168  mTextMap[temp.entry][temp.group].push_back(temp);
169 
170  ++textCount;
171  }
172  while (result->NextRow());
173 
174  TC_LOG_INFO("server.loading", ">> Loaded %u creature texts for " SZFMTD " creatures in %u ms", textCount, mTextMap.size(), GetMSTimeDiffToNow(oldMSTime));
175 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: SharedDefines.h:961
Definition: SharedDefines.h:4300
float GetFloat() const
Definition: Field.h:222
Emote emote
Definition: CreatureTextMgr.h:47
Definition: CreatureTextMgr.h:31
uint8 id
Definition: CreatureTextMgr.h:42
Emote
Definition: SharedDefines.h:2410
#define SZFMTD
Definition: Define.h:143
DB2Storage< BroadcastTextEntry > sBroadcastTextStore("BroadcastText.db2", BroadcastTextFormat, HOTFIX_SEL_BROADCAST_TEXT)
uint8 group
Definition: CreatureTextMgr.h:41
Definition: CreatureTextMgr.h:35
CreatureTextRange TextRange
Definition: CreatureTextMgr.h:51
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 getMSTime()
Definition: Timer.h:24
ChatMsg
Definition: SharedDefines.h:4228
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
uint32 entry
Definition: CreatureTextMgr.h:40
Definition: PreparedStatement.h:74
uint32 duration
Definition: CreatureTextMgr.h:48
DBCStorage< EmotesEntry > sEmotesStore(Emotesfmt)
ChatMsg type
Definition: CreatureTextMgr.h:44
uint32 BroadcastTextId
Definition: CreatureTextMgr.h:50
uint8 GetUInt8() const
Definition: Field.h:70
Definition: WorldDatabase.h:35
Definition: CreatureTextMgr.h:38
Language
Definition: SharedDefines.h:959
uint32_t uint32
Definition: Define.h:150
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
CreatureTextRange
Definition: CreatureTextMgr.h:29
std::string text
Definition: CreatureTextMgr.h:43
LanguageDesc const * GetLanguageDescByID(uint32 lang)
Definition: ObjectMgr.cpp:192
uint32 sound
Definition: CreatureTextMgr.h:49
Language lang
Definition: CreatureTextMgr.h:45
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
float probability
Definition: CreatureTextMgr.h:46
uint32 GetUInt32() const
Definition: Field.h:146
CreatureTextMap mTextMap
Definition: CreatureTextMgr.h:109
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: SharedDefines.h:4232
std::string GetString() const
Definition: Field.h:276
Definition: SharedDefines.h:2412
DB2Storage< SoundEntriesEntry > sSoundEntriesStore("SoundEntries.db2", SoundEntriesFormat, HOTFIX_SEL_SOUND_ENTRIES)

+ Here is the call graph for this function:

uint32 CreatureTextMgr::SendChat ( Creature source,
uint8  textGroup,
WorldObject const whisperTarget = nullptr,
ChatMsg  msgType = CHAT_MSG_ADDON,
Language  language = LANG_ADDON,
CreatureTextRange  range = TEXT_RANGE_NORMAL,
uint32  sound = 0,
Team  team = TEAM_OTHER,
bool  gmOnly = false,
Player srcPlr = nullptr 
)
207 {
208  if (!source)
209  return 0;
210 
211  CreatureTextMap::const_iterator sList = mTextMap.find(source->GetEntry());
212  if (sList == mTextMap.end())
213  {
214  TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find Text for Creature %s (%s) in 'creature_text' table. Ignoring.", source->GetName().c_str(), source->GetGUID().ToString().c_str());
215  return 0;
216  }
217 
218  CreatureTextHolder const& textHolder = sList->second;
219  CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
220  if (itr == textHolder.end())
221  {
222  TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find TextGroup %u for Creature %s (%s) in 'creature_text' table. Ignoring.", uint32(textGroup), source->GetName().c_str(), source->GetGUID().ToString().c_str());
223  return 0;
224  }
225 
226  CreatureTextGroup const& textGroupContainer = itr->second; //has all texts in the group
227  CreatureTextRepeatIds repeatGroup = GetRepeatGroup(source, textGroup);//has all textIDs from the group that were already said
228  CreatureTextGroup tempGroup;//will use this to talk after sorting repeatGroup
229 
230  for (CreatureTextGroup::const_iterator giter = textGroupContainer.begin(); giter != textGroupContainer.end(); ++giter)
231  if (std::find(repeatGroup.begin(), repeatGroup.end(), giter->id) == repeatGroup.end())
232  tempGroup.push_back(*giter);
233 
234  if (tempGroup.empty())
235  {
236  source->ClearTextRepeatGroup(textGroup);
237  tempGroup = textGroupContainer;
238  }
239 
240  auto iter = Trinity::Containers::SelectRandomWeightedContainerElement(tempGroup, [](CreatureTextEntry const& t) -> double
241  {
242  return t.probability;
243  });
244 
245  ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? iter->type : msgType;
246  Language finalLang = (language == LANG_ADDON) ? iter->lang : language;
247  uint32 finalSound = sound ? sound : iter->sound;
248 
249  if (range == TEXT_RANGE_NORMAL)
250  range = iter->TextRange;
251 
252  if (finalSound)
253  SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly);
254 
255  Unit* finalSource = source;
256  if (srcPlr)
257  finalSource = srcPlr;
258 
259  if (iter->emote)
260  SendEmote(finalSource, iter->emote);
261 
262  if (srcPlr)
263  {
264  PlayerTextBuilder builder(source, finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, whisperTarget);
265  SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly);
266  }
267  else
268  {
269  CreatureTextBuilder builder(finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, whisperTarget);
270  SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly);
271  }
272 
273  SetRepeatId(source, textGroup, iter->id);
274  return iter->duration;
275 }
Definition: CreatureTextMgr.cpp:30
void SetRepeatId(Creature *source, uint8 textGroup, uint8 id)
Definition: CreatureTextMgr.cpp:391
Definition: CreatureTextMgr.h:31
static void SendChatPacket(WorldObject *source, Builder const &builder, ChatMsg msgType, WorldObject const *whisperTarget=nullptr, CreatureTextRange range=TEXT_RANGE_NORMAL, Team team=TEAM_OTHER, bool gmOnly=false)
Definition: CreatureTextMgr.h:166
std::vector< CreatureTextEntry > CreatureTextGroup
Definition: CreatureTextMgr.h:73
C::const_iterator SelectRandomWeightedContainerElement(C const &container, std::vector< double > weights)
Definition: Containers.h:85
std::string const & GetName() const
Definition: Object.h:479
std::vector< uint8 > CreatureTextRepeatIds
Definition: Creature.h:464
ChatMsg
Definition: SharedDefines.h:4228
Definition: CreatureTextMgr.h:38
Language
Definition: SharedDefines.h:959
uint32_t uint32
Definition: Define.h:150
CreatureTextRepeatIds GetRepeatGroup(Creature *source, uint8 textGroup) const
Definition: CreatureTextMgr.cpp:399
Definition: CreatureTextMgr.cpp:54
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Definition: SharedDefines.h:4230
float probability
Definition: CreatureTextMgr.h:46
static void SendSound(Creature *source, uint32 sound, ChatMsg msgType, WorldObject const *whisperTarget=nullptr, CreatureTextRange range=TEXT_RANGE_NORMAL, Team team=TEAM_OTHER, bool gmOnly=false)
Definition: CreatureTextMgr.cpp:296
uint8 getGender() const
Definition: Unit.h:1415
CreatureTextMap mTextMap
Definition: CreatureTextMgr.h:109
uint32 GetEntry() const
Definition: Object.h:107
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
std::unordered_map< uint8, CreatureTextGroup > CreatureTextHolder
Definition: CreatureTextMgr.h:74
uint32_t uint32
Definition: g3dmath.h:168
static void SendEmote(Unit *source, uint32 emote)
Definition: CreatureTextMgr.cpp:383
Definition: Unit.h:1305
std::string ToString() const
Definition: ObjectGuid.cpp:99
void ClearTextRepeatGroup(uint8 textGroup)
Definition: Creature.cpp:2815
Definition: SharedDefines.h:985

+ Here is the call graph for this function:

template<class Builder >
void CreatureTextMgr::SendChatPacket ( WorldObject source,
Builder const builder,
ChatMsg  msgType,
WorldObject const whisperTarget = nullptr,
CreatureTextRange  range = TEXT_RANGE_NORMAL,
Team  team = TEAM_OTHER,
bool  gmOnly = false 
)
static
167 {
168  if (!source)
169  return;
170 
171  CreatureTextLocalizer<Builder> localizer(builder, msgType);
172 
173  switch (msgType)
174  {
176  {
177  if (!whisperTarget)
178  return;
179 
180  if (Player* whisperPlayer = const_cast<Player*>(whisperTarget->ToPlayer()))
181  {
182  if (Group* group = whisperPlayer->GetGroup())
183  group->BroadcastWorker(localizer);
184  }
185  return;
186  }
189  {
190  if (range == TEXT_RANGE_NORMAL) // ignores team and gmOnly
191  {
192  if (!whisperTarget || whisperTarget->GetTypeId() != TYPEID_PLAYER)
193  return;
194 
195  localizer(const_cast<Player*>(whisperTarget->ToPlayer()));
196  return;
197  }
198  break;
199  }
200  default:
201  break;
202  }
203 
204  switch (range)
205  {
206  case TEXT_RANGE_AREA:
207  {
208  uint32 areaId = source->GetAreaId();
209  Map::PlayerList const& players = source->GetMap()->GetPlayers();
210  for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
211  if (itr->GetSource()->GetAreaId() == areaId && (!team || Team(itr->GetSource()->GetTeam()) == team) && (!gmOnly || itr->GetSource()->IsGameMaster()))
212  localizer(itr->GetSource());
213  return;
214  }
215  case TEXT_RANGE_ZONE:
216  {
217  uint32 zoneId = source->GetZoneId();
218  Map::PlayerList const& players = source->GetMap()->GetPlayers();
219  for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
220  if (itr->GetSource()->GetZoneId() == zoneId && (!team || Team(itr->GetSource()->GetTeam()) == team) && (!gmOnly || itr->GetSource()->IsGameMaster()))
221  localizer(itr->GetSource());
222  return;
223  }
224  case TEXT_RANGE_MAP:
225  {
226  Map::PlayerList const& players = source->GetMap()->GetPlayers();
227  for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
228  if ((!team || Team(itr->GetSource()->GetTeam()) == team) && (!gmOnly || itr->GetSource()->IsGameMaster()))
229  localizer(itr->GetSource());
230  return;
231  }
232  case TEXT_RANGE_WORLD:
233  {
234  SessionMap const& smap = sWorld->GetAllSessions();
235  for (SessionMap::const_iterator iter = smap.begin(); iter != smap.end(); ++iter)
236  if (Player* player = iter->second->GetPlayer())
237  if ((!team || Team(player->GetTeam()) == team) && (!gmOnly || player->IsGameMaster()))
238  localizer(player);
239  return;
240  }
241  case TEXT_RANGE_NORMAL:
242  default:
243  break;
244  }
245 
246  float dist = GetRangeForChatType(msgType);
247  Trinity::PlayerDistWorker<CreatureTextLocalizer<Builder> > worker(source, dist, localizer);
248  source->VisitNearbyWorldObject(dist, worker);
249 }
static float GetRangeForChatType(ChatMsg msgType)
Definition: CreatureTextMgr.cpp:277
Map * GetMap() const
Definition: Object.h:543
Definition: CreatureTextMgr.h:31
Definition: GridNotifiers.h:560
Definition: CreatureTextMgr.h:35
Definition: SharedDefines.h:4246
void VisitNearbyWorldObject(float const &radius, NOTIFIER &notifier) const
Definition: Object.h:589
uint32 GetZoneId() const
Definition: Object.cpp:1525
#define sWorld
Definition: World.h:887
iterator begin()
Definition: MapRefManager.h:37
Definition: CreatureTextMgr.h:34
Team
Definition: SharedDefines.h:997
Definition: SharedDefines.h:4244
Definition: CreatureTextMgr.h:32
Definition: CreatureTextMgr.h:33
Definition: SharedDefines.h:4273
uint32_t uint32
Definition: Define.h:150
Definition: LinkedList.h:141
uint32 GetAreaId() const
Definition: Object.cpp:1530
PlayerList const & GetPlayers() const
Definition: Map.h:433
Definition: CreatureTextMgr.h:116
Definition: MapRefManager.h:26
Definition: ObjectGuid.h:33
std::unordered_map< uint32, WorldSession * > SessionMap
Definition: World.h:530
iterator end()
Definition: MapRefManager.h:38
Definition: Group.h:191

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CreatureTextMgr::SendEmote ( Unit source,
uint32  emote 
)
static
384 {
385  if (!source)
386  return;
387 
388  source->HandleEmoteCommand(emote);
389 }
void HandleEmoteCommand(uint32 anim_id)
Definition: Unit.cpp:1444

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CreatureTextMgr::SendNonChatPacket ( WorldObject source,
WorldPacket const data,
ChatMsg  msgType,
WorldObject const whisperTarget,
CreatureTextRange  range,
Team  team,
bool  gmOnly 
)
staticprivate
305 {
306  switch (msgType)
307  {
309  {
310  if (!whisperTarget)
311  return;
312 
313  if (Player const* whisperPlayer = whisperTarget->ToPlayer())
314  {
315  if (Group const* group = whisperPlayer->GetGroup())
316  group->BroadcastWorker([data](Player* player) { player->SendDirectMessage(data); });
317  }
318  return;
319  }
322  {
323  if (range == TEXT_RANGE_NORMAL) // ignores team and gmOnly
324  {
325  if (!whisperTarget || whisperTarget->GetTypeId() != TYPEID_PLAYER)
326  return;
327 
328  whisperTarget->ToPlayer()->GetSession()->SendPacket(data);
329  return;
330  }
331  break;
332  }
333  default:
334  break;
335  }
336 
337  switch (range)
338  {
339  case TEXT_RANGE_AREA:
340  {
341  uint32 areaId = source->GetAreaId();
342  Map::PlayerList const& players = source->GetMap()->GetPlayers();
343  for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
344  if (itr->GetSource()->GetAreaId() == areaId && (!team || Team(itr->GetSource()->GetTeam()) == team) && (!gmOnly || itr->GetSource()->IsGameMaster()))
345  itr->GetSource()->GetSession()->SendPacket(data);
346  return;
347  }
348  case TEXT_RANGE_ZONE:
349  {
350  uint32 zoneId = source->GetZoneId();
351  Map::PlayerList const& players = source->GetMap()->GetPlayers();
352  for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
353  if (itr->GetSource()->GetZoneId() == zoneId && (!team || Team(itr->GetSource()->GetTeam()) == team) && (!gmOnly || itr->GetSource()->IsGameMaster()))
354  itr->GetSource()->GetSession()->SendPacket(data);
355  return;
356  }
357  case TEXT_RANGE_MAP:
358  {
359  Map::PlayerList const& players = source->GetMap()->GetPlayers();
360  for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
361  if ((!team || Team(itr->GetSource()->GetTeam()) == team) && (!gmOnly || itr->GetSource()->IsGameMaster()))
362  itr->GetSource()->GetSession()->SendPacket(data);
363  return;
364  }
365  case TEXT_RANGE_WORLD:
366  {
367  SessionMap const& smap = sWorld->GetAllSessions();
368  for (SessionMap::const_iterator iter = smap.begin(); iter != smap.end(); ++iter)
369  if (Player* player = iter->second->GetPlayer())
370  if (player->GetSession() && (!team || Team(player->GetTeam()) == team) && (!gmOnly || player->IsGameMaster()))
371  player->GetSession()->SendPacket(data);
372  return;
373  }
374  case TEXT_RANGE_NORMAL:
375  default:
376  break;
377  }
378 
379  float dist = GetRangeForChatType(msgType);
380  source->SendMessageToSetInRange(data, dist, true);
381 }
static float GetRangeForChatType(ChatMsg msgType)
Definition: CreatureTextMgr.cpp:277
Map * GetMap() const
Definition: Object.h:543
Definition: CreatureTextMgr.h:31
Definition: CreatureTextMgr.h:35
Definition: SharedDefines.h:4246
uint32 GetZoneId() const
Definition: Object.cpp:1525
virtual void SendMessageToSetInRange(WorldPacket const *data, float dist, bool self)
Definition: Object.cpp:2150
#define sWorld
Definition: World.h:887
iterator begin()
Definition: MapRefManager.h:37
Definition: CreatureTextMgr.h:34
Team
Definition: SharedDefines.h:997
Definition: SharedDefines.h:4244
Definition: CreatureTextMgr.h:32
Definition: CreatureTextMgr.h:33
Definition: SharedDefines.h:4273
uint32_t uint32
Definition: Define.h:150
Definition: LinkedList.h:141
uint32 GetAreaId() const
Definition: Object.cpp:1530
PlayerList const & GetPlayers() const
Definition: Map.h:433
Definition: MapRefManager.h:26
Definition: ObjectGuid.h:33
std::unordered_map< uint32, WorldSession * > SessionMap
Definition: World.h:530
iterator end()
Definition: MapRefManager.h:38
Definition: Group.h:191

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CreatureTextMgr::SendSound ( Creature source,
uint32  sound,
ChatMsg  msgType,
WorldObject const whisperTarget = nullptr,
CreatureTextRange  range = TEXT_RANGE_NORMAL,
Team  team = TEAM_OTHER,
bool  gmOnly = false 
)
static
297 {
298  if (!sound || !source)
299  return;
300 
301  SendNonChatPacket(source, WorldPackets::Misc::PlaySound(source->GetGUID(), sound).Write(), msgType, whisperTarget, range, team, gmOnly);
302 }
static void SendNonChatPacket(WorldObject *source, WorldPacket const *data, ChatMsg msgType, WorldObject const *whisperTarget, CreatureTextRange range, Team team, bool gmOnly)
Definition: CreatureTextMgr.cpp:304
Definition: MiscPackets.h:601
ObjectGuid const & GetGUID() const
Definition: Object.h:105

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CreatureTextMgr::SetRepeatId ( Creature source,
uint8  textGroup,
uint8  id 
)
private
392 {
393  if (!source)
394  return;
395 
396  source->SetTextRepeatId(textGroup, id);
397 }
void SetTextRepeatId(uint8 textGroup, uint8 id)
Definition: Creature.cpp:2795

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool CreatureTextMgr::TextExist ( uint32  sourceEntry,
uint8  textGroup 
) const
407 {
408  if (!sourceEntry)
409  return false;
410 
411  CreatureTextMap::const_iterator sList = mTextMap.find(sourceEntry);
412  if (sList == mTextMap.end())
413  {
414  TC_LOG_DEBUG("entities.unit", "CreatureTextMgr::TextExist: Could not find Text for Creature (entry %u) in 'creature_text' table.", sourceEntry);
415  return false;
416  }
417 
418  CreatureTextHolder const& textHolder = sList->second;
419  CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
420  if (itr == textHolder.end())
421  {
422  TC_LOG_DEBUG("entities.unit", "CreatureTextMgr::TextExist: Could not find TextGroup %u for Creature (entry %u).", uint32(textGroup), sourceEntry);
423  return false;
424  }
425 
426  return true;
427 }
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
CreatureTextMap mTextMap
Definition: CreatureTextMgr.h:109
std::unordered_map< uint8, CreatureTextGroup > CreatureTextHolder
Definition: CreatureTextMgr.h:74
uint32_t uint32
Definition: g3dmath.h:168

Member Data Documentation

LocaleCreatureTextMap CreatureTextMgr::mLocaleTextMap
private
CreatureTextMap CreatureTextMgr::mTextMap
private

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