Add IAwakened interface for future PB7 format

This commit is contained in:
Kurt 2018-11-10 20:21:36 -08:00
parent ebd1155bfc
commit 113eb550d4
2 changed files with 121 additions and 0 deletions

View file

@ -314,6 +314,9 @@ namespace PKHeX.Core
pk.SetIsShiny(Set.Shiny); pk.SetIsShiny(Set.Shiny);
pk.SetRandomEC(); pk.SetRandomEC();
if (pk is IAwakened a)
a.SetSuggestedAwakenedValues(pk);
var legal = new LegalityAnalysis(pk); var legal = new LegalityAnalysis(pk);
if (legal.Parsed && legal.Info.Relearn.Any(z => !z.Valid)) if (legal.Parsed && legal.Info.Relearn.Any(z => !z.Valid))
pk.RelearnMoves = pk.GetSuggestedRelearnMoves(legal); pk.RelearnMoves = pk.GetSuggestedRelearnMoves(legal);

View file

@ -0,0 +1,118 @@
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
{
/// <summary>
/// Sums all values.
/// </summary>
/// <param name="pk">Data to sum with</param>
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;
/// <summary>
/// Clears all values.
/// </summary>
/// <param name="pk">Data to clear from</param>
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;
/// <summary>
/// Sets all values to the maximum value.
/// </summary>
/// <param name="pk">Data to clear from</param>
public static void AwakeningMax(this IAwakened pk) => pk.AwakeningSetAllTo(Legal.AwakeningMax);
/// <summary>
/// Sets all values to the specified value.
/// </summary>
/// <param name="pk">Data to clear from</param>
/// <param name="value">Value to set all to</param>
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;
/// <summary>
/// Gets if all values are within legal limits.
/// </summary>
/// <param name="pk">Data to check</param>
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;
}
/// <summary>
/// Sets one of the <see cref="IAwakened"/> values based on its index within the array.
/// </summary>
/// <param name="pk">Pokémon to modify.</param>
/// <param name="index">Index to set to</param>
/// <param name="value">Value to set</param>
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));
}
}
/// <summary>
/// Sets one of the <see cref="IAwakened"/> values based on its index within the array.
/// </summary>
/// <param name="pk">Pokémon to check.</param>
/// <param name="index">Index to get</param>
public static int GetAV(this IAwakened pk, int index)
{
switch (index)
{
case 0: return pk.AV_HP;
case 1: return pk.AV_ATK;
case 2: return pk.AV_DEF;
case 3: return pk.AV_SPE;
case 4: return pk.AV_SPA;
case 5: return pk.AV_SPD;
default:
throw new ArgumentOutOfRangeException(nameof(index));
}
}
/// <summary>
/// Sets the values based on the current <see cref="PKM.IVs"/>.
/// </summary>
/// <param name="a">Accessor for setting the values</param>
/// <param name="pk">Retriever for IVs</param>
public static void SetSuggestedAwakenedValues(this IAwakened a, PKM pk)
{
for (int i = 0; i < 6; i++)
{
if (pk.GetIV(i) > 2)
a.SetAV(i, 200);
}
}
}
}