Minor updates

increase readability, simplifly some expressions
relocate hot path for legality report string creation
This commit is contained in:
Kurt 2019-05-11 10:12:14 -07:00
parent 332784d34b
commit 21e7f4317e
7 changed files with 195 additions and 190 deletions

View file

@ -81,9 +81,7 @@ namespace PKHeX.Core
return _allSuggestedRelearnMoves; return _allSuggestedRelearnMoves;
if (Error || Info == null) if (Error || Info == null)
return new int[4]; return new int[4];
var gender = pkm.PersonalInfo.Gender; return _allSuggestedRelearnMoves = Legal.GetValidRelearn(pkm, Info.EncounterMatch.Species, (GameVersion)pkm.Version).ToArray();
var inheritLvlMoves = (gender > 0 && gender < 255) || Legal.MixedGenderBreeding.Contains(Info.EncounterMatch.Species);
return _allSuggestedRelearnMoves = Legal.GetValidRelearn(pkm, Info.EncounterMatch.Species, inheritLvlMoves).ToArray();
} }
} }
@ -130,7 +128,7 @@ namespace PKHeX.Core
&& Info.Moves.All(m => m.Valid) && Info.Moves.All(m => m.Valid)
&& Info.Relearn.All(m => m.Valid); && Info.Relearn.All(m => m.Valid);
if (pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch is EncounterInvalid) if (!Valid && pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch is EncounterInvalid)
AddLine(Severity.Indeterminate, LFatefulGiftMissing, CheckIdentifier.Fateful); AddLine(Severity.Indeterminate, LFatefulGiftMissing, CheckIdentifier.Fateful);
} }
#if SUPPRESS #if SUPPRESS
@ -299,6 +297,8 @@ namespace PKHeX.Core
private string GetLegalityReport() private string GetLegalityReport()
{ {
if (Valid)
return L_ALegal;
if (!Parsed || Info == null) if (!Parsed || Info == null)
return L_AnalysisUnavailable; return L_AnalysisUnavailable;
@ -308,7 +308,7 @@ namespace PKHeX.Core
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
if (!vMoves[i].Valid) if (!vMoves[i].Valid)
lines.Add(string.Format(L_F0_M_1_2, vMoves[i].Rating, i + 1, vMoves[i].Comment)); lines.Add(vMoves[i].Format(L_F0_M_1_2, i + 1));
} }
if (pkm.Format >= 6) if (pkm.Format >= 6)
@ -316,19 +316,13 @@ namespace PKHeX.Core
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
if (!vRelearn[i].Valid) if (!vRelearn[i].Valid)
lines.Add(string.Format(L_F0_RM_1_2, vRelearn[i].Rating, i + 1, vRelearn[i].Comment)); lines.Add(vRelearn[i].Format(L_F0_RM_1_2, i + 1));
} }
} }
if (lines.Count == 0 && Parse.All(chk => chk.Valid) && Valid)
return L_ALegal;
// Build result string... // Build result string...
var outputLines = Parse.Where(chk => !chk.Valid); // Only invalid var outputLines = Parse.Where(chk => !chk.Valid);
lines.AddRange(outputLines.Select(chk => string.Format(L_F0_1, chk.Rating, chk.Comment))); lines.AddRange(outputLines.Select(chk => chk.Format(L_F0_1)));
if (lines.Count == 0)
return L_AError;
return string.Join(Environment.NewLine, lines); return string.Join(Environment.NewLine, lines);
} }
@ -351,7 +345,7 @@ namespace PKHeX.Core
var move = vMoves[i]; var move = vMoves[i];
if (!move.Valid) if (!move.Valid)
continue; continue;
var msg = string.Format(L_F0_M_1_2, move.Rating, i + 1, move.Comment); var msg = move.Format(L_F0_M_1_2, i + 1);
if (pkm.Format != move.Generation) if (pkm.Format != move.Generation)
msg += $" [Gen{move.Generation}]"; msg += $" [Gen{move.Generation}]";
lines.Add(msg); lines.Add(msg);
@ -362,7 +356,7 @@ namespace PKHeX.Core
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
if (vRelearn[i].Valid) if (vRelearn[i].Valid)
lines.Add(string.Format(L_F0_RM_1_2, vRelearn[i].Rating, i + 1, vRelearn[i].Comment)); lines.Add(vRelearn[i].Format(L_F0_RM_1_2, i + 1));
} }
} }
@ -370,7 +364,7 @@ namespace PKHeX.Core
lines.Add(br[1]); lines.Add(br[1]);
var outputLines = Parse.Where(chk => chk?.Valid == true && chk.Comment != L_AValid).OrderBy(chk => chk.Judgement); // Fishy sorted to top var outputLines = Parse.Where(chk => chk?.Valid == true && chk.Comment != L_AValid).OrderBy(chk => chk.Judgement); // Fishy sorted to top
lines.AddRange(outputLines.Select(chk => string.Format(L_F0_1, chk.Rating, chk.Comment))); lines.AddRange(outputLines.Select(chk => chk.Format(L_F0_1)));
lines.AddRange(br); lines.AddRange(br);
lines.Add(string.Format(L_FEncounterType_0, EncounterName)); lines.Add(string.Format(L_FEncounterType_0, EncounterName));

