From 9ca4ef1e0962845f265ad1d09dba3e2d07e5e0b8 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 16 Mar 2019 12:07:22 -0700 Subject: [PATCH] Move pkx hidden power logic to HiddenPower.cs --- PKHeX.Core/Editing/HiddenPower.cs | 48 ++++++++++++++++++- PKHeX.Core/Editing/ShowdownSet.cs | 2 +- PKHeX.Core/PKM/PKM.cs | 12 ++--- PKHeX.Core/PKM/Util/PKX.cs | 45 ----------------- .../Controls/PKM Editor/StatEditor.cs | 2 +- 5 files changed, 55 insertions(+), 54 deletions(-) diff --git a/PKHeX.Core/Editing/HiddenPower.cs b/PKHeX.Core/Editing/HiddenPower.cs index 63de0c4b1..88eb00295 100644 --- a/PKHeX.Core/Editing/HiddenPower.cs +++ b/PKHeX.Core/Editing/HiddenPower.cs @@ -76,7 +76,7 @@ public static bool SetIVsForType(int hpVal, int[] IVs) { if (IVs.All(z => z == 31)) { - PKX.SetHPIVs(hpVal, IVs); // Get IVs + SetIVs(hpVal, IVs); // Get IVs return true; } @@ -131,5 +131,51 @@ private static IEnumerable> GetPermutations(ICollection lis return GetPermutations(list, length - 1) .SelectMany(list.Except, (t1, t2) => t1.Concat(new[] { t2 })); } + + /// Calculate the Hidden Power Type of the entered IVs. + /// Hidden Power Type + /// Individual Values (H/A/B/S/C/D) + /// Generation specific format + /// Hidden Power Type + public static int[] SetIVs(int type, int[] ivs, int format = PKX.Generation) + { + if (format <= 2) + { + ivs[1] = (ivs[1] & ~3) | (type >> 2); + ivs[2] = (ivs[2] & ~3) | (type & 3); + return ivs; + } + for (int i = 0; i < 6; i++) + ivs[i] = (ivs[i] & 0x1E) + DefaultLowBits[type, i]; + return ivs; + } + + /// + /// Hidden Power IV values (even or odd) to achieve a specified Hidden Power Type + /// + /// + /// There are other IV combinations to achieve the same Hidden Power Type. + /// These are just precomputed for fast modification. + /// Individual Values (H/A/B/S/C/D) + /// + public static readonly int[,] DefaultLowBits = + { + { 1, 1, 0, 0, 0, 0 }, // Fighting + { 0, 0, 0, 1, 0, 0 }, // Flying + { 1, 1, 0, 1, 0, 0 }, // Poison + { 1, 1, 1, 1, 0, 0 }, // Ground + { 1, 1, 0, 0, 1, 0 }, // Rock + { 1, 0, 0, 1, 1, 0 }, // Bug + { 1, 0, 1, 1, 1, 0 }, // Ghost + { 1, 1, 1, 1, 1, 0 }, // Steel + { 1, 0, 1, 0, 0, 1 }, // Fire + { 1, 0, 0, 1, 0, 1 }, // Water + { 1, 0, 1, 1, 0, 1 }, // Grass + { 1, 1, 1, 1, 0, 1 }, // Electric + { 1, 0, 1, 0, 1, 1 }, // Psychic + { 1, 0, 0, 1, 1, 1 }, // Ice + { 1, 0, 1, 1, 1, 1 }, // Dragon + { 1, 1, 1, 1, 1, 1 }, // Dark + }; } } diff --git a/PKHeX.Core/Editing/ShowdownSet.cs b/PKHeX.Core/Editing/ShowdownSet.cs index 3e946da80..f1cadbb1e 100644 --- a/PKHeX.Core/Editing/ShowdownSet.cs +++ b/PKHeX.Core/Editing/ShowdownSet.cs @@ -559,7 +559,7 @@ private string ParseLineMove(string line) } else if (hpVal >= 0) { - IVs = PKX.SetHPIVs(hpVal, IVs, Format); // Get IVs + IVs = HiddenPower.SetIVs(hpVal, IVs, Format); // Get IVs } else { diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index 61943bc1f..68b654cdc 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -500,12 +500,12 @@ public virtual int HPType get => 15 * HPVal / 63; set { - IV_HP = (IV_HP & ~1) + PKX.hpivs[value, 0]; - IV_ATK = (IV_ATK & ~1) + PKX.hpivs[value, 1]; - IV_DEF = (IV_DEF & ~1) + PKX.hpivs[value, 2]; - IV_SPE = (IV_SPE & ~1) + PKX.hpivs[value, 3]; - IV_SPA = (IV_SPA & ~1) + PKX.hpivs[value, 4]; - IV_SPD = (IV_SPD & ~1) + PKX.hpivs[value, 5]; + IV_HP = (IV_HP & ~1) + HiddenPower.DefaultLowBits[value, 0]; + IV_ATK = (IV_ATK & ~1) + HiddenPower.DefaultLowBits[value, 1]; + IV_DEF = (IV_DEF & ~1) + HiddenPower.DefaultLowBits[value, 2]; + IV_SPE = (IV_SPE & ~1) + HiddenPower.DefaultLowBits[value, 3]; + IV_SPA = (IV_SPA & ~1) + HiddenPower.DefaultLowBits[value, 4]; + IV_SPD = (IV_SPD & ~1) + HiddenPower.DefaultLowBits[value, 5]; } } diff --git a/PKHeX.Core/PKM/Util/PKX.cs b/PKHeX.Core/PKM/Util/PKX.cs index f4c0e6149..ce7deed44 100644 --- a/PKHeX.Core/PKM/Util/PKX.cs +++ b/PKHeX.Core/PKM/Util/PKX.cs @@ -578,51 +578,6 @@ public static string[] GetFormList(int species, IReadOnlyList types, IRe return FormConverter.GetFormList(species, types, forms, genders, generation); } - /// Calculate the Hidden Power Type of the entered IVs. - /// Hidden Power Type - /// Individual Values (H/A/B/S/C/D) - /// Generation specific format - /// Hidden Power Type - public static int[] SetHPIVs(int type, int[] ivs, int format = Generation) - { - if (format <= 2) - { - ivs[1] = (ivs[1] & ~3) | (type >> 2); - ivs[2] = (ivs[2] & ~3) | (type & 3); - return ivs; - } - for (int i = 0; i < 6; i++) - ivs[i] = (ivs[i] & 0x1E) + hpivs[type, i]; - return ivs; - } - - /// - /// Hidden Power IV values (even or odd) to achieve a specified Hidden Power Type - /// - /// - /// There are other IV combinations to achieve the same Hidden Power Type. - /// These are just precomputed for fast modification. - /// Individual Values (H/A/B/S/C/D) - /// - public static readonly int[,] hpivs = { - { 1, 1, 0, 0, 0, 0 }, // Fighting - { 0, 0, 0, 1, 0, 0 }, // Flying - { 1, 1, 0, 1, 0, 0 }, // Poison - { 1, 1, 1, 1, 0, 0 }, // Ground - { 1, 1, 0, 0, 1, 0 }, // Rock - { 1, 0, 0, 1, 1, 0 }, // Bug - { 1, 0, 1, 1, 1, 0 }, // Ghost - { 1, 1, 1, 1, 1, 0 }, // Steel - { 1, 0, 1, 0, 0, 1 }, // Fire - { 1, 0, 0, 1, 0, 1 }, // Water - { 1, 0, 1, 1, 0, 1 }, // Grass - { 1, 1, 1, 1, 0, 1 }, // Electric - { 1, 0, 1, 0, 1, 1 }, // Psychic - { 1, 0, 0, 1, 1, 1 }, // Ice - { 1, 0, 1, 1, 1, 1 }, // Dragon - { 1, 1, 1, 1, 1, 1 }, // Dark - }; - /// /// Gets the Unown Forme ID from PID. /// diff --git a/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs index 067b0ed43..891f7c1fb 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs @@ -246,7 +246,7 @@ private void UpdateHPType(object sender, EventArgs e) // Change IVs to match the new Hidden Power int hpower = WinFormsUtil.GetIndex(CB_HPType); - int[] newIVs = PKX.SetHPIVs(hpower, pkm.IVs, pkm.Format); + int[] newIVs = HiddenPower.SetIVs(hpower, pkm.IVs, pkm.Format); LoadIVs(newIVs); }