mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 02:04:52 +01:00
Scripts: Minor loop refactors (#25325)
This commit is contained in:
@@ -57,12 +57,14 @@ class npc_pet_dk_ebon_gargoyle : public CreatureScript
|
||||
Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, 30.0f);
|
||||
Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
|
||||
Cell::VisitAllObjects(me, searcher, 30.0f);
|
||||
for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
|
||||
if ((*iter)->HasAura(SPELL_DK_SUMMON_GARGOYLE_1, ownerGuid))
|
||||
for (Unit* target : targets)
|
||||
{
|
||||
if (target->HasAura(SPELL_DK_SUMMON_GARGOYLE_1, ownerGuid))
|
||||
{
|
||||
me->Attack((*iter), false);
|
||||
me->Attack(target, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JustDied(Unit* /*killer*/) override
|
||||
|
||||
@@ -95,20 +95,20 @@ class npc_pet_hunter_snake_trap : public CreatureScript
|
||||
Unit* summoner = me->ToTempSummon()->GetSummonerUnit();
|
||||
|
||||
std::vector<Unit*> targets;
|
||||
for (std::pair<ObjectGuid const, PvPCombatReference*> const& pair : summoner->GetCombatManager().GetPvPCombatRefs())
|
||||
|
||||
auto addTargetIfValid = [this, &targets, summoner](CombatReference* ref) mutable
|
||||
{
|
||||
Unit* enemy = pair.second->GetOther(summoner);
|
||||
Unit* enemy = ref->GetOther(summoner);
|
||||
if (!enemy->HasBreakableByDamageCrowdControlAura() && me->CanCreatureAttack(enemy) && me->IsWithinDistInMap(enemy, me->GetAttackDistance(enemy)))
|
||||
targets.push_back(enemy);
|
||||
}
|
||||
};
|
||||
|
||||
for (std::pair<ObjectGuid const, PvPCombatReference*> const& pair : summoner->GetCombatManager().GetPvPCombatRefs())
|
||||
addTargetIfValid(pair.second);
|
||||
|
||||
if (targets.empty())
|
||||
for (std::pair<ObjectGuid const, CombatReference*> const& pair : summoner->GetCombatManager().GetPvECombatRefs())
|
||||
{
|
||||
Unit* enemy = pair.second->GetOther(summoner);
|
||||
if (!enemy->HasBreakableByDamageCrowdControlAura() && me->CanCreatureAttack(enemy) && me->IsWithinDistInMap(enemy, me->GetAttackDistance(enemy)))
|
||||
targets.push_back(enemy);
|
||||
}
|
||||
addTargetIfValid(pair.second);
|
||||
|
||||
for (Unit* target : targets)
|
||||
me->EngageWithTarget(target);
|
||||
|
||||
Reference in New Issue
Block a user