From b109af18e7b204622bfc1f9d63dda8742d3c70a9 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 21 Mar 2016 21:31:06 -0700 Subject: [PATCH] Add History check, Expand ball check --- Legality/Analysis.cs | 5 ++-- Legality/Checks.cs | 61 +++++++++++++++++++++++++++++++++++++++++++- Legality/Core.cs | 4 +++ 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/Legality/Analysis.cs b/Legality/Analysis.cs index a529ac223..dd209d022 100644 --- a/Legality/Analysis.cs +++ b/Legality/Analysis.cs @@ -8,7 +8,7 @@ namespace PKHeX private readonly PK6 pk6; private WC6 MatchedWC6; private object EncounterMatch; - private LegalityCheck ECPID, Nickname, IDs, IVs, EVs, Encounter, Level, Ribbons, Ability, Ball; + private LegalityCheck ECPID, Nickname, IDs, IVs, EVs, Encounter, Level, Ribbons, Ability, Ball, HandlerMemories; public bool Valid = true; public bool SecondaryChecked; @@ -50,6 +50,7 @@ namespace PKHeX Ribbons = verifyRibbons(); Ability = verifyAbility(); Ball = verifyBall(); + HandlerMemories = verifyHandlerMemories(); SecondaryChecked = true; } private string getLegalityReport() @@ -57,7 +58,7 @@ namespace PKHeX if (!pk6.Gen6) return "Analysis only available for Pokémon that originate from X/Y & OR/AS."; - var chks = new[] { ECPID, Nickname, IVs, EVs, IDs, Encounter, Level, Ribbons, Ability, Ball }; + var chks = new[] { ECPID, Nickname, IVs, EVs, IDs, Encounter, Level, Ribbons, Ability, Ball, HandlerMemories }; string r = ""; for (int i = 0; i < 4; i++) diff --git a/Legality/Checks.cs b/Legality/Checks.cs index 87a2dd455..fec6d1d78 100644 --- a/Legality/Checks.cs +++ b/Legality/Checks.cs @@ -137,6 +137,7 @@ namespace PKHeX } private LegalityCheck verifyEncounter() { + EncounterMatch = null; // Reset object if (!pk6.Gen6) return new LegalityCheck {Judgement = Severity.NotImplemented}; @@ -223,6 +224,8 @@ namespace PKHeX } private LegalityCheck verifyLevel() { + if (MatchedWC6 != null && MatchedWC6.Level != pk6.Met_Level) + return new LegalityCheck(Severity.Invalid, "Met Level does not match Wonder Card level."); return pk6.CurrentLevel < pk6.Met_Level ? new LegalityCheck(Severity.Invalid, "Current level is below met level.") : new LegalityCheck(Severity.Valid, "Current level is not below met level."); @@ -307,7 +310,6 @@ namespace PKHeX ? new LegalityCheck(Severity.Invalid, "Ability does not match ability number.") : new LegalityCheck(Severity.Valid, "Ability matches ability number."); } - private LegalityCheck verifyBall() { if (MatchedWC6 != null) @@ -329,8 +331,20 @@ namespace PKHeX // Feel free to improve, there's a lot of very minor things to check for some species. } + if (pk6.WasLink) + { + if (pk6.Species == 251) + return pk6.Ball != 11 // Luxury + ? new LegalityCheck(Severity.Invalid, "Incorrect ball on Link gift.") + : new LegalityCheck(Severity.Valid, "Correct ball on Link gift."); + + return pk6.Ball != 4 // Pokeball + ? new LegalityCheck(Severity.Invalid, "Incorrect ball on Link gift.") + : new LegalityCheck(Severity.Valid, "Correct ball on Link gift."); + } if (EncounterMatch == null) { + // Egg and Event already checked, if not a recognized Trade // Wild Encounter return !Legal.WildPokeballs.Contains(pk6.Ball) ? new LegalityCheck(Severity.Invalid, "Unobtainable ball on captured encounter.") @@ -343,6 +357,51 @@ namespace PKHeX return new LegalityCheck(Severity.Indeterminate, "Unable to verify Ball"); } + private LegalityCheck verifyHandlerMemories() + { + if (MatchedWC6?.OT.Length > 0) // Has Event OT -- null propagation yields false if MatchedWC6=null + { + if (pk6.OT_Friendship != PKX.getBaseFriendship(pk6.Species)) + return new LegalityCheck(Severity.Invalid, "Event OT Friendship does not match base friendship."); + if (pk6.OT_Affection != 0) + return new LegalityCheck(Severity.Invalid, "Event OT Affection should be zero."); + if (pk6.CurrentHandler != 1) + return new LegalityCheck(Severity.Invalid, "Current handler should not be Event OT."); + } + if (!pk6.WasEvent && (pk6.HT_Name.Length == 0 || pk6.Geo1_Country == 0)) // Is not Traded + { + if (pk6.HT_Name.Length != 0) + return new LegalityCheck(Severity.Invalid, "GeoLocation -- HT Name present but has no previous Country."); + if (pk6.Geo1_Country != 0) + return new LegalityCheck(Severity.Invalid, "GeoLocation -- Previous country of residence but no Handling Trainer."); + if (pk6.HT_Memory != 0) + return new LegalityCheck(Severity.Invalid, "Memory -- Handling Trainer memory present but no Handling Trainer."); + if (pk6.CurrentHandler != 0) // Badly edited; PKHeX doesn't trip this. + return new LegalityCheck(Severity.Invalid, "Untraded -- Current handler should not be the Handling Trainer."); + if (pk6.HT_Friendship != 0) + return new LegalityCheck(Severity.Invalid, "Untraded -- Handling Trainer Friendship should be zero."); + if (pk6.HT_Affection != 0) + return new LegalityCheck(Severity.Invalid, "Untraded -- Handling Trainer Affection should be zero."); + + // We know it is untraded (HT is empty), if it must be trade evolved flag it. + if (Legal.getHasTradeEvolved(pk6)) + { + if (pk6.Species != 350) // Milotic + return new LegalityCheck(Severity.Invalid, "Untraded -- requires a trade evolution."); + if (pk6.CNT_Beauty < 170) // Beauty Contest Stat Requirement + return new LegalityCheck(Severity.Invalid, "Untraded -- Beauty is not high enough for Levelup Evolution."); + } + } + else // Is Traded + { + if (pk6.HT_Memory == 0) + return new LegalityCheck(Severity.Invalid, "Memory -- missing Handling Trainer Memory."); + } + + // Unimplemented: Ingame Trade Memories + + return new LegalityCheck(Severity.Valid, "History is valid."); + } private LegalityCheck[] verifyMoves() { int[] Moves = pk6.Moves; diff --git a/Legality/Core.cs b/Legality/Core.cs index a1e0f8627..dc1eeb5e6 100644 --- a/Legality/Core.cs +++ b/Legality/Core.cs @@ -220,6 +220,10 @@ namespace PKHeX { return getValidPreEvolutions(pk6).Count() > 1; } + internal static bool getHasTradeEvolved(PK6 pk6) + { + return Evolves[pk6.Species].Evos.Any(evo => evo.Level == 1); // 1: Trade, 0: Item, >=2: Levelup + } internal static bool getIsFossil(PK6 pk6) { if (pk6.Met_Level != 20)