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)
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "GridDefines.h"
|
||||
#include "GridRefManager.h"
|
||||
#include "MapDefines.h"
|
||||
#include "MapReference.h"
|
||||
#include "MapRefManager.h"
|
||||
#include "MPSCQueue.h"
|
||||
#include "ObjectGuid.h"
|
||||
@@ -433,6 +434,14 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
|
||||
typedef MapRefManager PlayerList;
|
||||
PlayerList const& GetPlayers() const { return m_mapRefManager; }
|
||||
|
||||
template <typename T>
|
||||
void DoOnPlayers(T&& fn)
|
||||
{
|
||||
for (MapReference const& ref : GetPlayers())
|
||||
if (Player* player = ref.GetSource())
|
||||
fn(player);
|
||||
}
|
||||
|
||||
//per-map script storage
|
||||
void ScriptsStart(std::map<uint32, std::multimap<uint32, ScriptInfo>> const& scripts, uint32 id, Object* source, Object* target);
|
||||
void ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* source, Object* target);
|
||||
|
||||
@@ -653,21 +653,16 @@ class npc_acolyte_of_shadron : public CreatureScript
|
||||
if (ObjectAccessor::GetCreature(*me, instance->GetGuidData(DATA_SHADRON)))
|
||||
instance->SetBossState(DATA_PORTAL_OPEN, NOT_STARTED);
|
||||
|
||||
Map::PlayerList const& PlayerList = me->GetMap()->GetPlayers();
|
||||
|
||||
if (PlayerList.isEmpty())
|
||||
return;
|
||||
|
||||
for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
|
||||
instance->instance->DoOnPlayers([](Player* player)
|
||||
{
|
||||
if (i->GetSource()->IsAlive() && i->GetSource()->HasAura(SPELL_TWILIGHT_SHIFT) && !i->GetSource()->GetVictim())
|
||||
if (player->IsAlive() && player->HasAura(SPELL_TWILIGHT_SHIFT) && !player->GetVictim())
|
||||
{
|
||||
i->GetSource()->CastSpell(i->GetSource(), SPELL_TWILIGHT_SHIFT_REMOVAL_ALL, true);
|
||||
i->GetSource()->CastSpell(i->GetSource(), SPELL_TWILIGHT_RESIDUE, true);
|
||||
i->GetSource()->RemoveAurasDueToSpell(SPELL_TWILIGHT_SHIFT);
|
||||
i->GetSource()->RemoveAurasDueToSpell(SPELL_TWILIGHT_SHIFT_ENTER);
|
||||
player->CastSpell(player, SPELL_TWILIGHT_SHIFT_REMOVAL_ALL, true);
|
||||
player->CastSpell(player, SPELL_TWILIGHT_RESIDUE, true);
|
||||
player->RemoveAurasDueToSpell(SPELL_TWILIGHT_SHIFT);
|
||||
player->RemoveAurasDueToSpell(SPELL_TWILIGHT_SHIFT_ENTER);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// not solo fight, so main boss has debuff
|
||||
if (Creature* debuffTarget = ObjectAccessor::GetCreature(*me, instance->GetGuidData(DATA_SARTHARION)))
|
||||
@@ -737,23 +732,19 @@ class npc_acolyte_of_vesperon : public CreatureScript
|
||||
vesperon->RemoveAurasDueToSpell(SPELL_TWILIGHT_TORMENT_VESP);
|
||||
}
|
||||
|
||||
Map::PlayerList const& PlayerList = me->GetMap()->GetPlayers();
|
||||
|
||||
if (PlayerList.isEmpty())
|
||||
return;
|
||||
|
||||
for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
|
||||
instance->instance->DoOnPlayers([](Player* player)
|
||||
{
|
||||
if (i->GetSource()->IsAlive() && i->GetSource()->HasAura(SPELL_TWILIGHT_SHIFT) && !i->GetSource()->GetVictim())
|
||||
if (player->IsAlive() && player->HasAura(SPELL_TWILIGHT_SHIFT) && !player->GetVictim())
|
||||
{
|
||||
i->GetSource()->CastSpell(i->GetSource(), SPELL_TWILIGHT_SHIFT_REMOVAL_ALL, true);
|
||||
i->GetSource()->CastSpell(i->GetSource(), SPELL_TWILIGHT_RESIDUE, true);
|
||||
i->GetSource()->RemoveAurasDueToSpell(SPELL_TWILIGHT_SHIFT);
|
||||
i->GetSource()->RemoveAurasDueToSpell(SPELL_TWILIGHT_SHIFT_ENTER);
|
||||
player->CastSpell(player, SPELL_TWILIGHT_SHIFT_REMOVAL_ALL, true);
|
||||
player->CastSpell(player, SPELL_TWILIGHT_RESIDUE, true);
|
||||
player->RemoveAurasDueToSpell(SPELL_TWILIGHT_SHIFT);
|
||||
player->RemoveAurasDueToSpell(SPELL_TWILIGHT_SHIFT_ENTER);
|
||||
}
|
||||
if (i->GetSource()->IsAlive() && i->GetSource()->HasAura(SPELL_TWILIGHT_TORMENT_VESP) && !i->GetSource()->GetVictim())
|
||||
i->GetSource()->RemoveAurasDueToSpell(SPELL_TWILIGHT_TORMENT_VESP);
|
||||
}
|
||||
|
||||
if (player->IsAlive() && player->HasAura(SPELL_TWILIGHT_TORMENT_VESP) && !player->GetVictim())
|
||||
player->RemoveAurasDueToSpell(SPELL_TWILIGHT_TORMENT_VESP);
|
||||
});
|
||||
|
||||
instance->DoRemoveAurasDueToSpellOnPlayers(SPELL_TWILIGHT_TORMENT_VESP_ACO, true, true);
|
||||
instance->DoRemoveAurasDueToSpellOnPlayers(57935, true, true);
|
||||
|
||||
@@ -28,6 +28,7 @@ EndScriptData */
|
||||
#include "ObjectAccessor.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptedCreature.h"
|
||||
#include "InstanceScript.h"
|
||||
|
||||
enum Spells
|
||||
{
|
||||
@@ -110,21 +111,22 @@ public:
|
||||
//Inhibitmagic_Timer
|
||||
if (Inhibitmagic_Timer <= diff)
|
||||
{
|
||||
float dist;
|
||||
Map::PlayerList const& PlayerList = me->GetMap()->GetPlayers();
|
||||
for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
|
||||
if (Player* i_pl = i->GetSource())
|
||||
if (i_pl->IsAlive() && (dist = i_pl->GetDistance(me)) < 45)
|
||||
{
|
||||
i_pl->RemoveAurasDueToSpell(SPELL_INHIBITMAGIC);
|
||||
me->AddAura(SPELL_INHIBITMAGIC, i_pl);
|
||||
if (dist < 35)
|
||||
me->AddAura(SPELL_INHIBITMAGIC, i_pl);
|
||||
if (dist < 25)
|
||||
me->AddAura(SPELL_INHIBITMAGIC, i_pl);
|
||||
if (dist < 15)
|
||||
me->AddAura(SPELL_INHIBITMAGIC, i_pl);
|
||||
}
|
||||
me->GetMap()->DoOnPlayers([this](Player* player)
|
||||
{
|
||||
float dist = player->GetDistance(me);
|
||||
|
||||
if (player->IsAlive() && dist < 45.f)
|
||||
{
|
||||
player->RemoveAurasDueToSpell(SPELL_INHIBITMAGIC);
|
||||
me->AddAura(SPELL_INHIBITMAGIC, player);
|
||||
if (dist < 35)
|
||||
me->AddAura(SPELL_INHIBITMAGIC, player);
|
||||
if (dist < 25)
|
||||
me->AddAura(SPELL_INHIBITMAGIC, player);
|
||||
if (dist < 15)
|
||||
me->AddAura(SPELL_INHIBITMAGIC, player);
|
||||
}
|
||||
});
|
||||
Inhibitmagic_Timer = 3000 + (rand32() % 1000);
|
||||
} else Inhibitmagic_Timer -= diff;
|
||||
|
||||
|
||||
@@ -186,11 +186,11 @@ class boss_grandmaster_vorpil : public CreatureScript
|
||||
break;
|
||||
case EVENT_DRAW_SHADOWS:
|
||||
{
|
||||
Map::PlayerList const& PlayerList = me->GetMap()->GetPlayers();
|
||||
for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
|
||||
if (Player* i_pl = i->GetSource())
|
||||
if (i_pl->IsAlive() && !i_pl->HasAura(SPELL_BANISH))
|
||||
i_pl->TeleportTo(me->GetMapId(), VorpilPosition.GetPositionX(), VorpilPosition.GetPositionY(), VorpilPosition.GetPositionZ(), VorpilPosition.GetOrientation(), TELE_TO_NOT_LEAVE_COMBAT);
|
||||
instance->instance->DoOnPlayers([this](Player* player)
|
||||
{
|
||||
if (player->IsAlive() && !player->HasAura(SPELL_BANISH))
|
||||
player->TeleportTo(me->GetMapId(), VorpilPosition.GetPositionX(), VorpilPosition.GetPositionY(), VorpilPosition.GetPositionZ(), VorpilPosition.GetOrientation(), TELE_TO_NOT_LEAVE_COMBAT);
|
||||
});
|
||||
|
||||
me->UpdatePosition(VorpilPosition);
|
||||
DoCast(me, SPELL_DRAW_SHADOWS, true);
|
||||
|
||||
@@ -285,12 +285,11 @@ public:
|
||||
|
||||
if (RotTimer)
|
||||
{
|
||||
Map::PlayerList const& PlayerList = me->GetMap()->GetPlayers();
|
||||
for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
|
||||
instance->instance->DoOnPlayers([this, diff](Player* player)
|
||||
{
|
||||
if (i->GetSource() && i->GetSource()->IsAlive() && me->HasInArc(diff/20000.f*float(M_PI)*2.f, i->GetSource()) && me->IsWithinDist(i->GetSource(), SPOUT_DIST) && !i->GetSource()->IsInWater())
|
||||
DoCast(i->GetSource(), SPELL_SPOUT, true); // only knock back players in arc, in 100yards, not in water
|
||||
}
|
||||
if (player->IsAlive() && me->HasInArc(diff / 20000.f * float(M_PI) * 2.f, player) && me->IsWithinDist(player, SPOUT_DIST) && !player->IsInWater())
|
||||
DoCast(player, SPELL_SPOUT, true); // only knock back players in arc, in 100yards, not in water
|
||||
});
|
||||
|
||||
if (SpoutAnimTimer <= diff)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user