From 729b9f501d7af0d004e2389c22377c1074289402 Mon Sep 17 00:00:00 2001 From: Dave Corley Date: Fri, 29 Sep 2023 07:11:56 -0500 Subject: [PATCH] Feat(Server): Add functions to send music packets to clients --- apps/openmw-mp/Script/Functions/Objects.cpp | 15 +++++++++++ apps/openmw-mp/Script/Functions/Objects.hpp | 29 ++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/apps/openmw-mp/Script/Functions/Objects.cpp b/apps/openmw-mp/Script/Functions/Objects.cpp index 4e5860c99..db52f71a3 100644 --- a/apps/openmw-mp/Script/Functions/Objects.cpp +++ b/apps/openmw-mp/Script/Functions/Objects.cpp @@ -561,6 +561,11 @@ void ObjectFunctions::SetObjectSound(const char* soundId, double volume, double tempObject.pitch = pitch; } +void ObjectFunctions::SetObjectTrack(const char *soundId) noexcept +{ + tempObject.musicFilename = soundId; +} + void ObjectFunctions::SetObjectSummonState(bool summonState) noexcept { tempObject.isSummon = summonState; @@ -833,6 +838,16 @@ void ObjectFunctions::SendObjectSound(bool sendToOtherPlayers, bool skipAttached packet->Send(true); } +void ObjectFunctions::SendObjectTrack(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept { + mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_MUSIC_PLAY); + packet->setObjectList(&writeObjectList); + + if (!skipAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); +} + void ObjectFunctions::SendObjectState(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_OBJECT_STATE); diff --git a/apps/openmw-mp/Script/Functions/Objects.hpp b/apps/openmw-mp/Script/Functions/Objects.hpp index 73ae9d7cb..03fce621a 100644 --- a/apps/openmw-mp/Script/Functions/Objects.hpp +++ b/apps/openmw-mp/Script/Functions/Objects.hpp @@ -117,6 +117,7 @@ {"SetObjectPosition", ObjectFunctions::SetObjectPosition},\ {"SetObjectRotation", ObjectFunctions::SetObjectRotation},\ {"SetObjectSound", ObjectFunctions::SetObjectSound},\ + {"SetObjectTrack", ObjectFunctions::SetObjectTrack},\ \ {"SetObjectSummonState", ObjectFunctions::SetObjectSummonState},\ {"SetObjectSummonEffectId", ObjectFunctions::SetObjectSummonEffectId},\ @@ -160,6 +161,7 @@ {"SendObjectTrap", ObjectFunctions::SendObjectTrap},\ {"SendObjectScale", ObjectFunctions::SendObjectScale},\ {"SendObjectSound", ObjectFunctions::SendObjectSound},\ + {"SendObjectTrack", ObjectFunctions::SendObjectTrack},\ {"SendObjectState", ObjectFunctions::SendObjectState},\ {"SendObjectMove", ObjectFunctions::SendObjectMove},\ {"SendObjectRotate", ObjectFunctions::SendObjectRotate},\ @@ -1087,7 +1089,21 @@ public: */ static void SetObjectRotation(double x, double y, double z) noexcept; - static void SetObjectSound(const char* soundId, double volume, double pitch) noexcept; + /** + * \brief Set the Sound of the temporary object stored on the server + * + * \param soundId Sets the refId of the sound to be played on the client + * \param volume Set the volume of the sound to be played on the client + * \param pitch Set the pitch of the sound to be played on the client + */ + static void SetObjectSound(const char *soundId, double volume, double pitch) noexcept; + + /** + * \brief Set the Sound of the temporary object stored on the server + * + * \param track Sets the track name to be played on the client + */ + static void SetObjectTrack(const char *soundId) noexcept; /** * \brief Set the summon state of the temporary object stored on the server. @@ -1439,6 +1455,17 @@ public: */ static void SendObjectSound(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept; + /** + * \brief Send a Music_Play packet. + * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param skipAttachedPlayer Whether the packet should skip being sent to the player attached + * to the packet (false by default). + * \return void + */ + static void SendObjectTrack(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept; + /** * \brief Send an ObjectState packet. *