Scripts: Minor loop refactors (#25325)

This commit is contained in:
Maks Szokalski
2020-08-28 23:13:26 +02:00
committed by GitHub
parent 5d2780c43c
commit dc9e0c1e86
2 changed files with 13 additions and 11 deletions

View File

@@ -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

View File

@@ -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);