mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-07 18:16:36 -05:00
Move pkx hidden power logic to HiddenPower.cs
This commit is contained in:
@@ -76,7 +76,7 @@ public static bool SetIVsForType(int hpVal, int[] IVs)
|
||||
{
|
||||
if (IVs.All(z => z == 31))
|
||||
{
|
||||
PKX.SetHPIVs(hpVal, IVs); // Get IVs
|
||||
SetIVs(hpVal, IVs); // Get IVs
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -131,5 +131,51 @@ private static IEnumerable<IEnumerable<T>> GetPermutations<T>(ICollection<T> lis
|
||||
return GetPermutations(list, length - 1)
|
||||
.SelectMany(list.Except, (t1, t2) => t1.Concat(new[] { t2 }));
|
||||
}
|
||||
|
||||
/// <summary>Calculate the Hidden Power Type of the entered IVs.</summary>
|
||||
/// <param name="type">Hidden Power Type</param>
|
||||
/// <param name="ivs">Individual Values (H/A/B/S/C/D)</param>
|
||||
/// <param name="format">Generation specific format</param>
|
||||
/// <returns>Hidden Power Type</returns>
|
||||
public static int[] SetIVs(int type, int[] ivs, int format = PKX.Generation)
|
||||
{
|
||||
if (format <= 2)
|
||||
{
|
||||
ivs[1] = (ivs[1] & ~3) | (type >> 2);
|
||||
ivs[2] = (ivs[2] & ~3) | (type & 3);
|
||||
return ivs;
|
||||
}
|
||||
for (int i = 0; i < 6; i++)
|
||||
ivs[i] = (ivs[i] & 0x1E) + DefaultLowBits[type, i];
|
||||
return ivs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hidden Power IV values (even or odd) to achieve a specified Hidden Power Type
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// There are other IV combinations to achieve the same Hidden Power Type.
|
||||
/// These are just precomputed for fast modification.
|
||||
/// Individual Values (H/A/B/S/C/D)
|
||||
/// </remarks>
|
||||
public static readonly int[,] DefaultLowBits =
|
||||
{
|
||||
{ 1, 1, 0, 0, 0, 0 }, // Fighting
|
||||
{ 0, 0, 0, 1, 0, 0 }, // Flying
|
||||
{ 1, 1, 0, 1, 0, 0 }, // Poison
|
||||
{ 1, 1, 1, 1, 0, 0 }, // Ground
|
||||
{ 1, 1, 0, 0, 1, 0 }, // Rock
|
||||
{ 1, 0, 0, 1, 1, 0 }, // Bug
|
||||
{ 1, 0, 1, 1, 1, 0 }, // Ghost
|
||||
{ 1, 1, 1, 1, 1, 0 }, // Steel
|
||||
{ 1, 0, 1, 0, 0, 1 }, // Fire
|
||||
{ 1, 0, 0, 1, 0, 1 }, // Water
|
||||
{ 1, 0, 1, 1, 0, 1 }, // Grass
|
||||
{ 1, 1, 1, 1, 0, 1 }, // Electric
|
||||
{ 1, 0, 1, 0, 1, 1 }, // Psychic
|
||||
{ 1, 0, 0, 1, 1, 1 }, // Ice
|
||||
{ 1, 0, 1, 1, 1, 1 }, // Dragon
|
||||
{ 1, 1, 1, 1, 1, 1 }, // Dark
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ private string ParseLineMove(string line)
|
||||
}
|
||||
else if (hpVal >= 0)
|
||||
{
|
||||
IVs = PKX.SetHPIVs(hpVal, IVs, Format); // Get IVs
|
||||
IVs = HiddenPower.SetIVs(hpVal, IVs, Format); // Get IVs
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -500,12 +500,12 @@ public virtual int HPType
|
||||
get => 15 * HPVal / 63;
|
||||
set
|
||||
{
|
||||
IV_HP = (IV_HP & ~1) + PKX.hpivs[value, 0];
|
||||
IV_ATK = (IV_ATK & ~1) + PKX.hpivs[value, 1];
|
||||
IV_DEF = (IV_DEF & ~1) + PKX.hpivs[value, 2];
|
||||
IV_SPE = (IV_SPE & ~1) + PKX.hpivs[value, 3];
|
||||
IV_SPA = (IV_SPA & ~1) + PKX.hpivs[value, 4];
|
||||
IV_SPD = (IV_SPD & ~1) + PKX.hpivs[value, 5];
|
||||
IV_HP = (IV_HP & ~1) + HiddenPower.DefaultLowBits[value, 0];
|
||||
IV_ATK = (IV_ATK & ~1) + HiddenPower.DefaultLowBits[value, 1];
|
||||
IV_DEF = (IV_DEF & ~1) + HiddenPower.DefaultLowBits[value, 2];
|
||||
IV_SPE = (IV_SPE & ~1) + HiddenPower.DefaultLowBits[value, 3];
|
||||
IV_SPA = (IV_SPA & ~1) + HiddenPower.DefaultLowBits[value, 4];
|
||||
IV_SPD = (IV_SPD & ~1) + HiddenPower.DefaultLowBits[value, 5];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -578,51 +578,6 @@ public static string[] GetFormList(int species, IReadOnlyList<string> types, IRe
|
||||
return FormConverter.GetFormList(species, types, forms, genders, generation);
|
||||
}
|
||||
|
||||
/// <summary>Calculate the Hidden Power Type of the entered IVs.</summary>
|
||||
/// <param name="type">Hidden Power Type</param>
|
||||
/// <param name="ivs">Individual Values (H/A/B/S/C/D)</param>
|
||||
/// <param name="format">Generation specific format</param>
|
||||
/// <returns>Hidden Power Type</returns>
|
||||
public static int[] SetHPIVs(int type, int[] ivs, int format = Generation)
|
||||
{
|
||||
if (format <= 2)
|
||||
{
|
||||
ivs[1] = (ivs[1] & ~3) | (type >> 2);
|
||||
ivs[2] = (ivs[2] & ~3) | (type & 3);
|
||||
return ivs;
|
||||
}
|
||||
for (int i = 0; i < 6; i++)
|
||||
ivs[i] = (ivs[i] & 0x1E) + hpivs[type, i];
|
||||
return ivs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hidden Power IV values (even or odd) to achieve a specified Hidden Power Type
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// There are other IV combinations to achieve the same Hidden Power Type.
|
||||
/// These are just precomputed for fast modification.
|
||||
/// Individual Values (H/A/B/S/C/D)
|
||||
/// </remarks>
|
||||
public static readonly int[,] hpivs = {
|
||||
{ 1, 1, 0, 0, 0, 0 }, // Fighting
|
||||
{ 0, 0, 0, 1, 0, 0 }, // Flying
|
||||
{ 1, 1, 0, 1, 0, 0 }, // Poison
|
||||
{ 1, 1, 1, 1, 0, 0 }, // Ground
|
||||
{ 1, 1, 0, 0, 1, 0 }, // Rock
|
||||
{ 1, 0, 0, 1, 1, 0 }, // Bug
|
||||
{ 1, 0, 1, 1, 1, 0 }, // Ghost
|
||||
{ 1, 1, 1, 1, 1, 0 }, // Steel
|
||||
{ 1, 0, 1, 0, 0, 1 }, // Fire
|
||||
{ 1, 0, 0, 1, 0, 1 }, // Water
|
||||
{ 1, 0, 1, 1, 0, 1 }, // Grass
|
||||
{ 1, 1, 1, 1, 0, 1 }, // Electric
|
||||
{ 1, 0, 1, 0, 1, 1 }, // Psychic
|
||||
{ 1, 0, 0, 1, 1, 1 }, // Ice
|
||||
{ 1, 0, 1, 1, 1, 1 }, // Dragon
|
||||
{ 1, 1, 1, 1, 1, 1 }, // Dark
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Unown Forme ID from PID.
|
||||
/// </summary>
|
||||
|
||||
@@ -246,7 +246,7 @@ private void UpdateHPType(object sender, EventArgs e)
|
||||
|
||||
// Change IVs to match the new Hidden Power
|
||||
int hpower = WinFormsUtil.GetIndex(CB_HPType);
|
||||
int[] newIVs = PKX.SetHPIVs(hpower, pkm.IVs, pkm.Format);
|
||||
int[] newIVs = HiddenPower.SetIVs(hpower, pkm.IVs, pkm.Format);
|
||||
LoadIVs(newIVs);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user