Add move rand for batch editor

Also add Move Rand & Move Reset to box modify contextmenu
This commit is contained in:
Kurt
2018-05-20 14:29:13 -07:00
parent c103220e0c
commit 199b6f2caf
5 changed files with 47 additions and 14 deletions

View File

@@ -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;
}
}
/// <summary>
/// Sets the provided moves in a random order.
/// </summary>
/// <param name="pkm">Pokémon to modify.</param>
/// <param name="moves">Moves to apply.</param>
private static ModifyResult SetMoves(PKM pkm, int[] moves)
{
pkm.SetMoves(moves);
return ModifyResult.Modified;
}
/// <summary>
/// Sets the <see cref="PKM"/> byte array propery to a specified value.
/// </summary>

View File

@@ -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();
}
}

View File

@@ -571,6 +571,30 @@ public static void MaximizeLevel(this PKM pkm)
pkm.CurrentLevel = 100;
}
/// <summary>
/// Gets a moveset for the provided <see cref="PKM"/> data.
/// </summary>
/// <param name="pkm">PKM to generate for</param>
/// <param name="random">Full movepool & shuffling</param>
/// <param name="la">Precomputed optional</param>
/// <returns>4 moves</returns>
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;
}
/// <summary>
/// Sets the Memory details to a Hatched Egg's memories.
/// </summary>
@@ -584,6 +608,10 @@ public static void SetHatchMemory6(this PKM pk)
pk.OT_TextVar = pk.XY ? 43 : 27; // riverside road : battling spot
}
/// <summary>
/// Sets a random memory specific to <see cref="GameVersion.Gen6"/> locality.
/// </summary>
/// <param name="pk">Pokémon to modify.</param>
public static void SetRandomMemory6(this PKM pk)
{
// for lack of better randomization :)

View File

@@ -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;

View File

@@ -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)