From 968114199b0585c51d3c75ca86b5fe112773ae87 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 19 Jun 2022 00:44:49 -0700 Subject: [PATCH] The shooting Gallery now properly ends when a player leaves the instance The shooting Gallery now properly ends when a player leaves the instance Frakjaw player update Update the Frakjaw battle instance script to remove players when they leave the instance Simplify comparison Simplify comparison for entity pointer to be implicit --- dGame/EntityManager.cpp | 2 +- dScripts/NjMonastryBossInstance.cpp | 24 +++++++++++++++++++++--- dScripts/SGCannon.cpp | 5 +++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/dGame/EntityManager.cpp b/dGame/EntityManager.cpp index 96a2328..db60a1d 100644 --- a/dGame/EntityManager.cpp +++ b/dGame/EntityManager.cpp @@ -226,7 +226,7 @@ void EntityManager::UpdateEntities(const float deltaTime) { const auto& ghostingToDelete = std::find(m_EntitiesToGhost.begin(), m_EntitiesToGhost.end(), entityToDelete); - if (entityToDelete != nullptr) + if (entityToDelete) { // If we are a player run through the player destructor. if (entityToDelete->IsPlayer()) diff --git a/dScripts/NjMonastryBossInstance.cpp b/dScripts/NjMonastryBossInstance.cpp index c6c8e32..27de743 100644 --- a/dScripts/NjMonastryBossInstance.cpp +++ b/dScripts/NjMonastryBossInstance.cpp @@ -91,9 +91,27 @@ void NjMonastryBossInstance::OnPlayerLoaded(Entity *self, Entity *player) { void NjMonastryBossInstance::OnPlayerExit(Entity *self, Entity *player) { UpdatePlayer(self, player->GetObjectID(), true); - //TODO: Add functionality to dynamically turn off the large team variable when enough players leave. - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"PlayerLeft", 0, 0, - player->GetObjectID(), "", UNASSIGNED_SYSTEM_ADDRESS); + // Fetch the total players loaded from the vars + auto totalPlayersLoaded = self->GetVar >(TotalPlayersLoadedVariable); + + // Find the player to remove + auto playerToRemove = std::find(totalPlayersLoaded.begin(), totalPlayersLoaded.end(), player->GetObjectID()); + + // If we found the player remove them from out list of players + if (playerToRemove != totalPlayersLoaded.end()) { + totalPlayersLoaded.erase(playerToRemove); + } else { + Game::logger->Log("NjMonastryBossInstance", "Failed to remove player at exit.\n"); + } + + // Set the players loaded var back + self->SetVar>(TotalPlayersLoadedVariable, totalPlayersLoaded); + + // Since this is an exit method, check if enough players have left. If enough have left + // resize the instance to account for such. + if (totalPlayersLoaded.size() <= 2) self->SetVar(LargeTeamVariable, false); + + GameMessages::SendNotifyClientObject(self->GetObjectID(), u"PlayerLeft", 0, 0, player->GetObjectID(), "", UNASSIGNED_SYSTEM_ADDRESS); } void NjMonastryBossInstance::OnActivityTimerDone(Entity *self, const std::string &name) { diff --git a/dScripts/SGCannon.cpp b/dScripts/SGCannon.cpp index a5c2c84..3912364 100644 --- a/dScripts/SGCannon.cpp +++ b/dScripts/SGCannon.cpp @@ -144,8 +144,9 @@ void SGCannon::OnMessageBoxResponse(Entity *self, Entity *sender, int32_t button if (player != nullptr) { if (button == 1 && identifier == u"Shooting_Gallery_Stop") { - static_cast(player)->SendToZone(1300); - + UpdatePlayer(self, player->GetObjectID(), true); + RemovePlayer(player->GetObjectID()); + StopGame(self, true); return; }