mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
feat(messages): CelebrationCompleted, and scripts can listen for a player's celebration ending
The client sends CelebrationCompleted with no payload when a celebration ends; scripts subscribed to the player
("CelebrationCompleted", the Lua's notification request) hear it. As the message carries no celebration id, a script
that needs it remembers which one it started.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -589,7 +589,7 @@ void Entity::Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd, co
|
||||
} else if (notificationName == "PlayerResurrectionFinished") {
|
||||
LOG("Subscribing to PlayerResurrectionFinished");
|
||||
m_Subscriptions[scriptObjId][notificationName] = scriptToAdd;
|
||||
} else if (notificationName == "FireEvent") {
|
||||
} else if (notificationName == "FireEvent" || notificationName == "CelebrationCompleted") {
|
||||
m_Subscriptions[scriptObjId][notificationName] = scriptToAdd;
|
||||
}
|
||||
}
|
||||
@@ -602,7 +602,7 @@ void Entity::Unsubscribe(LWOOBJID scriptObjId, const std::string& notificationNa
|
||||
} else if (notificationName == "PlayerResurrectionFinished") {
|
||||
LOG("Unsubscribing from PlayerResurrectionFinished");
|
||||
m_Subscriptions[scriptObjId].erase(notificationName);
|
||||
} else if (notificationName == "FireEvent") {
|
||||
} else if (notificationName == "FireEvent" || notificationName == "CelebrationCompleted") {
|
||||
m_Subscriptions[scriptObjId].erase(notificationName);
|
||||
}
|
||||
}
|
||||
@@ -1928,3 +1928,14 @@ bool Entity::MsgChildRemoved(GameMessages::ChildRemoved& msg) {
|
||||
GetScript()->OnChildRemoved(*this, msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Entity::NotifyCelebrationCompleted() {
|
||||
// A copy: a script may cancel its request
|
||||
const auto subscriptions = m_Subscriptions;
|
||||
for (const auto& [subscriberID, scripts] : subscriptions) {
|
||||
const auto it = scripts.find("CelebrationCompleted");
|
||||
if (it == scripts.end()) continue;
|
||||
auto* const subscriber = Game::entityManager->GetEntity(subscriberID);
|
||||
if (subscriber) it->second->NotifyCelebrationCompleted(subscriber, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,6 +200,8 @@ public:
|
||||
|
||||
void Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd, const std::string& notificationName);
|
||||
void Unsubscribe(LWOOBJID scriptObjId, const std::string& notificationName);
|
||||
// Tells the scripts subscribed to "CelebrationCompleted" that this player's celebration ended
|
||||
void NotifyCelebrationCompleted();
|
||||
|
||||
void SetProximityRadius(float proxRadius, std::string name, uint32_t collisionGroup = 0);
|
||||
void SetProximityRadius(dpEntity* entity, std::string name);
|
||||
|
||||
@@ -296,6 +296,11 @@ namespace GameMessages {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The scripts that asked to hear of the player's celebrations ending
|
||||
void CelebrationCompleted::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
entity.NotifyCelebrationCompleted();
|
||||
}
|
||||
|
||||
void MessageBoxRespond::Handle(Entity& entityRef, const SystemAddress& sysAddr) {
|
||||
Entity* entity = &entityRef;
|
||||
LOG("Button: %d; LOT: %u identifier: %s; userData: %s", iButton, entity->GetLOT(), GeneralUtils::UTF16ToWTF8(identifier).c_str(), GeneralUtils::UTF16ToWTF8(userData).c_str());
|
||||
|
||||
@@ -205,6 +205,14 @@ namespace GameMessages {
|
||||
};
|
||||
|
||||
// Server -> client.
|
||||
// Client -> server: the player's celebration (StartCelebrationEffect) has ended. No payload, as the client writes it.
|
||||
struct CelebrationCompleted : public NetGameMsg {
|
||||
CelebrationCompleted() : NetGameMsg(MessageType::Game::CELEBRATION_COMPLETED) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override {}
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override { return true; }
|
||||
void Handle(Entity& entity, const SystemAddress& sysAddr) override;
|
||||
};
|
||||
|
||||
struct DisplayMessageBox : public NetGameMsg {
|
||||
DisplayMessageBox() : NetGameMsg(MessageType::Game::DISPLAY_MESSAGE_BOX) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
|
||||
@@ -78,6 +78,7 @@ json ToJson(const GameMessages::Stop2DAmbientSound& m);
|
||||
json ToJson(const GameMessages::UIMessageServerToSingleClient& m);
|
||||
json ToJson(const GameMessages::UIMessageServerToAllClients& m);
|
||||
json ToJson(const GameMessages::StartCelebrationEffect& m);
|
||||
json ToJson(const GameMessages::CelebrationCompleted& m);
|
||||
json ToJson(const GameMessages::DisplayMessageBox& m);
|
||||
json ToJson(const GameMessages::MessageBoxRespond& m);
|
||||
json ToJson(const GameMessages::ChoiceBoxRespond& m);
|
||||
@@ -930,6 +931,10 @@ json ToJson(const GameMessages::StartCelebrationEffect& m) {
|
||||
j["subText"] = ToJson(m.subText);
|
||||
return j;
|
||||
}
|
||||
json ToJson(const GameMessages::CelebrationCompleted& m) {
|
||||
json j = json::object();
|
||||
return j;
|
||||
}
|
||||
json ToJson(const GameMessages::DisplayMessageBox& m) {
|
||||
json j = json::object();
|
||||
j["bShow"] = ToJson(m.bShow);
|
||||
@@ -2636,6 +2641,7 @@ const std::vector<Entry>& Entries() {
|
||||
{ MessageType::Game::UI_MESSAGE_SERVER_TO_SINGLE_CLIENT, eDirection::TO_CLIENT, "UIMessageServerToSingleClient", &ReadWith<GameMessages::UIMessageServerToSingleClient> },
|
||||
{ MessageType::Game::UI_MESSAGE_SERVER_TO_ALL_CLIENTS, eDirection::TO_CLIENT, "UIMessageServerToAllClients", &ReadWith<GameMessages::UIMessageServerToAllClients> },
|
||||
{ MessageType::Game::START_CELEBRATION_EFFECT, eDirection::TO_CLIENT, "StartCelebrationEffect", &ReadWith<GameMessages::StartCelebrationEffect> },
|
||||
{ MessageType::Game::CELEBRATION_COMPLETED, eDirection::TO_SERVER, "CelebrationCompleted", &ReadWith<GameMessages::CelebrationCompleted> },
|
||||
{ MessageType::Game::DISPLAY_MESSAGE_BOX, eDirection::TO_CLIENT, "DisplayMessageBox", &ReadWith<GameMessages::DisplayMessageBox> },
|
||||
{ MessageType::Game::MESSAGE_BOX_RESPOND, eDirection::TO_SERVER, "MessageBoxRespond", &ReadWith<GameMessages::MessageBoxRespond> },
|
||||
{ MessageType::Game::CHOICE_BOX_RESPOND, eDirection::TO_SERVER, "ChoiceBoxRespond", &ReadWith<GameMessages::ChoiceBoxRespond> },
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace {
|
||||
// Effects, emotes, cinematics, UI
|
||||
{ PLAY_EMOTE, []() { return std::make_unique<PlayEmote>(); } },
|
||||
{ MESSAGE_BOX_RESPOND, []() { return std::make_unique<MessageBoxRespond>(); } },
|
||||
{ CELEBRATION_COMPLETED, []() { return std::make_unique<CelebrationCompleted>(); } },
|
||||
{ CHOICE_BOX_RESPOND, []() { return std::make_unique<ChoiceBoxRespond>(); } },
|
||||
{ CINEMATIC_UPDATE, []() { return std::make_unique<CinematicUpdate>(); } },
|
||||
|
||||
|
||||
@@ -199,6 +199,14 @@ namespace CppScripts {
|
||||
*/
|
||||
virtual void NotifyFireEvent(Entity* self, Entity* other, const std::string& args) {};
|
||||
|
||||
/**
|
||||
* Invoked when a player self subscribed to ("CelebrationCompleted") has finished a celebration. The client's
|
||||
* message carries nothing, so a script that needs to know which one remembers what it started.
|
||||
*
|
||||
* Equivalent to 'function notifyCelebrationCompleted(self, player, msg)'
|
||||
*/
|
||||
virtual void NotifyCelebrationCompleted(Entity* self, Entity* player) {};
|
||||
|
||||
/**
|
||||
* Invoked when a player has responsed to a mission.
|
||||
*
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "02_server/Map/General/BossGarmadonTornado.h"
|
||||
#include "02_server/Map/General/WavesManagerServer.h"
|
||||
#include "EntityManager.h"
|
||||
#include "BitStream.h"
|
||||
|
||||
namespace {
|
||||
// A kill counter extension that records its limit events
|
||||
@@ -203,3 +204,32 @@ TEST_F(FireTempleScriptsTest, WavesManagerWaves) {
|
||||
EXPECT_EQ(WavesManagerServer::Waves()[2].size(), 8u);
|
||||
EXPECT_EQ(WavesManagerServer::Waves()[0][0].largeNum, 3);
|
||||
}
|
||||
|
||||
namespace {
|
||||
class CelebrationListener : public CppScripts::Script {
|
||||
public:
|
||||
std::vector<LWOOBJID> heard;
|
||||
void NotifyCelebrationCompleted(Entity* self, Entity* player) override { heard.push_back(player->GetObjectID()); }
|
||||
};
|
||||
}
|
||||
|
||||
// The client's CelebrationCompleted (no payload) reaches the scripts that subscribed to the player, until they cancel
|
||||
TEST_F(FireTempleScriptsTest, CelebrationCompletedReachesSubscribers) {
|
||||
CDClientDatabase::Connect(":memory:");
|
||||
CDClientDatabase::ExecuteDML("CREATE TABLE IF NOT EXISTS ComponentsRegistry (id INTEGER, component_type INTEGER, component_id INTEGER);");
|
||||
CDClientDatabase::ExecuteDML("CREATE TABLE IF NOT EXISTS Objects (id INTEGER, name TEXT, type TEXT, interactionDistance REAL);");
|
||||
auto* const manager = Game::entityManager->CreateEntity(info, nullptr, nullptr, false, 288300744895900220);
|
||||
auto* const player = Game::entityManager->CreateEntity(info, nullptr, nullptr, false, 288300744895900221);
|
||||
CelebrationListener listener;
|
||||
player->Subscribe(manager->GetObjectID(), &listener, "CelebrationCompleted");
|
||||
GameMessages::CelebrationCompleted message;
|
||||
RakNet::BitStream bitStream;
|
||||
message.Serialize(bitStream);
|
||||
EXPECT_EQ(bitStream.GetNumberOfBitsUsed(), 0u);
|
||||
message.Handle(*player, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
ASSERT_EQ(listener.heard.size(), 1u);
|
||||
EXPECT_EQ(listener.heard[0], player->GetObjectID());
|
||||
player->Unsubscribe(manager->GetObjectID(), "CelebrationCompleted");
|
||||
message.Handle(*player, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
EXPECT_EQ(listener.heard.size(), 1u);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user