diff --git a/dScripts/02_server/Map/General/CMakeLists.txt b/dScripts/02_server/Map/General/CMakeLists.txt index c2142666c..b33a813cb 100644 --- a/dScripts/02_server/Map/General/CMakeLists.txt +++ b/dScripts/02_server/Map/General/CMakeLists.txt @@ -26,7 +26,8 @@ set(DSCRIPTS_SOURCES_02_SERVER_MAP_GENERAL "TouchMissionUpdateServer.cpp" "VisToggleNotifierServer.cpp" "NTNaomiDirtServer.cpp" - "WishingWellServer.cpp") + "WishingWellServer.cpp" + "ZoneFireTempleServer.cpp") add_subdirectory(Ninjago) diff --git a/dScripts/02_server/Map/General/ZoneFireTempleServer.cpp b/dScripts/02_server/Map/General/ZoneFireTempleServer.cpp new file mode 100644 index 000000000..113b4fb2e --- /dev/null +++ b/dScripts/02_server/Map/General/ZoneFireTempleServer.cpp @@ -0,0 +1,50 @@ +#include "ZoneFireTempleServer.h" +#include "GameMessages.h" +#include "EffectsMessages.h" +#include "Entity.h" +#include "Character.h" +#include "CharacterComponent.h" +#include "Amf3.h" + +void ZoneFireTempleServer::OnZoneLoadedInfo(Entity* self, const GameMessages::ZoneLoadedInfo& info) { + self->SetVar(u"initialPlayerCount", info.maxPlayers); +} + +void ZoneFireTempleServer::ToggleActivityCloseButton(Entity* player, const bool show) { + AMFArrayValue args; + args.Insert("bShow", show); + GameMessages::UIMessageServerToSingleClient uiMessage; + uiMessage.target = player->GetObjectID(); + uiMessage.strMessageName = "ToggleActivityCloseButton"; + uiMessage.args = std::move(args); + uiMessage.SendToClient(player->GetSystemAddress()); +} + +// (The Lua also keeps a list of the players in the zone, which nothing reads.) +void ZoneFireTempleServer::OnPlayerLoaded(Entity* self, Entity* player) { + ToggleActivityCloseButton(player, true); +} + +void ZoneFireTempleServer::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) { + if (!sender) return; + const auto asked = u"|" + GeneralUtils::ASCIIToUTF16(std::to_string(sender->GetObjectID())); + if (identifier == u"ActivityButton" && !self->GetVar(asked)) { + self->SetVar(asked, true); + GameMessages::DisplayMessageBox messageBox; + messageBox.target = sender->GetObjectID(); + messageBox.bShow = true; + messageBox.imageID = 1; + messageBox.callbackClient = self->GetObjectID(); + messageBox.text = u"UI_EULA_CONFIRM_EXIT_LINE2"; + messageBox.identifier = u"Exit"; + messageBox.SendToClient(sender->GetSystemAddress()); + } else if (identifier == u"Exit") { + self->SetVar(asked, false); + if (button == 1) { + ToggleActivityCloseButton(sender, false); + auto* const character = sender->GetCharacter(); + auto* const characterComponent = sender->GetComponent(); + if (character && characterComponent) characterComponent->SendToZone(character->GetLastNonInstanceZoneID()); + } + } +} diff --git a/dScripts/02_server/Map/General/ZoneFireTempleServer.h b/dScripts/02_server/Map/General/ZoneFireTempleServer.h new file mode 100644 index 000000000..136c2ac25 --- /dev/null +++ b/dScripts/02_server/Map/General/ZoneFireTempleServer.h @@ -0,0 +1,13 @@ +#pragma once +#include "CppScripts.h" + +// L_ZONE_FIRE_TEMPLE_SERVER.lua: the Fire Temple instance's zone script. Each player gets the activity close button; +// using it asks to confirm leaving (UI_EULA_CONFIRM_EXIT_LINE2), and yes takes the button away and sends the player +// to the last zone that is not an instance. +class ZoneFireTempleServer : public CppScripts::Script { +public: + void OnZoneLoadedInfo(Entity* self, const GameMessages::ZoneLoadedInfo& info) override; + void OnPlayerLoaded(Entity* self, Entity* player) override; + void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) override; + static void ToggleActivityCloseButton(Entity* player, bool show); +}; diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index 32acbd5b6..75f805a8f 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -280,6 +280,7 @@ #include "SpinnersVol.h" #include "DoorIndicatorServer.h" #include "ElementalChestsServer.h" +#include "ZoneFireTempleServer.h" #include "SimpleOnceOnlyMoverSpinnerEvent.h" #include "ImaginationShrineServer.h" #include "Lieutenant.h" @@ -699,6 +700,7 @@ namespace { {"scripts\\02_server\\Map\\firetemple\\L_DSPINNERS_VOL.lua", []() {return new DSpinnersVol();}}, {"scripts\\02_server\\Map\\firetemple\\L_DOOR_INDICATOR_SERVER.lua", []() {return new DoorIndicatorServer();}}, {"scripts\\02_server\\Map\\firetemple\\L_ELEMENTAL_CHESTS_SERVER.lua", []() {return new ElementalChestsServer();}}, + {"scripts\\02_server\\Map\\firetemple\\L_ZONE_FIRE_TEMPLE_SERVER.lua", []() {return new ZoneFireTempleServer();}}, {"scripts\\02_server\\Map\\General\\L_KILL_COUNTER_UTIL.lua", []() {return new KillCounterUtil();}}, {"scripts\\02_server\\Enemy\\General\\L_ENEMY_NJ_BUFF_STUN_IMMUNITY.lua", []() {return new EnemyNjBuff();}}, {"scripts\\02_server\\Map\\njhub\\L_IMAGINATION_SHRINE_SERVER.lua", []() {return new ImaginationShrineServer();}}, diff --git a/tests/dGameTests/FireTempleScriptsTests.cpp b/tests/dGameTests/FireTempleScriptsTests.cpp index 37b7b1655..6090329e3 100644 --- a/tests/dGameTests/FireTempleScriptsTests.cpp +++ b/tests/dGameTests/FireTempleScriptsTests.cpp @@ -8,6 +8,8 @@ #include "02_server/Map/General/DoorIndicatorServer.h" #include "02_server/Map/General/ElementalChestsServer.h" #include "CDClientDatabase.h" +#include "02_server/Map/General/ZoneFireTempleServer.h" +#include "EffectsMessages.h" namespace { // A kill counter extension that records its limit events @@ -106,3 +108,21 @@ TEST_F(FireTempleScriptsTest, ElementalChestFlagIsItsPreconditionsTarget) { EXPECT_EQ(ElementalChestsServer::PreconditionFlag("322"), std::nullopt); EXPECT_EQ(ElementalChestsServer::PreconditionFlag(""), std::nullopt); } + +// L_ZONE_FIRE_TEMPLE_SERVER: the close button asks once to confirm; no keeps the player here, and the box can be asked +// for again +TEST_F(FireTempleScriptsTest, FireTempleExitAsksToConfirm) { + Entity zone(288300744895900204, info); + Entity player(288300744895900205, info); + ZoneFireTempleServer script; + auto* const mock = static_cast(Game::server); + mock->ClearSentPackets(); + script.OnMessageBoxResponse(&zone, &player, 1, u"ActivityButton", u""); + EXPECT_EQ(mock->GetSentPackets().size(), 1u); + // Asked again before answering: nothing more + script.OnMessageBoxResponse(&zone, &player, 1, u"ActivityButton", u""); + EXPECT_EQ(mock->GetSentPackets().size(), 1u); + script.OnMessageBoxResponse(&zone, &player, 0, u"Exit", u""); + script.OnMessageBoxResponse(&zone, &player, 1, u"ActivityButton", u""); + EXPECT_EQ(mock->GetSentPackets().size(), 2u); +}