public override void InitializeAI() { base.InitializeAI(); ObjectGuid ownerGuid = me.GetOwnerGUID(); if (ownerGuid.IsEmpty()) { return; } // Find victim of Summon Gargoyle spell List <Unit> targets = new List <Unit>(); 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) { if (iter.GetAura(SpellSummonGargoyle1, ownerGuid) != null) { me.Attack(iter, false); break; } } }
bool IsInThreatList(Unit target) { Unit owner = me.GetCharmerOrOwner(); List <Unit> targets = new List <Unit>(); var u_check = new AnyUnfriendlyUnitInObjectRangeCheck(me, me, 30.0f); var searcher = new UnitListSearcher(me, targets, u_check); Cell.VisitAllObjects(me, searcher, 40.0f); foreach (var unit in targets) { if (unit == target) { // Consider only units without CC if (!unit.HasBreakableByDamageCrowdControlAura(unit)) { var triggers = unit.GetThreatManager().getThreatList(); foreach (var reference in triggers) { // Try to find threat referenced to owner if (reference.getTarget() == owner) { return(true); } } } } } return(false); }
void Init() { Unit owner = me.GetCharmerOrOwner(); List <Unit> targets = new List <Unit>(); var u_check = new AnyUnfriendlyUnitInObjectRangeCheck(me, me, 30.0f); var searcher = new UnitListSearcher(me, targets, u_check); Cell.VisitAllObjects(me, searcher, 40.0f); Unit highestThreatUnit = null; float highestThreat = 0.0f; Unit nearestPlayer = null; foreach (var unit in targets) { // Consider only units without CC if (!unit.HasBreakableByDamageCrowdControlAura(unit)) { // Take first found unit if (!highestThreatUnit && !unit.IsTypeId(TypeId.Player)) { highestThreatUnit = unit; continue; } if (!nearestPlayer && unit.IsTypeId(TypeId.Player)) { nearestPlayer = unit; continue; } // else compare best fit unit with current unit var triggers = unit.GetThreatManager().getThreatList(); foreach (var reference in triggers) { // Try to find threat referenced to owner if (reference.getTarget() == owner) { // Check if best fit hostile unit hs lower threat than this current unit if (highestThreat < reference.getThreat()) { // If so, update best fit unit highestThreat = reference.getThreat(); highestThreatUnit = unit; break; } } } // In case no unit with threat was found so far, always check for nearest unit (only for players) if (unit.IsTypeId(TypeId.Player)) { // If this player is closer than the previous one, update it if (me.GetDistance(unit.GetPosition()) < me.GetDistance(nearestPlayer.GetPosition())) { nearestPlayer = unit; } } } } // Prioritize units with threat referenced to owner if (highestThreat > 0.0f && highestThreatUnit) { me.Attack(highestThreatUnit, false); } // If there is no such target, try to attack nearest hostile unit if such exists else if (nearestPlayer) { me.Attack(nearestPlayer, false); } }