random IVs with specified count

Closes #1553
removes duplicate logic in batch editor
This commit is contained in:
Kurt 2017-11-02 09:05:44 -07:00
parent 008605c4ff
commit a00f3ed894
2 changed files with 23 additions and 18 deletions

View file

@ -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;
}
/// <summary>
/// Gets the amount of flawless IVs that the <see cref="PKM"/> should have.
/// </summary>
/// <returns>Count of IVs that should be max.</returns>
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;
}
/// <summary>
/// Converts a <see cref="XK3"/> or <see cref="PK3"/> to <see cref="CK3"/>.
/// </summary>

View file

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