mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
feat(messages): StopNDAudioEmitter
Server to client, as live sent it: fading out, no emitter id, the event GUID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -106,6 +106,23 @@ namespace GameMessages {
|
||||
return true;
|
||||
}
|
||||
|
||||
void StopNDAudioEmitter::Serialize(RakNet::BitStream& bitStream) const {
|
||||
bitStream.Write(allowNativeFadeOut);
|
||||
BitStreamUtils::WriteOptional<uint32_t>(bitStream, NDAudioEmitterID, 0);
|
||||
BitStreamUtils::WriteLengthPrefixed<uint32_t>(bitStream, NDAudioEventGUID);
|
||||
BitStreamUtils::WriteLengthPrefixed<uint32_t>(bitStream, NDAudioMetaEventName);
|
||||
bitStream.Write(result);
|
||||
}
|
||||
|
||||
bool StopNDAudioEmitter::Deserialize(RakNet::BitStream& bitStream) {
|
||||
VALIDATE_READ(bitStream.Read(allowNativeFadeOut));
|
||||
VALIDATE_READ(BitStreamUtils::ReadOptional<uint32_t>(bitStream, NDAudioEmitterID, 0));
|
||||
VALIDATE_READ(BitStreamUtils::ReadLengthPrefixed<uint32_t>(bitStream, NDAudioEventGUID));
|
||||
VALIDATE_READ(BitStreamUtils::ReadLengthPrefixed<uint32_t>(bitStream, NDAudioMetaEventName));
|
||||
VALIDATE_READ(bitStream.Read(result));
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlayEmbeddedEffectOnAllClientsNearObject::Serialize(RakNet::BitStream& bitStream) const {
|
||||
BitStreamUtils::WriteLengthPrefixed<uint32_t>(bitStream, effectName);
|
||||
bitStream.Write(fromObjectID);
|
||||
|
||||
@@ -65,6 +65,23 @@ namespace GameMessages {
|
||||
LWOOBJID targetObjectIDForNDAudioCallbackMessages{ LWOOBJID_EMPTY }; // optional
|
||||
};
|
||||
|
||||
// Server -> client, broadcast. Stops a sound PlayNDAudioEmitter started on the object (live let it fade out).
|
||||
struct StopNDAudioEmitter : public NetGameMsg {
|
||||
StopNDAudioEmitter() : NetGameMsg(MessageType::Game::STOP_ND_AUDIO_EMITTER) {}
|
||||
StopNDAudioEmitter(const LWOOBJID _target, const std::string& _NDAudioEventGUID) : StopNDAudioEmitter() {
|
||||
target = _target;
|
||||
NDAudioEventGUID = _NDAudioEventGUID;
|
||||
}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
|
||||
bool allowNativeFadeOut{ true };
|
||||
uint32_t NDAudioEmitterID{}; // optional
|
||||
std::string NDAudioEventGUID{};
|
||||
std::string NDAudioMetaEventName{};
|
||||
bool result{};
|
||||
};
|
||||
|
||||
// Server -> client, broadcast.
|
||||
struct PlayEmbeddedEffectOnAllClientsNearObject : public NetGameMsg {
|
||||
PlayEmbeddedEffectOnAllClientsNearObject() : NetGameMsg(MessageType::Game::PLAY_EMBEDDED_EFFECT_ON_ALL_CLIENTS_NEAR_OBJECT) {}
|
||||
|
||||
@@ -68,6 +68,7 @@ json ToJson(const GameMessages::DeactivateBubbleBuffFromServer& m);
|
||||
json ToJson(const GameMessages::PreloadAnimation& m);
|
||||
json ToJson(const GameMessages::PlayAnimation& m);
|
||||
json ToJson(const GameMessages::PlayNDAudioEmitter& m);
|
||||
json ToJson(const GameMessages::StopNDAudioEmitter& m);
|
||||
json ToJson(const GameMessages::PlayEmbeddedEffectOnAllClientsNearObject& m);
|
||||
json ToJson(const GameMessages::PlayFXEffect& m);
|
||||
json ToJson(const GameMessages::StopFXEffect& m);
|
||||
@@ -847,6 +848,15 @@ json ToJson(const GameMessages::PlayNDAudioEmitter& m) {
|
||||
j["targetObjectIDForNDAudioCallbackMessages"] = ToJson(m.targetObjectIDForNDAudioCallbackMessages);
|
||||
return j;
|
||||
}
|
||||
json ToJson(const GameMessages::StopNDAudioEmitter& m) {
|
||||
json j = json::object();
|
||||
j["allowNativeFadeOut"] = ToJson(m.allowNativeFadeOut);
|
||||
j["NDAudioEmitterID"] = ToJson(m.NDAudioEmitterID);
|
||||
j["NDAudioEventGUID"] = ToJson(m.NDAudioEventGUID);
|
||||
j["NDAudioMetaEventName"] = ToJson(m.NDAudioMetaEventName);
|
||||
j["result"] = ToJson(m.result);
|
||||
return j;
|
||||
}
|
||||
json ToJson(const GameMessages::PlayEmbeddedEffectOnAllClientsNearObject& m) {
|
||||
json j = json::object();
|
||||
j["effectName"] = ToJson(m.effectName);
|
||||
@@ -2616,6 +2626,7 @@ const std::vector<Entry>& Entries() {
|
||||
{ MessageType::Game::PRELOAD_ANIMATION, eDirection::TO_CLIENT, "PreloadAnimation", &ReadWith<GameMessages::PreloadAnimation> },
|
||||
{ MessageType::Game::PLAY_ANIMATION, eDirection::TO_CLIENT, "PlayAnimation", &ReadWith<GameMessages::PlayAnimation> },
|
||||
{ MessageType::Game::PLAY_ND_AUDIO_EMITTER, eDirection::TO_CLIENT, "PlayNDAudioEmitter", &ReadWith<GameMessages::PlayNDAudioEmitter> },
|
||||
{ MessageType::Game::STOP_ND_AUDIO_EMITTER, eDirection::TO_CLIENT, "StopNDAudioEmitter", &ReadWith<GameMessages::StopNDAudioEmitter> },
|
||||
{ MessageType::Game::PLAY_EMBEDDED_EFFECT_ON_ALL_CLIENTS_NEAR_OBJECT, eDirection::TO_CLIENT, "PlayEmbeddedEffectOnAllClientsNearObject", &ReadWith<GameMessages::PlayEmbeddedEffectOnAllClientsNearObject> },
|
||||
{ MessageType::Game::PLAY_FX_EFFECT, eDirection::TO_CLIENT, "PlayFXEffect", &ReadWith<GameMessages::PlayFXEffect> },
|
||||
{ MessageType::Game::STOP_FX_EFFECT, eDirection::TO_CLIENT, "StopFXEffect", &ReadWith<GameMessages::StopFXEffect> },
|
||||
|
||||
@@ -121,6 +121,31 @@ TEST_F(EffectsMessagesTests, PlayNDAudioEmitterMatchesLegacy) {
|
||||
ExpectTruncatedFails(full);
|
||||
}
|
||||
|
||||
// As live sent it to the NJ falling tiles: fading out, no emitter id, the GUID, no meta event, no result
|
||||
TEST_F(EffectsMessagesTests, StopNDAudioEmitterLikeLive) {
|
||||
const std::string guid = "{b7b848ad-7db0-4d51-a664-e38b386607dc}";
|
||||
const GameMessages::StopNDAudioEmitter msg(1, guid);
|
||||
RakNet::BitStream bitStream;
|
||||
msg.Serialize(bitStream);
|
||||
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), 1 + 1 + 32 + 38 * 8 + 32 + 1);
|
||||
EXPECT_EQ(bitStream.GetData()[0], 0x89);
|
||||
EXPECT_EQ(bitStream.GetData()[1], 0x80);
|
||||
const auto copy = RoundTrip(msg);
|
||||
EXPECT_TRUE(copy.allowNativeFadeOut);
|
||||
EXPECT_EQ(copy.NDAudioEventGUID, guid);
|
||||
GameMessages::StopNDAudioEmitter full(1, guid);
|
||||
full.allowNativeFadeOut = false;
|
||||
full.NDAudioEmitterID = 7;
|
||||
full.NDAudioMetaEventName = "meta";
|
||||
full.result = true;
|
||||
const auto fullCopy = RoundTrip(full);
|
||||
EXPECT_FALSE(fullCopy.allowNativeFadeOut);
|
||||
EXPECT_EQ(fullCopy.NDAudioEmitterID, 7u);
|
||||
EXPECT_EQ(fullCopy.NDAudioMetaEventName, "meta");
|
||||
EXPECT_TRUE(fullCopy.result);
|
||||
ExpectTruncatedFails(full);
|
||||
}
|
||||
|
||||
TEST_F(EffectsMessagesTests, PlayEmbeddedEffectMatchesLegacy) {
|
||||
for (const auto target : g_Targets) {
|
||||
Entity entity(target, info);
|
||||
|
||||
Reference in New Issue
Block a user