From 186e6f1196685eed309fbdfa5955f745e6b20f1d Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 27 Nov 2016 09:26:58 -0800 Subject: [PATCH] Add legend IV3 randomization Closes #511 --- PKHeX/Legality/Tables.cs | 15 +++++++++++++++ PKHeX/MainWindow/Main.cs | 17 +++++++++++------ PKHeX/Subforms/PKM Editors/BatchEditor.cs | 15 ++++++++++++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/PKHeX/Legality/Tables.cs b/PKHeX/Legality/Tables.cs index f345fd16b..1e41ab86a 100644 --- a/PKHeX/Legality/Tables.cs +++ b/PKHeX/Legality/Tables.cs @@ -196,6 +196,21 @@ public static partial class Legal 719, }; + internal static readonly int[] Legends = + { + 150, 151, 249, 250, 251, 382, 383, 384, 385, 386, 483, + 484, 487, 489, 490, 491, 492, 493, 494, 643, 644, 646, + 647, 648, 649, 716, 717, 718, 719, 720, 721, 789, 790, + 791, 792, 800, 801, 802 + }; + internal static readonly int[] SubLegends = + { + 144, 145, 146, 243, 244, 245, 377, 378, 379, 380, 381, + 480, 481, 482, 485, 486, 488, 638, 639, 640, 641, 642, + 645, 772, 773, 787, 788, 785, 786, 793, 794, 795, 796, + 797, 798, 799 + }; + #region Games internal static readonly int[] Games_7sm = { 30, 31 }; diff --git a/PKHeX/MainWindow/Main.cs b/PKHeX/MainWindow/Main.cs index 328bb31e6..c8be4ba16 100644 --- a/PKHeX/MainWindow/Main.cs +++ b/PKHeX/MainWindow/Main.cs @@ -2045,12 +2045,17 @@ private void updateRandomIVs(object sender, EventArgs e) } else { - TB_HPIV.Text = (Util.rnd32() % SAV.MaxIV).ToString(); - TB_ATKIV.Text = (Util.rnd32() % SAV.MaxIV).ToString(); - TB_DEFIV.Text = (Util.rnd32() % SAV.MaxIV).ToString(); - TB_SPAIV.Text = (Util.rnd32() % SAV.MaxIV).ToString(); - TB_SPDIV.Text = (Util.rnd32() % SAV.MaxIV).ToString(); - TB_SPEIV.Text = (Util.rnd32() % SAV.MaxIV).ToString(); + bool IV3 = Legal.Legends.Contains(pkm.Species) || Legal.SubLegends.Contains(pkm.Species); + int[] IVs = new int[6]; + do + { + for (int i = 0; i < 6; i++) + IVs[i] = (int)(Util.rnd32() & SAV.MaxIV); + } while (IV3 && IVs.Where(i => i == SAV.MaxIV).Count() < 3); + + var IVBoxes = new[] {TB_HPIV, TB_ATKIV, TB_DEFIV, TB_SPAIV, TB_SPDIV, TB_SPEIV}; + for (int i = 0; i < 6; i++) + IVBoxes[i].Text = IVs[i].ToString(); } changingFields = false; updateIVs(null, e); diff --git a/PKHeX/Subforms/PKM Editors/BatchEditor.cs b/PKHeX/Subforms/PKM Editors/BatchEditor.cs index a9b770144..144a45cdd 100644 --- a/PKHeX/Subforms/PKM Editors/BatchEditor.cs +++ b/PKHeX/Subforms/PKM Editors/BatchEditor.cs @@ -332,11 +332,20 @@ private static ModifyResult ProcessPKM(PKM PKM, IEnumerable F } private static void setRandomIVs(PKM PKM, StringInstruction cmd) { - int MaxIVs = PKM.Format <= 2 ? 15 : 31; + int MaxIV = PKM.Format <= 2 ? 15 : 31; if (cmd.PropertyName == "IVs") - ReflectUtil.SetValue(PKM, cmd.PropertyName, new byte[6].Select(i => (int)Util.rnd32() & MaxIVs).ToArray()); + { + bool IV3 = Legal.Legends.Contains(PKM.Species) || Legal.SubLegends.Contains(PKM.Species); + int[] IVs = new int[6]; + do + { + for (int i = 0; i < 6; i++) + IVs[i] = (int)(Util.rnd32() & MaxIV); + } while (IV3 && IVs.Where(i => i == MaxIV).Count() < 3); + ReflectUtil.SetValue(PKM, cmd.PropertyName, IVs); + } else - ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32() & MaxIVs); + ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32() & MaxIV); } private void B_Add_Click(object sender, EventArgs e)