using System; namespace PKHeX.Core; public static class EffortValues { /// /// Gets randomized EVs for a given generation format /// /// Array containing randomized EVs (H/A/B/S/C/D) /// Generation specific formatting option public static void SetRandom(Span evs, int generation) { var rnd = Util.Rand; if (generation > 2) SetRandom252(evs, rnd); else SetRandom12(evs, rnd); } private static void SetRandom252(Span evs, Random rnd) { do { int max = 510; for (int i = 0; i < evs.Length - 1; i++) max -= evs[i] = (byte)Math.Min(rnd.Next(Math.Min(300, max)), 252); evs[5] = max; } while (evs[5] > 252); Util.Shuffle(evs, 0, evs.Length, rnd); } private static void SetRandom12(Span evs, Random rnd) { for (int i = 0; i < evs.Length; i++) evs[i] = rnd.Next(ushort.MaxValue + 1); } public static void SetMax(Span evs, PKM entity) { if (entity.Format < 3) SetMax12(evs); else SetMax252(evs, entity); } private static void SetMax252(Span evs, PKM entity) { // Get the 3 highest base stat indexes from the entity PersonalInfo var pi = entity.PersonalInfo; Span<(int Index, int Stat)> tuples = stackalloc (int, int)[6]; pi.GetSortedStatIndexes(tuples); evs[tuples[0].Index] = 252; evs[tuples[1].Index] = 252; evs[tuples[2].Index] = 6; } private static void SetMax12(Span evs) { for (int i = 0; i < evs.Length; i++) evs[i] = ushort.MaxValue; } public static void Clear(Span values) => values.Clear(); }