View file

@ -99,9 +99,14 @@ namespace PKHeX.Core
return GetValidMoves(pkm, version, evoChain, generation, minLvLG1: minLvLG1, minLvLG2: minLvLG2, LVL: LVL, Relearn: false, Tutor: Tutor, Machine: Machine, MoveReminder: MoveReminder, RemoveTransferHM: RemoveTransferHM); return GetValidMoves(pkm, version, evoChain, generation, minLvLG1: minLvLG1, minLvLG2: minLvLG2, LVL: LVL, Relearn: false, Tutor: Tutor, Machine: Machine, MoveReminder: MoveReminder, RemoveTransferHM: RemoveTransferHM);
} }
internal static IEnumerable<int> GetValidRelearn(PKM pkm, int species, GameVersion version = GameVersion.Any)
{
return GetValidRelearn(pkm, species, GetCanInheritMoves(species), version);
}
internal static IEnumerable<int> GetValidRelearn(PKM pkm, int species, bool inheritlvlmoves, GameVersion version = GameVersion.Any) internal static IEnumerable<int> GetValidRelearn(PKM pkm, int species, bool inheritlvlmoves, GameVersion version = GameVersion.Any)
{ {
List<int> r = new List<int> { 0 }; var r = new List<int> { 0 };
if (pkm.GenNumber < 6) if (pkm.GenNumber < 6)
return r; return r;
@ -707,7 +712,7 @@ namespace PKHeX.Core
private static IEnumerable<int> GetValidMoves(PKM pkm, GameVersion Version, IReadOnlyList<IReadOnlyList<EvoCriteria>> vs, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = false, bool Relearn = false, bool Tutor = false, bool Machine = false, bool MoveReminder = true, bool RemoveTransferHM = true) private static IEnumerable<int> GetValidMoves(PKM pkm, GameVersion Version, IReadOnlyList<IReadOnlyList<EvoCriteria>> vs, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = false, bool Relearn = false, bool Tutor = false, bool Machine = false, bool MoveReminder = true, bool RemoveTransferHM = true)
{ {
List<int> r = new List<int> { 0 }; var r = new List<int> { 0 };
if (Relearn && pkm.Format >= 6) if (Relearn && pkm.Format >= 6)
r.AddRange(pkm.RelearnMoves); r.AddRange(pkm.RelearnMoves);
@ -722,7 +727,7 @@ namespace PKHeX.Core
private static IEnumerable<int> GetValidMoves(PKM pkm, GameVersion Version, IReadOnlyList<EvoCriteria> vs, int generation, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = false, bool Relearn = false, bool Tutor = false, bool Machine = false, bool MoveReminder = true, bool RemoveTransferHM = true) private static IEnumerable<int> GetValidMoves(PKM pkm, GameVersion Version, IReadOnlyList<EvoCriteria> vs, int generation, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = false, bool Relearn = false, bool Tutor = false, bool Machine = false, bool MoveReminder = true, bool RemoveTransferHM = true)
{ {
List<int> r = new List<int> { 0 }; var r = new List<int> { 0 };
if (vs.Count == 0) if (vs.Count == 0)
return r; return r;
int species = pkm.Species; int species = pkm.Species;
@ -802,7 +807,7 @@ namespace PKHeX.Core
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) 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>(); var r = new List<int>();
if (LVL) if (LVL)
r.AddRange(MoveLevelUp.GetMovesLevelUp(pkm, species, minlvlG1, minlvlG2, lvl, form, Version, MoveReminder, generation)); r.AddRange(MoveLevelUp.GetMovesLevelUp(pkm, species, minlvlG1, minlvlG2, lvl, form, Version, MoveReminder, generation));
if (Machine) if (Machine)

View file

@ -12,11 +12,11 @@ namespace PKHeX
/// </summary> /// </summary>
internal static class GBRestrictions internal static class GBRestrictions
{ {
internal static readonly int[] G1CaterpieMoves = { 33, 81 }; private static readonly int[] G1CaterpieMoves = { 33, 81 };
internal static readonly int[] G1WeedleMoves = { 40, 81 }; private static readonly int[] G1WeedleMoves = { 40, 81 };
internal static readonly int[] G1MetapodMoves = G1CaterpieMoves.Concat(new[] { 106 }).ToArray(); private static readonly int[] G1MetapodMoves = { 33, 81, 106 };
internal static readonly int[] G1KakunaMoves = G1WeedleMoves.Concat(new[] { 106 }).ToArray(); private static readonly int[] G1KakunaMoves = { 40, 81, 106 };
internal static readonly int[] G1Exeggcute_IncompatibleMoves = { 78, 77, 79 }; private static readonly int[] G1Exeggcute_IncompatibleMoves = { 78, 77, 79 };
internal static readonly int[] Stadium_CatchRate = internal static readonly int[] Stadium_CatchRate =
{ {
@ -24,7 +24,7 @@ namespace PKHeX
168, // Gorgeous Box 168, // Gorgeous Box
}; };
internal static readonly HashSet<int> Stadium_GiftSpecies = new HashSet<int> private static readonly HashSet<int> Stadium_GiftSpecies = new HashSet<int>
{ {
001, // Bulbasaur 001, // Bulbasaur
004, // Charmander 004, // Charmander
@ -37,12 +37,14 @@ namespace PKHeX
140, // Kabuto 140, // Kabuto
}; };
internal static readonly HashSet<int> SpecialMinMoveSlots = new HashSet<int> private static readonly HashSet<int> SpecialMinMoveSlots = new HashSet<int>
{ {
25, 26, 29, 30, 31, 32, 33, 34, 36, 38, 40, 59, 91, 103, 114, 121, 25, 26, 29, 30, 31, 32, 33, 34, 36, 38, 40, 59, 91, 103, 114, 121,
}; };
internal static readonly HashSet<int> Types_Gen1 = new HashSet<int> internal static bool TypeIDExists(int type) => Types_Gen1.Contains(type);
private static readonly HashSet<int> Types_Gen1 = new HashSet<int>
{ {
0, 1, 2, 3, 4, 5, 7, 8, 20, 21, 22, 23, 24, 25, 26 0, 1, 2, 3, 4, 5, 7, 8, 20, 21, 22, 23, 24, 25, 26
}; };

View file

@ -25,5 +25,8 @@
Comment = c; Comment = c;
Identifier = i; Identifier = i;
} }
public string Format(string format) => string.Format(format, Rating, Comment);
public string Format(string format, int index) => string.Format(format, Rating, index, Comment);
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using static PKHeX.Core.LegalityCheckStrings; using static PKHeX.Core.LegalityCheckStrings;
using static PKHeX.Core.CheckIdentifier;
namespace PKHeX.Core namespace PKHeX.Core
{ {
@ -9,7 +10,7 @@ namespace PKHeX.Core
/// </summary> /// </summary>
public sealed class MiscVerifier : Verifier public sealed class MiscVerifier : Verifier
{ {
protected override CheckIdentifier Identifier => CheckIdentifier.Misc; protected override CheckIdentifier Identifier => Misc;
public override void Verify(LegalityAnalysis data) public override void Verify(LegalityAnalysis data)
{ {
@ -19,21 +20,21 @@ namespace PKHeX.Core
VerifyMiscEggCommon(data); VerifyMiscEggCommon(data);
if (pkm is IContestStats s && s.HasContestStats()) if (pkm is IContestStats s && s.HasContestStats())
data.AddLine(GetInvalid(LEggContest, CheckIdentifier.Egg)); data.AddLine(GetInvalid(LEggContest, Egg));
switch (pkm) switch (pkm)
{ {
case PK5 pk5 when pk5.PokeStarFame != 0 && pk5.IsEgg: case PK5 pk5 when pk5.PokeStarFame != 0 && pk5.IsEgg:
data.AddLine(GetInvalid(LEggShinyPokeStar, CheckIdentifier.Egg)); data.AddLine(GetInvalid(LEggShinyPokeStar, Egg));
break; break;
case PK4 pk4 when pk4.ShinyLeaf != 0: case PK4 pk4 when pk4.ShinyLeaf != 0:
data.AddLine(GetInvalid(LEggShinyLeaf, CheckIdentifier.Egg)); data.AddLine(GetInvalid(LEggShinyLeaf, Egg));
break; break;
case PK4 pk4 when pk4.PokéathlonStat != 0: case PK4 pk4 when pk4.PokéathlonStat != 0:
data.AddLine(GetInvalid(LEggPokeathlon, CheckIdentifier.Egg)); data.AddLine(GetInvalid(LEggPokeathlon, Egg));
break; break;
case PK3 _ when pkm.Language != 1: // All Eggs are Japanese and flagged specially for localized string case PK3 _ when pkm.Language != 1: // All Eggs are Japanese and flagged specially for localized string
data.AddLine(GetInvalid(string.Format(LOTLanguage, LanguageID.Japanese, (LanguageID)pkm.Language), CheckIdentifier.Egg)); data.AddLine(GetInvalid(string.Format(LOTLanguage, LanguageID.Japanese, (LanguageID)pkm.Language), Egg));
break; break;
} }
} }
@ -53,7 +54,7 @@ namespace PKHeX.Core
{ {
VerifyMiscEggCommon(data); VerifyMiscEggCommon(data);
if (pkm.PKRS_Cured || pkm.PKRS_Infected) if (pkm.PKRS_Cured || pkm.PKRS_Infected)
data.AddLine(GetInvalid(LEggPokerus, CheckIdentifier.Egg)); data.AddLine(GetInvalid(LEggPokerus, Egg));
} }
if (!(pkm is PK1 pk1)) if (!(pkm is PK1 pk1))
@ -67,14 +68,14 @@ namespace PKHeX.Core
{ {
var Type_A = pk1.Type_A; var Type_A = pk1.Type_A;
var Type_B = pk1.Type_B; var Type_B = pk1.Type_B;
if (pk1.Species == 137) // Porygon if (pk1.Species == (int)Species.Porygon)
{ {
// Can have any type combination of any species by using Conversion. // Can have any type combination of any species by using Conversion.
if (!GBRestrictions.Types_Gen1.Contains(Type_A)) if (!GBRestrictions.TypeIDExists(Type_A))
{ {
data.AddLine(GetInvalid(LG1TypePorygonFail1)); data.AddLine(GetInvalid(LG1TypePorygonFail1));
} }
else if (!GBRestrictions.Types_Gen1.Contains(Type_B)) if (!GBRestrictions.TypeIDExists(Type_B))
{ {
data.AddLine(GetInvalid(LG1TypePorygonFail2)); data.AddLine(GetInvalid(LG1TypePorygonFail2));
} }
@ -166,35 +167,35 @@ namespace PKHeX.Core
VerifyFatefulMysteryGift(data, g); VerifyFatefulMysteryGift(data, g);
return; return;
case EncounterStatic s when s.Fateful: // ingame fateful case EncounterStatic s when s.Fateful: // ingame fateful
case EncounterSlot _ when pkm.Version == 15: // ingame pokespot case EncounterSlot x when x.Version == GameVersion.XD: // ingame pokespot
case EncounterTrade t when t.Fateful: case EncounterTrade t when t.Fateful:
VerifyFatefulIngameActive(data); VerifyFatefulIngameActive(data);
return; return;
} }
if (pkm.FatefulEncounter) if (pkm.FatefulEncounter)
data.AddLine(GetInvalid(LFatefulInvalid, CheckIdentifier.Fateful)); data.AddLine(GetInvalid(LFatefulInvalid, Fateful));
} }
private static void VerifyMiscEggCommon(LegalityAnalysis data) private static void VerifyMiscEggCommon(LegalityAnalysis data)
{ {
var pkm = data.pkm; var pkm = data.pkm;
if (pkm.Move1_PPUps > 0 || pkm.Move2_PPUps > 0 || pkm.Move3_PPUps > 0 || pkm.Move4_PPUps > 0) if (pkm.Move1_PPUps > 0 || pkm.Move2_PPUps > 0 || pkm.Move3_PPUps > 0 || pkm.Move4_PPUps > 0)
data.AddLine(GetInvalid(LEggPPUp, CheckIdentifier.Egg)); data.AddLine(GetInvalid(LEggPPUp, Egg));
if (pkm.Move1_PP != pkm.GetMovePP(pkm.Move1, 0) || pkm.Move2_PP != pkm.GetMovePP(pkm.Move2, 0) || pkm.Move3_PP != pkm.GetMovePP(pkm.Move3, 0) || pkm.Move4_PP != pkm.GetMovePP(pkm.Move4, 0)) if (pkm.Move1_PP != pkm.GetMovePP(pkm.Move1, 0) || pkm.Move2_PP != pkm.GetMovePP(pkm.Move2, 0) || pkm.Move3_PP != pkm.GetMovePP(pkm.Move3, 0) || pkm.Move4_PP != pkm.GetMovePP(pkm.Move4, 0))
data.AddLine(GetInvalid(LEggPP, CheckIdentifier.Egg)); data.AddLine(GetInvalid(LEggPP, Egg));
var EncounterMatch = data.EncounterOriginal; var EncounterMatch = data.EncounterOriginal;
var HatchCycles = (EncounterMatch as EncounterStatic)?.EggCycles; var HatchCycles = (EncounterMatch as EncounterStatic)?.EggCycles;
if (HatchCycles == 0 || HatchCycles == null) if (HatchCycles == 0 || HatchCycles == null)
HatchCycles = pkm.PersonalInfo.HatchCycles; HatchCycles = pkm.PersonalInfo.HatchCycles;
if (pkm.CurrentFriendship > HatchCycles) if (pkm.CurrentFriendship > HatchCycles)
data.AddLine(GetInvalid(LEggHatchCycles, CheckIdentifier.Egg)); data.AddLine(GetInvalid(LEggHatchCycles, Egg));
if (pkm.Format >= 6 && EncounterMatch is EncounterEgg && !pkm.Moves.SequenceEqual(pkm.RelearnMoves)) if (pkm.Format >= 6 && EncounterMatch is EncounterEgg && !pkm.Moves.SequenceEqual(pkm.RelearnMoves))
{ {
var moves = string.Join(", ", LegalityAnalysis.GetMoveNames(pkm.Moves)); var moves = string.Join(", ", LegalityAnalysis.GetMoveNames(pkm.Moves));
var msg = string.Format(LMoveFExpect_0, moves); var msg = string.Format(LMoveFExpect_0, moves);
data.AddLine(GetInvalid(msg, CheckIdentifier.Egg)); data.AddLine(GetInvalid(msg, Egg));
} }
} }
@ -206,12 +207,12 @@ namespace PKHeX.Core
var Info = data.Info; var Info = data.Info;
Info.PIDIV = MethodFinder.Analyze(pkm); Info.PIDIV = MethodFinder.Analyze(pkm);
if (Info.PIDIV.Type != PIDType.G5MGShiny && pkm.Egg_Location != Locations.LinkTrade5) if (Info.PIDIV.Type != PIDType.G5MGShiny && pkm.Egg_Location != Locations.LinkTrade5)
data.AddLine(GetInvalid(LPIDTypeMismatch, CheckIdentifier.PID)); data.AddLine(GetInvalid(LPIDTypeMismatch, PID));
} }
var result = pkm.FatefulEncounter != pkm.WasLink var result = pkm.FatefulEncounter != pkm.WasLink
? GetValid(LFatefulMystery, CheckIdentifier.Fateful) ? GetValid(LFatefulMystery, Fateful)
: GetInvalid(LFatefulMysteryMissing, CheckIdentifier.Fateful); : GetInvalid(LFatefulMysteryMissing, Fateful);
data.AddLine(result); data.AddLine(result);
} }
@ -222,13 +223,13 @@ namespace PKHeX.Core
{ {
case WC6 wc6 when !wc6.CanBeReceivedByVersion(pkm.Version) && !pkm.WasTradedEgg: case WC6 wc6 when !wc6.CanBeReceivedByVersion(pkm.Version) && !pkm.WasTradedEgg:
case WC7 wc7 when !wc7.CanBeReceivedByVersion(pkm.Version) && !pkm.WasTradedEgg: case WC7 wc7 when !wc7.CanBeReceivedByVersion(pkm.Version) && !pkm.WasTradedEgg:
data.AddLine(GetInvalid(LEncGiftVersionNotDistributed, CheckIdentifier.GameOrigin)); data.AddLine(GetInvalid(LEncGiftVersionNotDistributed, GameOrigin));
return; return;
case WC6 wc6 when wc6.RestrictLanguage != 0 && wc6.Language != wc6.RestrictLanguage: case WC6 wc6 when wc6.RestrictLanguage != 0 && wc6.Language != wc6.RestrictLanguage:
data.AddLine(GetInvalid(string.Format(LOTLanguage, wc6.RestrictLanguage, pkm.Language), CheckIdentifier.Language)); data.AddLine(GetInvalid(string.Format(LOTLanguage, wc6.RestrictLanguage, pkm.Language), Language));
return; return;
case WC7 wc7 when wc7.RestrictLanguage != 0 && wc7.Language != wc7.RestrictLanguage: case WC7 wc7 when wc7.RestrictLanguage != 0 && wc7.Language != wc7.RestrictLanguage:
data.AddLine(GetInvalid(string.Format(LOTLanguage, wc7.RestrictLanguage, pkm.Language), CheckIdentifier.Language)); data.AddLine(GetInvalid(string.Format(LOTLanguage, wc7.RestrictLanguage, pkm.Language), Language));
return; return;
} }
} }
@ -237,7 +238,7 @@ namespace PKHeX.Core
{ {
// check for shiny locked gifts // check for shiny locked gifts
if (!g3.Shiny.IsValid(data.pkm)) if (!g3.Shiny.IsValid(data.pkm))
data.AddLine(GetInvalid(LEncGiftShinyMismatch, CheckIdentifier.Fateful)); data.AddLine(GetInvalid(LEncGiftShinyMismatch, Fateful));
} }
private static void VerifyFatefulIngameActive(LegalityAnalysis data) private static void VerifyFatefulIngameActive(LegalityAnalysis data)
@ -247,14 +248,14 @@ namespace PKHeX.Core
{ {
// can't have fateful until traded away, which clears ShadowID // can't have fateful until traded away, which clears ShadowID
if (xk3.FatefulEncounter && xk3.ShadowID != 0 && data.EncounterMatch is EncounterStaticShadow) if (xk3.FatefulEncounter && xk3.ShadowID != 0 && data.EncounterMatch is EncounterStaticShadow)
data.AddLine(GetInvalid(LFatefulInvalid, CheckIdentifier.Fateful)); data.AddLine(GetInvalid(LFatefulInvalid, Fateful));
return; // fateful is set when transferred away return; // fateful is set when transferred away
} }
var result = pkm.FatefulEncounter var result = pkm.FatefulEncounter
? GetValid(LFateful, CheckIdentifier.Fateful) ? GetValid(LFateful, Fateful)
: GetInvalid(LFatefulMissing, CheckIdentifier.Fateful); : GetInvalid(LFatefulMissing, Fateful);
data.AddLine(result); data.AddLine(result);
} }
@ -273,7 +274,7 @@ namespace PKHeX.Core
bool Sun() => pkm.Version == (int)GameVersion.SN || pkm.Version == (int)GameVersion.US; bool Sun() => pkm.Version == (int)GameVersion.SN || pkm.Version == (int)GameVersion.US;
bool Moon() => pkm.Version == (int)GameVersion.MN || pkm.Version == (int)GameVersion.UM; bool Moon() => pkm.Version == (int)GameVersion.MN || pkm.Version == (int)GameVersion.UM;
if (pkm.IsUntraded) if (pkm.IsUntraded)
data.AddLine(GetInvalid(LEvoTradeRequired, CheckIdentifier.Evolution)); data.AddLine(GetInvalid(LEvoTradeRequired, Evolution));
break; break;
} }
} }
@ -282,18 +283,18 @@ namespace PKHeX.Core
{ {
// ReSharper disable once CompareOfFloatsByEqualityOperator -- THESE MUST MATCH EXACTLY // ReSharper disable once CompareOfFloatsByEqualityOperator -- THESE MUST MATCH EXACTLY
if (!IsCloseEnough(pb7.HeightAbsolute, pb7.CalcHeightAbsolute)) if (!IsCloseEnough(pb7.HeightAbsolute, pb7.CalcHeightAbsolute))
data.AddLine(GetInvalid(LStatIncorrectHeight, CheckIdentifier.Encounter)); data.AddLine(GetInvalid(LStatIncorrectHeight, Encounter));
// ReSharper disable once CompareOfFloatsByEqualityOperator -- THESE MUST MATCH EXACTLY // ReSharper disable once CompareOfFloatsByEqualityOperator -- THESE MUST MATCH EXACTLY
if (!IsCloseEnough(pb7.WeightAbsolute, pb7.CalcWeightAbsolute)) if (!IsCloseEnough(pb7.WeightAbsolute, pb7.CalcWeightAbsolute))
data.AddLine(GetInvalid(LStatIncorrectWeight, CheckIdentifier.Encounter)); data.AddLine(GetInvalid(LStatIncorrectWeight, Encounter));
if (pb7.Stat_CP != pb7.CalcCP && !IsStarter(pb7)) if (pb7.Stat_CP != pb7.CalcCP && !IsStarter(pb7))
data.AddLine(GetInvalid(LStatIncorrectCP, CheckIdentifier.Encounter)); data.AddLine(GetInvalid(LStatIncorrectCP, Encounter));
if (IsTradeEvoRequired7b(data.EncounterOriginal, pb7)) if (IsTradeEvoRequired7b(data.EncounterOriginal, pb7))
{ {
var unevolved = LegalityAnalysis.SpeciesStrings[pb7.Species]; var unevolved = LegalityAnalysis.SpeciesStrings[pb7.Species];
var evolved = LegalityAnalysis.SpeciesStrings[pb7.Species + 1]; var evolved = LegalityAnalysis.SpeciesStrings[pb7.Species + 1];
data.AddLine(GetInvalid(string.Format(LEvoTradeReqOutsider, unevolved, evolved), CheckIdentifier.Evolution)); data.AddLine(GetInvalid(string.Format(LEvoTradeReqOutsider, unevolved, evolved), Evolution));
} }
} }

