Files
DarkflameServer/tests/dGameTests/FireTempleScriptsTests.cpp
Aaron Kimbrell a30f3bf904 feat(scripts): L_ZONE_FIRE_TEMPLE_SERVER
Each player gets the activity close button; it asks to confirm leaving, and yes takes the button away and sends the
player to their last zone that is not an instance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 11:45:47 -06:00

129 lines
5.5 KiB
C++

#include "GameDependencies.h"
#include <gtest/gtest.h>
#include "Entity.h"
#include "GameMessages.h"
#include "02_server/Map/General/KillCounterUtil.h"
#include "02_server/Map/General/SpinnersVol.h"
#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
class TestCounter : public KillCounterUtil {
public:
std::vector<bool> events;
protected:
void ProcessEvent(Entity* self, bool upperLimitReached) override { events.push_back(upperLimitReached); }
};
}
class FireTempleScriptsTest : public GameDependenciesTest {
protected:
void SetUp() override { SetUpDependencies(); }
void TearDown() override { TearDownDependencies(); }
};
// L_KILL_COUNTER_UTIL: events named by the object's config count up to max and back down to min; past either end
// nothing more happens
TEST_F(FireTempleScriptsTest, KillCounterCountsToItsLimits) {
info.settings.Insert<int32_t>(u"max", 2);
info.settings.Insert<std::u16string>(u"up", u"increment");
info.settings.Insert<std::u16string>(u"down", u"decrement");
Entity entity(288300744895900200, info);
info.settings.values.clear();
TestCounter counter;
counter.OnStartup(&entity);
EXPECT_EQ(entity.GetVar<int32_t>(u"min"), 0);
EXPECT_EQ(entity.GetVar<int32_t>(u"max"), 2);
counter.OnFireEventServerSide(&entity, &entity, "up", 0, 0, 0);
EXPECT_TRUE(counter.events.empty());
counter.OnFireEventServerSide(&entity, &entity, "up", 0, 0, 0);
ASSERT_EQ(counter.events.size(), 1u);
EXPECT_TRUE(counter.events[0]);
EXPECT_EQ(entity.GetVar<int32_t>(u"counter"), 2);
counter.OnFireEventServerSide(&entity, &entity, "up", 0, 0, 0);
EXPECT_EQ(entity.GetVar<int32_t>(u"counter"), 2);
// An event the config does not name does nothing
counter.OnFireEventServerSide(&entity, &entity, "increment", 0, 0, 0);
EXPECT_EQ(entity.GetVar<int32_t>(u"counter"), 2);
counter.OnFireEventServerSide(&entity, &entity, "down", 0, 0, 0);
counter.OnFireEventServerSide(&entity, &entity, "down", 0, 0, 0);
ASSERT_EQ(counter.events.size(), 2u);
EXPECT_FALSE(counter.events[1]);
EXPECT_EQ(entity.GetVar<int32_t>(u"counter"), 0);
counter.OnFireEventServerSide(&entity, &entity, "down", 0, 0, 0);
EXPECT_EQ(entity.GetVar<int32_t>(u"counter"), 0);
}
// Without max or spawn networks the counter's max is 1
TEST_F(FireTempleScriptsTest, KillCounterWithoutNetworksCountsToOne) {
Entity entity(288300744895900201, info);
TestCounter counter;
counter.OnStartup(&entity);
EXPECT_EQ(entity.GetVar<int32_t>(u"max"), 1);
}
// The spinner volumes at max: a timer, then the rail's network; at min nothing
TEST_F(FireTempleScriptsTest, SpinnersVolStartsItsRailTimerAtMax) {
info.settings.Insert<int32_t>(u"max", 1);
info.settings.Insert<std::u16string>(u"up", u"increment");
Entity entity(288300744895900202, info);
info.settings.values.clear();
BSpinnersVol blades;
blades.OnStartup(&entity);
EXPECT_FALSE(entity.HasTimer("SpawnIceRail"));
blades.OnFireEventServerSide(&entity, &entity, "up", 0, 0, 0);
// (a new timer starts on the object's next update)
entity.Update(0.0f);
EXPECT_TRUE(entity.HasTimer("SpawnIceRail"));
// No spawner of that name: nothing to activate
blades.OnTimerDone(&entity, "SpawnIceRail");
}
// L_DOOR_INDICATOR_SERVER: either named event lights the flame; any other does nothing
TEST_F(FireTempleScriptsTest, DoorIndicatorLightsOnEitherEvent) {
info.settings.Insert<std::u16string>(u"name_activated_event", u"DoorOpen");
info.settings.Insert<std::u16string>(u"name_deactivated_event", u"DoorClose");
Entity entity(288300744895900203, info);
info.settings.values.clear();
DoorIndicatorServer indicator;
indicator.OnFireEventServerSide(&entity, &entity, "Other", 0, 0, 0);
EXPECT_FALSE(entity.GetNetworkVar<bool>(u"FlameOn"));
indicator.OnFireEventServerSide(&entity, &entity, "DoorClose", 0, 0, 0);
EXPECT_TRUE(entity.GetNetworkVar<bool>(u"FlameOn"));
}
// L_ELEMENTAL_CHESTS_SERVER: the flag set on use is the chest's precondition's target
TEST_F(FireTempleScriptsTest, ElementalChestFlagIsItsPreconditionsTarget) {
CDClientDatabase::Connect(":memory:");
CDClientDatabase::ExecuteDML("CREATE TABLE Preconditions (id INTEGER, type INTEGER, targetLOT TEXT, targetCount INTEGER, validContexts INTEGER);");
CDClientDatabase::ExecuteDML("INSERT INTO Preconditions VALUES (321, 23, '2063', 1, 0);");
EXPECT_EQ(ElementalChestsServer::PreconditionFlag("321"), 2063u);
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<dServerMock*>(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);
}