From 66a365f2f6867f2f9b615c30593773d594b0b392 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 11 Mar 2022 18:19:32 -0500 Subject: [PATCH] Scripts: Minor loop refactors Port From (https://github.com/TrinityCore/TrinityCore/commit/663ec927947c77a1668515334cf0f2e8c7673d31) --- Source/Scripts/Pets/DeathKnight.cs | 6 +++--- Source/Scripts/Pets/Hunter.cs | 18 ++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Source/Scripts/Pets/DeathKnight.cs b/Source/Scripts/Pets/DeathKnight.cs index e95681998..35eee3b21 100644 --- a/Source/Scripts/Pets/DeathKnight.cs +++ b/Source/Scripts/Pets/DeathKnight.cs @@ -53,11 +53,11 @@ namespace Scripts.Pets var u_check = new AnyUnfriendlyUnitInObjectRangeCheck(me, me, 30.0f); var searcher = new UnitListSearcher(me, targets, u_check); 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; } } diff --git a/Source/Scripts/Pets/Hunter.cs b/Source/Scripts/Pets/Hunter.cs index ce83d1328..062fba13f 100644 --- a/Source/Scripts/Pets/Hunter.cs +++ b/Source/Scripts/Pets/Hunter.cs @@ -17,6 +17,7 @@ using Framework.Constants; using Game.AI; +using Game.Combat; using Game.Entities; using Game.Scripting; using Game.Spells; @@ -73,24 +74,21 @@ namespace Scripts.Pets if (me.IsSummon() && !me.GetThreatManager().GetFixateTarget()) { // find new target Unit summoner = me.ToTempSummon().GetSummonerUnit(); - List 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))) targets.Add(enemy); } + foreach (var pair in summoner.GetCombatManager().GetPvPCombatRefs()) + addTargetIfValid(pair.Value); + if (targets.Empty()) - { foreach (var pair in summoner.GetCombatManager().GetPvECombatRefs()) - { - Unit enemy = pair.Value.GetOther(summoner); - if (!enemy.HasBreakableByDamageCrowdControlAura() && me.CanCreatureAttack(enemy) && me.IsWithinDistInMap(enemy, me.GetAttackDistance(enemy))) - targets.Add(enemy); - } - } + addTargetIfValid(pair.Value); foreach (Unit target in targets) me.EngageWithTarget(target);