diff options
Diffstat (limited to 'src/server/game/Texts/CreatureTextMgr.cpp')
-rw-r--r-- | src/server/game/Texts/CreatureTextMgr.cpp | 80 |
1 files changed, 21 insertions, 59 deletions
diff --git a/src/server/game/Texts/CreatureTextMgr.cpp b/src/server/game/Texts/CreatureTextMgr.cpp index aaafe219157..6251bb15d90 100644 --- a/src/server/game/Texts/CreatureTextMgr.cpp +++ b/src/server/game/Texts/CreatureTextMgr.cpp @@ -20,6 +20,7 @@ #include "ObjectMgr.h" #include "Cell.h" #include "CellImpl.h" +#include "Chat.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "CreatureTextMgr.h" @@ -27,39 +28,21 @@ class CreatureTextBuilder { public: - CreatureTextBuilder(WorldObject* obj, ChatMsg msgtype, uint8 textGroup, uint32 id, uint32 language, uint64 targetGUID) - : _source(obj), _msgType(msgtype), _textGroup(textGroup), _textId(id), _language(language), _targetGUID(targetGUID) + CreatureTextBuilder(WorldObject* obj, ChatMsg msgtype, uint8 textGroup, uint32 id, uint32 language, WorldObject const* target) + : _source(obj), _msgType(msgtype), _textGroup(textGroup), _textId(id), _language(language), _target(target) { } size_t operator()(WorldPacket* data, LocaleConstant locale) const { std::string const& text = sCreatureTextMgr->GetLocalizedChatString(_source->GetEntry(), _textGroup, _textId, locale); - std::string const& localizedName = _source->GetNameForLocaleIdx(locale); - - *data << uint8(_msgType); - *data << uint32(_language); - *data << uint64(_source->GetGUID()); - *data << uint32(1); // 2.1.0 - *data << uint32(localizedName.size() + 1); - *data << localizedName; - size_t whisperGUIDpos = data->wpos(); - *data << uint64(_targetGUID); // Unit Target - if (_targetGUID && !IS_PLAYER_GUID(_targetGUID)) - { - *data << uint32(1); // target name length - *data << uint8(0); // target name - } - *data << uint32(text.length() + 1); - *data << text; - *data << uint8(0); // ChatTag if (_msgType == CHAT_MSG_RAID_BOSS_EMOTE || _msgType == CHAT_MSG_RAID_BOSS_WHISPER) { *data << float(0); *data << uint8(0); } - return whisperGUIDpos; + return ChatHandler::BuildChatPacket(*data, _msgType, Language(_language), _source, _target, text, 0, "", locale); } WorldObject* _source; @@ -67,14 +50,14 @@ class CreatureTextBuilder uint8 _textGroup; uint32 _textId; uint32 _language; - uint64 _targetGUID; + WorldObject const* _target; }; class PlayerTextBuilder { public: - PlayerTextBuilder(WorldObject* obj, WorldObject* speaker, ChatMsg msgtype, uint8 textGroup, uint32 id, uint32 language, uint64 targetGUID) - : _source(obj), _talker(speaker), _msgType(msgtype), _textGroup(textGroup), _textId(id), _language(language), _targetGUID(targetGUID) + PlayerTextBuilder(WorldObject* obj, WorldObject* speaker, ChatMsg msgtype, uint8 textGroup, uint32 id, uint32 language, WorldObject const* target) + : _source(obj), _talker(speaker), _msgType(msgtype), _textGroup(textGroup), _textId(id), _language(language), _target(target) { } @@ -82,28 +65,7 @@ class PlayerTextBuilder { std::string const& text = sCreatureTextMgr->GetLocalizedChatString(_source->GetEntry(), _textGroup, _textId, locale); - *data << uint8(_msgType); - *data << uint32(_language); - *data << uint64(_talker->GetGUID()); - *data << uint32(1); // 2.1.0 - *data << uint32(_talker->GetName().size() + 1); - *data << _talker->GetName(); - size_t whisperGUIDpos = data->wpos(); - *data << uint64(_targetGUID); // Unit Target - if (_targetGUID && !IS_PLAYER_GUID(_targetGUID)) - { - *data << uint32(1); // target name length - *data << uint8(0); // target name - } - *data << uint32(text.length() + 1); - *data << text; - *data << uint8(0); // ChatTag - if (_msgType == CHAT_MSG_RAID_BOSS_EMOTE || _msgType == CHAT_MSG_RAID_BOSS_WHISPER) - { - *data << float(0); - *data << uint8(0); - } - return whisperGUIDpos; + return ChatHandler::BuildChatPacket(*data, _msgType, Language(_language), _talker, _target, text, 0, "", locale); } WorldObject* _source; @@ -112,7 +74,7 @@ class PlayerTextBuilder uint8 _textGroup; uint32 _textId; uint32 _language; - uint64 _targetGUID; + WorldObject const* _target; }; void CreatureTextMgr::LoadCreatureTexts() @@ -220,7 +182,7 @@ void CreatureTextMgr::LoadCreatureTextLocales() } -uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid /*= 0*/, 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 /*= NULL*/) +uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject const* whisperTarget /*= NULL*/, 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 /*= NULL*/) { if (!source) return 0; @@ -302,7 +264,7 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, uint64 whisp uint32 finalSound = sound ? sound : iter->sound; if (finalSound) - SendSound(source, finalSound, finalType, whisperGuid, range, team, gmOnly); + SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly); Unit* finalSource = source; if (srcPlr) @@ -313,13 +275,13 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, uint64 whisp if (srcPlr) { - PlayerTextBuilder builder(source, finalSource, finalType, iter->group, iter->id, finalLang, whisperGuid); - SendChatPacket(finalSource, builder, finalType, whisperGuid, range, team, gmOnly); + PlayerTextBuilder builder(source, finalSource, finalType, iter->group, iter->id, finalLang, whisperTarget); + SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly); } else { - CreatureTextBuilder builder(finalSource, finalType, iter->group, iter->id, finalLang, whisperGuid); - SendChatPacket(finalSource, builder, finalType, whisperGuid, range, team, gmOnly); + CreatureTextBuilder builder(finalSource, finalType, iter->group, iter->id, finalLang, whisperTarget); + SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly); } if (isEqualChanced || (!isEqualChanced && totalChance == 100.0f)) SetRepeatId(source, textGroup, iter->id); @@ -346,7 +308,7 @@ float CreatureTextMgr::GetRangeForChatType(ChatMsg msgType) const return dist; } -void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType, uint64 whisperGuid, CreatureTextRange range, Team team, bool gmOnly) +void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly) { if (!sound || !source) return; @@ -354,10 +316,10 @@ void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldPacket data(SMSG_PLAY_SOUND, 4); data << uint32(sound); data << uint64(source->GetGUID()); - SendNonChatPacket(source, &data, msgType, whisperGuid, range, team, gmOnly); + SendNonChatPacket(source, &data, msgType, whisperTarget, range, team, gmOnly); } -void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket* data, ChatMsg msgType, uint64 whisperGuid, CreatureTextRange range, Team team, bool gmOnly) const +void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket* data, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly) const { float dist = GetRangeForChatType(msgType); @@ -368,10 +330,10 @@ void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket* data, { if (range == TEXT_RANGE_NORMAL)//ignores team and gmOnly { - Player* player = ObjectAccessor::FindPlayer(whisperGuid); - if (!player || !player->GetSession()) + if (!whisperTarget || whisperTarget->GetTypeId() != TYPEID_PLAYER) return; - player->GetSession()->SendPacket(data); + + whisperTarget->ToPlayer()->GetSession()->SendPacket(data); return; } break; |