diff options
Diffstat (limited to 'src/server/game/Texts')
| -rw-r--r-- | src/server/game/Texts/CreatureTextMgr.cpp | 50 | ||||
| -rw-r--r-- | src/server/game/Texts/CreatureTextMgr.h | 58 |
2 files changed, 62 insertions, 46 deletions
diff --git a/src/server/game/Texts/CreatureTextMgr.cpp b/src/server/game/Texts/CreatureTextMgr.cpp index 6da4f6fdade..1cff81c171d 100644 --- a/src/server/game/Texts/CreatureTextMgr.cpp +++ b/src/server/game/Texts/CreatureTextMgr.cpp @@ -24,7 +24,6 @@ #include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "CreatureTextMgr.h" -#include "Group.h" class CreatureTextBuilder { @@ -91,7 +90,6 @@ void CreatureTextMgr::LoadCreatureTexts() } uint32 textCount = 0; - uint32 creatureCount = 0; do { @@ -109,25 +107,26 @@ void CreatureTextMgr::LoadCreatureTexts() temp.duration = fields[8].GetUInt32(); temp.sound = fields[9].GetUInt32(); temp.BroadcastTextId = fields[10].GetUInt32(); + temp.TextRange = CreatureTextRange(fields[11].GetUInt8()); if (temp.sound) { if (!sSoundEntriesStore.LookupEntry(temp.sound)) { - 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); + 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); temp.sound = 0; } } if (!GetLanguageDescByID(temp.lang)) { - 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)); + 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)); temp.lang = LANG_UNIVERSAL; } if (temp.type >= MAX_CHAT_MSG_TYPE) { - 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)); + 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)); temp.type = CHAT_MSG_SAY; } @@ -135,7 +134,7 @@ void CreatureTextMgr::LoadCreatureTexts() { if (!sEmotesStore.LookupEntry(temp.emote)) { - 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)); + 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)); temp.emote = EMOTE_ONESHOT_NONE; } } @@ -149,9 +148,11 @@ void CreatureTextMgr::LoadCreatureTexts() } } - // entry not yet added, add empty TextHolder (list of groups) - if (mTextMap.find(temp.entry) == mTextMap.end()) - ++creatureCount; + if (temp.TextRange > TEXT_RANGE_WORLD) + { + 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); + temp.TextRange = TEXT_RANGE_NORMAL; + } // add the text into our entry's group mTextMap[temp.entry][temp.group].push_back(temp); @@ -160,7 +161,7 @@ void CreatureTextMgr::LoadCreatureTexts() } while (result->NextRow()); - TC_LOG_INFO("server.loading", ">> Loaded %u creature texts for %u creatures in %u ms", textCount, creatureCount, GetMSTimeDiffToNow(oldMSTime)); + TC_LOG_INFO("server.loading", ">> Loaded %u creature texts for " SZFMTD " creatures in %u ms", textCount, mTextMap.size(), GetMSTimeDiffToNow(oldMSTime)); } void CreatureTextMgr::LoadCreatureTextLocales() @@ -193,7 +194,7 @@ void CreatureTextMgr::LoadCreatureTextLocales() } -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*/) +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*/) { if (!source) return 0; @@ -274,6 +275,9 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject Language finalLang = (language == LANG_ADDON) ? iter->lang : language; uint32 finalSound = sound ? sound : iter->sound; + if (range == TEXT_RANGE_NORMAL) + range = iter->TextRange; + if (finalSound) SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly); @@ -335,6 +339,18 @@ void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket* data, { switch (msgType) { + case CHAT_MSG_MONSTER_PARTY: + { + if (!whisperTarget) + return; + + if (Player const* whisperPlayer = whisperTarget->ToPlayer()) + { + if (Group const* group = whisperPlayer->GetGroup()) + group->BroadcastWorker([data](Player* player) { player->SendDirectMessage(data); }); + } + return; + } case CHAT_MSG_MONSTER_WHISPER: case CHAT_MSG_RAID_BOSS_WHISPER: { @@ -348,18 +364,6 @@ void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket* data, } break; } - case CHAT_MSG_MONSTER_PARTY: - if (!whisperTarget) - return; - - if (Player const* player = whisperTarget->ToPlayer()) - { - if (Group* group = const_cast<Group*>(player->GetGroup())) - for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next()) - if (Player* member = itr->GetSource()) - member->GetSession()->SendPacket(data); - } - return; default: break; } diff --git a/src/server/game/Texts/CreatureTextMgr.h b/src/server/game/Texts/CreatureTextMgr.h index aef38a1923e..147228b51db 100644 --- a/src/server/game/Texts/CreatureTextMgr.h +++ b/src/server/game/Texts/CreatureTextMgr.h @@ -23,6 +23,16 @@ #include "ObjectAccessor.h" #include "SharedDefines.h" #include "Opcodes.h" +#include "Group.h" + +enum CreatureTextRange +{ + TEXT_RANGE_NORMAL = 0, + TEXT_RANGE_AREA = 1, + TEXT_RANGE_ZONE = 2, + TEXT_RANGE_MAP = 3, + TEXT_RANGE_WORLD = 4 +}; struct CreatureTextEntry { @@ -37,15 +47,7 @@ struct CreatureTextEntry uint32 duration; uint32 sound; uint32 BroadcastTextId; -}; - -enum CreatureTextRange -{ - TEXT_RANGE_NORMAL = 0, - TEXT_RANGE_AREA = 1, - TEXT_RANGE_ZONE = 2, - TEXT_RANGE_MAP = 3, - TEXT_RANGE_WORLD = 4 + CreatureTextRange TextRange; }; struct CreatureTextLocale @@ -55,9 +57,7 @@ struct CreatureTextLocale struct CreatureTextId { - CreatureTextId(uint32 e, uint32 g, uint32 i) : entry(e), textGroup(g), textId(i) - { - } + CreatureTextId(uint32 e, uint32 g, uint32 i) : entry(e), textGroup(g), textId(i) { } bool operator<(CreatureTextId const& right) const { @@ -69,22 +69,22 @@ struct CreatureTextId uint32 textId; }; -typedef std::vector<CreatureTextEntry> CreatureTextGroup; //texts in a group -typedef std::unordered_map<uint8, CreatureTextGroup> CreatureTextHolder; //groups for a creature by groupid -typedef std::unordered_map<uint32, CreatureTextHolder> CreatureTextMap; //all creatures by entry +typedef std::vector<CreatureTextEntry> CreatureTextGroup; // texts in a group +typedef std::unordered_map<uint8, CreatureTextGroup> CreatureTextHolder; // groups for a creature by groupid +typedef std::unordered_map<uint32, CreatureTextHolder> CreatureTextMap; // all creatures by entry typedef std::map<CreatureTextId, CreatureTextLocale> LocaleCreatureTextMap; //used for handling non-repeatable random texts typedef std::vector<uint8> CreatureTextRepeatIds; typedef std::unordered_map<uint8, CreatureTextRepeatIds> CreatureTextRepeatGroup; -typedef std::unordered_map<uint64, CreatureTextRepeatGroup> CreatureTextRepeatMap;//guid based +typedef std::unordered_map<ObjectGuid, CreatureTextRepeatGroup> CreatureTextRepeatMap;//guid based class CreatureTextMgr { private: - CreatureTextMgr() { }; - ~CreatureTextMgr() { }; + CreatureTextMgr() { } + ~CreatureTextMgr() { } public: static CreatureTextMgr* instance() @@ -101,11 +101,11 @@ class CreatureTextMgr void SendEmote(Unit* source, uint32 emote); //if sent, returns the 'duration' of the text else 0 if error - uint32 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); + 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); 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* whisperTarget = NULL, CreatureTextRange range = TEXT_RANGE_NORMAL, Team team = TEAM_OTHER, bool gmOnly = false) const; + template<class Builder> 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) const; private: CreatureTextRepeatIds GetRepeatGroup(Creature* source, uint8 textGroup); @@ -165,7 +165,7 @@ class CreatureTextLocalizer { case CHAT_MSG_MONSTER_WHISPER: case CHAT_MSG_RAID_BOSS_WHISPER: - data.put<uint64>(whisperGUIDpos, player->GetGUID()); + data.put<uint64>(whisperGUIDpos, player->GetGUID().GetRawValue()); break; default: break; @@ -181,7 +181,7 @@ class CreatureTextLocalizer }; template<class Builder> -void CreatureTextMgr::SendChatPacket(WorldObject* source, Builder const& builder, ChatMsg msgType, WorldObject const* whisperTarget /*= NULL*/, CreatureTextRange range /*= TEXT_RANGE_NORMAL*/, Team team /*= TEAM_OTHER*/, bool gmOnly /*= false*/) const +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*/) const { if (!source) return; @@ -190,6 +190,18 @@ void CreatureTextMgr::SendChatPacket(WorldObject* source, Builder const& builder switch (msgType) { + case CHAT_MSG_MONSTER_PARTY: + { + if (!whisperTarget) + return; + + if (Player* whisperPlayer = const_cast<Player*>(whisperTarget->ToPlayer())) + { + if (Group* group = whisperPlayer->GetGroup()) + group->BroadcastWorker(localizer); + } + return; + } case CHAT_MSG_MONSTER_WHISPER: case CHAT_MSG_RAID_BOSS_WHISPER: { @@ -240,7 +252,7 @@ void CreatureTextMgr::SendChatPacket(WorldObject* source, Builder const& builder SessionMap const& smap = sWorld->GetAllSessions(); for (SessionMap::const_iterator iter = smap.begin(); iter != smap.end(); ++iter) if (Player* player = iter->second->GetPlayer()) - if (player->GetSession() && (!team || Team(player->GetTeam()) == team) && (!gmOnly || player->IsGameMaster())) + if ((!team || Team(player->GetTeam()) == team) && (!gmOnly || player->IsGameMaster())) localizer(player); return; } |
