From 6aa8e4389cafbf6ebb9153a66693e5e4bf188fa3 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Fri, 1 May 2020 18:35:53 +0200 Subject: [PATCH] Core/Texts: allow creature texts to play sounds via different opcodes (Direct Sound, Object Sound and Music) --- .../world/4.3.4/2020_05_01_00_world.sql | 1 + .../Database/Implementation/WorldDatabase.cpp | 2 +- src/server/game/Server/Packets/MiscPackets.h | 2 ++ src/server/game/Texts/CreatureTextMgr.cpp | 32 ++++++++++++++++--- src/server/game/Texts/CreatureTextMgr.h | 10 +++++- .../IcecrownCitadel/boss_the_lich_king.cpp | 2 +- .../Ulduar/Ulduar/boss_yogg_saron.cpp | 2 +- 7 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 sql/updates/world/4.3.4/2020_05_01_00_world.sql diff --git a/sql/updates/world/4.3.4/2020_05_01_00_world.sql b/sql/updates/world/4.3.4/2020_05_01_00_world.sql new file mode 100644 index 00000000000..9e4fea2dc4c --- /dev/null +++ b/sql/updates/world/4.3.4/2020_05_01_00_world.sql @@ -0,0 +1 @@ +ALTER TABLE `creature_text` ADD COLUMN `SoundType` MEDIUMINT(8) UNSIGNED DEFAULT 0 NOT NULL AFTER `Sound`; diff --git a/src/server/database/Database/Implementation/WorldDatabase.cpp b/src/server/database/Database/Implementation/WorldDatabase.cpp index 7f8ee7b7e7a..2f3c6bbbb00 100644 --- a/src/server/database/Database/Implementation/WorldDatabase.cpp +++ b/src/server/database/Database/Implementation/WorldDatabase.cpp @@ -26,7 +26,7 @@ void WorldDatabaseConnection::DoPrepareStatements() PrepareStatement(WORLD_SEL_QUEST_POOLS, "SELECT entry, pool_entry FROM pool_quest", CONNECTION_SYNCH); PrepareStatement(WORLD_DEL_CRELINKED_RESPAWN, "DELETE FROM linked_respawn WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(WORLD_REP_CREATURE_LINKED_RESPAWN, "REPLACE INTO linked_respawn (guid, linkedGuid) VALUES (?, ?)", CONNECTION_ASYNC); - PrepareStatement(WORLD_SEL_CREATURE_TEXT, "SELECT CreatureID, GroupID, ID, Text, Type, Language, Probability, Emote, Duration, Sound, BroadcastTextId, TextRange FROM creature_text", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_CREATURE_TEXT, "SELECT CreatureID, GroupID, ID, Text, Type, Language, Probability, Emote, Duration, Sound, SoundType, BroadcastTextId, TextRange FROM creature_text", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_SMART_SCRIPTS, "SELECT entryorguid, source_type, id, link, event_type, event_phase_mask, event_chance, event_flags, event_param1, event_param2, event_param3, event_param4, event_param5, action_type, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, target_type, target_param1, target_param2, target_param3, target_x, target_y, target_z, target_o FROM smart_scripts ORDER BY entryorguid, source_type, id, link", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_SMARTAI_WP, "SELECT entry, pointid, position_x, position_y, position_z FROM waypoints ORDER BY entry, pointid", CONNECTION_SYNCH); PrepareStatement(WORLD_DEL_GAMEOBJECT, "DELETE FROM gameobject WHERE guid = ?", CONNECTION_ASYNC); diff --git a/src/server/game/Server/Packets/MiscPackets.h b/src/server/game/Server/Packets/MiscPackets.h index 94348c06cf6..1d4cd3d7772 100644 --- a/src/server/game/Server/Packets/MiscPackets.h +++ b/src/server/game/Server/Packets/MiscPackets.h @@ -172,6 +172,8 @@ namespace WorldPackets { public: PlayObjectSound() : ServerPacket(SMSG_PLAY_OBJECT_SOUND, 8 + 8 + 4) { } + PlayObjectSound(ObjectGuid sourceObjectGuid, ObjectGuid targetObjectGuid, uint32 soundKitID) : ServerPacket(SMSG_PLAY_OBJECT_SOUND, 8 + 8 + 4), + SourceObjectGUID(sourceObjectGuid), TargetObjectGUID(targetObjectGuid), SoundKitID(soundKitID) { } WorldPacket const* Write() override; diff --git a/src/server/game/Texts/CreatureTextMgr.cpp b/src/server/game/Texts/CreatureTextMgr.cpp index 90376809021..07a317ffe4f 100644 --- a/src/server/game/Texts/CreatureTextMgr.cpp +++ b/src/server/game/Texts/CreatureTextMgr.cpp @@ -115,8 +115,9 @@ void CreatureTextMgr::LoadCreatureTexts() temp.emote = Emote(fields[7].GetUInt32()); temp.duration = fields[8].GetUInt32(); temp.sound = fields[9].GetUInt32(); - temp.BroadcastTextId = fields[10].GetUInt32(); - temp.TextRange = CreatureTextRange(fields[11].GetUInt8()); + temp.soundType = CreatureTextSoundType(fields[10].GetUInt32()); + temp.BroadcastTextId = fields[11].GetUInt32(); + temp.TextRange = CreatureTextRange(fields[12].GetUInt8()); if (temp.sound) { @@ -163,6 +164,12 @@ void CreatureTextMgr::LoadCreatureTexts() temp.TextRange = TEXT_RANGE_NORMAL; } + if (temp.soundType > CreatureTextSoundType::Music) + { + TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has incorrect SoundType %u.", temp.creatureId, temp.groupId, temp.id, AsUnderlyingType(temp.TextRange)); + temp.soundType = CreatureTextSoundType::DirectSound; + } + // add the text into our entry's group mTextMap[temp.creatureId][temp.groupId].push_back(temp); @@ -247,7 +254,9 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? iter->type : msgType; Language finalLang = (language == LANG_ADDON) ? iter->lang : language; + CreatureTextSoundType soundType = iter->soundType; uint32 finalSound = iter->sound; + if (sound) finalSound = sound; else if (BroadcastText const* bct = sObjectMgr->GetBroadcastText(iter->BroadcastTextId)) @@ -258,7 +267,7 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject range = iter->TextRange; if (finalSound) - SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly); + SendSound(source, finalSound, soundType, finalType, whisperTarget, range, team, gmOnly); Unit* finalSource = source; if (srcPlr) @@ -301,12 +310,25 @@ float CreatureTextMgr::GetRangeForChatType(ChatMsg msgType) const return dist; } -void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly) +void CreatureTextMgr::SendSound(Creature* source, uint32 sound, CreatureTextSoundType soundType, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly) { if (!sound || !source) return; - SendNonChatPacket(source, WorldPackets::Misc::PlaySound(source->GetGUID(), sound).Write(), msgType, whisperTarget, range, team, gmOnly); + switch (soundType) + { + case CreatureTextSoundType::DirectSound: + SendNonChatPacket(source, WorldPackets::Misc::PlaySound(source->GetGUID(), sound).Write(), msgType, whisperTarget, range, team, gmOnly); + break; + case CreatureTextSoundType::ObjectSound: + SendNonChatPacket(source, WorldPackets::Misc::PlayObjectSound(source->GetGUID(), whisperTarget ? whisperTarget->GetGUID() : source->GetGUID(), sound).Write(), msgType, whisperTarget, range, team, gmOnly); + break; + case CreatureTextSoundType::Music: + SendNonChatPacket(source, WorldPackets::Misc::PlayMusic(sound, source->GetGUID()).Write(), msgType, whisperTarget, range, team, gmOnly); + break; + default: + break; + } } void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket const* data, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly) const diff --git a/src/server/game/Texts/CreatureTextMgr.h b/src/server/game/Texts/CreatureTextMgr.h index 7b14188a410..3d4643eb482 100644 --- a/src/server/game/Texts/CreatureTextMgr.h +++ b/src/server/game/Texts/CreatureTextMgr.h @@ -39,6 +39,13 @@ enum CreatureTextRange TEXT_RANGE_WORLD = 4 }; +enum class CreatureTextSoundType : uint32 +{ + DirectSound = 0, + ObjectSound = 1, + Music = 2 +}; + struct CreatureTextEntry { uint32 creatureId; @@ -51,6 +58,7 @@ struct CreatureTextEntry Emote emote; uint32 duration; uint32 sound; + CreatureTextSoundType soundType; uint32 BroadcastTextId; CreatureTextRange TextRange; }; @@ -93,7 +101,7 @@ class TC_GAME_API CreatureTextMgr void LoadCreatureTextLocales(); CreatureTextMap const& GetTextMap() const { return mTextMap; } - void SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly); + void SendSound(Creature* source, uint32 sound, CreatureTextSoundType soundType, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly); void SendEmote(Unit* source, uint32 emote); //if sent, returns the 'duration' of the text else 0 if error diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp index 29760c9be30..4f23ce466c9 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp @@ -1102,7 +1102,7 @@ class boss_the_lich_king : public CreatureScript break; case EVENT_OUTRO_SOUL_BARRAGE: me->CastSpell((Unit*)nullptr, SPELL_SOUL_BARRAGE, TRIGGERED_IGNORE_CAST_IN_PROGRESS); - sCreatureTextMgr->SendSound(me, SOUND_PAIN, CHAT_MSG_MONSTER_YELL, 0, TEXT_RANGE_NORMAL, TEAM_OTHER, false); + sCreatureTextMgr->SendSound(me, SOUND_PAIN, CreatureTextSoundType::DirectSound, CHAT_MSG_MONSTER_YELL, 0, TEXT_RANGE_NORMAL, TEAM_OTHER, false); // set flight me->SetDisableGravity(true); me->SetByteFlag(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_ANIM_TIER, UNIT_BYTE1_FLAG_ALWAYS_STAND | UNIT_BYTE1_FLAG_HOVER); diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_yogg_saron.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_yogg_saron.cpp index 5a4000a0a1f..7b96eaf0ac0 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_yogg_saron.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_yogg_saron.cpp @@ -988,7 +988,7 @@ class boss_yogg_saron : public CreatureScript break; case EVENT_LUNATIC_GAZE: DoCast(me, SPELL_LUNATIC_GAZE); - sCreatureTextMgr->SendSound(me, SOUND_LUNATIC_GAZE, CHAT_MSG_MONSTER_YELL, 0, TEXT_RANGE_NORMAL, TEAM_OTHER, false); + sCreatureTextMgr->SendSound(me, SOUND_LUNATIC_GAZE, CreatureTextSoundType::DirectSound, CHAT_MSG_MONSTER_YELL, 0, TEXT_RANGE_NORMAL, TEAM_OTHER, false); _events.ScheduleEvent(EVENT_LUNATIC_GAZE, 12000, 0, PHASE_THREE); break; case EVENT_DEAFENING_ROAR: