diff --git a/PKHeX.Core/Editing/Saves/Slots/Extensions.cs b/PKHeX.Core/Editing/Saves/Slots/Extensions.cs index 1ce7410a1..6bd163549 100644 --- a/PKHeX.Core/Editing/Saves/Slots/Extensions.cs +++ b/PKHeX.Core/Editing/Saves/Slots/Extensions.cs @@ -60,9 +60,9 @@ namespace PKHeX.Core private static List GetExtraSlots2(SAV2 sav) { - return new() + return new List { - new SlotInfoMisc(sav.Data, 0, sav.GetDaycareSlotOffset(0, 2)) {Type = StorageSlotType.Daycare }, // egg + new(sav.Data, 0, sav.GetDaycareSlotOffset(0, 2)) {Type = StorageSlotType.Daycare }, // egg }; } @@ -89,52 +89,52 @@ namespace PKHeX.Core private static List GetExtraSlots5(SAV5 sav) { - return new() + return new List { - new SlotInfoMisc(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS}, - new SlotInfoMisc(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused}, - new SlotInfoMisc(sav.Data, 0, sav.PGL) { Type = StorageSlotType.Misc }, + new(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS}, + new(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused}, + new(sav.Data, 0, sav.PGL) { Type = StorageSlotType.Misc }, - new SlotInfoMisc(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox}, }; } private static List GetExtraSlots6XY(SAV6XY sav) { - return new() + return new List { - new SlotInfoMisc(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS}, - new SlotInfoMisc(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused}, - new SlotInfoMisc(sav.Data, 0, sav.SUBE.Give) {Type = StorageSlotType.Misc}, // Old Man + new(sav.Data, 0, sav.GTS) {Type = StorageSlotType.GTS}, + new(sav.Data, 0, sav.Fused) {Type = StorageSlotType.Fused}, + new(sav.Data, 0, sav.SUBE.Give) {Type = StorageSlotType.Misc}, // Old Man - new SlotInfoMisc(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox}, }; } private static List GetExtraSlots6AO(SAV6AO sav) { - return new() + return new List { - new SlotInfoMisc(sav.Data, 0, SAV6AO.GTS) {Type = StorageSlotType.GTS}, - new SlotInfoMisc(sav.Data, 0, SAV6AO.Fused) {Type = StorageSlotType.Fused}, - new SlotInfoMisc(sav.Data, 0, sav.SUBE.Give) {Type = StorageSlotType.Misc}, + new(sav.Data, 0, SAV6AO.GTS) {Type = StorageSlotType.GTS}, + new(sav.Data, 0, SAV6AO.Fused) {Type = StorageSlotType.Fused}, + new(sav.Data, 0, sav.SUBE.Give) {Type = StorageSlotType.Misc}, - new SlotInfoMisc(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox}, - new SlotInfoMisc(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 0, sav.GetBattleBoxSlot(0)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 1, sav.GetBattleBoxSlot(1)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 2, sav.GetBattleBoxSlot(2)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 3, sav.GetBattleBoxSlot(3)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 4, sav.GetBattleBoxSlot(4)) {Type = StorageSlotType.BattleBox}, + new(sav.Data, 5, sav.GetBattleBoxSlot(5)) {Type = StorageSlotType.BattleBox}, }; } @@ -171,9 +171,9 @@ namespace PKHeX.Core private static List GetExtraSlots7b(SAV7b sav) { - return new() + return new List { - new SlotInfoMisc(sav.Data, 0, sav.Blocks.GetBlockOffset(BelugaBlockIndex.Daycare) + 8, true) {Type = StorageSlotType.Daycare}, + new(sav.Data, 0, sav.Blocks.GetBlockOffset(BelugaBlockIndex.Daycare) + 8, true) {Type = StorageSlotType.Daycare}, }; } @@ -205,17 +205,17 @@ namespace PKHeX.Core private static List GetExtraSlots8b(SAV8BS sav) { - return new() + return new List { - new SlotInfoMisc(sav.Data, 0, sav.UgSaveData.GetSlotOffset(0), true) { Type = StorageSlotType.Misc }, - new SlotInfoMisc(sav.Data, 1, sav.UgSaveData.GetSlotOffset(1), true) { Type = StorageSlotType.Misc }, - new SlotInfoMisc(sav.Data, 2, sav.UgSaveData.GetSlotOffset(2), true) { Type = StorageSlotType.Misc }, - new SlotInfoMisc(sav.Data, 3, sav.UgSaveData.GetSlotOffset(3), true) { Type = StorageSlotType.Misc }, - new SlotInfoMisc(sav.Data, 4, sav.UgSaveData.GetSlotOffset(4), true) { Type = StorageSlotType.Misc }, - new SlotInfoMisc(sav.Data, 5, sav.UgSaveData.GetSlotOffset(5), true) { Type = StorageSlotType.Misc }, - new SlotInfoMisc(sav.Data, 6, sav.UgSaveData.GetSlotOffset(6), true) { Type = StorageSlotType.Misc }, - new SlotInfoMisc(sav.Data, 7, sav.UgSaveData.GetSlotOffset(7), true) { Type = StorageSlotType.Misc }, - new SlotInfoMisc(sav.Data, 8, sav.UgSaveData.GetSlotOffset(8), true) { Type = StorageSlotType.Misc }, + new(sav.Data, 0, sav.UgSaveData.GetSlotOffset(0), true) { Type = StorageSlotType.Misc }, + new(sav.Data, 1, sav.UgSaveData.GetSlotOffset(1), true) { Type = StorageSlotType.Misc }, + new(sav.Data, 2, sav.UgSaveData.GetSlotOffset(2), true) { Type = StorageSlotType.Misc }, + new(sav.Data, 3, sav.UgSaveData.GetSlotOffset(3), true) { Type = StorageSlotType.Misc }, + new(sav.Data, 4, sav.UgSaveData.GetSlotOffset(4), true) { Type = StorageSlotType.Misc }, + new(sav.Data, 5, sav.UgSaveData.GetSlotOffset(5), true) { Type = StorageSlotType.Misc }, + new(sav.Data, 6, sav.UgSaveData.GetSlotOffset(6), true) { Type = StorageSlotType.Misc }, + new(sav.Data, 7, sav.UgSaveData.GetSlotOffset(7), true) { Type = StorageSlotType.Misc }, + new(sav.Data, 8, sav.UgSaveData.GetSlotOffset(8), true) { Type = StorageSlotType.Misc }, }; } } diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8NC.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8NC.cs index ce76b7b6b..fdb85e83e 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8NC.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8NC.cs @@ -6,10 +6,8 @@ namespace PKHeX.Core /// Generation 8 Nest Encounter (Distributed Crystal Data) /// /// - public sealed record EncounterStatic8NC : EncounterStatic8Nest + public sealed record EncounterStatic8NC(GameVersion Version) : EncounterStatic8Nest(Version) { - public EncounterStatic8NC(GameVersion game) : base(game) { } - protected override bool IsMatchLocation(PKM pkm) { var loc = pkm.Met_Location; diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8S.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8S.cs index 567243e06..c0595ee68 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8S.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8S.cs @@ -8,12 +8,10 @@ namespace PKHeX.Core /// with multiple references (used for multiple met locations) /// /// - public sealed record EncounterStatic8S : EncounterStatic8 + public sealed record EncounterStatic8S(GameVersion Version) : EncounterStatic8(Version) { public override int Location { get => Locations[0]; init { } } public IReadOnlyList Locations { get; init; } = Array.Empty(); protected override bool IsMatchLocation(PKM pkm) => Locations.Contains(pkm.Met_Location); - - public EncounterStatic8S(GameVersion game) : base(game) { } } } diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterCriteria.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterCriteria.cs index 4771a3d40..4ec0f1389 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterCriteria.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterCriteria.cs @@ -86,25 +86,21 @@ namespace PKHeX.Core /// Template data (end result). /// Personal info the end result will exist with. /// Initialized criteria data to be passed to generators. - public static EncounterCriteria GetCriteria(IBattleTemplate s, PersonalInfo pi) + public static EncounterCriteria GetCriteria(IBattleTemplate s, PersonalInfo pi) => new() { - int gender = s.Gender; - return new EncounterCriteria - { - Gender = gender, - IV_HP = s.IVs[0], - IV_ATK = s.IVs[1], - IV_DEF = s.IVs[2], - IV_SPE = s.IVs[3], - IV_SPA = s.IVs[4], - IV_SPD = s.IVs[5], - HPType = s.HiddenPowerType, + Gender = s.Gender, + IV_HP = s.IVs[0], + IV_ATK = s.IVs[1], + IV_DEF = s.IVs[2], + IV_SPE = s.IVs[3], + IV_SPA = s.IVs[4], + IV_SPD = s.IVs[5], + HPType = s.HiddenPowerType, - AbilityNumber = GetAbilityNumber(s.Ability, pi), - Nature = NatureUtil.GetNature(s.Nature), - Shiny = s.Shiny ? Shiny.Always : Shiny.Never, - }; - } + AbilityNumber = GetAbilityNumber(s.Ability, pi), + Nature = NatureUtil.GetNature(s.Nature), + Shiny = s.Shiny ? Shiny.Always : Shiny.Never, + }; private static AbilityPermission GetAbilityNumber(int ability, PersonalInfo pi) { diff --git a/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs b/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs index 9ee58442e..11363faba 100644 --- a/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs +++ b/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs @@ -99,8 +99,8 @@ namespace PKHeX.Core { for (int i = 0; i < ranges.Length; ++i) { - var span = ranges[i]; - if (esv >= span.Min && esv <= span.Max) + var (min, max) = ranges[i]; + if (esv >= min && esv <= max) return i; } return Invalid; diff --git a/PKHeX.Core/Legality/Verifiers/Misc/ContestStatInfo.cs b/PKHeX.Core/Legality/Verifiers/Misc/ContestStatInfo.cs index da911939b..08dfb5063 100644 --- a/PKHeX.Core/Legality/Verifiers/Misc/ContestStatInfo.cs +++ b/PKHeX.Core/Legality/Verifiers/Misc/ContestStatInfo.cs @@ -77,10 +77,9 @@ public static class ContestStatInfo var avg = Math.Max(1, nature % 6 == 0 ? rawAvg : GetAverageFeel(s, nature, initial)); avg = Math.Min(rawAvg, avg); // be generous - if (pokeBlock3) - return Math.Min(MaxContestStat, Math.Max(WorstFeelBlock, avg)); - else - return Math.Min(MaxContestStat, Math.Max(WorstFeelPoffin, avg)); + + var worst = pokeBlock3 ? WorstFeelBlock : WorstFeelPoffin; + return Math.Min(MaxContestStat, Math.Max(worst, avg)); } private static int GetAverageFeel(IContestStats s, int nature, IContestStats initial) diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index b195b0374..edf13f677 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -154,11 +154,9 @@ namespace PKHeX.WinForms if (File.Exists(path)) File.Delete(path); } - else if (entry.Source is SlotInfoBox b && entry.SAV == SAV) + else if (entry.Source is SlotInfoBox(var box, var slot) && entry.SAV == SAV) { // Data from Box: Delete from save file - int box = b.Box; - int slot = b.Slot; var change = new SlotInfoBox(box, slot); var pkSAV = change.Read(SAV); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs index 8aadc1135..c434f8bc0 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs @@ -319,9 +319,9 @@ namespace PKHeX.WinForms private void ChangeStatVal(object sender, EventArgs e) { - if (editingval) + if (editingval || sender is not NumericUpDown nud) return; - int n = Array.IndexOf(StatNUDA, sender); + int n = Array.IndexOf(StatNUDA, nud); if (n < 0) return; StatAddrControl(SetValToSav: n, SetSavToVal: false); diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_GroupViewer.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_GroupViewer.cs index 98da1fad5..0f5f7e257 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_GroupViewer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_GroupViewer.cs @@ -109,12 +109,12 @@ namespace PKHeX.WinForms if (index == CurrentGroup) return; - var group = Groups[index]; - Regenerate(group.Slots.Length); + var (_, slots) = Groups[index]; + Regenerate(slots.Length); var sav = SAV; - for (int i = 0; i < group.Slots.Length; i++) - Box.Entries[i].Image = group.Slots[i].Sprite(sav, -1, -1, true); + for (int i = 0; i < slots.Length; i++) + Box.Entries[i].Image = slots[i].Sprite(sav, -1, -1, true); if (slotSelected != -1 && (uint)slotSelected < Box.Entries.Count) Box.Entries[slotSelected].BackgroundImage = groupSelected != index ? null : SpriteUtil.Spriter.View; diff --git a/Tests/PKHeX.Core.Tests/PKM/PIDIVTests.cs b/Tests/PKHeX.Core.Tests/PKM/PIDIVTests.cs index ae9478de5..4417dd794 100644 --- a/Tests/PKHeX.Core.Tests/PKM/PIDIVTests.cs +++ b/Tests/PKHeX.Core.Tests/PKM/PIDIVTests.cs @@ -44,33 +44,38 @@ namespace PKHeX.Tests.PKM { // Method 3, reversed for Unown. var m3R = new PK3 { PID = 0x3DD1BB49, IVs = new[] { 23, 12, 31, 09, 03, 03 }, Species = 001 }; // Regular - var m3t = MethodFinder.Analyze(m3R).Type; - Assert.Equal(PIDType.Method_3, m3t); + var (type3, _) = MethodFinder.Analyze(m3R); + Assert.Equal(PIDType.Method_3, type3); + var m3u = new PK3 { PID = 0xBB493DD1, IVs = new[] { 23, 12, 31, 09, 03, 03 }, Species = 201 }; // Unown - var u3t = MethodFinder.Analyze(m3u).Type; - Assert.Equal(PIDType.Method_3_Unown, u3t); + var (type3R, _) = MethodFinder.Analyze(m3u); + Assert.Equal(PIDType.Method_3_Unown, type3R); } [Fact] - public void PIDIVMatchingTest3Misc() + public void PIDIVMatchingTest3MiscCXD() { // Colosseum / XD var pk3 = new PK3 {PID = 0x0985A297, IVs = new[] {06, 01, 00, 07, 17, 07}}; - var ak3 = MethodFinder.Analyze(pk3); - Assert.Equal(PIDType.CXD, MethodFinder.Analyze(pk3).Type); + var (type, seed) = MethodFinder.Analyze(pk3); + Assert.Equal(PIDType.CXD, type); var gk3 = new PK3(); - PIDGenerator.SetValuesFromSeed(gk3, PIDType.CXD, ak3.OriginSeed); + PIDGenerator.SetValuesFromSeed(gk3, PIDType.CXD, seed); Assert.Equal(pk3.PID, gk3.PID); Assert.True(pk3.IVs.SequenceEqual(gk3.IVs), "Unable to match generated IVs to CXD spread"); - + } + + [Fact] + public void PIDIVMatchingTest3MiscChannel() + { // Channel Jirachi var pkC = new PK3 {PID = 0x264750D9, IVs = new[] {06, 31, 14, 27, 05, 27}, SID = 45819, OT_Gender = 1, Version = (int)GameVersion.R}; - var akC = MethodFinder.Analyze(pkC); - Assert.Equal(PIDType.Channel,akC.Type); + var (type, seed) = MethodFinder.Analyze(pkC); + Assert.Equal(PIDType.Channel,type); var gkC = new PK3(); - PIDGenerator.SetValuesFromSeed(gkC, PIDType.Channel, akC.OriginSeed); + PIDGenerator.SetValuesFromSeed(gkC, PIDType.Channel, seed); Assert.Equal(pkC.PID, gkC.PID); Assert.True(pkC.IVs.SequenceEqual(gkC.IVs), "Unable to match generated IVs to Channel spread"); }