From 7442e86d6573ec6f9c5e5a398300d3a24dfd36cb Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 17 May 2025 14:45:49 -0500 Subject: [PATCH] level `int` -> `byte` Might refactor the learnset level get to byte later as a TryGet so -1 is never returned. --- .../Applicators/MoveShopRecordApplicator.cs | 9 ++-- .../Editing/PKM/EntitySuggestionUtil.cs | 2 +- PKHeX.Core/Game/GameStrings/GameInfo.cs | 20 +++----- PKHeX.Core/Game/GameStrings/GameLanguage.cs | 41 ++++++++--------- PKHeX.Core/Game/GameStrings/GameStrings.cs | 46 +++++++++++++------ .../Encounters/Data/Gen3/Encounters3Colo.cs | 2 +- .../Templates/GO/EncounterSlot7GO.cs | 2 +- .../Templates/GO/EncounterSlot8GO.cs | 4 +- .../Templates/Gen1/EncounterTrade1.cs | 2 +- .../Templates/Gen6/EncounterSlot6AO.cs | 6 +-- .../Templates/Gen8a/EncounterSlot8a.cs | 4 +- .../Templates/Gen8a/EncounterStatic8a.cs | 4 +- .../Gen8a/IMasteryInitialMoveShop8.cs | 2 +- .../Interfaces/Properties/ILevelRange.cs | 12 ++--- .../LearnSource/Sources/LearnSource1RB.cs | 2 +- .../LearnSource/Sources/LearnSource1YW.cs | 2 +- .../Sources/Shared/ILearnSource.cs | 2 +- PKHeX.Core/Legality/Learnset/Learnset.cs | 16 +++---- .../Legality/Moves/Breeding/MoveBreed2.cs | 4 +- .../Legality/Moves/Breeding/MoveBreed3.cs | 4 +- .../Legality/Moves/Breeding/MoveBreed4.cs | 4 +- .../Legality/Moves/Breeding/MoveBreed5.cs | 4 +- .../Legality/Moves/Breeding/MoveBreed6.cs | 4 +- .../Legality/RNG/ClassicEra/Gen3/MethodH.cs | 2 +- .../Legality/RNG/ClassicEra/Gen4/MethodJ.cs | 2 +- .../Legality/RNG/ClassicEra/Gen4/MethodK.cs | 2 +- .../Verifiers/LegendsArceusVerifier.cs | 4 +- .../Legality/Verifiers/LevelVerifier.cs | 7 ++- PKHeX.Core/Legality/Verifiers/MiscVerifier.cs | 2 +- PKHeX.Core/MysteryGifts/PL6.cs | 2 +- PKHeX.Core/PKM/HOME/IGameDataSide.cs | 2 +- PKHeX.Core/PKM/Interfaces/IMoveShop8.cs | 2 +- PKHeX.Core/PKM/PA8.cs | 8 ++-- PKHeX.Core/PKM/PB7.cs | 8 ++-- PKHeX.Core/PKM/PKM.cs | 6 +-- PKHeX.Core/PKM/Searching/SearchSettings.cs | 2 +- PKHeX.Core/PKM/Searching/SearchUtil.cs | 2 +- PKHeX.Core/PKM/Shared/GBPKM.cs | 2 +- .../Controls/PKM Editor/PKMEditor.cs | 2 +- PKHeX.WinForms/Subforms/SAV_Database.cs | 2 +- .../Save Editors/Gen7/SAV_FestivalPlaza.cs | 9 ++-- PKHeX.WinForms/Util/WinFormsUtil.cs | 16 ++----- Tests/PKHeX.Core.Tests/PKM/StatTest.cs | 4 +- 43 files changed, 142 insertions(+), 142 deletions(-) diff --git a/PKHeX.Core/Editing/Applicators/MoveShopRecordApplicator.cs b/PKHeX.Core/Editing/Applicators/MoveShopRecordApplicator.cs index 2b260c2e7..b4a63299d 100644 --- a/PKHeX.Core/Editing/Applicators/MoveShopRecordApplicator.cs +++ b/PKHeX.Core/Editing/Applicators/MoveShopRecordApplicator.cs @@ -61,7 +61,7 @@ public static void SetMoveShopFlagsAll(this IMoveShop8Mastery shop, PKM pk) /// /// Sets all possible move shop flags for the requested entity. /// - public static void SetMoveShopFlagsAll(this IMoveShop8Mastery shop, Learnset learn, Learnset mastery, int level) + public static void SetMoveShopFlagsAll(this IMoveShop8Mastery shop, Learnset learn, Learnset mastery, byte level) { var permit = shop.Permit; var possible = permit.RecordPermitIndexes; @@ -79,7 +79,7 @@ public static void SetMoveShopFlagsAll(this IMoveShop8Mastery shop, Learnset lea /// /// Sets all move shop flags for the currently known moves. /// - public static void SetMoveShopFlags(this IMoveShop8Mastery shop, ReadOnlySpan moves, Learnset learn, Learnset mastery, int level) + public static void SetMoveShopFlags(this IMoveShop8Mastery shop, ReadOnlySpan moves, Learnset learn, Learnset mastery, byte level) { var permit = shop.Permit; var possible = permit.RecordPermitIndexes; @@ -97,7 +97,7 @@ public static void SetMoveShopFlags(this IMoveShop8Mastery shop, ReadOnlySpan /// Sets the "mastered" move shop flag for the requested move. /// - public static void SetMasteredFlag(this IMoveShop8Mastery shop, Learnset learn, Learnset mastery, int level, int index, ushort move) + public static void SetMasteredFlag(this IMoveShop8Mastery shop, Learnset learn, Learnset mastery, byte level, int index, ushort move) { if (shop.GetMasteredRecordFlag(index)) return; @@ -116,7 +116,7 @@ public static void SetMasteredFlag(this IMoveShop8Mastery shop, Learnset learn, /// /// Sets the "mastered" move shop flag for the encounter. /// - public static void SetEncounterMasteryFlags(this IMoveShop8Mastery shop, ReadOnlySpan moves, Learnset mastery, int level) + public static void SetEncounterMasteryFlags(this IMoveShop8Mastery shop, ReadOnlySpan moves, Learnset mastery, byte level) { var permit = shop.Permit; var possible = permit.RecordPermitIndexes; @@ -143,7 +143,6 @@ public static void SetEncounterMasteryFlags(this IMoveShop8Mastery shop, ReadOnl public static void SetPurchasedFlagsAll(this IMoveShop8Mastery shop) { var permit = shop.Permit; - var possible = permit.RecordPermitIndexes; for (int index = 0; index < permit.RecordCountUsed; index++) { var allowed = permit.IsRecordPermitted(index); diff --git a/PKHeX.Core/Editing/PKM/EntitySuggestionUtil.cs b/PKHeX.Core/Editing/PKM/EntitySuggestionUtil.cs index 595ccd0d4..7771aeb2a 100644 --- a/PKHeX.Core/Editing/PKM/EntitySuggestionUtil.cs +++ b/PKHeX.Core/Editing/PKM/EntitySuggestionUtil.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public static class EntitySuggestionUtil { - public static List GetMetLocationSuggestionMessage(PKM pk, int level, ushort location, int minimumLevel, IEncounterable? enc) + public static List GetMetLocationSuggestionMessage(PKM pk, byte level, ushort location, int minimumLevel, IEncounterable? enc) { var suggestion = new List { MsgPKMSuggestionStart }; if (pk.Format >= 3) diff --git a/PKHeX.Core/Game/GameStrings/GameInfo.cs b/PKHeX.Core/Game/GameStrings/GameInfo.cs index e26b7d036..bfcf81a05 100644 --- a/PKHeX.Core/Game/GameStrings/GameInfo.cs +++ b/PKHeX.Core/Game/GameStrings/GameInfo.cs @@ -13,17 +13,8 @@ public static class GameInfo public static readonly IReadOnlyList GenderSymbolUnicode = ["♂", "♀", "-"]; public static readonly IReadOnlyList GenderSymbolASCII = ["M", "F", "-"]; private static GameStrings _strings = GetStrings(CurrentLanguage); - - public static GameStrings GetStrings(string lang) - { - int index = GameLanguage.GetLanguageIndex(lang); - return GetStrings(index); - } - - public static GameStrings GetStrings(int index) - { - return Languages[index] ??= new GameStrings(GameLanguage.LanguageCode(index)); - } + public static GameDataSource Sources { get; private set; } = new(_strings); + public static FilteredGameDataSource FilteredSources { get; set; } = new(FakeSaveFile.Default, Sources); public static GameStrings Strings { @@ -31,8 +22,11 @@ public static GameStrings Strings set => Sources = new GameDataSource(_strings = value); } - public static GameDataSource Sources { get; private set; } = new(_strings); - public static FilteredGameDataSource FilteredSources { get; set; } = new(FakeSaveFile.Default, Sources); + public static GameStrings GetStrings(string lang) + { + int index = GameLanguage.GetLanguageIndex(lang); + return Languages[index] ??= new GameStrings(lang); + } public static string GetVersionName(GameVersion version) { diff --git a/PKHeX.Core/Game/GameStrings/GameLanguage.cs b/PKHeX.Core/Game/GameStrings/GameLanguage.cs index 1d9fb721d..e7e4d37d0 100644 --- a/PKHeX.Core/Game/GameStrings/GameLanguage.cs +++ b/PKHeX.Core/Game/GameStrings/GameLanguage.cs @@ -9,7 +9,10 @@ namespace PKHeX.Core; public static class GameLanguage { public const string DefaultLanguage = "en"; // English - public static int DefaultLanguageIndex => Array.IndexOf(LanguageCodes, DefaultLanguage); + public const int DefaultLanguageIndex = 1; + + private static readonly string[] LanguageCodes = ["ja", "en", "fr", "it", "de", "es", "ko", "zh-Hans", "zh-Hant"]; + public static string LanguageCode(int lang) => (uint)lang >= LanguageCodes.Length ? DefaultLanguage : LanguageCodes[lang]; public static int LanguageCount => LanguageCodes.Length; @@ -24,6 +27,20 @@ public static int GetLanguageIndex(string lang) return l < 0 ? DefaultLanguageIndex : l; } + public static LanguageID GetLanguage(string lang) => lang switch + { + "ja" => LanguageID.Japanese, + "en" => LanguageID.English, + "fr" => LanguageID.French, + "it" => LanguageID.Italian, + "de" => LanguageID.German, + "es" => LanguageID.Spanish, + "ko" => LanguageID.Korean, + "zh-Hans" => LanguageID.ChineseS, + "zh-Hant" => LanguageID.ChineseT, + _ => LanguageID.English, + }; + /// /// Checks whether the language code is supported. /// @@ -37,28 +54,6 @@ public static int GetLanguageIndex(string lang) /// public static ReadOnlySpan AllSupportedLanguages => LanguageCodes; - private static readonly string[] LanguageCodes = ["ja", "en", "fr", "it", "de", "es", "ko", "zh-Hans", "zh-Hant"]; - - /// - /// Pokétransporter location names, ordered per index of - /// - private static readonly string[] ptransp = ["ポケシフター", "Poké Transfer", "Poké Fret", "Pokétrasporto", "Poképorter", "Pokétransfer", "포케시프터", "宝可传送", "寶可傳送"]; - - /// - /// Gets the Met Location display name for the Pokétransporter. - /// - /// Language Index from - public static string GetTransporterName(int language) - { - if ((uint)language >= ptransp.Length) - language = 2; - return ptransp[language]; - } - - /// - /// Language name from - public static string GetTransporterName(string lang) => GetTransporterName(GetLanguageIndex(lang)); - /// /// Gets a list of strings for the specified language and file type. /// diff --git a/PKHeX.Core/Game/GameStrings/GameStrings.cs b/PKHeX.Core/Game/GameStrings/GameStrings.cs index 0fc8e19d5..3b47930f0 100644 --- a/PKHeX.Core/Game/GameStrings/GameStrings.cs +++ b/PKHeX.Core/Game/GameStrings/GameStrings.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using static PKHeX.Core.LanguageID; namespace PKHeX.Core; @@ -26,9 +27,9 @@ public sealed class GameStrings : IBasicStrings public readonly string[] wallpapernames, puffs, walkercourses; public readonly string[] uggoods, ugspheres, ugtraps, ugtreasures; public readonly string[] seals, accessories, backdrops, poketchapps; - private readonly string lang; - private readonly int LanguageIndex; + private readonly string LanguageFilePrefix; + public LanguageID Language { get; } public string EggName { get; } public IReadOnlyList Species => specieslist; public IReadOnlyList Item => itemlist; @@ -37,7 +38,7 @@ public sealed class GameStrings : IBasicStrings public IReadOnlyList Types => types; public IReadOnlyList Natures => natures; - private string[] Get(string ident) => GameLanguage.GetStrings(ident, lang); + private string[] Get(string ident) => GameLanguage.GetStrings(ident, LanguageFilePrefix); private const string NPC = "NPC"; private const string EmptyIndex = "---"; @@ -53,10 +54,10 @@ public sealed class GameStrings : IBasicStrings 1712, 1713, 1746, 1747, 1748, 1749, 1750, 1771, ]; - internal GameStrings(string l) + internal GameStrings(string langFilePrefix) { - lang = l; - LanguageIndex = GameLanguage.GetLanguageIndex(l); + Language = GameLanguage.GetLanguage(LanguageFilePrefix = langFilePrefix); + ribbons = Get("ribbons"); // Past Generation strings @@ -75,7 +76,7 @@ internal GameStrings(string l) AppendLocationIndex(CXD.Met0.AsSpan(0, 227)); // Current Generation strings - natures = Util.GetNaturesList(l); + natures = Util.GetNaturesList(langFilePrefix); types = Get("types"); abilitylist = Get("abilities"); @@ -275,13 +276,13 @@ private void SanitizeItemNames() SanitizeItemsLA(itemlist); SanitizeItemsSV(itemlist); - if (lang is "fr") + if (Language is LanguageID.French) { itemlist[1681] += " (LA)"; // Galet Noir dup with 617 (Dark Stone | Black Tumblestone) itemlist[1262] += " (G8)"; // Nouilles dup with 1934 (Instant Noodles | Rice) itemlist[1263] += " (G8)"; // Steak Haché dup with 1925 (Precooked Burger | Herbed Sausage) } - else if (lang is "ja") + else if (Language is LanguageID.Japanese) { itemlist[1693] += " (LA)"; // むしよけスプレー dup with 79 (Repel) itemlist[1716] += " (LA)"; // ビビリだま dup with 847 (Adrenaline Orb | Scatter Bang) @@ -390,7 +391,7 @@ private void SanitizeMetLocations() SanitizeMetGen8b(Gen8b); SanitizeMetGen9(Gen9); - if (lang is "es" or "it") + if (Language is Italian or Spanish) { // Campeonato Mundial duplicates for (int i = 28; i < 35; i++) @@ -402,7 +403,7 @@ private void SanitizeMetLocations() Gen7b.Met4[27] += " (-)"; } - if (lang == "ko") + if (Language is Korean) { // Pokémon Ranger duplicate (should be Ranger Union) Gen5.Met4[71] += " (-)"; @@ -444,7 +445,7 @@ private void SanitizeMetGen5(LocationSet6 set) set.Met4[i] += $" ({i - 97})"; // Localize the Poketransfer to the language (30001) - set.Met3[1] = GameLanguage.GetTransporterName(LanguageIndex); + set.Met3[1] = GetTransporterName(Language); set.Met3[2] += $" ({NPC})"; // Anything from an NPC set.Met3[3] += $" ({EggName})"; // Link Trade (Egg) @@ -600,7 +601,7 @@ private void SanitizeMetGen8a(LocationSet6 set) for (int i = 55; i <= 60; i++) // distinguish second set of YYYY Event from the first set.Met4[i] += " (-)"; - if (lang is "en" or "es" or "de" or "it" or "fr") + if (Language is English or Spanish or German or Italian or French) { // Final four locations are not nouns, rather the same location reference (at the...) as prior entries. set.Met0[152] += " (152)"; // Galaxy Hall @@ -756,7 +757,7 @@ private string[] GetItemStrings9() // in Generation 9, TM #'s are padded to 3 digits; format them appropriately here var clone = (string[])itemlist.Clone(); var span = clone.AsSpan(); - var zero = lang is "ja" or "zh-Hans" or "zh-Hant" ? "0" : "0"; + var zero = Language is Japanese or ChineseS or ChineseT ? "0" : "0"; InsertZero(span[328..420], zero); // 01-92 InsertZero(span[618..621], zero); // 93-95 InsertZero(span[690..694], zero); // 96-99 @@ -866,4 +867,21 @@ public ReadOnlySpan GetLocationNames(byte generation, GameVersion versio return []; return set.GetLocationNames(bankID); } + + /// + /// Gets the Met Location display name for the Pokétransporter. + /// + public static string GetTransporterName(LanguageID language) => language switch + { + Japanese => "ポケシフター", // ja + French => "Poké Fret", // fr + Italian => "Pokétrasporto", // it + German => "Poképorter", // de + Spanish => "Pokétransfer", // es + Korean => "포케시프터", // ko + ChineseS => "宝可传送", // zh-Hans + ChineseT => "寶可傳送", // zh-Hant + + _ => "Poké Transfer", // en + }; } diff --git a/PKHeX.Core/Legality/Encounters/Data/Gen3/Encounters3Colo.cs b/PKHeX.Core/Legality/Encounters/Data/Gen3/Encounters3Colo.cs index 80f2adfd3..5abd8711d 100644 --- a/PKHeX.Core/Legality/Encounters/Data/Gen3/Encounters3Colo.cs +++ b/PKHeX.Core/Legality/Encounters/Data/Gen3/Encounters3Colo.cs @@ -22,7 +22,7 @@ internal static class Encounters3Colo internal static readonly EncounterGift3Colo[] Gifts = [ // In-Game without Bonus Disk - new(311, 13, TrainerNameDuking, GameVersion.CXD) { Location = 254, TID16 = 37149, OriginalTrainerGender = 0, Moves = new(045, 086, 098, 270) }, // Plusle @ Ingame Trade + new(311, 13, TrainerNameDuking, GameVersion.CXD) { Location = 254, TID16 = 37149, OriginalTrainerGender = 0, Moves = new(045, 086, 098, 270) }, // Plusle @ In-game Trade ]; internal static readonly EncounterShadow3Colo[] Shadow = diff --git a/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot7GO.cs b/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot7GO.cs index 34ddd154e..af56f27c5 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot7GO.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot7GO.cs @@ -107,7 +107,7 @@ private void SetPINGA(PB7 pk, EncounterCriteria criteria) } } - private void SetEncounterMoves(PB7 pk, int level) + private void SetEncounterMoves(PB7 pk, byte level) { Span moves = stackalloc ushort[4]; var source = LearnSource7GG.Instance; diff --git a/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs b/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs index 1f80e2139..3181a4f33 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs @@ -196,14 +196,14 @@ private void SetPINGA(PKM pk, EncounterCriteria criteria) } } - private void SetEncounterMoves(PKM pk, int level) + private void SetEncounterMoves(PKM pk, byte level) { Span moves = stackalloc ushort[4]; GetInitialMoves(level, moves); pk.SetMoves(moves); } - public void GetInitialMoves(int level, Span moves) + public void GetInitialMoves(byte level, Span moves) { var source = GameData.GetLearnSource(OriginGroup); source.SetEncounterMoves(Species, Form, level, moves); diff --git a/PKHeX.Core/Legality/Encounters/Templates/Gen1/EncounterTrade1.cs b/PKHeX.Core/Legality/Encounters/Templates/Gen1/EncounterTrade1.cs index 4f4cbcdfc..2bf84b0ed 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/Gen1/EncounterTrade1.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/Gen1/EncounterTrade1.cs @@ -174,7 +174,7 @@ public bool IsMatchExact(PKM pk, EvoCriteria evo) return true; } - private bool IsMatchLevel(PKM pk, int lvl) + private bool IsMatchLevel(PKM pk, byte lvl) { if (pk is not PK1 || CanObtainMinGSC()) return lvl >= LevelMinGSC; diff --git a/PKHeX.Core/Legality/Encounters/Templates/Gen6/EncounterSlot6AO.cs b/PKHeX.Core/Legality/Encounters/Templates/Gen6/EncounterSlot6AO.cs index 69663997d..9ba59438d 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/Gen6/EncounterSlot6AO.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/Gen6/EncounterSlot6AO.cs @@ -118,9 +118,9 @@ private void SetPINGA(PK6 pk, EncounterCriteria criteria, PersonalInfo6AO pi) #region Matching - private const int FluteBoostMin = 4; // White Flute decreases levels. - private const int FluteBoostMax = 4; // Black Flute increases levels. - private const int DexNavBoost = 29 + FluteBoostMax; // Maximum DexNav chain (95) and Flute. + private const byte FluteBoostMin = 4; // White Flute decreases levels. + private const byte FluteBoostMax = 4; // Black Flute increases levels. + private const byte DexNavBoost = 29 + FluteBoostMax; // Maximum DexNav chain (95) and Flute. public byte GetDownleveledMin() => (byte)(LevelMin - FluteBoostMin); diff --git a/PKHeX.Core/Legality/Encounters/Templates/Gen8a/EncounterSlot8a.cs b/PKHeX.Core/Legality/Encounters/Templates/Gen8a/EncounterSlot8a.cs index 3523d0baa..bfb87725f 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/Gen8a/EncounterSlot8a.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/Gen8a/EncounterSlot8a.cs @@ -117,7 +117,7 @@ private OverworldParam8a GetParams(PersonalInfo8LA pi) => new() _ => 0, }); - private void SetEncounterMoves(PA8 pk, int level) + private void SetEncounterMoves(PA8 pk, byte level) { Span moves = stackalloc ushort[4]; var (learn, mastery) = GetLevelUpInfo(); @@ -128,7 +128,7 @@ private void SetEncounterMoves(PA8 pk, int level) pk.SetMasteryFlagMove(pk.AlphaMove); } - public void LoadInitialMoveset(PA8 pa8, Span moves, Learnset learn, int level) + public void LoadInitialMoveset(PA8 pa8, Span moves, Learnset learn, byte level) { if (pa8.AlphaMove != 0) { diff --git a/PKHeX.Core/Legality/Encounters/Templates/Gen8a/EncounterStatic8a.cs b/PKHeX.Core/Legality/Encounters/Templates/Gen8a/EncounterStatic8a.cs index 1785b97a3..edfae128b 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/Gen8a/EncounterStatic8a.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/Gen8a/EncounterStatic8a.cs @@ -127,7 +127,7 @@ public void GenerateSeed64(PKM pk, ulong seed) Finalize(pa8, slotSeed); } - private void SetEncounterMoves(PA8 pk, int level) + private void SetEncounterMoves(PA8 pk, byte level) { Span moves = stackalloc ushort[4]; var (learn, mastery) = GetLevelUpInfo(); @@ -140,7 +140,7 @@ private void SetEncounterMoves(PA8 pk, int level) public (Learnset Learn, Learnset Mastery) GetLevelUpInfo() => LearnSource8LA.GetLearnsetAndMastery(Species, Form); - public void LoadInitialMoveset(PA8 pa8, Span moves, Learnset learn, int level) + public void LoadInitialMoveset(PA8 pa8, Span moves, Learnset learn, byte level) { if (Moves.HasMoves) Moves.CopyTo(moves); diff --git a/PKHeX.Core/Legality/Encounters/Templates/Gen8a/IMasteryInitialMoveShop8.cs b/PKHeX.Core/Legality/Encounters/Templates/Gen8a/IMasteryInitialMoveShop8.cs index d44833213..c4e571b60 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/Gen8a/IMasteryInitialMoveShop8.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/Gen8a/IMasteryInitialMoveShop8.cs @@ -8,7 +8,7 @@ namespace PKHeX.Core; public interface IMasteryInitialMoveShop8 { (Learnset Learn, Learnset Mastery) GetLevelUpInfo(); - void LoadInitialMoveset(PA8 pa8, Span moves, Learnset learn, int level); + void LoadInitialMoveset(PA8 pa8, Span moves, Learnset learn, byte level); bool IsForcedMasteryCorrect(PKM pk); void SetInitialMastery(PKM pk) { diff --git a/PKHeX.Core/Legality/Encounters/Templates/Interfaces/Properties/ILevelRange.cs b/PKHeX.Core/Legality/Encounters/Templates/Interfaces/Properties/ILevelRange.cs index 208f525b0..eba553336 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/Interfaces/Properties/ILevelRange.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/Interfaces/Properties/ILevelRange.cs @@ -27,12 +27,12 @@ public static class LevelRangeExtensions /// Range reference /// Single level /// True if within slot's range, false if impossible. - public static bool IsLevelWithinRange(this ILevelRange r, int lvl) => r.LevelMin <= lvl && lvl <= r.LevelMax; + public static bool IsLevelWithinRange(this ILevelRange r, byte lvl) => r.LevelMin <= lvl && lvl <= r.LevelMax; - /// - public static bool IsLevelWithinRange(int level, int min, int max) => min <= level && level <= max; + /// + public static bool IsLevelWithinRange(byte level, byte min, byte max) => min <= level && level <= max; - /// + /// public static bool IsLevelWithinRange(this ILevelRange r, T other) where T : ILevelRange => IsLevelWithinRange(r, other.LevelMin, other.LevelMax); /// @@ -52,7 +52,7 @@ public static class LevelRangeExtensions /// Highest value the low end of levels can be /// Lowest value the high end of levels can be /// True if within slot's range, false if impossible. - public static bool IsLevelWithinRange(this ILevelRange r, int lvl, int minDecrease, int maxIncrease) => r.LevelMin - minDecrease <= lvl && lvl <= r.LevelMax + maxIncrease; + public static bool IsLevelWithinRange(this ILevelRange r, byte lvl, byte minDecrease, byte maxIncrease) => r.LevelMin - minDecrease <= lvl && lvl <= r.LevelMax + maxIncrease; /// /// Gets if the specified level inputs are within range of the and @@ -63,5 +63,5 @@ public static class LevelRangeExtensions /// Highest value the low end of levels can be /// Lowest value the high end of levels can be /// True if within slot's range, false if impossible. - public static bool IsLevelWithinRange(this ILevelRange r, byte min, byte max, int minDecrease, int maxIncrease) => r.LevelMin - minDecrease <= max && min <= r.LevelMax + maxIncrease; + public static bool IsLevelWithinRange(this ILevelRange r, byte min, byte max, int minDecrease, byte maxIncrease) => r.LevelMin - minDecrease <= max && min <= r.LevelMax + maxIncrease; } diff --git a/PKHeX.Core/Legality/LearnSource/Sources/LearnSource1RB.cs b/PKHeX.Core/Legality/LearnSource/Sources/LearnSource1RB.cs index 5f3d7e628..1bfe0a617 100644 --- a/PKHeX.Core/Legality/LearnSource/Sources/LearnSource1RB.cs +++ b/PKHeX.Core/Legality/LearnSource/Sources/LearnSource1RB.cs @@ -97,7 +97,7 @@ public void GetAllMoves(Span result, PKM pk, EvoCriteria evo, MoveSourceTy } } - public void SetEncounterMoves(ushort species, byte form, int level, Span init) + public void SetEncounterMoves(ushort species, byte form, byte level, Span init) { if (!TryGetPersonal(species, 0, out var personal)) return; diff --git a/PKHeX.Core/Legality/LearnSource/Sources/LearnSource1YW.cs b/PKHeX.Core/Legality/LearnSource/Sources/LearnSource1YW.cs index 1213ba435..443eabd02 100644 --- a/PKHeX.Core/Legality/LearnSource/Sources/LearnSource1YW.cs +++ b/PKHeX.Core/Legality/LearnSource/Sources/LearnSource1YW.cs @@ -97,7 +97,7 @@ public void GetAllMoves(Span result, PKM pk, EvoCriteria evo, MoveSourceTy } } - public void SetEncounterMoves(ushort species, byte form, int level, Span init) + public void SetEncounterMoves(ushort species, byte form, byte level, Span init) { if (!TryGetPersonal(species, 0, out var personal)) return; diff --git a/PKHeX.Core/Legality/LearnSource/Sources/Shared/ILearnSource.cs b/PKHeX.Core/Legality/LearnSource/Sources/Shared/ILearnSource.cs index f6660465b..cd98c222b 100644 --- a/PKHeX.Core/Legality/LearnSource/Sources/Shared/ILearnSource.cs +++ b/PKHeX.Core/Legality/LearnSource/Sources/Shared/ILearnSource.cs @@ -24,7 +24,7 @@ public interface ILearnSource /// Entity form public Learnset GetLearnset(ushort species, byte form); - public void SetEncounterMoves(ushort species, byte form, int level, Span init) + public void SetEncounterMoves(ushort species, byte form, byte level, Span init) { var start = (init.LastIndexOfAnyExcept(0) + 1) & 3; var learn = GetLearnset(species, form); diff --git a/PKHeX.Core/Legality/Learnset/Learnset.cs b/PKHeX.Core/Legality/Learnset/Learnset.cs index f2917f7cf..b0e282103 100644 --- a/PKHeX.Core/Legality/Learnset/Learnset.cs +++ b/PKHeX.Core/Legality/Learnset/Learnset.cs @@ -21,7 +21,7 @@ public sealed class Learnset(ushort[] Moves, byte[] Levels) public ReadOnlySpan GetAllMoves() => Moves; - public ReadOnlySpan GetMoveRange(int maxLevel, int minLevel = 0) + public ReadOnlySpan GetMoveRange(byte maxLevel, byte minLevel = 0) { if (minLevel <= 1 && maxLevel >= 100) return Moves; @@ -38,7 +38,7 @@ public ReadOnlySpan GetMoveRange(int maxLevel, int minLevel = 0) return Moves.AsSpan(start, length); } - private int FindGrq(int level, int start = 0) + private int FindGrq(byte level, int start = 0) { var levels = Levels; for (int i = start; i < levels.Length; i++) @@ -49,7 +49,7 @@ private int FindGrq(int level, int start = 0) return -1; } - private int FindGr(int level, int start) + private int FindGr(byte level, int start) { var levels = Levels; for (int i = start; i < levels.Length; i++) @@ -60,7 +60,7 @@ private int FindGr(int level, int start) return -1; } - private int FindLastLeq(int level, int end = 0) + private int FindLastLeq(byte level, int end = 0) { var levels = Levels; for (int i = levels.Length - 1; i >= end; i--) @@ -77,7 +77,7 @@ private int FindLastLeq(int level, int end = 0) /// Move array to write to /// Starting index to begin overwriting at /// Array of Move IDs - public void SetEncounterMoves(int level, Span moves, int ctr = 0) + public void SetEncounterMoves(byte level, Span moves, int ctr = 0) { for (int i = 0; i < Moves.Length; i++) { @@ -115,7 +115,7 @@ private static void RectifyOrderShift(Span moves, int ctr) } } - public void SetEncounterMovesBackwards(int level, Span moves, int ctr = 0) + public void SetEncounterMovesBackwards(byte level, Span moves, int ctr = 0) { int index = FindLastLeq(level); @@ -145,7 +145,7 @@ public void SetEncounterMovesBackwards(int level, Span moves, int ctr = } /// Adds the learned moves by level up to the specified level. - public void SetLevelUpMoves(int startLevel, int endLevel, Span moves, int ctr = 0) + public void SetLevelUpMoves(byte startLevel, byte endLevel, Span moves, int ctr = 0) { int startIndex = FindGrq(startLevel); if (startIndex == -1) @@ -176,7 +176,7 @@ public void SetEvolutionMoves(Span moves, int ctr = 0) } /// Adds the learned moves by level up to the specified level. - public void SetLevelUpMoves(int startLevel, int endLevel, Span moves, ReadOnlySpan ignore, int ctr = 0) + public void SetLevelUpMoves(byte startLevel, byte endLevel, Span moves, ReadOnlySpan ignore, int ctr = 0) { int startIndex = FindGrq(startLevel); if (startIndex == -1) diff --git a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed2.cs b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed2.cs index a8264db38..01903a807 100644 --- a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed2.cs +++ b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed2.cs @@ -12,7 +12,7 @@ namespace PKHeX.Core; /// Refer to for inheritance ordering. public static class MoveBreed2 { - private const int level = 5; + private const byte Level = EncounterEgg2.Level; /// public static bool Validate(ushort species, GameVersion version, ReadOnlySpan moves, Span origins) @@ -34,7 +34,7 @@ public static bool Validate(ushort species, GameVersion version, ReadOnlySpan(origins); Span possible = stackalloc byte[count]; - var value = new BreedInfo(actual, possible, learnset, moves, level); + var value = new BreedInfo(actual, possible, learnset, moves, Level); bool inherit = Breeding.GetCanInheritMoves(species); MarkMovesForOrigin(value, eggMoves, count, inherit, pi, version); diff --git a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed3.cs b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed3.cs index 78f977b61..913547fab 100644 --- a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed3.cs +++ b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed3.cs @@ -13,7 +13,7 @@ namespace PKHeX.Core; /// Refer to for inheritance ordering. public static class MoveBreed3 { - private const int level = 5; + private const byte Level = EncounterEgg3.Level; /// public static bool Validate(ushort species, GameVersion version, ReadOnlySpan moves, Span origins) @@ -39,7 +39,7 @@ public static bool Validate(ushort species, GameVersion version, ReadOnlySpan(origins); Span possible = stackalloc byte[count]; - var value = new BreedInfo(actual, possible, learnset, moves, level); + var value = new BreedInfo(actual, possible, learnset, moves, Level); if (species is (int)Species.Pichu && moves[count - 1] is (int)Move.VoltTackle && version == E) actual[--count] = VoltTackle; diff --git a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed4.cs b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed4.cs index 17599cea2..14a8128f7 100644 --- a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed4.cs +++ b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed4.cs @@ -13,7 +13,7 @@ namespace PKHeX.Core; /// Refer to for inheritance ordering. public static class MoveBreed4 { - private const int level = 1; + private const byte Level = EncounterEgg4.Level; /// public static bool Validate(ushort species, GameVersion version, ReadOnlySpan moves, Span origins) @@ -40,7 +40,7 @@ public static bool Validate(ushort species, GameVersion version, ReadOnlySpan(origins); Span possible = stackalloc byte[count]; - var value = new BreedInfo(actual, possible, learnset, moves, level); + var value = new BreedInfo(actual, possible, learnset, moves, Level); if (species is (int)Species.Pichu && moves[count - 1] is (int)Move.VoltTackle) actual[--count] = VoltTackle; diff --git a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed5.cs b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed5.cs index 8f5389403..74dfa6e68 100644 --- a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed5.cs +++ b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed5.cs @@ -11,7 +11,7 @@ namespace PKHeX.Core; /// Refer to for inheritance ordering. public static class MoveBreed5 { - private const int level = 1; + private const byte Level = EncounterEgg5.Level; /// public static bool Validate(ushort species, GameVersion version, ReadOnlySpan moves, Span origins) @@ -35,7 +35,7 @@ public static bool Validate(ushort species, GameVersion version, ReadOnlySpan(origins); Span possible = stackalloc byte[count]; - var value = new BreedInfo(actual, possible, learnset, moves, level); + var value = new BreedInfo(actual, possible, learnset, moves, Level); if (species is (int)Species.Pichu && moves[count - 1] is (int)Move.VoltTackle) actual[--count] = VoltTackle; diff --git a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed6.cs b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed6.cs index 2cace30d9..4c09f5a21 100644 --- a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed6.cs +++ b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed6.cs @@ -11,7 +11,7 @@ namespace PKHeX.Core; /// Refer to for inheritance ordering. public static class MoveBreed6 { - private const int level = 1; + private const byte Level = EncounterEgg6.Level; /// public static bool Validate(byte generation, ushort species, byte form, GameVersion version, ReadOnlySpan moves, Span origins) @@ -27,7 +27,7 @@ public static bool Validate(byte generation, ushort species, byte form, GameVers var actual = MemoryMarshal.Cast(origins); Span possible = stackalloc byte[count]; - var value = new BreedInfo(actual, possible, learnset, moves, level); + var value = new BreedInfo(actual, possible, learnset, moves, Level); if (species is (int)Species.Pichu && moves[count - 1] is (int)Move.VoltTackle) actual[--count] = VoltTackle; diff --git a/PKHeX.Core/Legality/RNG/ClassicEra/Gen3/MethodH.cs b/PKHeX.Core/Legality/RNG/ClassicEra/Gen3/MethodH.cs index 6fb3d7f80..f1314e706 100644 --- a/PKHeX.Core/Legality/RNG/ClassicEra/Gen3/MethodH.cs +++ b/PKHeX.Core/Legality/RNG/ClassicEra/Gen3/MethodH.cs @@ -606,7 +606,7 @@ private static bool IsOriginalLevelValid(byte min, byte max, byte format, uint l { if (format == Format && min > 1) return level == min; // Met Level matches - return LevelRangeExtensions.IsLevelWithinRange((int)level, min, max); + return LevelRangeExtensions.IsLevelWithinRange((byte)level, min, max); } public static uint GetRandomLevel(T enc, uint u16LevelRand, LeadRequired lead) where T : ILevelRange => lead switch diff --git a/PKHeX.Core/Legality/RNG/ClassicEra/Gen4/MethodJ.cs b/PKHeX.Core/Legality/RNG/ClassicEra/Gen4/MethodJ.cs index 755b4d54a..ec9d32953 100644 --- a/PKHeX.Core/Legality/RNG/ClassicEra/Gen4/MethodJ.cs +++ b/PKHeX.Core/Legality/RNG/ClassicEra/Gen4/MethodJ.cs @@ -474,7 +474,7 @@ private static bool IsOriginalLevelValid(byte min, byte max, byte format, uint l { if (format == Format && min > 1) return level == min; // Met Level matches - return LevelRangeExtensions.IsLevelWithinRange((int)level, min, max); + return LevelRangeExtensions.IsLevelWithinRange((byte)level, min, max); } public static uint GetRandomLevel(T enc, uint seed, LeadRequired lead) where T : IEncounterSlot4 diff --git a/PKHeX.Core/Legality/RNG/ClassicEra/Gen4/MethodK.cs b/PKHeX.Core/Legality/RNG/ClassicEra/Gen4/MethodK.cs index 4e71a929f..ae882a3ca 100644 --- a/PKHeX.Core/Legality/RNG/ClassicEra/Gen4/MethodK.cs +++ b/PKHeX.Core/Legality/RNG/ClassicEra/Gen4/MethodK.cs @@ -501,7 +501,7 @@ private static bool IsOriginalLevelValid(byte min, byte max, byte format, uint l { if (format == Format && min > 1) return level == min; // Met Level matches - return LevelRangeExtensions.IsLevelWithinRange((int)level, min, max); + return LevelRangeExtensions.IsLevelWithinRange((byte)level, min, max); } public static uint GetRandomLevel(T enc, uint seed, LeadRequired lead) where T : IEncounterSlot4 diff --git a/PKHeX.Core/Legality/Verifiers/LegendsArceusVerifier.cs b/PKHeX.Core/Legality/Verifiers/LegendsArceusVerifier.cs index a17f5a941..2a35f6335 100644 --- a/PKHeX.Core/Legality/Verifiers/LegendsArceusVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/LegendsArceusVerifier.cs @@ -138,7 +138,7 @@ private static void LoadPurchasedMoves(PA8 pa, Span result) } } - private static int AddMasteredMissing(PA8 pa, Span current, int ctr, Learnset baseLearn, Learnset currentLearn, int level) + private static int AddMasteredMissing(PA8 pa, Span current, int ctr, Learnset baseLearn, Learnset currentLearn, byte level) { var purchased = pa.Permit.RecordPermitIndexes; for (int i = 0; i < purchased.Length; i++) @@ -234,7 +234,7 @@ private static bool CanLearnMoveByLevelUp(LegalityAnalysis data, PA8 pa, int i, continue; // cannot learn via level up level = Math.Min(lvl, level); } - return pa.CurrentLevel >= level; + return level <= pa.CurrentLevel; } private void VerifyAlphaMove(LegalityAnalysis data, PA8 pa, ushort alphaMove, IPermitRecord permit) diff --git a/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs b/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs index 04b9b4d1c..421262be8 100644 --- a/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs @@ -80,14 +80,13 @@ public void VerifyG1(LegalityAnalysis data) var enc = data.EncounterMatch; if (pk.IsEgg) { - const int elvl = 5; - if (elvl != pk.CurrentLevel) - data.AddLine(GetInvalid(string.Format(LEggFMetLevel_0, elvl))); + if (pk.CurrentLevel != EncounterEgg2.Level) + data.AddLine(GetInvalid(string.Format(LEggFMetLevel_0, EncounterEgg2.Level))); return; } if (pk.MetLocation != 0) // crystal { - int lvl = pk.CurrentLevel; + var lvl = pk.CurrentLevel; if (lvl < pk.MetLevel) data.AddLine(GetInvalid(LLevelMetBelow)); } diff --git a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs index a9af63d00..fb111d112 100644 --- a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs @@ -484,7 +484,7 @@ private static void VerifyMiscFatefulEncounter(LegalityAnalysis data) VerifyReceivability(data, g); VerifyFatefulMysteryGift(data, g); return; - case IFatefulEncounterReadOnly {FatefulEncounter: true}: // ingame fateful + case IFatefulEncounterReadOnly {FatefulEncounter: true}: // in-game fateful VerifyFatefulIngameActive(data); return; } diff --git a/PKHeX.Core/MysteryGifts/PL6.cs b/PKHeX.Core/MysteryGifts/PL6.cs index 6cf116951..450438c89 100644 --- a/PKHeX.Core/MysteryGifts/PL6.cs +++ b/PKHeX.Core/MysteryGifts/PL6.cs @@ -144,7 +144,7 @@ public string OT set => StringConverter6.SetString(OriginalTrainerTrash, value, 12, Language, StringConverterOption.ClearZero); } - public int Level { get => Data[0x68]; set => Data[0x68] = (byte)value; } + public byte Level { get => Data[0x68]; set => Data[0x68] = value; } public bool IsEgg { get => Data[0x69] == 1; set => Data[0x69] = value ? (byte)1 : (byte)0; } public uint PID { get => ReadUInt32LittleEndian(Data[0x6C..]); set => WriteUInt32LittleEndian(Data[0x6C..], value); } public ushort RelearnMove1 { get => ReadUInt16LittleEndian(Data[0x70..]); set => WriteUInt16LittleEndian(Data[0x70..], value); } diff --git a/PKHeX.Core/PKM/HOME/IGameDataSide.cs b/PKHeX.Core/PKM/HOME/IGameDataSide.cs index a8369ca5e..056883b8e 100644 --- a/PKHeX.Core/PKM/HOME/IGameDataSide.cs +++ b/PKHeX.Core/PKM/HOME/IGameDataSide.cs @@ -108,7 +108,7 @@ public static void CopyFrom(this IGameDataSide data, PKM pk) /// /// Resets the moves using the for the given level. /// - public static void ResetMoves(this IGameDataSide data, ushort species, byte form, int level, ILearnSource source, EntityContext context) + public static void ResetMoves(this IGameDataSide data, ushort species, byte form, byte level, ILearnSource source, EntityContext context) { var learn = source.GetLearnset(species, form); Span moves = stackalloc ushort[4]; diff --git a/PKHeX.Core/PKM/Interfaces/IMoveShop8.cs b/PKHeX.Core/PKM/Interfaces/IMoveShop8.cs index c080f4abc..17b99bc31 100644 --- a/PKHeX.Core/PKM/Interfaces/IMoveShop8.cs +++ b/PKHeX.Core/PKM/Interfaces/IMoveShop8.cs @@ -61,7 +61,7 @@ public interface IMoveShop8Mastery : IMoveShop8 public static class MoveShop8MasteryExtensions { - public static bool IsValidPurchasedEncounter(this IMoveShop8 shop, Learnset learn, int level, ushort alpha, bool allowPurchasedAlpha) + public static bool IsValidPurchasedEncounter(this IMoveShop8 shop, Learnset learn, byte level, ushort alpha, bool allowPurchasedAlpha) { var permit = shop.Permit.RecordPermitIndexes; var current = shop.Permit; diff --git a/PKHeX.Core/PKM/PA8.cs b/PKHeX.Core/PKM/PA8.cs index 0a25181ba..56215339e 100644 --- a/PKHeX.Core/PKM/PA8.cs +++ b/PKHeX.Core/PKM/PA8.cs @@ -512,7 +512,7 @@ public ulong Tracker public override void LoadStats(IBaseStat p, Span stats) { - int level = CurrentLevel; + var level = CurrentLevel; var nature = StatNature; stats[0] = (ushort)(GetGanbaruStat(p.HP, HT_HP ? 31 : IV_HP, GV_HP, level) + GetStatHp(p.HP, level)); @@ -523,7 +523,7 @@ public override void LoadStats(IBaseStat p, Span stats) stats[5] = (ushort)(GetGanbaruStat(p.SPD, HT_SPD ? 31 : IV_SPD, GV_SPD, level) + GetStat(p.SPD, level, nature, 3)); } - public static int GetGanbaruStat(int baseStat, int iv, byte gv, int level) + public static int GetGanbaruStat(int baseStat, int iv, byte gv, byte level) { var mul = GanbaruExtensions.GetGanbaruMultiplier(gv, iv); double step1 = Math.Abs(Math.Sqrt(baseStat)) * mul; // The game does abs after sqrt; should be before. It's fine because baseStat is never negative. @@ -531,12 +531,12 @@ public static int GetGanbaruStat(int baseStat, int iv, byte gv, int level) return (int)Math.Round(result, MidpointRounding.AwayFromZero); } - public static int GetStatHp(int baseStat, int level) + public static int GetStatHp(int baseStat, byte level) { return (int)((((level / 100.0f) + 1.0f) * baseStat) + level); } - public static int GetStat(int baseStat, int level, Nature nature, int statIndex) + public static int GetStat(int baseStat, byte level, Nature nature, int statIndex) { var initial = (int)((((level / 50.0f) + 1.0f) * baseStat) / 1.5f); return NatureAmp.AmplifyStat(nature, statIndex, initial); diff --git a/PKHeX.Core/PKM/PB7.cs b/PKHeX.Core/PKM/PB7.cs index dd585da6c..f836af1de 100644 --- a/PKHeX.Core/PKM/PB7.cs +++ b/PKHeX.Core/PKM/PB7.cs @@ -514,7 +514,7 @@ public void FixMemories() public override void LoadStats(IBaseStat p, Span stats) { - int level = CurrentLevel; + var level = CurrentLevel; var nature = Nature; int friend = CurrentFriendship; // stats +10% depending on friendship! int scalar = (int)(((friend / 255.0f / 10.0f) + 1.0f) * 100.0f); @@ -533,7 +533,7 @@ public override void LoadStats(IBaseStat p, Span stats) /// Current IV, already accounted for Hyper Training /// Current Level /// Initial Stat - private static int GetStat(int baseStat, int iv, int level) => (iv + (2 * baseStat)) * level / 100; + private static int GetStat(int baseStat, int iv, byte level) => (iv + (2 * baseStat)) * level / 100; /// /// Gets the initial stat value with nature amplification applied. Used for all stats except HP. @@ -544,7 +544,7 @@ public override void LoadStats(IBaseStat p, Span stats) /// /// Stat amp index in the nature amp table /// Initial Stat with nature amplification applied. - private static int GetStat(int baseStat, int iv, int level, Nature nature, int statIndex) + private static int GetStat(int baseStat, int iv, byte level, Nature nature, int statIndex) { int initial = GetStat(baseStat, iv, level) + 5; return NatureAmp.AmplifyStat(nature, statIndex, initial); @@ -557,7 +557,7 @@ public int BaseCP get { var p = PersonalInfo; - int level = CurrentLevel; + var level = CurrentLevel; var nature = Nature; int scalar = CPScalar; diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index b943c678e..d77373b1e 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -703,7 +703,7 @@ public ushort[] GetStats(IBaseStat p) public virtual void LoadStats(IBaseStat p, Span stats) { - int level = CurrentLevel; // recalculate instead of checking Stat_Level + var level = CurrentLevel; // recalculate instead of checking Stat_Level if (this is IHyperTrain t) LoadStats(stats, p, t, level); else @@ -713,7 +713,7 @@ public virtual void LoadStats(IBaseStat p, Span stats) NatureAmp.ModifyStatsForNature(stats, StatNature); } - private void LoadStats(Span stats, IBaseStat p, IHyperTrain t, int level) + private void LoadStats(Span stats, IBaseStat p, IHyperTrain t, byte level) { stats[0] = (ushort)(p.HP == 1 ? 1 : (((t.HT_HP ? 31 : IV_HP) + (2 * p.HP) + (EV_HP / 4) + 100) * level / 100) + 10); stats[1] = (ushort)((((t.HT_ATK ? 31 : IV_ATK) + (2 * p.ATK) + (EV_ATK / 4)) * level / 100) + 5); @@ -723,7 +723,7 @@ private void LoadStats(Span stats, IBaseStat p, IHyperTrain t, int level stats[3] = (ushort)((((t.HT_SPE ? 31 : IV_SPE) + (2 * p.SPE) + (EV_SPE / 4)) * level / 100) + 5); } - private void LoadStats(Span stats, IBaseStat p, int level) + private void LoadStats(Span stats, IBaseStat p, byte level) { stats[0] = (ushort)(p.HP == 1 ? 1 : ((IV_HP + (2 * p.HP) + (EV_HP / 4) + 100) * level / 100) + 10); stats[1] = (ushort)(((IV_ATK + (2 * p.ATK) + (EV_ATK / 4)) * level / 100) + 5); diff --git a/PKHeX.Core/PKM/Searching/SearchSettings.cs b/PKHeX.Core/PKM/Searching/SearchSettings.cs index d49a5b465..30b94ca3a 100644 --- a/PKHeX.Core/PKM/Searching/SearchSettings.cs +++ b/PKHeX.Core/PKM/Searching/SearchSettings.cs @@ -27,7 +27,7 @@ public sealed class SearchSettings public bool? SearchLegal { get; set; } public bool? SearchEgg { get; set; } public int? ESV { get; set; } - public int? Level { get; init; } + public byte? Level { get; init; } public int IVType { get; init; } public int EVType { get; init; } diff --git a/PKHeX.Core/PKM/Searching/SearchUtil.cs b/PKHeX.Core/PKM/Searching/SearchUtil.cs index 0d4c1e155..bf14cd4fd 100644 --- a/PKHeX.Core/PKM/Searching/SearchUtil.cs +++ b/PKHeX.Core/PKM/Searching/SearchUtil.cs @@ -27,7 +27,7 @@ public static class SearchUtil _ => pk.Generation == generation, }; - public static bool SatisfiesFilterLevel(PKM pk, SearchComparison option, int level) => option switch + public static bool SatisfiesFilterLevel(PKM pk, SearchComparison option, byte level) => option switch { SearchComparison.LessThanEquals => pk.Stat_Level <= level, SearchComparison.Equals => pk.Stat_Level == level, diff --git a/PKHeX.Core/PKM/Shared/GBPKM.cs b/PKHeX.Core/PKM/Shared/GBPKM.cs index b8b1dabdf..68fa72682 100644 --- a/PKHeX.Core/PKM/Shared/GBPKM.cs +++ b/PKHeX.Core/PKM/Shared/GBPKM.cs @@ -237,7 +237,7 @@ public override void LoadStats(IBaseStat p, Span stats) stats[5] = GetStat(p.SPD, IV_SPD, EV_SPD, lv); } - protected static ushort GetStat(int baseStat, int iv, int effort, int level) + protected static ushort GetStat(int baseStat, int iv, int effort, byte level) { // The games store a precomputed ushort[256] i^2 table for all ushort->byte square root calculations. // The game then iterates to find the lowest index with a value >= input (effort). diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index ebc898947..5a7abc2dc 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -914,7 +914,7 @@ private void UpdateEXPLevel(object sender, EventArgs e) var expInput = Util.ToUInt32(TB_EXP.Text); var expCalc = expInput; var gr = Entity.PersonalInfo.EXPGrowth; - int lvlExp = Experience.GetLevel(expInput, gr); + var lvlExp = Experience.GetLevel(expInput, gr); if (lvlExp == 100) expCalc = Experience.GetEXP(100, gr); diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index ae244bc4d..9c57d9b30 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -564,7 +564,7 @@ private SearchSettings GetSearchSettings() BatchInstructions = RTB_Instructions.Text, - Level = int.TryParse(TB_Level.Text, out var lvl) ? lvl : null, + Level = byte.TryParse(TB_Level.Text, out var lvl) ? lvl : null, SearchLevel = (SearchComparison)CB_Level.SelectedIndex, EVType = CB_EVTrain.SelectedIndex, IVType = CB_IV.SelectedIndex, diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_FestivalPlaza.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_FestivalPlaza.cs index ae527c6b2..09ff74ff3 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_FestivalPlaza.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_FestivalPlaza.cs @@ -468,16 +468,17 @@ private void HexTextBox_TextChanged(object sender, EventArgs e) } if (sender == TB_UsedFlags) { - f[entry].UsedFlags = Convert.ToUInt32(t, 16); + f[entry].UsedFlags = Util.GetHexValue(t); } else if (sender == TB_UsedStats) { - f[entry].UsedRandStat = Convert.ToUInt32(t, 16); + f[entry].UsedRandStat = Util.GetHexValue(t); } else if (sender == TB_FacilityID) { - var updated = Util.GetBytesFromHexString(t.PadLeft(24, '0')); - updated.CopyTo(f[entry].TrainerFesID); + var dest = f[entry].TrainerFesID; + dest.Clear(); + Util.GetBytesFromHexString(t, dest); } } diff --git a/PKHeX.WinForms/Util/WinFormsUtil.cs b/PKHeX.WinForms/Util/WinFormsUtil.cs index 21c4b232f..cc13f90cb 100644 --- a/PKHeX.WinForms/Util/WinFormsUtil.cs +++ b/PKHeX.WinForms/Util/WinFormsUtil.cs @@ -367,7 +367,7 @@ private static void SaveBackup(string path) /// Opens a dialog to save a file. /// /// to be saved. - /// Box the player will be greeted with when accessing the PC ingame. + /// Box the player will be greeted with when accessing the PC in-game. /// True if the file was saved. public static bool ExportSAVDialog(SaveFile sav, int currentBox = 0) { @@ -406,16 +406,10 @@ private static void ExportSAV(SaveFile sav, string path) } catch (Exception x) { - switch (x) - { - case UnauthorizedAccessException: - case FileNotFoundException: - case IOException: - Error(MsgFileWriteFail + Environment.NewLine + x.Message, MsgFileWriteProtectedAdvice); - break; - default: - throw; - } + if (x is UnauthorizedAccessException or FileNotFoundException or IOException) + Error(MsgFileWriteFail + Environment.NewLine + x.Message, MsgFileWriteProtectedAdvice); + else // Don't know what threw, but it wasn't I/O related. + throw; } } diff --git a/Tests/PKHeX.Core.Tests/PKM/StatTest.cs b/Tests/PKHeX.Core.Tests/PKM/StatTest.cs index bc8533184..c3355c034 100644 --- a/Tests/PKHeX.Core.Tests/PKM/StatTest.cs +++ b/Tests/PKHeX.Core.Tests/PKM/StatTest.cs @@ -59,8 +59,8 @@ public void CalcStatsGBPidgeot() ushort effort = 63001; effort = (ushort)(Math.Min((ushort)255, (ushort)Math.Ceiling(Math.Sqrt(effort))) >> 2); + const byte level = 100; const int iv = 15; - const int level = 100; const int baseStat = 91; var expect = (ushort)((((2 * (baseStat + iv)) + effort) * level / 100) + 5); expect.Should().Be(279); @@ -81,7 +81,7 @@ public class BelugaTests { [Theory] [InlineData(41, 25, 91)] - public void CalculateCP(int level, int statSum, int expect) + public void CalculateCP(byte level, int statSum, int expect) { var result1 = (((level * 4.0f / 100.0f) + 2.0f) * (statSum & 0xFFFF)); var result2 = (int)result1;