diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt index 03f695dcf..f84222ba8 100644 --- a/src/game/CMakeLists.txt +++ b/src/game/CMakeLists.txt @@ -285,6 +285,7 @@ set (game_SRCS Chat/AsyncCommandHandlers.h Chat/AbstractPlayer.h Chat/MasterPlayer.h + Chat/MonsterChatBuilder.h Database/CharacterDatabaseCache.h Database/CharacterDatabaseCleaner.h Database/DBCEnums.h diff --git a/src/game/Chat/MonsterChatBuilder.h b/src/game/Chat/MonsterChatBuilder.h new file mode 100644 index 000000000..508de7cbd --- /dev/null +++ b/src/game/Chat/MonsterChatBuilder.h @@ -0,0 +1,123 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef MONSTER_CHAT_BUILDER_H +#define MONSTER_CHAT_BUILDER_H + +#include "Common.h" +#include "SharedDefines.h" +#include "ObjectGuid.h" +#include "Chat.h" +#include "ObjectMgr.h" + +struct CreatureInfo; +class WorldObject; + +namespace MaNGOS +{ + class MonsterChatBuilderFormat + { + public: + MonsterChatBuilderFormat(WorldObject const& obj, ChatMsg msgtype, int32 textId, Language language, Unit const* target, va_list* vaList = nullptr) + : i_source(obj), i_msgtype(msgtype), i_textId(textId), i_language(language), i_target(target), i_vaList(vaList) {} + void operator()(WorldPacket& data, int32 loc_idx) + { + char const* text = i_textId > 0 ? sObjectMgr.GetBroadcastText(i_textId, loc_idx, i_source.GetGender()) : sObjectMgr.GetMangosString(i_textId, loc_idx); + char textFinal[2048]; + va_list argsCpy; + va_copy(argsCpy, *i_vaList); + vsnprintf(textFinal, 2048, text, argsCpy); + va_end(argsCpy); + ChatHandler::BuildChatPacket(data, i_msgtype, text, i_language, CHAT_TAG_NONE, i_source.GetObjectGuid(), i_source.GetNameForLocaleIdx(loc_idx), + i_target ? i_target->GetObjectGuid() : ObjectGuid(), i_target ? i_target->GetNameForLocaleIdx(loc_idx) : ""); + } + + private: + WorldObject const& i_source; + ChatMsg i_msgtype; + int32 i_textId; + Language i_language; + Unit const* i_target; + va_list* i_vaList; + }; + + class MonsterChatBuilder + { + public: + MonsterChatBuilder(WorldObject const& obj, ChatMsg msgtype, int32 textId, Language language, Unit const* target) + : i_source(obj), i_msgtype(msgtype), i_textId(textId), i_language(language), i_target(target) {} + void operator()(WorldPacket& data, int32 loc_idx) const + { + char const* text = i_textId > 0 ? sObjectMgr.GetBroadcastText(i_textId, loc_idx, i_source.GetGender()) : sObjectMgr.GetMangosString(i_textId, loc_idx); + + ChatHandler::BuildChatPacket(data, i_msgtype, text, i_language, CHAT_TAG_NONE, i_source.GetObjectGuid(), i_source.GetNameForLocaleIdx(loc_idx), + i_target ? i_target->GetObjectGuid() : ObjectGuid(), i_target ? i_target->GetNameForLocaleIdx(loc_idx) : ""); + } + + private: + WorldObject const& i_source; + ChatMsg i_msgtype; + int32 i_textId; + Language i_language; + Unit const* i_target; + }; + + class StaticMonsterChatBuilder + { + public: + StaticMonsterChatBuilder(CreatureInfo const* cInfo, ChatMsg msgtype, int32 textId, Language language, Unit const* target, uint32 senderLowGuid = 0) + : i_cInfo(cInfo), i_msgtype(msgtype), i_textId(textId), i_language(language), i_target(target) + { + // 0 lowguid not used in core, but accepted fine in this case by client + i_senderGuid = i_cInfo->GetObjectGuid(senderLowGuid); + + if (CreatureDisplayInfoAddon const* displayAddon = sObjectMgr.GetCreatureDisplayInfoAddon(cInfo->display_id[0])) + i_senderGender = displayAddon->gender; + } + void operator()(WorldPacket& data, int32 loc_idx) + { + char const* text = i_textId > 0 ? sObjectMgr.GetBroadcastText(i_textId, loc_idx, i_senderGender) : sObjectMgr.GetMangosString(i_textId, loc_idx); + + std::string nameForLocale; + if (loc_idx >= 0) + { + CreatureLocale const* cl = sObjectMgr.GetCreatureLocale(i_cInfo->entry); + if (cl) + { + if (cl->Name.size() > (size_t)loc_idx && !cl->Name[loc_idx].empty()) + nameForLocale = cl->Name[loc_idx]; + } + } + + if (nameForLocale.empty()) + nameForLocale = i_cInfo->name; + + ChatHandler::BuildChatPacket(data, i_msgtype, text, i_language, CHAT_TAG_NONE, i_senderGuid, nameForLocale.c_str(), i_target ? i_target->GetObjectGuid() : ObjectGuid(), + i_target ? i_target->GetNameForLocaleIdx(loc_idx) : ""); + } + + private: + ObjectGuid i_senderGuid; + CreatureInfo const* i_cInfo; + uint8 i_senderGender = GENDER_NONE; + ChatMsg i_msgtype; + int32 i_textId; + Language i_language; + Unit const* i_target; + }; +} // namespace MaNGOS + +#endif diff --git a/src/game/Maps/Map.cpp b/src/game/Maps/Map.cpp index 315a75ec0..b58718afd 100644 --- a/src/game/Maps/Map.cpp +++ b/src/game/Maps/Map.cpp @@ -46,6 +46,7 @@ #include "MoveMap.h" #include "SocialMgr.h" #include "Chat.h" +#include "MonsterChatBuilder.h" #include "Weather.h" #include "MovementBroadcaster.h" #include "PlayerBroadcaster.h" @@ -2931,100 +2932,35 @@ uint32 Map::GenerateLocalLowGuid(HighGuid guidhigh) return guid; } -/** - * Helper structure for building static chat information - * - */ -class StaticMonsterChatBuilder +void Map::SendMonsterTextToMap(int32 textId, Language language, ChatMsg chatMsg, uint32 creatureId, WorldObject const* pSource, Unit const* pTarget) { -public: - StaticMonsterChatBuilder(CreatureInfo const* cInfo, ChatMsg msgtype, int32 textId, Language language, Unit const* target, uint32 senderLowGuid = 0) - : i_cInfo(cInfo), i_msgtype(msgtype), i_textId(textId), i_language(language), i_target(target) + if (pSource) { - // 0 lowguid not used in core, but accepted fine in this case by client - i_senderGuid = i_cInfo->GetObjectGuid(senderLowGuid); - } - void operator()(WorldPacket& data, int32 loc_idx) - { - char const* text = i_textId > 0 ? sObjectMgr.GetBroadcastText(i_textId, loc_idx) : sObjectMgr.GetMangosString(i_textId, loc_idx); + MaNGOS::MonsterChatBuilder say_build(*pSource, chatMsg, textId, language, pTarget); + MaNGOS::LocalizedPacketDo say_do(say_build); - std::string nameForLocale; - if (loc_idx >= 0) - { - CreatureLocale const* cl = sObjectMgr.GetCreatureLocale(i_cInfo->entry); - if (cl) - { - if (cl->Name.size() > (size_t)loc_idx && !cl->Name[loc_idx].empty()) - nameForLocale = cl->Name[loc_idx]; - } - } - - if (nameForLocale.empty()) - nameForLocale = i_cInfo->name; - - ChatHandler::BuildChatPacket(data, i_msgtype, text, i_language, CHAT_TAG_NONE, i_senderGuid, nameForLocale.c_str(), i_target ? i_target->GetObjectGuid() : ObjectGuid(), - i_target ? i_target->GetNameForLocaleIdx(loc_idx) : ""); - } - -private: - ObjectGuid i_senderGuid; - CreatureInfo const* i_cInfo; - ChatMsg i_msgtype; - int32 i_textId; - Language i_language; - Unit const* i_target; -}; - - -/** - * Function simulates yell of creature - * - * @param guid must be creature guid of whom to Simulate the yell, non-creature guids not supported at this moment - * @param textId Id of the simulated text - * @param language language of the text - * @param target, can be nullptr - */ -void Map::MonsterYellToMap(ObjectGuid guid, int32 textId, Language language, Unit const* target) const -{ - if (guid.IsAnyTypeCreature()) - { - CreatureInfo const* cInfo = ObjectMgr::GetCreatureTemplate(guid.GetEntry()); - if (!cInfo) - { - sLog.outError("Map::MonsterYellToMap: Called for nonexistent creature entry in guid: %s", guid.GetString().c_str()); - return; - } - - MonsterYellToMap(cInfo, textId, language, target, guid.GetCounter()); + Map::PlayerList const& pList = GetPlayers(); + for (const auto& itr : pList) + say_do(itr.getSource()); } else { - sLog.outError("Map::MonsterYellToMap: Called for non creature guid: %s", guid.GetString().c_str()); - return; + CreatureInfo const* cInfo = sObjectMgr.GetCreatureTemplate(creatureId); + if (!cInfo) + { + sLog.outError("SendMonsterTextToMap called with no source and invalid creature id!"); + return; + } + + MaNGOS::StaticMonsterChatBuilder say_build(cInfo, chatMsg, textId, language, pTarget, 0); + MaNGOS::LocalizedPacketDo say_do(say_build); + + Map::PlayerList const& pList = GetPlayers(); + for (const auto& itr : pList) + say_do(itr.getSource()); } } - -/** - * Function simulates yell of creature - * - * @param cinfo must be entry of Creature of whom to Simulate the yell - * @param textId Id of the simulated text - * @param language language of the text - * @param target, can be nullptr - * @param senderLowGuid provide way proper show yell for near spawned creature with known lowguid, - * 0 accepted by client else if this not important - */ -void Map::MonsterYellToMap(CreatureInfo const* cinfo, int32 textId, Language language, Unit const* target, uint32 senderLowGuid /*= 0*/) const -{ - StaticMonsterChatBuilder say_build(cinfo, CHAT_MSG_MONSTER_YELL, textId, language, target, senderLowGuid); - MaNGOS::LocalizedPacketDo say_do(say_build); - - Map::PlayerList const& pList = GetPlayers(); - for (const auto& itr : pList) - say_do(itr.getSource()); -} - /** * Function to play sound to all players in map * diff --git a/src/game/Maps/Map.h b/src/game/Maps/Map.h index a542e4475..2a2427fdb 100644 --- a/src/game/Maps/Map.h +++ b/src/game/Maps/Map.h @@ -541,8 +541,7 @@ class Map : public GridRefManager InstanceData const* GetInstanceData() const { return i_data; } uint32 GetScriptId() const { return i_script_id; } - void MonsterYellToMap(ObjectGuid guid, int32 textId, Language language, Unit const* target) const; - void MonsterYellToMap(CreatureInfo const* cinfo, int32 textId, Language language, Unit const* target, uint32 senderLowGuid = 0) const; + void SendMonsterTextToMap(int32 textId, Language language, ChatMsg chatMsg, uint32 creatureId, WorldObject const* pSource = nullptr, Unit const* pTarget = nullptr); void PlayDirectSoundToMap(uint32 soundId, uint32 zoneId = 0) const; // GameObjectCollision diff --git a/src/game/Objects/Object.cpp b/src/game/Objects/Object.cpp index 3726c64a4..039d64b9e 100644 --- a/src/game/Objects/Object.cpp +++ b/src/game/Objects/Object.cpp @@ -48,6 +48,7 @@ #include "ZoneScriptMgr.h" #include "InstanceData.h" #include "Chat.h" +#include "MonsterChatBuilder.h" #include "Anticheat.h" #include "packet_builder.h" @@ -3071,59 +3072,6 @@ void WorldObject::SetActiveObjectState(bool on) } } -namespace MaNGOS -{ - class MonsterChatBuilderFormat - { - public: - MonsterChatBuilderFormat(WorldObject const& obj, ChatMsg msgtype, int32 textId, Language language, Unit const* target, va_list* vaList = nullptr) - : i_source(obj), i_msgtype(msgtype), i_textId(textId), i_language(language), i_target(target), i_vaList(vaList) {} - void operator()(WorldPacket& data, int32 loc_idx) - { - char const* text = i_textId > 0 ? sObjectMgr.GetBroadcastText(i_textId, loc_idx, i_source.GetGender()) : sObjectMgr.GetMangosString(i_textId, loc_idx); - char textFinal[2048]; - va_list argsCpy; - va_copy(argsCpy, *i_vaList); - vsnprintf(textFinal, 2048, text, argsCpy); - va_end(argsCpy); - ChatHandler::BuildChatPacket(data, i_msgtype, text, i_language, CHAT_TAG_NONE, i_source.GetObjectGuid(), i_source.GetNameForLocaleIdx(loc_idx), - i_target ? i_target->GetObjectGuid() : ObjectGuid(), i_target ? i_target->GetNameForLocaleIdx(loc_idx) : ""); - } - - private: - WorldObject const& i_source; - ChatMsg i_msgtype; - int32 i_textId; - Language i_language; - Unit const* i_target; - va_list* i_vaList; - }; -} - -namespace MaNGOS -{ - class MonsterChatBuilder - { - public: - MonsterChatBuilder(WorldObject const& obj, ChatMsg msgtype, int32 textId, Language language, Unit const* target) - : i_source(obj), i_msgtype(msgtype), i_textId(textId), i_language(language), i_target(target) {} - void operator()(WorldPacket& data, int32 loc_idx) const - { - char const* text = i_textId > 0 ? sObjectMgr.GetBroadcastText(i_textId, loc_idx, i_source.GetGender()) : sObjectMgr.GetMangosString(i_textId, loc_idx); - - ChatHandler::BuildChatPacket(data, i_msgtype, text, i_language, CHAT_TAG_NONE, i_source.GetObjectGuid(), i_source.GetNameForLocaleIdx(loc_idx), - i_target ? i_target->GetObjectGuid() : ObjectGuid(), i_target ? i_target->GetNameForLocaleIdx(loc_idx) : ""); - } - - private: - WorldObject const& i_source; - ChatMsg i_msgtype; - int32 i_textId; - Language i_language; - Unit const* i_target; - }; -} // namespace MaNGOS - void WorldObject::PMonsterSay(int32 textId, ...) const { va_list ap; diff --git a/src/game/ScriptMgr.cpp b/src/game/ScriptMgr.cpp index cfe3533da..53ddd9646 100644 --- a/src/game/ScriptMgr.cpp +++ b/src/game/ScriptMgr.cpp @@ -2520,112 +2520,112 @@ void ScriptMgr::CollectPossibleEventIds(std::set& eventIds) } } -void DoScriptText(int32 iTextEntry, WorldObject* pSource, Unit* pTarget, int32 chatTypeOverride) +void DoScriptText(int32 textId, WorldObject* pSource, Unit* pTarget, int32 chatTypeOverride) { if (!pSource) { - sLog.outError("DoScriptText entry %i, invalid Source pointer.", iTextEntry); + sLog.outError("DoScriptText entry %i, invalid Source pointer.", textId); return; } - uint8 Type; - uint32 Emote; - uint32 Language; - uint32 SoundId; + uint8 chatType; + uint32 emoteId; + uint32 languageId; + uint32 soundId; - if (iTextEntry >= 0) + if (textId >= 0) { - if (BroadcastText const* bct = sObjectMgr.GetBroadcastTextLocale(iTextEntry)) + if (BroadcastText const* bct = sObjectMgr.GetBroadcastTextLocale(textId)) { - Type = bct->chatType; - Emote = bct->emoteId1; - Language = bct->languageId; - SoundId = bct->soundId; + chatType = bct->chatType; + emoteId = bct->emoteId1; + languageId = bct->languageId; + soundId = bct->soundId; } else { - sLog.outError("DoScriptText with source entry %u (TypeId=%u, guid=%u) attempts to process broadcast text id %i, but text id does not exist.", pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), iTextEntry); + sLog.outError("DoScriptText with source entry %u (TypeId=%u, guid=%u) attempts to process broadcast text id %i, but text id does not exist.", pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), textId); return; } } else { - if (StringTextData const* pData = sScriptMgr.GetTextData(iTextEntry)) + if (StringTextData const* pData = sScriptMgr.GetTextData(textId)) { - Type = pData->Type; - Emote = pData->Emote; - Language = pData->Language; - SoundId = pData->SoundId; + chatType = pData->Type; + emoteId = pData->Emote; + languageId = pData->Language; + soundId = pData->SoundId; } else { - sLog.outError("DoScriptText with source entry %u (TypeId=%u, guid=%u) could not find text entry %i.", pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), iTextEntry); + sLog.outError("DoScriptText with source entry %u (TypeId=%u, guid=%u) could not find text entry %i.", pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), textId); return; } } if (chatTypeOverride >= 0) - Type = chatTypeOverride; + chatType = chatTypeOverride; - DEBUG_LOG("DoScriptText: text entry=%i, Sound=%u, Type=%u, Language=%u, Emote=%u", - iTextEntry, SoundId, Type, Language, Emote); + DEBUG_LOG("DoScriptText: textId=%i, soundId=%u, chatType=%u, languageId=%u, emoteId=%u", + textId, soundId, chatType, languageId, emoteId); - if (SoundId) + if (soundId) { - if (sObjectMgr.GetSoundEntry(SoundId)) + if (sObjectMgr.GetSoundEntry(soundId)) { - if (Type == CHAT_TYPE_ZONE_YELL) + if (chatType == CHAT_TYPE_ZONE_YELL) { if (Map* pZone = pSource->GetMap()) - pZone->PlayDirectSoundToMap(SoundId); + pZone->PlayDirectSoundToMap(soundId); } else - pSource->PlayDirectSound(SoundId); + pSource->PlayDirectSound(soundId); } else - sLog.outError("DoScriptText entry %i tried to process invalid sound id %u.", iTextEntry, SoundId); + sLog.outError("DoScriptText entry %i tried to process invalid sound id %u.", textId, soundId); } - if (Emote) + if (emoteId) { if (pSource->GetTypeId() == TYPEID_UNIT || pSource->GetTypeId() == TYPEID_PLAYER) - ((Unit*)pSource)->HandleEmoteCommand(Emote); + ((Unit*)pSource)->HandleEmoteCommand(emoteId); else - sLog.outError("DoScriptText entry %i tried to process emote for invalid TypeId (%u).", iTextEntry, pSource->GetTypeId()); + sLog.outError("DoScriptText entry %i tried to process emote for invalid TypeId (%u).", textId, pSource->GetTypeId()); } - switch (Type) + switch (chatType) { case CHAT_TYPE_SAY: - pSource->MonsterSay(iTextEntry, Language, pTarget); + pSource->MonsterSay(textId, languageId, pTarget); break; case CHAT_TYPE_YELL: - pSource->MonsterYell(iTextEntry, Language, pTarget); + pSource->MonsterYell(textId, languageId, pTarget); break; case CHAT_TYPE_TEXT_EMOTE: - pSource->MonsterTextEmote(iTextEntry, pTarget); + pSource->MonsterTextEmote(textId, pTarget); break; case CHAT_TYPE_BOSS_EMOTE: - pSource->MonsterTextEmote(iTextEntry, pTarget, true); + pSource->MonsterTextEmote(textId, pTarget, true); break; case CHAT_TYPE_WHISPER: if (pTarget && pTarget->GetTypeId() == TYPEID_PLAYER) - pSource->MonsterWhisper(iTextEntry, pTarget); + pSource->MonsterWhisper(textId, pTarget); else - sLog.outError("DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", iTextEntry); + sLog.outError("DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", textId); break; case CHAT_TYPE_BOSS_WHISPER: { if (pTarget && pTarget->GetTypeId() == TYPEID_PLAYER) - pSource->MonsterWhisper(iTextEntry, pTarget, true); + pSource->MonsterWhisper(textId, pTarget, true); else - sLog.outError("DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", iTextEntry); + sLog.outError("DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", textId); break; } case CHAT_TYPE_ZONE_YELL: - pSource->MonsterYellToZone(iTextEntry, Language, pTarget); + pSource->MonsterYellToZone(textId, languageId, pTarget); break; } } @@ -2634,79 +2634,96 @@ void DoScriptText(int32 iTextEntry, WorldObject* pSource, Unit* pTarget, int32 c /** * Function that either simulates or does script text for a map * - * @param iTextEntry Entry of the text, stored in SD2-database, only type CHAT_TYPE_ZONE_YELL supported - * @param uiCreatureEntry Id of the creature of whom saying will be simulated + * @param textId Entry of the text, stored in SD2-database, only type CHAT_TYPE_ZONE_YELL supported + * @param creatureId Id of the creature of whom saying will be simulated * @param pMap Given Map on which the map-wide text is displayed - * @param pCreatureSource Can be nullptr. If pointer to Creature is given, then the creature does the map-wide text + * @param pSource Can be nullptr. If pointer to Creature is given, then the creature does the map-wide text * @param pTarget Can be nullptr. Possible target for the text */ -void DoOrSimulateScriptTextForMap(int32 iTextEntry, uint32 uiCreatureEntry, Map* pMap, Creature* pCreatureSource /*=nullptr*/, Unit* pTarget /*=nullptr*/) +void DoOrSimulateScriptTextForMap(int32 textId, uint32 creatureId, Map* pMap, Creature* pSource /*= nullptr*/, Unit* pTarget /*= nullptr*/) { if (!pMap) { - sLog.outError("DoOrSimulateScriptTextForMap entry %i, invalid Map pointer.", iTextEntry); - return; - } - - CreatureInfo const* pInfo = sObjectMgr.GetCreatureTemplate(uiCreatureEntry); - if (!pInfo) - { - sLog.outError("DoOrSimulateScriptTextForMap has invalid source entry %u for map %u.", uiCreatureEntry, pMap->GetId()); + sLog.outError("DoOrSimulateScriptTextForMap entry %i, invalid Map pointer.", textId); return; } - uint8 Type; - uint32 Emote; - uint32 LanguageId; - uint32 SoundId; + uint8 chatType; + uint32 emoteId; + uint32 languageId; + uint32 soundId; - if (iTextEntry >= 0) + if (textId >= 0) { - if (BroadcastText const* bct = sObjectMgr.GetBroadcastTextLocale(iTextEntry)) + if (BroadcastText const* bct = sObjectMgr.GetBroadcastTextLocale(textId)) { - Type = bct->chatType; - Emote = bct->emoteId1; - LanguageId = bct->languageId; - SoundId = bct->soundId; + chatType = bct->chatType; + emoteId = bct->emoteId1; + languageId = bct->languageId; + soundId = bct->soundId; } else { - sLog.outError("DoOrSimulateScriptTextForMap with source entry %u for map %u could not find broadcast text id %i.", uiCreatureEntry, pMap->GetId(), iTextEntry); + sLog.outError("DoOrSimulateScriptTextForMap with source entry %u for map %u could not find broadcast text id %i.", creatureId, pMap->GetId(), textId); return; } } else { - if (MangosStringLocale const* pData = sObjectMgr.GetMangosStringLocale(iTextEntry)) + if (MangosStringLocale const* pData = sObjectMgr.GetMangosStringLocale(textId)) { - Type = pData->Type; - Emote = pData->Emote; - LanguageId = pData->LanguageId; - SoundId = pData->SoundId; + chatType = pData->Type; + emoteId = pData->Emote; + languageId = pData->LanguageId; + soundId = pData->SoundId; } else { - sLog.outError("DoOrSimulateScriptTextForMap with source entry %u for map %u could not find script text entry %i.", uiCreatureEntry, pMap->GetId(), iTextEntry); + sLog.outError("DoOrSimulateScriptTextForMap with source entry %u for map %u could not find script text entry %i.", creatureId, pMap->GetId(), textId); return; } } sLog.outDebug("SD2: DoOrSimulateScriptTextForMap: text entry=%i, Sound=%u, Type=%u, Language=%u, Emote=%u", - iTextEntry, SoundId, Type, LanguageId, Emote); + textId, soundId, chatType, languageId, emoteId); - if (Type != CHAT_TYPE_ZONE_YELL) + uint8 chatMsg; + switch (chatType) { - sLog.outError("DoSimulateScriptTextForMap entry %i has not supported chat type %u.", iTextEntry, Type); - return; + case CHAT_TYPE_SAY: + chatMsg = CHAT_MSG_MONSTER_SAY; + break; + case CHAT_TYPE_YELL: + case CHAT_TYPE_ZONE_YELL: + chatMsg = CHAT_MSG_MONSTER_YELL; + break; + case CHAT_TYPE_TEXT_EMOTE: + chatMsg = CHAT_MSG_MONSTER_EMOTE; + break; + case CHAT_TYPE_BOSS_EMOTE: + chatMsg = CHAT_MSG_RAID_BOSS_EMOTE; + break; + case CHAT_TYPE_WHISPER: + chatMsg = CHAT_MSG_MONSTER_WHISPER; + break; + case CHAT_TYPE_BOSS_WHISPER: + { + chatMsg = CHAT_MSG_RAID_BOSS_WHISPER; + break; + } + default: + { + sLog.outError("DoSimulateScriptTextForMap entry %i has not supported chat type %u.", textId, chatType); + return; + } } - if (SoundId) - pMap->PlayDirectSoundToMap(SoundId); + if (soundId) + pMap->PlayDirectSoundToMap(soundId); + if (emoteId && pSource) + pSource->HandleEmote(emoteId); - if (pCreatureSource) // If provided pointer for sayer, use direct version - pMap->MonsterYellToMap(pCreatureSource->GetObjectGuid(), iTextEntry, Language(LanguageId), pTarget); - else // Simulate yell - pMap->MonsterYellToMap(pInfo, iTextEntry, Language(LanguageId), pTarget); + pMap->SendMonsterTextToMap(textId, Language(languageId), ChatMsg(chatMsg), creatureId, pSource, pTarget); } void Script::RegisterSelf(bool bReportError) diff --git a/src/game/ScriptMgr.h b/src/game/ScriptMgr.h index 9d6fee893..fa40fc792 100644 --- a/src/game/ScriptMgr.h +++ b/src/game/ScriptMgr.h @@ -71,8 +71,8 @@ extern ScriptMapMap sCreatureAIScripts; #define TEXT_SOURCE_CUSTOM_END TEXT_SOURCE_RANGE*3 + 1 //Generic scripting functions -void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target = nullptr, int32 chatTypeOverride = -1); -void DoOrSimulateScriptTextForMap(int32 iTextEntry, uint32 uiCreatureEntry, Map* pMap, Creature* pCreatureSource = nullptr, Unit* pTarget = nullptr); +void DoScriptText(int32 textId, WorldObject* pSource, Unit* pTarget = nullptr, int32 chatTypeOverride = -1); +void DoOrSimulateScriptTextForMap(int32 textId, uint32 creatureId, Map* pMap, Creature* pSource = nullptr, Unit* pTarget = nullptr); // Returns a target based on the type specified. WorldObject* GetTargetByType(WorldObject* pSource, WorldObject* pTarget, Map* pMap, uint8 targetType, uint32 param1 = 0u, uint32 param2 = 0u, SpellEntry const* pSpellEntry = nullptr);