diff --git a/pkNX.Randomization/Randomizers/GenericRandomizer.cs b/pkNX.Randomization/Randomizers/GenericRandomizer.cs index 7f5e4c11..90ee4573 100644 --- a/pkNX.Randomization/Randomizers/GenericRandomizer.cs +++ b/pkNX.Randomization/Randomizers/GenericRandomizer.cs @@ -5,14 +5,14 @@ /// The shuffled list is iterated over, and reshuffled when exhausted. /// The list does not repeat values until the list is exhausted. /// - public class GenericRandomizer + public class GenericRandomizer { - public GenericRandomizer(int[] randomValues) + public GenericRandomizer(T[] randomValues) { RandomValues = randomValues; } - private readonly int[] RandomValues; + private readonly T[] RandomValues; private int ctr; public int Count => RandomValues.Length; @@ -22,14 +22,22 @@ public void Reset() Util.Shuffle(RandomValues); } - public int Next() + public T Next() { if (ctr == 0) Util.Shuffle(RandomValues); - int value = RandomValues[ctr++]; + T value = RandomValues[ctr++]; ctr %= RandomValues.Length; return value; } + + public T[] GetMany(int count) + { + var arr = new T[count]; + for (int i = 0; i < arr.Length; i++) + arr[i] = Next(); + return arr; + } } } diff --git a/pkNX.Randomization/Randomizers/MoveRandomizer.cs b/pkNX.Randomization/Randomizers/MoveRandomizer.cs index 855da78a..37766e57 100644 --- a/pkNX.Randomization/Randomizers/MoveRandomizer.cs +++ b/pkNX.Randomization/Randomizers/MoveRandomizer.cs @@ -11,7 +11,7 @@ public class MoveRandomizer : Randomizer private readonly PersonalTable SpeciesStat; private readonly GameInfo Config; - private GenericRandomizer RandMove; + private GenericRandomizer RandMove; internal MovesetRandSettings Settings; public MoveRandomizer(GameInfo config, Move[] moves, PersonalTable t) @@ -20,7 +20,7 @@ public MoveRandomizer(GameInfo config, Move[] moves, PersonalTable t) var maxMoveId = config.MaxMoveID; MoveData = moves; SpeciesStat = t; - RandMove = new GenericRandomizer(Enumerable.Range(1, maxMoveId - 1).ToArray()); + RandMove = new GenericRandomizer(Enumerable.Range(1, maxMoveId - 1).ToArray()); } public override void Execute() => throw new Exception("Shouldn't be called."); @@ -41,7 +41,7 @@ public void Initialize(MovesetRandSettings settings, int[] bannedMoves) var all = Enumerable.Range(1, Config.MaxMoveID - 1); var moves = all.Except(nanned); - RandMove = new GenericRandomizer(moves.ToArray()); + RandMove = new GenericRandomizer(moves.ToArray()); } public int[] GetRandomLearnset(int index, int movecount) => GetRandomLearnset(SpeciesStat[index].Types, movecount); @@ -128,7 +128,7 @@ public void ReorderMovesPower(IList moves) 141, // Leech Life }; - private static readonly GenericRandomizer first = new GenericRandomizer(firstMoves); + private static readonly GenericRandomizer first = new GenericRandomizer(firstMoves); public int GetRandomFirstMoveAny() { diff --git a/pkNX.Randomization/Randomizers/SpeciesRandomizer.cs b/pkNX.Randomization/Randomizers/SpeciesRandomizer.cs index 280a0665..90149175 100644 --- a/pkNX.Randomization/Randomizers/SpeciesRandomizer.cs +++ b/pkNX.Randomization/Randomizers/SpeciesRandomizer.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using pkNX.Structures; namespace pkNX.Randomization @@ -28,11 +27,11 @@ public void Initialize(SpeciesSettings settings, params int[] banlist) { s = settings; var list = s.GetSpecies(Game.MaxSpeciesID, Game.Generation).Except(banlist); - RandSpec = new GenericRandomizer(list.ToArray()); + RandSpec = new GenericRandomizer(list.ToArray()); } #region Random Species Filtering Parameters - private GenericRandomizer RandSpec; + private GenericRandomizer RandSpec; private int loopctr; private const int l = 10; // tweakable scalars private const int h = 11; diff --git a/pkNX.Randomization/Randomizers/TrainerRandomizer.cs b/pkNX.Randomization/Randomizers/TrainerRandomizer.cs index 96e6da2b..9ab4c288 100644 --- a/pkNX.Randomization/Randomizers/TrainerRandomizer.cs +++ b/pkNX.Randomization/Randomizers/TrainerRandomizer.cs @@ -16,7 +16,7 @@ public class TrainerRandomizer : Randomizer private readonly IList SpecialClasses; private readonly IList CrashClasses; - public GenericRandomizer Class { get; set; } + public GenericRandomizer Class { get; set; } public LearnsetRandomizer Learn { get; set; } public SpeciesRandomizer RandSpec { get; set; } public MoveRandomizer RandMove { get; set; } @@ -46,7 +46,7 @@ public void Initialize(TrainerRandSettings settings) IEnumerable classes = Enumerable.Range(0, ClassCount).Except(CrashClasses); if (Settings.SkipSpecialClasses) classes = classes.Except(SpecialClasses); - Class = new GenericRandomizer(classes.ToArray()); + Class = new GenericRandomizer(classes.ToArray()); } public override void Execute()