201{
202 if (!source)
203 return 0;
204
207 {
208 LOG_ERROR(
"sql.sql",
"CreatureTextMgr: Could not find Text for Creature({}) Entry {} in 'creature_text' table. Ignoring.", source->
GetName(), source->
GetEntry());
209 return 0;
210 }
211
213 CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
214 if (itr == textHolder.end())
215 {
216 LOG_ERROR(
"sql.sql",
"CreatureTextMgr: Could not find TextGroup {} for Creature {} ({}). Ignoring.",
218 return 0;
219 }
220
224
225 for (CreatureTextGroup::const_iterator giter = textGroupContainer.begin(); giter != textGroupContainer.end(); ++giter)
226 if (std::find(repeatGroup.begin(), repeatGroup.end(), giter->id) == repeatGroup.end())
227 tempGroup.push_back(*giter);
228
229 if (tempGroup.empty())
230 {
233 {
234 CreatureTextRepeatGroup::iterator groupItr = mapItr->second.find(textGroup);
235 groupItr->second.clear();
236 }
237
238 tempGroup = textGroupContainer;
239 }
240
242 float lastChance = -1;
243 bool isEqualChanced = true;
244
245 float totalChance = 0;
246
247 for (CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter)
248 {
249 if (lastChance >= 0 && lastChance != iter->probability)
250 isEqualChanced = false;
251
252 lastChance = iter->probability;
253 totalChance += iter->probability;
254 ++count;
255 }
256
258 if (!isEqualChanced)
259 {
260 for (CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter)
261 {
264 ++offset;
265 if (r <= chance)
266 break;
267 }
268 }
269
271 if (isEqualChanced || offset < 0)
272 pos =
urand(0, count - 1);
273 else if (offset >= 0)
274 pos = offset;
275
276 CreatureTextGroup::const_iterator iter = tempGroup.begin() + pos;
277
280 uint32 finalSound = sound ? sound : iter->sound;
281
283 range = iter->TextRange;
284
285 if (finalSound)
286 SendSound(source, finalSound, finalType, target, range, teamId, gmOnly);
287
288 Unit* finalSource = source;
289 if (srcPlr)
290 finalSource = srcPlr;
291
292 if (iter->emote)
294
295 if (srcPlr)
296 {
297 PlayerTextBuilder builder(source, finalSource, finalSource->
getGender(), finalType, iter->group, iter->id, finalLang, target);
298 SendChatPacket(finalSource, builder, finalType, target, range, teamId, gmOnly);
299 }
300 else
301 {
303 SendChatPacket(finalSource, builder, finalType, target, range, teamId, gmOnly);
304 }
305 if (isEqualChanced || (!isEqualChanced && totalChance == 100.0f))
307
308 return iter->duration;
309}
std::int32_t int32
Definition: Define.h:104
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:44
std::vector< CreatureTextEntry > CreatureTextGroup
Definition: CreatureTextMgr.h:74
std::unordered_map< uint8, CreatureTextGroup > CreatureTextHolder
Definition: CreatureTextMgr.h:75
@ CHAT_MSG_ADDON
Definition: SharedDefines.h:3123
@ LANG_ADDON
Definition: SharedDefines.h:725
uint32 GetEntry() const
Definition: Object.h:109
std::string const & GetName() const
Definition: Object.h:446
std::string ToString() const
Definition: ObjectGuid.cpp:47
uint8 getGender() const
Definition: Unit.h:1440
Definition: CreatureTextMgr.cpp:30
Definition: CreatureTextMgr.cpp:53
void SendChatPacket(WorldObject *source, Builder const &builder, ChatMsg msgType, WorldObject const *target=nullptr, CreatureTextRange range=TEXT_RANGE_NORMAL, TeamId teamId=TEAM_NEUTRAL, bool gmOnly=false) const
Definition: CreatureTextMgr.h:180
void SetRepeatId(Creature *source, uint8 textGroup, uint8 id)
Definition: CreatureTextMgr.cpp:414
void SendEmote(Unit *source, uint32 emote)
Definition: CreatureTextMgr.cpp:406
void SendSound(Creature *source, uint32 sound, ChatMsg msgType, WorldObject const *target, CreatureTextRange range, TeamId teamId, bool gmOnly)
Definition: CreatureTextMgr.cpp:330
CreatureTextRepeatIds GetRepeatGroup(Creature *source, uint8 textGroup)
Definition: CreatureTextMgr.cpp:427