2022-08-27 06:43:36 +00:00
|
|
|
namespace PKHeX.Core;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Indicates or coerces values pertaining to <see cref="Species.Wurmple"/> and its branched evolutions.
|
|
|
|
/// </summary>
|
|
|
|
public static class WurmpleUtil
|
2019-05-11 21:25:58 +00:00
|
|
|
{
|
2022-01-08 17:54:32 +00:00
|
|
|
/// <summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// Gets the Wurmple Evolution Value for a given <see cref="PKM.EncryptionConstant"/>
|
2022-01-08 17:54:32 +00:00
|
|
|
/// </summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <param name="encryptionConstant">Encryption Constant</param>
|
|
|
|
/// <returns>Wurmple Evolution Value</returns>
|
2023-08-28 06:05:50 +00:00
|
|
|
public static WurmpleEvolution GetWurmpleEvoVal(uint encryptionConstant)
|
2019-05-11 21:25:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var evoVal = encryptionConstant >> 16;
|
2023-08-28 06:05:50 +00:00
|
|
|
return (WurmpleEvolution)(evoVal % 10 / 5);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-05-11 21:25:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the evo chain of Wurmple
|
|
|
|
/// </summary>
|
2023-08-28 06:05:50 +00:00
|
|
|
/// <param name="species">Current species, must be evolved from Wurmple.</param>
|
|
|
|
public static WurmpleEvolution GetWurmpleEvoGroup(ushort species)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
int wIndex = species - (int)Species.Silcoon;
|
|
|
|
if ((wIndex & 3) != wIndex) // Wurmple evo, [0,3]
|
2023-08-28 06:05:50 +00:00
|
|
|
return WurmpleEvolution.None;
|
|
|
|
return (WurmpleEvolution)(wIndex >> 1); // Silcoon, Cascoon
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-05-11 21:25:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the Wurmple <see cref="PKM.EncryptionConstant"/> for a given Evolution Value
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="evoVal">Wurmple Evolution Value</param>
|
|
|
|
/// <remarks>0 = Silcoon, 1 = Cascoon</remarks>
|
|
|
|
/// <returns>Encryption Constant</returns>
|
2023-08-28 06:05:50 +00:00
|
|
|
public static uint GetWurmpleEncryptionConstant(WurmpleEvolution evoVal)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
uint result;
|
|
|
|
var rnd = Util.Rand;
|
|
|
|
do result = rnd.Rand32();
|
|
|
|
while (evoVal != GetWurmpleEvoVal(result));
|
|
|
|
return result;
|
|
|
|
}
|
2019-05-11 21:25:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks to see if the input <see cref="pk"/>, with species being that of Wurmple's evo chain, is valid.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="pk">Pokémon data</param>
|
|
|
|
/// <returns>True if valid, false if invalid</returns>
|
|
|
|
public static bool IsWurmpleEvoValid(PKM pk)
|
|
|
|
{
|
2023-08-28 06:05:50 +00:00
|
|
|
var evoVal = GetWurmpleEvoVal(pk.EncryptionConstant);
|
|
|
|
var wIndex = GetWurmpleEvoGroup(pk.Species);
|
2022-06-18 18:04:24 +00:00
|
|
|
return evoVal == wIndex;
|
2019-05-11 21:25:58 +00:00
|
|
|
}
|
2022-01-08 17:54:32 +00:00
|
|
|
}
|
2023-08-28 06:05:50 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Indicates the evolution of Wurmple
|
|
|
|
/// </summary>
|
|
|
|
public enum WurmpleEvolution
|
|
|
|
{
|
|
|
|
/// <summary> Invalid value </summary>
|
|
|
|
None = -1,
|
|
|
|
|
|
|
|
/// <summary> Evolves into Silcoon/Beautifly </summary>
|
|
|
|
Silcoon = 0,
|
|
|
|
|
|
|
|
/// <summary> Evolves into Cascoon/Dustox </summary>
|
|
|
|
Cascoon = 1,
|
|
|
|
}
|