diff --git a/include/game/game_handler.hpp b/include/game/game_handler.hpp index d6b4227a..3534acf6 100644 --- a/include/game/game_handler.hpp +++ b/include/game/game_handler.hpp @@ -943,6 +943,11 @@ public: using PlayMusicCallback = std::function; void setPlayMusicCallback(PlayMusicCallback cb) { playMusicCallback_ = std::move(cb); } + // Server-triggered 2-D sound effect callback — fires when SMSG_PLAY_SOUND is received. + // The soundId corresponds to a SoundEntries.dbc record. + using PlaySoundCallback = std::function; + void setPlaySoundCallback(PlaySoundCallback cb) { playSoundCallback_ = std::move(cb); } + // Mount state using MountCallback = std::function; // 0 = dismount void setMountCallback(MountCallback cb) { mountCallback_ = std::move(cb); } @@ -2095,8 +2100,9 @@ private: // ---- Forced faction reactions (SMSG_SET_FORCED_REACTIONS) ---- std::unordered_map forcedReactions_; // factionId -> reaction tier - // ---- Server-triggered music ---- + // ---- Server-triggered audio ---- PlayMusicCallback playMusicCallback_; + PlaySoundCallback playSoundCallback_; }; } // namespace game diff --git a/src/core/application.cpp b/src/core/application.cpp index 99658508..e6199c7a 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -2121,6 +2121,27 @@ void Application::setupUICallbacks() { } }); + // SMSG_PLAY_SOUND: look up SoundEntries.dbc and play 2-D sound effect + gameHandler->setPlaySoundCallback([this](uint32_t soundId) { + if (!assetManager) return; + + auto dbc = assetManager->loadDBC("SoundEntries.dbc"); + if (!dbc || !dbc->isLoaded()) return; + + int32_t idx = dbc->findRecordById(soundId); + if (idx < 0) return; + + const uint32_t row = static_cast(idx); + std::string dir = dbc->getString(row, 23); + for (uint32_t f = 3; f <= 12; ++f) { + std::string name = dbc->getString(row, f); + if (name.empty()) continue; + std::string path = dir.empty() ? name : dir + "\\" + name; + audio::AudioEngine::instance().playSound2D(path); + return; + } + }); + // Other player level-up callback — trigger 3D effect + chat notification gameHandler->setOtherPlayerLevelUpCallback([this](uint64_t guid, uint32_t newLevel) { if (!gameHandler || !renderer) return; diff --git a/src/game/game_handler.cpp b/src/game/game_handler.cpp index 25a4400f..706e8cb7 100644 --- a/src/game/game_handler.cpp +++ b/src/game/game_handler.cpp @@ -3041,6 +3041,7 @@ void GameHandler::handlePacket(network::Packet& packet) { if (packet.getSize() - packet.getReadPos() >= 4) { uint32_t soundId = packet.readUInt32(); LOG_DEBUG("SMSG_PLAY_SOUND id=", soundId); + if (playSoundCallback_) playSoundCallback_(soundId); } break;