diff --git a/PKHeX.Core/Editing/Bulk/BatchEditing.cs b/PKHeX.Core/Editing/Bulk/BatchEditing.cs index c4cf2746a..896a306fc 100644 --- a/PKHeX.Core/Editing/Bulk/BatchEditing.cs +++ b/PKHeX.Core/Editing/Bulk/BatchEditing.cs @@ -232,6 +232,8 @@ private static ModifyResult SetPKMProperty(StringInstruction cmd, PKMInfo info, if (cmd.PropertyValue == CONST_SUGGEST) return SetSuggestedPKMProperty(cmd.PropertyName, info); + if (cmd.PropertyValue == CONST_RAND && cmd.PropertyName == nameof(PKM.Moves)) + return SetMoves(pkm, pkm.GetMoveSet(true, info.Legality)); if (SetComplexProperty(pkm, cmd)) return ModifyResult.Modified; @@ -349,16 +351,24 @@ private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info) return ModifyResult.Modified; case nameof(PKM.Moves): - var moves = info.SuggestedMoves; - Util.Shuffle(moves); - PKM.SetMoves(moves); - return ModifyResult.Modified; + return SetMoves(PKM, PKM.GetMoveSet(la: info.Legality)); default: return ModifyResult.Error; } } + /// + /// Sets the provided moves in a random order. + /// + /// Pokémon to modify. + /// Moves to apply. + private static ModifyResult SetMoves(PKM pkm, int[] moves) + { + pkm.SetMoves(moves); + return ModifyResult.Modified; + } + /// /// Sets the byte array propery to a specified value. /// diff --git a/PKHeX.Core/Editing/Bulk/PKMInfo.cs b/PKHeX.Core/Editing/Bulk/PKMInfo.cs index cc878a242..f73d5d1a1 100644 --- a/PKHeX.Core/Editing/Bulk/PKMInfo.cs +++ b/PKHeX.Core/Editing/Bulk/PKMInfo.cs @@ -6,11 +6,10 @@ internal sealed class PKMInfo internal PKMInfo(PKM pk) { pkm = pk; } private LegalityAnalysis la; - private LegalityAnalysis Legality => la ?? (la = new LegalityAnalysis(pkm)); + internal LegalityAnalysis Legality => la ?? (la = new LegalityAnalysis(pkm)); - internal bool Legal => Legality.Valid; + public bool Legal => Legality.Valid; internal int[] SuggestedRelearn => Legality.GetSuggestedRelearn(); - internal int[] SuggestedMoves => Legality.GetSuggestedMoves(tm: true, tutor: true, reminder: false); internal EncounterStatic SuggestedEncounter => Legality.GetSuggestedMetInfo(); } } \ No newline at end of file diff --git a/PKHeX.Core/Editing/CommonEdits.cs b/PKHeX.Core/Editing/CommonEdits.cs index 967a31603..2700ce665 100644 --- a/PKHeX.Core/Editing/CommonEdits.cs +++ b/PKHeX.Core/Editing/CommonEdits.cs @@ -571,6 +571,30 @@ public static void MaximizeLevel(this PKM pkm) pkm.CurrentLevel = 100; } + /// + /// Gets a moveset for the provided data. + /// + /// PKM to generate for + /// Full movepool & shuffling + /// Precomputed optional + /// 4 moves + public static int[] GetMoveSet(this PKM pkm, bool random = false, LegalityAnalysis la = null) + { + if (la == null) + la = new LegalityAnalysis(pkm); + int[] m = la.GetSuggestedMoves(tm: random, tutor: random, reminder: random); + if (m == null) + return null; + if (random) + Util.Shuffle(m); + + const int count = 4; + if (m.Length > count) + return m.Skip(m.Length - count).ToArray(); + Array.Resize(ref m, count); + return m; + } + /// /// Sets the Memory details to a Hatched Egg's memories. /// @@ -584,6 +608,10 @@ public static void SetHatchMemory6(this PKM pk) pk.OT_TextVar = pk.XY ? 43 : 27; // riverside road : battling spot } + /// + /// Sets a random memory specific to locality. + /// + /// Pokémon to modify. public static void SetRandomMemory6(this PKM pk) { // for lack of better randomization :) diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index e260b9f3b..7ce89fa9d 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -638,7 +638,7 @@ private void ClickMoves(object sender, EventArgs e) } private bool SetSuggestedMoves(bool random = false, bool silent = false) { - int[] m = Legality.GetSuggestedMoves(tm: random, tutor: random, reminder: random); + int[] m = pkm.GetMoveSet(random); if (m == null) { if (!silent) @@ -646,12 +646,6 @@ private bool SetSuggestedMoves(bool random = false, bool silent = false) return false; } - if (random) - Util.Shuffle(m); - if (m.Length > 4) - m = m.Skip(m.Length - 4).ToArray(); - Array.Resize(ref m, 4); - if (pkm.Moves.SequenceEqual(m)) return false; diff --git a/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs b/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs index aed993fd3..07b3fa2cb 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs @@ -59,6 +59,8 @@ Image GetImage(Level l) AddItem(Level.Modify, GetItem("HatchEggs", "Hatch Eggs", () => Modify(z => z.ForceHatchPKM()), Resources.about)); AddItem(Level.Modify, GetItem("MaxFriendship", "Max Friendship", () => Modify(z => z.MaximizeFriendship()), Resources.heart)); AddItem(Level.Modify, GetItem("MaxLevel", "Max Level", () => Modify(z => z.MaximizeLevel()), Resources.showdown)); + AddItem(Level.Modify, GetItem("Reset Moves", "Reset Moves", () => Modify(z => z.SetMoves(z.GetMoveSet())), Resources.date)); + AddItem(Level.Modify, GetItem("RandomMoves", "Randomize Moves", () => Modify(z => z.SetMoves(z.GetMoveSet(true))), Resources.wand)); AddItem(Level.Modify, GetItem("RemoveItem", "Delete Held Item", () => Modify(z => z.HeldItem = 0), Resources.gift)); void AddItem(Level v, ToolStripItem t)