PKHeX/PKHeX.Core/Legality/Encounters/Data/EncounterUtil.cs
Kurt 37782f0ce4 Consolidate EncounterTrade1 level objects
Adds Nickname checks, thanks @ShadowMario3 for grabbing these into separate text files from Bulbapedia.

I reordered all the encounters to match Bulbapedia; each level is denoted if different if it can be sourced from RBY.
2020-11-22 16:19:03 -08:00

44 lines
1.8 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);
}
static string[] getNames(int i, IEnumerable<string[]> names) => names.Select(z => z.Length > i ? z[i] : string.Empty).ToArray();
}
internal static void MarkEncounterTradeNicknames<T>(T[] table, string[][] strings) where T : EncounterTrade
{
for (int i = 0; i < table.Length; i++)
{
var t = table[i];
t.Nicknames = getNames(i, strings);
}
static string[] getNames(int i, IEnumerable<string[]> names) => names.Select(z => z.Length > i ? z[i] : string.Empty).ToArray();
}
}
}