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

View File

@@ -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;

View File

@@ -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;
}