mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-14 01:05:19 -05:00
Refactoring
remove some unneeded logic moves in gen1/2 can be reordered, sequence match should be intersect (full) contains match.
This commit is contained in:
@@ -395,63 +395,6 @@ internal static IEnumerable<GameVersion> GetGen1Versions(LegalInfo Info)
|
||||
// it is sufficient to check just RB's case
|
||||
yield return GameVersion.RB;
|
||||
}
|
||||
internal static IEnumerable<int> GetInitialMovesGBEncounter(int species, int lvl, GameVersion ver)
|
||||
{
|
||||
int[] InitialMoves;
|
||||
int[] LevelUpMoves;
|
||||
int diff;
|
||||
switch (ver)
|
||||
{
|
||||
case GameVersion.YW:
|
||||
case GameVersion.RD:
|
||||
case GameVersion.BU:
|
||||
case GameVersion.GN:
|
||||
case GameVersion.RB:
|
||||
{
|
||||
var LevelTable = ver == GameVersion.YW ? LevelUpY : LevelUpRB;
|
||||
int index = PersonalTable.RB.GetFormeIndex(species, 0);
|
||||
if (index == 0)
|
||||
return Enumerable.Empty<int>();
|
||||
LevelUpMoves = LevelTable[species].GetEncounterMoves(lvl);
|
||||
diff = 4 - LevelUpMoves.Count(z => z != 0);
|
||||
if (diff == 0)
|
||||
return LevelUpMoves;
|
||||
var table = ver == GameVersion.YW ? PersonalTable.Y : PersonalTable.RB;
|
||||
InitialMoves = ((PersonalInfoG1)table[index]).Moves;
|
||||
break;
|
||||
}
|
||||
case GameVersion.C:
|
||||
case GameVersion.GD:
|
||||
case GameVersion.SV:
|
||||
case GameVersion.GS:
|
||||
{
|
||||
if (species == 235)
|
||||
return new[] { 166 }; // Smeargle only learns Sketch, is duplicated in the level up tables
|
||||
var LevelTable = ver == GameVersion.C ? LevelUpC : LevelUpGS;
|
||||
int index = PersonalTable.C.GetFormeIndex(species, 0);
|
||||
if (index == 0)
|
||||
return Enumerable.Empty<int>();
|
||||
LevelUpMoves = LevelTable[species].GetEncounterMoves(lvl);
|
||||
diff = 4 - LevelUpMoves.Count(z => z != 0);
|
||||
if (diff == 0)
|
||||
return LevelUpMoves;
|
||||
// Level Up 1 moves are initial moves, it can be duplicated in levels 2-100
|
||||
InitialMoves = LevelTable[species].GetEncounterMoves(1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return Enumerable.Empty<int>();
|
||||
}
|
||||
// Initial Moves could be duplicated in the level up table
|
||||
// level up table moves have preference
|
||||
var moves = InitialMoves.Where(p => p != 0).Except(LevelUpMoves).ToList();
|
||||
// If all of the personal table moves can't be included, the last moves have preference.
|
||||
int pop = moves.Count - diff;
|
||||
if (pop > 0)
|
||||
moves.RemoveRange(0, pop);
|
||||
// The order for the pokemon default moves are first moves from personal table and then moves from level up table
|
||||
return moves.Union(LevelUpMoves).ToArray();
|
||||
}
|
||||
internal static int GetRequiredMoveCount(PKM pk, int[] moves, LegalInfo info, int[] initialmoves)
|
||||
{
|
||||
if (pk.Format != 1 || !pk.Gen1_NotTradeback) // No Move Deleter in Gen 1
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
|
||||
@@ -7,13 +7,13 @@ public static class EncounterLinkGenerator
|
||||
{
|
||||
public static IEnumerable<EncounterLink> GetPossible(PKM pkm)
|
||||
{
|
||||
if (pkm.GenNumber != 6)
|
||||
if (!pkm.Gen6)
|
||||
return Enumerable.Empty<EncounterLink>();
|
||||
return Encounters6.LinkGifts6.Where(g => g.Species == pkm.Species);
|
||||
}
|
||||
public static IEnumerable<EncounterLink> GetPossible(PKM pkm, IReadOnlyList<DexLevel> vs)
|
||||
{
|
||||
if (pkm.GenNumber != 6)
|
||||
if (!pkm.Gen6)
|
||||
return Enumerable.Empty<EncounterLink>();
|
||||
return Encounters6.LinkGifts6.Where(g => vs.Any(z => z.Species == g.Species));
|
||||
}
|
||||
|
||||
@@ -157,11 +157,11 @@ private static CheckMoveResult[] ParseMovesGenGB(PKM pkm, int[] Moves, LegalInfo
|
||||
return ParseMovesSpecialMoveset(pkm, Moves, info);
|
||||
var InitialMoves = new int[0];
|
||||
int[] SpecialMoves = GetSpecialMoves(info.EncounterMatch);
|
||||
IEnumerable<GameVersion> games = (info.EncounterMatch as IGeneration)?.Generation == 1 ? Legal.GetGen1Versions(info) : Legal.GetGen2Versions(info);
|
||||
foreach (GameVersion ver in games)
|
||||
var games = info.EncounterMatch is IGeneration g && g.Generation == 1 ? Legal.GetGen1Versions(info) : Legal.GetGen2Versions(info);
|
||||
foreach (var ver in games)
|
||||
{
|
||||
var VerInitialMoves = Legal.GetInitialMovesGBEncounter(G1Encounter.Species, G1Encounter.LevelMin, ver).ToArray();
|
||||
if (VerInitialMoves.SequenceEqual(InitialMoves))
|
||||
var VerInitialMoves = MoveLevelUp.GetEncounterMoves(G1Encounter.Species, 0, G1Encounter.LevelMin, ver);
|
||||
if (VerInitialMoves.Intersect(InitialMoves).Count() == VerInitialMoves.Length)
|
||||
return res;
|
||||
|
||||
var source = new MoveParseSource
|
||||
|
||||
@@ -424,8 +424,6 @@ private static List<int> AddMovesLevelUp7(List<int> moves, GameVersion ver, int
|
||||
|
||||
public static int[] GetEncounterMoves(PKM pk, int level, GameVersion version)
|
||||
{
|
||||
if (RBY.Contains(version))
|
||||
return GetEncounterMoves1(pk.Species, level, version);
|
||||
if (version <= 0)
|
||||
version = (GameVersion)pk.Version;
|
||||
return GetEncounterMoves(pk.Species, pk.AltForm, level, version);
|
||||
@@ -441,9 +439,23 @@ private static int[] GetEncounterMoves1(int species, int level, GameVersion vers
|
||||
|
||||
return learn[index].GetEncounterMoves(level, lvl0, start);
|
||||
}
|
||||
private static int[] GetEncounterMoves2(int species, int level, GameVersion version)
|
||||
{
|
||||
var learn = GameData.GetLearnsets(version);
|
||||
var table = GameData.GetPersonal(version);
|
||||
var index = table.GetFormeIndex(species, 0);
|
||||
var lvl0 = learn[species].GetEncounterMoves(1);
|
||||
int start = Math.Max(0, Array.FindIndex(lvl0, z => z == 0));
|
||||
|
||||
return learn[index].GetEncounterMoves(level, lvl0, start);
|
||||
}
|
||||
|
||||
public static int[] GetEncounterMoves(int 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.GetFormeIndex(species, form);
|
||||
|
||||
Reference in New Issue
Block a user