Scripts: Minor loop refactors
Port From (https://github.com/TrinityCore/TrinityCore/commit/663ec927947c77a1668515334cf0f2e8c7673d31)
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user