Scripts: Minor loop refactors (#25325)

(cherry picked from commit dc9e0c1e86efbabb52085b3977ec1258f4fbb986)
This commit is contained in:
Maks Szokalski
2022-02-04 12:06:01 +01:00
committed by Shauren
parent 5a20f14a99
commit 663ec92794
2 changed files with 13 additions and 11 deletions
+5 -3
View File
@@ -56,12 +56,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
+8 -8
View File
@@ -78,20 +78,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);