using System;
namespace PKHeX.Core
{
public interface IAwakened
{
int AV_HP { get; set; }
int AV_ATK { get; set; }
int AV_DEF { get; set; }
int AV_SPE { get; set; }
int AV_SPA { get; set; }
int AV_SPD { get; set; }
}
public static partial class Extensions
{
///
/// Sums all values.
///
/// Data to sum with
public static int AwakeningSum(this IAwakened pk) => pk.AV_HP + pk.AV_ATK + pk.AV_DEF + pk.AV_SPE + pk.AV_SPA + pk.AV_SPD;
///
/// Clears all values.
///
/// Data to clear from
public static void AwakeningClear(this IAwakened pk) => pk.AV_HP = pk.AV_ATK = pk.AV_DEF = pk.AV_SPE = pk.AV_SPA = pk.AV_SPD = 0;
///
/// Sets all values to the maximum value.
///
/// Data to clear from
public static void AwakeningMax(this IAwakened pk) => pk.AwakeningSetAllTo(Legal.AwakeningMax);
///
/// Sets all values to the specified value.
///
/// Data to clear from
/// Value to set all to
public static void AwakeningSetAllTo(this IAwakened pk, int value) => pk.AV_HP = pk.AV_ATK = pk.AV_DEF = pk.AV_SPE = pk.AV_SPA = pk.AV_SPD = value;
///
/// Gets if all values are within legal limits.
///
/// Data to check
public static bool AwakeningAllValid(this IAwakened pk)
{
if (pk.AV_HP > Legal.AwakeningMax)
return false;
if (pk.AV_ATK > Legal.AwakeningMax)
return false;
if (pk.AV_DEF > Legal.AwakeningMax)
return false;
if (pk.AV_SPE > Legal.AwakeningMax)
return false;
if (pk.AV_SPA > Legal.AwakeningMax)
return false;
if (pk.AV_SPD > Legal.AwakeningMax)
return false;
return true;
}
///
/// Sets one of the values based on its index within the array.
///
/// Pokémon to modify.
/// Index to set to
/// Value to set
public static void SetAV(this IAwakened pk, int index, int value)
{
switch (index)
{
case 0: pk.AV_HP = value; break;
case 1: pk.AV_ATK = value; break;
case 2: pk.AV_DEF = value; break;
case 3: pk.AV_SPE = value; break;
case 4: pk.AV_SPA = value; break;
case 5: pk.AV_SPD = value; break;
default:
throw new ArgumentOutOfRangeException(nameof(index));
}
}
///
/// Sets one of the values based on its index within the array.
///
/// Pokémon to check.
/// Index to get
public static int GetAV(this IAwakened pk, int index)
{
return index switch
{
0 => pk.AV_HP,
1 => pk.AV_ATK,
2 => pk.AV_DEF,
3 => pk.AV_SPE,
4 => pk.AV_SPA,
5 => pk.AV_SPD,
_ => throw new ArgumentOutOfRangeException(nameof(index))
};
}
///
/// Sets the values based on the current .
///
/// Accessor for setting the values
/// Retriever for IVs
public static void SetSuggestedAwakenedValues(this IAwakened a, PKM pk)
{
a.AV_HP = Legal.AwakeningMax;
a.AV_ATK = pk.IV_ATK == 0 ? 0 : Legal.AwakeningMax;
a.AV_DEF = Legal.AwakeningMax;
a.AV_SPE = pk.IV_SPE == 0 ? 0 : Legal.AwakeningMax;
a.AV_SPA = Legal.AwakeningMax;
a.AV_SPD = Legal.AwakeningMax;
}
public static bool IsAwakeningBelow(this IAwakened current, IAwakened initial) => !current.IsAwakeningAboveOrEqual(initial);
public static bool IsAwakeningAboveOrEqual(this IAwakened current, IAwakened initial)
{
if (current.AV_HP < initial.AV_HP)
return false;
if (current.AV_ATK < initial.AV_ATK)
return false;
if (current.AV_DEF < initial.AV_DEF)
return false;
if (current.AV_SPA < initial.AV_SPA)
return false;
if (current.AV_SPD < initial.AV_SPD)
return false;
if (current.AV_SPE < initial.AV_SPE)
return false;
return true;
}
}
}