diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index e2cd111e4..9b62a64bc 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -1206,8 +1206,7 @@ internal static bool IsEvolutionValidWithMove(PKM pkm, LegalInfo info) // Check also if the current encounter include the evolve move as an special move // That means the pokemon have the move from the encounter level - int[] SpecialMoves = (info.EncounterMatch as IMoveset)?.Moves ?? new int[0]; - if (SpecialMoves.Any(m => moves.Contains(m))) + if (info.EncounterMatch is IMoveset s && s.Moves != null && s.Moves.Any(m => moves.Contains(m))) LearnLevel = Math.Min(LearnLevel, info.EncounterMatch.LevelMin); // If the encounter is a player hatched egg check if the move could be an egg move or inherited level up move @@ -1392,7 +1391,7 @@ internal static int GetMinLevelEncounter(PKM pkm) if (pkm.Format == 3 && pkm.WasEgg) // Only for gen 3 pokemon in format 3, after transfer to gen 4 it should return transfer level return 5; - if (pkm.Format == 4 && pkm.GenNumber == 4 && pkm.WasEgg) + if (pkm.Format == 4 && pkm.Gen4 && pkm.WasEgg) // Only for gen 4 pokemon in format 4, after transfer to gen 5 it should return transfer level return 1; return pkm.HasOriginalMetLocation ? pkm.Met_Level : GetMaxLevelGeneration(pkm); diff --git a/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs b/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs index 52e144307..c9d49a164 100644 --- a/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs +++ b/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs @@ -92,10 +92,12 @@ private static CheckMoveResult[] ParseMovesWasEggPreRelearn(PKM pkm, int[] Moves var AllowLevelUp = pkm.PersonalInfo.Gender > 0 && pkm.PersonalInfo.Gender < 255 || Legal.MixedGenderBreeding.Contains(e.Species); int BaseLevel = AllowLevelUp ? 100 : e.LevelMin; var LevelUp = Legal.GetBaseEggMoves(pkm, e.Species, e.Game, BaseLevel); + var TradebackPreevo = pkm.Format == 2 && info.EncounterMatch.Species > 151; - var NonTradebackLvlMoves = new int[0]; - if (TradebackPreevo) - NonTradebackLvlMoves = Legal.GetExclusivePreEvolutionMoves(pkm, info.EncounterMatch.Species, info.EvoChainsAllGens[2], 2, e.Game).Where(m => m > Legal.MaxMoveID_1).ToArray(); + var NonTradebackLvlMoves = TradebackPreevo + ? Legal.GetExclusivePreEvolutionMoves(pkm, info.EncounterMatch.Species, info.EvoChainsAllGens[2], 2, e.Game).Where(m => m > Legal.MaxMoveID_1).ToArray() + : new int[0]; + var Egg = Legal.GetEggMoves(pkm, e.Species, pkm.AltForm, e.Game); if (info.Generation < 3 && pkm.Format >= 7 && pkm.VC1) Egg = Egg.Where(m => m <= Legal.MaxMoveID_1).ToArray(); diff --git a/PKHeX.Core/Legality/RNG/MethodFinder.cs b/PKHeX.Core/Legality/RNG/MethodFinder.cs index 0512df0d3..daa95676f 100644 --- a/PKHeX.Core/Legality/RNG/MethodFinder.cs +++ b/PKHeX.Core/Legality/RNG/MethodFinder.cs @@ -73,7 +73,7 @@ private static bool GetModifiedPIDMatch(PKM pk, uint pid, uint[] IVs, out PIDIV } private static bool GetModified8BitMatch(PKM pk, uint pid, out PIDIV pidiv) { - return pk.GenNumber == 4 + return pk.Gen4 ? pid <= 0xFF && GetCuteCharmMatch(pk, pid, out pidiv) || GetG5MGShinyMatch(pk, pid, out pidiv) : GetG5MGShinyMatch(pk, pid, out pidiv) || pid <= 0xFF && GetCuteCharmMatch(pk, pid, out pidiv); } diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index d5f7c65d6..be2949edf 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -406,7 +406,7 @@ public int PIDAbility if (Version == (int) GameVersion.CXD) return Array.IndexOf(PersonalInfo.Abilities, Ability); - return (int)((GenNumber == 5 ? PID >> 16 : PID) & 1); + return (int)((Gen5 ? PID >> 16 : PID) & 1); } } @@ -490,13 +490,14 @@ public virtual bool WasGiftEgg { case 4: return Legal.GiftEggLocation4.Contains(Egg_Location) || (Egg_Location == 3002 && HGSS); // faraway case 5: return Egg_Location == 60003; - case 6: return Egg_Location == 60004; + case 6: + case 7: return Egg_Location == 60004; } return false; } } public virtual bool WasEvent => Met_Location > 40000 && Met_Location < 50000 || FatefulEncounter; - public virtual bool WasEventEgg => GenNumber == 4 ? WasEgg && Species == 490 : ((Egg_Location > 40000 && Egg_Location < 50000) || (FatefulEncounter && Egg_Location > 0)) && Met_Level == 1; + public virtual bool WasEventEgg => Gen4 ? WasEgg && Species == 490 : ((Egg_Location > 40000 && Egg_Location < 50000) || (FatefulEncounter && Egg_Location > 0)) && Met_Level == 1; public bool WasTradedEgg { get @@ -512,7 +513,7 @@ public bool WasTradedEgg } } } - public virtual bool WasIngameTrade => Met_Location == 30001 || GenNumber == 4 && Egg_Location == 2001; + public virtual bool WasIngameTrade => Met_Location == 30001 || Gen4 && Egg_Location == 2001; public virtual bool IsUntraded => Format >= 6 && string.IsNullOrWhiteSpace(HT_Name) && GenNumber == Format; public virtual bool IsNative => GenNumber == Format; public virtual bool IsOriginValid => Species <= Legal.GetMaxSpeciesOrigin(Format); diff --git a/PKHeX.Core/PKM/PKMConverter.cs b/PKHeX.Core/PKM/PKMConverter.cs index 08bd0c813..8e369b7b0 100644 --- a/PKHeX.Core/PKM/PKMConverter.cs +++ b/PKHeX.Core/PKM/PKMConverter.cs @@ -325,10 +325,10 @@ private static bool IsNotTransferrable(PKM pk, out string comment) default: comment = null; return false; - case 025 when pk.AltForm != 0 && pk.GenNumber == 6: // Cosplay Pikachu + case 025 when pk.AltForm != 0 && pk.Gen6: // Cosplay Pikachu comment = "Cannot transfer Cosplay Pikachu forward."; return true; - case 172 when pk.AltForm != 0 && pk.GenNumber == 4: // Spiky Eared Pichu + case 172 when pk.AltForm != 0 && pk.Gen4: // Spiky Eared Pichu comment = "Cannot transfer Spiky-Eared Pichu forward."; return true; } diff --git a/PKHeX.Core/PKM/ShowdownSet.cs b/PKHeX.Core/PKM/ShowdownSet.cs index 8dede8032..a531ef2f4 100644 --- a/PKHeX.Core/PKM/ShowdownSet.cs +++ b/PKHeX.Core/PKM/ShowdownSet.cs @@ -20,7 +20,7 @@ public class ShowdownSet private static readonly string[] moves = Util.GetMovesList(Language); private static readonly string[] abilities = Util.GetAbilitiesList(Language); private static readonly string[] hptypes = types.Skip(1).ToArray(); - private const int MAX_SPECIES = Legal.MaxSpeciesID_7_USUM; + private int MAX_SPECIES => species.Length-1; // Default Set Data public string Nickname { get; set; } @@ -54,7 +54,8 @@ public ShowdownSet(string input = null) lines = lines.Where(line => line.Length > 2).ToArray(); - if (lines.Length < 3) return; + if (lines.Length < 3) + return; // Seek for start of set int start = Array.FindIndex(lines, line => line.Contains(" @ ")); @@ -89,7 +90,7 @@ public ShowdownSet(string input = null) string[] brokenline = line.Split(new[] { ": " }, StringSplitOptions.None); if (brokenline.Length == 1) - brokenline = new[] {brokenline[0], ""}; + brokenline = new[] {brokenline[0], string.Empty}; switch (brokenline[0]) { case "Trait": @@ -152,7 +153,7 @@ public ShowdownSet(string input = null) private string GetText() { if (Species == 0 || Species > MAX_SPECIES) - return ""; + return string.Empty; var result = new List(); @@ -227,7 +228,8 @@ private IEnumerable GetStringMoves() public static string GetShowdownText(PKM pkm) { - if (pkm.Species == 0) return ""; + if (pkm.Species == 0) + return string.Empty; string[] Forms = PKX.GetFormList(pkm.Species, types, forms, new[] {"", "F", ""}, pkm.Format); ShowdownSet Set = new ShowdownSet @@ -244,11 +246,11 @@ public static string GetShowdownText(PKM pkm) Friendship = pkm.CurrentFriendship, Level = PKX.GetLevel(pkm.Species, pkm.EXP), Shiny = pkm.IsShiny, - Form = pkm.AltForm > 0 && pkm.AltForm < Forms.Length ? Forms[pkm.AltForm] : "", + Form = pkm.AltForm > 0 && pkm.AltForm < Forms.Length ? Forms[pkm.AltForm] : string.Empty, }; if (Set.Form == "F") - Set.Gender = ""; + Set.Gender = string.Empty; return Set.Text; } @@ -297,7 +299,7 @@ private void ParseSpeciesNickname(ref string line) n1 = line.Substring(end + 2); } - bool inverted = Array.IndexOf(species, n2.Replace(" ", "")) > -1 || (Species = Array.IndexOf(species, n2.Split('-')[0])) > 0; + bool inverted = Array.IndexOf(species, n2.Replace(" ", string.Empty)) > -1 || (Species = Array.IndexOf(species, n2.Split('-')[0])) > 0; line = inverted ? n2 : n1; Nickname = inverted ? n1 : n2; } diff --git a/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs index 5b80b72c2..95975c721 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs @@ -47,6 +47,11 @@ public BoxEditor() } } + public bool ControlsVisible + { + get => CB_BoxSelect.Enabled; + set => CB_BoxSelect.Enabled = CB_BoxSelect.Visible = B_BoxLeft.Visible = B_BoxRight.Visible = value; + } public int CurrentBox { get => CB_BoxSelect.SelectedIndex; @@ -91,21 +96,29 @@ public void ResetBoxNames() { if (!SAV.HasBox) return; - // Build ComboBox Dropdown Items - try + if (!SAV.Exportable) + getBoxNamesDefault(); + else + { + try { getBoxNamesFromSave(); } + catch { getBoxNamesDefault(); } + } + + if (SAV.CurrentBox < CB_BoxSelect.Items.Count) + CurrentBox = SAV.CurrentBox; // restore selected box + + void getBoxNamesFromSave() { CB_BoxSelect.Items.Clear(); for (int i = 0; i < SAV.BoxCount; i++) CB_BoxSelect.Items.Add(SAV.GetBoxName(i)); } - catch + void getBoxNamesDefault() { CB_BoxSelect.Items.Clear(); - for (int i = 1; i <= SAV.BoxCount; i++) - CB_BoxSelect.Items.Add($"BOX {i}"); + for (int i = 0; i <= SAV.BoxCount; i++) + CB_BoxSelect.Items.Add($"Box {i+1}"); } - if (SAV.CurrentBox < CB_BoxSelect.Items.Count) - CurrentBox = SAV.CurrentBox; // restore selected box } public void ResetSlots() { diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Roamer3.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Roamer3.cs index da750efb3..b6842c60b 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Roamer3.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Roamer3.cs @@ -43,6 +43,7 @@ private void SaveData() Reader.PID = Util.GetHexValue(TB_PID.Text); Reader.Species = WinFormsUtil.GetIndex(CB_Species); + Reader.IVs = IVs; } private void B_Save_Click(object sender, EventArgs e) { diff --git a/PKHeX.WinForms/Util/PKMUtil.cs b/PKHeX.WinForms/Util/PKMUtil.cs index 185dbc9e3..dbbbbb605 100644 --- a/PKHeX.WinForms/Util/PKMUtil.cs +++ b/PKHeX.WinForms/Util/PKMUtil.cs @@ -83,6 +83,8 @@ public static Image GetSprite(int species, int form, int gender, int item, bool // Redraw int x = 22 + (15 - itemimg.Width)/2; + if (x + itemimg.Width > baseImage.Width) + x = baseImage.Width - itemimg.Width; int y = 15 + (15 - itemimg.Height); baseImage = ImageUtil.LayerImage(baseImage, itemimg, x, y, 1); } @@ -153,7 +155,7 @@ private static Image GetSprite(PKM pkm, SaveFile SAV, int box, int slot, bool fl if (slot < 30) pkm.Box = box; var la = new LegalityAnalysis(pkm, SAV.Personal); - if (la.Parsed && !la.Valid && pkm.Species != 0) + if (la.ParsedInvalid && pkm.Species != 0) sprite = ImageUtil.LayerImage(sprite, Resources.warn, 0, 14, 1); } if (inBox) // in box