mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
Either named event lights the Fire Temple door indicator's flame (FlameOn), as the Lua does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
3.8 KiB
C++
97 lines
3.8 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"
|
|
|
|
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"));
|
|
}
|