diff --git a/src/server/game/Instances/InstanceScript.cpp b/src/server/game/Instances/InstanceScript.cpp index 6d7fb4633..d2e2b8bbe 100644 --- a/src/server/game/Instances/InstanceScript.cpp +++ b/src/server/game/Instances/InstanceScript.cpp @@ -591,81 +591,66 @@ void InstanceScript::DoUpdateWorldState(uint32 uiStateId, uint32 uiStateData) // Send Notify to all players in instance void InstanceScript::DoSendNotifyToInstance(char const* format, ...) { - InstanceMap::PlayerList const& players = instance->GetPlayers(); - - if (!players.IsEmpty()) + if (!instance->GetPlayers().IsEmpty()) { 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()) - player->GetSession()->SendNotification("%s", buff); + + instance->DoForAllPlayers([&, buff](Player* player) + { + player->GetSession()->SendNotification("%s", buff); + }); } } // Update Achievement Criteria for all players in instance void InstanceScript::DoUpdateAchievementCriteria(AchievementCriteriaTypes 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->UpdateAchievementCriteria(type, miscValue1, miscValue2, unit); + instance->DoForAllPlayers([&](Player* player) + { + player->UpdateAchievementCriteria(type, miscValue1, miscValue2, unit); + }); } // Start timed achievement for all players in instance void InstanceScript::DoStartTimedAchievement(AchievementCriteriaTimedTypes type, 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->StartTimedAchievement(type, entry); + instance->DoForAllPlayers([&](Player* player) + { + player->StartTimedAchievement(type, entry); + }); } // Stop timed achievement for all players in instance void InstanceScript::DoStopTimedAchievement(AchievementCriteriaTimedTypes type, 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->RemoveTimedAchievement(type, entry); + instance->DoForAllPlayers([&](Player* player) + { + player->RemoveTimedAchievement(type, entry); + }); } // Remove Auras due to Spell on all players in instance void InstanceScript::DoRemoveAurasDueToSpellOnPlayers(uint32 spell) { - Map::PlayerList const& PlayerList = instance->GetPlayers(); - if (!PlayerList.IsEmpty()) + instance->DoForAllPlayers([&](Player* player) { - for (Map::PlayerList::const_iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr) - { - if (Player* player = itr->GetSource()) - { - player->RemoveAurasDueToSpell(spell); - if (Pet* pet = player->GetPet()) - pet->RemoveAurasDueToSpell(spell); - } - } - } + player->RemoveAurasDueToSpell(spell); + if (Pet* pet = player->GetPet()) + pet->RemoveAurasDueToSpell(spell); + }); } // Cast spell on all players in instance void InstanceScript::DoCastSpellOnPlayers(uint32 spell) { - 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->CastSpell(player, spell, true); + instance->DoForAllPlayers([&](Player* player) + { + player->CastSpell(player, spell, true); + }); } void InstanceScript::DoCastSpellOnPlayer(Player* player, uint32 spell, bool includePets /*= false*/, bool includeControlled /*= false*/)