/// <summary> /// Select the best target (in <targetType> order) satisfying <predicate> from the threat list. /// If <offset> is nonzero, the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM) are skipped. /// </summary> public Unit SelectTarget(SelectAggroTarget targetType, uint offset, ISelector selector) { ThreatManager mgr = GetThreatManager(); // shortcut: if we ignore the first <offset> elements, and there are at most <offset> elements, then we ignore ALL elements if (mgr.GetThreatListSize() <= offset) { return(null); } List <Unit> targetList = SelectTargetList((uint)mgr.GetThreatListSize(), targetType, offset, selector); // maybe nothing fulfills the predicate if (targetList.Empty()) { return(null); } switch (targetType) { case SelectAggroTarget.MaxThreat: case SelectAggroTarget.MinThreat: case SelectAggroTarget.MaxDistance: case SelectAggroTarget.MinDistance: return(targetList[0]); case SelectAggroTarget.Random: return(targetList.SelectRandom()); default: return(null); } }
// Select the targets satifying the predicate. // predicate shall extend std.unary_function<Unit*, bool> public List <Unit> SelectTargetList(ISelector selector, uint maxTargets, SelectAggroTarget targetType) { var targetList = new List <Unit>(); var threatlist = GetThreatManager().getThreatList(); if (threatlist.Empty()) { return(targetList); } foreach (var hostileRef in threatlist) { if (selector.Check(hostileRef.getTarget())) { targetList.Add(hostileRef.getTarget()); } } if (targetList.Count < maxTargets) { return(targetList); } if (targetType == SelectAggroTarget.Nearest || targetType == SelectAggroTarget.Farthest) { SortByDistanceTo(me, targetList); } if (targetType == SelectAggroTarget.Farthest || targetType == SelectAggroTarget.BottomAggro) { targetList.Reverse(); } if (targetType == SelectAggroTarget.Random) { targetList = targetList.SelectRandom(maxTargets).ToList(); } else { targetList.Resize(maxTargets); } return(targetList); }
/// <summary> /// Select the best (up to) <num> targets (in <targetType> order) satisfying <predicate> from the threat list and stores them in <targetList> (which is cleared first). /// If <offset> is nonzero, the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM) are skipped. /// </summary> public List <Unit> SelectTargetList(uint num, SelectAggroTarget targetType, uint offset, ISelector selector) { var targetList = new List <Unit>(); ThreatManager mgr = GetThreatManager(); // shortcut: we're gonna ignore the first <offset> elements, and there's at most <offset> elements, so we ignore them all - nothing to do here if (mgr.GetThreatListSize() <= offset) { return(targetList); } if (targetType == SelectAggroTarget.MaxDistance || targetType == SelectAggroTarget.MinDistance) { foreach (HostileReference refe in mgr.GetThreatList()) { if (!refe.IsOnline()) { continue; } targetList.Add(refe.GetTarget()); } } else { Unit currentVictim = mgr.GetCurrentVictim(); if (currentVictim != null) { targetList.Add(currentVictim); } foreach (HostileReference refe in mgr.GetThreatList()) { if (!refe.IsOnline()) { continue; } Unit thisTarget = refe.GetTarget(); if (thisTarget != currentVictim) { targetList.Add(thisTarget); } } } // shortcut: the list isn't gonna get any larger if (targetList.Count <= offset) { targetList.Clear(); return(targetList); } // right now, list is unsorted for DISTANCE types - re-sort by MAXDISTANCE if (targetType == SelectAggroTarget.MaxDistance || targetType == SelectAggroTarget.MinDistance) { SortByDistance(targetList, targetType == SelectAggroTarget.MinDistance); } // now the list is MAX sorted, reverse for MIN types if (targetType == SelectAggroTarget.MinThreat) { targetList.Reverse(); } // ignore the first <offset> elements while (offset != 0) { targetList.RemoveAt(0); --offset; } // then finally filter by predicate targetList.RemoveAll(target => { return(!selector.Check(target)); }); if (targetList.Count <= num) { return(targetList); } if (targetType == SelectAggroTarget.Random) { targetList = targetList.SelectRandom(num).ToList(); } else { targetList.Resize(num); } return(targetList); }
/// <summary> /// Select the best (up to) <num> targets (in <targetType> order) from the threat list that fulfill the following: /// - Not among the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM). /// - Within at most <dist> yards (if dist > 0.0f) /// - At least -<dist> yards away (if dist < 0.0f) /// - Is a player (if playerOnly = true) /// - Not the current tank (if withTank = false) /// - Has aura with ID <aura> (if aura > 0) /// - Does not have aura with ID -<aura> (if aura < 0) /// The resulting targets are stored in <targetList> (which is cleared first). /// </summary> public List <Unit> SelectTargetList(uint num, SelectAggroTarget targetType, uint offset, float dist, bool playerOnly, bool withTank, int aura = 0) { return(SelectTargetList(num, targetType, offset, new DefaultTargetSelector(me, dist, playerOnly, withTank, aura))); }
/// <summary> /// Select the best target (in <targetType> order) from the threat list that fulfill the following: /// - Not among the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM). /// - Within at most <dist> yards (if dist > 0.0f) /// - At least -<dist> yards away (if dist < 0.0f) /// - Is a player (if playerOnly = true) /// - Not the current tank (if withTank = false) /// - Has aura with ID <aura> (if aura > 0) /// - Does not have aura with ID -<aura> (if aura < 0) /// </summary> public Unit SelectTarget(SelectAggroTarget targetType, uint offset = 0, float dist = 0.0f, bool playerOnly = false, bool withTank = true, int aura = 0) { return(SelectTarget(targetType, offset, new DefaultTargetSelector(me, dist, playerOnly, withTank, aura))); }
public List <Unit> SelectTargetList(uint num, SelectAggroTarget targetType, float dist, bool playerOnly, int aura = 0) { return(SelectTargetList(new DefaultTargetSelector(me, dist, playerOnly, aura), num, targetType)); }
// Select the targets satifying the predicate. public Unit SelectTarget(SelectAggroTarget targetType, uint position, ISelector selector) { var threatlist = GetThreatManager().getThreatList(); if (position >= threatlist.Count) { return(null); } List <Unit> targetList = new List <Unit>(); Unit currentVictim = null; var currentVictimReference = GetThreatManager().getCurrentVictim(); if (currentVictimReference != null) { currentVictim = currentVictimReference.getTarget(); // Current victim always goes first if (currentVictim && selector.Check(currentVictim)) { targetList.Add(currentVictim); } } foreach (var hostileRef in threatlist) { if (currentVictim != null && hostileRef.getTarget() != currentVictim && selector.Check(hostileRef.getTarget())) { targetList.Add(hostileRef.getTarget()); } else if (currentVictim == null && selector.Check(hostileRef.getTarget())) { targetList.Add(hostileRef.getTarget()); } } if (position >= targetList.Count) { return(null); } if (targetType == SelectAggroTarget.Nearest || targetType == SelectAggroTarget.Farthest) { SortByDistanceTo(me, targetList); } switch (targetType) { case SelectAggroTarget.Nearest: case SelectAggroTarget.TopAggro: { return(targetList.First()); } case SelectAggroTarget.Farthest: case SelectAggroTarget.BottomAggro: { return(targetList.Last()); } case SelectAggroTarget.Random: { return(targetList.SelectRandom()); } default: break; } return(null); }
public Unit SelectTarget(SelectAggroTarget targetType, uint position = 0, float dist = 0.0f, bool playerOnly = false, int aura = 0) { return(SelectTarget(targetType, position, new DefaultTargetSelector(me, dist, playerOnly, aura))); }