mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
feat(scripts): L_KILL_COUNTER_UTIL and the Fire Temple spinner volumes
The kill counter counts its spawn networks' deaths (or the events its config names) to max and back to min and fires the limit events at their groups. L_BSPINNERS_VOL and L_DSPINNERS_VOL extend it: at max each player in the volume sees the room's cinematic and 2 s later the rail quick build's network is activated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ set(DSCRIPTS_SOURCES_02_SERVER_MAP_GENERAL
|
||||
"ForceVolumeServer.cpp"
|
||||
"GrowingFlower.cpp"
|
||||
"ImaginationBackpackHealServer.cpp"
|
||||
"KillCounterUtil.cpp"
|
||||
"MailBoxServer.cpp"
|
||||
"NjRailSwitch.cpp"
|
||||
"PetDigServer.cpp"
|
||||
@@ -17,6 +18,7 @@ set(DSCRIPTS_SOURCES_02_SERVER_MAP_GENERAL
|
||||
"QbSpawner.cpp"
|
||||
"SimpleMoverSwitch.cpp"
|
||||
"SimpleOnceOnlyMoverSpinnerEvent.cpp"
|
||||
"SpinnersVol.cpp"
|
||||
"StoryBoxInteractServer.cpp"
|
||||
"TokenConsoleServer.cpp"
|
||||
"TouchMissionUpdateServer.cpp"
|
||||
|
||||
128
dScripts/02_server/Map/General/KillCounterUtil.cpp
Normal file
128
dScripts/02_server/Map/General/KillCounterUtil.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "KillCounterUtil.h"
|
||||
#include "Entity.h"
|
||||
#include "EntityManager.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "Spawner.h"
|
||||
#include "Logger.h"
|
||||
|
||||
namespace {
|
||||
// Where the counter starts from unless the object sets min
|
||||
constexpr int32_t DefaultCounterMin = 0;
|
||||
|
||||
bool IsFalse(Entity* self, const std::u16string& name) {
|
||||
return self->HasVar(name) && !self->GetVar<bool>(name);
|
||||
}
|
||||
}
|
||||
|
||||
// The spawner of each spawnNw1, spawnNw2, ... the object names, up to the first it does not
|
||||
std::vector<Spawner*> KillCounterUtil::SpawnNetworks(Entity* self) {
|
||||
std::vector<Spawner*> spawners;
|
||||
for (int32_t count = 1; self->HasVar(GeneralUtils::ASCIIToUTF16("spawnNw" + std::to_string(count))); count++) {
|
||||
const auto name = self->GetVarAsString(GeneralUtils::ASCIIToUTF16("spawnNw" + std::to_string(count)));
|
||||
const auto found = Game::zoneManager->GetSpawnersByName(name);
|
||||
spawners.push_back(found.empty() ? nullptr : found.front());
|
||||
}
|
||||
return spawners;
|
||||
}
|
||||
|
||||
void KillCounterUtil::OnStartup(Entity* self) {
|
||||
const auto cntMin = self->HasVar(u"min") ? self->GetVarAs<int32_t>(u"min") : DefaultCounterMin;
|
||||
self->SetVar<int32_t>(u"min", cntMin);
|
||||
self->SetVar<int32_t>(u"counter", cntMin);
|
||||
|
||||
const auto spawnNetworks = SpawnNetworks(self);
|
||||
if (!self->HasVar(u"max")) {
|
||||
int32_t cntMax = 1;
|
||||
if (!spawnNetworks.empty()) {
|
||||
int32_t cntTally = 0;
|
||||
for (auto* const spawner : spawnNetworks) {
|
||||
if (spawner && spawner->m_Info.maxToSpawn != -1) cntTally += spawner->m_Info.maxToSpawn;
|
||||
}
|
||||
if (cntTally == 0) LOG_DEBUG("Kill counter %llu has only infinite spawn networks", self->GetObjectID());
|
||||
else cntMax = cntTally;
|
||||
} else {
|
||||
LOG_DEBUG("Kill counter %llu has no max and no spawn networks", self->GetObjectID());
|
||||
}
|
||||
self->SetVar<int32_t>(u"max", cntMax);
|
||||
} else {
|
||||
self->SetVar<int32_t>(u"max", self->GetVarAs<int32_t>(u"max"));
|
||||
}
|
||||
|
||||
if (IsFalse(self, u"bManageNotifies")) return;
|
||||
if (!spawnNetworks.empty()) SpawnerNotifies(self, true);
|
||||
else LOG_DEBUG("Kill counter %llu manages notifies without spawn networks", self->GetObjectID());
|
||||
}
|
||||
|
||||
// Listening to the deaths of what the networks spawn (once per network; stopping only mutes it)
|
||||
void KillCounterUtil::SpawnerNotifies(Entity* self, const bool subscribe) {
|
||||
self->SetVar<bool>(u"killCounterListening", subscribe);
|
||||
if (!subscribe || self->GetVar<bool>(u"killCounterSubscribed")) return;
|
||||
self->SetVar<bool>(u"killCounterSubscribed", true);
|
||||
const auto selfID = self->GetObjectID();
|
||||
for (auto* const spawner : SpawnNetworks(self)) {
|
||||
if (!spawner) continue;
|
||||
spawner->AddSpawnedEntityDieCallback([this, selfID]() {
|
||||
auto* const counter = Game::entityManager->GetEntity(selfID);
|
||||
if (counter && counter->GetVar<bool>(u"killCounterListening")) ModifyCounter(counter, "increment");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void KillCounterUtil::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) {
|
||||
const auto name = GeneralUtils::ASCIIToUTF16(args);
|
||||
if (!self->HasVar(name)) return;
|
||||
const auto eventType = self->GetVarAsString(name);
|
||||
if (eventType == "increment" || eventType == "decrement") ModifyCounter(self, eventType);
|
||||
else if (eventType == "stopNotifies") SpawnerNotifies(self, false);
|
||||
else if (eventType == "startNotifies") SpawnerNotifies(self, true);
|
||||
else if (eventType == "reset") ResetCounter(self);
|
||||
}
|
||||
|
||||
void KillCounterUtil::ResetCounter(Entity* self) {
|
||||
self->SetVar<int32_t>(u"counter", self->GetVar<int32_t>(u"min"));
|
||||
if (IsFalse(self, u"bManageNotifies")) {
|
||||
SpawnerNotifies(self, false);
|
||||
return;
|
||||
}
|
||||
if (!SpawnNetworks(self).empty()) SpawnerNotifies(self, true);
|
||||
else LOG_DEBUG("Kill counter %llu manages notifies without spawn networks", self->GetObjectID());
|
||||
}
|
||||
|
||||
void KillCounterUtil::ModifyCounter(Entity* self, const std::string& modType) {
|
||||
auto counter = self->GetVar<int32_t>(u"counter");
|
||||
const auto cntMax = self->GetVar<int32_t>(u"max");
|
||||
if (modType == "increment") {
|
||||
counter++;
|
||||
if (counter == cntMax) {
|
||||
SendEvent(self, true);
|
||||
ProcessEvent(self, true);
|
||||
if (IsFalse(self, u"bAutoShutoff")) return;
|
||||
SpawnerNotifies(self, false);
|
||||
} else if (counter > cntMax) {
|
||||
return;
|
||||
}
|
||||
self->SetVar<int32_t>(u"counter", counter);
|
||||
} else if (modType == "decrement") {
|
||||
counter--;
|
||||
const auto cntMin = self->GetVar<int32_t>(u"min");
|
||||
if (counter == cntMin) {
|
||||
SendEvent(self, false);
|
||||
ProcessEvent(self, false);
|
||||
} else if (counter < cntMin) {
|
||||
return;
|
||||
}
|
||||
self->SetVar<int32_t>(u"counter", counter);
|
||||
}
|
||||
}
|
||||
|
||||
// The limit's event (maxHit_event / minHit_event) to every object in its group (maxHit_group / minHit_group)
|
||||
void KillCounterUtil::SendEvent(Entity* self, const bool upperLimitReached) {
|
||||
const std::u16string eventVar = upperLimitReached ? u"maxHit_event" : u"minHit_event";
|
||||
const std::u16string groupVar = upperLimitReached ? u"maxHit_group" : u"minHit_group";
|
||||
if (!self->HasVar(eventVar) || !self->HasVar(groupVar)) return;
|
||||
const auto eventName = self->GetVarAsString(eventVar);
|
||||
const auto eventGroup = self->GetVarAsString(groupVar);
|
||||
for (auto* const obj : Game::entityManager->GetEntitiesInGroup(eventGroup)) {
|
||||
if (obj) obj->OnFireEventServerSide(self, eventName);
|
||||
}
|
||||
}
|
||||
24
dScripts/02_server/Map/General/KillCounterUtil.h
Normal file
24
dScripts/02_server/Map/General/KillCounterUtil.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
class Spawner;
|
||||
|
||||
// L_KILL_COUNTER_UTIL.lua: counts the deaths of what its spawner networks (spawnNw1, spawnNw2, ...) spawn, from min
|
||||
// (0) to max (the networks' max_to_spawn when not set). At max it fires maxHit_event at maxHit_group and stops
|
||||
// listening (unless bAutoShutoff is false); back at min it fires minHit_event at minHit_group. Events it is sent by
|
||||
// name (a config value: increment, decrement, stopNotifies, startNotifies, reset) work the counter. Scripts that extend
|
||||
// it act on the limits in ProcessEvent.
|
||||
class KillCounterUtil : public CppScripts::Script {
|
||||
public:
|
||||
void OnStartup(Entity* self) override;
|
||||
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override;
|
||||
protected:
|
||||
// Reached max (true) or min (false)
|
||||
virtual void ProcessEvent(Entity* self, bool upperLimitReached) {}
|
||||
void ModifyCounter(Entity* self, const std::string& modType);
|
||||
private:
|
||||
void SpawnerNotifies(Entity* self, bool subscribe);
|
||||
void ResetCounter(Entity* self);
|
||||
void SendEvent(Entity* self, bool upperLimitReached);
|
||||
static std::vector<Spawner*> SpawnNetworks(Entity* self);
|
||||
};
|
||||
38
dScripts/02_server/Map/General/SpinnersVol.cpp
Normal file
38
dScripts/02_server/Map/General/SpinnersVol.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "SpinnersVol.h"
|
||||
#include "Entity.h"
|
||||
#include "EntityManager.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "Spawner.h"
|
||||
#include "EffectsMessages.h"
|
||||
#include "PhantomPhysicsComponent.h"
|
||||
#include "dpEntity.h"
|
||||
|
||||
namespace {
|
||||
// The wait before the rail's network is activated
|
||||
constexpr float SpawnDelay = 2.0f;
|
||||
}
|
||||
|
||||
void SpinnersVol::ProcessEvent(Entity* self, const bool upperLimitReached) {
|
||||
if (!upperLimitReached) return;
|
||||
// Each player in the volume sees the cinematic
|
||||
auto* const phantomPhysics = self->GetComponent<PhantomPhysicsComponent>();
|
||||
if (phantomPhysics && phantomPhysics->GetdpEntity()) {
|
||||
for (const auto id : phantomPhysics->GetdpEntity()->GetCurrentlyCollidingObjects()) {
|
||||
auto* const player = Game::entityManager->GetEntity(id);
|
||||
if (!player || !player->IsPlayer()) continue;
|
||||
GameMessages::PlayCinematic cinematic;
|
||||
cinematic.target = player->GetObjectID();
|
||||
cinematic.pathName = m_TargetCine;
|
||||
cinematic.Send(player->GetSystemAddress());
|
||||
}
|
||||
}
|
||||
// (a timer with cancel: a second one replaces the first)
|
||||
self->CancelTimer(m_TimerName);
|
||||
self->AddTimer(m_TimerName, SpawnDelay);
|
||||
}
|
||||
|
||||
void SpinnersVol::OnTimerDone(Entity* self, std::string timerName) {
|
||||
if (timerName != m_TimerName) return;
|
||||
const auto spawners = Game::zoneManager->GetSpawnersByName(m_TargetNetwork);
|
||||
if (!spawners.empty() && spawners.front()) spawners.front()->Activate();
|
||||
}
|
||||
30
dScripts/02_server/Map/General/SpinnersVol.h
Normal file
30
dScripts/02_server/Map/General/SpinnersVol.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "KillCounterUtil.h"
|
||||
|
||||
// L_BSPINNERS_VOL.lua and L_DSPINNERS_VOL.lua: the Fire Temple's Blade Spinners and Dart Spinners room volumes, kill
|
||||
// counters that, once all the room's enemies are dead, play a cinematic for each player in the volume and 2 s later
|
||||
// activate the spawner network of the rail quick build out of the room
|
||||
class SpinnersVol : public KillCounterUtil {
|
||||
public:
|
||||
SpinnersVol(const std::string& targetNetwork, const std::u16string& targetCine, const std::string& timerName)
|
||||
: m_TargetNetwork(targetNetwork), m_TargetCine(targetCine), m_TimerName(timerName) {}
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
protected:
|
||||
void ProcessEvent(Entity* self, bool upperLimitReached) override;
|
||||
private:
|
||||
std::string m_TargetNetwork;
|
||||
std::u16string m_TargetCine;
|
||||
std::string m_TimerName;
|
||||
};
|
||||
|
||||
// L_BSPINNERS_VOL.lua
|
||||
class BSpinnersVol : public SpinnersVol {
|
||||
public:
|
||||
BSpinnersVol() : SpinnersVol("BladeSpinners_IRail", u"PopUpBlades_IRail_QBSpawn", "SpawnIceRail") {}
|
||||
};
|
||||
|
||||
// L_DSPINNERS_VOL.lua
|
||||
class DSpinnersVol : public SpinnersVol {
|
||||
public:
|
||||
DSpinnersVol() : SpinnersVol("DartSpinEarthRail", u"3Tier_EarthRailSpawn", "SpawnEarthRail") {}
|
||||
};
|
||||
@@ -276,6 +276,8 @@
|
||||
#include "FireTransRocks.h"
|
||||
#include "FireTransRocksManager.h"
|
||||
#include "SimpleMoverSwitch.h"
|
||||
#include "KillCounterUtil.h"
|
||||
#include "SpinnersVol.h"
|
||||
#include "SimpleOnceOnlyMoverSpinnerEvent.h"
|
||||
#include "ImaginationShrineServer.h"
|
||||
#include "Lieutenant.h"
|
||||
@@ -691,6 +693,9 @@ namespace {
|
||||
{"scripts\\02_server\\Map\\njhub\\L_FIRE_TRANS_ROCKS_MANAGER.lua", []() {return new FireTransRocksManager();}},
|
||||
{"scripts\\02_server\\Map\\General\\L_SIMPLE_MOVER_SWITCH.lua", []() {return new SimpleMoverSwitch();}},
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_SIMPLE_ONCE_ONLY_MOVER_SPINNER_EVENT.lua", []() {return new SimpleOnceOnlyMoverSpinnerEvent();}},
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_BSPINNERS_VOL.lua", []() {return new BSpinnersVol();}},
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_DSPINNERS_VOL.lua", []() {return new DSpinnersVol();}},
|
||||
{"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();}},
|
||||
{"scripts\\02_server\\Map\\njhub\\L_LIEUTENANT.lua", []() {return new Lieutenant();}},
|
||||
|
||||
@@ -14,6 +14,7 @@ set(DGAMETEST_SOURCES
|
||||
"KnockbackTests.cpp"
|
||||
"ShootingGalleryTests.cpp"
|
||||
"MedusaScriptsTests.cpp"
|
||||
"FireTempleScriptsTests.cpp"
|
||||
"LuaAITests.cpp"
|
||||
"CollisionFilterTests.cpp"
|
||||
"MovementBlockerTests.cpp"
|
||||
|
||||
83
tests/dGameTests/FireTempleScriptsTests.cpp
Normal file
83
tests/dGameTests/FireTempleScriptsTests.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#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"
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user