diff options
author | Subv <subv2112@gmail.com> | 2013-12-29 15:13:14 -0500 |
---|---|---|
committer | Subv <subv2112@gmail.com> | 2013-12-29 15:13:14 -0500 |
commit | d234d0f3d0889e799eb066ba39c9b1edbc964d6e (patch) | |
tree | 17d6281266900fe843573d03eff46a3b2beabedb /src/server/game/Texts/CreatureTextMgr.cpp | |
parent | 8658b5338c905c79daf50cb56dbe739f82d25acc (diff) | |
parent | c40cdc2968c58d952878c09a60926af74f782867 (diff) |
Merge branch 'master' of github.com:TrinityCore/TrinityCore into mmaps_rw
Diffstat (limited to 'src/server/game/Texts/CreatureTextMgr.cpp')
-rw-r--r-- | src/server/game/Texts/CreatureTextMgr.cpp | 76 |
1 files changed, 21 insertions, 55 deletions
diff --git a/src/server/game/Texts/CreatureTextMgr.cpp b/src/server/game/Texts/CreatureTextMgr.cpp index 264b69750f0..e0f37624a7a 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,34 +28,16 @@ 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 - return whisperGUIDpos; + return ChatHandler::BuildChatPacket(*data, _msgType, Language(_language), _source, _target, text, 0, "", locale); } WorldObject* _source; @@ -62,14 +45,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) { } @@ -77,24 +60,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 - - return whisperGUIDpos; + return ChatHandler::BuildChatPacket(*data, _msgType, Language(_language), _talker, _target, text, 0, "", locale); } WorldObject* _source; @@ -103,7 +69,7 @@ class PlayerTextBuilder uint8 _textGroup; uint32 _textId; uint32 _language; - uint64 _targetGUID; + WorldObject const* _target; }; void CreatureTextMgr::LoadCreatureTexts() @@ -211,7 +177,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; @@ -293,7 +259,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) @@ -304,13 +270,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); @@ -337,17 +303,17 @@ 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; WorldPacket data(SMSG_PLAY_SOUND, 4); data << uint32(sound); - 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); @@ -358,10 +324,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; |