Refactoring

slight simplification related to #1486
This commit is contained in:
Kurt 2017-09-23 16:24:22 -07:00
parent caf25efb46
commit 7974943bcf
8 changed files with 41 additions and 22 deletions

View file

@ -154,18 +154,30 @@ namespace PKHeX.Core
AddLine(Severity.Invalid, xorPID ? V215 : V216, CheckIdentifier.EC);
}
#region verifyLanguage
private bool verifyLanguage()
private bool VerifyLanguage()
{
int maxLanguageID = Legal.GetMaxLanguageID(Info.Generation);
// Language ID 6 is unused; flag if an impossible language is used
if (pkm.Language == 6 || pkm.Language > maxLanguageID)
{
AddLine(Severity.Invalid, string.Format(V5, "<=" + maxLanguageID, pkm.Language), CheckIdentifier.Language);
return false;
}
if(pkm.Format == 4 && pkm.Gen4 && (pkm.Language == 8) != (Legal.SavegameLanguage == 8))
// Korean Gen4 games can not trade with other Gen4 languages, but can use Pal Park with any Gen3 game/language.
if (pkm.Format == 4 && pkm.Gen4 && pkm.Language == 8 != (Legal.SavegameLanguage == 8))
{
// Korean gen 4 games can not trade with non-korean gen 4 games, but can use palpark with any gen3 game
AddLine(Severity.Invalid, pkm.Language == 8 ? V610 : V611, CheckIdentifier.Language);
var currentpkm = pkm.Language == 8 ? V611 : V612;
var currentsav = pkm.Language == 8 ? V612 : V611;
AddLine(Severity.Invalid, string.Format(V610, currentpkm, currentsav), CheckIdentifier.Language);
return false;
}
// Korean Crystal does not exist
if (pkm.Version == (int)GameVersion.C && pkm.Korean)
{
AddLine(Severity.Invalid, string.Format(V5, "!=" + pkm.Language, pkm.Language), CheckIdentifier.Language);
return false;
}
@ -200,7 +212,7 @@ namespace PKHeX.Core
if (!Encounter.Valid)
return;
if (!verifyLanguage())
if (!VerifyLanguage())
return;
if (Type == typeof(EncounterTrade))

View file

@ -258,7 +258,7 @@ namespace PKHeX.Core
moves2.RemoveAll(x => !hashMoves.Contains(x) || common.Contains(x));
return new[] { moves1, moves2 };
}
private static IEnumerable<int> GetLvlMoves(int species, int form, int Generation, int minlvl, int lvl, bool korean, GameVersion Version = GameVersion.Any)
private static IEnumerable<int> GetLvlMoves(int species, int form, int Generation, int minlvl, int lvl, bool korean = true, GameVersion Version = GameVersion.Any)
{
var r = new List<int>();
var ver = Version;
@ -587,7 +587,7 @@ namespace PKHeX.Core
for (int i = 0; i <= index; i++)
{
var evo = evoChain[i];
var moves = GetMoves(pkm, evo.Species, 1, 1, evo.Level, pkm.AltForm, moveTutor: true, Version: Version, LVL: true, specialTutors: true, Machine: true, MoveReminder: true, RemoveTransferHM: false, Generation: Generation, Korean: pkm.Korean);
var moves = GetMoves(pkm, evo.Species, 1, 1, evo.Level, pkm.AltForm, moveTutor: true, Version: Version, LVL: true, specialTutors: true, Machine: true, MoveReminder: true, RemoveTransferHM: false, Generation: Generation);
// Moves from Species or any species after in the evolution phase
evomoves.AddRange(moves);
}
@ -601,7 +601,7 @@ namespace PKHeX.Core
for (int i = 0; i < evoChain.Length; i++)
{
var evo = evoChain[i];
var moves = GetMoves(pkm, evo.Species, 1, 1, evo.Level, pkm.AltForm, moveTutor: true, Version: Version, LVL: true, specialTutors: true, Machine: true, MoveReminder: true, RemoveTransferHM: false, Generation: Generation, Korean: pkm.Korean);
var moves = GetMoves(pkm, evo.Species, 1, 1, evo.Level, pkm.AltForm, moveTutor: true, Version: Version, LVL: true, specialTutors: true, Machine: true, MoveReminder: true, RemoveTransferHM: false, Generation: Generation);
var list = i >= index ? preevomoves : evomoves;
list.AddRange(moves);
}
@ -609,9 +609,9 @@ namespace PKHeX.Core
}
// Encounter
internal static IEnumerable<GameVersion> GetGen2Versions(LegalInfo Info, bool Korean)
internal static IEnumerable<GameVersion> GetGen2Versions(LegalInfo Info)
{
if (AllowGen2Crystal(Korean) && Info.Game == GameVersion.C)
if (AllowGen2Crystal(Info.Korean) && Info.Game == GameVersion.C)
yield return GameVersion.C;
// Any encounter marked with version GSC is for pokemon with the same moves in GS and C
@ -1655,7 +1655,7 @@ namespace PKHeX.Core
// In gen 3 deoxys has different forms depending on the current game, in personal info there is no alter form info
formcount = 4;
for (int i = 0; i < formcount; i++)
r.AddRange(GetMoves(pkm, species, minLvLG1, minLvLG2, vs.First().Level, i, moveTutor, Version, LVL, Tutor, Machine, MoveReminder, RemoveTransferHM, Generation, pkm.Korean));
r.AddRange(GetMoves(pkm, species, minLvLG1, minLvLG2, vs.First().Level, i, moveTutor, Version, LVL, Tutor, Machine, MoveReminder, RemoveTransferHM, Generation));
if (Relearn) r.AddRange(pkm.RelearnMoves);
return r.Distinct();
}
@ -1678,7 +1678,7 @@ namespace PKHeX.Core
if (evo.MinLevel > 1)
minlvlevo2 = Math.Min(pkm.CurrentLevel, evo.MinLevel);
}
r.AddRange(GetMoves(pkm, evo.Species, minlvlevo1, minlvlevo2, evo.Level, pkm.AltForm, moveTutor, Version, LVL, Tutor, Machine, MoveReminder, RemoveTransferHM, Generation, pkm.Korean));
r.AddRange(GetMoves(pkm, evo.Species, minlvlevo1, minlvlevo2, evo.Level, pkm.AltForm, moveTutor, Version, LVL, Tutor, Machine, MoveReminder, RemoveTransferHM, Generation));
}
if (pkm.Format <= 3)
@ -1712,7 +1712,7 @@ namespace PKHeX.Core
r.AddRange(pkm.RelearnMoves);
return r.Distinct();
}
private static IEnumerable<int> GetMoves(PKM pkm, int species, int minlvlG1, int minlvlG2, int lvl, int form, bool moveTutor, GameVersion Version, bool LVL, bool specialTutors, bool Machine, bool MoveReminder, bool RemoveTransferHM, int Generation,bool Korean)
private static IEnumerable<int> GetMoves(PKM pkm, int species, int minlvlG1, int minlvlG2, int lvl, int form, bool moveTutor, GameVersion Version, bool LVL, bool specialTutors, bool Machine, bool MoveReminder, bool RemoveTransferHM, int Generation)
{
List<int> r = new List<int>();

View file

@ -51,9 +51,12 @@ namespace PKHeX.Core
/// <remarks>This boolean is true until all valid <see cref="PIDIV"/> encounters are tested, at which time it is false.</remarks>
public bool PIDIVMatches { get; set; } = true;
public readonly bool Korean;
public LegalInfo(PKM pk)
{
pkm = pk;
Korean = pk.Korean;
// Store repeatedly accessed values
Game = (GameVersion)pkm.Version;

View file

@ -151,7 +151,7 @@ namespace PKHeX.Core
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, pkm.Korean);
IEnumerable<GameVersion> games = (info.EncounterMatch as IGeneration)?.Generation == 1 ? Legal.GetGen1Versions(info) : Legal.GetGen2Versions(info);
foreach (GameVersion ver in games)
{
var VerInitialMoves = Legal.GetInitialMovesGBEncounter(G1Encounter.Species, G1Encounter.LevelMin, ver).ToArray();

View file

@ -414,8 +414,9 @@ namespace PKHeX.Core
public static string V607 { get; set; } = "Kanto Route 14 fishing encounter. Unreachable Water tiles.";
public static string V608 { get; set; } = "National Park fishing encounter. Unreachable Water tiles.";
public static string V609 { get; set; } = "Generation 2 Safari Zone fishing encounter. Unreachable zone.";
public static string V610 { get; set; } = "Korean gen4 pokemon in non-korean savegame."; // Invalid
public static string V611 { get; set; } = "Non-korean gen4 pokemon in korean savegame."; // Invalid
public static string V610 { get; set; } = "{0} origin cannot exist in the currently loaded ({1}) savegame."; // Invalid
public static string V611 { get; set; } = "Korean"; // Invalid
public static string V612 { get; set; } = "Non-Korean"; // Invalid
#endregion
}

View file

@ -351,5 +351,6 @@ V606 = Could not find a tree for Crystal headbutt encounter that matches OTID.
V607 = Kanto Route 14 fishing encounter. Unreachable Water tiles.
V608 = National Park fishing encounter. Unreachable Water tiles.
V609 = Generation 2 Safari Zone fishing encounter. Unreachable zone.
V610 = Korean gen4 pokemon in non-korean savegame.
V611 = Non-korean gen4 pokemon in korean savegame.
V610 = {0} origin cannot exist in the currently loaded ({1}) savegame.
V611 = Korean
V612 = Non-Korean

View file

@ -351,5 +351,6 @@ V606 = 크리스탈 버전 어버이 ID와 일치하는 박치기 인카운터
V607 = 관동 14번 도로의 낚시 인카운터입니다. 물 타일에 접근할 수 없는 지역입니다.
V608 = 자연공원의 낚시 인카운터입니다. 물 타일에 접근할 수 없는 지역입니다.
V609 = 2세대 사파리존의 낚시 인카운터입니다. 접근할 수 없는 지역입니다.
V610 = Korean gen4 pokemon in non-korean savegame.
V611 = Non-korean gen4 pokemon in korean savegame.
V610 = {0} origin cannot exist in the currently loaded ({1}) savegame.
V611 = Korean
V612 = Non-Korean

View file

@ -351,5 +351,6 @@ V606 = 无法在水晶版找到头锤遇敌的树符合初训家ID。
V607 = 关都14号道路钓鱼遇敌。无法到达的水域。
V608 = 自然公园钓鱼遇敌。无法到达的水域。
V609 = 第二世代狩猎区钓鱼遇敌。无法到达的区域。
V610 = Korean gen4 pokemon in non-korean savegame.
V611 = Non-korean gen4 pokemon in korean savegame.
V610 = {0} origin cannot exist in the currently loaded ({1}) savegame.
V611 = Korean
V612 = Non-Korean