From 2c45e499f7cfb9ccd2114f61ade94a7b0eae9591 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 13 Nov 2016 09:37:28 -0800 Subject: [PATCH] Add magearna Add fallthrough for events that do not match (fateful/event location) so that magearna can be caught in the static encounter check Add fateful/wishing ribbon checks for Static Encounters Add Gen7 WC6DB beginnings --- PKHeX/Legality/Checks.cs | 43 +++++++++++++++----- PKHeX/Legality/Core.cs | 12 +++--- PKHeX/Legality/Structures/EncounterStatic.cs | 3 ++ PKHeX/Legality/Tables6.cs | 2 +- PKHeX/Legality/Tables7.cs | 9 +++- PKHeX/MainWindow/Main.cs | 2 +- PKHeX/Subforms/SAV_MysteryGiftDB.cs | 3 +- 7 files changed, 53 insertions(+), 21 deletions(-) diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index d06c1ed68..b8bdd815b 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -348,12 +348,12 @@ private CheckResult verifyEncounter() ? new CheckResult(Severity.Invalid, "Invalid Link Gift: should not be Fateful Encounter.", CheckIdentifier.Encounter) : new CheckResult(Severity.Valid, "Valid Link gift.", CheckIdentifier.Encounter); } + if (pkm.WasEvent || pkm.WasEventEgg) { MysteryGift MatchedGift = EncounterMatch as MysteryGift; - return MatchedGift == null - ? new CheckResult(Severity.Invalid, "Unable to match to a Mystery Gift in the database.", CheckIdentifier.Encounter) - : new CheckResult(Severity.Valid, $"Matches #{MatchedGift.CardID.ToString("0000")} ({MatchedGift.CardTitle})", CheckIdentifier.Encounter); + if (MatchedGift != null) + return new CheckResult(Severity.Valid, $"Matches #{MatchedGift.CardID.ToString("0000")} ({MatchedGift.CardTitle})", CheckIdentifier.Encounter); } EncounterMatch = Legal.getValidStaticEncounter(pkm); @@ -463,9 +463,10 @@ private CheckResult verifyEncounter() } EncounterMatch = Legal.getValidIngameTrade(pkm); if (EncounterMatch != null) - { return new CheckResult(Severity.Valid, "Valid ingame trade.", CheckIdentifier.Encounter); - } + + if (pkm.WasEvent || pkm.WasEventEgg) + return new CheckResult(Severity.Invalid, "Unable to match to a Mystery Gift in the database.", CheckIdentifier.Encounter); return new CheckResult(Severity.Invalid, "Not a valid encounter.", CheckIdentifier.Encounter); } private void verifyLevel() @@ -578,6 +579,22 @@ private void verifyRibbons() if (classic ^ ((EncounterLink)EncounterMatch).Classic) (classic ? invalidRibbons : missingRibbons).Add(EventRibName[4]); } + else if (EncounterType == typeof(EncounterStatic)) + { + // No Event Ribbons except Wishing (which is only for Magearna) + for (int i = 0; i < EventRib.Length; i++) + { + if (i == 10) + continue; + + if (ReflectUtil.getBooleanState(pkm, EventRib[i]) == true) + invalidRibbons.Add(EventRibName[i]); + } + + bool wishing = ReflectUtil.getBooleanState(pkm, EventRib[10]) == true; + if (wishing ^ ((EncounterStatic)EncounterMatch).RibbonWishing) + (wishing ? invalidRibbons : missingRibbons).Add(EventRibName[10]); + } else // No ribbons { for (int i = 0; i < EventRib.Length; i++) @@ -1351,13 +1368,17 @@ private void verifyMisc() if (Encounter.Valid && EncounterIsMysteryGift ^ pkm.FatefulEncounter) { - if (pkm.AO && EncounterType == typeof(EncounterStatic) && pkm.Species == 386) // Deoxys Matched @ Sky Pillar - { AddLine(Severity.Valid, "Sky Pillar Deoxys matched Fateful Encounter.", CheckIdentifier.Fateful); return; } - else - { AddLine(Severity.Invalid, "Fateful Encounter should " + (pkm.FatefulEncounter ? "not " : "") + "be checked.", CheckIdentifier.Fateful); return; } + if (EncounterType == typeof (EncounterStatic)) + { + var enc = EncounterMatch as EncounterStatic; + if (enc.Fateful) + AddLine(Severity.Valid, "Special ingame Fateful Encounter.", CheckIdentifier.Fateful); + return; + } + AddLine(Severity.Invalid, "Fateful Encounter should " + (pkm.FatefulEncounter ? "not " : "") + "be checked.", CheckIdentifier.Fateful); + return; } - else - { AddLine(Severity.Valid, "Fateful Encounter is Valid.", CheckIdentifier.Fateful); return; } + AddLine(Severity.Valid, "Fateful Encounter is Valid.", CheckIdentifier.Fateful); } private CheckResult[] verifyMoves() { diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index b96cf6cd6..58c79843b 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -6,7 +6,7 @@ namespace PKHeX public static partial class Legal { // Event Database(s) - internal static WC6[] WC6DB; + internal static MysteryGift[] MGDB_G6, MGDB_G7 = new MysteryGift[0]; // Gen 6 private static readonly EggMoves[] EggMovesXY = EggMoves6.getArray(Data.unpackMini(Properties.Resources.eggmove_xy, "xy")); @@ -349,17 +349,19 @@ internal static IEnumerable getValidGifts(PKM pkm) switch (pkm.GenNumber) { case 6: - return getMatchingWC6(pkm); + return getMatchingWC6(pkm, MGDB_G6); default: - return null; + return getMatchingWC6(pkm, MGDB_G7); } } - private static IEnumerable getMatchingWC6(PKM pkm) + private static IEnumerable getMatchingWC6(PKM pkm, IEnumerable DB) { List validWC6 = new List(); + if (DB == null) + return validWC6; var vs = getValidPreEvolutions(pkm).ToArray(); - foreach (WC6 wc in WC6DB.Where(wc => vs.Any(dl => dl.Species == wc.Species))) + foreach (WC6 wc in DB.OfType().Where(wc => vs.Any(dl => dl.Species == wc.Species))) { if (pkm.Egg_Location == 0) // Not Egg { diff --git a/PKHeX/Legality/Structures/EncounterStatic.cs b/PKHeX/Legality/Structures/EncounterStatic.cs index 63ac274e0..768a29242 100644 --- a/PKHeX/Legality/Structures/EncounterStatic.cs +++ b/PKHeX/Legality/Structures/EncounterStatic.cs @@ -20,5 +20,8 @@ public class EncounterStatic public bool IV3; public int[] Contest = { 0, 0, 0, 0, 0, 0 }; public int HeldItem { get; set; } + + public bool Fateful = false; + public bool RibbonWishing = false; } } diff --git a/PKHeX/Legality/Tables6.cs b/PKHeX/Legality/Tables6.cs index 6ddc3cce8..b8c6ed0af 100644 --- a/PKHeX/Legality/Tables6.cs +++ b/PKHeX/Legality/Tables6.cs @@ -445,7 +445,7 @@ public static partial class Legal new EncounterStatic { Species = 382, Level = 45, Location = 296, Version = GameVersion.AS, Shiny = false, IV3 = true }, // Kyogre new EncounterStatic { Species = 383, Level = 45, Location = 296, Version = GameVersion.OR, Shiny = false, IV3 = true }, // Groudon new EncounterStatic { Species = 384, Level = 70, Location = 316, Shiny = false, IV3 = true }, // Rayquaza - new EncounterStatic { Species = 386, Level = 80, Location = 316, Shiny = false, IV3 = true }, // Deoxys + new EncounterStatic { Species = 386, Level = 80, Location = 316, Shiny = false, IV3 = true, Fateful = true }, // Deoxys new EncounterStatic { Species = 377, Level = 40, Location = 278, IV3 = true }, // Regirock new EncounterStatic { Species = 378, Level = 40, Location = 306, IV3 = true }, // Regice diff --git a/PKHeX/Legality/Tables7.cs b/PKHeX/Legality/Tables7.cs index 678ea9819..3361c3380 100644 --- a/PKHeX/Legality/Tables7.cs +++ b/PKHeX/Legality/Tables7.cs @@ -102,7 +102,7 @@ public static partial class Legal #region Encounters private static readonly EncounterStatic[] Encounter_SM = // @ a\1\5\5 { - // Gfits - 0.bin + // Gifts - 0.bin new EncounterStatic { Gift = true, Species = 722, Level = 5, Location = 24, }, // Rowlet new EncounterStatic { Gift = true, Species = 725, Level = 5, Location = 24, }, // Litten new EncounterStatic { Gift = true, Species = 728, Level = 5, Location = 24, }, // Popplio @@ -120,11 +120,16 @@ public static partial class Legal new EncounterStatic { Gift = true, Species = 133, Level = 1, EggLocation = 60002, }, // Eevee new EncounterStatic { Gift = true, Species = 137, Level = 30, Location = -1, }, // Porygon new EncounterStatic { Gift = true, Species = 772, Level = 40, Location = 188, IV3 = true, }, // Type: Null - new EncounterStatic { Gift = true, Species = 801, Level = 50, Location = 40001, Shiny = false, IV3 = true, }, // Magearna (Bottle Cap) 00 FF new EncounterStatic { Gift = true, Species = 789, Level = 5, Location = 142, Shiny = false, IV3 = true, Version = GameVersion.SN}, // Cosmog 00 FF new EncounterStatic { Gift = true, Species = 789, Level = 5, Location = 144, Shiny = false, IV3 = true, Version = GameVersion.MN}, // Cosmog 00 FF new EncounterStatic { Gift = true, Species = 142, Level = 40, Location = -1, }, // Aerodactyl + new EncounterStatic // Magearna (Bottle Cap) 00 FF + { + Gift = true, Species = 801, Level = 50, Location = 40001, Shiny = false, IV3 = true, + Fateful = true, RibbonWishing = true, Relearn = new [] {705, 430, 381, 270}, Ball = 0x10, // Cherish + }, + // Static Encounters - 1.bin new EncounterStatic { Species = 731, Form = 0, Level = 03, Relearn = new[]{000, 000, 000, 000}, Shiny = false, Ability = 1, Location = -1, }, // Pikipek // new EncounterStatic { Species = 793, Form = 0, Level = 27, Relearn = new[]{000, 000, 000, 000}, Shiny = false, Ability = 1, IVs = new[] {31, 01, 31, 01, 31, 31}, Location = -1, IV3 = true, }, // Nihilego diff --git a/PKHeX/MainWindow/Main.cs b/PKHeX/MainWindow/Main.cs index e8f5e9597..285578e0e 100644 --- a/PKHeX/MainWindow/Main.cs +++ b/PKHeX/MainWindow/Main.cs @@ -1223,7 +1223,7 @@ private static void refreshWC6DB() where new[] {".wc6full", ".wc6"}.Contains(fi.Extension) && new[] {WC6.Size, WC6.SizeFull}.Contains((int)fi.Length) select new WC6(File.ReadAllBytes(file))); - Legal.WC6DB = wc6db.Distinct().ToArray(); + Legal.MGDB_G6 = wc6db.Distinct().ToArray(); } // Language Translation diff --git a/PKHeX/Subforms/SAV_MysteryGiftDB.cs b/PKHeX/Subforms/SAV_MysteryGiftDB.cs index 9342b6061..7e490c2a6 100644 --- a/PKHeX/Subforms/SAV_MysteryGiftDB.cs +++ b/PKHeX/Subforms/SAV_MysteryGiftDB.cs @@ -74,7 +74,8 @@ public SAV_MysteryGiftDB(Main f1) // Load Data RawDB = new List(); - RawDB.AddRange(Legal.WC6DB); + RawDB.AddRange(Legal.MGDB_G6); + RawDB.AddRange(Legal.MGDB_G7); if (Directory.Exists(DatabasePath)) foreach (string file in Directory.GetFiles(DatabasePath, "*", SearchOption.AllDirectories))