mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
feat(scripts): L_BOSS_MANAGER_SERVER
The Fire Temple boss fight: intro celebration and camera, the centre portal and the tornado, four elemental phases whose portal moves between its spawner's nodes and is hit by riders of the element's rail, the middle celebration, Garmadon stunned and a wave of spinner enemies each fifth of his health, then the end bouncer. The client's CelebrationCompleted carries no celebration id, so the manager branches on the celebration it started. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
461
dScripts/02_server/Map/General/BossManagerServer.cpp
Normal file
461
dScripts/02_server/Map/General/BossManagerServer.cpp
Normal file
@@ -0,0 +1,461 @@
|
||||
#include "BossManagerServer.h"
|
||||
#include "Entity.h"
|
||||
#include "EntityManager.h"
|
||||
#include "BuffComponent.h"
|
||||
#include "DestroyableComponent.h"
|
||||
#include "MissionComponent.h"
|
||||
#include "RenderComponent.h"
|
||||
#include "CombatMessages.h"
|
||||
#include "EffectsMessages.h"
|
||||
#include "MovementMessages.h"
|
||||
#include "ObjectMessages.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "Spawner.h"
|
||||
#include "Zone.h"
|
||||
#include "eStateChangeType.h"
|
||||
#include "FireTempleCinematics.h"
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
namespace {
|
||||
const std::vector<std::string> ElementalOrder = { "earth", "ice", "lightning", "fire" };
|
||||
// Seconds before the portal moves, per element
|
||||
float TeleportTime(const std::string& element) {
|
||||
if (element == "earth") return 40.0f;
|
||||
if (element == "ice") return 30.0f;
|
||||
if (element == "lightning") return 40.0f;
|
||||
if (element == "fire") return 20.0f;
|
||||
return 0.0f;
|
||||
}
|
||||
// The waypoint of the element's rail at which a rider hits the portal
|
||||
int32_t RailNode(const std::string& element) {
|
||||
if (element == "earth") return 14;
|
||||
if (element == "ice") return 5;
|
||||
if (element == "lightning") return 10;
|
||||
if (element == "fire") return 3;
|
||||
return -1;
|
||||
}
|
||||
const std::string CutsceneVolume = "BossCutsceneVolume";
|
||||
const std::string SpawnerSpinners = "BossSpawnerSpinners";
|
||||
const std::string CenterPortalSpawner = "BossCenterPortal";
|
||||
const std::string ElementalPortalSpawner = "BossPortalSpawn_";
|
||||
const std::string LGTornadoSpawner = "BossLGTornado";
|
||||
const std::string EndpostSpawner = "BossEndposts_";
|
||||
const std::string ActivatorSpawner = "BossActivators_";
|
||||
const std::string GarmadonSpawner = "BossLordGarmadon";
|
||||
const std::string BaseEnemiesSpawner = "BossSpawnerSpinner_";
|
||||
const std::string BouncerSpawner = "BossEndBouncer";
|
||||
const std::string LightningBouncerSpawner = "BossLightningBouncers";
|
||||
const std::u16string BeginningCine = u"BossStartCam";
|
||||
const std::u16string Phase2Cine = u"BossLGCam";
|
||||
const std::u16string SpawnWaveCine = u"BossSpawnWaveCam";
|
||||
const std::u16string WaveOverCine = u"BossWaveOverCam";
|
||||
const std::u16string SpawnBouncerCine = u"BossEndBouncerSpawnCam";
|
||||
constexpr int32_t IntroCutScene = 26;
|
||||
constexpr int32_t PortalDeadCutScene = 27;
|
||||
constexpr float DelayToCounterSpawn = 2.0f;
|
||||
constexpr uint32_t DestroyPortalMission = 2094;
|
||||
constexpr LOT Tornado = 16807;
|
||||
constexpr LOT Portal = 16802;
|
||||
constexpr LOT Garmadon = 16810;
|
||||
|
||||
struct WaveEnemy {
|
||||
LOT lot;
|
||||
int32_t largeNum;
|
||||
int32_t smallNum;
|
||||
};
|
||||
// blacksmith 16836, overseer 16847, marksman 16849, wolf 13996, beetle 13998, vulture 14000, hand 14002,
|
||||
// frakjaw 16854
|
||||
const std::vector<std::vector<WaveEnemy>> Waves = {
|
||||
{ { 16849, 2, 1 }, { 13998, 2, 1 }, { 16836, 2, 1 }, { 13996, 2, 1 } },
|
||||
{ { 13998, 1, 0 }, { 16836, 2, 2 }, { 14000, 3, 2 }, { 16847, 2, 1 } },
|
||||
{ { 16836, 2, 1 }, { 14002, 4, 2 }, { 14000, 2, 2 }, { 16849, 2, 0 } },
|
||||
{ { 14002, 2, 2 }, { 16854, 1, 1 }, { 16836, 3, 1 }, { 13998, 2, 0 } },
|
||||
};
|
||||
|
||||
Spawner* GetSpawner(const std::string& name) {
|
||||
const auto spawners = Game::zoneManager->GetSpawnersByName(name);
|
||||
return spawners.empty() ? nullptr : spawners.front();
|
||||
}
|
||||
|
||||
void AddTimerWithCancel(Entity* self, const std::string& name, const float time) {
|
||||
self->CancelTimer(name);
|
||||
self->AddTimer(name, time);
|
||||
}
|
||||
|
||||
float CinematicTime(const std::u16string& cine) {
|
||||
return FireTempleCinematics::GetCinematicInfo(GeneralUtils::UTF16ToWTF8(cine)).value_or(3.0f);
|
||||
}
|
||||
|
||||
void Stun(Entity* object, const eStateChangeType type) {
|
||||
GameMessages::SetStunned stun;
|
||||
stun.target = object->GetObjectID();
|
||||
stun.StateChangeType = type;
|
||||
stun.bCantAttack = true;
|
||||
stun.bCantMove = true;
|
||||
stun.bIgnoreImmunity = true;
|
||||
stun.bCantTurn = true;
|
||||
stun.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
||||
Entity* VarEntity(Entity* self, const std::u16string& name) {
|
||||
return Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(name));
|
||||
}
|
||||
}
|
||||
|
||||
bool BossManagerServer::ReachedWave(const float health, const float maxHealth, const int32_t nextWave) {
|
||||
return health <= (maxHealth - (maxHealth * ((1.0f / (static_cast<float>(Waves.size()) + 1.0f) * static_cast<float>(nextWave)))));
|
||||
}
|
||||
|
||||
void BossManagerServer::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);
|
||||
PlayCelebration(self, IntroCutScene);
|
||||
AddTimerWithCancel(self, "SpawnStartingPortal", 1.0f);
|
||||
}
|
||||
|
||||
void BossManagerServer::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) {
|
||||
if (name != "ActivatorUsed" || !sender) return;
|
||||
if (param1 != self->GetVar<int32_t>(u"PortalNode")) return;
|
||||
sender->Subscribe(self->GetObjectID(), this, "PlayerRailArrivedNotification");
|
||||
self->CancelTimer("TeleportPortal");
|
||||
}
|
||||
|
||||
void BossManagerServer::NotifyCelebrationCompleted(Entity* self, Entity* player) {
|
||||
player->Unsubscribe(self->GetObjectID(), "CelebrationCompleted");
|
||||
const auto playersStillInCutscene = self->GetVar<int32_t>(u"PlayersInCutscene") - 1;
|
||||
self->SetVar<int32_t>(u"PlayersInCutscene", playersStillInCutscene);
|
||||
if (playersStillInCutscene > 0) return;
|
||||
// (the celebration this manager started: the client's message has no id)
|
||||
const auto celebrationID = self->GetVar<int32_t>(u"CurrentCelebration");
|
||||
if (celebrationID == IntroCutScene) {
|
||||
PlayCinematic(self, BeginningCine);
|
||||
const auto cineTime = CinematicTime(BeginningCine);
|
||||
AddTimerWithCancel(self, "KillStartingPortal", cineTime - 0.5f);
|
||||
AddTimerWithCancel(self, "UnstunTornado", cineTime);
|
||||
} else if (celebrationID == PortalDeadCutScene) {
|
||||
UpdateMission(self);
|
||||
PlayCinematic(self, Phase2Cine);
|
||||
const auto cineTime = CinematicTime(Phase2Cine);
|
||||
const auto garmadon = self->GetVar<LWOOBJID>(u"Garmadon");
|
||||
GameMessages::NotifyClientObject(self->GetObjectID(), u"TurnOnHealthBar", 0, 0, garmadon).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
AddTimerWithCancel(self, "Unstun_" + std::to_string(garmadon), cineTime + 5.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void BossManagerServer::NotifyPlayerRailArrived(Entity* self, Entity* activator, const std::u16string& pathName, int32_t waypointNumber) {
|
||||
const auto* const path = Game::zoneManager->GetZone()->GetPath(GeneralUtils::UTF16ToWTF8(pathName));
|
||||
const auto pathLength = path ? static_cast<int32_t>(path->pathWaypoints.size()) : 0;
|
||||
if (waypointNumber == pathLength - 1) {
|
||||
activator->Smash(self->GetObjectID());
|
||||
return;
|
||||
}
|
||||
if (self->GetVar<bool>(u"PortalHit")) return;
|
||||
const auto elementNum = self->GetVar<int32_t>(u"ElementNumber");
|
||||
if (elementNum < 1 || elementNum > static_cast<int32_t>(ElementalOrder.size())) return;
|
||||
if (waypointNumber != RailNode(ElementalOrder[elementNum - 1])) return;
|
||||
self->SetVar<bool>(u"PortalHit", true);
|
||||
if (!self->GetVar<bool>(u"PortalAlreadyHitOnce")) {
|
||||
self->SetVar<bool>(u"PortalAlreadyHitOnce", true);
|
||||
AddTimerWithCancel(self, "TeleportPortal", 1.0f);
|
||||
} else {
|
||||
self->SetVar<bool>(u"PortalAlreadyHitOnce", true);
|
||||
// (the Lua plays onhit on the portal's spawner, which has no animation: its 1.5 s default)
|
||||
AddTimerWithCancel(self, "StartNextElementalPhase", 1.5f);
|
||||
}
|
||||
}
|
||||
|
||||
void BossManagerServer::ListenToSpawner(Entity* self, Spawner* spawner) {
|
||||
if (!spawner) return;
|
||||
const auto var = GeneralUtils::ASCIIToUTF16("listening_" + spawner->GetName());
|
||||
if (self->GetVar<bool>(var)) return;
|
||||
self->SetVar<bool>(var, true);
|
||||
const auto selfID = self->GetObjectID();
|
||||
spawner->AddEntitySpawnedCallback([this, selfID, spawner](Entity* object) {
|
||||
auto* const manager = Game::entityManager->GetEntity(selfID);
|
||||
if (manager && object) SpawnedObjectLoaded(manager, object, spawner->GetNodeIndex(object->GetObjectID()));
|
||||
});
|
||||
}
|
||||
|
||||
void BossManagerServer::SpawnedObjectLoaded(Entity* self, Entity* object, const int32_t spawnNode) {
|
||||
const auto lot = object->GetLOT();
|
||||
if (lot == Tornado) {
|
||||
self->SetVar<LWOOBJID>(u"LGTornado", object->GetObjectID());
|
||||
} else if (lot == Portal) {
|
||||
self->SetVar<LWOOBJID>(u"Portal", object->GetObjectID());
|
||||
self->SetVar<int32_t>(u"PortalNode", spawnNode);
|
||||
AddTimerWithCancel(self, "TeleportPortal", TeleportTime(self->GetVar<std::string>(u"CurrentElement")));
|
||||
} else if (lot == Garmadon) {
|
||||
self->SetVar<LWOOBJID>(u"Garmadon", object->GetObjectID());
|
||||
Stun(object, eStateChangeType::PUSH);
|
||||
object->SetVar<LWOOBJID>(u"BossManager", self->GetObjectID());
|
||||
object->Subscribe(self->GetObjectID(), this, "HitOrHealResult");
|
||||
self->SetVar<int32_t>(u"WaveNum", 0);
|
||||
m_GarmadonPos = object->GetPosition();
|
||||
m_GarmadonRot = object->GetRotation();
|
||||
if (auto* const destroyable = object->GetComponent<DestroyableComponent>()) {
|
||||
std::string factions;
|
||||
for (const auto faction : destroyable->GetFactionIDs()) factions += std::to_string(faction) + ";";
|
||||
self->SetVar<std::string>(u"LGFaction", factions);
|
||||
if (self->GetVar<bool>(u"LargeTeam")) {
|
||||
const auto health = destroyable->GetHealth() * 2;
|
||||
destroyable->SetMaxHealth(static_cast<float>(health));
|
||||
destroyable->SetHealth(health);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// self is Garmadon, the subscribed object
|
||||
void BossManagerServer::NotifyHitOrHealResult(Entity* self, Entity* attacker, int32_t damage) {
|
||||
auto* const manager = VarEntity(self, u"BossManager");
|
||||
auto* const destroyable = self->GetComponent<DestroyableComponent>();
|
||||
if (!manager || !destroyable) return;
|
||||
if (destroyable->GetHealth() == 0) {
|
||||
AddTimerWithCancel(manager, "StartSpawnBouncerCine", 3.0f);
|
||||
GameMessages::NotifyClientObject(manager->GetObjectID(), u"GarmadonIsDead").Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
return;
|
||||
}
|
||||
const auto nextWave = manager->GetVar<int32_t>(u"WaveNum") + 1;
|
||||
if (ReachedWave(static_cast<float>(destroyable->GetHealth()), destroyable->GetMaxHealth(), nextWave)) {
|
||||
manager->SetVar<int32_t>(u"WaveNum", nextWave);
|
||||
StartNewWave(manager, self, nextWave);
|
||||
}
|
||||
}
|
||||
|
||||
void BossManagerServer::NotifyFireEvent(Entity* self, Entity* other, const std::string& args) {
|
||||
if (args != "SpawnedEnemiesDead") return;
|
||||
other->Unsubscribe(self->GetObjectID(), "FireEvent");
|
||||
if (!self->HasVar(u"SpinnersActive")) return;
|
||||
const 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;
|
||||
AddTimerWithCancel(self, "WaveOver", DelayToCounterSpawn);
|
||||
}
|
||||
|
||||
void BossManagerServer::PlayCelebration(Entity* self, const int32_t cutscene) {
|
||||
const auto players = GetPlayersInRange(self);
|
||||
if (players.empty()) return;
|
||||
self->SetVar<int32_t>(u"CurrentCelebration", cutscene);
|
||||
for (auto* const player : players) {
|
||||
if (auto* const buff = player->GetComponent<BuffComponent>()) buff->RemoveBuff(60);
|
||||
if (player->IsPlayer()) {
|
||||
GameMessages::StartCelebrationEffect celebration;
|
||||
celebration.target = player->GetObjectID();
|
||||
celebration.celebrationID = cutscene;
|
||||
celebration.SendToClient(player->GetSystemAddress());
|
||||
}
|
||||
player->Subscribe(self->GetObjectID(), this, "CelebrationCompleted");
|
||||
}
|
||||
self->SetVar<int32_t>(u"PlayersInCutscene", self->GetVar<int32_t>(u"PlayersInCutscene") + static_cast<int32_t>(players.size()));
|
||||
}
|
||||
|
||||
void BossManagerServer::PlayCinematic(Entity* self, const std::u16string& cine) {
|
||||
for (auto* const player : GetPlayersInRange(self)) {
|
||||
if (auto* const buff = player->GetComponent<BuffComponent>()) buff->RemoveBuff(60);
|
||||
FireTempleCinematics::PlayCinematic(player, cine);
|
||||
}
|
||||
}
|
||||
|
||||
// Everything in the cutscene volumes, once each
|
||||
std::vector<Entity*> BossManagerServer::GetPlayersInRange(Entity* self) {
|
||||
std::vector<Entity*> players;
|
||||
for (auto* const trigger : Game::entityManager->GetEntitiesInGroup(CutsceneVolume)) {
|
||||
for (auto* const player : FireTempleCinematics::ObjectsInVolume(trigger)) {
|
||||
if (std::find(players.begin(), players.end(), player) == players.end()) players.push_back(player);
|
||||
}
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
void BossManagerServer::StartElement(Entity* self, const int32_t elementNum) {
|
||||
const auto& elementString = ElementalOrder[elementNum - 1];
|
||||
self->SetVar<std::string>(u"CurrentElement", elementString);
|
||||
const auto portalSpawner = ElementalPortalSpawner + elementString;
|
||||
self->SetVar<std::string>(u"ElementPortalSpawner", portalSpawner);
|
||||
TeleportPortal(self, portalSpawner);
|
||||
self->SetVar<bool>(u"PortalAlreadyHitOnce", false);
|
||||
if (auto* const endposts = GetSpawner(EndpostSpawner + elementString)) endposts->Activate();
|
||||
if (auto* const activators = GetSpawner(ActivatorSpawner + elementString)) activators->Activate();
|
||||
if (elementString == "lightning") {
|
||||
if (auto* const bouncers = GetSpawner(LightningBouncerSpawner)) bouncers->Activate();
|
||||
}
|
||||
}
|
||||
|
||||
void BossManagerServer::TeleportPortal(Entity* self, const std::string& portalSpawner) {
|
||||
DestroyPortal(portalSpawner);
|
||||
auto* const spawner = GetSpawner(portalSpawner);
|
||||
if (!spawner) return;
|
||||
const auto totalNodes = static_cast<int32_t>(spawner->m_Info.nodes.size());
|
||||
if (totalNodes == 0) return;
|
||||
const auto nextNode = GetNewNode(self, totalNodes);
|
||||
// (listening before the spawn: DLU spawns at once, the Lua hears the object load later)
|
||||
ListenToSpawner(self, spawner);
|
||||
spawner->SpawnAtIndex(nextNode);
|
||||
self->SetVar<bool>(u"PortalHit", false);
|
||||
}
|
||||
|
||||
void BossManagerServer::DestroyPortal(const std::string& portalSpawner) {
|
||||
auto* const spawner = GetSpawner(portalSpawner);
|
||||
if (!spawner) return;
|
||||
spawner->Deactivate();
|
||||
spawner->DestroyAllEntities();
|
||||
}
|
||||
|
||||
void BossManagerServer::DestroyRails(const std::string& elementString) {
|
||||
for (const auto& name : { EndpostSpawner + elementString, ActivatorSpawner + elementString }) {
|
||||
if (auto* const spawner = GetSpawner(name)) {
|
||||
spawner->Deactivate();
|
||||
spawner->DestroyAllEntities();
|
||||
}
|
||||
}
|
||||
if (elementString == "lightning") {
|
||||
if (auto* const bouncers = GetSpawner(LightningBouncerSpawner)) {
|
||||
bouncers->Deactivate();
|
||||
bouncers->DestroyAllEntities();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A random node other than the portal's last (any with a single node)
|
||||
int32_t BossManagerServer::GetNewNode(Entity* self, const int32_t totalNodes) {
|
||||
const auto last = self->HasVar(u"PortalNode") ? self->GetVar<int32_t>(u"PortalNode") : -1;
|
||||
int32_t nextNode = GeneralUtils::GenerateRandomNumber<int32_t>(0, totalNodes - 1);
|
||||
while (totalNodes > 1 && nextNode == last) nextNode = GeneralUtils::GenerateRandomNumber<int32_t>(0, totalNodes - 1);
|
||||
return nextNode;
|
||||
}
|
||||
|
||||
void BossManagerServer::UpdateMission(Entity* self) {
|
||||
for (auto* const player : GetPlayersInRange(self)) {
|
||||
if (auto* const missions = player->GetComponent<MissionComponent>()) missions->CompleteMission(DestroyPortalMission);
|
||||
}
|
||||
}
|
||||
|
||||
void BossManagerServer::StartNewWave(Entity* self, Entity* garmadon, const int32_t nextWave) {
|
||||
PlayCinematic(self, SpawnWaveCine);
|
||||
const auto cineTime = CinematicTime(SpawnWaveCine);
|
||||
if (auto* const destroyable = garmadon->GetComponent<DestroyableComponent>()) destroyable->SetFaction(-1);
|
||||
Stun(garmadon, eStateChangeType::PUSH);
|
||||
const auto pos = m_GarmadonPos;
|
||||
const auto rot = m_GarmadonRot;
|
||||
garmadon->SetPosition(pos);
|
||||
garmadon->SetRotation(rot);
|
||||
GameMessages::Teleport(garmadon->GetObjectID(), pos, rot, true).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
RenderComponent::PlayAnimation(garmadon, u"summon");
|
||||
auto animTime = RenderComponent::GetAnimationTime(garmadon, u"summon");
|
||||
if (animTime == 0.0f) animTime = 1.5f;
|
||||
AddTimerWithCancel(self, "MakeLGTransparent", animTime);
|
||||
AddTimerWithCancel(self, "SpawnEnemies", cineTime / 2.0f);
|
||||
}
|
||||
|
||||
void BossManagerServer::ActivateWaveSpinners(Entity* self, const int32_t waveNum) {
|
||||
if (waveNum < 1 || waveNum > static_cast<int32_t>(Waves.size())) return;
|
||||
int32_t spinnerNum = 1;
|
||||
int32_t spawnerNum = 1;
|
||||
for (const auto& enemy : Waves[waveNum - 1]) {
|
||||
auto* const spawner = GetSpawner(BaseEnemiesSpawner + std::to_string(spinnerNum) + "_" + std::to_string(spawnerNum));
|
||||
if (!spawner) continue;
|
||||
const auto spawnNum = self->GetVar<bool>(u"LargeTeam") ? enemy.largeNum : enemy.smallNum;
|
||||
if (spawnNum <= 0) continue;
|
||||
spawner->m_Info.maxToSpawn = spawnNum;
|
||||
spawner->SetNumToMaintain(spawnNum);
|
||||
spawner->SetSpawnLot(enemy.lot);
|
||||
if (spinnerNum == 1) {
|
||||
spinnerNum = 2;
|
||||
} else {
|
||||
spinnerNum = 1;
|
||||
spawnerNum++;
|
||||
}
|
||||
}
|
||||
auto spinnersUp = self->GetVar<int32_t>(u"SpinnersActive");
|
||||
for (auto* const spinner : Game::entityManager->GetEntitiesInGroup(SpawnerSpinners)) {
|
||||
if (!spinner) continue;
|
||||
spinner->OnFireEventServerSide(self, "SpawnEnemies");
|
||||
spinner->Subscribe(self->GetObjectID(), this, "FireEvent");
|
||||
spinnersUp++;
|
||||
}
|
||||
self->SetVar<int32_t>(u"SpinnersActive", spinnersUp);
|
||||
}
|
||||
|
||||
void BossManagerServer::OnTimerDone(Entity* self, std::string timerName) {
|
||||
const auto var = GeneralUtils::SplitString(timerName, '_');
|
||||
const auto& name = var.empty() ? timerName : var[0];
|
||||
if (name == "SpawnStartingPortal") {
|
||||
if (auto* const portal = GetSpawner(CenterPortalSpawner)) portal->Activate();
|
||||
auto* const tornado = GetSpawner(LGTornadoSpawner);
|
||||
ListenToSpawner(self, tornado);
|
||||
if (tornado) tornado->Activate();
|
||||
} else if (name == "KillStartingPortal") {
|
||||
DestroyPortal(CenterPortalSpawner);
|
||||
AddTimerWithCancel(self, "StartEarth", 2.0f);
|
||||
} else if (name == "UnstunTornado") {
|
||||
if (auto* const tornado = VarEntity(self, u"LGTornado")) tornado->NotifyObject(self, "FindAPath");
|
||||
} else if (name == "StartEarth") {
|
||||
StartElement(self, 1);
|
||||
self->SetVar<int32_t>(u"ElementNumber", 1);
|
||||
} else if (name == "TeleportPortal") {
|
||||
TeleportPortal(self, self->GetVar<std::string>(u"ElementPortalSpawner"));
|
||||
} else if (name == "StartNextElementalPhase") {
|
||||
DestroyPortal(self->GetVar<std::string>(u"ElementPortalSpawner"));
|
||||
const auto elementNum = self->GetVar<int32_t>(u"ElementNumber");
|
||||
if (elementNum >= 1 && elementNum <= 4) DestroyRails(ElementalOrder[elementNum - 1]);
|
||||
if (elementNum < 4) {
|
||||
AddTimerWithCancel(self, "StartNextElement", 5.0f);
|
||||
} else {
|
||||
if (auto* const tornado = VarEntity(self, u"LGTornado")) tornado->NotifyObject(self, "StopPathing");
|
||||
AddTimerWithCancel(self, "StartNextPhase", 5.0f);
|
||||
}
|
||||
} else if (name == "StartNextElement") {
|
||||
const auto elementNum = self->GetVar<int32_t>(u"ElementNumber") + 1;
|
||||
self->SetVar<int32_t>(u"ElementNumber", elementNum);
|
||||
if (auto* const tornado = VarEntity(self, u"LGTornado")) tornado->NotifyObject(self, "NewElement", elementNum);
|
||||
StartElement(self, elementNum);
|
||||
} else if (name == "StartNextPhase") {
|
||||
PlayCelebration(self, PortalDeadCutScene);
|
||||
AddTimerWithCancel(self, "DestroyPhase1", 0.5f);
|
||||
} else if (name == "DestroyPhase1") {
|
||||
if (auto* const tornado = VarEntity(self, u"LGTornado")) tornado->Smash(self->GetObjectID());
|
||||
DestroyPortal(self->GetVar<std::string>(u"ElementPortalSpawner"));
|
||||
auto* const garmadonSpawner = GetSpawner(GarmadonSpawner);
|
||||
ListenToSpawner(self, garmadonSpawner);
|
||||
if (garmadonSpawner) garmadonSpawner->Activate();
|
||||
} else if (name == "Unstun") {
|
||||
const auto id = var.size() > 1 ? GeneralUtils::TryParse<LWOOBJID>(var[1]) : std::nullopt;
|
||||
auto* const obj = id ? Game::entityManager->GetEntity(*id) : nullptr;
|
||||
if (!obj) return;
|
||||
if (obj->GetLOT() == Garmadon) {
|
||||
if (auto* const destroyable = obj->GetComponent<DestroyableComponent>()) {
|
||||
bool first = true;
|
||||
for (const auto& faction : GeneralUtils::SplitString(self->GetVar<std::string>(u"LGFaction"), ';')) {
|
||||
const auto factionID = GeneralUtils::TryParse<int32_t>(faction);
|
||||
if (!factionID) continue;
|
||||
if (first) destroyable->SetFaction(*factionID);
|
||||
else destroyable->AddFaction(*factionID);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Stun(obj, eStateChangeType::POP);
|
||||
} else if (name == "SpawnEnemies") {
|
||||
ActivateWaveSpinners(self, self->GetVar<int32_t>(u"WaveNum"));
|
||||
} else if (name == "WaveOver") {
|
||||
PlayCinematic(self, WaveOverCine);
|
||||
const auto cineTime = CinematicTime(WaveOverCine);
|
||||
AddTimerWithCancel(self, "GarmadonBack", 0.5f);
|
||||
AddTimerWithCancel(self, "Unstun_" + std::to_string(self->GetVar<LWOOBJID>(u"Garmadon")), cineTime + 2.0f);
|
||||
} else if (name == "MakeLGTransparent") {
|
||||
GameMessages::NotifyClientObject(self->GetObjectID(), u"LGVisible", 0, 0, self->GetVar<LWOOBJID>(u"Garmadon")).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
} else if (name == "GarmadonBack") {
|
||||
GameMessages::NotifyClientObject(self->GetObjectID(), u"LGVisible", 1, 0, self->GetVar<LWOOBJID>(u"Garmadon")).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
} else if (name == "StartSpawnBouncerCine") {
|
||||
PlayCinematic(self, SpawnBouncerCine);
|
||||
AddTimerWithCancel(self, "SpawnBouncer", 0.5f);
|
||||
} else if (name == "SpawnBouncer") {
|
||||
if (auto* const bouncer = GetSpawner(BouncerSpawner)) bouncer->Activate();
|
||||
}
|
||||
}
|
||||
48
dScripts/02_server/Map/General/BossManagerServer.h
Normal file
48
dScripts/02_server/Map/General/BossManagerServer.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
#include "NiPoint3.h"
|
||||
#include "NiQuaternion.h"
|
||||
|
||||
class Spawner;
|
||||
|
||||
// L_BOSS_MANAGER_SERVER.lua: the Fire Temple boss fight. The first touch plays the intro celebration (26) to the
|
||||
// players in BossCutsceneVolume, then the start camera, while the centre portal and the tornado spawn; the tornado then
|
||||
// paths. Four elemental phases (earth, ice, lightning, fire) each spawn a portal at a random node of its spawner, which
|
||||
// moves every so often, plus the element's rail endposts and activators: a player riding the rail used at the portal's
|
||||
// node to the element's rail node hits the portal (twice moves on to the next element). After fire the middle
|
||||
// celebration (27) plays, Garmadon spawns stunned, and each fifth of his health lost starts a wave of enemies from the
|
||||
// BossSpawnerSpinners; once he dies the end bouncer spawns.
|
||||
// Not as the Lua: the client's CelebrationCompleted carries no celebration id (the Lua's msg.celebrationID is always
|
||||
// nil there), so the manager branches on the celebration it started. The portal's onhit animation is played on the
|
||||
// portal's spawner in the Lua, which has none to play: the wait for it is the Lua's 1.5 s default.
|
||||
class BossManagerServer : public CppScripts::Script {
|
||||
public:
|
||||
void OnCollisionPhantom(Entity* self, Entity* target) override;
|
||||
void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override;
|
||||
void NotifyCelebrationCompleted(Entity* self, Entity* player) override;
|
||||
void NotifyPlayerRailArrived(Entity* self, Entity* activator, const std::u16string& pathName, int32_t waypointNumber) override;
|
||||
void NotifyHitOrHealResult(Entity* self, Entity* attacker, int32_t damage) override;
|
||||
void NotifyFireEvent(Entity* self, Entity* other, const std::string& args) override;
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
|
||||
// The wave Garmadon's health has dropped into: a fifth of his health lost per wave
|
||||
static bool ReachedWave(float health, float maxHealth, int32_t nextWave);
|
||||
private:
|
||||
void SpawnedObjectLoaded(Entity* self, Entity* object, int32_t spawnNode);
|
||||
void ListenToSpawner(Entity* self, Spawner* spawner);
|
||||
void PlayCelebration(Entity* self, int32_t cutscene);
|
||||
static void PlayCinematic(Entity* self, const std::u16string& cine);
|
||||
static std::vector<Entity*> GetPlayersInRange(Entity* self);
|
||||
void StartElement(Entity* self, int32_t elementNum);
|
||||
void TeleportPortal(Entity* self, const std::string& portalSpawner);
|
||||
static void DestroyPortal(const std::string& portalSpawner);
|
||||
static void DestroyRails(const std::string& elementString);
|
||||
static int32_t GetNewNode(Entity* self, int32_t totalNodes);
|
||||
static void UpdateMission(Entity* self);
|
||||
void StartNewWave(Entity* self, Entity* garmadon, int32_t nextWave);
|
||||
void ActivateWaveSpinners(Entity* self, int32_t waveNum);
|
||||
|
||||
// Where Garmadon spawned (one boss fight per instance)
|
||||
NiPoint3 m_GarmadonPos{};
|
||||
NiQuaternion m_GarmadonRot{};
|
||||
};
|
||||
@@ -3,6 +3,7 @@ set(DSCRIPTS_SOURCES_02_SERVER_MAP_GENERAL
|
||||
"BaseInteractDropLootServer.cpp"
|
||||
"Binoculars.cpp"
|
||||
"BossGarmadonTornado.cpp"
|
||||
"BossManagerServer.cpp"
|
||||
"DoorIndicatorServer.cpp"
|
||||
"ElementalChestsServer.cpp"
|
||||
"EnemyClearThreat.cpp"
|
||||
|
||||
@@ -284,6 +284,7 @@
|
||||
#include "EventCounterUtil.h"
|
||||
#include "BossGarmadonTornado.h"
|
||||
#include "WavesManagerServer.h"
|
||||
#include "BossManagerServer.h"
|
||||
#include "SimpleOnceOnlyMoverSpinnerEvent.h"
|
||||
#include "ImaginationShrineServer.h"
|
||||
#include "Lieutenant.h"
|
||||
@@ -705,6 +706,7 @@ namespace {
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_ELEMENTAL_CHESTS_SERVER.lua", []() {return new ElementalChestsServer();}},
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_ZONE_FIRE_TEMPLE_SERVER.lua", []() {return new ZoneFireTempleServer();}},
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_WAVES_MANAGER_SERVER.lua", []() {return new WavesManagerServer();}},
|
||||
{"scripts\\02_server\\Map\\firetemple\\L_BOSS_MANAGER_SERVER.lua", []() {return new BossManagerServer();}},
|
||||
// (the CDServer row writes this path with forward slashes)
|
||||
{"scripts/02_server/Map/firetemple/L_BOSS_GARMADON_TORNADO.lua", []() {return new BossGarmadonTornado();}},
|
||||
{"scripts\\02_server\\Map\\General\\L_KILL_COUNTER_UTIL.lua", []() {return new KillCounterUtil();}},
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "02_server/Map/General/EventCounterUtil.h"
|
||||
#include "02_server/Map/General/BossGarmadonTornado.h"
|
||||
#include "02_server/Map/General/WavesManagerServer.h"
|
||||
#include "02_server/Map/General/BossManagerServer.h"
|
||||
#include "EntityManager.h"
|
||||
#include "BitStream.h"
|
||||
|
||||
@@ -260,3 +261,31 @@ TEST_F(FireTempleScriptsTest, RailArrivalReachesTheActivatorsSubscribers) {
|
||||
activator->NotifyPlayerRailArrived(u"BossRail", 6);
|
||||
EXPECT_EQ(listener.waypoints.size(), 1u);
|
||||
}
|
||||
|
||||
// L_BOSS_MANAGER_SERVER: a wave starts each time Garmadon loses another fifth of his health
|
||||
TEST_F(FireTempleScriptsTest, BossWavesAtEachFifthOfGarmadonsHealth) {
|
||||
EXPECT_FALSE(BossManagerServer::ReachedWave(81.0f, 100.0f, 1));
|
||||
EXPECT_TRUE(BossManagerServer::ReachedWave(80.0f, 100.0f, 1));
|
||||
EXPECT_FALSE(BossManagerServer::ReachedWave(61.0f, 100.0f, 2));
|
||||
EXPECT_TRUE(BossManagerServer::ReachedWave(20.0f, 100.0f, 4));
|
||||
}
|
||||
|
||||
// The intro celebration's end (the last player's) starts the start camera timers; the manager knows it was the intro
|
||||
TEST_F(FireTempleScriptsTest, BossManagerBranchesOnTheCelebrationItStarted) {
|
||||
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, 288300744895900240);
|
||||
auto* const player = Game::entityManager->CreateEntity(info, nullptr, nullptr, false, 288300744895900241);
|
||||
BossManagerServer boss;
|
||||
manager->SetVar<int32_t>(u"CurrentCelebration", 26);
|
||||
manager->SetVar<int32_t>(u"PlayersInCutscene", 1);
|
||||
player->Subscribe(manager->GetObjectID(), &boss, "CelebrationCompleted");
|
||||
player->NotifyCelebrationCompleted();
|
||||
manager->Update(0.0f);
|
||||
EXPECT_TRUE(manager->HasTimer("KillStartingPortal"));
|
||||
EXPECT_TRUE(manager->HasTimer("UnstunTornado"));
|
||||
// No longer subscribed
|
||||
player->NotifyCelebrationCompleted();
|
||||
EXPECT_EQ(manager->GetVar<int32_t>(u"PlayersInCutscene"), 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user