mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 18:01:39 +00:00
The Fire Temple boss's tornado: a moving platform on a random BossTornadoPath_ path, a new one at each path's end; it smashes the faction 130 quick builds it touches, casts skill 1741 on players it touches and drops bombs (LOT 16891) on a random player in the boss game space, sooner for the later elements. Its proximity is a 24 x 30 x 24 box for the Lua's cylinder (12 round, 30 high). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
166 lines
7.2 KiB
C++
166 lines
7.2 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"
|
|
|
|
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");
|
|
}
|