Scripts: Minor loop refactors

Port From (https://github.com/TrinityCore/TrinityCore/commit/663ec927947c77a1668515334cf0f2e8c7673d31)
This commit is contained in:
hondacrx
2022-03-11 18:19:32 -05:00
parent 84de4826e4
commit 66a365f2f6
2 changed files with 11 additions and 13 deletions
+3 -3
View File
@@ -53,11 +53,11 @@ namespace Scripts.Pets
var u_check = new AnyUnfriendlyUnitInObjectRangeCheck(me, me, 30.0f); var u_check = new AnyUnfriendlyUnitInObjectRangeCheck(me, me, 30.0f);
var searcher = new UnitListSearcher(me, targets, u_check); var searcher = new UnitListSearcher(me, targets, u_check);
Cell.VisitAllObjects(me, searcher, 30.0f); Cell.VisitAllObjects(me, searcher, 30.0f);
foreach (var iter in targets) foreach (var target in targets)
{ {
if (iter.GetAura(SpellIds.SummonGargoyle1, ownerGuid) != null) if (target.HasAura(SpellIds.SummonGargoyle1, ownerGuid))
{ {
me.Attack(iter, false); me.Attack(target, false);
break; break;
} }
} }
+8 -10
View File
@@ -17,6 +17,7 @@
using Framework.Constants; using Framework.Constants;
using Game.AI; using Game.AI;
using Game.Combat;
using Game.Entities; using Game.Entities;
using Game.Scripting; using Game.Scripting;
using Game.Spells; using Game.Spells;
@@ -73,24 +74,21 @@ namespace Scripts.Pets
if (me.IsSummon() && !me.GetThreatManager().GetFixateTarget()) if (me.IsSummon() && !me.GetThreatManager().GetFixateTarget())
{ // find new target { // find new target
Unit summoner = me.ToTempSummon().GetSummonerUnit(); Unit summoner = me.ToTempSummon().GetSummonerUnit();
List<Unit> targets = new(); List<Unit> targets = new();
foreach (var pair in summoner.GetCombatManager().GetPvPCombatRefs())
void addTargetIfValid(CombatReference refe)
{ {
Unit enemy = pair.Value.GetOther(summoner); Unit enemy = refe.GetOther(summoner);
if (!enemy.HasBreakableByDamageCrowdControlAura() && me.CanCreatureAttack(enemy) && me.IsWithinDistInMap(enemy, me.GetAttackDistance(enemy))) if (!enemy.HasBreakableByDamageCrowdControlAura() && me.CanCreatureAttack(enemy) && me.IsWithinDistInMap(enemy, me.GetAttackDistance(enemy)))
targets.Add(enemy); targets.Add(enemy);
} }
foreach (var pair in summoner.GetCombatManager().GetPvPCombatRefs())
addTargetIfValid(pair.Value);
if (targets.Empty()) if (targets.Empty())
{
foreach (var pair in summoner.GetCombatManager().GetPvECombatRefs()) foreach (var pair in summoner.GetCombatManager().GetPvECombatRefs())
{ addTargetIfValid(pair.Value);
Unit enemy = pair.Value.GetOther(summoner);
if (!enemy.HasBreakableByDamageCrowdControlAura() && me.CanCreatureAttack(enemy) && me.IsWithinDistInMap(enemy, me.GetAttackDistance(enemy)))
targets.Add(enemy);
}
}
foreach (Unit target in targets) foreach (Unit target in targets)
me.EngageWithTarget(target); me.EngageWithTarget(target);