Core/Spells: Rewrite SelectRandomInjuredTargets to make extending it with additional requirements easier and allow it to prioritize group members

Port From (https://github.com/TrinityCore/TrinityCore/commit/d4d28d27f8322d6c07a6c384de1b4aecd1bb8a92)
This commit is contained in:
hondacrx
2023-09-14 04:03:00 -04:00
parent fde57f7cf0
commit 572bab53e4
2 changed files with 64 additions and 50 deletions
@@ -120,6 +120,18 @@ namespace System.Collections.Generic
list.Resize(size);
}
public static void RandomShuffle<T>(this IList<T> array, int first, int count)
{
for (int n = count; n > 1;)
{
int k = (int)RandomHelper.Rand32(n);
--n;
T temp = array[n + first];
array[n + first] = array[k + first];
array[k + first] = temp;
}
}
public static T SelectRandom<T>(this IEnumerable<T> source)
{
return source.SelectRandom(1).Single();