Move pkx hidden power logic to HiddenPower.cs

This commit is contained in:
Kurt 2019-03-16 12:07:22 -07:00
parent 13a6d16cb9
commit 9ca4ef1e09
5 changed files with 55 additions and 54 deletions

View file

@ -76,7 +76,7 @@ namespace PKHeX.Core
{
if (IVs.All(z => z == 31))
{
PKX.SetHPIVs(hpVal, IVs); // Get IVs
SetIVs(hpVal, IVs); // Get IVs
return true;
}
@ -131,5 +131,51 @@ namespace PKHeX.Core
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
};
}
}

View file

@ -559,7 +559,7 @@ namespace PKHeX.Core
}
else if (hpVal >= 0)
{
IVs = PKX.SetHPIVs(hpVal, IVs, Format); // Get IVs
IVs = HiddenPower.SetIVs(hpVal, IVs, Format); // Get IVs
}
else
{

View file

@ -500,12 +500,12 @@ namespace PKHeX.Core
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];
}
}

View file

@ -578,51 +578,6 @@ namespace PKHeX.Core
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>

View file

@ -246,7 +246,7 @@ namespace PKHeX.WinForms.Controls
// 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);
}