2018-06-06 04:31:42 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
public interface IHyperTrain
|
|
|
|
|
{
|
2022-03-06 20:01:47 +00:00
|
|
|
|
byte HyperTrainFlags { get; set; }
|
2018-06-06 04:31:42 +00:00
|
|
|
|
bool HT_HP { get; set; }
|
|
|
|
|
bool HT_ATK { get; set; }
|
|
|
|
|
bool HT_DEF { get; set; }
|
|
|
|
|
bool HT_SPA { get; set; }
|
|
|
|
|
bool HT_SPD { get; set; }
|
|
|
|
|
bool HT_SPE { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static partial class Extensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Toggles the Hyper Training flag for a given stat.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="t">Hyper Trainable object</param>
|
|
|
|
|
/// <param name="index">Battle Stat (H/A/B/S/C/D)</param>
|
|
|
|
|
/// <returns>Final Hyper Training Flag value</returns>
|
2021-01-02 00:39:33 +00:00
|
|
|
|
public static bool HyperTrainInvert(this IHyperTrain t, int index) => index switch
|
2018-06-06 04:31:42 +00:00
|
|
|
|
{
|
2021-01-02 00:39:33 +00:00
|
|
|
|
0 => t.HT_HP ^= true,
|
|
|
|
|
1 => t.HT_ATK ^= true,
|
|
|
|
|
2 => t.HT_DEF ^= true,
|
|
|
|
|
3 => t.HT_SPE ^= true,
|
|
|
|
|
4 => t.HT_SPA ^= true,
|
|
|
|
|
5 => t.HT_SPD ^= true,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => false,
|
2021-01-02 00:39:33 +00:00
|
|
|
|
};
|
2018-06-06 04:31:42 +00:00
|
|
|
|
|
2019-01-07 00:21:34 +00:00
|
|
|
|
public static bool IsHyperTrainedAll(this IHyperTrain t) => t.HyperTrainFlags == 0x3F;
|
2018-06-06 04:31:42 +00:00
|
|
|
|
public static void HyperTrainClear(this IHyperTrain t) => t.HyperTrainFlags = 0;
|
|
|
|
|
public static bool IsHyperTrained(this IHyperTrain t) => t.HyperTrainFlags != 0;
|
2018-07-29 20:27:48 +00:00
|
|
|
|
|
2018-06-06 04:31:42 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets one of the <see cref="IHyperTrain"/> values based on its index within the array.
|
|
|
|
|
/// </summary>
|
2021-01-02 00:39:33 +00:00
|
|
|
|
/// <param name="t">Entity to check.</param>
|
2018-06-06 04:31:42 +00:00
|
|
|
|
/// <param name="index">Index to get</param>
|
2021-01-02 00:39:33 +00:00
|
|
|
|
public static bool IsHyperTrained(this IHyperTrain t, int index) => index switch
|
2018-06-06 04:31:42 +00:00
|
|
|
|
{
|
2021-01-02 00:39:33 +00:00
|
|
|
|
0 => t.HT_HP,
|
|
|
|
|
1 => t.HT_ATK,
|
|
|
|
|
2 => t.HT_DEF,
|
|
|
|
|
3 => t.HT_SPE,
|
|
|
|
|
4 => t.HT_SPA,
|
|
|
|
|
5 => t.HT_SPD,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index)),
|
2021-01-02 00:39:33 +00:00
|
|
|
|
};
|
2018-06-06 04:31:42 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets <see cref="IHyperTrain.HyperTrainFlags"/> to valid values which may best enhance the <see cref="PKM"/> stats.
|
|
|
|
|
/// </summary>
|
2022-06-12 16:26:45 +00:00
|
|
|
|
/// <param name="pk"></param>
|
|
|
|
|
/// <param name="h">History of evolutions present as</param>
|
2018-06-06 04:31:42 +00:00
|
|
|
|
/// <param name="IVs"><see cref="PKM.IVs"/> to use (if already known). Will fetch the current <see cref="PKM.IVs"/> if not provided.</param>
|
2022-06-13 07:04:20 +00:00
|
|
|
|
public static void SetSuggestedHyperTrainingData(this PKM pk, EvolutionHistory h, ReadOnlySpan<int> IVs)
|
2018-06-06 04:31:42 +00:00
|
|
|
|
{
|
2022-06-12 16:26:45 +00:00
|
|
|
|
if (pk is not IHyperTrain t)
|
2018-06-06 04:31:42 +00:00
|
|
|
|
return;
|
2022-06-12 16:26:45 +00:00
|
|
|
|
if (!pk.IsHyperTrainingAvailable(h))
|
2018-06-06 04:31:42 +00:00
|
|
|
|
{
|
|
|
|
|
t.HyperTrainFlags = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.HT_HP = IVs[0] != 31;
|
|
|
|
|
t.HT_ATK = IVs[1] != 31 && IVs[1] > 2;
|
|
|
|
|
t.HT_DEF = IVs[2] != 31;
|
|
|
|
|
t.HT_SPA = IVs[4] != 31;
|
|
|
|
|
t.HT_SPD = IVs[5] != 31;
|
2018-11-21 20:31:05 +00:00
|
|
|
|
|
2020-08-15 04:49:01 +00:00
|
|
|
|
// sometimes unusual speed IVs are desirable for competitive reasons
|
|
|
|
|
// if nothing else was HT'd and the IV isn't too high, it was probably intentional
|
|
|
|
|
t.HT_SPE = IVs[3] != 31 && IVs[3] > 2 &&
|
|
|
|
|
(IVs[3] > 17 || t.HT_HP || t.HT_ATK || t.HT_DEF || t.HT_SPA || t.HT_SPD);
|
|
|
|
|
|
2022-06-12 16:26:45 +00:00
|
|
|
|
if (pk is ICombatPower pb)
|
2018-11-21 20:31:05 +00:00
|
|
|
|
pb.ResetCP();
|
2018-06-06 04:31:42 +00:00
|
|
|
|
}
|
2022-02-05 01:35:15 +00:00
|
|
|
|
|
2022-06-13 07:04:20 +00:00
|
|
|
|
/// <inheritdoc cref="SetSuggestedHyperTrainingData(PKM,EvolutionHistory,ReadOnlySpan{int})"/>
|
2022-06-12 16:26:45 +00:00
|
|
|
|
public static void SetSuggestedHyperTrainingData(this PKM pk, int[]? IVs = null) => pk.SetSuggestedHyperTrainingData(EvolutionHistory.Empty, IVs ?? pk.IVs);
|
|
|
|
|
|
2022-02-05 01:35:15 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if Hyper Training is available for toggling.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="t">Entity to train</param>
|
2022-06-12 16:26:45 +00:00
|
|
|
|
/// <param name="h">History of evolutions present as</param>
|
2022-02-05 01:35:15 +00:00
|
|
|
|
/// <returns>True if available, otherwise false.</returns>
|
2022-06-12 16:26:45 +00:00
|
|
|
|
public static bool IsHyperTrainingAvailable(this IHyperTrain t, EvolutionHistory h) => t switch
|
2022-02-05 01:35:15 +00:00
|
|
|
|
{
|
|
|
|
|
// Check for game formats where training is unavailable:
|
2022-06-12 16:26:45 +00:00
|
|
|
|
PA8 pa8 => pa8.HasVisitedSWSH(h.Gen8) || pa8.HasVisitedBDSP(h.Gen8b),
|
2022-03-06 04:03:52 +00:00
|
|
|
|
_ => true,
|
|
|
|
|
};
|
2022-02-05 01:35:15 +00:00
|
|
|
|
|
2022-06-12 16:26:45 +00:00
|
|
|
|
/// <inheritdoc cref="IsHyperTrainingAvailable(IHyperTrain, EvolutionHistory)"/>
|
2022-02-05 01:35:15 +00:00
|
|
|
|
/// <param name="pk">Entity data</param>
|
2022-06-12 16:26:45 +00:00
|
|
|
|
/// <param name="h">History of evolutions present as</param>
|
|
|
|
|
public static bool IsHyperTrainingAvailable(this PKM pk, EvolutionHistory h)
|
2022-02-05 01:35:15 +00:00
|
|
|
|
{
|
|
|
|
|
if (pk is not IHyperTrain t)
|
|
|
|
|
return false;
|
2022-06-12 16:26:45 +00:00
|
|
|
|
if (!t.IsHyperTrainingAvailable(h))
|
2022-02-05 01:35:15 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Gated behind level 100.
|
|
|
|
|
return pk.CurrentLevel == 100;
|
|
|
|
|
}
|
2018-06-06 04:31:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|