diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index fdd7ce6f..4345d2db 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1473,6 +1473,12 @@ void Entity::OnChoiceBoxResponse(Entity* sender, int32_t button, const std::u16s } } +void Entity::RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled) { + for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { + script->OnRequestActivityExit(sender, player, canceled); + } +} + void Entity::Smash(const LWOOBJID source, const eKillType killType, const std::u16string& deathType) { if (!m_PlayerIsReadyForUpdates) return; diff --git a/dGame/Entity.h b/dGame/Entity.h index b980b179..90f2a34f 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -207,6 +207,7 @@ public: void OnMessageBoxResponse(Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData); void OnChoiceBoxResponse(Entity* sender, int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier); + void RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled); void Smash(const LWOOBJID source = LWOOBJID_EMPTY, const eKillType killType = eKillType::VIOLENT, const std::u16string& deathType = u""); void Kill(Entity* murderer = nullptr); diff --git a/dGame/dGameMessages/GameMessageHandler.cpp b/dGame/dGameMessages/GameMessageHandler.cpp index 50c7876b..be751598 100644 --- a/dGame/dGameMessages/GameMessageHandler.cpp +++ b/dGame/dGameMessages/GameMessageHandler.cpp @@ -677,6 +677,9 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System case eGameMessageType::ZONE_SUMMARY_DISMISSED: GameMessages::HandleZoneSummaryDismissed(inStream, entity); break; + case eGameMessageType::REQUEST_ACTIVITY_EXIT: + GameMessages::HandleRequestActivityExit(inStream, entity); + break; default: // Game::logger->Log("GameMessageHandler", "Unknown game message ID: %i", messageID); break; diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 99b1c67f..165876ff 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -91,6 +91,7 @@ #include "eReplicaComponentType.h" #include "eClientMessageType.h" #include "eGameMessageType.h" +#include "ActivityManager.h" #include "CDComponentsRegistryTable.h" #include "CDObjectsTable.h" @@ -6204,3 +6205,15 @@ void GameMessages::SendShowBillboardInteractIcon(const SystemAddress& sysAddr, L if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) SEND_PACKET_BROADCAST else SEND_PACKET } + +void GameMessages::HandleRequestActivityExit(RakNet::BitStream* inStream, Entity* entity) { + bool canceled = false; + inStream->Read(canceled); + if (!canceled) return; + + LWOOBJID player_id = LWOOBJID_EMPTY; + inStream->Read(player_id); + auto player = EntityManager::Instance()->GetEntity(player_id); + if (!entity || !player) return; + entity->RequestActivityExit(entity, player_id, canceled); +} diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index ce24a105..94b24b65 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -648,6 +648,7 @@ namespace GameMessages { void SendDeactivateBubbleBuffFromServer(LWOOBJID objectId, const SystemAddress& sysAddr); void HandleZoneSummaryDismissed(RakNet::BitStream* inStream, Entity* entity); + void HandleRequestActivityExit(RakNet::BitStream* inStream, Entity* entity); }; #endif // GAMEMESSAGES_H diff --git a/dScripts/CppScripts.h b/dScripts/CppScripts.h index 4bf3720f..1b9d0591 100644 --- a/dScripts/CppScripts.h +++ b/dScripts/CppScripts.h @@ -349,6 +349,15 @@ namespace CppScripts { * @param itemObjId The items Object ID */ virtual void OnFactionTriggerItemUnequipped(Entity* itemOwner, LWOOBJID itemObjId) {}; + + /** + * Handles exiting a scripted activity + * + * @param sender + * @param player the player to remove + * @param canceled if it was done via the cancel button + */ + virtual void OnRequestActivityExit(Entity* sender, LWOOBJID player, bool canceled){}; }; Script* GetScript(Entity* parent, const std::string& scriptName); diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 50cd229a..c3274da1 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -135,38 +135,26 @@ void SGCannon::OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int } } -void SGCannon::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, - const std::u16string& userData) { +void SGCannon::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) { auto* player = EntityManager::Instance()->GetEntity(self->GetVar(PlayerIDVariable)); - if (player != nullptr) { - if (button == 1 && identifier == u"Shooting_Gallery_Stop") { + if (!player) return; + + if (identifier == u"Scoreboardinfo") { + GameMessages::SendDisplayMessageBox(player->GetObjectID(), true, + dZoneManager::Instance()->GetZoneControlObject()->GetObjectID(), + u"Shooting_Gallery_Retry", 2, u"Retry?", + u"", player->GetSystemAddress()); + } else { + if ((button == 1 && (identifier == u"Shooting_Gallery_Retry" || identifier == u"RePlay")) || identifier == u"SG1" || button == 0) { + if (IsPlayerInActivity(self, player->GetObjectID())) return; + self->SetNetworkVar(ClearVariable, true); + StartGame(self); + } else if (button == 0 && ((identifier == u"Shooting_Gallery_Retry" || identifier == u"RePlay"))){ + RemovePlayer(player->GetObjectID()); + UpdatePlayer(self, player->GetObjectID(), true); + } else if (button == 1 && identifier == u"Shooting_Gallery_Exit") { UpdatePlayer(self, player->GetObjectID(), true); RemovePlayer(player->GetObjectID()); - StopGame(self, true); - return; - } - - if (identifier == u"Scoreboardinfo") { - GameMessages::SendDisplayMessageBox(player->GetObjectID(), true, - dZoneManager::Instance()->GetZoneControlObject()->GetObjectID(), - u"Shooting_Gallery_Retry?", 2, u"Retry?", - u"", player->GetSystemAddress()); - } else { - if ((button == 1 && (identifier == u"Shooting_Gallery_Retry" || identifier == u"RePlay")) - || identifier == u"SG1" || button == 0) { - - if (identifier == u"RePlay") { - static_cast(player)->SendToZone(1300); - - return; - } - - self->SetNetworkVar(ClearVariable, true); - StartGame(self); - } else if (button == 1 && identifier == u"Shooting_Gallery_Exit") { - UpdatePlayer(self, player->GetObjectID(), true); - RemovePlayer(player->GetObjectID()); - } } } } @@ -267,14 +255,13 @@ void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) { 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 = dZoneManager::Instance()->GetZone()->GetPath( - toSpawn.spawnPaths.at(pathIndex) - ); - + const auto* path = dZoneManager::Instance()->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; @@ -341,6 +328,7 @@ SGCannon::OnActivityTimerUpdate(Entity* self, const std::string& name, float_t t } void SGCannon::StartGame(Entity* self) { + if (self->GetVar(GameStartedVariable)) return; self->SetNetworkVar(TimeLimitVariable, self->GetVar(TimeLimitVariable)); self->SetNetworkVar(AudioStartIntroVariable, true); self->SetVar(CurrentRewardVariable, LOT_NULL); @@ -447,6 +435,14 @@ void SGCannon::RemovePlayer(LWOOBJID playerID) { } } +void SGCannon::OnRequestActivityExit(Entity* self, LWOOBJID player, bool canceled){ + if (canceled){ + StopGame(self, canceled); + RemovePlayer(player); + } +} + + void SGCannon::StartChargedCannon(Entity* self, uint32_t optionalTime) { optionalTime = optionalTime == 0 ? constants.chargedTime : optionalTime; self->SetVar(SuperChargePausedVariable, false); diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h index df9831ad..b20fae6d 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h @@ -63,12 +63,11 @@ public: void OnStartup(Entity* self) override; void OnPlayerLoaded(Entity* self, Entity* player) override; void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override; - void OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int32_t value1, - int32_t value2, const std::u16string& stringValue) override; - void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, - const std::u16string& userData) override; + void OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int32_t value1, int32_t value2, const std::u16string& stringValue) override; + void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) override; 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; private: static std::vector> GetWaves(); static SGConstants GetConstants();