Dictionary<WoWUnit, double> mobList = new Dictionary<WoWUnit, double>();
List<KeyValuePair<WoWUnit, double>> sortedmobList = new List<KeyValuePair<WoWUnit, double>>();
// Adds <unit, unit.distance> to mobList dictionary
foreach (WoWUnit unit in ObjectManager.GetObjectsOfType<WoWUnit>(false))
{
if (unit.Guid != Me.Guid && !unit.IsFriendly && unit.Attackable && unit.InLineOfSight)
{
mobList.Add(unit, unit.Distance);
}
}
// Convert mobList dictionary to sortedmobList List
if (mobList.Count > 0)
{
sortedmobList = new List<KeyValuePair<WoWUnit, double>>(mobList);
}
// This sorts the List by comparing pair.Values (which is the unit.Distance in <unit, unit.Distance>)
// Lowest value goes to index 0
if (sortedmobList.Count > 1)
{
sortedmobList.Sort(delegate(KeyValuePair<WoWUnit, double> firstPair, KeyValuePair<WoWUnit, double> nextPair)
{ return firstPair.Value.CompareTo(nextPair.Value);});
}
if (MeCheck && !Me.Combat && sortedmobList.Count > 0)
{
if (Me.CurrentTarget == null)
{
// Target the closest by calling index 0 of sortedmobList
sortedmobList[0].Key.Target();
Thread.Sleep(100);
}
SequenceManager.CallSequenceExecutor(Sequence.Pull);
return;
}