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>
123 lines
5.1 KiB
C++
123 lines
5.1 KiB
C++
#include "WavesManagerServer.h"
|
|
#include "Entity.h"
|
|
#include "EntityManager.h"
|
|
#include "BuffComponent.h"
|
|
#include "dZoneManager.h"
|
|
#include "Spawner.h"
|
|
#include "FireTempleCinematics.h"
|
|
|
|
namespace {
|
|
constexpr float CamDelay = 1.0f;
|
|
const std::string EnemySpawnerPre = "Waves_";
|
|
const std::string EnemySpawnerPost = "_Spawner";
|
|
const std::u16string DoorCam = u"WavesDoorCam";
|
|
const std::u16string SpawningCam = u"WavesSpawnerSpinners";
|
|
const std::string RoomVolume = "WavesRoomVolume";
|
|
const std::string DoorIndicators = "WavesDoorIndicator";
|
|
const std::string Door = "WavesDoor";
|
|
const std::string ElevatorSpinner = "WavesElevatorSpinner";
|
|
const std::string SpawnerSpinners = "WavesSpinner";
|
|
|
|
// The first object of the group, sent the event
|
|
void FireFirst(Entity* self, const std::string& group, const std::string& event) {
|
|
const auto objects = Game::entityManager->GetEntitiesInGroup(group);
|
|
for (auto* const object : objects) {
|
|
if (!object) continue;
|
|
object->OnFireEventServerSide(self, event);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
const std::vector<std::vector<WavesManagerServer::Enemy>>& WavesManagerServer::Waves() {
|
|
static const std::vector<std::vector<Enemy>> waves = {
|
|
{ { "Blacksmith", 3, 2 }, { "Hand", 2, 1 }, { "Marksman", 2, 1 } },
|
|
{ { "Hand", 2, 2 }, { "Scientist", 4, 2 }, { "Wolf", 2, 1 }, { "Beetle", 2, 1 } },
|
|
{ { "Blacksmith", 2, 1 }, { "Scientist", 2, 1 }, { "Marksman", 2, 1 }, { "Overseer", 2, 1 }, { "Wolf", 2, 1 },
|
|
{ "Beetle", 1, 1 }, { "Hand", 3, 1 }, { "Bonezai", 1, 1 } },
|
|
};
|
|
return waves;
|
|
}
|
|
|
|
void WavesManagerServer::OnCollisionPhantom(Entity* self, Entity* target) {
|
|
if (self->GetVar<bool>(u"bStarted")) return;
|
|
self->SetVar<bool>(u"bStarted", true);
|
|
auto* const zoneControl = Game::entityManager->GetZoneControlEntity();
|
|
if (zoneControl && zoneControl->GetVar<int32_t>(u"initialPlayerCount") > 2) self->SetVar<bool>(u"LargeTeam", true);
|
|
ActivateWaveSpinners(self, 1);
|
|
}
|
|
|
|
void WavesManagerServer::NotifyFireEvent(Entity* self, Entity* other, const std::string& args) {
|
|
if (args != "SpawnedEnemiesDead") return;
|
|
other->Unsubscribe(self->GetObjectID(), "FireEvent");
|
|
if (!self->HasVar(u"SpinnersActive")) return;
|
|
auto activeSpinners = self->GetVar<int32_t>(u"SpinnersActive") - 1;
|
|
if (activeSpinners < 0) {
|
|
LOG("Warning!! too many spinners deactivated");
|
|
return;
|
|
}
|
|
self->SetVar<int32_t>(u"SpinnersActive", activeSpinners);
|
|
if (activeSpinners > 0) return;
|
|
self->CancelTimer("ShowDoor");
|
|
self->AddTimer("ShowDoor", CamDelay);
|
|
}
|
|
|
|
void WavesManagerServer::ActivateWaveSpinners(Entity* self, const int32_t waveNum) {
|
|
if (waveNum > static_cast<int32_t>(Waves().size())) return;
|
|
PlayCamera(self, SpawningCam);
|
|
self->SetVar<int32_t>(u"CurrentWave", waveNum);
|
|
for (const auto& enemy : Waves()[waveNum - 1]) {
|
|
const auto spawners = Game::zoneManager->GetSpawnersByName(EnemySpawnerPre + enemy.name + EnemySpawnerPost);
|
|
if (spawners.empty() || !spawners.front()) continue;
|
|
auto* const spawner = spawners.front();
|
|
const auto spawnNum = self->GetVar<bool>(u"LargeTeam") ? enemy.largeNum : enemy.smallNum;
|
|
if (spawnNum <= 0) continue;
|
|
spawner->m_Info.maxToSpawn = spawnNum;
|
|
spawner->SetNumToMaintain(spawnNum);
|
|
auto spinnersUp = self->GetVar<int32_t>(u"SpinnersActive");
|
|
for (auto* const spinner : Game::entityManager->GetEntitiesInGroup(SpawnerSpinners + enemy.name)) {
|
|
if (!spinner) continue;
|
|
spinner->OnFireEventServerSide(self, "SpawnEnemies");
|
|
spinner->Subscribe(self->GetObjectID(), this, "FireEvent");
|
|
spinnersUp++;
|
|
}
|
|
self->SetVar<int32_t>(u"SpinnersActive", spinnersUp);
|
|
}
|
|
}
|
|
|
|
void WavesManagerServer::PlayCamera(Entity* self, const std::u16string& cine) {
|
|
const auto roomTrigger = Game::entityManager->GetEntitiesInGroup(RoomVolume);
|
|
for (auto* const trigger : roomTrigger) {
|
|
if (!trigger) continue;
|
|
const auto players = FireTempleCinematics::ObjectsInVolume(trigger);
|
|
if (players.empty()) return;
|
|
for (auto* const player : players) {
|
|
if (auto* const buff = player->GetComponent<BuffComponent>()) buff->RemoveBuff(60);
|
|
FireTempleCinematics::PlayCinematic(player, cine);
|
|
}
|
|
}
|
|
}
|
|
|
|
void WavesManagerServer::OnTimerDone(Entity* self, std::string timerName) {
|
|
if (timerName == "ShowDoor") {
|
|
PlayCamera(self, DoorCam);
|
|
self->CancelTimer("TurnOnIndicator");
|
|
self->AddTimer("TurnOnIndicator", 1.0f);
|
|
const auto cineTime = FireTempleCinematics::GetCinematicInfo(GeneralUtils::UTF16ToWTF8(DoorCam)).value_or(3.0f);
|
|
self->CancelTimer("SpawnNextWave");
|
|
self->AddTimer("SpawnNextWave", cineTime);
|
|
} else if (timerName == "TurnOnIndicator") {
|
|
const auto currentWave = self->GetVar<int32_t>(u"CurrentWave");
|
|
const auto indicators = Game::entityManager->GetEntitiesInGroup(DoorIndicators + std::to_string(currentWave));
|
|
if (indicators.empty()) return;
|
|
FireFirst(self, DoorIndicators + std::to_string(currentWave), "IndicatorOn");
|
|
if (currentWave == static_cast<int32_t>(Waves().size())) {
|
|
if (Game::entityManager->GetEntitiesInGroup(Door).empty()) return;
|
|
FireFirst(self, Door, "IndicatorOn");
|
|
FireFirst(self, ElevatorSpinner, "TurnOn");
|
|
}
|
|
} else if (timerName == "SpawnNextWave") {
|
|
ActivateWaveSpinners(self, self->GetVar<int32_t>(u"CurrentWave") + 1);
|
|
}
|
|
}
|