diff --git a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheChampion/instance_trial_of_the_champion.cpp b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheChampion/instance_trial_of_the_champion.cpp index 9b6e057f0..792e1a15c 100644 --- a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheChampion/instance_trial_of_the_champion.cpp +++ b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheChampion/instance_trial_of_the_champion.cpp @@ -256,26 +256,36 @@ public: // EVENT STUFF BELOW: - void OnPlayerEnter(Player*) override + void OnPlayerEnter(Player* plr) override { - if( DoNeedCleanup(true) ) + if (DoNeedCleanup(plr)) + { InstanceCleanup(); + } events.RescheduleEvent(EVENT_CHECK_PLAYERS, CLEANUP_CHECK_INTERVAL); } - bool DoNeedCleanup(bool /*enter*/) + bool DoNeedCleanup(Player* ignoredPlayer = nullptr) { uint8 aliveCount = 0; - Map::PlayerList const& pl = instance->GetPlayers(); - for( Map::PlayerList::const_iterator itr = pl.begin(); itr != pl.end(); ++itr ) - if( Player* plr = itr->GetSource() ) - if( plr->IsAlive() && !plr->IsGameMaster() ) + for (const auto &itr: instance->GetPlayers()) + { + if (Player* plr = itr.GetSource()) + { + if (plr != ignoredPlayer && plr->IsAlive() && !plr->IsGameMaster()) + { ++aliveCount; + } + } + } bool need = aliveCount == 0; - if( !need && CLEANED ) + if (!need && CLEANED) + { CLEANED = false; + } + return need; } @@ -769,8 +779,10 @@ public: break; case EVENT_CHECK_PLAYERS: { - if( DoNeedCleanup(false) ) + if (DoNeedCleanup()) + { InstanceCleanup(); + } events.RepeatEvent(CLEANUP_CHECK_INTERVAL); } break; diff --git a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/instance_trial_of_the_crusader.cpp b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/instance_trial_of_the_crusader.cpp index c8d22f5c9..02f8f4030 100644 --- a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/instance_trial_of_the_crusader.cpp +++ b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/instance_trial_of_the_crusader.cpp @@ -567,8 +567,10 @@ public: DoCheckDedicatedInsanity(); bSwitcher = !bSwitcher; - if( DoNeedCleanup(false) ) + if (DoNeedCleanup()) + { InstanceCleanup(); + } events.RepeatEvent(CLEANUP_CHECK_INTERVAL); } break; @@ -1401,8 +1403,10 @@ public: else plr->SendUpdateWorldState(UPDATE_STATE_UI_SHOW, 0); - if( DoNeedCleanup(true) ) + if (DoNeedCleanup(plr)) + { InstanceCleanup(); + } // if missing spawn anub'arak SpawnAnubArak(); @@ -1410,18 +1414,26 @@ public: events.RescheduleEvent(EVENT_CHECK_PLAYERS, CLEANUP_CHECK_INTERVAL); } - bool DoNeedCleanup(bool /*enter*/) + bool DoNeedCleanup(Player* ignoredPlayer = nullptr) { uint8 aliveCount = 0; - Map::PlayerList const& pl = instance->GetPlayers(); - for( Map::PlayerList::const_iterator itr = pl.begin(); itr != pl.end(); ++itr ) - if( Player* plr = itr->GetSource() ) - if( plr->IsAlive() && !plr->IsGameMaster() ) + for (const auto &itr: instance->GetPlayers()) + { + if (Player* plr = itr.GetSource()) + { + if (plr != ignoredPlayer && plr->IsAlive() && !plr->IsGameMaster()) + { ++aliveCount; + } + } + } bool need = aliveCount == 0; - if( !need && CLEANED ) + if (!need && CLEANED) + { CLEANED = false; + } + return need; }