mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
Entity::Subscribe takes "FireEvent" (the Lua's notification request on FireEvent): the subscriber's script hears every FireEvent the object is sent (NotifyFireEvent). The Fire Temple waves manager uses it to hear its spinners being sent SpawnedEnemiesDead, which the spinners send to their own group once their enemies are dead (level config name_deactivated_event / group_deactivated_event). LEVEL:GetCinematicInfo is the camera path's time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
206 lines
9.3 KiB
C++
206 lines
9.3 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"
|
|
#include "02_server/Map/General/EventCounterUtil.h"
|
|
#include "02_server/Map/General/BossGarmadonTornado.h"
|
|
#include "02_server/Map/General/WavesManagerServer.h"
|
|
#include "EntityManager.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);
|
|
}
|
|
|
|
// L_EVENT_COUNTER_UTIL: max 1 by default; reaching it fires the max event at its group, once
|
|
TEST_F(FireTempleScriptsTest, EventCounterFiresAtMax) {
|
|
info.settings.Insert<std::u16string>(u"hit", u"increment");
|
|
info.settings.Insert<std::u16string>(u"maxHit_event", u"Open");
|
|
info.settings.Insert<std::u16string>(u"maxHit_group", u"TestDoors");
|
|
Entity entity(288300744895900206, info);
|
|
info.settings.values.clear();
|
|
EventCounterUtil counter;
|
|
counter.OnStartup(&entity);
|
|
EXPECT_EQ(entity.GetVar<int32_t>(u"max"), 1);
|
|
counter.OnFireEventServerSide(&entity, &entity, "hit", 0, 0, 0);
|
|
EXPECT_EQ(entity.GetVar<int32_t>(u"counter"), 1);
|
|
counter.OnFireEventServerSide(&entity, &entity, "hit", 0, 0, 0);
|
|
EXPECT_EQ(entity.GetVar<int32_t>(u"counter"), 1);
|
|
}
|
|
|
|
// L_BOSS_GARMADON_TORNADO: the bomb wait is a whole number of seconds from half the element's delay to all of it, and
|
|
// the boss manager's NewElement picks the element by its place in the order
|
|
TEST_F(FireTempleScriptsTest, TornadoBombsSoonerForLaterElements) {
|
|
for (int32_t i = 0; i < 50; i++) {
|
|
const auto earth = BossGarmadonTornado::BombDelay("earth");
|
|
EXPECT_GE(earth, 20);
|
|
EXPECT_LE(earth, 40);
|
|
const auto fire = BossGarmadonTornado::BombDelay("fire");
|
|
EXPECT_GE(fire, 14);
|
|
EXPECT_LE(fire, 28);
|
|
}
|
|
Entity entity(288300744895900207, info);
|
|
BossGarmadonTornado tornado;
|
|
tornado.OnNotifyObject(&entity, &entity, "NewElement", 3);
|
|
EXPECT_EQ(entity.GetVar<std::string>(u"CurrentElement"), "lightning");
|
|
tornado.OnNotifyObject(&entity, &entity, "NewElement", 0);
|
|
EXPECT_EQ(entity.GetVar<std::string>(u"CurrentElement"), "lightning");
|
|
}
|
|
|
|
// L_WAVES_MANAGER_SERVER: it hears its spinners being sent SpawnedEnemiesDead (a FireEvent subscription), stops
|
|
// listening to each, and when the last is done waits a moment and shows the door
|
|
TEST_F(FireTempleScriptsTest, WavesManagerHearsItsSpinnersFinish) {
|
|
// Creating an entity looks its LOT up in the CDClient
|
|
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, 288300744895900210);
|
|
auto* const first = Game::entityManager->CreateEntity(info, nullptr, nullptr, false, 288300744895900211);
|
|
auto* const second = Game::entityManager->CreateEntity(info, nullptr, nullptr, false, 288300744895900212);
|
|
WavesManagerServer waves;
|
|
manager->SetVar<int32_t>(u"SpinnersActive", 2);
|
|
first->Subscribe(manager->GetObjectID(), &waves, "FireEvent");
|
|
second->Subscribe(manager->GetObjectID(), &waves, "FireEvent");
|
|
|
|
first->OnFireEventServerSide(first, "SomethingElse");
|
|
EXPECT_EQ(manager->GetVar<int32_t>(u"SpinnersActive"), 2);
|
|
first->OnFireEventServerSide(first, "SpawnedEnemiesDead");
|
|
EXPECT_EQ(manager->GetVar<int32_t>(u"SpinnersActive"), 1);
|
|
// No longer listening to the first
|
|
first->OnFireEventServerSide(first, "SpawnedEnemiesDead");
|
|
EXPECT_EQ(manager->GetVar<int32_t>(u"SpinnersActive"), 1);
|
|
manager->Update(0.0f);
|
|
EXPECT_FALSE(manager->HasTimer("ShowDoor"));
|
|
|
|
second->OnFireEventServerSide(second, "SpawnedEnemiesDead");
|
|
EXPECT_EQ(manager->GetVar<int32_t>(u"SpinnersActive"), 0);
|
|
manager->Update(0.0f);
|
|
EXPECT_TRUE(manager->HasTimer("ShowDoor"));
|
|
}
|
|
|
|
// The waves as the Lua has them: three, the last with eight kinds
|
|
TEST_F(FireTempleScriptsTest, WavesManagerWaves) {
|
|
ASSERT_EQ(WavesManagerServer::Waves().size(), 3u);
|
|
EXPECT_EQ(WavesManagerServer::Waves()[2].size(), 8u);
|
|
EXPECT_EQ(WavesManagerServer::Waves()[0][0].largeNum, 3);
|
|
}
|