diff --git a/PKHeX.Core/Game/GameStrings/GameStrings.cs b/PKHeX.Core/Game/GameStrings/GameStrings.cs index b948b018f..1daba642c 100644 --- a/PKHeX.Core/Game/GameStrings/GameStrings.cs +++ b/PKHeX.Core/Game/GameStrings/GameStrings.cs @@ -22,10 +22,9 @@ public class GameStrings : IBasicStrings // Misc public readonly string[] wallpapernames, puffs; - public readonly string eggname; private readonly string lang; - public string EggName => eggname; + public string EggName { get; } public IReadOnlyList Species => specieslist; public IReadOnlyList Item => itemlist; public IReadOnlyList Move => movelist; @@ -97,10 +96,10 @@ public GameStrings(string l) trainingbags = Get("trainingbag"); trainingstage = Get("supertraining"); puffs = Get("puff"); - Array.Resize(ref puffs, puffs.Length + 1); + Array.Resize(ref puffs, puffs.Length + 1); // shift all down, 0th will be 'none' -- applied later Array.Copy(puffs, 0, puffs, 1, puffs.Length - 1); - eggname = specieslist[0]; + EggName = specieslist[0]; metHGSS_00000 = Get("hgss_00000"); metHGSS_02000 = Get("hgss_02000"); metHGSS_03000 = Get("hgss_03000"); @@ -198,7 +197,7 @@ private void SanitizeMetLocations() private void SanitizeMetG5BW() { metHGSS_02000[1] += $" ({NPC})"; // Anything from an NPC - metHGSS_02000[2] += $" ({eggname})"; // Egg From Link Trade + metHGSS_02000[2] += $" ({EggName})"; // Egg From Link Trade metBW2_00000[36] = $"{metBW2_00000[84]}/{metBW2_00000[36]}"; // Cold Storage in BW = PWT in BW2 metBW2_00000[40] += "(B/W)"; // Victory Road in BW metBW2_00000[134] += "(B2/W2)"; // Victory Road in B2W2 @@ -213,7 +212,7 @@ private void SanitizeMetG5BW() // Localize the Poketransfer to the language (30001) metBW2_30000[1 - 1] = GameInfo.GetTransporterName(lang); // Default to English metBW2_30000[2 - 1] += $" ({NPC})"; // Anything from an NPC - metBW2_30000[3 - 1] += $" ({eggname})"; // Link Trade (Egg) + metBW2_30000[3 - 1] += $" ({EggName})"; // Link Trade (Egg) // Zorua/Zoroark events metBW2_30000[10 - 1] = $"{specieslist[251]} ({specieslist[570]} 1)"; // Celebi's Zorua Event @@ -221,7 +220,7 @@ private void SanitizeMetG5BW() metBW2_30000[12 - 1] = $"{specieslist[571]} (1)"; // Zoroark metBW2_30000[13 - 1] = $"{specieslist[571]} (2)"; // Zoroark - metBW2_60000[3 - 1] += $" ({eggname})"; // Egg Treasure Hunter/Breeder, whatever... + metBW2_60000[3 - 1] += $" ({EggName})"; // Egg Treasure Hunter/Breeder, whatever... } private void SanitizeMetG6XY() @@ -231,7 +230,7 @@ private void SanitizeMetG6XY() metXY_00000[202] += " (OR/AS)"; // Pokémon League metXY_00000[298] += " (OR/AS)"; // Victory Road metXY_30000[0] += $" ({NPC})"; // Anything from an NPC - metXY_30000[1] += $" ({eggname})"; // Egg From Link Trade + metXY_30000[1] += $" ({EggName})"; // Egg From Link Trade } private void SanitizeMetG7SM() @@ -250,7 +249,7 @@ private void SanitizeMetG7SM() metSM_00000_good.CopyTo(metSM_00000, 0); metSM_30000[0] += $" ({NPC})"; // Anything from an NPC - metSM_30000[1] += $" ({eggname})"; // Egg From Link Trade + metSM_30000[1] += $" ({EggName})"; // Egg From Link Trade for (int i = 2; i <= 5; i++) // distinguish first set of regions (unused) from second (used) metSM_30000[i] += " (-)"; } diff --git a/PKHeX.Core/Game/GameStrings/MemoryStrings.cs b/PKHeX.Core/Game/GameStrings/MemoryStrings.cs index 180baaff4..7b306ba63 100644 --- a/PKHeX.Core/Game/GameStrings/MemoryStrings.cs +++ b/PKHeX.Core/Game/GameStrings/MemoryStrings.cs @@ -47,19 +47,19 @@ private List GetMemories() return Util.GetOffsetCBList(memory_list1, mems, 0, allowed); } - public List GetMemoryQualities() + public string[] GetMemoryQualities() { - List list = new List(); - for (int i = 0; i < 7; i++) - list.Add(s.memories[2 + i]); + var list = new string[7]; + for (int i = 0; i < list.Length; i++) + list[i] = s.memories[2 + i]; return list; } - public List GetMemoryFeelings() + public string[] GetMemoryFeelings() { - List list = new List(); + var list = new string[24]; for (int i = 0; i < 24; i++) - list.Add(s.memories[10 + i]); + list[i] = s.memories[10 + i]; return list; } diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index 979acd2d7..4de2ce9e4 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -178,12 +178,12 @@ internal static IEnumerable GetValidRelearn(PKM pkm, int species, bool inhe return r.Distinct(); } - internal static IList GetShedinjaEvolveMoves(PKM pkm, int generation, int lvl = -1) + internal static int[] GetShedinjaEvolveMoves(PKM pkm, int generation, int lvl = -1) { if (lvl == -1) lvl = pkm.CurrentLevel; if (pkm.Species != 292 || lvl < 20) - return new List(); + return Array.Empty(); // If nincada evolves into Ninjask an learn in the evolution a move from ninjask learnset pool // Shedinja would appear with that move learned. Only one move above level 20 allowed, only in generations 3 and 4 @@ -191,14 +191,14 @@ internal static IList GetShedinjaEvolveMoves(PKM pkm, int generation, int l { case 3: // Ninjask have the same learnset in every gen 3 games if (pkm.InhabitedGeneration(3)) - return LevelUpE[291].GetMoves(lvl, 20).ToList(); + return LevelUpE[291].GetMoves(lvl, 20); break; case 4: // Ninjask have the same learnset in every gen 4 games if (pkm.InhabitedGeneration(4)) return LevelUpPt[291].GetMoves(lvl, 20); break; } - return new List(); + return Array.Empty(); } internal static int GetShedinjaMoveLevel(int species, int move, int generation) @@ -817,14 +817,14 @@ internal static int GetMaxLanguageID(int generation) { case 1: case 3: - return 7; // 1-7 except 6 + return (int)LanguageID.Spanish; // 1-7 except 6 case 2: case 4: case 5: case 6: - return 8; + return (int)LanguageID.Korean; case 7: - return 10; + return (int)LanguageID.ChineseT; } return -1; } @@ -1071,8 +1071,8 @@ internal static int GetBaseSpecies(PKM pkm, int skipOption = 0, int generation = internal static int GetBaseSpecies(PKM pkm, IReadOnlyList evos, int skipOption = 0) { - if (pkm.Species == 292) - return 290; + if (pkm.Species == 292) // Shedinja + return 290; // Nincada switch (skipOption) { case -1: return pkm.Species; diff --git a/PKHeX.Core/Legality/Encounters/Verifiers/VerifyCurrentMoves.cs b/PKHeX.Core/Legality/Encounters/Verifiers/VerifyCurrentMoves.cs index d764b5711..8a99861a3 100644 --- a/PKHeX.Core/Legality/Encounters/Verifiers/VerifyCurrentMoves.cs +++ b/PKHeX.Core/Legality/Encounters/Verifiers/VerifyCurrentMoves.cs @@ -199,8 +199,8 @@ private static CheckMoveResult[] ParseMovesSpecialMoveset(PKM pkm, int[] Moves, private static int[] GetSpecialMoves(IEncounterable EncounterMatch) { - if (EncounterMatch is IMoveset mg) - return mg.Moves ?? Array.Empty(); + if (EncounterMatch is IMoveset mg && mg.Moves != null) + return mg.Moves; return Array.Empty(); } @@ -507,7 +507,7 @@ private static List GetIncompatibleRBYMoves(PKM pkm, int[] moves) { // Check moves that are learned at the same level in red/blue and yellow, these are illegal because there is no move reminder // There are only two incompatibilites; there is no illegal combination in generation 2+. - var incompatible = new List(); + var incompatible = new List(3); switch (pkm.Species) { @@ -742,7 +742,7 @@ private static CheckMoveResult[] VerifyPreRelearnEggBase(PKM pkm, int[] Moves, E // Obtain level1 moves var reqBase = GetRequiredBaseMoveCount(Moves, infoset); - var em = string.Empty; + var sb = new System.Text.StringBuilder(); // Check if the required amount of Base Egg Moves are present. for (int i = 0; i < reqBase; i++) { @@ -757,7 +757,7 @@ private static CheckMoveResult[] VerifyPreRelearnEggBase(PKM pkm, int[] Moves, E res[z] = new CheckMoveResult(MoveSource.Initial, gen, Severity.Invalid, LMoveRelearnEggMissing, CheckIdentifier.Move); // provide the list of suggested base moves for the last required slot - em = string.Join(", ", GetMoveNames(infoset.Base)); + sb.Append(string.Join(", ", GetMoveNames(infoset.Base))); break; } @@ -777,15 +777,15 @@ private static CheckMoveResult[] VerifyPreRelearnEggBase(PKM pkm, int[] Moves, E res[z] = new CheckMoveResult(MoveSource.SpecialEgg, gen, Severity.Invalid, LMoveEggMissing, CheckIdentifier.Move); // provide the list of suggested base moves and species moves for the last required slot - if (string.IsNullOrEmpty(em)) - em = string.Join(", ", GetMoveNames(infoset.Base)); - em += ", "; - em += string.Join(", ", GetMoveNames(infoset.Special)); + if (sb.Length == 0) + sb.Append(string.Join(", ", GetMoveNames(infoset.Base))); + sb.Append(", "); + sb.Append(string.Join(", ", GetMoveNames(infoset.Special))); break; } - if (!string.IsNullOrEmpty(em)) - res[reqBase > 0 ? reqBase - 1 : 0].Comment = string.Format(Environment.NewLine + LMoveFExpect_0, em); + if (sb.Length != 0) + res[reqBase > 0 ? reqBase - 1 : 0].Comment = string.Format(Environment.NewLine + LMoveFExpect_0, sb.ToString()); // Inherited moves appear after the required base moves. var AllowInheritedSeverity = infoset.AllowInherited ? Severity.Valid : Severity.Invalid; @@ -841,28 +841,22 @@ private static void VerifyNoEmptyDuplicates(int[] Moves, CheckMoveResult[] res) private static void UpdateGen1LevelUpMoves(PKM pkm, ValidEncounterMoves EncounterMoves, int defaultLvlG1, int generation, LegalInfo info) { - switch (generation) - { - case 1: - case 2: - var lvlG1 = info.EncounterMatch?.LevelMin + 1 ?? 6; - if (lvlG1 != defaultLvlG1) - EncounterMoves.LevelUpMoves[1] = Legal.GetValidMoves(pkm, info.EvoChainsAllGens[1], generation: 1, minLvLG1: lvlG1, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList(); - break; - } + if (generation >= 3) + return; + var lvlG1 = info.EncounterMatch?.LevelMin + 1 ?? 6; + if (lvlG1 == defaultLvlG1) + return; + EncounterMoves.LevelUpMoves[1] = Legal.GetValidMoves(pkm, info.EvoChainsAllGens[1], generation: 1, minLvLG1: lvlG1, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList(); } private static void UpdateGen2LevelUpMoves(PKM pkm, ValidEncounterMoves EncounterMoves, int defaultLvlG2, int generation, LegalInfo info) { - switch (generation) - { - case 1: - case 2: - var lvlG2 = info.EncounterMatch?.LevelMin + 1 ?? 6; - if (lvlG2 != defaultLvlG2) - EncounterMoves.LevelUpMoves[2] = Legal.GetValidMoves(pkm, info.EvoChainsAllGens[2], generation: 2, minLvLG2: defaultLvlG2, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList(); - break; - } + if (generation >= 3) + return; + var lvlG2 = info.EncounterMatch?.LevelMin + 1 ?? 6; + if (lvlG2 == defaultLvlG2) + return; + EncounterMoves.LevelUpMoves[2] = Legal.GetValidMoves(pkm, info.EvoChainsAllGens[2], generation: 2, minLvLG2: defaultLvlG2, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList(); } public static int[] GetGenMovesCheckOrder(PKM pkm) @@ -886,10 +880,12 @@ private static int[] GetGenMovesOrderVC(PKM pkm) return xfer; } + private static readonly int[] G2 = {2}; + private static readonly int[] G12 = {1, 2}; private static int[] GetGenMovesCheckOrderGB(PKM pkm, int originalGeneration) { if (originalGeneration == 2) - return pkm.Korean ? new[] {2} : new[] {2, 1}; + return pkm.Korean ? G2 : G12; return new[] {1, 2}; // RBY } diff --git a/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs b/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs index acd0732fc..f28bc3870 100644 --- a/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs +++ b/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs @@ -115,7 +115,9 @@ private static CheckResult[] VerifyRelearnEggBase(PKM pkm, LegalInfo info, Encou inheritMoves.Add(344); // Volt Tackle // If any splitbreed moves are invalid, flag accordingly - var splitMoves = e is EncounterEggSplit s ? Legal.GetValidRelearn(pkm, s.OtherSpecies, inheritLvlMoves, e.Version).ToList() : new List(); + var splitMoves = e is EncounterEggSplit s + ? Legal.GetValidRelearn(pkm, s.OtherSpecies, inheritLvlMoves, e.Version).ToList() + : (IReadOnlyList)Array.Empty(); // Inherited moves appear after the required base moves. // If the pkm is capable of split-species breeding and any inherited move is from the other split scenario, flag accordingly. diff --git a/PKHeX.Core/Util/DataUtil.cs b/PKHeX.Core/Util/DataUtil.cs index d5bc693b0..99bf57790 100644 --- a/PKHeX.Core/Util/DataUtil.cs +++ b/PKHeX.Core/Util/DataUtil.cs @@ -265,9 +265,6 @@ public static List GetCBList(IReadOnlyList inStrings, params public static List GetOffsetCBList(List cbList, IReadOnlyList inStrings, int offset, IEnumerable allowed) { - if (allowed == null) - allowed = Enumerable.Range(0, inStrings.Count); - var list = allowed .Select(z => new ComboItem {Text = inStrings[z - offset], Value = z}) .OrderBy(z => z.Text); @@ -279,13 +276,17 @@ public static List GetOffsetCBList(List cbList, IReadOnlyL public static List GetVariedCBListBall(string[] inStrings, int[] stringNum, int[] stringVal) { // First 3 Balls are always first - List newlist = new List(); - for (int i = 4; i > 1; i--) // add 4,3,2 - newlist.Add(new ComboItem { Text = inStrings[i], Value = i }); + var newlist = new List(3 + stringNum.Length) + { + new ComboItem {Text = inStrings[4], Value = (int)Ball.Poke}, + new ComboItem {Text = inStrings[3], Value = (int)Ball.Great}, + new ComboItem {Text = inStrings[2], Value = (int)Ball.Ultra}, + }; - newlist.AddRange(stringNum - .Select((z, i) => new ComboItem { Text = inStrings[z], Value = stringVal[i] }) - .OrderBy(z => z.Text)); + var ordered = stringNum + .Select((z, i) => new ComboItem {Text = inStrings[z], Value = stringVal[i]}) + .OrderBy(z => z.Text); + newlist.AddRange(ordered); return newlist; } #endregion diff --git a/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs b/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs index afeb6479d..2c754c9e6 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs @@ -121,7 +121,7 @@ private void LoadFields() } else { - GB_M_OT.Text = GB_M_CT.Text = $"N/A: {GameInfo.Strings.eggname}"; + GB_M_OT.Text = GB_M_CT.Text = $"N/A: {GameInfo.Strings.EggName}"; } init = true;