mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-15 08:47:14 +00:00
9667e86446
precompute result size set Gen5 as lumped group for common encounters remove linq usage (besides Sum call, whatever) GetEncounters now only filters the in-game static encounters rather than the dreamworld too, as those are already filtered by separate arrays.
34 lines
1.4 KiB
C#
34 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
/// <summary>
|
|
/// Miscellaneous setup utility for legality checking <see cref="IEncounterable"/> data sources.
|
|
/// </summary>
|
|
internal static class EncounterUtil
|
|
{
|
|
/// <summary>
|
|
/// Gets the relevant <see cref="EncounterStatic"/> objects that appear in the relevant game.
|
|
/// </summary>
|
|
/// <param name="source">Table of valid encounters that appear for the game pairing</param>
|
|
/// <param name="game">Game to filter for</param>
|
|
/// <returns>Array of encounter objects that can be encountered in the input game</returns>
|
|
internal static T[] GetEncounters<T>(IEnumerable<T> source, GameVersion game) where T : IVersion
|
|
{
|
|
return source.Where(s => s.Version.Contains(game)).ToArray();
|
|
}
|
|
|
|
internal static void MarkEncounterTradeStrings<T>(T[] table, string[][] strings) where T : EncounterTrade
|
|
{
|
|
int half = strings[1].Length / 2;
|
|
for (int i = 0; i < half; i++)
|
|
{
|
|
var t = table[i];
|
|
t.Nicknames = getNames(i, strings);
|
|
t.TrainerNames = getNames(i + half, strings);
|
|
}
|
|
string[] getNames(int i, IEnumerable<string[]> names) => names.Select(z => z.Length > i ? z[i] : string.Empty).ToArray();
|
|
}
|
|
}
|
|
}
|