From 094797881bd761dafbac6568c8e8b8832fb4eb9d Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 9 Oct 2023 13:29:11 -0700 Subject: [PATCH] Cannon Cove: Fix incorrect sign (#1211) Update CMakeVariables.txt Cannon Cove: Fix incorrect sign --- .../ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp | 320 ++++++++++-------- dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h | 6 + 2 files changed, 182 insertions(+), 144 deletions(-) diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 66171b95..97798dc8 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -160,166 +160,198 @@ void SGCannon::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button } } -void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) { - if (name == SuperChargeTimer && !self->GetVar(SuperChargePausedVariable)) { - if (self->GetVar(WaveStatusVariable) || self->GetVar(CurrentSuperChargedTimeVariable) < 1) { - self->SetNetworkVar(ChargeCountingVariable, 99); - self->SetNetworkVar(SuperChargeBarVariable, 0); - ToggleSuperCharge(self, false); +void SGCannon::SuperChargeTimerFunc(Entity* self) { + if (self->GetVar(WaveStatusVariable) || self->GetVar(CurrentSuperChargedTimeVariable) < 1) { + self->SetNetworkVar(ChargeCountingVariable, 99); + self->SetNetworkVar(SuperChargeBarVariable, 0); + ToggleSuperCharge(self, false); + } +} + +void SGCannon::SpawnWaveTimerFunc(Entity* self) { + if (self->GetVar(GameStartedVariable)) { + self->SetVar(WaveStatusVariable, true); + const auto wave = (int32_t)self->GetVar(ThisWaveVariable); + + if (wave != 0 && self->GetVar(SuperChargePausedVariable)) { + StartChargedCannon(self, self->GetVar(CurrentSuperChargedTimeVariable)); + self->SetVar(CurrentSuperChargedTimeVariable, 0); } - } else if (name == SpawnWaveTimer) { - if (self->GetVar(GameStartedVariable)) { - self->SetVar(WaveStatusVariable, true); - const auto wave = (int32_t)self->GetVar(ThisWaveVariable); - if (wave != 0 && self->GetVar(SuperChargePausedVariable)) { - StartChargedCannon(self, self->GetVar(CurrentSuperChargedTimeVariable)); - self->SetVar(CurrentSuperChargedTimeVariable, 0); - } + TimerToggle(self, true); - TimerToggle(self, true); - - for (const auto& enemyToSpawn : m_Waves.at(self->GetVar(ThisWaveVariable))) { - SpawnObject(self, enemyToSpawn, true); - } - - Game::logger->Log("SGCannon", "Current wave spawn: %i/%i", wave, m_Waves.size()); - - // All waves completed - const auto timeLimit = (float_t)self->GetVar(TimeLimitVariable); - if (wave >= m_Waves.size()) { - ActivityTimerStart(self, GameOverTimer, timeLimit, timeLimit); - } else { - ActivityTimerStart(self, EndWaveTimer, timeLimit, timeLimit); - } - - const auto* player = Game::entityManager->GetEntity(self->GetVar(PlayerIDVariable)); - if (player != nullptr) { - GameMessages::SendPlayFXEffect(player->GetObjectID(), -1, u"SG-start", ""); - - GameMessages::SendStartActivityTime(self->GetObjectID(), timeLimit, player->GetSystemAddress()); - Game::logger->Log("SGCannon", "Sending ActivityPause false"); - - GameMessages::SendActivityPause(self->GetObjectID(), false, player->GetSystemAddress()); - } + for (const auto& enemyToSpawn : m_Waves.at(self->GetVar(ThisWaveVariable))) { + SpawnObject(self, enemyToSpawn, true); } - } else if (name == EndWaveTimer) { - self->SetVar(WaveStatusVariable, false); + + Game::logger->Log("SGCannon", "Current wave spawn: %i/%i", wave, m_Waves.size()); + + // All waves completed + const auto timeLimit = (float_t)self->GetVar(TimeLimitVariable); + if (wave >= m_Waves.size()) { + ActivityTimerStart(self, GameOverTimer, timeLimit, timeLimit); + } else { + ActivityTimerStart(self, EndWaveTimer, timeLimit, timeLimit); + } + + const auto* player = Game::entityManager->GetEntity(self->GetVar(PlayerIDVariable)); + if (player != nullptr) { + GameMessages::SendPlayFXEffect(player->GetObjectID(), -1, u"SG-start", ""); + + GameMessages::SendStartActivityTime(self->GetObjectID(), timeLimit, player->GetSystemAddress()); + Game::logger->Log("SGCannon", "Sending ActivityPause false"); + + GameMessages::SendActivityPause(self->GetObjectID(), false, player->GetSystemAddress()); + } + } +} + +void SGCannon::EndWaveTimerFunc(Entity* self) { + self->SetVar(WaveStatusVariable, false); + TimerToggle(self); + RecordPlayerScore(self); + + if (self->GetVar(ThisWaveVariable) >= 2) { + GameMessages::SendActivityPause(self->GetObjectID(), true); + ActivityTimerStart(self, GameOverTimer, 0.1, 0.1); + return; + } + + self->SetVar(ThisWaveVariable, self->GetVar(ThisWaveVariable) + 1); + PlaySceneAnimation(self, u"wave" + GeneralUtils::to_u16string(self->GetVar(ThisWaveVariable)), true, true, 1.7f); + self->SetNetworkVar(WaveNumVariable, self->GetVar(ThisWaveVariable) + 1); + self->SetNetworkVar(WaveStrVariable, self->GetVar(TimeLimitVariable)); + + Game::logger->Log("SGCannon", "Current wave: %i/%i", self->GetVar(ThisWaveVariable), m_Waves.size()); + + if (self->GetVar(ThisWaveVariable) >= m_Waves.size()) { + ActivityTimerStart(self, GameOverTimer, 0.1, 0.1); + } else { + ActivityTimerStart(self, SpawnWaveTimer, constants.inBetweenWavePause, constants.inBetweenWavePause); + } + + Game::logger->Log("SGCannon", "Sending ActivityPause true"); + + GameMessages::SendActivityPause(self->GetObjectID(), true); + if (self->GetVar(SuperChargeActiveVariable) && !self->GetVar(SuperChargePausedVariable)) { + PauseChargeCannon(self); + } +} + +void SGCannon::GameOverTimerFunc(Entity* self) { + auto* player = Game::entityManager->GetEntity(self->GetVar(PlayerIDVariable)); + if (player != nullptr) { + Game::logger->Log("SGCannon", "Sending ActivityPause true"); + + GameMessages::SendActivityPause(self->GetObjectID(), true, player->GetSystemAddress()); + + /*const auto leftoverCannonballs = Game::entityManager->GetEntitiesInGroup("cannonball"); + if (leftoverCannonballs.empty()) { + RecordPlayerScore(self); + + } else { + ActivityTimerStart(self, EndGameBufferTimer, 1, leftoverCannonballs.size()); + }*/ + + ActivityTimerStart(self, EndGameBufferTimer, 1, 1); + TimerToggle(self); - RecordPlayerScore(self); + } +} - if (self->GetVar(ThisWaveVariable) >= 2) { - GameMessages::SendActivityPause(self->GetObjectID(), true); - ActivityTimerStart(self, GameOverTimer, 0.1, 0.1); +void SGCannon::DoSpawnTimerFunc(Entity* self, const std::string& name) { + if (self->GetVar(GameStartedVariable)) { + Game::logger->LogDebug("SGCannon", "time name %s %s", name.c_str(), name.substr(7).c_str()); + const auto spawnNumber = (uint32_t)std::stoi(name.substr(7)); + const auto& activeSpawns = self->GetVar>(ActiveSpawnsVariable); + Game::logger->LogDebug("SGCannon", "size %i, %i", activeSpawns.size(), spawnNumber); + if (activeSpawns.size() <= spawnNumber) { + Game::logger->Log("SGCannon", "Trying to spawn %i when spawns size is only %i", spawnNumber, activeSpawns.size()); return; } - self->SetVar(ThisWaveVariable, self->GetVar(ThisWaveVariable) + 1); - PlaySceneAnimation(self, u"wave" + GeneralUtils::to_u16string(self->GetVar(ThisWaveVariable)), true, true, 1.7f); - self->SetNetworkVar(WaveNumVariable, self->GetVar(ThisWaveVariable) + 1); - self->SetNetworkVar(WaveStrVariable, self->GetVar(TimeLimitVariable)); - - Game::logger->Log("SGCannon", "Current wave: %i/%i", self->GetVar(ThisWaveVariable), m_Waves.size()); - - if (self->GetVar(ThisWaveVariable) >= m_Waves.size()) { - ActivityTimerStart(self, GameOverTimer, 0.1, 0.1); - } else { - ActivityTimerStart(self, SpawnWaveTimer, constants.inBetweenWavePause, constants.inBetweenWavePause); + const auto& toSpawn = activeSpawns.at(spawnNumber); + Game::logger->LogDebug("SGCannon", "toSpawn %i", toSpawn.spawnPaths.size()); + const auto pathIndex = GeneralUtils::GenerateRandomNumber(0, toSpawn.spawnPaths.size() - 1); + Game::logger->LogDebug("SGCannon", "index %f", pathIndex); + Game::logger->LogDebug("SGCannon", "%s", toSpawn.spawnPaths.at(pathIndex).c_str()); + const auto* path = Game::zoneManager->GetZone()->GetPath(toSpawn.spawnPaths.at(pathIndex)); + if (!path) { + Game::logger->Log("SGCannon", "Path %s at index %i is null", toSpawn.spawnPaths.at(pathIndex).c_str(), pathIndex); + return; } - Game::logger->Log("SGCannon", "Sending ActivityPause true"); + Game::logger->LogDebug("SGCannon", "%s", path->pathName.c_str()); - GameMessages::SendActivityPause(self->GetObjectID(), true); - if (self->GetVar(SuperChargeActiveVariable) && !self->GetVar(SuperChargePausedVariable)) { - PauseChargeCannon(self); + auto info = EntityInfo{}; + info.lot = toSpawn.lot; + info.spawnerID = self->GetObjectID(); + info.pos = path->pathWaypoints.at(0).position; + + info.settings = { + new LDFData(u"SpawnData", toSpawn), + new LDFData(u"custom_script_server", "scripts/ai/ACT/SG_TARGET.lua"), + new LDFData(u"custom_script_client", "scripts/client/ai/SG_TARGET_CLIENT.lua"), + new LDFData(u"attached_path", path->pathName), + new LDFData(u"attached_path_start", 0), + new LDFData(u"groupID", u"SGEnemy") + }; + + Game::logger->Log("SGCannon", "Spawning enemy %i on path %s", toSpawn.lot, path->pathName.c_str()); + + auto* enemy = Game::entityManager->CreateEntity(info, nullptr, self); + Game::entityManager->ConstructEntity(enemy); + + auto* movementAI = new MovementAIComponent(enemy, {}); + + enemy->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAI); + + movementAI->SetMaxSpeed(toSpawn.initialSpeed); + movementAI->SetCurrentSpeed(toSpawn.initialSpeed); + movementAI->SetHaltDistance(0.0f); + + std::vector pathWaypoints; + + for (const auto& waypoint : path->pathWaypoints) { + pathWaypoints.push_back(waypoint.position); } + + if (GeneralUtils::GenerateRandomNumber(0, 1) < 0.5f) { + std::reverse(pathWaypoints.begin(), pathWaypoints.end()); + } + + movementAI->SetPath(pathWaypoints); + + enemy->AddDieCallback([this, self, enemy, name]() { + RegisterHit(self, enemy, name); + }); + + // Save the enemy and tell it to start pathing + if (enemy != nullptr) { + const_cast&>(self->GetVar>(SpawnedObjects)).push_back(enemy->GetObjectID()); + GameMessages::SendPlatformResync(enemy, UNASSIGNED_SYSTEM_ADDRESS); + } + } +} + +void SGCannon::EndGameBufferTimerFunc(Entity* self) { + RecordPlayerScore(self); + StopGame(self, false); +} + +void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) { + if (name == SuperChargeTimer && !self->GetVar(SuperChargePausedVariable)) { + SuperChargeTimerFunc(self); + } else if (name == SpawnWaveTimer) { + SpawnWaveTimerFunc(self); + } else if (name == EndWaveTimer) { + EndWaveTimerFunc(self); } else if (name == GameOverTimer) { - auto* player = Game::entityManager->GetEntity(self->GetVar(PlayerIDVariable)); - if (player != nullptr) { - Game::logger->Log("SGCannon", "Sending ActivityPause true"); - - GameMessages::SendActivityPause(self->GetObjectID(), true, player->GetSystemAddress()); - - /*const auto leftoverCannonballs = Game::entityManager->GetEntitiesInGroup("cannonball"); - if (leftoverCannonballs.empty()) { - RecordPlayerScore(self); - - } else { - ActivityTimerStart(self, EndGameBufferTimer, 1, leftoverCannonballs.size()); - }*/ - - ActivityTimerStart(self, EndGameBufferTimer, 1, 1); - - TimerToggle(self); - } + GameOverTimerFunc(self); } else if (name.rfind(DoSpawnTimer, 0) == 0) { - if (self->GetVar(GameStartedVariable)) { - const auto spawnNumber = (uint32_t)std::stoi(name.substr(7)); - const auto& activeSpawns = self->GetVar>(ActiveSpawnsVariable); - if (activeSpawns.size() < spawnNumber) { - Game::logger->Log("SGCannon", "Trying to spawn %i when spawns size is only %i", spawnNumber, activeSpawns.size()); - return; - } - const auto& toSpawn = activeSpawns.at(spawnNumber); - const auto pathIndex = GeneralUtils::GenerateRandomNumber(0, toSpawn.spawnPaths.size() - 1); - const auto* path = Game::zoneManager->GetZone()->GetPath(toSpawn.spawnPaths.at(pathIndex)); - if (!path) { - Game::logger->Log("SGCannon", "Path %s at index %i is null", toSpawn.spawnPaths.at(pathIndex).c_str(), pathIndex); - return; - } - - auto info = EntityInfo{}; - info.lot = toSpawn.lot; - info.spawnerID = self->GetObjectID(); - info.pos = path->pathWaypoints.at(0).position; - - info.settings = { - new LDFData(u"SpawnData", toSpawn), - new LDFData(u"custom_script_server", "scripts/ai/ACT/SG_TARGET.lua"), - new LDFData(u"custom_script_client", "scripts/client/ai/SG_TARGET_CLIENT.lua"), - new LDFData(u"attached_path", path->pathName), - new LDFData(u"attached_path_start", 0), - new LDFData(u"groupID", u"SGEnemy") - }; - - Game::logger->Log("SGCannon", "Spawning enemy %i on path %s", toSpawn.lot, path->pathName.c_str()); - - auto* enemy = Game::entityManager->CreateEntity(info, nullptr, self); - Game::entityManager->ConstructEntity(enemy); - - auto* movementAI = new MovementAIComponent(enemy, {}); - - enemy->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAI); - - movementAI->SetMaxSpeed(toSpawn.initialSpeed); - movementAI->SetCurrentSpeed(toSpawn.initialSpeed); - movementAI->SetHaltDistance(0.0f); - - std::vector pathWaypoints; - - for (const auto& waypoint : path->pathWaypoints) { - pathWaypoints.push_back(waypoint.position); - } - - if (GeneralUtils::GenerateRandomNumber(0, 1) < 0.5f) { - std::reverse(pathWaypoints.begin(), pathWaypoints.end()); - } - - movementAI->SetPath(pathWaypoints); - - enemy->AddDieCallback([this, self, enemy, name]() { - RegisterHit(self, enemy, name); - }); - - // Save the enemy and tell it to start pathing - if (enemy != nullptr) { - const_cast&>(self->GetVar>(SpawnedObjects)).push_back(enemy->GetObjectID()); - GameMessages::SendPlatformResync(enemy, UNASSIGNED_SYSTEM_ADDRESS); - } - } + DoSpawnTimerFunc(self, name); } else if (name == EndGameBufferTimer) { - RecordPlayerScore(self); - StopGame(self, false); + EndGameBufferTimerFunc(self); } } diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h index b20fae6d..712983c9 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h @@ -68,6 +68,12 @@ public: void OnActivityTimerDone(Entity* self, const std::string& name) override; void OnActivityTimerUpdate(Entity* self, const std::string& name, float_t timeRemaining, float_t elapsedTime) override; void OnRequestActivityExit(Entity* self, LWOOBJID player, bool canceled) override; + void SuperChargeTimerFunc(Entity* self); + void SpawnWaveTimerFunc(Entity* self); + void EndWaveTimerFunc(Entity* self); + void GameOverTimerFunc(Entity* self); + void DoSpawnTimerFunc(Entity* self, const std::string& name); + void EndGameBufferTimerFunc(Entity* self); private: static std::vector> GetWaves(); static SGConstants GetConstants();