View file

@ -6,17 +6,17 @@ namespace PKHeX.Core
{ {
public static partial class Legal public static partial class Legal
{ {
private struct CountryTable private class CountryTable
{ {
public byte countryID; public byte CountryID;
public byte mainform; public byte BaseForm;
public FormSubregionTable[] otherforms; public FormSubregionTable[] SubRegionForms;
} }
private struct FormSubregionTable private class FormSubregionTable
{ {
public byte form; public byte Form;
public int[] region; public int[] Regions;
} }
private static readonly int[][] VivillonCountryTable = private static readonly int[][] VivillonCountryTable =
@ -45,204 +45,204 @@ namespace PKHeX.Core
private static readonly CountryTable[] RegionFormTable = private static readonly CountryTable[] RegionFormTable =
{ {
new CountryTable{ new CountryTable{
countryID = 001, // Japan CountryID = 001, // Japan
mainform = 05, // Elegant BaseForm = 05, // Elegant
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 02, region = new[] {03,04} }, new FormSubregionTable { Form = 02, Regions = new[] {03,04} },
new FormSubregionTable { form = 13, region = new[] {48} }, new FormSubregionTable { Form = 13, Regions = new[] {48} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 049, // USA CountryID = 049, // USA
mainform = 07, // Modern BaseForm = 07, // Modern
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 01, region = new[] {03,09,21,23,24,32,33,36,40,41,48,50} }, new FormSubregionTable { Form = 01, Regions = new[] {03,09,21,23,24,32,33,36,40,41,48,50} },
new FormSubregionTable { form = 09, region = new[] {53} }, new FormSubregionTable { Form = 09, Regions = new[] {53} },
new FormSubregionTable { form = 10, region = new[] {06,07,08,15,28,34,35,39,46,49} }, new FormSubregionTable { Form = 10, Regions = new[] {06,07,08,15,28,34,35,39,46,49} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 018, // Canada CountryID = 018, // Canada
mainform = 01, // Polar BaseForm = 01, // Polar
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 00, region = new[] {12,13,14} }, new FormSubregionTable { Form = 00, Regions = new[] {12,13,14} },
new FormSubregionTable { form = 07, region = new[] {05} }, new FormSubregionTable { Form = 07, Regions = new[] {05} },
new FormSubregionTable { form = 10, region = new[] {04} }, new FormSubregionTable { Form = 10, Regions = new[] {04} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 016, // Brazil CountryID = 016, // Brazil
mainform = 14, // Savanna BaseForm = 14, // Savanna
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 17, region = new[] {03,06} }, new FormSubregionTable { Form = 17, Regions = new[] {03,06} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 010, // Argentina CountryID = 010, // Argentina
mainform = 14, // Savanna BaseForm = 14, // Savanna
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 01, region = new[] {21,24} }, new FormSubregionTable { Form = 01, Regions = new[] {21,24} },
new FormSubregionTable { form = 03, region = new[] {16} }, new FormSubregionTable { Form = 03, Regions = new[] {16} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 020, // Chile CountryID = 020, // Chile
mainform = 08, // Marine BaseForm = 08, // Marine
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 01, region = new[] {12} }, new FormSubregionTable { Form = 01, Regions = new[] {12} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 036, // Mexico CountryID = 036, // Mexico
mainform = 15, // Sun BaseForm = 15, // Sun
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 09, region = new[] {32} }, new FormSubregionTable { Form = 09, Regions = new[] {32} },
new FormSubregionTable { form = 10, region = new[] {04,08,09,12,15,19,20,23,26,27,29} }, new FormSubregionTable { Form = 10, Regions = new[] {04,08,09,12,15,19,20,23,26,27,29} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 052, // Venezuela CountryID = 052, // Venezuela
mainform = 09, // Archipelago BaseForm = 09, // Archipelago
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 17, region = new[] {17} }, new FormSubregionTable { Form = 17, Regions = new[] {17} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 065, // Australia CountryID = 065, // Australia
mainform = 09, // River BaseForm = 09, // River
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 04, region = new[] {07} }, new FormSubregionTable { Form = 04, Regions = new[] {07} },
new FormSubregionTable { form = 15, region = new[] {04} }, new FormSubregionTable { Form = 15, Regions = new[] {04} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 066, // Austria CountryID = 066, // Austria
mainform = 08, // Marine BaseForm = 08, // Marine
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 06, region = new[] {10} }, new FormSubregionTable { Form = 06, Regions = new[] {10} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 073, // Czecg Republic CountryID = 073, // Czecg Republic
mainform = 08, // Marine BaseForm = 08, // Marine
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 03, region = new[] {03} }, new FormSubregionTable { Form = 03, Regions = new[] {03} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 076, // Finland CountryID = 076, // Finland
mainform = 00, // Icy Snow BaseForm = 00, // Icy Snow
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 01, region = new[] {27} }, new FormSubregionTable { Form = 01, Regions = new[] {27} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 077, // France CountryID = 077, // France
mainform = 06, // Meadow BaseForm = 06, // Meadow
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 03, region = new[] {18} }, new FormSubregionTable { Form = 03, Regions = new[] {18} },
new FormSubregionTable { form = 08, region = new[] {04,06,08,19} }, new FormSubregionTable { Form = 08, Regions = new[] {04,06,08,19} },
new FormSubregionTable { form = 16, region = new[] {27} }, new FormSubregionTable { Form = 16, Regions = new[] {27} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 078, // Germany CountryID = 078, // Germany
mainform = 03, // Continental BaseForm = 03, // Continental
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 06, region = new[] {04,13} }, new FormSubregionTable { Form = 06, Regions = new[] {04,13} },
new FormSubregionTable { form = 08, region = new[] {05} }, new FormSubregionTable { Form = 08, Regions = new[] {05} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 078, // Italy CountryID = 078, // Italy
mainform = 08, // Marine BaseForm = 08, // Marine
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 06, region = new[] {04,06} }, new FormSubregionTable { Form = 06, Regions = new[] {04,06} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 085, // Lesotho CountryID = 085, // Lesotho
mainform = 09, // Archipelago ?? BaseForm = 09, // Archipelago ??
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 12, region = new[] {04} }, new FormSubregionTable { Form = 12, Regions = new[] {04} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 096, // Norway CountryID = 096, // Norway
mainform = 03, // Continental ?? BaseForm = 03, // Continental ??
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 00, region = new[] {11} }, new FormSubregionTable { Form = 00, Regions = new[] {11} },
new FormSubregionTable { form = 01, region = new[] {12,15,16,17,20,22} }, new FormSubregionTable { Form = 01, Regions = new[] {12,15,16,17,20,22} },
new FormSubregionTable { form = 02, region = new[] {13,14} }, new FormSubregionTable { Form = 02, Regions = new[] {13,14} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 097, // Poland CountryID = 097, // Poland
mainform = 03, // Continental BaseForm = 03, // Continental
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 04, region = new[] {11} }, new FormSubregionTable { Form = 04, Regions = new[] {11} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 100, // Russia CountryID = 100, // Russia
mainform = 01, // Polar BaseForm = 01, // Polar
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 00, region = new[] {14,22,34,38,40,52,66,88} }, new FormSubregionTable { Form = 00, Regions = new[] {14,22,34,38,40,52,66,88} },
new FormSubregionTable { form = 03, region = new[] {29,46,51,69} }, new FormSubregionTable { Form = 03, Regions = new[] {29,46,51,69} },
new FormSubregionTable { form = 10, region = new[] {20,24,25,28,33,71,73} }, new FormSubregionTable { Form = 10, Regions = new[] {20,24,25,28,33,71,73} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 104, //South Africa CountryID = 104, //South Africa
mainform = 12, // River ?? BaseForm = 12, // River ??
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 03, region = new[] {03,05} }, new FormSubregionTable { Form = 03, Regions = new[] {03,05} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 105, // Spain CountryID = 105, // Spain
mainform = 08, // Marine BaseForm = 08, // Marine
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 06, region = new[] {11} }, new FormSubregionTable { Form = 06, Regions = new[] {11} },
new FormSubregionTable { form = 12, region = new[] {07} }, new FormSubregionTable { Form = 12, Regions = new[] {07} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 107, // Sweden CountryID = 107, // Sweden
mainform = 03, // Continental BaseForm = 03, // Continental
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 00, region = new[] {11,21} }, new FormSubregionTable { Form = 00, Regions = new[] {11,21} },
new FormSubregionTable { form = 01, region = new[] {09,13} }, new FormSubregionTable { Form = 01, Regions = new[] {09,13} },
} }
}, },
new CountryTable{ new CountryTable{
countryID = 169, // India CountryID = 169, // India
mainform = 13, // Monsoon ?? BaseForm = 13, // Monsoon ??
otherforms = new[] SubRegionForms = new[]
{ {
new FormSubregionTable { form = 17, region = new[] {12} }, new FormSubregionTable { Form = 17, Regions = new[] {12} },
} }
}, },
}; };
@ -259,14 +259,14 @@ namespace PKHeX.Core
if (!VivillonCountryTable[form].Contains(country)) if (!VivillonCountryTable[form].Contains(country))
return false; // Country mismatch return false; // Country mismatch
var ct = Array.Find(RegionFormTable, t => t.countryID == country); var ct = Array.Find(RegionFormTable, t => t.CountryID == country);
if (ct.otherforms == null) // empty struct = no forms referenced if (ct.SubRegionForms == null) // empty struct = no forms referenced
return true; // No subregion table return true; // No subregion table
if (ct.mainform == form) if (ct.BaseForm == form)
return !ct.otherforms.Any(e => e.region.Contains(region)); //true if Mainform not in other specific region return !ct.SubRegionForms.Any(e => e.Regions.Contains(region)); //true if Mainform not in other specific region
return ct.otherforms.Any(e => e.form == form && e.region.Contains(region)); return ct.SubRegionForms.Any(e => e.Form == form && e.Regions.Contains(region));
} }
/// <summary> /// <summary>
@ -276,17 +276,17 @@ namespace PKHeX.Core
/// <param name="region">Console Region ID</param> /// <param name="region">Console Region ID</param>
public static int GetVivillonPattern(int country, int region) public static int GetVivillonPattern(int country, int region)
{ {
var ct = Array.Find(RegionFormTable, t => t.countryID == country); var ct = Array.Find(RegionFormTable, t => t.CountryID == country);
if (ct.otherforms == null) // empty struct = no forms referenced if (ct.SubRegionForms == null) // empty struct = no forms referenced
return ct.mainform; // No subregion table return ct.BaseForm; // No subregion table
foreach (var sub in ct.otherforms) foreach (var sub in ct.SubRegionForms)
{ {
if (sub.region.Contains(region)) if (sub.Regions.Contains(region))
return sub.form; return sub.Form;
} }
return ct.mainform; return ct.BaseForm;
} }
/// <summary> /// <summary>

View file

@ -1,4 +1,4 @@
using System.Linq; using System.Collections.Generic;
namespace PKHeX.Core namespace PKHeX.Core
{ {
@ -10,7 +10,7 @@ namespace PKHeX.Core
public InventoryItem Clone() => (InventoryItem) MemberwiseClone(); public InventoryItem Clone() => (InventoryItem) MemberwiseClone();
// Check Pouch Compatibility // Check Pouch Compatibility
public bool Valid(ushort[] LegalItems, bool HaX, int MaxItemID) public bool Valid(IList<ushort> LegalItems, bool HaX, int MaxItemID)
{ {
if (Index == 0) if (Index == 0)
return true; return true;