Core/Instances: improve DoRemoveAurasDueToSpellOnPlayers & DoCastSpellOnPlayers handling

(cherry picked from commit 22b3b21ae3)
This commit is contained in:
ccrs
2019-06-29 18:36:11 +02:00
committed by Shauren
parent cadbf42ea4
commit 70fd6e7398
10 changed files with 69 additions and 31 deletions

View File

@@ -648,33 +648,70 @@ void InstanceScript::DoStopCriteriaTimer(CriteriaStartEvent startEvent, uint32 e
player->RemoveCriteriaTimer(startEvent, entry);
}
// Remove Auras due to Spell on all players in instance
void InstanceScript::DoRemoveAurasDueToSpellOnPlayers(uint32 spell)
void InstanceScript::DoRemoveAurasDueToSpellOnPlayers(uint32 spell, bool includePets /*= false*/, bool includeControlled /*= false*/)
{
Map::PlayerList const& PlayerList = instance->GetPlayers();
if (!PlayerList.isEmpty())
Map::PlayerList const& playerList = instance->GetPlayers();
for (auto itr = playerList.begin(); itr != playerList.end(); ++itr)
{
for (Map::PlayerList::const_iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr)
if (Player* player = itr->GetSource())
{
if (Player* player = itr->GetSource())
player->RemoveAurasDueToSpell(spell);
if (!includePets)
continue;
for (uint8 itr2 = 0; itr2 < MAX_SUMMON_SLOT; ++itr2)
{
player->RemoveAurasDueToSpell(spell);
if (Pet* pet = player->GetPet())
pet->RemoveAurasDueToSpell(spell);
ObjectGuid summonGUID = player->m_SummonSlot[itr2];
if (!summonGUID.IsEmpty())
if (Creature* summon = instance->GetCreature(summonGUID))
summon->RemoveAurasDueToSpell(spell);
}
if (!includeControlled)
continue;
for (auto itr2 = player->m_Controlled.begin(); itr2 != player->m_Controlled.end(); ++itr2)
{
if (Unit* controlled = *itr2)
if (controlled->IsInWorld() && controlled->GetTypeId() == TYPEID_UNIT)
controlled->RemoveAurasDueToSpell(spell);
}
}
}
}
// Cast spell on all players in instance
void InstanceScript::DoCastSpellOnPlayers(uint32 spell)
void InstanceScript::DoCastSpellOnPlayers(uint32 spell, bool includePets /*= false*/, bool includeControlled /*= false*/)
{
Map::PlayerList const& PlayerList = instance->GetPlayers();
Map::PlayerList const& playerList = instance->GetPlayers();
for (auto itr = playerList.begin(); itr != playerList.end(); ++itr)
{
if (Player* player = itr->GetSource())
{
player->CastSpell(player, spell, true);
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);
if (!includePets)
continue;
for (uint8 itr2 = 0; itr2 < MAX_SUMMON_SLOT; ++itr2)
{
ObjectGuid summonGUID = player->m_SummonSlot[itr2];
if (!summonGUID.IsEmpty())
if (Creature* summon = instance->GetCreature(summonGUID))
summon->CastSpell(player, spell, true);
}
if (!includeControlled)
continue;
for (auto itr2 = player->m_Controlled.begin(); itr2 != player->m_Controlled.end(); ++itr2)
{
if (Unit* controlled = *itr2)
if (controlled->IsInWorld() && controlled->GetTypeId() == TYPEID_UNIT)
controlled->CastSpell(player, spell, true);
}
}
}
}
bool InstanceScript::ServerAllowsTwoSideGroups()