From a00f3ed8949d6a65b1a28160925b1c6f2c4c0385 Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 2 Nov 2017 09:05:44 -0700 Subject: [PATCH] random IVs with specified count Closes #1553 removes duplicate logic in batch editor --- PKHeX.Core/PKM/PKM.cs | 22 +++++++++++++++---- .../Subforms/PKM Editors/BatchEditor.cs | 19 +++++----------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index 866c3bd94..d5f7c65d6 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -874,17 +874,31 @@ namespace PKHeX.Core for (int i = 0; i < 6; i++) ivs[i] = (int)(Util.Rand32() & MaxIV); - bool IV3 = GenNumber >= 6 && (Legal.Legends.Contains(Species) || Legal.SubLegends.Contains(Species)); - if (IV3) + int count = GetFlawlessIVCount(); + if (count != 0) { - for (int i = 0; i < 3; i++) + for (int i = 0; i < count; i++) ivs[i] = MaxIV; Util.Shuffle(ivs); // Randomize IV order } + IVs = ivs; return ivs; } - + + /// + /// Gets the amount of flawless IVs that the should have. + /// + /// Count of IVs that should be max. + public int GetFlawlessIVCount() + { + if (GenNumber >= 6 && (Legal.Legends.Contains(Species) || Legal.SubLegends.Contains(Species))) + return 3; + if (VC) + return Species == 151 || Species == 251 ? 5 : 3; + return 0; + } + /// /// Converts a or to . /// diff --git a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs index 26bce0d32..e23dda370 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs @@ -629,22 +629,13 @@ namespace PKHeX.WinForms } private static void SetRandomIVs(PKM PKM, StringInstruction cmd) { - int MaxIV = PKM.Format <= 2 ? 15 : 31; - if (cmd.PropertyName == "IVs") + if (cmd.PropertyName == nameof(PKM.IVs)) { - int[] IVs = new int[6]; - - for (int i = 0; i < 6; i++) - IVs[i] = (int)(Util.Rand32() & MaxIV); - if (Legal.Legends.Contains(PKM.Species) || Legal.SubLegends.Contains(PKM.Species)) - for (int i = 0; i < 3; i++) - IVs[i] = MaxIV; - - Util.Shuffle(IVs); - PKM.IVs = IVs; + PKM.SetRandomIVs(); + return; } - else - ReflectFrameworkUtil.SetValue(PKM, cmd.PropertyName, Util.Rand32() & MaxIV); + int MaxIV = PKM.Format <= 2 ? 15 : 31; + ReflectFrameworkUtil.SetValue(PKM, cmd.PropertyName, Util.Rand32() & MaxIV); } }