aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Instances/InstanceScript.cpp
diff options
context:
space:
mode:
authorTraesh <Traesh@users.noreply.github.com>2022-02-16 23:54:26 +0100
committerGitHub <noreply@github.com>2022-02-16 23:54:26 +0100
commit543a7b79c3e5259ed3da413a6d91f00dfd85977e (patch)
treeda6ab6007675f5213ea3d12f7c9c9a9a624f9813 /src/server/game/Instances/InstanceScript.cpp
parent64e8e11377c9b0bf92e81afb38e0668ba3fdf3f4 (diff)
Core/Maps: Add Map::DoOnPlayers helper function (#25233)
Diffstat (limited to 'src/server/game/Instances/InstanceScript.cpp')
-rw-r--r--src/server/game/Instances/InstanceScript.cpp95
1 files changed, 40 insertions, 55 deletions
diff --git a/src/server/game/Instances/InstanceScript.cpp b/src/server/game/Instances/InstanceScript.cpp
index ea4c26ee653..8df7d06cdfb 100644
--- a/src/server/game/Instances/InstanceScript.cpp
+++ b/src/server/game/Instances/InstanceScript.cpp
@@ -383,12 +383,11 @@ bool InstanceScript::SetBossState(uint32 id, EncounterState state)
InitializeCombatResurrections(1, resInterval);
SendEncounterStart(1, 9, resInterval, resInterval);
- Map::PlayerList const &playerList = instance->GetPlayers();
- if (!playerList.isEmpty())
- for (Map::PlayerList::const_iterator i = playerList.begin(); i != playerList.end(); ++i)
- if (Player* player = i->GetSource())
- if (player->IsAlive())
- Unit::ProcSkillsAndAuras(player, nullptr, PROC_FLAG_ENCOUNTER_START, PROC_FLAG_NONE, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
+ instance->DoOnPlayers([](Player* player)
+ {
+ if (player->IsAlive())
+ Unit::ProcSkillsAndAuras(player, nullptr, PROC_FLAG_ENCOUNTER_START, PROC_FLAG_NONE, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
+ });
break;
}
case FAIL:
@@ -590,75 +589,60 @@ void InstanceScript::DoRespawnGameObject(ObjectGuid guid, Seconds timeToDespawn
void InstanceScript::DoUpdateWorldState(uint32 uiStateId, uint32 uiStateData)
{
- Map::PlayerList const& lPlayers = instance->GetPlayers();
-
- if (!lPlayers.isEmpty())
+ instance->DoOnPlayers([uiStateId, uiStateData](Player const* player)
{
- for (Map::PlayerList::const_iterator itr = lPlayers.begin(); itr != lPlayers.end(); ++itr)
- if (Player* player = itr->GetSource())
- player->SendUpdateWorldState(uiStateId, uiStateData);
- }
- else
- TC_LOG_DEBUG("scripts", "DoUpdateWorldState attempt send data but no players in map.");
+ player->SendUpdateWorldState(uiStateId, uiStateData);
+ });
}
// Send Notify to all players in instance
void InstanceScript::DoSendNotifyToInstance(char const* format, ...)
{
- InstanceMap::PlayerList const& players = instance->GetPlayers();
+ va_list ap;
+ va_start(ap, format);
+ char buff[1024];
+ vsnprintf(buff, 1024, format, ap);
+ va_end(ap);
- if (!players.isEmpty())
+ instance->DoOnPlayers([&buff](Player const* player)
{
- va_list ap;
- va_start(ap, format);
- char buff[1024];
- vsnprintf(buff, 1024, format, ap);
- va_end(ap);
- for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
- if (Player* player = i->GetSource())
- if (WorldSession* session = player->GetSession())
- session->SendNotification("%s", buff);
- }
+ player->GetSession()->SendNotification("%s", buff);
+ });
}
// Update Achievement Criteria for all players in instance
void InstanceScript::DoUpdateCriteria(CriteriaType type, uint32 miscValue1 /*= 0*/, uint32 miscValue2 /*= 0*/, Unit* unit /*= nullptr*/)
{
- Map::PlayerList const& PlayerList = instance->GetPlayers();
-
- if (!PlayerList.isEmpty())
- for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
- if (Player* player = i->GetSource())
- player->UpdateCriteria(type, miscValue1, miscValue2, 0, unit);
+ instance->DoOnPlayers([type, miscValue1, miscValue2, unit](Player* player)
+ {
+ player->UpdateCriteria(type, miscValue1, miscValue2, 0, unit);
+ });
}
// Start timed achievement for all players in instance
void InstanceScript::DoStartCriteriaTimer(CriteriaStartEvent startEvent, uint32 entry)
{
- Map::PlayerList const& PlayerList = instance->GetPlayers();
-
- if (!PlayerList.isEmpty())
- for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
- if (Player* player = i->GetSource())
- player->StartCriteriaTimer(startEvent, entry);
+ instance->DoOnPlayers([startEvent, entry](Player* player)
+ {
+ player->StartCriteriaTimer(startEvent, entry);
+ });
}
// Stop timed achievement for all players in instance
void InstanceScript::DoStopCriteriaTimer(CriteriaStartEvent startEvent, uint32 entry)
{
- Map::PlayerList const& PlayerList = instance->GetPlayers();
-
- if (!PlayerList.isEmpty())
- for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
- if (Player* player = i->GetSource())
- player->RemoveCriteriaTimer(startEvent, entry);
+ instance->DoOnPlayers([startEvent, entry](Player* player)
+ {
+ player->RemoveCriteriaTimer(startEvent, entry);
+ });
}
void InstanceScript::DoRemoveAurasDueToSpellOnPlayers(uint32 spell, bool includePets /*= false*/, bool includeControlled /*= false*/)
{
- Map::PlayerList const& playerList = instance->GetPlayers();
- for (auto itr = playerList.begin(); itr != playerList.end(); ++itr)
- DoRemoveAurasDueToSpellOnPlayer(itr->GetSource(), spell, includePets, includeControlled);
+ instance->DoOnPlayers([this, spell, includePets, includeControlled](Player* player)
+ {
+ DoRemoveAurasDueToSpellOnPlayer(player, spell, includePets, includeControlled);
+ });
}
void InstanceScript::DoRemoveAurasDueToSpellOnPlayer(Player* player, uint32 spell, bool includePets /*= false*/, bool includeControlled /*= false*/)
@@ -692,9 +676,10 @@ void InstanceScript::DoRemoveAurasDueToSpellOnPlayer(Player* player, uint32 spel
void InstanceScript::DoCastSpellOnPlayers(uint32 spell, bool includePets /*= false*/, bool includeControlled /*= false*/)
{
- Map::PlayerList const& playerList = instance->GetPlayers();
- for (auto itr = playerList.begin(); itr != playerList.end(); ++itr)
- DoCastSpellOnPlayer(itr->GetSource(), spell, includePets, includeControlled);
+ instance->DoOnPlayers([this, spell, includePets, includeControlled](Player* player)
+ {
+ DoCastSpellOnPlayer(player, spell, includePets, includeControlled);
+ });
}
void InstanceScript::DoCastSpellOnPlayer(Player* player, uint32 spell, bool includePets /*= false*/, bool includeControlled /*= false*/)
@@ -866,10 +851,10 @@ void InstanceScript::UpdateEncounterStateForSpellCast(uint32 spellId, Unit* sour
void InstanceScript::UpdatePhasing()
{
- Map::PlayerList const& players = instance->GetPlayers();
- for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
- if (Player* player = itr->GetSource())
- PhasingHandler::SendToPlayer(player);
+ instance->DoOnPlayers([](Player const* player)
+ {
+ PhasingHandler::SendToPlayer(player);
+ });
}
/*static*/ char const* InstanceScript::GetBossStateName(uint8 state)