PKHeX/PKHeX.Core/Legality/Moves/MoveLevelUp.cs
Kurt 3c232505e5
Refactoring: Narrow some value types (Species, Move, Form) (#3575)
In this pull request I've changed a ton of method signatures to reflect the more-narrow types of Species, Move# and Form; additionally, I've narrowed other large collections that stored lists of species / permitted values, and reworked them to be more performant with the latest API spaghetti that PKHeX provides. Roamer met locations, usually in a range of [max-min]<64, can be quickly checked using a bitflag operation on a UInt64. Other collections (like "Is this from Colosseum or XD") were eliminated -- shadow state is not transferred COLO<->XD, so having a Shadow ID or matching the met location from a gift/wild encounter is a sufficient check for "originated in XD".
2022-08-26 23:43:36 -07:00

53 lines
1.8 KiB
C#

using System;
using static PKHeX.Core.GameVersion;
namespace PKHeX.Core;
public static class MoveLevelUp
{
public static ushort[] GetEncounterMoves(PKM pk, int level, GameVersion version)
{
if (version <= 0)
version = (GameVersion)pk.Version;
return GetEncounterMoves(pk.Species, pk.Form, level, version);
}
private static ushort[] GetEncounterMoves1(ushort species, int level, GameVersion version)
{
var learn = GameData.GetLearnsets(version);
var table = GameData.GetPersonal(version);
var index = table.GetFormIndex(species, 0);
Span<ushort> lvl0 = stackalloc ushort[4];
((PersonalInfo1) table[index]).GetMoves(lvl0);
int start = Math.Max(0, lvl0.IndexOf((ushort)0));
learn[index].SetEncounterMoves(level, lvl0, start);
return lvl0.ToArray();
}
private static ushort[] GetEncounterMoves2(ushort species, int level, GameVersion version)
{
var learn = GameData.GetLearnsets(version);
var table = GameData.GetPersonal(version);
var index = table.GetFormIndex(species, 0);
var lvl0 = learn[species].GetEncounterMoves(1);
int start = Math.Max(0, Array.IndexOf(lvl0, (ushort)0));
learn[index].SetEncounterMoves(level, lvl0, start);
return lvl0;
}
public static ushort[] GetEncounterMoves(ushort species, int form, int level, GameVersion version)
{
if (RBY.Contains(version))
return GetEncounterMoves1(species, level, version);
if (GSC.Contains(version))
return GetEncounterMoves2(species, level, version);
var learn = GameData.GetLearnsets(version);
var table = GameData.GetPersonal(version);
var index = table.GetFormIndex(species, form);
return learn[index].GetEncounterMoves(level);
}
}