From 66e0613d822770378fefb5aefce32c66de1fa868 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 30 Aug 2022 15:00:45 -0700 Subject: [PATCH] Minor clean --- .../Editing/Applicators/MoveSetApplicator.cs | 10 +---- PKHeX.Core/Editing/Bulk/BatchEditor.cs | 4 +- PKHeX.Core/Editing/PKM/EntityTemplates.cs | 2 +- PKHeX.Core/Editing/Showdown/ShowdownSet.cs | 4 +- PKHeX.Core/Legality/Breeding.cs | 2 +- .../Legality/Evolutions/EvolutionLegality.cs | 1 - PKHeX.Core/Legality/Moves/MoveEgg.cs | 2 +- PKHeX.Core/Legality/RNG/Frame/SeedInfo.cs | 2 +- .../Restrictions/Memories/MemoryContext8.cs | 2 +- PKHeX.Core/Legality/Tables/Tables.cs | 25 +++++++++---- PKHeX.Core/Legality/Tables/Tables3.cs | 1 + PKHeX.Core/Legality/Tables/Tables4.cs | 9 ++++- PKHeX.Core/Legality/Tables/Tables8a.cs | 1 - PKHeX.Core/MysteryGifts/WR7.cs | 2 +- PKHeX.Core/PKM/PB7.cs | 2 +- PKHeX.Core/PKM/PK3.cs | 2 +- PKHeX.Core/PKM/PK6.cs | 2 +- PKHeX.Core/PKM/PK7.cs | 2 +- PKHeX.Core/PKM/Util/EntityPID.cs | 2 +- PKHeX.Core/PersonalInfo/PersonalInfo.cs | 2 +- PKHeX.Core/Saves/SAV1.cs | 2 +- .../Saves/Substructures/PokeDex/Zukan5.cs | 2 +- .../Saves/Substructures/PokeDex/Zukan8.cs | 2 +- PKHeX.WinForms/MainWindow/Main.cs | 2 +- .../Subforms/PKM Editors/BatchEditor.cs | 2 +- PKHeX.WinForms/Subforms/SAV_Encounters.cs | 6 +-- .../Save Editors/Gen6/SAV_PokedexORAS.cs | 2 +- .../Save Editors/Gen7/SAV_PokedexGG.cs | 2 +- .../Save Editors/Gen7/SAV_PokedexSM.cs | 8 ++-- .../Subforms/Save Editors/SAV_Wondercard.cs | 37 ++++++++++++------- Tests/PKHeX.Core.Tests/Legality/BreedTests.cs | 2 +- 31 files changed, 82 insertions(+), 64 deletions(-) diff --git a/PKHeX.Core/Editing/Applicators/MoveSetApplicator.cs b/PKHeX.Core/Editing/Applicators/MoveSetApplicator.cs index 9e10b22af..a1229b532 100644 --- a/PKHeX.Core/Editing/Applicators/MoveSetApplicator.cs +++ b/PKHeX.Core/Editing/Applicators/MoveSetApplicator.cs @@ -51,19 +51,11 @@ public static class MoveSetApplicator return m; } - /// - /// Fetches based on the provided . - /// - /// Pokémon to modify. - /// Encounter the relearn moves should be suggested for. If not provided, will try to detect it via legality analysis. - /// best suited for the current data. - public static IReadOnlyList GetSuggestedRelearnMoves(this PKM pk, IEncounterTemplate? enc = null) => GetSuggestedRelearnMoves(new LegalityAnalysis(pk), enc); - /// /// Fetches based on the provided . /// /// which contains parsed information pertaining to legality. - /// Encounter the relearn moves should be suggested for. If not provided, will try to detect it via legality analysis. + /// Encounter the relearn moves should be suggested for. If not provided, will use the original encounter from the analysis. /// best suited for the current data. public static IReadOnlyList GetSuggestedRelearnMoves(this LegalityAnalysis legal, IEncounterTemplate? enc = null) { diff --git a/PKHeX.Core/Editing/Bulk/BatchEditor.cs b/PKHeX.Core/Editing/Bulk/BatchEditor.cs index 668166541..be0453bba 100644 --- a/PKHeX.Core/Editing/Bulk/BatchEditor.cs +++ b/PKHeX.Core/Editing/Bulk/BatchEditor.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -24,7 +24,7 @@ public sealed class BatchEditor /// Result of the attempted modification. public bool Process(PKM pk, IEnumerable filters, IEnumerable modifications) { - if (pk.Species <= 0) + if (pk.Species == 0) return false; if (!pk.Valid) { diff --git a/PKHeX.Core/Editing/PKM/EntityTemplates.cs b/PKHeX.Core/Editing/PKM/EntityTemplates.cs index 4b9f3eb34..a70135d42 100644 --- a/PKHeX.Core/Editing/PKM/EntityTemplates.cs +++ b/PKHeX.Core/Editing/PKM/EntityTemplates.cs @@ -62,7 +62,7 @@ public static class EntityTemplates private static ushort GetTemplateSpecies(PKM pk, ITrainerInfo tr) { ushort species = tr is IGameValueLimit s ? s.MaxSpeciesID : ((GameVersion)pk.Version).GetMaxSpeciesID(); - if (species <= 0) + if (species == 0) species = pk.MaxSpeciesID; return species; } diff --git a/PKHeX.Core/Editing/Showdown/ShowdownSet.cs b/PKHeX.Core/Editing/Showdown/ShowdownSet.cs index 9d812467e..cda1b6948 100644 --- a/PKHeX.Core/Editing/Showdown/ShowdownSet.cs +++ b/PKHeX.Core/Editing/Showdown/ShowdownSet.cs @@ -262,7 +262,7 @@ public sealed class ShowdownSet : IBattleTemplate private string GetText(GameStrings? strings = null) { - if (Species is <= 0 or > MAX_SPECIES) + if (Species is 0 or > MAX_SPECIES) return string.Empty; if (strings != null) @@ -402,7 +402,7 @@ public sealed class ShowdownSet : IBattleTemplate /// New ShowdownSet object representing the input public ShowdownSet(PKM pk) { - if (pk.Species <= 0) + if (pk.Species == 0) return; Context = pk.Context; diff --git a/PKHeX.Core/Legality/Breeding.cs b/PKHeX.Core/Legality/Breeding.cs index 381719841..cd4e814dd 100644 --- a/PKHeX.Core/Legality/Breeding.cs +++ b/PKHeX.Core/Legality/Breeding.cs @@ -118,7 +118,7 @@ public static class Breeding } /// - /// Some species can have forms that cannot exist as egg (event/special forms). Same idea as + /// Some species can have forms that cannot exist as egg (event/special forms). Same idea as /// /// True if can be bred. private static bool IsBreedableForm(ushort species, byte form) => species switch diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionLegality.cs b/PKHeX.Core/Legality/Evolutions/EvolutionLegality.cs index ddbb57197..e98904860 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionLegality.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionLegality.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; namespace PKHeX.Core; diff --git a/PKHeX.Core/Legality/Moves/MoveEgg.cs b/PKHeX.Core/Legality/Moves/MoveEgg.cs index 080f732f6..faab180f5 100644 --- a/PKHeX.Core/Legality/Moves/MoveEgg.cs +++ b/PKHeX.Core/Legality/Moves/MoveEgg.cs @@ -46,7 +46,7 @@ public static class MoveEgg return Array.Empty(); var entry = table[species]; - if (form <= 0 || entry.FormTableIndex <= species) + if (form == 0 || species >= entry.FormTableIndex) return entry.Moves; // Sanity check form in the event it is out of range. diff --git a/PKHeX.Core/Legality/RNG/Frame/SeedInfo.cs b/PKHeX.Core/Legality/RNG/Frame/SeedInfo.cs index 714ec8777..088a33578 100644 --- a/PKHeX.Core/Legality/RNG/Frame/SeedInfo.cs +++ b/PKHeX.Core/Legality/RNG/Frame/SeedInfo.cs @@ -59,7 +59,7 @@ public readonly record struct SeedInfo(uint Seed, bool Charm3 = false) foreach (var seed in seeds) yield return new SeedInfo(seed); } - + /// /// Yields an enumerable list of seeds until another valid PID breaks the chain. /// diff --git a/PKHeX.Core/Legality/Restrictions/Memories/MemoryContext8.cs b/PKHeX.Core/Legality/Restrictions/Memories/MemoryContext8.cs index f9bf09ed8..9d0948f73 100644 --- a/PKHeX.Core/Legality/Restrictions/Memories/MemoryContext8.cs +++ b/PKHeX.Core/Legality/Restrictions/Memories/MemoryContext8.cs @@ -149,7 +149,7 @@ public sealed partial class MemoryContext8 : MemoryContext { if (memory >= MemoryFeelings.Length) return false; - if (feeling <= 0) + if (feeling == 0) return false; // Different from Gen6; this +1 is to match them treating 0 as empty return (MemoryFeelings[memory] & (1 << --feeling)) != 0; } diff --git a/PKHeX.Core/Legality/Tables/Tables.cs b/PKHeX.Core/Legality/Tables/Tables.cs index f6b4ae3e5..502d204be 100644 --- a/PKHeX.Core/Legality/Tables/Tables.cs +++ b/PKHeX.Core/Legality/Tables/Tables.cs @@ -91,19 +91,30 @@ public static partial class Legal (int)Meowstic, // (M/F) form specific }; - private static bool[] GetPermitList(int max, ReadOnlySpan held) + /// + /// Gets a permit list with the permitted indexes, then un-flags the indexes that are not permitted. + /// + /// Maximum index expected to allow + /// Allowed indexes + private static bool[] GetPermitList(int max, ReadOnlySpan allowed) { var result = new bool[max + 1]; - foreach (var item in held) - result[item] = true; + foreach (var index in allowed) + result[index] = true; return result; } - private static bool[] GetPermitList(int max, ReadOnlySpan held, ReadOnlySpan unreleased) + /// + /// Gets a permit list with the permitted indexes, then un-flags the indexes that are not permitted. + /// + /// Maximum index expected to allow + /// Allowed indexes (may have some disallowed) + /// Disallowed indexes + private static bool[] GetPermitList(int max, ReadOnlySpan allowed, ReadOnlySpan disallow) { - var result = GetPermitList(max, held); - foreach (var u in unreleased) - result[u] = false; + var result = GetPermitList(max, allowed); + foreach (var index in disallow) + result[index] = false; return result; } } diff --git a/PKHeX.Core/Legality/Tables/Tables3.cs b/PKHeX.Core/Legality/Tables/Tables3.cs index 489c62e1d..6b72c29ad 100644 --- a/PKHeX.Core/Legality/Tables/Tables3.cs +++ b/PKHeX.Core/Legality/Tables/Tables3.cs @@ -97,6 +97,7 @@ public static partial class Legal 060, 061, 062, 063, 065, 066, 067, 068, 069, 070 , 072, 073, 074 , 076 , 078, 079, 080, 081, 082, 083, 085, 086, 087, }; + // 155 - 158 Sevii Isle 6-9 Unused // 171 - 173 Sevii Isle 22-24 Unused internal static readonly HashSet ValidMet_FRLG = new() diff --git a/PKHeX.Core/Legality/Tables/Tables4.cs b/PKHeX.Core/Legality/Tables/Tables4.cs index f70065b9a..0f3daa1a4 100644 --- a/PKHeX.Core/Legality/Tables/Tables4.cs +++ b/PKHeX.Core/Legality/Tables/Tables4.cs @@ -138,13 +138,18 @@ public static partial class Legal internal static int GetTransfer45MetLocation(PKM pk) { + // Everything except for crown beasts and Celebi get the default transfer location. + // Crown beasts and Celebi are 100% identifiable by the species ID and fateful encounter, originating from Gen4. if (!pk.Gen4 || !pk.FatefulEncounter) return Locations.Transfer4; // Pokétransfer return pk.Species switch { - 243 or 244 or 245 => Locations.Transfer4_CrownUnused, // Beast - 251 => Locations.Transfer4_CelebiUnused, // Celebi + // Crown Beast + (int)Species.Raikou or (int)Species.Entei or (int)Species.Suicune => Locations.Transfer4_CrownUnused, + // Celebi + (int)Species.Celebi => Locations.Transfer4_CelebiUnused, + // Default _ => Locations.Transfer4, }; } diff --git a/PKHeX.Core/Legality/Tables/Tables8a.cs b/PKHeX.Core/Legality/Tables/Tables8a.cs index 4e2c5aa61..6a017a5be 100644 --- a/PKHeX.Core/Legality/Tables/Tables8a.cs +++ b/PKHeX.Core/Legality/Tables/Tables8a.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; namespace PKHeX.Core; diff --git a/PKHeX.Core/MysteryGifts/WR7.cs b/PKHeX.Core/MysteryGifts/WR7.cs index fcddcd418..33796957a 100644 --- a/PKHeX.Core/MysteryGifts/WR7.cs +++ b/PKHeX.Core/MysteryGifts/WR7.cs @@ -57,7 +57,7 @@ public sealed class WR7 : DataMysteryGift // unknown: region from 0x10 to 0xFF ? - public override ushort Species + public override ushort Species { get => ReadUInt16LittleEndian(Data.AsSpan(0x10C)); set => WriteUInt16LittleEndian(Data.AsSpan(0x10C), value); diff --git a/PKHeX.Core/PKM/PB7.cs b/PKHeX.Core/PKM/PB7.cs index 590b5a141..cb3e9ab50 100644 --- a/PKHeX.Core/PKM/PB7.cs +++ b/PKHeX.Core/PKM/PB7.cs @@ -62,7 +62,7 @@ public sealed class PB7 : G6PKM, IHyperTrain, IAwakened, IScaledSizeValue, IComb set => WriteUInt16LittleEndian(Data.AsSpan(0x06), value); } - public override ushort Species + public override ushort Species { get => ReadUInt16LittleEndian(Data.AsSpan(0x08)); set => WriteUInt16LittleEndian(Data.AsSpan(0x08), value); diff --git a/PKHeX.Core/PKM/PK3.cs b/PKHeX.Core/PKM/PK3.cs index b7348f932..178d6c607 100644 --- a/PKHeX.Core/PKM/PK3.cs +++ b/PKHeX.Core/PKM/PK3.cs @@ -71,7 +71,7 @@ public sealed class PK3 : G3PKM, ISanityChecksum #region Block A public override ushort SpeciesID3 { get => ReadUInt16LittleEndian(Data.AsSpan(0x20)); set => WriteUInt16LittleEndian(Data.AsSpan(0x20), value); } // raw access - public override ushort Species + public override ushort Species { get => SpeciesConverter.GetG4Species(SpeciesID3); set diff --git a/PKHeX.Core/PKM/PK6.cs b/PKHeX.Core/PKM/PK6.cs index e803affe8..8c0af0a16 100644 --- a/PKHeX.Core/PKM/PK6.cs +++ b/PKHeX.Core/PKM/PK6.cs @@ -50,7 +50,7 @@ public sealed class PK6 : G6PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetC set => WriteUInt16LittleEndian(Data.AsSpan(0x06), value); } - public override ushort Species + public override ushort Species { get => ReadUInt16LittleEndian(Data.AsSpan(0x08)); set => WriteUInt16LittleEndian(Data.AsSpan(0x08), value); diff --git a/PKHeX.Core/PKM/PK7.cs b/PKHeX.Core/PKM/PK7.cs index 5718d1e33..f75f4c742 100644 --- a/PKHeX.Core/PKM/PK7.cs +++ b/PKHeX.Core/PKM/PK7.cs @@ -51,7 +51,7 @@ public sealed class PK7 : G6PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetC set => WriteUInt16LittleEndian(Data.AsSpan(0x06), value); } - public override ushort Species + public override ushort Species { get => ReadUInt16LittleEndian(Data.AsSpan(0x08)); set => WriteUInt16LittleEndian(Data.AsSpan(0x08), value); diff --git a/PKHeX.Core/PKM/Util/EntityPID.cs b/PKHeX.Core/PKM/Util/EntityPID.cs index f2597f6d9..505c77b0f 100644 --- a/PKHeX.Core/PKM/Util/EntityPID.cs +++ b/PKHeX.Core/PKM/Util/EntityPID.cs @@ -64,7 +64,7 @@ public static class EntityPID return pid; } } - + /// /// Gets the Unown Forme ID from PID. /// diff --git a/PKHeX.Core/PersonalInfo/PersonalInfo.cs b/PKHeX.Core/PersonalInfo/PersonalInfo.cs index d706923e8..f851613e3 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfo.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfo.cs @@ -82,7 +82,7 @@ public abstract class PersonalInfo : IPersonalInfo public bool HasForm(byte form) { - if (form <= 0) // no form requested + if (form == 0) // no form requested return false; if (FormStatsIndex <= 0) // no forms present return false; diff --git a/PKHeX.Core/Saves/SAV1.cs b/PKHeX.Core/Saves/SAV1.cs index e92b9ddd5..601eca684 100644 --- a/PKHeX.Core/Saves/SAV1.cs +++ b/PKHeX.Core/Saves/SAV1.cs @@ -508,7 +508,7 @@ public sealed class SAV1 : SaveFile, ILangDeviantSave, IEventFlagArray private bool CanSetDex(ushort species) { - if (species <= 0) + if (species == 0) return false; if (species > MaxSpeciesID) return false; diff --git a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan5.cs b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan5.cs index 74d5e7e9d..5c7af5d54 100644 --- a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan5.cs +++ b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan5.cs @@ -108,7 +108,7 @@ public sealed class Zukan5 : Zukan } return false; } - + private int FormLen => SAV is SAV5B2W2 ? 0xB : 0x9; private int FormDex => 0x8 + (BitSeenSize * 9); diff --git a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs index 41210a6f2..11c16cd26 100644 --- a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs +++ b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs @@ -533,7 +533,7 @@ public sealed class Zukan8 : ZukanBase SetUnk1Count(species, 0); SetUnk2Count(species, 0); } - + public override void SeenAll(bool shinyToo = false) { SetAllSeen(true, shinyToo); diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index daf69b154..d28c6ed14 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -482,7 +482,7 @@ public partial class Main : Form // Get Simulator Data var Set = new ShowdownSet(Clipboard.GetText()); - if (Set.Species < 0) + if (Set.Species == 0) { WinFormsUtil.Alert(MsgSimulatorFailClipboard); return; } if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSimulatorLoad, Set.Text)) diff --git a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs index a39eecfcd..9e95687ce 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs @@ -227,7 +227,7 @@ public partial class BatchEditor : Form var pk = data[i].Entity; var spec = pk.Species; - if (spec <= 0 || spec > max) + if (spec == 0 || spec > max) continue; if (entry.Source is SlotInfoBox info && SAV.GetSlotFlags(info.Box, info.Slot).IsOverwriteProtected()) diff --git a/PKHeX.WinForms/Subforms/SAV_Encounters.cs b/PKHeX.WinForms/Subforms/SAV_Encounters.cs index de442855c..9b40514c6 100644 --- a/PKHeX.WinForms/Subforms/SAV_Encounters.cs +++ b/PKHeX.WinForms/Subforms/SAV_Encounters.cs @@ -224,15 +224,15 @@ public partial class SAV_Encounters : Form private IEnumerable SearchDatabase(CancellationToken token) { var settings = GetSearchSettings(); - var moves = settings.Moves.ToArray(); // If nothing is specified, instead of just returning all possible encounters, just return nothing. - if (settings.Species <= 0 && moves.Length == 0 && Main.Settings.EncounterDb.ReturnNoneIfEmptySearch) + if (settings.Species == 0 && settings.Moves.Count == 0 && Main.Settings.EncounterDb.ReturnNoneIfEmptySearch) return Array.Empty(); var pk = SAV.BlankPKM; + var moves = settings.Moves.ToArray(); var versions = settings.GetVersions(SAV); - var species = settings.Species <= 0 ? GetFullRange(SAV.MaxSpeciesID) : new[] { settings.Species }; + var species = settings.Species == 0 ? GetFullRange(SAV.MaxSpeciesID) : new[] { settings.Species }; var results = GetAllSpeciesFormEncounters(species, SAV.Personal, versions, moves, pk, token); if (settings.SearchEgg != null) results = results.Where(z => z.EggEncounter == settings.SearchEgg); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexORAS.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexORAS.cs index 20e972a03..675bf7ff9 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexORAS.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexORAS.cs @@ -153,7 +153,7 @@ public partial class SAV_PokedexORAS : Form private void SetEntry() { - if (species < 0) + if (species == 0) return; Zukan.SetCaught(species, CP[0].Checked); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs index 755ad0090..65b6ddae0 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs @@ -241,7 +241,7 @@ public partial class SAV_PokedexGG : Form private void SetEntry() { - if (currentSpecies <= 0) + if (currentSpecies == 0) return; int pk = currentSpecies - 1; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs index 66ff80bf4..676e9ddcf 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs @@ -226,16 +226,16 @@ public partial class SAV_PokedexSM : Form private void SetEntry() { - if (currentSpecies <= 0) + if (currentSpecies == 0) return; - int pk = currentSpecies - 1; + int bit = currentSpecies - 1; for (int i = 0; i < 4; i++) Dex.SetSeen(currentSpecies, i, CP[i + 1].Checked); for (int i = 0; i < 4; i++) - Dex.SetDisplayed(pk, i, CP[i + 5].Checked); + Dex.SetDisplayed(bit, i, CP[i + 5].Checked); if (currentSpecies > SAV.MaxSpeciesID) return; @@ -243,7 +243,7 @@ public partial class SAV_PokedexSM : Form Dex.SetCaught(currentSpecies, CHK_P1.Checked); for (int i = 0; i < 9; i++) - Dex.SetLanguageFlag(pk, i, CL[i].Checked); + Dex.SetLanguageFlag(bit, i, CL[i].Checked); } private void B_Cancel_Click(object sender, EventArgs e) diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs index 48b519740..9fa18ef7e 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs @@ -86,8 +86,12 @@ public partial class SAV_Wondercard : Form try { // only check if the form is visible (not opening) - if (Visible && g.GiftUsed && DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgMsyteryGiftUsedAlert, MsgMysteryGiftUsedFix)) - g.GiftUsed = false; + if (Visible && g.GiftUsed) + { + var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgMsyteryGiftUsedAlert, MsgMysteryGiftUsedFix); + if (prompt == DialogResult.Yes) + g.GiftUsed = false; + } RTB.Lines = g.GetDescription().ToArray(); PB_Preview.Image = g.Sprite(); @@ -96,8 +100,8 @@ public partial class SAV_Wondercard : Form // Some user input mystery gifts can have out-of-bounds values. Just swallow any exception. catch (Exception e) { - WinFormsUtil.Error(MsgMysteryGiftParseTypeUnknown, e); RTB.Clear(); + WinFormsUtil.Error(MsgMysteryGiftParseTypeUnknown, e); } } @@ -128,17 +132,21 @@ public partial class SAV_Wondercard : Form // Mystery Gift IO (.file<->window) private void B_Import_Click(object sender, EventArgs e) { - using var import = new OpenFileDialog {Filter = WinFormsUtil.GetMysterGiftFilter(SAV.Generation, SAV.Version) }; - if (import.ShowDialog() != DialogResult.OK) return; + var fileFilter = WinFormsUtil.GetMysterGiftFilter(SAV.Generation, SAV.Version); + using var import = new OpenFileDialog { Filter = fileFilter }; + if (import.ShowDialog() != DialogResult.OK) + return; - string path = import.FileName; - var g = MysteryGift.GetMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path)); - if (g == null) + var path = import.FileName; + var data = File.ReadAllBytes(path); + var ext = Path.GetExtension(path); + var gift = MysteryGift.GetMysteryGift(data, ext); + if (gift == null) { WinFormsUtil.Error(MsgMysteryGiftInvalid, path); return; } - ViewGiftData(g); + ViewGiftData(gift); } private void B_Output_Click(object sender, EventArgs e) @@ -148,18 +156,21 @@ public partial class SAV_Wondercard : Form WinFormsUtil.ExportMGDialog(mg, SAV.Version); } - private static int GetLastUnfilledByType(MysteryGift Gift, MysteryGiftAlbum Album) + private static int GetLastUnfilledByType(MysteryGift gift, MysteryGiftAlbum album) { - for (int i = 0; i < Album.Gifts.Length; i++) + var gifts = album.Gifts; + for (int i = 0; i < gifts.Length; i++) { - if (!Album.Gifts[i].Empty) + var exist = gifts[i]; + if (!exist.Empty) continue; - if (Album.Gifts[i].Type != Gift.Type) + if (exist.Type != gift.Type) continue; return i; } return -1; } + // Mystery Gift RW (window<->sav) private void ClickView(object sender, EventArgs e) { diff --git a/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs b/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs index 178e39b91..00946c06c 100644 --- a/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs +++ b/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs @@ -66,7 +66,7 @@ public class BreedTests var test = MoveBreed.Validate(gen, (ushort)species, form, game, moves, result); test.Should().BeFalse(); } - + [Theory] [InlineData(GD, Bulbasaur, 0, Growl, Tackle)] // swap order, two base moves [InlineData(UM, Charmander, 0, Ember, BellyDrum, Scratch, Growl)] // swap order, inherit + egg moves