mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Maps: Add Map::DoOnPlayers helper function (#25233)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user