fix(Scripts/ToC): Fix Trial of the Champion and Trial of the Crusader on … (#13772)

fix(scripts): Fix Trial of the Champion and Trial of the Crusader on player enter cleanup
This commit is contained in:
Mickaël Mauger
2022-11-12 16:14:24 +01:00
committed by GitHub
parent 26a7648765
commit 7222699f61
2 changed files with 41 additions and 17 deletions
@@ -256,26 +256,36 @@ public:
// EVENT STUFF BELOW: // EVENT STUFF BELOW:
void OnPlayerEnter(Player*) override void OnPlayerEnter(Player* plr) override
{
if (DoNeedCleanup(plr))
{ {
if( DoNeedCleanup(true) )
InstanceCleanup(); InstanceCleanup();
}
events.RescheduleEvent(EVENT_CHECK_PLAYERS, CLEANUP_CHECK_INTERVAL); events.RescheduleEvent(EVENT_CHECK_PLAYERS, CLEANUP_CHECK_INTERVAL);
} }
bool DoNeedCleanup(bool /*enter*/) bool DoNeedCleanup(Player* ignoredPlayer = nullptr)
{ {
uint8 aliveCount = 0; uint8 aliveCount = 0;
Map::PlayerList const& pl = instance->GetPlayers(); for (const auto &itr: instance->GetPlayers())
for( Map::PlayerList::const_iterator itr = pl.begin(); itr != pl.end(); ++itr ) {
if( Player* plr = itr->GetSource() ) if (Player* plr = itr.GetSource())
if( plr->IsAlive() && !plr->IsGameMaster() ) {
if (plr != ignoredPlayer && plr->IsAlive() && !plr->IsGameMaster())
{
++aliveCount; ++aliveCount;
}
}
}
bool need = aliveCount == 0; bool need = aliveCount == 0;
if (!need && CLEANED) if (!need && CLEANED)
{
CLEANED = false; CLEANED = false;
}
return need; return need;
} }
@@ -769,8 +779,10 @@ public:
break; break;
case EVENT_CHECK_PLAYERS: case EVENT_CHECK_PLAYERS:
{ {
if( DoNeedCleanup(false) ) if (DoNeedCleanup())
{
InstanceCleanup(); InstanceCleanup();
}
events.RepeatEvent(CLEANUP_CHECK_INTERVAL); events.RepeatEvent(CLEANUP_CHECK_INTERVAL);
} }
break; break;
@@ -567,8 +567,10 @@ public:
DoCheckDedicatedInsanity(); DoCheckDedicatedInsanity();
bSwitcher = !bSwitcher; bSwitcher = !bSwitcher;
if( DoNeedCleanup(false) ) if (DoNeedCleanup())
{
InstanceCleanup(); InstanceCleanup();
}
events.RepeatEvent(CLEANUP_CHECK_INTERVAL); events.RepeatEvent(CLEANUP_CHECK_INTERVAL);
} }
break; break;
@@ -1401,8 +1403,10 @@ public:
else else
plr->SendUpdateWorldState(UPDATE_STATE_UI_SHOW, 0); plr->SendUpdateWorldState(UPDATE_STATE_UI_SHOW, 0);
if( DoNeedCleanup(true) ) if (DoNeedCleanup(plr))
{
InstanceCleanup(); InstanceCleanup();
}
// if missing spawn anub'arak // if missing spawn anub'arak
SpawnAnubArak(); SpawnAnubArak();
@@ -1410,18 +1414,26 @@ public:
events.RescheduleEvent(EVENT_CHECK_PLAYERS, CLEANUP_CHECK_INTERVAL); events.RescheduleEvent(EVENT_CHECK_PLAYERS, CLEANUP_CHECK_INTERVAL);
} }
bool DoNeedCleanup(bool /*enter*/) bool DoNeedCleanup(Player* ignoredPlayer = nullptr)
{ {
uint8 aliveCount = 0; uint8 aliveCount = 0;
Map::PlayerList const& pl = instance->GetPlayers(); for (const auto &itr: instance->GetPlayers())
for( Map::PlayerList::const_iterator itr = pl.begin(); itr != pl.end(); ++itr ) {
if( Player* plr = itr->GetSource() ) if (Player* plr = itr.GetSource())
if( plr->IsAlive() && !plr->IsGameMaster() ) {
if (plr != ignoredPlayer && plr->IsAlive() && !plr->IsGameMaster())
{
++aliveCount; ++aliveCount;
}
}
}
bool need = aliveCount == 0; bool need = aliveCount == 0;
if (!need && CLEANED) if (!need && CLEANED)
{
CLEANED = false; CLEANED = false;
}
return need; return need;
} }